diff --git a/NEWS b/NEWS index 0664cf4e4e31..3948c1c08cea 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,10 @@ PHP NEWS . Fixed a leak when a persistent connection failed a liveness check with no other live PDO handle. (iliaal) +- PDO_PGSQL: + . Fixed PDO::CURSOR_SCROLL statements failing under lazy fetching + (PDO::ATTR_PREFETCH => 0). (KentarouTakeda) + - Readline: . Fixed the interactive shell not waiting for the pager process to exit. (Weilin Du) diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 54b2e25f72f6..6a978fde52d0 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -320,6 +320,10 @@ static bool pgsql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t * : H->default_fetching_laziness ; + if (scrollable) { + S->is_unbuffered = false; + } + 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-- + +--FILE-- +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