HI,
I’m building a summary table with the Query Builder and have gotten an error attempting to join two QB queries. I’m getting a ‘could not resolve column’ issue on the join,
as it will not recognize the aliased ‘total_marks’ column on a join. What might i be doing wrong?
I’ve tried other attempts with various QB commands, and extra columns have been removed in the code below. Tried placing a ‘total_marks’ calculation on the table, also to no avail.
I’m building a table to review one table, constrained by elements of other tables.
Additional solution stuff…
Joins can only be made within the same server, between different inmem-datasources is also possible.
Rob Gansevles (thanks! Couldn’t get out of the forest for the trees.)
So this one is out.
Returned to the original joins and finally resolved to the fact that a table will have unique rows, upon join, there is a possibility of duplicate column data within rows which necessitates the inclusion of said rows into a groupBy statement, which only exist on QBSelect statements, not QBJoins.
Creating a foundset from a datasource can be summed up from a Query Builder statement, as such:
var pmST = databaseManager.createDataSourceByQuery(‘pmSTxx’,st,-1);//st is the createselect query, um, root…?
var fsST = databaseManager.getFoundSet(pmST);
fsST.loadAllRecords(); // foundset is memory-based, but is form independent
---------- current working QB Statements -------------
/** @type {QBSelectdb:/stsservoy/sheets} /
var st = databaseManager.createSelect(‘db:/stsservoy/sheets’);
st.sort.add(st.columns.sheet_number);
st.where.add(st.columns.delete_flag.isNull);
st.where.add(st.columns.job_id.eq(jobId));
st.where.add(st.columns.tenant_uuid.eq(globals.secCurrentTenantID));
if (criteria.sheetnuma && criteria.sheetnuma.length > 0){
st.where.add(st.columns.sheet_number.isin(criteria.sheetnuma));
}
/* @type {QBSelectdb:/stsservoy/marks} /
var pmm = st.joins.add(‘db:/stsservoy/marks’);
pmm.on.add(st.columns.sheet_id.eq(pmm.columns.sheet_id));
if (criteria.marksa && criteria.marksa.length == 1){
st.where.add(pmm.columns.mark.like(“%”+criteria.marksa.pop()+“%”));
}
if (criteria.marksa && criteria.marksa.length == 2){ // I’d really like an iteration here of some type
st.where.add(st.or
.add(pmm.columns.mark.like(“%”+criteria.marksa.pop()+“%”))
.add(pmm.columns.mark.like(“%”+criteria.marksa.pop()+“%”))
)
}
st.result.distinct;
st.sort.add(pmm.columns.mark);
st.sort.add(pmm.columns.parent_mark);
st.groupBy.add(pmm.columns.mark_id);
st.groupBy.add(st.columns.sheet_number);
st.groupBy.add(st.columns.sheet_id);
st.where.add(pmm.columns.delete_flag.isNull);
/* @type {QBJoindb:/stsservoy/routings} /
var rt1 = pmm.joins.add(‘db:/stsservoy/routings’,JSRelation.RIGHT_OUTER_JOIN,‘r’);
rt1.on.add(pmm.columns.e_route_code_id.eq(rt1.columns.routing_id));
/* @type {QBJoindb:/stsservoy/idfiles} */
var id1 = st.joins.add(‘db:/stsservoy/idfiles’);
st.where.add(pmm.columns.mark_id.eq(id1.columns.mark_id));
st.result.add(id1.columns.summed_quantity.sum,‘total_marks’);
var pmTable = databaseManager.getTable(‘stsservoy’,‘marks’);
var pmCols = pmTable.getColumnNames();
for (var index = 0;index < pmCols.length;index++){
st.result.add(pmm.columns[pmCols[index]]);
}
//pmDS = databaseManager.createDataSourceByQuery(‘pmSTxx’,st,-1)
//pmFS = databaseManager.getFoundSet(pmDS)
//pmFS.loadAllRecords()
yields when criteria.marksa=[“ZYX”,“MMM”]:
Record[DATA:Row(mem:pmSTxx)[DATA:_sv_rowid=61,total_marks=1.0,mark_id=BBBC6A7D-FE08-4619-AE27-534EDEE9B856,sheet_id=121F34A8-8DED-410F-A07D-9278D0541609,parent_mark=ZYX,mark=ZYX,material_class=null,fireproof_cubic_feet=null,e_route_code_id=F8008976-50A7-4BCB-A78F-13F5426971FF,
Record[DATA:Row(mem:pmSTxx)[DATA:_sv_rowid=62,total_marks=1.0,mark_id=B33B9417-A8F3-4E4E-BAFB-AE80BDF417F5,sheet_id=121F34A8-8DED-410F-A07D-9278D0541609,parent_mark=MMM,mark=MMM,material_class=null,fireproof_cubic_feet=null,e_route_code_id=F8008976-50A7-4BCB-A78F-13F5426971FF,
Obviously cut a bunch of junk out.
Thanks!
Joe
/** @type {QBSelectdb:/stsservoy/sheets} */
var st = databaseManager.createSelect(‘db:/stsservoy/sheets’);
st.where.add(st.columns.job_id.eq(jobId));
/** @type {QBSelectdb:/stsservoy/marks} */
var pmm = st.joins.add(‘db:/stsservoy/marks’);
pmm.on.add(st.columns.sheet_id.eq(pmm.columns.sheet_id));
st.result.add(pmm.columns.mark_id);
//pmDS = databaseManager.createDataSourceByQuery(‘stDSxxx’,st,-1)
//pmFS = databaseManager.getFoundSet(pmDS)
//pmFS.loadAllRecords()
yields:
Record[DATA:Row(mem:stDSxxx)[DATA:_sv_rowid=1,mark_id=1290C2CC-EBC5-437B-B8CD-39FA2D89862E,
Record[DATA:Row(mem:stDSxxx)[DATA:_sv_rowid=2,mark_id=47BFB275-FFAE-4AB3-ABBB-D55C69C94211,
Record[DATA:Row(mem:stDSxxx)[DATA:_sv_rowid=3,mark_id=BBBC6A7D-FE08-4619-AE27-534EDEE9B856,
Record[DATA:Row(mem:stDSxxx)[DATA:_sv_rowid=4,mark_id=77336B2E-2F84-43F2-BC66-5448E56CECBF,
Record[DATA:Row(mem:stDSxxx)[DATA:_sv_rowid=5,mark_id=B33B9417-A8F3-4E4E-BAFB-AE80BDF417F5,
Record[DATA:Row(mem:stDSxxx)[DATA:_sv_rowid=6,mark_id=7B290EDB-2E23-43BC-AD00-586C03FCE670,
Record[DATA:Row(mem:stDSxxx)[DATA:_sv_rowid=7,mark_id=FB6D2F88-E835-4224-89DC-26742EB1FE90,
/** @type {QBSelectdb:/stsservoy/idfiles} /
var id = databaseManager.createSelect(‘db:/stsservoy/idfiles’);
id.result.add(id.columns.mark_id);
id.result.add(id.columns.summed_quantity.sum, ‘total_marks’);
id.groupBy.add(id.columns.mark_id);
id.where.add(id.columns.mark_id.isin(st));
/* @type {QBSelect<db;/stsservoy/idfiles>} */
var idds = databaseManager.createDataSourceByQuery(‘idDS’,id,-1);
yields:
pRecord[DATA:Row(mem:stDSy)[DATA:_sv_rowid=1,mark_id=BBBC6A7D-FE08-4619-AE27-534EDEE9B856,total_marks=1.0,
Record[DATA:Row(mem:stDSy)[DATA:_sv_rowid=2,mark_id=B33B9417-A8F3-4E4E-BAFB-AE80BDF417F5,total_marks=1.0,
Record[DATA:Row(mem:stDSy)[DATA:_sv_rowid=3,mark_id=1290C2CC-EBC5-437B-B8CD-39FA2D89862E,total_marks=16.0,
Record[DATA:Row(mem:stDSy)[DATA:_sv_rowid=4,mark_id=FB6D2F88-E835-4224-89DC-26742EB1FE90,total_marks=1.0,
Record[DATA:Row(mem:stDSy)[DATA:_sv_rowid=5,mark_id=7B290EDB-2E23-43BC-AD00-586C03FCE670,total_marks=1.0,
Record[DATA:Row(mem:stDSy)[DATA:_sv_rowid=6,mark_id=47BFB275-FFAE-4AB3-ABBB-D55C69C94211,total_marks=80.0,
Record[DATA:Row(mem:stDSy)[DATA:_sv_rowid=7,mark_id=77336B2E-2F84-43F2-BC66-5448E56CECBF,total_marks=1.0,
/** @type {QBJoin} */
var idfls = st.joins.add(idds,JSRelation.INNER_JOIN,‘table’);
var columnT = idfls.getColumn(‘table’,‘total_marks’);
var columnP = idfls.getColumn(‘table’,‘mark_id’);
idfls.on.add(pmm.columns.marks_id.eq(columnP));
st.result.add(columnT);
yields:
“Error during evaluation:Wrapped java.lang.RuntimeException: com.servoy.j2db.persistence.RepositoryException: java.lang.IllegalStateException: Could not resolve column TEMP_13_A1003EFE-2138-49B2-9253-099DBC3A68A1mem:idDS#table.1073748223=?”