PDO: Store/pass query_string as zend_string

Rather than storing char* + size_t, use a zend_string*. Also
avoid various copies of the query string.
This commit is contained in:
Nikita Popov 2020-12-11 17:13:38 +01:00
parent c288b5294b
commit 2d51c203f0
15 changed files with 81 additions and 102 deletions

View file

@ -100,7 +100,7 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
S->param_types = NULL;
}
if (S->query) {
efree(S->query);
zend_string_release(S->query);
S->query = NULL;
}
@ -151,7 +151,7 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt)
efree(q);
}
spprintf(&q, 0, "DECLARE %s SCROLL CURSOR WITH HOLD FOR %s", S->cursor_name, stmt->active_query_string);
spprintf(&q, 0, "DECLARE %s SCROLL CURSOR WITH HOLD FOR %s", S->cursor_name, ZSTR_VAL(stmt->active_query_string));
S->result = PQexec(H->server, q);
efree(q);
@ -177,7 +177,7 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt)
stmt_retry:
/* we deferred the prepare until now, because we didn't
* know anything about the parameter types; now we do */
S->result = PQprepare(H->server, S->stmt_name, S->query,
S->result = PQprepare(H->server, S->stmt_name, ZSTR_VAL(S->query),
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0,
S->param_types);
status = PQresultStatus(S->result);
@ -222,7 +222,7 @@ stmt_retry:
0);
} else if (stmt->supports_placeholders == PDO_PLACEHOLDER_NAMED) {
/* execute query with parameters */
S->result = PQexecParams(H->server, S->query,
S->result = PQexecParams(H->server, ZSTR_VAL(S->query),
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0,
S->param_types,
(const char**)S->param_values,
@ -231,7 +231,7 @@ stmt_retry:
0);
} else {
/* execute plain query (with embedded parameters) */
S->result = PQexec(H->server, stmt->active_query_string);
S->result = PQexec(H->server, ZSTR_VAL(stmt->active_query_string));
}
status = PQresultStatus(S->result);