Question

I have an error that seems to be associated with <cfscript> db operation

// traffic tracking
myQry = new Query();
myQry.setSQL("INSERT INTO   dbo.Traffic (Circuit, Fuseaction, IP_hash) VALUES   (:circuit, :fuseaction, :ip_hash)");
myQry.addParam(name="circuit",      value="#listfirst(rc.fuseaction, '.')#",    cfsqltype="CF_SQL_VARCHAR");
myQry.addParam(name="fuseaction",   value="#listlast(rc.fuseaction, '.')#",     cfsqltype="CF_SQL_VARCHAR");
myQry.addParam(name="ip_hash",      value="#cgi.remote_addr#",                  cfsqltype="CF_SQL_VARCHAR");    
myQry.execute();

The really strange thing is, it looks like the operation completed. What kind of a error is this?

enter image description here

Was it helpful?

Solution

Short answer: It's probably a scoping issue. Try:

var myQry = new Query();


Long-winded waffley answer:

I'd call it an Adobe-developers-being-useless kind of error.

If you look at line 460 of that file, you'll see the error is due to a failure of StructFind to find the query name in the variables scope, and the reason it's appearing in debug input is because there's a try/catch with type any surrounding it. The same functionality could be achieved without causing/catching an error by replacing the try/catch with <cfif StructKeyExists(variables,tagAttributes['name']) > which is basic CFML knowledge, and certainly something a developer of the CF product should know!

The same code still exists in the CF10 version of base.cfc, so you may or not feel like submitting it as a bug in Adobe's CF bugbase - though it's unlikely they'll fix it for CF9 (and uncertain whether they'll feel CF10 is worth the effort either).

However, that would only be side-stepping the issue of the variable not existing, not addressing the real issue of why it doesn't actually exist. Given that the debug info shows the query is successfully executing, and the query code is basically right above that line (starts at line 442), it shouldn't be a repeated/common error, but it may be due to your myQry variable not being scoped, and thus it could be colliding with another variable also called myQry (or even the same var from a separate call to the function) which is happening between the execution of the new Query() and .execute() lines, and thus causing the original query to not be there when the StructFind looks for it.

The solution is to put the keyword var before the first use of myQry which will place it in the local scope for that function - something that should be done for all variables that are only for use within an instance of a function, (otherwise they are placed in the variables scope of the component/request that the function exists within).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top