ext/pdo_pgsql: Retrieve the memory usage of the query result resource (#14260)

`getAttribute()` can now retrieve the memory usage of query results.
`PDO::PGSQL_ATTR_RESULT_MEMORY_SIZE` was added for this feature.

closes #14260
This commit is contained in:
武田 憲太郎 2024-05-15 11:15:33 +00:00 committed by Saki Takamachi
parent ba534e70e6
commit b7dd3d8347
No known key found for this signature in database
GPG key ID: E4A36F6D37931A8B
9 changed files with 96 additions and 2 deletions

View file

@ -705,6 +705,32 @@ static int pdo_pgsql_stmt_cursor_closer(pdo_stmt_t *stmt)
return 1;
}
static int pgsql_stmt_get_attr(pdo_stmt_t *stmt, zend_long attr, zval *val)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
switch (attr) {
#ifdef HAVE_PG_RESULT_MEMORY_SIZE
case PDO_PGSQL_ATTR_RESULT_MEMORY_SIZE:
if(stmt->executed) {
ZVAL_LONG(val, PQresultMemorySize(S->result));
} else {
char *tmp;
spprintf(&tmp, 0, "statement '%s' has not been executed yet", S->stmt_name);
pdo_pgsql_error_stmt_msg(stmt, 0, "HY000", tmp);
efree(tmp);
ZVAL_NULL(val);
}
return 1;
#endif
default:
return 0;
}
}
const struct pdo_stmt_methods pgsql_stmt_methods = {
pgsql_stmt_dtor,
pgsql_stmt_execute,
@ -713,7 +739,7 @@ const struct pdo_stmt_methods pgsql_stmt_methods = {
pgsql_stmt_get_col,
pgsql_stmt_param_hook,
NULL, /* set_attr */
NULL, /* get_attr */
pgsql_stmt_get_attr,
pgsql_stmt_get_column_meta,
NULL, /* next_rowset */
pdo_pgsql_stmt_cursor_closer