]> granicus.if.org Git - php/commitdiff
remember ? -> :pdox mapping so that binds by position can be mapped to names if required.
authorWez Furlong <wez@php.net>
Tue, 12 Jul 2005 03:19:44 +0000 (03:19 +0000)
committerWez Furlong <wez@php.net>
Tue, 12 Jul 2005 03:19:44 +0000 (03:19 +0000)
ext/pdo/pdo_sql_parser.re
ext/pdo/pdo_stmt.c

index f0ab2a6cb127ec0a62f1c9c19601966ed0218ba3..d707a286d95ca14d80063c3221c86cbca051aaff 100644 (file)
@@ -276,9 +276,15 @@ rewrite:
                /* rewrite ? to :pdoX */
                char idxbuf[32];
                const char *tmpl = stmt->named_rewrite_template ? stmt->named_rewrite_template : ":pdo%d";
+               char *name;
                
                newbuffer_len = inquery_len;
 
+               if (stmt->bound_param_map == NULL) {
+                       ALLOC_HASHTABLE(stmt->bound_param_map);
+                       zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
+               }
+
                for (plc = placeholders; plc; plc = plc->next) {
                        snprintf(idxbuf, sizeof(idxbuf), tmpl, plc->bindno + 1);
                        plc->quoted = estrdup(idxbuf);
@@ -286,18 +292,18 @@ rewrite:
                        plc->freeq = 1;
                        newbuffer_len += plc->qlen;
 
+                       name = estrndup(plc->pos, plc->len);
+
                        if (stmt->named_rewrite_template) {
                                /* create a mapping */
-                               char *name = estrndup(plc->pos, plc->len);
                                
-                               if (stmt->bound_param_map == NULL) {
-                                       ALLOC_HASHTABLE(stmt->bound_param_map);
-                                       zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
-                               }
-
                                zend_hash_update(stmt->bound_param_map, name, plc->len + 1, idxbuf, plc->qlen + 1, NULL);
-                               efree(name);
                        }
+
+                       /* map number to name */
+                       zend_hash_index_update(stmt->bound_param_map, plc->bindno, idxbuf, plc->qlen + 1, NULL);
+                       
+                       efree(name);
                }
                                
                goto rewrite;
index 131c31c8a29b6fc3aeaa8cff106a72eee366e240..1c316d25a3e2d9499aea4503921e32531edc7000 100755 (executable)
@@ -92,7 +92,14 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa
                        return 1;
                }
                if (!param->name) {
-                       return 1;
+                       /* do the reverse; map the parameter number to the name */
+                       if (SUCCESS == zend_hash_index_find(stmt->bound_param_map, param->paramno, (void**)&name)) {
+                               param->name = estrdup(name);
+                               param->namelen = strlen(param->name);
+                               return 1;
+                       }
+                       pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC);
+                       return 0;
                }
     
                zend_hash_internal_pointer_reset(stmt->bound_param_map);