diff options
Diffstat (limited to 'ext/pdo')
-rw-r--r-- | ext/pdo/pdo_sql_parser.c | 9 | ||||
-rw-r--r-- | ext/pdo/pdo_sql_parser.re | 9 | ||||
-rw-r--r-- | ext/pdo/pdo_stmt.c | 12 |
3 files changed, 18 insertions, 12 deletions
diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c index 4420fcf97c..50b2b5d6ec 100644 --- a/ext/pdo/pdo_sql_parser.c +++ b/ext/pdo/pdo_sql_parser.c @@ -434,6 +434,10 @@ struct placeholder { struct placeholder *next; }; +static void free_param_name(zval *el) { + efree(Z_PTR_P(el)); +} + PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char **outquery, int *outquery_len TSRMLS_DC) { @@ -670,7 +674,7 @@ rewrite: 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_init(stmt->bound_param_map, 13, NULL, free_param_name, 0); } for (plc = placeholders; plc; plc = plc->next) { @@ -711,12 +715,11 @@ rewrite: 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_init(stmt->bound_param_map, 13, NULL, free_param_name, 0); } for (plc = placeholders; plc; plc = plc->next) { char *name; - name = estrndup(plc->pos, plc->len); zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1); efree(name); diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re index 883a22c7ff..4a206c79f4 100644 --- a/ext/pdo/pdo_sql_parser.re +++ b/ext/pdo/pdo_sql_parser.re @@ -76,6 +76,10 @@ struct placeholder { struct placeholder *next; }; +static void free_param_name(zval *el) { + efree(Z_PTR_P(el)); +} + PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, char **outquery, int *outquery_len TSRMLS_DC) { @@ -312,7 +316,7 @@ rewrite: 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_init(stmt->bound_param_map, 13, NULL, free_param_name, 0); } for (plc = placeholders; plc; plc = plc->next) { @@ -353,12 +357,11 @@ rewrite: 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_init(stmt->bound_param_map, 13, NULL, free_param_name, 0); } for (plc = placeholders; plc; plc = plc->next) { char *name; - name = estrndup(plc->pos, plc->len); zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1); efree(name); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index bb8a95eaff..62db2c6636 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -128,7 +128,7 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa * we will raise an error, as we can't be sure that it is safe * to bind multiple parameters onto the same zval in the underlying * driver */ - zval *name; + char *name; int position = 0; if (stmt->named_rewrite_template) { @@ -137,16 +137,16 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa } if (!param->name) { /* do the reverse; map the parameter number to the name */ - if ((name = zend_hash_index_find(stmt->bound_param_map, param->paramno)) != NULL) { - param->name = STR_COPY(Z_STR_P(name)); + if ((name = zend_hash_index_find_ptr(stmt->bound_param_map, param->paramno)) != NULL) { + param->name = STR_INIT(name, strlen(name), 0); return 1; } pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC); return 0; } - ZEND_HASH_FOREACH_VAL(stmt->bound_param_map, name) { - if (strncmp(Z_STRVAL_P(name), param->name->val, param->name->len + 1)) { + ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) { + if (strncmp(name, param->name->val, param->name->len + 1)) { position++; continue; } @@ -460,7 +460,7 @@ static PHP_METHOD(PDOStatement, execute) if (key) { /* yes this is correct. we don't want to count the null byte. ask wez */ - param.name = STR_COPY(key); + param.name = key; param.paramno = -1; } else { /* we're okay to be zero based here */ |