no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | tech:codecharge:trapping_sql_errors [2014/11/15 15:13] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Trapping SQL Errors in CodeCharge ====== | ||
| + | From an old post | ||
| + | |||
| + | URL: http:// | ||
| + | |||
| + | Posted: 06/13/2003, 12:18 PM | ||
| + | |||
| + | ---- | ||
| + | < | ||
| + | |||
| + | 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 " | ||
| + | |||
| + | The db_oci.php class file will create an associated array called Error. | ||
| + | |||
| + | DO NOT CONFUSE THIS WITH CODECHARGE STUDIO' | ||
| + | |||
| + | 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" | ||
| + | |||
| + | 2. I would then setup a simple test such as this: | ||
| + | if ($formname-> | ||
| + | $formname-> | ||
| + | } | ||
| + | |||
| + | You can do other tests based on the Error[' | ||
| + | to the screen for certain error codes. | ||
| + | |||
| + | </ | ||