Skip to content

check PQsetErrorContextVisibility availability (libpq >= 9.6) #11495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ PHP 8.3 UPGRADE NOTES
. Added posix_eaccess call to check the effective user id's permission for a path.

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

- Random:
. Added Randomizer::getBytesFromString().
Expand Down
1 change: 1 addition & 0 deletions ext/pgsql/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ if test "$PHP_PGSQL" != "no"; then
AC_CHECK_LIB(pq, PQlibVersion,, AC_MSG_ERROR([Unable to build the PostgreSQL extension: at least libpq 9.1 is required]))
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]))
LIBS=$old_LIBS
LDFLAGS=$old_LDFLAGS

Expand Down
2 changes: 2 additions & 0 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,7 @@ PHP_FUNCTION(pg_set_error_verbosity)
}
/* }}} */

#ifdef HAVE_PG_CONTEXT_VISIBILITY
PHP_FUNCTION(pg_set_error_context_visibility)
{
zval *pgsql_link = NULL;
Expand All @@ -2856,6 +2857,7 @@ PHP_FUNCTION(pg_set_error_context_visibility)
RETURN_THROWS();
}
}
#endif

/* {{{ Set client encoding */
PHP_FUNCTION(pg_set_client_encoding)
Expand Down
5 changes: 4 additions & 1 deletion ext/pgsql/pgsql.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
const PGSQL_PIPELINE_ABORTED = UNKNOWN;
#endif

#ifdef HAVE_PG_CONTEXT_VISIBILITY
/* For pg_set_error_context_visibility() */

/**
Expand All @@ -480,7 +481,7 @@
* @cvalue PQSHOW_CONTEXT_ALWAYS
*/
const PGSQL_SHOW_CONTEXT_ALWAYS = UNKNOWN;
#endif

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

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

#ifdef HAVE_PG_CONTEXT_VISIBILITY
function pg_set_error_context_visibility(PgSql\Connection $connection, int $visibility): int {}
#endif
}

namespace PgSql {
Expand Down
14 changes: 13 additions & 1 deletion ext/pgsql/pgsql_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions ext/pgsql/tests/07optional.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ if (function_exists('pg_set_error_verbosity')) {
pg_set_error_verbosity($db, PGSQL_ERRORS_VERBOSE);
pg_set_error_verbosity($db, PGSQL_ERRORS_SQLSTATE);
}
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_NEVER);
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ERRORS);
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ALWAYS);
if (function_exists('pg_set_error_context_visibility')) {
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_NEVER);
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ERRORS);
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ALWAYS);
}
echo "OK";
?>
--EXPECT--
Expand Down