Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tech:codecharge:trapping_sql_errors [2014/11/15 09:13]
tech:codecharge:trapping_sql_errors [2014/11/15 09:13] (current)
Line 1: Line 1:
 +====== Trapping SQL Errors in CodeCharge ======
  
 +From an old post
 +
 +URL: http://​forums.codecharge.com/​posts.php?​post_id=21736
 +
 +Posted: 06/13/2003, 12:18 PM
 +
 +----
 +<​code>​
 +
 +Harold. I did already find a way to catch the Oracle Errors, however it is not a global solution. ​
 +In other words, you would have to do a page by page implementation of it.
 +
 +If you are only interested in catching the Oracle errors for certain pages than this may help you out.
 +
 +
 +In order to catch an error from the Oracle, you may "​hi-jack"​ the error codes from the current dataset Error . 
 +
 +The db_oci.php class file will create an associated array called Error.
 +
 +DO NOT CONFUSE THIS WITH CODECHARGE STUDIO'​S ERRORS ARRAY! THEY ARE TWO DIFFERENT ARRAYS.
 +
 +Error should contain the following elements:
 +1. code: The Oracle Error Code 
 +Example: 2292
 +2. message: The full message of the Oracle Error
 +Example: ORA-02292: integrity constraint (WEBUSER.SCONTSITEID_FK) violated - child record found 
 +If using PHP >= 4.3
 +3. offset: Indicates the location of the error.
 +4. sqltext: The statement which caused the error.
 +Example: DELETE FROM SITE_ACCT WHERE SITE_ID = 30008 
 +
 +To explain how to trap the errors, let's use an example of trying to delete a record where there 
 +is a Primary Key/Foreign Key relationship. If I were to try to delete a record from the Primary ​
 +Key table, and there was a child record in the other, than an ORA-02292: integrity constraint ​
 +error would occur.
 +
 +So if I wanted to allow the user to see ANY errors, not just the ORA-02292, ​
 +then I would do the following.
 +
 +1. I would setup a Custom Code Event in the "After Execute Delete"​ Event.
 +
 +2. I would then setup a simple test such as this:
 +if ($formname->​ds->​Error["​code"​] != 0) {
 +$formname->​Errors->​addError($formname->​ds->​Error['​message'​]);​
 +}
 +
 +You can do other tests based on the Error['​code'​] too. That way you can throw the error 
 +to the screen for certain error codes.
 +
 +</​code>​

QR Code
QR Code tech:codecharge:trapping_sql_errors (generated for current page)