Skip to content

Commit ce668c0

Browse files
committed
PGSQL and POD_SQL: don't include pg_config.h
Even if that header file is available, we better consider it private, and don't include it. The information about whether SSL support is enabled is now missing (`USE_(OPEN)SSL`), and it seems there is no alternative way to get it (`PQinitSSL()` is always defined), so we remove it from the PHP info. Furthermore, the `PG_VERSION` and `PG_VERSION_STR` macros are no longer available, but as of libpq 9.1 there is `PQlibVersion()` which allows us to construct `PG_VERSION` in a most likely backwards compatible manner. The additional information available through `PG_VERSION_STR` is lost, though, so we define `PGSQL_LIBPQ_VERSION_STR` basically as alias of `PGSQL_LIBPQ_VERSION`, and deprecate it right away. Since we are now requiring at least libpq 9.1, we can remove some further compatibility code and additional checks. Regarding the raised requirements: official support for PostGreSQL 9.0 ended on 2015-10-08, and even CentOS 7 already has PostGreSQL 9.2, so this is not supposed to be too much of an issue.
1 parent f3efb9e commit ce668c0

File tree

11 files changed

+77
-193
lines changed

11 files changed

+77
-193
lines changed

NEWS

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ PHP NEWS
9696
. Don't ignore invalid escape sequences. (sjon)
9797

9898
- PGSQL:
99-
. Bumped required libpq version to 7.4.
99+
. Bumped required libpq version to 9.1. (cmb)
100100

101101
- PDO:
102102
. Changed default PDO error mode to exceptions. (AllenJB)
@@ -107,6 +107,9 @@ PHP NEWS
107107
. Added support for setting and getting the oracle OCI 18c call timeout.
108108
(camporter)
109109

110+
- PDO_PGSQL:
111+
. Bumped required libpq version to 9.1. (cmb)
112+
110113
- phpdbg:
111114
. Fixed bug #76596 (phpdbg support for display_errors=stderr). (kabel)
112115
. Fixed bug #76801 (too many open files). (alekitto)

UPGRADING

+6-2
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,10 @@ PHP 8.0 UPGRADE NOTES
559559
. enchant_dict_add_to_personal, use enchant_dict_add instead
560560
. enchant_dict_is_in_session, use enchant_dict_is_added instead
561561

562+
- PGSQL / PDO PGSQL:
563+
. The constant PG_VERSION_STR has now the same value as PG_VERSION, and thus
564+
is deprecated.
565+
562566
- Zip:
563567
. Using empty file as ZipArchive is deprecated. Libzip 1.6.0
564568
do not accept empty files as valid zip archives any longer.
@@ -680,8 +684,8 @@ PHP 8.0 UPGRADE NOTES
680684
. When mysqlnd is not used (which is the default and recommended option),
681685
the minimum supported libmysqlclient version is now 5.1.
682686

683-
- PGSQL:
684-
. The PGSQL extension now required at least libpq 7.4.
687+
- PGSQL / PDO PGSQL:
688+
. The PGSQL and PDO PGSQL extensions now require at least libpq 9.1.
685689

686690
========================================
687691
10. New Global Constants

ext/pdo_pgsql/config.m4

+1-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ if test "$PHP_PDO_PGSQL" != "no"; then
2424
AC_MSG_RESULT([$PG_CONFIG])
2525
PGSQL_INCLUDE=`$PG_CONFIG --includedir`
2626
PGSQL_LIBDIR=`$PG_CONFIG --libdir`
27-
AC_DEFINE(HAVE_PG_CONFIG_H,1,[Whether to have pg_config.h])
2827
else
2928
AC_MSG_RESULT(not found)
3029
if test "$PHP_PDO_PGSQL" = "yes"; then
@@ -38,9 +37,6 @@ if test "$PHP_PDO_PGSQL" != "no"; then
3837
if test -r "$i/$j/libpq-fe.h"; then
3938
PGSQL_INC_BASE=$i
4039
PGSQL_INCLUDE=$i/$j
41-
if test -r "$i/$j/pg_config.h"; then
42-
AC_DEFINE(HAVE_PG_CONFIG_H,1,[Whether to have pg_config.h])
43-
fi
4440
fi
4541
done
4642

@@ -70,10 +66,7 @@ if test "$PHP_PDO_PGSQL" != "no"; then
7066
old_LDFLAGS=$LDFLAGS
7167
LDFLAGS="-L$PGSQL_LIBDIR $LDFLAGS"
7268

73-
AC_CHECK_LIB(pq, PQprepare,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
74-
AC_CHECK_LIB(pq, PQexecParams,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
75-
AC_CHECK_LIB(pq, PQescapeStringConn,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
76-
AC_CHECK_LIB(pq, PQescapeByteaConn,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
69+
AC_CHECK_LIB(pq, PQlibVersion,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: at least libpq 9.1 is required]))
7770

7871
LIBS=$old_LIBS
7972
LDFLAGS=$old_LDFLAGS

ext/pdo_pgsql/config.w32

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ if (PHP_PDO_PGSQL != "no") {
77
CHECK_HEADER_ADD_INCLUDE("libpq-fe.h", "CFLAGS_PDO_PGSQL", PHP_PDO_PGSQL + "\\include;" + PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PHP_BUILD + "\\include\\libpq;")) {
88
EXTENSION("pdo_pgsql", "pdo_pgsql.c pgsql_driver.c pgsql_statement.c");
99

10-
if (CHECK_HEADER_ADD_INCLUDE("pg_config.h", "CFLAGS_PDO_PGSQL", PHP_PDO_PGSQL + ";" + PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PHP_BUILD + "\\include\\libpq;")) {
11-
ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PG_CONFIG_H");
12-
}
1310
if (X64) {
1411
ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PG_LO64=1");
1512
}

ext/pdo_pgsql/pdo_pgsql.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
#include "php_pdo_pgsql.h"
2727
#include "php_pdo_pgsql_int.h"
2828

29-
#ifdef HAVE_PG_CONFIG_H
30-
#undef SIZEOF_OFF_T
31-
#include <pg_config.h>
32-
#endif
33-
3429
/* {{{ pdo_pgsql_functions[] */
3530
static const zend_function_entry pdo_pgsql_functions[] = {
3631
PHP_FE_END
@@ -96,11 +91,12 @@ PHP_MSHUTDOWN_FUNCTION(pdo_pgsql)
9691
*/
9792
PHP_MINFO_FUNCTION(pdo_pgsql)
9893
{
94+
char buf[16];
95+
9996
php_info_print_table_start();
10097
php_info_print_table_row(2, "PDO Driver for PostgreSQL", "enabled");
101-
#ifdef HAVE_PG_CONFIG_H
102-
php_info_print_table_row(2, "PostgreSQL(libpq) Version", PG_VERSION);
103-
#endif
98+
pdo_libpq_version(buf, sizeof(buf));
99+
php_info_print_table_row(2, "PostgreSQL(libpq) Version", buf);
104100
php_info_print_table_end();
105101
}
106102
/* }}} */

ext/pdo_pgsql/pgsql_driver.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "pdo/php_pdo_error.h"
3131
#include "ext/standard/file.h"
3232
#undef SIZEOF_OFF_T
33-
#include "pg_config.h" /* needed for PG_VERSION */
3433
#include "php_pdo_pgsql.h"
3534
#include "php_pdo_pgsql_int.h"
3635
#include "zend_exceptions.h"
@@ -377,6 +376,20 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *
377376
return id;
378377
}
379378

379+
void pdo_libpq_version(char *buf, size_t len)
380+
{
381+
int version = PQlibVersion();
382+
int major = version / 10000;
383+
if (major >= 10) {
384+
int minor = version % 10000;
385+
snprintf(buf, len, "%d.%d", major, minor);
386+
} else {
387+
int minor = version / 100 % 100;
388+
int revision = version % 100;
389+
snprintf(buf, len, "%d.%d.%d", major, minor, revision);
390+
}
391+
}
392+
380393
static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value)
381394
{
382395
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
@@ -390,9 +403,12 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_
390403
ZVAL_BOOL(return_value, H->disable_prepares);
391404
break;
392405

393-
case PDO_ATTR_CLIENT_VERSION:
394-
ZVAL_STRING(return_value, PG_VERSION);
406+
case PDO_ATTR_CLIENT_VERSION: {
407+
char buf[16];
408+
pdo_libpq_version(buf, sizeof(buf));
409+
ZVAL_STRING(return_value, buf);
395410
break;
411+
}
396412

397413
case PDO_ATTR_SERVER_VERSION:
398414
if (PQprotocolVersion(H->server) >= 3) { /* PostgreSQL 7.4 or later */
@@ -458,8 +474,8 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_
458474
(char*)PQparameterStatus(H->server, "DateStyle"));
459475

460476
ZVAL_STR(return_value, str_info);
461-
}
462477
break;
478+
}
463479

464480
default:
465481
return 0;

ext/pdo_pgsql/php_pdo_pgsql_int.h

+2
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,6 @@ enum pdo_pgsql_specific_constants {
107107
php_stream *pdo_pgsql_create_lob_stream(zval *pdh, int lfd, Oid oid);
108108
extern const php_stream_ops pdo_pgsql_lob_stream_ops;
109109

110+
void pdo_libpq_version(char *buf, size_t len);
111+
110112
#endif /* PHP_PDO_PGSQL_INT_H */

ext/pgsql/config.m4

+1-13
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ if test "$PHP_PGSQL" != "no"; then
2222
AC_MSG_RESULT([$PG_CONFIG])
2323
PGSQL_INCLUDE=`$PG_CONFIG --includedir`
2424
PGSQL_LIBDIR=`$PG_CONFIG --libdir`
25-
if test -r "$PGSQL_INCLUDE/pg_config.h"; then
26-
AC_DEFINE(HAVE_PG_CONFIG_H,1,[Whether to have pg_config.h])
27-
fi
2825
else
2926
AC_MSG_RESULT(not found)
3027
if test "$PHP_PGSQL" = "yes"; then
@@ -38,9 +35,6 @@ if test "$PHP_PGSQL" != "no"; then
3835
if test -r "$i/$j/libpq-fe.h"; then
3936
PGSQL_INC_BASE=$i
4037
PGSQL_INCLUDE=$i/$j
41-
if test -r "$i/$j/pg_config.h"; then
42-
AC_DEFINE(HAVE_PG_CONFIG_H,1,[Whether to have pg_config.h])
43-
fi
4438
fi
4539
done
4640

@@ -68,15 +62,9 @@ if test "$PHP_PGSQL" != "no"; then
6862
old_LIBS=$LIBS
6963
old_LDFLAGS=$LDFLAGS
7064
LDFLAGS="-L$PGSQL_LIBDIR $LDFLAGS"
71-
AC_CHECK_LIB(pq, PQprepare,, AC_MSG_ERROR([Unable to build the PostgreSQL extension: at least libpq 7.4 is required]))
72-
AC_CHECK_LIB(pq, PQescapeStringConn, AC_DEFINE(HAVE_PQESCAPE_CONN,1,[PostgreSQL 8.1.4 or later]))
73-
AC_CHECK_LIB(pq, PQescapeByteaConn, AC_DEFINE(HAVE_PQESCAPE_BYTEA_CONN,1,[PostgreSQL 8.1.4 or later]))
65+
AC_CHECK_LIB(pq, PQlibVersion,, AC_MSG_ERROR([Unable to build the PostgreSQL extension: at least libpq 9.1 is required]))
7466
AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibyte]))
75-
AC_CHECK_LIB(pq, lo_create, AC_DEFINE(HAVE_PG_LO_CREATE,1,[PostgreSQL 8.1 or later]))
76-
AC_CHECK_LIB(pq, lo_import_with_oid, AC_DEFINE(HAVE_PG_LO_IMPORT_WITH_OID,1,[PostgreSQL 8.4 or later]))
77-
AC_CHECK_LIB(pq, lo_truncate, AC_DEFINE(HAVE_PG_LO_TRUNCATE,1,[PostgreSQL 8.3 or later]))
7867
AC_CHECK_LIB(pq, lo_truncate64, AC_DEFINE(HAVE_PG_LO64,1,[PostgreSQL 9.3 or later]))
79-
AC_CHECK_LIB(pq, PQescapeLiteral, AC_DEFINE(HAVE_PQESCAPELITERAL,1,[PostgreSQL 9.0 or later]))
8068
LIBS=$old_LIBS
8169
LDFLAGS=$old_LDFLAGS
8270

ext/pgsql/config.w32

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (PHP_PGSQL != "no") {
77
CHECK_HEADER_ADD_INCLUDE("libpq-fe.h", "CFLAGS_PGSQL", PHP_PGSQL + "\\include;" + PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PHP_BUILD + "\\include\\libpq;" + PHP_PGSQL)) {
88
EXTENSION("pgsql", "pgsql.c", PHP_PGSQL_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
99
AC_DEFINE('HAVE_PGSQL', 1, 'Have PostgreSQL library');
10-
ADD_FLAG("CFLAGS_PGSQL", "/D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS /D HAVE_PQESCAPE_CONN /D HAVE_PQESCAPE_BYTEA_CONN /D HAVE_PQFREEMEM /D HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT /D HAVE_PG_LO_CREATE /D HAVE_PG_LO_IMPORT_WITH_OID /D HAVE_PG_LO_TRUNCATE" + (X64 ? " /D HAVE_PG_LO64" : "") + " /D HAVE_PQESCAPELITERAL");
10+
ADD_FLAG("CFLAGS_PGSQL", "/D PGSQL_EXPORTS /D HAVE_PQFREEMEM /D HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT" + (X64 ? " /D HAVE_PG_LO64" : "") + " ");
1111
} else {
1212
WARNING("pgsql not enabled; libraries and headers not found");
1313
}

0 commit comments

Comments
 (0)