This code raise an exception:
<cfqueryparam value="#notExists#" null="#!IsDefined('notExists')#">
Error is:
variable [notExists] doesn't exist
Yes, “notExists” not really exists :
<cfdump var="#IsDefined('notExists')#"> -> false
If null=true, according to the documentation, Lucee shouldn’t even evaluate the variable in “value” attribute.
It’s not so?
OS: Windows 10
Java Version: AdoptOpenJDK 11.0.11
Lucee Version: 5.3.9.133
try and avoid isDefined
try
<cfparam name="notExists" default="">
then
<cfqueryparam value="#notExists#" null="#isEmpty(notExists)#">
pretty sure the “#notExists#” is always going to be evaluated as an attribute, i don’t think the shortcut evaluation like in a if statement applies here
sure, this works.
I just tried, ACF works like Lucee too.
But it seems bit nonsense to me… By ACF docs:
Whether parameter is passed as a null value:
· yes: tag ignores the value attribute.
· no
Bye
I take that to mean “the engine doesn’t pass the specified value to the database in the sql statement”, not “the engine skips over the value attribute and doesn’t try to evaluate it”.
1 Like
Definitely feels like it would be better to skip over it.
Some other patters I’ve seen/used over always defining as a blank (sometimes not defined is how the code was written/intended):
<cfqueryparam value="#isDefined('notExists')?notExists:''#" null="#!isDefined('notExists')#">
<cfqueryparam value="#isNull(notExists)?'':notExists#" null="#isNull(notExists)#">
I’d also prefer the shorter (more intuitive) version
<cfqueryparam value="#notExists#" null="#isNull(notExists)#">
1 Like
Sure … I think the better question is why evaluate it?
In theory we’re already checking the null attribute.
If null is true, why search the scopes / evaluate the variable when it never gets used?