Is there a way to get a single query to return nul...
# lucee
d
Is there a way to get a single query to return null values? I know I can enable it for an entire site/application, but curious if there's a way to get a single Query to return it's null values instead of casting them to a string.
z
we did this for QoQ https://luceeserver.atlassian.net/browse/LDEV-3640 not sure about else where?
@bdw429s??
d
I occasionally need the null value preserved. I'm working towards changing the code to support nulls, but it's large code base and it's not going to happen overnight.
z
yeah the idea was to preserver them internally
i think you can access them directly?
b
Yes, the query object in Lucee does preserve the null. It only converts to an empty string on access.
There is a method to get the raw value
There is no query-level flag however.
d
@bdw429s Do you know what the method is to get the raw value off the top of your head?
z
erm, query.col.getClass()
🙏 1
b
No, but I can prolly look it up
d
I can do the research. Thanks though!
I just thought if you knew it off the top of your head...
z
hahaha
i've been so slammed with lucee 6 my FIFO buffer is broken
report back 🙂
b
@dswitzer I'm sure this isn't the only way, but it works
Copy code
qry = queryNew( 'col', 'string', [[nullvalue()],['']] )
dump( qry )

dump( qry.getColumn( 'col' ).get( 1, nullValue() ) )
dump( qry.getColumn( 'col' ).get( 2, nullValue() ) )
https://trycf.com/gist/8d3bd55b1f7759407dd5f502b75f8678/lucee5?theme=monokai
🙏 1
You get the column object from the query (Lucee query objects store data in columns, not in rows)
Then that SPECIFIC get method with a default value bypasses all the null logic and just directly returns data from the underlying native array
Copy code
@Override
	public Object get(int row, Object emptyValue) {
		if (row < 1 || row > size) return emptyValue;
		return data[row - 1] == null ? emptyValue : data[row - 1];
	}
Any methods you see using queryUtil like this are going to obey your null settings
Copy code
return QueryUtil.getValue(pc, this, row);
d
Thanks. I came up with: query.colum.get( 1, nullValue() ) Which is basically what you had. It's weird that the get(int) method was depreciated, but that definitely works. Thanks for the help from both of you!
b
Yeah, no idea why Micha deprecated that one
The method just throws an exception
Micha is a HUGE fan of methods that return default values
z
^^^^ understatement