Is there any way to get the SQL statement (and par...
# lucee
a
Is there any way to get the SQL statement (and params) out of a
database
exception? If has
queryError
and
Sql
(nice capitalisation btw) there, but that is not what was sent to the DB: it's a string with the param placeholders swapped out for the data values.
EG my statement is
SELECT col FROM table WHERE id = ?
and params
["invalid"]
and I want to get those two bits of data back exactly like that, not
SELECT col FROM table WHERE id = 'invalid'
which is what would be in
queryError
/
Sql
in this situation.
w
i think it might depend on the type of exception it's actually throwing. like if it couldn't prepare the statement with the params i don't think it will return those. what is the exception message itself?
a
I have never seen the params not re-inlined in database exceptions. On any DB exception I've seen. My example above was just convenient for my explanation.
w
in certain cases it will be in the 'where' key of the exception
in cf10, for this query:
Copy code
SELECT id, <cfqueryparam cfsqltype="cf_sql_varchar" value="blah"> AS hello FROM tablename WHERE id = <cfqueryparam cfsqltype="cf_sql_varchar" value="blah">
the where key in the exception contains:
Copy code
(param 1) = [type='IN', class='java.lang.String', value='blah', sqltype='cf_sql_varchar'] , (param 2) = [type='IN', class='java.lang.String', value='blah', sqltype='cf_sql_varchar']
that's cf10, cfquery and cfqueryparam tags, fwiw
1