I had a weird error this morning.
Named Sql parameter 'state ORDER' used in the query not found in the queryparams
Below is the code I had and it look fine to me:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfscript>
queryService = new query();
queryService.setDatasource("cfdocexamples");
queryService.setName("GetParks");
queryService.addParam(name="state",value="MD",cfsqltype="VARCHAR");
queryService.setSQL(
"SELECT PARKNAME, REGION, STATE
FROM Parks WHERE STATE = :state
ORDER BY ParkName, State ");
result = queryService.execute();
writeDump( result.getResult() );
</cfscript>
1<cfscript>
2queryService = new query();
3queryService.setDatasource("cfdocexamples");
4queryService.setName("GetParks");
5queryService.addParam(name="state",value="MD",cfsqltype="VARCHAR");
6queryService.setSQL(
7"SELECT PARKNAME, REGION, STATE
8FROM Parks WHERE STATE = :state
9ORDER BY ParkName, State ");
10result = queryService.execute();
11writeDump( result.getResult() );
12</cfscript>
After staring at my code for a while and realising that doing that wouldn't fix anything I
butchered played around with the syntax and found that after the WHERE clause you need to keep your SQL on one line. Making
the following change to setSQL() fixed the problem:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
queryService.setSQL(
"SELECT PARKNAME, REGION, STATE
FROM Parks WHERE STATE = :state ORDER BY ParkName, State ");
1queryService.setSQL(
2"SELECT PARKNAME, REGION, STATE
3FROM Parks WHERE STATE = :state ORDER BY ParkName, State ");
I can't seem to find a reference as to how your SQL should be formatted but it seems the new line plays around
with the deliminators and the way the named params are found.
I'm posting this now but will hopefully later find time to look in on query.cfc in the com/adobe/coldfusion folder under customtags to find the actual reason