729 Commits
Author SHA1 Message Date
Jayant Chaudhary f2a6e29267 [skip ci] Fix typos in ext/pdo_pgsql comments
Closes GH-24550
2026-10-22 21:02:55 +02:00
dev-null-undefined b91ea8889c Fix GH-24490: pdo_pgsql prepare() hangs on a query containing a NUL byte
No rule in the scanner matches a NUL byte, so what re2c does with one
is undefined. Before 5ccc56b1e4 it happened to skip one character. Now
it returns a zero-length text token and pdo_parse_params() loops
forever, or reads an uninitialized YYMARKER if the NUL is the first
byte. Add a default rule so a NUL is skipped as one character of text
again.

Close GH-24496
2026-10-22 14:26:24 +01:00
Matthias Dötsch c0018beb11 ext/pdo_pgsql: Convert integer columns without strtoll()
PostgreSQL sends int2/int4/int8 values in text format in canonical
decimal form: an optional minus sign followed by digits without leading
zeros. That is exactly what ZEND_HANDLE_NUMERIC_STR() accepts for
numeric array keys, including the range check. Use it instead of
calling strtoll() through ZEND_ATOL() for every value, and keep
ZEND_ATOL() as fallback for anything else.

fetchAll(PDO::FETCH_ASSOC) of 1M rows with 4 integer columns:
-11% instructions, -9% cycles.

Close GH-24385
2026-10-22 14:25:10 +01:00
David Carlier b7c723ab82 Merge branch 'PHP-8.6'
* PHP-8.6:
  pdo_pgsql_request_shutdown() leaves statements of freed PDO objects prepared.
  ext/pdo_pgsql: persistent connection reset drops prepared statements and plans.
  ext/pdo: persistent_shutdown run while the connection is still shared.
2026-10-22 12:09:28 +01:00
David CarlierandArtem Ukrainskiy 296e8eac57 pdo_pgsql_request_shutdown() leaves statements of freed PDO objects prepared.
Track prepared statement names on the handle and close the leftovers.

Co-authored-by: Artem Ukrainskiy <art.ukrainskiy@gmail.com>
2026-10-22 12:05:20 +01:00
David Carlier ce6c465902 ext/pdo_pgsql: persistent connection reset drops prepared statements and plans.
Fix #24461

Keep the rest of DISCARD ALL, and reset the connection if it fails.
2026-10-22 12:05:19 +01:00
David Carlier a9138d768a ext/pdo: persistent_shutdown run while the connection is still shared.
Only call it for the last PDO object, like the rollback before it.
2026-10-22 12:05:15 +01:00
Matthias DötschandGina Peter Banyard 5ccc56b1e4 ext/pdo_pgsql: Speed up the SQL scanner
The scanner that finds placeholders in queries excluded e/E from plain
text, because they can start an E'...' string. So every e/E in a query
(SELECT, WHERE, created_at, ...) ended a text token and became a
one-character token of its own. Allow e/E inside text as long as the
text doesn't end with one, so E'...' strings are still recognized.

Also let re2c generate bitmaps (-b) for the character classes instead
of a switch on every input character.

The scanner runs in PDO::prepare() and, with emulated prepares, again in
PDOStatement::execute(). Instructions for 200k calls of prepare():

                    emulated   native
  SELECT, 11 cols     -24%      -16%
  INSERT, 8 params    -15%       -7%

For a whole emulated query (prepare, execute, fetch one row) against a
local server, PHP executes 7-9% fewer instructions.

Co-authored-by: Gina Peter Banyard <girgias@php.net>

Close GH-24353
2026-10-17 11:30:14 +01:00
武田 憲太郎 5d57dd6140 ext/pdo_pgsql: Fix crash when a persistent connection fails
The shutdown function tried to reset the session state even when the
connection had failed.

Regression from GH-20572.

Close GH-23922
2026-09-26 19:38:52 +01:00
David Carlier 810a9e58dc Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/pdo_pgsql: Fix CURSOR_SCROLL statements closing a nonexistent cursor

# Conflicts:
#	ext/pdo_pgsql/config.m4
#	ext/pdo_pgsql/pgsql_statement.c
2026-09-06 21:00:54 +01:00
David Carlier f3607f147f Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  ext/pdo_pgsql: Fix CURSOR_SCROLL statements closing a nonexistent cursor

# Conflicts:
#	ext/pdo_pgsql/pgsql_statement.c
#	ext/pdo_pgsql/php_pdo_pgsql_int.h
2026-09-06 21:00:24 +01:00
武田 憲太郎 c1a7ab07ec ext/pdo_pgsql: Fix CURSOR_SCROLL statements closing a nonexistent cursor
The destructor of a statement created with
[PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL] tried to close the cursor even
when it did not exist. The attempted close causes an error on the server
that the destructor discards, so it cannot be observed by the user, but
inside a transaction it leaves subsequent statements failing for a reason
nobody can see.

is_prepared was overloaded to also mean "cursor declared" and was never
reset, so the cursor state now has its own flag. A close that fails no
longer aborts the caller's transaction.

Close GH-23490
2026-09-06 20:58:28 +01:00
Dmytro Kulyk 67135cb97b gen_stub: Conditionally include zend_attributes.h to arginfo based on usage (#21570)
Headers required by the generated code (zend_attributes.h, zend_constants.h, zend_enum.h) are collected during generation and emitted as includes at the top of the arginfo file, with the same preprocessor conditions and PHP version guards as the code that needs them.

Removes the manual zend_attributes.h and zend_enum.h includes from sources that only needed them for the arginfo file they include.
2026-09-06 21:25:20 +02:00
Weilin Du 90e374a835 Tests: Migrate old extension checks from SKIPIF to EXTENSIONS (#23473) 2026-08-27 10:03:30 +02:00
武田 憲太郎 f4a17fdefd ext/pdo_pgsql: Add Pdo\Pgsql::ATTR_CHUNK_SIZE for chunked result fetching
Generalizes the lazy fetch added in GH-15287 by letting a statement choose
how many rows it fetches per chunk, trading memory for speed. ext/pgsql
already exposed this as pg_set_chunked_rows_size(); ext/pdo_pgsql had no
way to reach it.

ATTR_PREFETCH and ATTR_CHUNK_SIZE replace each other: setting one on the
connection clears the other, a statement given either does not inherit the
connection's value, and a chunk size of 1 or more wins when both are set on
the same statement. A chunk size cannot be combined with a statement-level
PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, which throws a ValueError; a
connection-level chunk size is simply disabled by a scrollable statement.

Requires libpq 17 or later.

Close GH-23210
2026-08-27 05:12:15 +01:00
David Carlier 6aed61af14 Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/pdo_pgsql: Fix PDO::CURSOR_SCROLL statements failing under lazy fetching
2026-08-27 05:10:03 +01:00
武田 憲太郎 197bdc0a40 ext/pdo_pgsql: Fix PDO::CURSOR_SCROLL statements failing under lazy fetching
A statement prepared with PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL and lazy
fetching (PDO::ATTR_PREFETCH => 0) failed at execute() with
SQLSTATE[HY000]: General error: 7 and no message. Either option alone
worked.

A cursor does not stream its result, but S->is_unbuffered stayed set, so
execute() called PQgetResult() with nothing in flight. Clear the flag when
the statement has a cursor.

Close GH-23471
2026-08-27 05:09:43 +01:00
David Carlier 61c601c5f8 Merge branch 'PHP-8.5'
* PHP-8.5:
  ext/pdo_pgsql: Fix several lazy fetch defects
2026-08-11 19:46:03 +01:00
武田 憲太郎 0b91828b01 ext/pdo_pgsql: Fix several lazy fetch defects
With PDO::ATTR_PREFETCH => 0 a statement streams its result set, and the
cleanup reads the rest of it by calling PQgetResult() until it returns
NULL. That never happens while the connection is copying: PQgetResult()
hands out a fresh COPY result every time. A COPY run through a lazy fetch
has therefore spun at 100% CPU since 8.5.0, as soon as another lazy fetch
takes the connection over. The copy has to be ended first: a copy in with
PQputCopyEnd(), a copy out by draining PQgetCopyData().

The drain was skipped as well, because is_running_unbuffered was cleared
first, both in the cleanup's own abort path and in pgsql_stmt_fetch()
before it calls the cleanup. With PDO::ATTR_EMULATE_PREPARES or
Pdo\Pgsql::ATTR_DISABLE_PREPARES the connection then stayed busy and the
next lazy fetch failed with "another command is already in progress".

The connection's pointer to the statement streaming on it was only cleared
while closing a server-side prepared statement, which those two modes do
not create, so destroying one left the pointer dangling for the next lazy
fetch to read. And a statement whose stream was taken over kept its row
counters after its result had been freed, so fetch() returned a row of
NULLs rather than false.

Close GH-23065
2026-08-11 19:45:04 +01:00
NickSdot 5d58876192 tests: Cache failed service probes (#22944)
Prevents unavailable optional test services from slowing the suite through repeated connection timeouts. PDO and SNMP availability probes cache the first failure for the duration of one test run, so later SKIPIF checks return immediately.

Only failures are cached; successful probes and test connections are unchanged. PDOs one second timeout applies only to the default availability probe. The caches are private, run-scoped and removed afterwards. A service becoming available mid run is detected on the next test-suite run.
2026-08-06 11:42:56 +02:00
Weilin Du 00f4cd6b80 Refactor various raw C-string concatenation to use existing API (#22879)
In #21607 we introduce several inline helpers for raw C-string concatenation.
This PR use them to refactor several manual C string construction.
2026-07-25 01:06:29 +08:00
Ilia Alshanetsky 52cc9236ce Merge branch 'PHP-8.5'
* PHP-8.5:
  pdo_pgsql: preserve the pending exception when a COPY row fails to convert
2026-06-22 06:52:51 -04:00
Ilia Alshanetsky f0236f11ba pdo_pgsql: preserve the pending exception when a COPY row fails to convert
pgsqlCopyFromArray() feeds each row through try_convert_to_string(). A
non-stringable row throws a TypeError, but both the array and iterator
branches then called pdo_pgsql_error() and recorded a fabricated
PGRES_FATAL_ERROR, leaving PDO::errorInfo() reporting "HY000" for what is
a client-side type error. Return through the pending exception instead of
overwriting the driver error state.

Closes GH-22384
2026-06-22 06:50:31 -04:00
David Carlier 8b343897df Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21683: PDOStatement::fetch() throws on empty result With PDO::ATTR_FETCH attribute.
2026-04-18 05:27:52 +01:00
Thomas Schiet ec79850c50 Fix GH-21683: PDOStatement::fetch() throws on empty result With PDO::ATTR_FETCH attribute.
close GH-21684.
2026-04-18 05:24:28 +01:00
Ben Ramsey eca7fb4115 license-update: ext/pdo_pgsql source headers
RFC: https://wiki.php.net/rfc/php_license_update
2026-04-11 21:20:54 -05:00
Peter Kokot 3619caa0b1 ext/{pdo_pgsql,pgsql}: Enable HAVE_PG_RESULT_MEMORY_SIZE (#21595)
PQresultMemorySize is available since libpq 12.
On Windows libpq 16.2 is used at time of writing:
https://github.com/winlibs/postgresql
2026-04-02 19:40:00 +02:00
KentarouTakeda c56e8caaed 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
2026-03-08 05:42:50 +00:00
Peter Kokot f17c5ad83b Windows build: Add new function CHECK_HEADER() (#21191)
The current function `CHECK_HEADER_ADD_INCLUDE()` automatically defines
`HAVE_<HEADER_NAME_H>` preprocessor macros, which makes it difficult to
sync with other build systems. Specially, if some `HAVE_` macro is used
in the code and this function defines this macro but Autotools doesn't.

The new `CHECK_HEADER()` function behaves similar except it doesn't
define the `HAVE_<HEADER_NAME_H>` preprocessor macro.

This removes the following unused compile definitions:

HAVE_ARGON2_H
HAVE_AVIF_H
HAVE_BZLIB_H
HAVE_CAPSTONE_CAPSTONE_H
HAVE_CURL_EASY_H
HAVE_DB_H
HAVE_DECODE_H
HAVE_DEPOT_H
HAVE_EDITLINE_READLINE_H
HAVE_ENCHANT_H
HAVE_ENCODE_H
HAVE_FFI_H
HAVE_FIREBIRD_INTERFACE_H
HAVE_FT2BUILD_H
HAVE_GD_H
HAVE_GLIB_H
HAVE_GMP_H
HAVE_HTTPD_H
HAVE_IBASE_H
HAVE_IR_IR_H
HAVE_KECCAKHASH_H
HAVE_LBER_H
HAVE_LDAP_H
HAVE_LIBEXSLT_EXSLT_H
HAVE_LIBINTL_H
HAVE_LIBPQ_FE_H
HAVE_LIBTIDY_TIDY_H
HAVE_LIBXML_PARSER_H
HAVE_LIBXML_TREE_H
HAVE_LIBXML_XMLWRITER_H
HAVE_LIBXSLT_XSLT_H
HAVE_LMDB_H
HAVE_MBSTRING_H
HAVE_MYSQL_H
HAVE_ONIGURUMA_H
HAVE_OPENSSL_SSL_H
HAVE_PNG_H
HAVE_SNMP_H
HAVE_SODIUM_H
HAVE_SQLITE3_H
HAVE_SQLITE3EXT_H
HAVE_SYBFRONT_H
HAVE_TIDY_H
HAVE_TIDY_TIDY_H
HAVE_TIDYBUFFIO_H
HAVE_TIMELIB_CONFIG_H
HAVE_UNICODE_USPOOF_H
HAVE_UNICODE_UTF_H
HAVE_XPM_H
HAVE_ZIP_H
HAVE_ZIPCONF_H
HAVE_ZLIB_H

The following compile definitions are defined explicitly:

- HAVE_ICONV_H
- HAVE_MSCOREE_H
- HAVE_SQL_H
- HAVE_SQLEXT_H

Additionally, the `SETUP_OPENSSL()` function doesn't accept the 6th
argument anymore.
2026-03-03 20:06:40 +01:00
David Carlier b16e534f9a Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix GH-21055: Pdo/Pgsql typo for GSS negotiation connection status attribute.
2026-01-28 18:15:04 +00:00
David Carlier 00466a068e Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix GH-21055: Pdo/Pgsql typo for GSS negotiation connection status attribute.
2026-01-28 18:14:53 +00:00
Loïc Saos 3037526810 Fix GH-21055: Pdo/Pgsql typo for GSS negotiation connection status attribute.
close GH-21057
2026-01-28 18:12:08 +00:00
Arnaud Le Blanc 65b4073922 Include the actual stub name in generated arginfo headers (#20993) 2026-01-21 20:57:00 +01:00
Jakub Zelenka 122a94ebe9 Merge branch 'PHP-8.5'
* PHP-8.5:
  Update NEWS with info about security issues
  Fix GHSA-www2-q4fc-65wf
  Fix GHSA-h96m-rvf9-jgm2
  Fix GHSA-8xr5-qppj-gvwj: PDO quoting result null deref
  Fix GH-20584: Information Leak of Memory
2025-12-16 15:37:38 +01:00
Jakub Zelenka 5c0a6feca2 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Update NEWS with info about security issues
  Fix GHSA-www2-q4fc-65wf
  Fix GHSA-h96m-rvf9-jgm2
  Fix GHSA-8xr5-qppj-gvwj: PDO quoting result null deref
  Fix GH-20584: Information Leak of Memory
2025-12-16 15:36:52 +01:00
Jakub Zelenka 633fb48fca Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Update NEWS with info about security issues
  Fix GHSA-www2-q4fc-65wf
  Fix GHSA-h96m-rvf9-jgm2
  Fix GHSA-8xr5-qppj-gvwj: PDO quoting result null deref
  Fix GH-20584: Information Leak of Memory
2025-12-16 15:35:25 +01:00
Jakub Zelenka e776695abf Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Update NEWS with info about security issues
  Fix GHSA-www2-q4fc-65wf
  Fix GHSA-h96m-rvf9-jgm2
  Fix GHSA-8xr5-qppj-gvwj: PDO quoting result null deref
  Fix GH-20584: Information Leak of Memory
2025-12-16 15:34:19 +01:00
Jakub Zelenka 6e124d0df6 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Update NEWS with info about security issues
  Fix GHSA-www2-q4fc-65wf
  Fix GHSA-h96m-rvf9-jgm2
  Fix GHSA-8xr5-qppj-gvwj: PDO quoting result null deref
  Fix GH-20584: Information Leak of Memory
2025-12-16 15:30:54 +01:00
Jakub Zelenka 727a4ddc39 Fix GHSA-8xr5-qppj-gvwj: PDO quoting result null deref 2025-12-16 15:26:59 +01:00
武田 憲太郎 19deb91002 pdo_pgsql: Reset persistent session state on disconnect-equivalent processing
close GH-20572
2025-12-11 20:22:09 +00:00
Niels Dossche 57ce245e1e Reduce code bloat in arginfo by using specialised string releases (#20016)
* Reduce code bloat in arginfo by using specialised string releases

Comparing this patch to master (c7da728574),
with a plain configure command without any options:

```
   text	   data	    bss	    dec	    hex	filename
20683738	1592400	 137712	22413850	156021a	sapi/cli/php
20688522	1592400	 137712	22418634	15614ca	sapi/cli/php_old
```

We see a minor reduction of 0.023% in code size.

* Also use true for the other initialization line

* Also use specialized code for consts
2025-10-02 22:00:20 +02:00
David Carlier 5668b16ad2 Revert "Pdo\Pgsql: Fix getColumnMeta() for GH-15287 Pdo\Pgsql::setAttribute(PDO::ATTR_PREFETCH, 0)"
This reverts commit 898235127b.
2025-09-29 14:43:51 +01:00
Guillaume Outters 898235127b Pdo\Pgsql: Fix getColumnMeta() for GH-15287 Pdo\Pgsql::setAttribute(PDO::ATTR_PREFETCH, 0)
As stated in the UPGRADING, using the passthrough ("single-row") mode of libpq (introduced in #15287)
forbids passing a new query while the current one's results have not been entirely consumed.
… But I didn't notice that ext/pdo_pgsql internally used new queries to fetch metadata (example use case:
a call to getColumnMeta() while fetch()ing row by row will interleave the getColumnMeta()-triggered
internal query to the database, with the results fetching for the user-called query).

This PR makes those internal calls return NULL for non-essential metadata, instead of letting libpq abort the user-called query.

It moreover includes a small tweak to table oid-to-name translation, with a 1-slot cache.
This may by chance allow the internal call to return something instead of NULL,
but it will nonetheless avoid 30 server calls to get the table name of 30 columns of the same table.

optimize calls to foreach(columns of the same table) getColumnMeta()

- each call queried the DB to know the name associated with the table's OID:
  cache the result between two calls
- make pdo_pgsql_translate_oid_to_table higher-level,
  with the last parameter being the handle instead of the raw connection;
  thus the statement is cleaner, letting the handle do all memory handling on the table oid-to-name translation cache
  (which by the way is a driver feature more than a statement one)

close GH-16249
2025-09-28 22:37:19 +01:00
Tim Düsterhus b965ea3a05 pdo_pgsql: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Gina Peter Banyard 05eda4318d Add missing extension dependencies for tests 2025-09-11 15:10:49 +02:00
David CARLIER 9f8802c416 ext/pdo_pgsql: [RFC] Deprecate PGSQL_TRANSACTION_ constants. (#19594) 2025-09-07 19:47:20 +01:00
Arnaud Le Blanc a4afc57f1d Deprecate driver specific PDO methods
RFC: https://wiki.php.net/rfc/deprecations_php_8_5.

Closes GH-19596
2025-09-03 08:42:33 +02:00
Arnaud Le Blanc 6f32e1c690 Deprecate driver specific PDO constants
RFC: https://wiki.php.net/rfc/deprecations_php_8_5.

Closes GH-19526
2025-08-26 09:06:19 +02:00
Gina Peter Banyard d9000b3094 tree: replace some unnecessary uses of spprintf (#19354) 2025-08-05 17:25:47 +01:00
David Carlier f7ca8138e7 Merge branch 'PHP-8.4' 2025-07-27 12:56:05 +01:00