I need to escape actual columns (`:`) which are ne...
# cfml-general
e
I need to escape actual columns (
:
) which are needed in a SELECT statement in
queryExecute
. More details in thread...
I am working with Snowflake and ACF21 and trying to run a
queryExecute
with a JDBC connection. In my case, Snowflake has a flattened JSON table column which you can query individual keys like this (assuming the column name is
RECORD_CONTENT
)
Copy code
return queryExecute(
	"SELECT TOP 50
	RECORD_CONTENT:booking_id AS id
	FROM mytable
	WHERE RECORD_CONTENT:status = :status",
	{
		status = {
			value = arguments.status,
			cfsqltype = "cf_sql_varchar"
		}
	}
);
However this creates issues when you add query params in the WHERE clause because they are separated by a column themselves. CF thinks that the selects are params, and ends up changing the query to this:
Copy code
... SELECT RECORD_CONTENT?:booking_id ...
(notice the "?"), and the query fails complaining about not having enough query params. I found this stackoverflow answer, which suggests escaping the columns, but it doesn't work for me: https://stackoverflow.com/questions/53308446/how-to-properly-escape-colon-in-queryexecute-sql-statement Is there any other solution than the suggested second solution in that answer, which is change all the SELECT columns into queryparams? That does seem like a lot of work.
Copy code
result = QueryExecute("
  SELECT :selectBookingid AS ...
  ",
  { selectBookingid : "RECORD_CONTENT:booking_id"}
  );
w
did you try a #chr(58)# as in
RECORD_CONTENT#chr(58)#status
or
"...WHERE RECORD_CONTENT:" & "status..."
?
e
I had not but I just tried that and it doesn't work. This
Copy code
RECORD_CONTENT#chr(58)#booking_id AS id
turns into this:
Copy code
SELECT TOP 50 RECORD_CONTENT? AS id
w
isn't there a way to build a parameterized sql statement using ? rather than the :xxx bindings
m
setting parameters as an array, instead of a struct would use ? instead of alias :xxx
r
I was just going to say that. Using ? and an array of values.
e
that's a good point, I had forgotten that you can use an array of params. Let me try that.
r
Note. It's an array of values, not params.
👍 1
e
Thank you. That works like a charm.