mirror of
https://github.com/php/php-src.git
synced 2024-09-22 18:37:25 +00:00
remember ? -> :pdox mapping so that binds by position can be mapped to names if required.
This commit is contained in:
parent
1bd3483dea
commit
9240c5f521
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user