I am currently building a function which needs to read a boolean field from a form, and depending on the value returned show or hide some records but keep any filtering already applied.
var vwherezero = forms.fabman_frm_budgeting_report_setup.br_skipyrzero
if (vwherezero == 1){
var $sql = databaseManager.getSQL(forms.zsystem_tci_fabman_detail.foundset)
var $year_zero_query = "SELECT budget_schedules.fc_fabric_key " +
"FROM budget_schedules, fabric_condition "+
"WHERE fabric_condition.fc_program_year_basic IS NOT NULL "+
"AND fabric_condition.fc_program_year_basic !=0 "+
"AND budget_schedules.fc_fabric_key = fabric_condition.fc_id "+
"AND fabric_condition.fc_id IN (" + $sql + ")"
controller.loadRecords($year_zero_query)
}
else
{
var $year_zero_query = "SELECT fc_fabric_key FROM budget_schedules"
controller.loadRecords($year_zero_query)
}
So where vwherezero = 1 i want to hide any records which have either 0 or null as a value for fc_program_year_basic.
I use getsql to get the sql code for a form i know has filters applied and concatenate it into a where clause for my new pk query, and then do loadRecords($year_zero_query).
When the code is executed i get the following error
There is a problem with an aggregate
> com.servoy.j2db.dataprocessing.DataException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and budget_schedules.fc_fabric_key = budgetschedules22743.fc_fabric_key) limit 2' at line 1
I do have aggregates within my solution, but all work fine except when i try to apply the above code.
Im not really sure what the line “budgetschedules22743” is referencing as i dont have that anywhere within my solution as far as i can tell.
For your info if i output the built SQL string to console i get the following
SELECT budget_schedules.fc_fabric_key FROM budget_schedules, fabric_condition WHERE fabric_condition.fc_program_year_basic IS NOT NULL AND fabric_condition.fc_program_year_basic !=0 AND budget_schedules.fc_fabric_key = fabric_condition.fc_id AND fabric_condition.fc_id IN (select fc_id from fabric_condition order by fc_id asc)
and if i run this within navicat i get the following result
This is the same query that causes the error ?
I see no filter being applied (SELECT fc_id FROM fabric_condition).
I am not sure if you can check out the aggregate query in the Performance Data page (in Servoy-admin pages) since it errors. But you could check that to see what exact SQL is used for the aggregate.
If it’s not there then you need to set the logging level to debug which will result in a WHOLE load of information with among it the aggregate query.
Yes this is the sql that seems to be causing the error as the form previews with aggregates and calculations fine without it.
I have a load of errors relating to aggregates within the server log when i try to print preview my form
here is an example
2009-12-18 11:39 AWT-EventQueue-0 ERROR com.servoy.j2db.util.Debug select sum(budgetschedules1529.bs_surface_prep_time) as bs_surface_prep_time_calc, sum(budgetschedules1529.bs_pre_treatment_cost) as bs_pre_treatment_calc, sum(budgetschedules1529.bs_paint_calculated_time) as bs_paint_time_calc, sum(budgetschedules1529.bs_m2) as m2_area_agg, sum(budgetschedules1529.bs_paint_material_cost) as bs_paint_material_cost_agg, sum(budgetschedules1529.bs_insulation_time) as direct_ins_time_agg, sum(budgetschedules1529.bs_surface_prep_mat_cost) as bs_surface_prep_mat_cost_agg, sum(budgetschedules1529.bs_insulation_material_cost) as bs_insulation_material_cost_agg, sum(budgetschedules1529.bs_pre_treat_mat_cost) as bs_pre_treat_mat_cost_agg from budget_schedules budgetschedules1529 where exists (select 1 from fabric_condition , budget_schedules where fabric_condition.fc_program_year_basic IS NOT NULL AND fabric_condition.fc_program_year_basic !=0 AND budget_schedules.fc_fabric_key = fabric_condition.fc_id AND fabric_condition.fc_id IN (select fc_id from fabric_condition and budget_schedules.fc_fabric_key = budgetschedules1529.fc_fabric_key) limit ? parameters: [2 ,type: java.lang.Integer]
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and budget_schedules.fc_fabric_key = budgetschedules1529.fc_fabric_key) limit 2' at line 1
at sun.reflect.GeneratedConstructorAccessor33.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2237)
at sun.reflect.GeneratedMethodAccessor453.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.servoy.j2db.persistence.datasource.Zf.invoke(Zf.java:8)
at $Proxy2.executeQuery(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:179)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:179)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:179)
at com.servoy.j2db.dataprocessing.SQLEngine.performSelect(SQLEngine.java:1042)
at com.servoy.j2db.dataprocessing.SQLEngine.performQuery(SQLEngine.java:691)
at com.servoy.j2db.dataprocessing.SQLEngine.performQuery(SQLEngine.java:239)
at com.servoy.j2db.dataprocessing.FoundSet.Zb(FoundSet.java:116)
at com.servoy.j2db.dataprocessing.FoundSet.Za(FoundSet.java:552)
at com.servoy.j2db.dataprocessing.FoundSet.getDataProviderValue(FoundSet.java:272)
at com.servoy.j2db.dataprocessing.Record.getValue(Record.java:143)
at com.servoy.j2db.dataprocessing.Zib.setRecord(Zib.java:182)
at com.servoy.j2db.dataprocessing.Zgb.Za(Zgb.java:297)
at com.servoy.j2db.dataui.Zze.refreshRecord(Zze.java:194)
at com.servoy.j2db.Zpb.Za(Zpb.java:200)
at com.servoy.j2db.Zpb.valueChanged(Zpb.java:344)
at com.servoy.j2db.Zpb.Za(Zpb.java:687)
at com.servoy.j2db.Zwb.Za(Zwb.java:316)
at com.servoy.j2db.Zwb.Ze(Zwb.java:146)
at com.servoy.j2db.Zgb.run(Zgb.java:2)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
SELECT SUM(budgetschedules1529.bs_surface_prep_time) as bs_surface_prep_time_calc,
SUM(budgetschedules1529.bs_pre_treatment_cost) as bs_pre_treatment_calc,
SUM(budgetschedules1529.bs_paint_calculated_time) as bs_paint_time_calc,
SUM(budgetschedules1529.bs_m2) as m2_area_agg,
SUM(budgetschedules1529.bs_paint_material_cost) as bs_paint_material_cost_agg,
SUM(budgetschedules1529.bs_insulation_time) as direct_ins_time_agg,
SUM(budgetschedules1529.bs_surface_prep_mat_cost) as bs_surface_prep_mat_cost_agg,
SUM(budgetschedules1529.bs_insulation_material_cost) as bs_insulation_material_cost_agg,
SUM(budgetschedules1529.bs_pre_treat_mat_cost) as bs_pre_treat_mat_cost_agg
FROM budget_schedules budgetschedules1529
WHERE
EXISTS (
SELECT 1 FROM fabric_condition, budget_schedules
WHERE fabric_condition.fc_program_year_basic IS NOT NULL
AND fabric_condition.fc_program_year_basic !=0
AND budget_schedules.fc_fabric_key = fabric_condition.fc_id
AND fabric_condition.fc_id IN (select fc_id from fabric_condition and budget_schedules.fc_fabric_key = budgetschedules1529.fc_fabric_key
)
LIMIT 2
This looks correct to me. Perhaps MySQL can’t handle such a join ?
What do you get when you run this in Navicat ?
fabric_condition.fc_id IN (SELECT fc_id FROM fabric_condition AND budget_schedules.fc_fabric_key = budgetschedules1529.fc_fabric_key
SELECT fc_id FROM fabric_condition
So far so good…then you get an AND instead of a WHERE…this is wrong.
And I think the tablename should’ve been aliased as well since it’s also used in the SELECT 1 FROM part of the query.
2009-12-18 13:07 AWT-EventQueue-0 ERROR com.servoy.j2db.util.Debug select budgetschedules4564.fc_fabric_key from budget_schedules budgetschedules4564 inner join fabric_condition fabriccondition4565 on budgetschedules4564.fc_fabric_key=fabriccondition4565.fc_id where budgetschedules4564.fc_fabric_key in (SELECT a.fc_fabric_key FROM budget_schedules a JOIN fabric_condition b ON a.fc_fabric_key = b.fc_id WHERE b.fc_program_year_basic IS NOT NULL AND b.fc_program_year_basic !=0 AND b.fc_id IN (select fc_id from fabric_condition ) order by fabriccondition4565.cd_complex asc, fabriccondition4565.cd_plant asc, fabriccondition4565.fc_program_year_basic asc parameters: <null>
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1957)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2086)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2237)
at sun.reflect.GeneratedMethodAccessor453.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.servoy.j2db.persistence.datasource.Zf.invoke(Zf.java:8)
at $Proxy2.executeQuery(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:179)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:179)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:179)
at com.servoy.j2db.dataprocessing.SQLEngine.performSelect(SQLEngine.java:1042)
at com.servoy.j2db.dataprocessing.SQLEngine.performQuery(SQLEngine.java:691)
at com.servoy.j2db.dataprocessing.SQLEngine.performQuery(SQLEngine.java:239)
at com.servoy.j2db.dataprocessing.FoundSet.loadByQuery(FoundSet.java:992)
at com.servoy.j2db.Zpb.Za(Zpb.java:644)
at com.servoy.j2db.FormController$JSForm.js_loadRecords(FormController.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:353)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2680)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:166)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3127)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:165)
at com.servoy.j2db.scripting.Zsb.executeFunction(Zsb.java:74)
at com.servoy.j2db.scripting.Ztb.executeFunction(Ztb.java:116)
at com.servoy.j2db.Zpb.Za(Zpb.java:1007)
at com.servoy.j2db.Zpb.Za(Zpb.java:636)
at com.servoy.j2db.Zpb.ZK(Zpb.java:852)
at com.servoy.j2db.Zwb.Za(Zwb.java:22)
at com.servoy.j2db.Zwb.Ze(Zwb.java:146)
at com.servoy.j2db.Zgb.run(Zgb.java:2)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
and also an error msg from navicat asking me to check my sql
As you can see the SQL is missing a closing parenthesis. Do you know where this SQL is generated ?
SELECT budgetschedules4564.fc_fabric_key
FROM budget_schedules budgetschedules4564
INNER JOIN fabric_condition fabriccondition4565 ON budgetschedules4564.fc_fabric_key=fabriccondition4565.fc_id
WHERE budgetschedules4564.fc_fabric_key IN
(
SELECT a.fc_fabric_key
FROM budget_schedules a
JOIN fabric_condition b ON a.fc_fabric_key = b.fc_id
WHERE b.fc_program_year_basic IS NOT NULL
AND b.fc_program_year_basic !=0
AND b.fc_id IN
(
SELECT fc_id FROM fabric_condition
)
ORDER BY
fabriccondition4565.cd_complex ASC,
fabriccondition4565.cd_plant ASC,
fabriccondition4565.fc_program_year_basic ASC