Re: FW: [PHP-DEV] OCIError patch

From: Date: Tue, 12 Mar 2002 22:26:24 +0000
Subject: Re: FW: [PHP-DEV] OCIError patch
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-81101@lists.php.net to get a copy of this message
How about doing what sqlplus does and simply add an asterisk at that point? I'm ok with rolling my own inside of the script by using the offset element. I simply think it'll do PHP users a service to have the "sqltext" in the array in _some_ form, even if only with an asterisk. Your thoughts? Daniel Markus Fischer wrote:
I'm -indefinite until the html gets out of it. There are no error messages which do html on their own (if so, they are bogus and need to be fixed). Command line does not use <b>..</b> anymore (has been fixed). On Tue, Mar 12, 2002 at 02:02:30PM -0800, Daniel Ceregatti wrote :
Hi, Andi, thanks for the feedback. I've changed the patch to include emalloc and efree. I actually use PHP from the command line a lot and I've noticed that warnings always get wrapped in <b>, so I figured it was ok to do HTML here too. I've modified the patch to also include an "offset" element in the array returned by OCIError. This will allow someone to "roll their own" method for displaying the error. I've decided to leave the code that produces "sqltext" in, because I have a feeling the lazy programmers (i.e. ME) will be happy with that instead. New patch attached. Daniel
-----Original Message----- From: Andi Gutmans [mailto:andi@zend.com] Sent: Tuesday, March 12, 2002 13:08 To: Walter A. Boring IV; php-dev@lists.php.net Subject: Re: [PHP-DEV] OCIError patch Hey, I'm not quite sure it's correct for the error message to print HTML itself. It's probably more correct to do this from user land. In any case, you should not be using malloc()/free() but emalloc()/efree(). If the request gets interrupted the memory will be freed if you're using emalloc(). Andi At 12:59 12/03/2002 -0800, Walter A. Boring IV wrote:
Ahh. very kewl patch Dan. Walt On Tue, 2002-03-12 at 12:48, Daniel Ceregatti wrote:
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
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php
-- Daniel Ceregatti - Programmer Omnis Networks, LLC Q: What's a WASP's idea of open-mindedness? A: Dating a Canadian.
--- 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 13:49:07 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,34 @@ (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 *) emalloc (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_long(return_value, "offset", errorofs); + add_assoc_string(return_value, "sqltext", (char *) retsql, 1); add_assoc_string(return_value, "message", (char*) errbuf, 1); + efree (retsql); } else { RETURN_FALSE; }
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.dev (#81101) next »