Hi, I’m trying to work out if I’m doing something stupid or there is a bug:
I have a query
SELECT document_id FROM acc_documents WHERE date_trunc('day',document_date) = ? ORDER BY document_number DESC
And a date argument in the args array
[Tue Jan 09 2007 00:00:00 GMT-0000 (GMT)]
If I try
currentcontroller.loadRecords(query,args);
I get an error
Error loading primary key data, Can't infer the SQL type to use for an instance of java.util.Date. Use setObject() with an explicit Types value to specify the type to use.
com.servoy.j2db.dataprocessing.DataException: Can't infer the SQL type to use for an instance of java.util.Date. Use setObject() with an explicit Types value to specify the type to use.
Hi, the argument is created using new Date(). The same query and args work when used in
databaseManager.getDataSetByQuery().
try this code (my table is called test2, with two fields, test2_id and a_date)
//CREATE SOME SAMPLE DATA
controller.loadAllRecords();
if(controller.getMaxRecordIndex() == 0) {
for ( var i = 1 ; i < 10 ; i++ )
{
controller.newRecord();
a_date = new Date();
//MY TREE DOES NOT CONTAIN controller.saveData() !!!!
}
}
//CODE WHICH FAILS
var query = "SELECT test2_id FROM test2 WHERE a_date = ? ORDER BY a_date";
var d = new Date();
var args = new Array();
args.push(d);
controller.loadRecords(query,args);
I think I have seen your error before. Have you reported this one (with sample)? Dates are one of the main reasons for using a prepared statement, because you never know what the database expects…