Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -6359,6 +6359,21 @@ PHP_FUNCTION(pg_socket_poll)
RETURN_LONG((zend_long)PQsocketPoll(socket, (int)read, (int)write, (int)ts));
}

PHP_FUNCTION(pg_set_single_row_mode)
{
zval *pgsql_link;
pgsql_link_handle *link;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
ZEND_PARSE_PARAMETERS_END();

link = Z_PGSQL_LINK_P(pgsql_link);
CHECK_PGSQL_LINK(link);

RETURN_BOOL(PQsetSingleRowMode(link->conn));
}

#if defined(HAVE_PG_SET_CHUNKED_ROWS_SIZE)
PHP_FUNCTION(pg_set_chunked_rows_size)
{
Expand Down
7 changes: 7 additions & 0 deletions ext/pgsql/pgsql.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@
* @cvalue PGRES_TUPLES_OK
*/
const PGSQL_TUPLES_OK = UNKNOWN;
/**
* @var int
* @cvalue PGRES_SINGLE_TUPLE
*/
const PGSQL_SINGLE_TUPLE = UNKNOWN;
#ifdef HAVE_PG_SET_CHUNKED_ROWS_SIZE
/**
* @var int
Expand Down Expand Up @@ -952,6 +957,8 @@ function pg_put_copy_end(PgSql\Connection $connection, ?string $error = null): i
*/
function pg_socket_poll($socket, int $read, int $write, int $timeout = -1): int {}

function pg_set_single_row_mode(Pgsql\Connection $connection): bool {}

#ifdef HAVE_PG_SET_CHUNKED_ROWS_SIZE
function pg_set_chunked_rows_size(PgSql\Connection $connection, int $size): bool {}
#endif
Expand Down
9 changes: 8 additions & 1 deletion ext/pgsql/pgsql_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions ext/pgsql/tests/pg_set_single_row_mode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--TEST--
PostgreSQL pg_set_single_row_mode
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php

include('inc/config.inc');
$table_name = "test_single_row_mode";

$conn = pg_connect($conn_str);
pg_query($conn, "CREATE TABLE {$table_name} (num int)");

for ($i = 0; $i < 3; $i++) {
pg_query($conn, "INSERT INTO {$table_name} VALUES ({$i})");
}

var_dump(pg_send_query($conn, "SELECT * FROM {$table_name} ORDER BY num"));
var_dump(pg_set_single_row_mode($conn));

for ($i = 0; $i < 3; $i++) {
$result = pg_get_result($conn);
var_dump(pg_result_status($result) === PGSQL_SINGLE_TUPLE);
var_dump(pg_fetch_result($result, 0, 0));
}

$result = pg_get_result($conn);
var_dump(pg_result_status($result) === PGSQL_TUPLES_OK);
var_dump(pg_num_rows($result));
var_dump(pg_get_result($conn));
var_dump(pg_set_single_row_mode($conn));
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "test_single_row_mode";

$conn = pg_connect($conn_str);
pg_query($conn, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
string(1) "0"
bool(true)
string(1) "1"
bool(true)
string(1) "2"
bool(true)
int(0)
bool(false)
bool(false)
Loading