diff options
author | Wez Furlong <wez@php.net> | 2005-07-12 03:19:44 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2005-07-12 03:19:44 +0000 |
commit | 9240c5f5216d289a4162bfd112774bb21566db62 (patch) | |
tree | 730889d6d50b6c7187ec7fa2e28b926b5f7370b4 | |
parent | 1bd3483dea1226cedf25e51ddd8f56cb7483e257 (diff) | |
download | php-git-9240c5f5216d289a4162bfd112774bb21566db62.tar.gz |
remember ? -> :pdox mapping so that binds by position can be mapped to names if required.
-rw-r--r-- | ext/pdo/pdo_sql_parser.re | 20 | ||||
-rwxr-xr-x | ext/pdo/pdo_stmt.c | 9 |
2 files changed, 21 insertions, 8 deletions
diff --git a/ext/pdo/pdo_sql_parser.re b/ext/pdo/pdo_sql_parser.re index f0ab2a6cb1..d707a286d9 100644 --- a/ext/pdo/pdo_sql_parser.re +++ b/ext/pdo/pdo_sql_parser.re @@ -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; diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 131c31c8a2..1c316d25a3 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -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); |