3 Replies Latest reply on Sep 15, 2006 7:11 AM by jdeline

    Display SQL query in error text

    Tea man
      Using CFMX 6.1.
      Is it possible to get our error handler page to display the SQL query that fails and causes an error?
      If tried #error.sql# but it doesn't exist after a db exception. If I put a cftry around a particular query and then use cfcatch.sql within a cfcatch tag pair, it works fine. But given our error handler page is for the entire site, I can't use cfcatch, at least not the way the site is currently architected. I was hoping error.sql would work since my quick ref quide states that "Any cfcatch variable that applies to exception type can be accessed within the Error scope. But then it doesn't list Error.SQL or CFCATCH.SQL for that matter in any documentation I've seen, yet the later works in cfcatch tags.

      Any help would be appreciated.
        • 1. Re: Display SQL query in error text
          jdeline Level 1
          What about using the CFTRY/CFCATCH method, then doing a CFLOCATION to your sitewide error handler with CFCATCH.SQL in the URL:
          <CFLOCATION URL="errHandler.cfm?#URLEncodedFormat(CFCATCH.SQL)#>
          Be sure to wrap this in <CFOUTPUT></CFOUTPUT>
          • 2. Re: Display SQL query in error text
            Tea man Level 1
            I'm not able to wrap all the site wide queries with cftry and cfcatch handlers. Some have it but there are far too many to do that for all of them. Maybe I missed your point/suggestion. But thanks anyway.
            • 3. Display SQL query in error text
              jdeline Level 1
              You don't have to place a CFTRY/CFCATCH around each query. I don't know how many pages you have in your application, but you could do something like the following:

              1. Replace <body> with <body><CFTRY>

              2. Replace </body> with the following
              <CFCATCH TYPE="database">
              <CFMODULE TEMPLATE="customErrorPage.cfm" sqlStatement="#CFCATCH.Sql# " message="#CFCATCH.message#">

              You can use a global search-and-replace utility, such as SR32, to make this task painless. Click here to go to the SR32 site.