Copy link to clipboard
Copied
Is there a way to display the value of cfqueryparam upon a database error? For example:
<cfquery name="causeError" datasource="#application.dsn#">
select street1 from house, #table2# where house.houseid = #table2#.houseid and house.houseid = #form.houseid#
</cfquery>
The variable table2 is dynamically generated and let's say an error is caused table2 being an empty string or a table that doesn't exist. So the error given is:
[Macromedia][Oracle JDBC Driver][Oracle]ORA-00903: invalid table name
4 : <cfquery name="causeError" datasource="#application.dsn#">
5 : select street1 from house, #table2# where house.houseid = #table2#.houseid and house.houseid = #form.houseid#
6 : </cfquery>
SQL select street1 from house, where houseid = 123;
So I know that the user was trying to look at a house with houseid = 123. I can then try to replicate the error using the same record in the database which can ultimately can help me diagnose the problem more quickly.
However, if I use cfqueryparam, i.e.:
<cfquery name="causeError" datasource="#application.dsn#">
select street1 from house, #table2# where house.houseid = #table2#.houseid and house.houseid = <cfqueryparam value="#form.houseid#" cfsqltype="cf_sql_integer">
</cfquery>
I get:
[Macromedia][Oracle JDBC Driver][Oracle]ORA-00903: invalid table name
4 : <cfquery name="causeError" datasource="#application.dsn#">
5 : select street1 from house, #table2# where house.houseid = #table2#.houseid and house.houseid = <cfqueryparam value="#form.houseid#" cfsqltype="cf_sql_integer">
6 : </cfquery>
SQL select street1 from house, where house.houseid = .houseid and house.houseid = (param 1)
I have no idea what the user entered.
The cfqueryparam value is buried deep in the cfcatch structure. You may get to it, for example, by doing something like this:
<cftry>
<!--- Put your query here --->
<cfcatch type="database">
<cfdump var="#cfcatch.where#">
</cfcatch>
</cftry>
Copy link to clipboard
Copied
The cfqueryparam value is buried deep in the cfcatch structure. You may get to it, for example, by doing something like this:
<cftry>
<!--- Put your query here --->
<cfcatch type="database">
<cfdump var="#cfcatch.where#">
</cfcatch>
</cftry>
Copy link to clipboard
Copied
Perfect. Thank you. I think I will probably end up dumping the whole cfcatch struct and the cgi struct and have it saved to some log.
Copy link to clipboard
Copied
OK. Then please mark the answer - which may, of course, be your own post - as correct. The main thing is that this will help fellow developers to find answers quickly.