mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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:
parent
ba534e70e6
commit
b7dd3d8347
9 changed files with 96 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue