queryExecute does not support passing arguments scope as param structure
Description
Environment
is blocked by
Activity
Michael Offner 14 August 2015 at 07:58
Michael Offner 14 August 2015 at 07:47
Former user 25 April 2015 at 22:27
Unit tests for this available on https://bitbucket.org/SimonHooker/lucee/branch/LDEV-24
Former user 25 April 2015 at 21:56Edited
I've reproduced this using the following (including some debug code that works in the same way as the queries do)
<cfscript>
function getData_errors (ID) {
var data = queryNew("ID","Integer");
queryAddRow(data);
querySetCell(data, "ID", 1);
var it = arguments.entryIterator();
while(it.hasNext()){
var e = it.next();
writedump( e.getKey().getString() );
writedump( e.getValue() );
}
//passing arguments directly doesnt work
return queryExecute("SELECT * FROM data where ID = :ID", arguments, {dbtype="query"});
}
try {
writedump(getData_errors(1)); //error! no param with name [name] found
} catch (any e) {
writedump(e);
}
</cfscript>
If you swap :ID for ? then it works, which indicates it's not resolving as a structure. This is due to the convert() method. It has 2 definitions
public static SQL convert(String sql, Struct params) throws PageException{
public static SQL convert(String sql, Array params) throws PageException{
However due to the arguments being both Struct and Array it's hitting the second one.
This is probably easily fixed, will just put together some unit tests.
Ryan Guill 31 January 2015 at 23:24
Can I get confirmation that this is a bug?
I believe this stems from this line: https://github.com/getrailo/railo/blob/694e8acf1a762431eab084da762a0abbe5290f49/railo-java/railo-core/src/railo/runtime/functions/query/QueryExecute.java#L21
the arguments structure returns true for both isArray and isStruct, so it is trying to treat it as an array instead of a structure. I suppose that someone might be trying to use question marks and the arguments structure as an array, in which case I guess it will work. But I suspect that far more people would want to use the arguments as a structure instead with named parameters.
Is there an efficient way to determine if the sql is using positional or named parameters, short of doing a regular expression trying to determine?
If we can come up with a resolution I would be happy to try and offer a PR for this.
(as an aside, I cannot seem to find queryExecute in the lucee repository. also, it seems as though bitbucket doesn't have a function to search the source code (which I will sorely miss!) so it may have been refactored, but I can't find it.)
Details
Assignee
Michael OffnerMichael OffnerReporter
Ryan GuillRyan GuillPriority
MajorLabels
New Issue warning screen
Before you create a new Issue, please post to the mailing list first https://dev.lucee.org
Once the issue has been verified, one of the Lucee team will ask you to file an issue
Details
Details
Assignee
Reporter
Priority
Labels
New Issue warning screen
Before you create a new Issue, please post to the mailing list first https://dev.lucee.org
Once the issue has been verified, one of the Lucee team will ask you to file an issue
migrated from: https://issues.jboss.org/browse/RAILO-3284
queryExecute() fails with an error message when attempting to use the arguments structure as the params structure. Here is a repo case:
https://gist.github.com/ryanguill/ba378a7f3167aff02b12
Writing a function that creates a new structure, key by key from the arguments scope allows it to work, which leads me to believe it is something specific with the arguments scope.
structCopy() and duplicate() do not resolve the issue.
The code performs correctly on CF 11. verified still an issue on lucee 4.5