]> granicus.if.org Git - php/commitdiff
The fix for #35332 caused #35671 (and thus PECL #6504).
authorWez Furlong <wez@php.net>
Mon, 27 Mar 2006 20:51:01 +0000 (20:51 +0000)
committerWez Furlong <wez@php.net>
Mon, 27 Mar 2006 20:51:01 +0000 (20:51 +0000)
Partially back out that fix and introduce an extra optional step for drivers to
canonicalize the "name" that is used for registering parameters.

ext/pdo/pdo_stmt.c
ext/pdo/php_pdo_driver.h
ext/pdo_pgsql/pgsql_statement.c

index c86aa91ac3ad433bbf36af03a0604dcc4c739143..9e4cbf757ffb39b4e0886bf477e7b0578c5defba 100755 (executable)
@@ -323,10 +323,14 @@ static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_s
                }
                return 0;
        }
-       
-       /* tell the driver we just created a parameter */
+
+       /* ask the driver to perform any normalization it needs on the
+        * parameter name.  Note that it is illegal for the driver to take
+        * a reference to param, as it resides in transient storage only
+        * at this time. */
        if (stmt->methods->param_hook) {
-               if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_ALLOC TSRMLS_CC)) {
+               if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_NORMALIZE
+                               TSRMLS_CC)) {
                        if (param->name) {
                                efree(param->name);
                                param->name = NULL;
@@ -335,16 +339,36 @@ static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_s
                }
        }
 
+       /* delete any other parameter registered with this number.
+        * If the parameter is named, it will be removed and correctly
+        * disposed of by the hash_update call that follows */
        if (param->paramno >= 0) {
                zend_hash_index_del(hash, param->paramno);
        }
-       
+
+       /* allocate storage for the parameter, keyed by its "canonical" name */
        if (param->name) {
-               zend_hash_update(hash, param->name, param->namelen, param, sizeof(*param), (void**)&pparam);
+               zend_hash_update(hash, param->name, param->namelen, param,
+                       sizeof(*param), (void**)&pparam);
        } else {
-               zend_hash_index_update(hash, param->paramno, param, sizeof(*param), (void**)&pparam);
+               zend_hash_index_update(hash, param->paramno, param, sizeof(*param),
+                       (void**)&pparam);
        }
 
+       /* tell the driver we just created a parameter */
+       if (stmt->methods->param_hook) {
+               if (!stmt->methods->param_hook(stmt, pparam, PDO_PARAM_EVT_ALLOC
+                                       TSRMLS_CC)) {
+                       /* undo storage allocation; the hash will free the parameter
+                        * name if required */
+                       if (pparam->name) {
+                               zend_hash_del(hash, pparam->name, pparam->namelen);
+                       } else {
+                               zend_hash_index_del(hash, pparam->paramno);
+                       }
+                       return 0;
+               }
+       }
        return 1;
 }
 /* }}} */
index 5d0c0685911b3c40c047a2e2866756f5a4649d4d..2b9d947a6a6d7a3cff328672c6370a66f96805d8 100755 (executable)
@@ -44,7 +44,7 @@ PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC);
 # define FALSE 0
 #endif
 
-#define PDO_DRIVER_API 20051128
+#define PDO_DRIVER_API 20060327
 
 enum pdo_param_type {
        PDO_PARAM_NULL,
@@ -338,7 +338,8 @@ enum pdo_param_event {
        PDO_PARAM_EVT_EXEC_PRE,
        PDO_PARAM_EVT_EXEC_POST,
        PDO_PARAM_EVT_FETCH_PRE,
-       PDO_PARAM_EVT_FETCH_POST
+       PDO_PARAM_EVT_FETCH_POST,
+       PDO_PARAM_EVT_NORMALIZE
 };
 
 typedef int (*pdo_stmt_param_hook_func)(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type TSRMLS_DC);
index 02418fa14024de61738b9853e9356e768d700080..d83b86ad781071ff6e418bdba4688b2f40f30652 100644 (file)
@@ -221,7 +221,7 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
                                }
                                break;
 
-                       case PDO_PARAM_EVT_ALLOC:
+                       case PDO_PARAM_EVT_NORMALIZE:
                                /* decode name from $1, $2 into 0, 1 etc. */
                                if (param->name) {
                                        if (param->name[0] == '$') {
@@ -240,6 +240,10 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
                                }
                                break;
 
+                       case PDO_PARAM_EVT_ALLOC:
+                               /* work is handled by EVT_NORMALIZE */
+                               return 1;
+
                        case PDO_PARAM_EVT_EXEC_PRE:
                                if (!S->param_values) {
                                        S->param_values = ecalloc(