Highlighted

Error Handling for CFQUERYPARAM

New Here ,
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.

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

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>

TOPICS
Database access

Views

430

Likes

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

Error Handling for CFQUERYPARAM

New Here ,
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.

Adobe Community Professional
Correct answer by BKBK | Adobe Community Professional

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>

TOPICS
Database access

Views

431

Likes

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
Jan 02, 2015 0
Adobe Community Professional ,
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>

Likes

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
Reply
Loading...
Jan 03, 2015 0
New Here ,
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.

Likes

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
Reply
Loading...
Jan 03, 2015 0
BKBK LATEST
Adobe Community Professional ,
Jan 04, 2015

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.

Likes

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
Reply
Loading...
Jan 04, 2015 0