Skip to content

Commit 65ff511

Browse files
authored
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.
1 parent aae237a commit 65ff511

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

ext/pgsql/config.m4

+15
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,30 @@ if test "$PHP_PGSQL" != "no"; then
6262
old_LIBS=$LIBS
6363
old_LDFLAGS=$LDFLAGS
6464
LDFLAGS="-L$PGSQL_LIBDIR $LDFLAGS"
65+
old_CFLAGS=$CFLAGS
66+
CFLAGS="$CFLAGS -I$PGSQL_INCLUDE"
6567
AC_CHECK_LIB(pq, PQlibVersion,, AC_MSG_ERROR([Unable to build the PostgreSQL extension: at least libpq 9.1 is required]))
6668
AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibyte]))
6769
AC_CHECK_LIB(pq, lo_truncate64, AC_DEFINE(HAVE_PG_LO64,1,[PostgreSQL 9.3 or later]))
6870
AC_CHECK_LIB(pq, PQsetErrorContextVisibility, AC_DEFINE(HAVE_PG_CONTEXT_VISIBILITY,1,[PostgreSQL 9.6 or later]))
6971
AC_CHECK_LIB(pq, PQresultMemorySize, AC_DEFINE(HAVE_PG_RESULT_MEMORY_SIZE,1,[PostgreSQL 12 or later]))
7072
AC_CHECK_LIB(pq, PQchangePassword, AC_DEFINE(HAVE_PG_CHANGE_PASSWORD,1,[PostgreSQL 17 or later]))
7173
AC_CHECK_LIB(pq, PQsocketPoll, AC_DEFINE(HAVE_PG_SOCKET_POLL,1,[PostgreSQL 17 or later]))
74+
75+
dnl Available since PostgreSQL 12.
76+
AC_CACHE_CHECK([if PGVerbosity enum has PQERRORS_SQLSTATE],
77+
[php_cv_enum_pgverbosity_pqerrors_sqlstate],
78+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <libpq-fe.h>],
79+
[PGVerbosity e = PQERRORS_SQLSTATE; (void)e;])],
80+
[php_cv_enum_pgverbosity_pqerrors_sqlstate=yes],
81+
[php_cv_enum_pgverbosity_pqerrors_sqlstate=no])])
82+
AS_VAR_IF([php_cv_enum_pgverbosity_pqerrors_sqlstate], [yes],
83+
[AC_DEFINE([HAVE_PQERRORS_SQLSTATE], [1],
84+
[Define to 1 if PGVerbosity enum has PQERRORS_SQLSTATE.])])
85+
7286
LIBS=$old_LIBS
7387
LDFLAGS=$old_LDFLAGS
88+
CFLAGS=$old_CFLAGS
7489

7590
PHP_ADD_LIBRARY_WITH_PATH(pq, $PGSQL_LIBDIR, PGSQL_SHARED_LIBADD)
7691
PHP_SUBST(PGSQL_SHARED_LIBADD)

ext/pgsql/pgsql.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ char pgsql_libpq_version[16];
116116
#define PQfreemem free
117117
#endif
118118

119-
#if PG_VERSION_NUM < 120000
119+
#ifndef HAVE_PQERRORS_SQLSTATE
120120
#define PQERRORS_SQLSTATE 0
121121
#endif
122122

ext/pgsql/pgsql.stub.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
* @cvalue PQERRORS_VERBOSE
184184
*/
185185
const PGSQL_ERRORS_VERBOSE = UNKNOWN;
186-
#if PG_VERSION_NUM > 110000
186+
#ifdef HAVE_PQERRORS_SQLSTATE
187187
/**
188188
* @var int
189189
* @cvalue PQERRORS_SQLSTATE

ext/pgsql/pgsql_arginfo.h

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

0 commit comments

Comments
 (0)