Skip to content

Instantly share code, notes, and snippets.

@ryanguill
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanguill/b6497628e951a3cffacd to your computer and use it in GitHub Desktop.
Save ryanguill/b6497628e951a3cffacd to your computer and use it in GitHub Desktop.
<cfscript>
writedump(server.lucee.version); //4.5.1.000
q = queryNew("columnA");
function test1() {
var qData = queryExecute("SELECT * FROM q", {}, {dbtype="query", result="result"});
writedump("test1");
writedump(var=isNull(variables.result), label="isnull(variables.result)"); //false, result exists in the variables scope
writedump(var=isNull(local.result), label="isNull(local.result)"); //true
writedump(var=result, label="result");
}
function test2() {
//try to put the result in the local scope...
var qData = queryExecute("SELECT * FROM q", {}, {dbtype="query", result="local.result"});
writedump("test2");
writedump(var=isNull(variables.result), label="isnull(variables.result)"); //true
writedump(var=isNull(local.result), label="isNull(local.result)"); //true
writedump(var=isNull(result), label="isNull(result)"); //true! it doesn't exist anywhere
//fails to work, silently
}
function test3() {
//try to put the variable that will ultimately hold the result in the local scope first...
var result = {};
var qData = queryExecute("SELECT * FROM q", {}, {dbtype="query", result="result"});
writedump("test3");
writedump(var=isNull(variables.result), label="isnull(variables.result)"); //true, doesnt exist in variables scope
writedump(var=isNull(local.result), label="isNull(local.result)"); //false
writedump(var=local.result, label="local.result") //empty struct, not the actual result
//the actual result doesn't exist
//fails to work, silently
}
function test4() {
//try to put the variable that will ultimately hold the result in the local scope first...
var result = {};
//try to set the result without the quotes
var qData = queryExecute("SELECT * FROM q", {}, {dbtype="query", result=result});
writedump("test4");
writedump(var=isNull(variables.result), label="isnull(variables.result)"); //true, doesnt exist in variables scope
writedump(var=isNull(local.result), label="isNull(local.result)"); //false
writedump(var=local.result, label="local.result") //empty struct, not the actual result
//the actual result doesn't exist
//fails to work, silently
}
function test5() {
//try to set the result without the quotes, without the variable previously existing...
try {
var qData = queryExecute("SELECT * FROM q", {}, {dbtype="query", result=result});
} catch (any e) {
writedump(e); // error! variable [RESULT] doesn't exist
}
writedump("test5");
}
function test7works() {
//try to put the variable that will ultimately hold the result in the local scope first...
var foo = {};
var qData = queryExecute("SELECT * FROM q", {}, {dbtype="query", result="foo.result"});
writedump("test6");
writedump(var=local, label="local"); //contains result! works!
writedump(var=local.foo.result, label="local.result") //contains the result data!
}
//only run one test at a time otherwise you are polluting the variables scope
//test1();
test2();
//test3();
//test4();
//test5();
//test6();
//test7works();
</cfscript>
<cffunction name="test6" access="public" returntype="void" output="true">
<cfquery name="local.qData" result="local.result" dbtype="query">
select * from q
</cfquery>
<cfdump var="test5" />
<cfdump var="#isNull(variables.result)#" /> <!--- true, doesn't exist, as expected --->
<cfdump var="#isNull(local.result)#" /> <!--- false, exists, as expected --->
<cfdump var="#local#" /> <!--- exists in local scope, as expected --->
</cffunction>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment