• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Error Handling for CFQUERYPARAM

New Here ,
Jan 02, 2015 Jan 02, 2015

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.

TOPICS
Database access

Views

518

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 03, 2015 Jan 03, 2015

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>

Votes

Translate

Translate
Community Expert ,
Jan 03, 2015 Jan 03, 2015

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 03, 2015 Jan 03, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2015 Jan 04, 2015

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation