summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-05-25 09:00:32 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-05-25 10:48:35 +0200
commitce668c0ec6393456be4ce77eabaa4692285d95e5 (patch)
tree75e3f417c58c78a9f64eaedc7fbd09975d4840d9 /ext/pdo_pgsql
parentf3efb9e3fb30fa307e0913e888fb2859cec8209a (diff)
downloadphp-git-ce668c0ec6393456be4ce77eabaa4692285d95e5.tar.gz
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.
Diffstat (limited to 'ext/pdo_pgsql')
-rw-r--r--ext/pdo_pgsql/config.m49
-rw-r--r--ext/pdo_pgsql/config.w323
-rw-r--r--ext/pdo_pgsql/pdo_pgsql.c12
-rw-r--r--ext/pdo_pgsql/pgsql_driver.c24
-rw-r--r--ext/pdo_pgsql/php_pdo_pgsql_int.h2
5 files changed, 27 insertions, 23 deletions
diff --git a/ext/pdo_pgsql/config.m4 b/ext/pdo_pgsql/config.m4
index 7655357de4..80ffd97ac2 100644
--- a/ext/pdo_pgsql/config.m4
+++ b/ext/pdo_pgsql/config.m4
@@ -24,7 +24,6 @@ if test "$PHP_PDO_PGSQL" != "no"; then
AC_MSG_RESULT([$PG_CONFIG])
PGSQL_INCLUDE=`$PG_CONFIG --includedir`
PGSQL_LIBDIR=`$PG_CONFIG --libdir`
- AC_DEFINE(HAVE_PG_CONFIG_H,1,[Whether to have pg_config.h])
else
AC_MSG_RESULT(not found)
if test "$PHP_PDO_PGSQL" = "yes"; then
@@ -38,9 +37,6 @@ if test "$PHP_PDO_PGSQL" != "no"; then
if test -r "$i/$j/libpq-fe.h"; then
PGSQL_INC_BASE=$i
PGSQL_INCLUDE=$i/$j
- if test -r "$i/$j/pg_config.h"; then
- AC_DEFINE(HAVE_PG_CONFIG_H,1,[Whether to have pg_config.h])
- fi
fi
done
@@ -70,10 +66,7 @@ if test "$PHP_PDO_PGSQL" != "no"; then
old_LDFLAGS=$LDFLAGS
LDFLAGS="-L$PGSQL_LIBDIR $LDFLAGS"
- AC_CHECK_LIB(pq, PQprepare,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
- AC_CHECK_LIB(pq, PQexecParams,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
- AC_CHECK_LIB(pq, PQescapeStringConn,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
- AC_CHECK_LIB(pq, PQescapeByteaConn,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
+ AC_CHECK_LIB(pq, PQlibVersion,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: at least libpq 9.1 is required]))
LIBS=$old_LIBS
LDFLAGS=$old_LDFLAGS
diff --git a/ext/pdo_pgsql/config.w32 b/ext/pdo_pgsql/config.w32
index 12ba8b7a07..cda62a64db 100644
--- a/ext/pdo_pgsql/config.w32
+++ b/ext/pdo_pgsql/config.w32
@@ -7,9 +7,6 @@ if (PHP_PDO_PGSQL != "no") {
CHECK_HEADER_ADD_INCLUDE("libpq-fe.h", "CFLAGS_PDO_PGSQL", PHP_PDO_PGSQL + "\\include;" + PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PHP_BUILD + "\\include\\libpq;")) {
EXTENSION("pdo_pgsql", "pdo_pgsql.c pgsql_driver.c pgsql_statement.c");
- if (CHECK_HEADER_ADD_INCLUDE("pg_config.h", "CFLAGS_PDO_PGSQL", PHP_PDO_PGSQL + ";" + PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PHP_BUILD + "\\include\\libpq;")) {
- ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PG_CONFIG_H");
- }
if (X64) {
ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PG_LO64=1");
}
diff --git a/ext/pdo_pgsql/pdo_pgsql.c b/ext/pdo_pgsql/pdo_pgsql.c
index 815d1ceb88..047329d3cb 100644
--- a/ext/pdo_pgsql/pdo_pgsql.c
+++ b/ext/pdo_pgsql/pdo_pgsql.c
@@ -26,11 +26,6 @@
#include "php_pdo_pgsql.h"
#include "php_pdo_pgsql_int.h"
-#ifdef HAVE_PG_CONFIG_H
-#undef SIZEOF_OFF_T
-#include <pg_config.h>
-#endif
-
/* {{{ pdo_pgsql_functions[] */
static const zend_function_entry pdo_pgsql_functions[] = {
PHP_FE_END
@@ -96,11 +91,12 @@ PHP_MSHUTDOWN_FUNCTION(pdo_pgsql)
*/
PHP_MINFO_FUNCTION(pdo_pgsql)
{
+ char buf[16];
+
php_info_print_table_start();
php_info_print_table_row(2, "PDO Driver for PostgreSQL", "enabled");
-#ifdef HAVE_PG_CONFIG_H
- php_info_print_table_row(2, "PostgreSQL(libpq) Version", PG_VERSION);
-#endif
+ pdo_libpq_version(buf, sizeof(buf));
+ php_info_print_table_row(2, "PostgreSQL(libpq) Version", buf);
php_info_print_table_end();
}
/* }}} */
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index 685a64e451..31d1bf59f7 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -30,7 +30,6 @@
#include "pdo/php_pdo_error.h"
#include "ext/standard/file.h"
#undef SIZEOF_OFF_T
-#include "pg_config.h" /* needed for PG_VERSION */
#include "php_pdo_pgsql.h"
#include "php_pdo_pgsql_int.h"
#include "zend_exceptions.h"
@@ -377,6 +376,20 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *
return id;
}
+void pdo_libpq_version(char *buf, size_t len)
+{
+ int version = PQlibVersion();
+ int major = version / 10000;
+ if (major >= 10) {
+ int minor = version % 10000;
+ snprintf(buf, len, "%d.%d", major, minor);
+ } else {
+ int minor = version / 100 % 100;
+ int revision = version % 100;
+ snprintf(buf, len, "%d.%d.%d", major, minor, revision);
+ }
+}
+
static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_value)
{
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_
ZVAL_BOOL(return_value, H->disable_prepares);
break;
- case PDO_ATTR_CLIENT_VERSION:
- ZVAL_STRING(return_value, PG_VERSION);
+ case PDO_ATTR_CLIENT_VERSION: {
+ char buf[16];
+ pdo_libpq_version(buf, sizeof(buf));
+ ZVAL_STRING(return_value, buf);
break;
+ }
case PDO_ATTR_SERVER_VERSION:
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_
(char*)PQparameterStatus(H->server, "DateStyle"));
ZVAL_STR(return_value, str_info);
- }
break;
+ }
default:
return 0;
diff --git a/ext/pdo_pgsql/php_pdo_pgsql_int.h b/ext/pdo_pgsql/php_pdo_pgsql_int.h
index 5d80e32205..07dfa8ce27 100644
--- a/ext/pdo_pgsql/php_pdo_pgsql_int.h
+++ b/ext/pdo_pgsql/php_pdo_pgsql_int.h
@@ -107,4 +107,6 @@ enum pdo_pgsql_specific_constants {
php_stream *pdo_pgsql_create_lob_stream(zval *pdh, int lfd, Oid oid);
extern const php_stream_ops pdo_pgsql_lob_stream_ops;
+void pdo_libpq_version(char *buf, size_t len);
+
#endif /* PHP_PDO_PGSQL_INT_H */