Skip to content

Commit 36aa38b

Browse files
committed
Revert "Refactor bound_param_map to point to a zend_string*"
This reverts commit caeb33972cb4691287a1c9644d4c04f07e4fc066.
1 parent 567096d commit 36aa38b

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

ext/pdo/pdo_sql_parser.re

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct placeholder {
7777
};
7878

7979
static void free_param_name(zval *el) {
80-
zend_string_release_ex(Z_PTR_P(el), 0);
80+
efree(Z_PTR_P(el));
8181
}
8282

8383
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, zend_string *inquery, zend_string **outquery)
@@ -359,22 +359,20 @@ rewrite:
359359

360360
for (plc = placeholders; plc; plc = plc->next) {
361361
int skip_map = 0;
362-
zend_string *p;
362+
char *p;
363363
zend_string *idxbuf;
364-
zend_string *name_str;
365364

366365
if (plc->bindno == PDO_PARSER_BINDNO_ESCAPED_CHAR) {
367366
continue;
368367
}
369368

370369
name = estrndup(plc->pos, plc->len);
371-
name_str = zend_string_init(name, plc->len, 0);
372370

373371
/* check if bound parameter is already available */
374-
if (!strcmp(name, "?") || (p = zend_hash_find_ptr(stmt->bound_param_map, name_str)) == NULL) {
372+
if (!strcmp(name, "?") || (p = zend_hash_str_find_ptr(stmt->bound_param_map, name, plc->len)) == NULL) {
375373
idxbuf = zend_strpprintf(0, tmpl, bind_no++);
376374
} else {
377-
idxbuf = p;
375+
idxbuf = zend_string_init(p, strlen(p), 0);
378376
skip_map = 1;
379377
}
380378

@@ -384,11 +382,11 @@ rewrite:
384382

385383
if (!skip_map && stmt->named_rewrite_template) {
386384
/* create a mapping */
387-
zend_hash_update_ptr(stmt->bound_param_map, name_str, plc->quoted);
385+
zend_hash_str_update_mem(stmt->bound_param_map, name, plc->len, ZSTR_VAL(plc->quoted), ZSTR_LEN(plc->quoted) + 1);
388386
}
389387

390388
/* map number to name */
391-
zend_hash_index_update_ptr(stmt->bound_param_map, plc->bindno, plc->quoted);
389+
zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, ZSTR_VAL(plc->quoted), ZSTR_LEN(plc->quoted) + 1);
392390

393391
efree(name);
394392
}
@@ -407,11 +405,8 @@ rewrite:
407405

408406
for (plc = placeholders; plc; plc = plc->next) {
409407
char *name;
410-
zend_string *name_str;
411408
name = estrndup(plc->pos, plc->len);
412-
name_str = zend_string_init(name, plc->len, 0);
413-
//zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1);
414-
zend_hash_index_update_ptr(stmt->bound_param_map, plc->bindno, name_str);
409+
zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1);
415410
efree(name);
416411
plc->quoted = ZSTR_CHAR('?');
417412
newbuffer_len -= plc->len - 1;

ext/pdo/pdo_stmt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p
5050
* we will raise an error, as we can't be sure that it is safe
5151
* to bind multiple parameters onto the same zval in the underlying
5252
* driver */
53-
zend_string *name;
53+
char *name;
5454
int position = 0;
5555

5656
if (stmt->named_rewrite_template) {
@@ -60,7 +60,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p
6060
if (!param->name) {
6161
/* do the reverse; map the parameter number to the name */
6262
if ((name = zend_hash_index_find_ptr(stmt->bound_param_map, param->paramno)) != NULL) {
63-
param->name = name;
63+
param->name = zend_string_init(name, strlen(name), 0);
6464
return 1;
6565
}
6666
/* TODO Error? */
@@ -69,7 +69,7 @@ static inline bool rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_p
6969
}
7070

7171
ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) {
72-
if (zend_string_equals(name, param->name)) {
72+
if (strncmp(name, ZSTR_VAL(param->name), ZSTR_LEN(param->name) + 1)) {
7373
position++;
7474
continue;
7575
}

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *
275275
ZEND_ATOL(param->paramno, ZSTR_VAL(param->name) + 1);
276276
} else {
277277
/* resolve parameter name to rewritten name */
278-
zend_string *namevar;
278+
char *namevar;
279279

280280
if (stmt->bound_param_map && (namevar = zend_hash_find_ptr(stmt->bound_param_map,
281281
param->name)) != NULL) {
282-
param->paramno = ZEND_STRTOL(ZSTR_VAL(namevar), NULL, 10);
282+
ZEND_ATOL(param->paramno, namevar + 1);
283283
param->paramno--;
284284
} else {
285285
pdo_pgsql_error_stmt_msg(stmt, 0, "HY093", ZSTR_VAL(param->name));

0 commit comments

Comments
 (0)