[php-src] master: Merge branch 'PHP-8.5'

David Carlier <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: David Carlier (devnexen)
Date: 2026-08-27T05:10:03+01:00

Commit: https://github.com/php/php-src/commit/6aed61af144b3b4f89d678be9891bd6bce3d37af
Raw diff: https://github.com/php/php-src/commit/6aed61af144b3b4f89d678be9891bd6bce3d37af.diff

Merge branch 'PHP-8.5'

* PHP-8.5:
  ext/pdo_pgsql: Fix PDO::CURSOR_SCROLL statements failing under lazy fetching

Changed paths:
  A  ext/pdo_pgsql/tests/cursor_scroll_lazy_fetch.phpt
  M  ext/pdo_pgsql/pgsql_driver.c


Diff:

diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index 52aae986dee1..5c96071c6774 100644
--- a/ext/pdo_pgsql/pgsql_driver.c
+++ b/ext/pdo_pgsql/pgsql_driver.c
@@ -285,7 +285,16 @@ static bool pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *
 	scrollable = pdo_attr_lval(driver_options, PDO_ATTR_CURSOR,
 		PDO_CURSOR_FWDONLY) == PDO_CURSOR_SCROLL;
 
+	S->is_unbuffered =
+		driver_options
+		&& (val = zend_hash_index_find(Z_ARRVAL_P(driver_options), PDO_ATTR_PREFETCH))
+		&& pdo_get_long_param(&lval, val)
+		? !lval
+		: H->default_fetching_laziness
+	;
+
 	if (scrollable) {
+		S->is_unbuffered = false;
 		if (S->cursor_name) {
 			efree(S->cursor_name);
 		}
@@ -310,14 +319,6 @@ static bool pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *
 		stmt->named_rewrite_template = "$%d";
 	}
 
-	S->is_unbuffered =
-		driver_options
-		&& (val = zend_hash_index_find(Z_ARRVAL_P(driver_options), PDO_ATTR_PREFETCH))
-		&& pdo_get_long_param(&lval, val)
-		? !lval
-		: H->default_fetching_laziness
-	;
-
 	ret = pdo_parse_params(stmt, sql, &nsql);
 
 	if (ret == -1) {
diff --git a/ext/pdo_pgsql/tests/cursor_scroll_lazy_fetch.phpt b/ext/pdo_pgsql/tests/cursor_scroll_lazy_fetch.phpt
new file mode 100644
index 000000000000..df4be41b8532
--- /dev/null
+++ b/ext/pdo_pgsql/tests/cursor_scroll_lazy_fetch.phpt
@@ -0,0 +1,33 @@
+--TEST--
+PDO PgSQL a scrollable cursor is unaffected by lazy fetching
+--EXTENSIONS--
+pdo_pgsql
+--SKIPIF--
+<?php
+require __DIR__ . '/config.inc';
+require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+
+require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
+$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
+$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$sql = "SELECT * FROM generate_series(1, 3)";
+$scrollable = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL];
+
+$stmt = $pdo->prepare($sql, $scrollable + [PDO::ATTR_PREFETCH => 0]);
+$stmt->execute();
+echo 'lazy on the statement: ', implode(',', $stmt->fetchAll(PDO::FETCH_COLUMN)), PHP_EOL;
+
+$pdo->setAttribute(PDO::ATTR_PREFETCH, 0);
+$stmt = $pdo->prepare($sql, $scrollable);
+$stmt->execute();
+echo 'lazy on the connection: ', implode(',', $stmt->fetchAll(PDO::FETCH_COLUMN)), PHP_EOL;
+
+?>
+--EXPECT--
+lazy on the statement: 1,2,3
+lazy on the connection: 1,2,3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.