Dave Merrill
05/31/2024, 1:57 PMAdam Cameron
Dave Merrill
05/31/2024, 8:34 PM<cfscript>
q = queryNew("name", "VARCHAR", []);
q.addRow({name:"Jack"});
x = q.name ?: "q.name doesn't exist";
readout(x);
x = q.lastname ?: "q.lastname doesn't exist";
readout(x);
x = q.name[1] ?: "q.name[1] doesn't exist";
readout(x);
x = q.name[2] ?: "q.name[2] doesn't exist";
readout(x);
function readout(required string t)
{
writeOutput("result: " & t & "<br>");
}
</cfscript>
RESULT:
result: Jack
result: q.lastname doesn't exist
result: Jack
result:
Instead of "q.name[2] doesn't exist", the last result is just empty string.
...and excuse the tacky tacky quick test...Adam Cameron
Mark Takata (Adobe)
05/31/2024, 9:17 PMAdam Cameron
??
.
That aside, not sure you're quite following the use case I was raising, which was nothing about the ?:
operator 😉
The issue is that in a one-row query, checks of elements in row 2 (and subsequent) are ""
, not null
. That is - objectively, I think - wrong.Adam Cameron
Dave Merrill
05/31/2024, 9:43 PMAdam Cameron
Mark Takata (Adobe)
05/31/2024, 10:04 PMMark Takata (Adobe)
05/31/2024, 10:05 PMMark Takata (Adobe)
05/31/2024, 10:05 PMMark Takata (Adobe)
05/31/2024, 10:24 PMMark Takata (Adobe)
06/01/2024, 3:21 AMDave Merrill
06/02/2024, 10:51 AMMark Takata (Adobe)
06/02/2024, 6:31 PMDave Merrill
06/03/2024, 2:09 AMMark Takata (Adobe)
06/03/2024, 2:10 AMDave Merrill
06/03/2024, 2:11 AMMark Takata (Adobe)
06/03/2024, 2:20 AMDave Merrill
06/03/2024, 12:10 PMAdam Cameron
?:
. It's an issue with queries misreporting on non-existent rows.
As for ?:
expectations... It's the standard short-circuit ? :
(ie ternary operator), with the exception that it treats null
as falsy (which it usually isn't, in CFML).
So CFML's implementation is not quite the usual ? :
short -circuit, nor is it a null-coalescing operator (as false
is a fail).Adam Cameron
??
(which I'd seen in C#).
True to form, rather than listening to me (😜), Adobe implemented something that was neither fish nor fowl.Dave Merrill
06/04/2024, 1:51 PMwriteOutput("<h3>query rows</h3>");
q = queryNew("name", "VARCHAR", []);
q.addRow({name:"Jack"});
for (n in [-1,0,1,2])
{
x = q.name[n] ?: "q.name[#n#] doesn't exist";
readout("n=#n#: #x#");
x = q.name[n]; // direct reference gives the same result as elvis
readout("n=#n#: #x#");
}
function readout(required string t)
{
writeOutput("result: " & t & "<br>");
}
RESULT
result: n=-1: Jack
result: n=-1: Jack
result: n=0:
result: n=0:
result: n=1: Jack
result: n=1: Jack
result: n=2:
result: n=2: