Hi CFMLers! Today I've been working with queries o...
# cfml-general
j
Hi CFMLers! Today I've been working with queries on CF2021, specifically the valueArray() function, as it's documented here: https://cfdocs.org/valuearray I've been running into some problems. I've supplied a query as the first argument and a string column name in the second argument, but I keep getting error messages along the lines of "Method valueArray() does not exist with the given parameters". Is this a known issue, or am I responsible for what may be going wrong here?
1
w
post the code where you're calling valuearray
j
Hi! I'm almost finished with a workaround of this problem, but here's the original code that created the issue
Copy code
myTable_preupdate = queryExecute( "SELECT * FROM myTable" );
pkArray = valueArray(myTable_preupdate, "id");
w
have you tried changing the query variable name to not have an underscore? in the past an underscore had additional 'meaning' for certain magic cf behavior
j
I will do that! Thanks for the tip
j
2 cents - does the dump show the variables you want?
w
also, if you replace value array with
listtoarray( valuelist("myTable_preupdate.id") )
give intended results?
1
j
When I dump the query, I do get the correct result set I am looking for. The problem just arises when calling valueArray().
👍 1
Wow. So it works when I remove the underscore from the variable name.
That's actually bonkers XD
w
in the olden days the underscore had influence on form parameter validation for cfinput/cfform. clearly unrelated to valuearray or queries, but it stood out to me when you pasted it, so whatever. i'm old
😀 1
j
Thanks for saying something! I thought I'd gone crazy
I think I'm going to suggest an addition to the docs because of this
👍 1
w
honestly i wish cfdocs or the official lucee/acf docs had community contributed snippets and examples like the php docs have always had
j
that is dusting off some hidden memory nodes. good catch @websolete
j
It looks like you can make edits to cfdocs via forking the github repository
w
i wouldn't want to moderate it that's for sure, but it was always quite valuable in the php docs i found, people would actually provide interesting and useful info
on a given function or whatever
i'm not saying this was the cause, but to be clear about what i was saying about underscores, as i recall if you had a form field named something_integer or something_phone or crap like that that it clued cf into trying to validate the value to whatever format was underscored onto it. i may be forgetting the specifics, but i wonder if there's some 'magic' (read that stupid and uninstended) functionality that cf has to try to 'validate' the variable, so perhaps under the hood it was trying to validate the 'preupdate' format. an underscore is a valid char in a variable name, even by itself, so it shouldn't do anything special, but who knows
or possibly it converted the underscore to an unexpected delimeter, so it thought your query reference was to myTable.preupdate and it got confused
j
It seems snakecase can be a bit deceitful in cf!
I haven't used much of snakecase naming, but just started a bit recently and now we had this issue
w
it's not perl for god's sake. suck it up and just name vars with three or less characters
😆 1
😂 2
j
If you can't read minified js like English, what are you doing with your life 😏
w
did the listtoarray/valuelist approach work? i would expect the same restriction on _preupdate to apply
j
No, the same restriction occurred there with the underscore causing an error.
w
dumb
i mean FEATURE
j
Yeah, it's a bit of a brain buster. I would have never caught it. Thanks again!
w
n_p
😂 1
g
This is odd. I copied the simple valueArray example from CFDocs (which uses queryNew), added "_preupdate" as a query variable name suffix and didn't get an error on CF2016+ or Lucee. Are you able to replicate this with a small example outside of your environment? (Note: I didn't test it the CF beta.)
Is it possible your query actually returns two (2) "ID" columns? I've seen some issues where using "*" can return duplicate columns names and it's a mystery to determine which one will get used when making assignments. (I think it may be the first one in the logical query order.)
j
This is peculiar. I just ran this on trycf.com. It looks like it's working fine here:
g
Another thing to watch out for is if you modify the data (ie, querySetCell) to make sure that you cast that value or you will encounter CF errors when using query-of-queries. This same issue could possibly manifest itself here too.
j
I've just confirmed that I have only one "id" column in the table that I'm working with. Some other columns include the characters "id" together, like "legacy_id", but there's just one "id" column.
a
@Jeff Stevens can you replicate the error on trycf.com at all? TBH, I don't believe any of the analysis here about underscores being relevant, and you haven't given us an exact repro case, and even the description of the error was vague "error messages along the lines of ~". The error message says "method", whereas the only code you've given us (or at least a picture of the code!), is calling the
valueArray
function.
I would not be suggesting any updates to any docs before you can actually demonstrate the issue with a stand-alone repro case.
🙌 1
j
@Adam Cameron I have been unable to replicate my error in trycf.com, unfortunately. Even in my own environment, I'm having trouble replicating the error 🫤 You're right to bring criticism to this solution. The most recollection I have of the error message was "the valuearray method was not found". I'd agree with you and say the jury isn't out on this.
a
Ah well. Next time eh? Will be interesting to see what it was that caused it.
🙌 1
j
For sure. I'll make sure to keep an eye out.