Skip to content

Commit 21aaf33

Browse files
committed
check PQsetErrorContextVisibility availability (libpq >= 9.6)
1 parent fe6263e commit 21aaf33

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

UPGRADING

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ PHP 8.3 UPGRADE NOTES
219219
. Added posix_eaccess call to check the effective user id's permission for a path.
220220

221221
- PGSQL:
222-
. Added pg_set_error_context_visilibity to set the visibility of the context in error messages.
222+
. Added pg_set_error_context_visilibity to set the visibility of the context
223+
in error messages (with libpq >= 9.6).
223224

224225
- Random:
225226
. Added Randomizer::getBytesFromString().

ext/pgsql/config.m4

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ if test "$PHP_PGSQL" != "no"; then
6565
AC_CHECK_LIB(pq, PQlibVersion,, AC_MSG_ERROR([Unable to build the PostgreSQL extension: at least libpq 9.1 is required]))
6666
AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibyte]))
6767
AC_CHECK_LIB(pq, lo_truncate64, AC_DEFINE(HAVE_PG_LO64,1,[PostgreSQL 9.3 or later]))
68+
AC_CHECK_LIB(pq, PQsetErrorContextVisibility, AC_DEFINE(HAVE_PG_CONTEXT_VISIBILITY,1,[PostgreSQL 9.6 or later]))
6869
LIBS=$old_LIBS
6970
LDFLAGS=$old_LDFLAGS
7071

ext/pgsql/pgsql.c

+2
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,7 @@ PHP_FUNCTION(pg_set_error_verbosity)
28342834
}
28352835
/* }}} */
28362836

2837+
#ifdef HAVE_PG_CONTEXT_VISIBILITY
28372838
PHP_FUNCTION(pg_set_error_context_visibility)
28382839
{
28392840
zval *pgsql_link = NULL;
@@ -2856,6 +2857,7 @@ PHP_FUNCTION(pg_set_error_context_visibility)
28562857
RETURN_THROWS();
28572858
}
28582859
}
2860+
#endif
28592861

28602862
/* {{{ Set client encoding */
28612863
PHP_FUNCTION(pg_set_client_encoding)

ext/pgsql/pgsql.stub.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@
463463
const PGSQL_PIPELINE_ABORTED = UNKNOWN;
464464
#endif
465465

466+
#ifdef HAVE_PG_CONTEXT_VISIBILITY
466467
/* For pg_set_error_context_visibility() */
467468

468469
/**
@@ -480,7 +481,7 @@
480481
* @cvalue PQSHOW_CONTEXT_ALWAYS
481482
*/
482483
const PGSQL_SHOW_CONTEXT_ALWAYS = UNKNOWN;
483-
484+
#endif
484485

485486
function pg_connect(string $connection_string, int $flags = 0): PgSql\Connection|false {}
486487

@@ -971,7 +972,9 @@ function pg_pipeline_sync(PgSql\Connection $connection): bool {}
971972
function pg_pipeline_status(PgSql\Connection $connection): int {}
972973
#endif
973974

975+
#ifdef HAVE_PG_CONTEXT_VISIBILITY
974976
function pg_set_error_context_visibility(PgSql\Connection $connection, int $visibility): int {}
977+
#endif
975978
}
976979

977980
namespace PgSql {

ext/pgsql/pgsql_arginfo.h

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/pgsql/tests/07optional.phpt

+5-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ if (function_exists('pg_set_error_verbosity')) {
2121
pg_set_error_verbosity($db, PGSQL_ERRORS_VERBOSE);
2222
pg_set_error_verbosity($db, PGSQL_ERRORS_SQLSTATE);
2323
}
24-
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_NEVER);
25-
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ERRORS);
26-
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ALWAYS);
24+
if (function_exists('pg_set_error_context_visibility')) {
25+
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_NEVER);
26+
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ERRORS);
27+
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ALWAYS);
28+
}
2729
echo "OK";
2830
?>
2931
--EXPECT--

0 commit comments

Comments
 (0)