Using "arguments" array in prepared statements

If a method accepts parameters, those parameters get mapped to Servoy’s arguments array automatically. This is a great feature, but I have not had any luck using the arguments array for prepared statements.

For example, the following code does not seem to work…

databaseManager.getDataSetByQuery(currentcontroller.getServerName(), ‘SELECT foo FROM bar where bar = ?’, arguments, 1);

Would be a time saver to be able to pass arguments to the getDataSetByQuery fx for prepared statement.

Perhaps I am just doing something wrong :oops:

Hi Jeff,

The issue is that arguments is not an Array type. It’s an Object.
The getDataSetByQuery expects a value of the type Array.
What you can do however is pass an Array with your values to the first argument of the method and then pass it to the getDataSetByQuery as arguments[0].

Hope this helps.

I have been playing a little bit and came up with this:

var array = new Array(0);
array = array.concat(arguments);

Can you test if this works for you?

What about simply adding brackets?

var arguments = 42
databaseManager.getDataSetByQuery(currentcontroller.getServerName(), 'SELECT foo FROM bar where bar = ?', [arguments], 1);

Rob

isn’t that adding an array as an element to the other array instead of concatenating it?

At the end of the day I was trying to avoid creating a new array to hold the data the args object already has. It’s redundant for me to have to do it in each method that I have prepared SQL statements in.

Maybe the getDataSetbyquery fx could someday be modified to accept either an array or an object? Servoy seems to be really very good at creating/implementing shortcuts for developers, this would be a good one in my opinion.

Thanks for all the replies.

Well, that the arguments are an object instead of an array is an “issue” of JavaScript in general.

The new JavaScript 2.0 specs have fixed this anomaly… If only they get the specs finilized… (they have been working on that since 1999…)

I won’t hold my breath then Paul. Thanks.