]> granicus.if.org Git - php/commitdiff
Properly rewrite queries where a bound parameter appears more then once.
authorIlia Alshanetsky <iliaa@php.net>
Wed, 25 Jan 2006 16:35:23 +0000 (16:35 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 25 Jan 2006 16:35:23 +0000 (16:35 +0000)
ext/pdo/pdo_sql_parser.c
ext/pdo/pdo_sql_parser.re

index f9bac22230037d68053af17f5724f1a196b7bf9d..e05b9f4bd3a763442662fe000553361798226f53 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.9.11 on Sun Jan  1 14:38:30 2006 */
+/* Generated by re2c 0.9.11 on Wed Jan 25 11:31:13 2006 */
 #line 1 "ext/pdo/pdo_sql_parser.re"
 /*
   +----------------------------------------------------------------------+
@@ -512,15 +512,25 @@ rewrite:
                }
 
                for (plc = placeholders; plc; plc = plc->next) {
-                       snprintf(idxbuf, sizeof(idxbuf), tmpl, plc->bindno + 1);
+                       int skip_map = 0;
+                       char *p;
+                       name = estrndup(plc->pos, plc->len);
+
+                       /* check if bound parameter is already available */
+                       if (!strcmp(name, "?") || zend_hash_find(stmt->bound_param_map, name, plc->len + 1, (void**) &p) == FAILURE) {
+                               snprintf(idxbuf, sizeof(idxbuf), tmpl, plc->bindno + 1);
+                       } else {
+                               memset(idxbuf, 0, sizeof(idxbuf));
+                               memcpy(idxbuf, p, sizeof(idxbuf));
+                               skip_map = 1;
+                       }
+
                        plc->quoted = estrdup(idxbuf);
                        plc->qlen = strlen(plc->quoted);
                        plc->freeq = 1;
                        newbuffer_len += plc->qlen;
 
-                       name = estrndup(plc->pos, plc->len);
-
-                       if (stmt->named_rewrite_template) {
+                       if (!skip_map && stmt->named_rewrite_template) {
                                /* create a mapping */
                                
                                zend_hash_update(stmt->bound_param_map, name, plc->len + 1, idxbuf, plc->qlen + 1, NULL);
index e90609b3dd5952eef6224cc624a3a9a75c117056..a976c1fa6e1e6141d4f9bea14eb3c0a8424ed210 100644 (file)
@@ -287,15 +287,25 @@ rewrite:
                }
 
                for (plc = placeholders; plc; plc = plc->next) {
-                       snprintf(idxbuf, sizeof(idxbuf), tmpl, plc->bindno + 1);
+                       int skip_map = 0;
+                       char *p;
+                       name = estrndup(plc->pos, plc->len);
+
+                       /* check if bound parameter is already available */
+                       if (!strcmp(name, "?") || zend_hash_find(stmt->bound_param_map, name, plc->len + 1, (void**) &p) == FAILURE) {
+                               snprintf(idxbuf, sizeof(idxbuf), tmpl, plc->bindno + 1);
+                       } else {
+                               memset(idxbuf, 0, sizeof(idxbuf));
+                               memcpy(idxbuf, p, sizeof(idxbuf));
+                               skip_map = 1;
+                       }
+
                        plc->quoted = estrdup(idxbuf);
                        plc->qlen = strlen(plc->quoted);
                        plc->freeq = 1;
                        newbuffer_len += plc->qlen;
 
-                       name = estrndup(plc->pos, plc->len);
-
-                       if (stmt->named_rewrite_template) {
+                       if (!skip_map && stmt->named_rewrite_template) {
                                /* create a mapping */
                                
                                zend_hash_update(stmt->bound_param_map, name, plc->len + 1, idxbuf, plc->qlen + 1, NULL);