Commit c56e8caaed7 for php.net
commit c56e8caaed776cc98bba0276c9cc4035a279ef7e
Author: KentarouTakeda <4785040+KentarouTakeda@users.noreply.github.com>
Date: Sun Mar 8 14:42:50 2026 +0900
ext/pgsql, ext/pdo_pgsql: Remove preprocessor guards for symbols predating libpq 10 (#21384)
While working on php/doc-en#5409 to clean up outdated PostgreSQL
version notes in the documentation, I noticed that the source code
also retains #ifdef guards for symbols guaranteed to exist in
libpq >= 10.0 (the minimum enforced in build/php.m4 via
PQencryptPasswordConn).
Removed guards (all confirmed in PostgreSQL 10 documentation):
- `PG_DIAG_{INTERNAL_POSITION,INTERNAL_QUERY}`: libpq 8.0+
- `PG_DIAG_{SCHEMA,TABLE,COLUMN,DATATYPE,CONSTRAINT}_NAME`: libpq 9.3+
- `PG_DIAG_SEVERITY_NONLOCALIZED`: libpq 9.6+
- `CONNECTION_SSL_STARTUP`: libpq 8.0+
- `CONNECTION_CONSUME`: libpq 10.0+
Refs:
- https://www.postgresql.org/docs/10/libpq-exec.html#LIBPQ-PQRESULTERRORFIELD
- https://www.postgresql.org/docs/10/libpq-connect.html#LIBPQ-PQCONNECTSTARTPARAMS
- https://github.com/php/php-src/blob/53e31d58834ef04375dae7bdc549d73dae371c5a/build/php.m4#L1927
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index ddc63f01059..be429075c51 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -505,20 +505,16 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_
case CONNECTION_AUTH_OK:
ZVAL_STRINGL(return_value, "Received authentication; waiting for backend start-up to finish.", strlen("Received authentication; waiting for backend start-up to finish."));
break;
-#ifdef CONNECTION_SSL_STARTUP
case CONNECTION_SSL_STARTUP:
ZVAL_STRINGL(return_value, "Negotiating SSL encryption.", strlen("Negotiating SSL encryption."));
break;
-#endif
case CONNECTION_SETENV:
ZVAL_STRINGL(return_value, "Negotiating environment-driven parameter settings.", strlen("Negotiating environment-driven parameter settings."));
break;
-#ifdef CONNECTION_CONSUME
case CONNECTION_CONSUME:
ZVAL_STRINGL(return_value, "Flushing send queue/consuming extra data.", strlen("Flushing send queue/consuming extra data."));
break;
-#endif
#ifdef CONNECTION_GSS_STARTUP
case CONNECTION_GSS_STARTUP:
ZVAL_STRINGL(return_value, "Negotiating GSSAPI.", strlen("Negotiating GSSAPI."));
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 03b02952355..8cd812eb084 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -3790,12 +3790,8 @@ PHP_FUNCTION(pg_result_error_field)
if (fieldcode & (PG_DIAG_SEVERITY|PG_DIAG_SQLSTATE|PG_DIAG_MESSAGE_PRIMARY|PG_DIAG_MESSAGE_DETAIL
|PG_DIAG_MESSAGE_HINT|PG_DIAG_STATEMENT_POSITION
-#ifdef PG_DIAG_INTERNAL_POSITION
|PG_DIAG_INTERNAL_POSITION
-#endif
-#ifdef PG_DIAG_INTERNAL_QUERY
|PG_DIAG_INTERNAL_QUERY
-#endif
|PG_DIAG_CONTEXT|PG_DIAG_SOURCE_FILE|PG_DIAG_SOURCE_LINE
|PG_DIAG_SOURCE_FUNCTION)) {
field = PQresultErrorField(pgsql_result, (int)fieldcode);
diff --git a/ext/pgsql/pgsql.stub.php b/ext/pgsql/pgsql.stub.php
index f379d115f6d..0ce1c7d922d 100644
--- a/ext/pgsql/pgsql.stub.php
+++ b/ext/pgsql/pgsql.stub.php
@@ -98,13 +98,11 @@
* @cvalue CONNECTION_AUTH_OK
*/
const PGSQL_CONNECTION_AUTH_OK = UNKNOWN;
-#ifdef CONNECTION_SSL_STARTUP
/**
* @var int
* @cvalue CONNECTION_SSL_STARTUP
*/
const PGSQL_CONNECTION_SSL_STARTUP = UNKNOWN;
-#endif
/**
* @var int
* @cvalue CONNECTION_SETENV
@@ -310,20 +308,16 @@
* @cvalue PG_DIAG_STATEMENT_POSITION
*/
const PGSQL_DIAG_STATEMENT_POSITION = UNKNOWN;
-#ifdef PG_DIAG_INTERNAL_POSITION
/**
* @var int
* @cvalue PG_DIAG_INTERNAL_POSITION
*/
const PGSQL_DIAG_INTERNAL_POSITION = UNKNOWN;
-#endif
-#ifdef PG_DIAG_INTERNAL_QUERY
/**
* @var int
* @cvalue PG_DIAG_INTERNAL_QUERY
*/
const PGSQL_DIAG_INTERNAL_QUERY = UNKNOWN;
-#endif
/**
* @var int
* @cvalue PG_DIAG_CONTEXT
@@ -344,48 +338,36 @@
* @cvalue PG_DIAG_SOURCE_FUNCTION
*/
const PGSQL_DIAG_SOURCE_FUNCTION = UNKNOWN;
-#ifdef PG_DIAG_SCHEMA_NAME
/**
* @var int
* @cvalue PG_DIAG_SCHEMA_NAME
*/
const PGSQL_DIAG_SCHEMA_NAME = UNKNOWN;
-#endif
-#ifdef PG_DIAG_TABLE_NAME
/**
* @var int
* @cvalue PG_DIAG_TABLE_NAME
*/
const PGSQL_DIAG_TABLE_NAME = UNKNOWN;
-#endif
-#ifdef PG_DIAG_COLUMN_NAME
/**
* @var int
* @cvalue PG_DIAG_COLUMN_NAME
*/
const PGSQL_DIAG_COLUMN_NAME = UNKNOWN;
-#endif
-#ifdef PG_DIAG_DATATYPE_NAME
/**
* @var int
* @cvalue PG_DIAG_DATATYPE_NAME
*/
const PGSQL_DIAG_DATATYPE_NAME = UNKNOWN;
-#endif
-#ifdef PG_DIAG_CONSTRAINT_NAME
/**
* @var int
* @cvalue PG_DIAG_CONSTRAINT_NAME
*/
const PGSQL_DIAG_CONSTRAINT_NAME = UNKNOWN;
-#endif
-#ifdef PG_DIAG_SEVERITY_NONLOCALIZED
/**
* @var int
* @cvalue PG_DIAG_SEVERITY_NONLOCALIZED
*/
const PGSQL_DIAG_SEVERITY_NONLOCALIZED = UNKNOWN;
-#endif
/* pg_convert options */
diff --git a/ext/pgsql/pgsql_arginfo.h b/ext/pgsql/pgsql_arginfo.h
index 0c49bcc7cfa..c9335741eb5 100644
Binary files a/ext/pgsql/pgsql_arginfo.h and b/ext/pgsql/pgsql_arginfo.h differ
diff --git a/ext/pgsql/tests/03sync_query.phpt b/ext/pgsql/tests/03sync_query.phpt
index 36b1230f5f8..3ecee338d22 100644
--- a/ext/pgsql/tests/03sync_query.phpt
+++ b/ext/pgsql/tests/03sync_query.phpt
@@ -70,14 +70,8 @@
pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL);
pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT);
pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION);
-if (defined('PGSQL_DIAG_INTERNAL_POSITION'))
-{
- pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION);
-}
-if (defined('PGSQL_DIAG_INTERNAL_QUERY'))
-{
- pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY);
-}
+pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION);
+pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY);
pg_result_error_field($result, PGSQL_DIAG_CONTEXT);
pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE);
pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE);