From dfa6626e31b3b710f855bc5bfdb39619c3e8a145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 12 May 2024 04:33:22 +0000 Subject: [PATCH] ext/pgsql: add `pg_result_memory_size` --- UPGRADING | 1 + ext/pgsql/config.m4 | 1 + ext/pgsql/pgsql.c | 17 +++++++++++++ ext/pgsql/pgsql.stub.php | 4 +++ ext/pgsql/pgsql_arginfo.h | 14 ++++++++++- ext/pgsql/tests/pg_result_memory_size.phpt | 29 ++++++++++++++++++++++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 ext/pgsql/tests/pg_result_memory_size.phpt diff --git a/UPGRADING b/UPGRADING index 0afe7cd2269f..d2b21942d7a3 100644 --- a/UPGRADING +++ b/UPGRADING @@ -339,6 +339,7 @@ PHP 8.4 UPGRADE NOTES 3-parameter signature with a null $row parameter instead. . Calling pg_field_is_null() with 2 arguments is deprecated. Use the 3-parameter signature with a null $row parameter instead. + . Added pg_result_memory_size to get the visibility the memory used by a query result. - Reflection: . Calling ReflectionMethod::__construct() with 1 argument is deprecated. diff --git a/ext/pgsql/config.m4 b/ext/pgsql/config.m4 index 606047ac6769..b4d1fec22d38 100644 --- a/ext/pgsql/config.m4 +++ b/ext/pgsql/config.m4 @@ -66,6 +66,7 @@ if test "$PHP_PGSQL" != "no"; then AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibyte])) AC_CHECK_LIB(pq, lo_truncate64, AC_DEFINE(HAVE_PG_LO64,1,[PostgreSQL 9.3 or later])) AC_CHECK_LIB(pq, PQsetErrorContextVisibility, AC_DEFINE(HAVE_PG_CONTEXT_VISIBILITY,1,[PostgreSQL 9.6 or later])) + AC_CHECK_LIB(pq, PQresultMemorySize, AC_DEFINE(HAVE_PG_RESULT_MEMORY_SIZE,1,[PostgreSQL 12 or later])) LIBS=$old_LIBS LDFLAGS=$old_LDFLAGS diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index fdf096d8107f..004752825205 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2911,6 +2911,23 @@ PHP_FUNCTION(pg_set_error_context_visibility) } #endif +#ifdef HAVE_PG_RESULT_MEMORY_SIZE +PHP_FUNCTION(pg_result_memory_size) +{ + zval *result; + pgsql_result_handle *pg_result; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &result, pgsql_result_ce) == FAILURE) { + RETURN_THROWS(); + } + + pg_result = Z_PGSQL_RESULT_P(result); + CHECK_PGSQL_RESULT(pg_result); + + RETURN_LONG(PQresultMemorySize(pg_result->result)); +} +#endif + /* {{{ Set client encoding */ PHP_FUNCTION(pg_set_client_encoding) { diff --git a/ext/pgsql/pgsql.stub.php b/ext/pgsql/pgsql.stub.php index b706959d8943..db4ee6b7bab5 100644 --- a/ext/pgsql/pgsql.stub.php +++ b/ext/pgsql/pgsql.stub.php @@ -943,6 +943,10 @@ function pg_select(PgSql\Connection $connection, string $table_name, array $cond #ifdef HAVE_PG_CONTEXT_VISIBILITY function pg_set_error_context_visibility(PgSql\Connection $connection, int $visibility): int {} #endif + +#ifdef HAVE_PG_RESULT_MEMORY_SIZE + function pg_result_memory_size(PgSql\Result $result): int {} +#endif } namespace PgSql { diff --git a/ext/pgsql/pgsql_arginfo.h b/ext/pgsql/pgsql_arginfo.h index 169f0eff67bb..9d4c036baca4 100644 --- a/ext/pgsql/pgsql_arginfo.h +++ b/ext/pgsql/pgsql_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: a37b9df0c3b172d1160b1a7ef953cbd5a0a811b6 */ + * Stub hash: e06a7116c1048975cbb348ffcdb36c9b65cee659 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_connect, 0, 1, PgSql\\Connection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0) @@ -459,6 +459,12 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_set_error_context_visibility, ZEND_END_ARG_INFO() #endif +#if defined(HAVE_PG_RESULT_MEMORY_SIZE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_result_memory_size, 0, 1, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, result, PgSql\\Result, 0) +ZEND_END_ARG_INFO() +#endif + ZEND_FUNCTION(pg_connect); ZEND_FUNCTION(pg_pconnect); ZEND_FUNCTION(pg_connect_poll); @@ -553,6 +559,9 @@ ZEND_FUNCTION(pg_select); #if defined(HAVE_PG_CONTEXT_VISIBILITY) ZEND_FUNCTION(pg_set_error_context_visibility); #endif +#if defined(HAVE_PG_RESULT_MEMORY_SIZE) +ZEND_FUNCTION(pg_result_memory_size); +#endif static const zend_function_entry ext_functions[] = { ZEND_FE(pg_connect, arginfo_pg_connect) @@ -671,6 +680,9 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(pg_select, arginfo_pg_select) #if defined(HAVE_PG_CONTEXT_VISIBILITY) ZEND_FE(pg_set_error_context_visibility, arginfo_pg_set_error_context_visibility) +#endif +#if defined(HAVE_PG_RESULT_MEMORY_SIZE) + ZEND_FE(pg_result_memory_size, arginfo_pg_result_memory_size) #endif ZEND_FE_END }; diff --git a/ext/pgsql/tests/pg_result_memory_size.phpt b/ext/pgsql/tests/pg_result_memory_size.phpt new file mode 100644 index 000000000000..33369a778815 --- /dev/null +++ b/ext/pgsql/tests/pg_result_memory_size.phpt @@ -0,0 +1,29 @@ +--TEST-- +pg_result_memory_size +--EXTENSIONS-- +pgsql +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +int(%d) +int(%d) +bool(true)