Hi,

I wrote a small patch to oci8.c's OCIError function which places the 
following tag:

<span style="color:#FF0000; font-weight:bold">&lt;ERROR&gt;</span>

just before an error in a sql statement and adds the modified statement 
text into a new element called "sqltext" to the array returned by 
OCIError, much the same way sqlplus adds an asterisk under an error.

I find this very useful, and I'm hoping you will too. I've attached the 
patch.

Thanks,

Daniel Ceregatti
--- php-4.1.2/ext/oci8/oci8.c.orig      Tue Mar 12 11:56:17 2002
+++ php-4.1.2/ext/oci8/oci8.c   Tue Mar 12 12:23:35 2002
@@ -4090,10 +4090,13 @@
        zval **arg;
        oci_statement *statement;
        oci_connection *connection;
-    text errbuf[512];
-    sb4 errcode = 0;
+       text errbuf[512];
+       sb4 errcode = 0;
        sword error = 0;
        dvoid *errh = NULL;
+       ub2 errorofs = 0;
+       text *sqltext;
+       char *retsql;
 
        if (zend_get_parameters_ex(1, &arg) == SUCCESS) {
                statement = (oci_statement *) zend_fetch_resource(arg TSRMLS_CC, -1, 
NULL, NULL, 1, le_stmt);
@@ -4130,10 +4133,33 @@
                                (ub4) sizeof(errbuf),
                                (ub4) OCI_HTYPE_ERROR));
 
+       CALL_OCI_RETURN(statement->error, OCIAttrGet(
+                               (dvoid *)statement->pStmt,
+                               OCI_HTYPE_STMT,
+                               (text *) &sqltext,
+                               (ub4 *)0,
+                               OCI_ATTR_STATEMENT,
+                               statement->pError));
+
+       CALL_OCI_RETURN(statement->error, OCIAttrGet(
+                               (dvoid *)statement->pStmt,
+                               OCI_HTYPE_STMT,
+                               (ub2 *)&errorofs,
+                               (ub4 *)0,
+                               OCI_ATTR_PARSE_ERROR_OFFSET,
+                               statement->pError));
+
        if (errcode) {
+               retsql = (char *) malloc (strlen (sqltext) + 100);
+               memset (retsql, 0, strlen (sqltext) + 100);
+               strncat (retsql, sqltext, (int) errorofs);
+               strcat (retsql, "<span style=\"color:#FF0000; 
+font-weight:bold\">&lt;ERROR&gt;</span>");
+               strcat (retsql, (char *) sqltext + (int) errorofs);
                array_init(return_value);
                add_assoc_long(return_value, "code", errcode);
+               add_assoc_string(return_value, "sqltext", (char *) retsql, 1);
                add_assoc_string(return_value, "message", (char*) errbuf, 1);
+               free (retsql);
        } else {
                RETURN_FALSE;
        }

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to