1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Check for PQERRORS_SQLSTATE in PGVerbosity enum (#14519)

The PG_VERSION_NUM is not available in intended public PostgreSQL
headers unless the pg_config.h is included or the PostgreSQL server
development headers are installed separately. This instead resorts to
checking for the PGVerbosity enum value. The PQERRORS_SQLSTATE was added
to PostgreSQL 12.0. At the time of writing, on Windows, PostgreSQL is at 11.4 so
it is not defined there yet.
This commit is contained in:
Peter Kokot
2024-06-09 11:47:06 +02:00
committed by GitHub
parent aae237aad5
commit 65ff5117ab
4 changed files with 20 additions and 5 deletions

View File

@@ -62,6 +62,8 @@ if test "$PHP_PGSQL" != "no"; then
old_LIBS=$LIBS
old_LDFLAGS=$LDFLAGS
LDFLAGS="-L$PGSQL_LIBDIR $LDFLAGS"
old_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -I$PGSQL_INCLUDE"
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]))
@@ -69,8 +71,21 @@ if test "$PHP_PGSQL" != "no"; then
AC_CHECK_LIB(pq, PQresultMemorySize, AC_DEFINE(HAVE_PG_RESULT_MEMORY_SIZE,1,[PostgreSQL 12 or later]))
AC_CHECK_LIB(pq, PQchangePassword, AC_DEFINE(HAVE_PG_CHANGE_PASSWORD,1,[PostgreSQL 17 or later]))
AC_CHECK_LIB(pq, PQsocketPoll, AC_DEFINE(HAVE_PG_SOCKET_POLL,1,[PostgreSQL 17 or later]))
dnl Available since PostgreSQL 12.
AC_CACHE_CHECK([if PGVerbosity enum has PQERRORS_SQLSTATE],
[php_cv_enum_pgverbosity_pqerrors_sqlstate],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <libpq-fe.h>],
[PGVerbosity e = PQERRORS_SQLSTATE; (void)e;])],
[php_cv_enum_pgverbosity_pqerrors_sqlstate=yes],
[php_cv_enum_pgverbosity_pqerrors_sqlstate=no])])
AS_VAR_IF([php_cv_enum_pgverbosity_pqerrors_sqlstate], [yes],
[AC_DEFINE([HAVE_PQERRORS_SQLSTATE], [1],
[Define to 1 if PGVerbosity enum has PQERRORS_SQLSTATE.])])
LIBS=$old_LIBS
LDFLAGS=$old_LDFLAGS
CFLAGS=$old_CFLAGS
PHP_ADD_LIBRARY_WITH_PATH(pq, $PGSQL_LIBDIR, PGSQL_SHARED_LIBADD)
PHP_SUBST(PGSQL_SHARED_LIBADD)

View File

@@ -116,7 +116,7 @@ char pgsql_libpq_version[16];
#define PQfreemem free
#endif
#if PG_VERSION_NUM < 120000
#ifndef HAVE_PQERRORS_SQLSTATE
#define PQERRORS_SQLSTATE 0
#endif

View File

@@ -183,7 +183,7 @@ namespace {
* @cvalue PQERRORS_VERBOSE
*/
const PGSQL_ERRORS_VERBOSE = UNKNOWN;
#if PG_VERSION_NUM > 110000
#ifdef HAVE_PQERRORS_SQLSTATE
/**
* @var int
* @cvalue PQERRORS_SQLSTATE

View File

@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 0ea640eeff569a01b335eb1ab4ae3bc90598c5e2 */
* Stub hash: 464db6ede26d59885bec20e40346702f84c3e515 */
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)
@@ -765,10 +765,10 @@ static void register_pgsql_symbols(int module_number)
REGISTER_LONG_CONSTANT("PGSQL_ERRORS_TERSE", PQERRORS_TERSE, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PGSQL_ERRORS_DEFAULT", PQERRORS_DEFAULT, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PGSQL_ERRORS_VERBOSE", PQERRORS_VERBOSE, CONST_PERSISTENT);
#if PG_VERSION_NUM > 110000
#if defined(HAVE_PQERRORS_SQLSTATE)
REGISTER_LONG_CONSTANT("PGSQL_ERRORS_SQLSTATE", PQERRORS_SQLSTATE, CONST_PERSISTENT);
#endif
#if !(PG_VERSION_NUM > 110000)
#if !(defined(HAVE_PQERRORS_SQLSTATE))
REGISTER_LONG_CONSTANT("PGSQL_ERRORS_SQLSTATE", PQERRORS_TERSE, CONST_PERSISTENT);
#endif
REGISTER_LONG_CONSTANT("PGSQL_SEEK_SET", SEEK_SET, CONST_PERSISTENT);