cvs: php-src(PHP_5_1) /ext/pdo pdo_stmt.c

From: Date: Fri, 25 Nov 2005 00:29:06 +0000
Subject: cvs: php-src(PHP_5_1) /ext/pdo pdo_stmt.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-35366@lists.php.net to get a copy of this message
wez Thu Nov 24 19:29:06 2005 EDT Modified files: (Branch: PHP_5_1) /php-src/ext/pdo pdo_stmt.c Log: Fix for #35332. The problem is caused by the user mixing positional and named parameters. PDO was blindly adding the parameters, unaware that the same parameters were already allocated by position. What we do now is register the parameter with the driver before adding it to any hash. This gives the driver an opportunity to normalize the name and parameter number. PDO can then ensure that only one entry is occupied in the hash for a given parameter. http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_stmt.c?r1=1.118.2.18&r2=1.118.2.19&ty=u Index: php-src/ext/pdo/pdo_stmt.c diff -u php-src/ext/pdo/pdo_stmt.c:1.118.2.18 php-src/ext/pdo/pdo_stmt.c:1.118.2.19 --- php-src/ext/pdo/pdo_stmt.c:1.118.2.18 Thu Nov 24 11:21:41 2005 +++ php-src/ext/pdo/pdo_stmt.c Thu Nov 24 19:29:04 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pdo_stmt.c,v 1.118.2.18 2005/11/24 16:21:41 iliaa Exp $ */ +/* $Id: pdo_stmt.c,v 1.118.2.19 2005/11/25 00:29:04 wez Exp $ */ /* The PDO Statement Handle Class */ @@ -288,7 +288,7 @@ ZVAL_ADDREF(param->driver_params); } - if (param->name && stmt->columns) { + if (!is_param && param->name && stmt->columns) { /* try to map the name to the column */ int i; @@ -299,13 +299,15 @@ } } -#if 0 /* if you prepare and then execute passing an array of params keyed by names, * then this will trigger, and we don't want that */ if (param->paramno == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Did not found column name '%s' in the defined columns; it will not be bound", param->name); } -#endif + } + + if (is_param && !rewrite_name_to_position(stmt, param TSRMLS_CC)) { + return 0; } if (param->name) { @@ -317,30 +319,26 @@ } else { param->name = estrndup(param->name, param->namelen); } - 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); - } - - if (is_param && !rewrite_name_to_position(stmt, pparam TSRMLS_CC)) { - return 0; } /* tell the driver we just created a parameter */ if (stmt->methods->param_hook) { - if (!stmt->methods->param_hook(stmt, pparam, + if (!stmt->methods->param_hook(stmt, param, PDO_PARAM_EVT_ALLOC TSRMLS_CC)) { - /* driver indicates that the parameter doesn't exist. - * remove it from our hash */ - if (pparam->name) { - zend_hash_del(hash, pparam->name, pparam->namelen); - } else { - zend_hash_index_del(hash, pparam->paramno); - } return 0; } } + if (param->paramno >= 0) { + zend_hash_index_del(hash, param->paramno); + } + + if (param->name) { + 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); + } + return 1; } /* }}} */

« previous php.cvs (#35366) next »