Skip to main content
Participant
Jan 3, 2015 4:14 AM UTC
Answered

Error Handling for CFQUERYPARAM

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.

This topic is closed to new replies. Start a new post to keep the conversation going.
BKBK
BKBKCorrect answer
Community Expert
Jan 3, 2015 7:55 PM UTC

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>

3 replies

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
Jan 3, 2015 7:55 PM UTC

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>

Translate
j_leeAuthor
Participant
Jan 3, 2015 8:20 PM UTC

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.

Translate
BKBK
Community Expert
Community Expert
Jan 4, 2015 10:37 AM UTC

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.

Translate