getDataSetByQuery and integer parameters

Since a while (I think since 3.5.2) I have the following problem:

See the coding:

var _table_id = parseInt(arguments [0]);

application.output(typeof(_table_id));

var _query = 'SELECT database_table_field_id, fieldname FROM database_table_field WHERE database_table_id = ?'
var _ds = databaseManager.getDataSetByQuery('servername', _query, new Array(_table_id), -1)

The method is being called. When I check the debugger I see value 297 in my variable ‘_table_id’; The parseInt() was added to test, but without this parseInt() is goes wrong as well.

The typeof() function returns ‘number’

But the line with getDataSetByQuery() gives the following error:

JSDataSet:exception:com.servoy.j2db.dataprocessing.DataException: Unable to convert between java.lang.Object and JAVA_OBJECT.

And I really don’t know why this error is triggered. This kind of construction I use very often and only on certain places I get this error. Specially when using an integer parameter.

When I change my query to:

var _query = 'SELECT database_table_field_id, fieldname FROM database_table_field WHERE database_table_id = ' + _table_id
var _ds = databaseManager.getDataSetByQuery('servername', _query, null, -1)

then it works all correct, so it has something to do with using (integer) parameters.

Anyone has the same problem?

The problem is that

new Array(5)

constructs an empty array of length 5. If you have

new Array(5, 2, 3)

it is no problem. It is safer to do this

databaseManager.getDataSetByQuery('servername', _query, new [_table_id], -1)

Hope this helps.

Hi Patrick,

Thanks for your reply, I understand what you want to say, but the solution you gave doesn’t work.

databaseManager.getDataSetByQuery(‘servername’, _query, new [_table_id], -1)

I’m getting error about “Invalid function”.

But I rewrote my coding like this

var _args = new Array()
_args[0] = _table_id

var _query = 'SELECT database_table_field_id, fieldname FROM database_table_field WHERE database_table_id = ?'
var _ds = databaseManager.getDataSetByQuery('servername', _query, _args, -1)

and now it works also

sorry, remove the “new” and my approach also works :wink:

I think in the previous case
you were creating an array of length _table_id using new Array(_table_id)

so array size was equal to _table_id . but having null values

May be this was the problem

sorry, remove the “new” and my approach also works

Thanks, you are right.
That avoids to make an extra variable for the argument like I did in my second solution