]> granicus.if.org Git - php/commitdiff
- Fixed bug #47398 (PDO_Firebird doesn't implements quoter correctly)
authorFelipe Pena <felipe@php.net>
Sun, 15 Feb 2009 21:51:00 +0000 (21:51 +0000)
committerFelipe Pena <felipe@php.net>
Sun, 15 Feb 2009 21:51:00 +0000 (21:51 +0000)
NEWS
ext/pdo_firebird/firebird_driver.c

diff --git a/NEWS b/NEWS
index 6cc28ea4721b1e72fa970b15a54edf4c6c2f6c87..3d2561559d183460c49d5941e96ca3465736893c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2009, PHP 5.3.0 Beta 2  
+- Fixed bug #47398 (PDO_Firebird doesn't implements quoter correctly). (Felipe)
 - Fixed bug #47329 (Crash in garbage collector). (Dmitry)
 - Fixed bug #47320 ($php_errormsg out of scope in functions). (Dmitry)
 - Fixed bug #47265 (generating phar.phar failes because of safe_mode). (Greg)
index eb83d9a7bb75ea059d94fbad044c9ecf88ea9276..1c875a2555dd1b2216f9a6314823991741d81777 100644 (file)
@@ -274,38 +274,38 @@ static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unqu
        char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC)
 {
        int qcount = 0;
-       char const *c;
+       char const *co, *l, *r;
+       char *c;
        
+       if (!unquotedlen) {
+               *quotedlen = 2;
+               *quoted = emalloc(*quotedlen+1);
+               strcpy(*quoted, "''");
+               return 1;
+       }
+                       
        /* Firebird only requires single quotes to be doubled if string lengths are used */
-       
        /* count the number of ' characters */
-       for (c = unquoted; (c = strchr(c,'\'')); qcount++, c++);
+       for (co = unquoted; (co = strchr(co,'\'')); qcount++, co++);
        
-       if (!qcount) {
-               return 0;
-       } else {
-               char const *l, *r;
-               char *c;
-               
-               *quotedlen = unquotedlen + qcount;
-               *quoted = c = emalloc(*quotedlen+1);
-               
-               /* foreach (chunk that ends in a quote) */
-               for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
-                       
-                       /* copy the chunk */
-                       strncpy(c, l, r-l);
-                       c += (r-l);
-                       
-                       /* add the second quote */
-                       *c++ = '\'';
-               }
-               
-               /* copy the remainder */
-               strncpy(c, l, *quotedlen-(c-*quoted));
+       *quotedlen = unquotedlen + qcount + 2;
+       *quoted = c = emalloc(*quotedlen+1);            
+       *c++ = '\'';
+       
+       /* foreach (chunk that ends in a quote) */
+       for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {                     
+               strncpy(c, l, r-l+1);
+               c += (r-l+1);                   
+               /* add the second quote */
+               *c++ = '\'';
+       }
                
-               return 1;
-       }                       
+       /* copy the remainder */
+       strncpy(c, l, *quotedlen-(c-*quoted)-1);
+       (*quoted)[*quotedlen-1] = '\''; 
+       (*quoted)[*quotedlen]   = '\0';
+       
+       return 1;
 }
 /* }}} */