Adam Cameron
<cfquery>
call that causes a DB error, is there any way of getting back the exact SQL string that was sent to the DB? In the returned exception all the param values have been inlined into the SQL (eg: I see SELECT * from tbl WHERE col = 'param value'
not SELECT * from tbl WHERE col = ?
(and then a separate struct of the param values that were passed).
Reason being... the error I am getting is with how Lucee is passing the param values, and I can't troubleshoot it if I can't see what it's passing.
I could likely get it back from the underlying JDBC exception, but Lucee swallows that (see https://luceeserver.atlassian.net/browse/LDEV-3738).
Am just wondering if there's any other way.
The issue is that somehow an SQL string / <cfqueryparam>
combo I am getting is somehow passing more params than it is param markers (ie, the ?
in the SQL string), and I'm trying to work out why. Error is Parameter index out of range (3 > number of parameters, which is 2)
The SQL string is getting munged by some CFWheels stupidity, but I am trying to work out how I'm not just getting a SQL syntax error (which I should), rather than this param count mismatch.
To recap, the question is just this: "is there any way of getting back the exact SQL string that was sent to the DB?"
The rest is context.zackster
09/07/2022, 2:39 PMzackster
09/07/2022, 2:52 PMAdam Cameron
zackster
09/07/2022, 2:55 PMzackster
09/07/2022, 2:56 PMpublic function after(args,caller,meta) {}
Adam Cameron
Adam Cameron
zackster
09/07/2022, 2:57 PMthis.query.listener=component {
public function after(args,caller,meta) {}
}
zackster
09/07/2022, 2:59 PMzackster
09/07/2022, 4:11 PMAdam Cameron
Adam Cameron
Olivia ('Ollie')
(it's their cat's name).
CFWheels's "ORM" then cocks that up, and the ensuing SQL fragment ends up being:
AND col2 = <cfqueryparam value="Olivia ('Ollie" cfsqltype="cf_sql_varchar">)'
(Note how it's mis-parsed the value due to an inability to deal with single quotes properly, and half the value is in the param, and half is after it).
This results in the entire SQL statement being:
SELECT *
FROM test
WHERE
col1 = <cfqueryparam value="val1" cfsqltype="cf_sql_varchar">
AND col2 = <cfqueryparam value="Olivia ('Ollie" cfsqltype="cf_sql_varchar">)'
AND col3 = <cfqueryparam value="val3" cfsqltype="cf_sql_varchar">
AND col4 = <cfqueryparam value="val4" cfsqltype="cf_sql_varchar">
When this is passed to the DB driver, it's like this:
SELECT *
FROM test
WHERE
col1 = ?
AND col2 = ?)'
AND col3 = ?
AND col4 = ?
It seems the driver doesn't care that that string starting with the last '
isn't terminated, and is seeing this as a string value:
AND col3 = ?
AND col4 = ?
So those ?
are not being seen as param markers. However Lucee is dutifully passing all four <cfqueryparam>
values through, as it should. The DB driver sees two param markers, but has four param values. Error.
So Lucee's doing nowt wrong, and nor is the DB driver... it's reporting things exactly as they are. It's just a quirky result of CFWheels messing up.
---
Now if only CFWheels... oh... [sigh]... never mind. I don't have any expectations of CFWheels doing things right once we stray away from completely obvious stuff.risto
09/07/2022, 7:56 PMAdam Cameron
8.0.22-13
Don't quite understand what specifically you are asking about re "Are you submitting this into the database..."
I mean... I posted the repro query. It's a SELECT
as you say, so... I cannot decipher exactly what yer asking as to me it seems like you answered your own question. What am I missing?risto
09/07/2022, 8:13 PMristo
09/07/2022, 8:13 PMristo
09/07/2022, 8:19 PMristo
09/07/2022, 8:22 PMWHERE
(
core_trees.treename =
'Olivia (''Ollie'
)
) AND (
core_trees.deletedAt IS NULL
)
Adam Cameron
exists
, where we're passing in some SQL in the where
parameter value. And Wheels - aaah bless - thinks it knows how to parse SQL like it's seen the grown-ups do.
It happens in the shitfuckery that is this mess:
https://github.com/cfwheels/cfwheels/blob/v1.4.5/wheels/model/adapters/Base.cfc#L302risto
09/07/2022, 8:42 PMAdam Cameron
risto
09/07/2022, 9:32 PM<cfqueryparam attributeCollection="#loc.queryParamAttributes#">
Your example search string is great. I always strip that stuff when submitted but I agree it should work. If the pets name is olivia or ollie choose one or the other when you search:)Adam Cameron
Adam Cameron
risto
09/07/2022, 9:45 PMAdam Cameron
Adam Cameron
Adam Cameron
risto
09/07/2022, 10:03 PMAdam Cameron
<cfquery>
for things that aren't 100% straight-forward. For anything other than obvious stuff, I find Wheels' "ORM" to be less effective/clear than just an SQL statement, if I am to be frank.