Weird question for all you old-timers. Have you ev...
# cfml-general
d
Weird question for all you old-timers. Have you ever been able to add a column to a query by just setting a value for it in one row? Like without calling queryAddColumn() or some such? Not that I remember, but someone is asking about that.
a
Pretty sure it doesn't work.
But am also sure it'd would be quicker to test than to type the question in here 😉
d
You're right, doesn't work, but I'm asking if historically it EVER worked. And just to be clear, I'm not recommending any such thing, just trying to answer that question.
a
I am 75% certain it's not worked back when I used to try such things. Which woulda been CF4.5-6.1-ish
👍 1
My test code shows up a possible bug in CF2023 though...
I take it back. it's a bugfix by the looks. Terrible error message though @Mark Takata (Adobe) https://trycf.com/gist/6fd92357c6189579e1c20dd93e84cfa8/acf2023?theme=monokai
(forget which CF engineers pay attn here, sorry, or I'd ping them)
👍 1
m
I’ll bring it to some folks’ attention.
a
Thanks pal
❤️ 1
m
Just because they'll ask, you say "terrible error message" but what would be your expected msg/response? Is the Lucee response acceptable?
a
Yeah, they're spitting out "implementation detail". Lucee's got it right. ie; I'm not working with a columnMap structure... they are working with a column map structure. TBH it's poss a bug in their code, and the error is bubbling up to CFMLland
The issue with my code is that I'm referencing a column that doesn't exist in my query object. The issue in their code is that they're not handling that properly, I think
m
Perfect. Thank you sir.
⭐ 1
g
I realise it is not what you're specifically asking about; But - if you just want to add a column that is the same value in every row - you can alter the SQL like below;
Copy code
SELECT
id, description, 'MYVALUE'
FROM
someTable
Which would give you results like;
Copy code
1,Description 1 is here, MYVALUE
2,Dexcription 2 is here, MYVALUE
...
I do this when I am working with a lot of joins and want it to be clear where the data from one table stops and the next starts;
Copy code
select
'111111', a.id, a.xxx, '222222', b.id, b.yyy
from
someTable a 
inner join someOtherTable b on ...
Copy code
111111, 1, xxx, 222222, 14, yyy
111111, 2, xxx, 222222, 87, yyy
...
a
I was curious and remembered I'd seen Julian Halliwell renamed columns in a query using
setColumnNames
- turns out you can use it to add columns as well... https://trycf.com/gist/d4c243c3130925290dd4abc27cf29a7a/lucee5?theme=monokai
⭐ 1
Not quite the scenario you described but may have been what they misremembered?
(Just searched our codebase to make sure we're not doing that as some of the code is must be 20 years old!)
e
Instead of QueryAdd, Get result of Queries for tables you need, then build the output based upon QoQ, Example: https://trycf.com/gist/ab1dc9b53327688df3a35ec2ebe1c185/lucee5?theme=monokai