Skip to content

Commit 3c6c95f

Browse files
PHP 8.4: pgsql: Add pg_set_chunked_rows_size, PGSQL_TUPLES_CHUNK (#4117)
Co-authored-by: Gina Peter Banyard <girgias@php.net>
1 parent 38d0723 commit 3c6c95f

File tree

4 files changed

+139
-1
lines changed

4 files changed

+139
-1
lines changed

reference/pgsql/constants.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,22 @@
251251
</simpara>
252252
</listitem>
253253
</varlistentry>
254+
<varlistentry xml:id="constant.pgsql-tuples-chunk">
255+
<term>
256+
<constant>PGSQL_TUPLES_CHUNK</constant>
257+
(<type>int</type>)
258+
</term>
259+
<listitem>
260+
<simpara>
261+
Returned by <function>pg_result_status</function>.
262+
Indicates the successful completion of a command returning data in chunked mode.
263+
Returned for <literal>SELECT</literal> commands when
264+
<function>pg_set_chunked_rows_size</function> is set.
265+
The result set is divided into multiple chunks, each containing a predefined number of rows.
266+
Available as of PHP 8.4.0 and libpq 17.
267+
</simpara>
268+
</listitem>
269+
</varlistentry>
254270
<varlistentry xml:id="constant.pgsql-copy-out">
255271
<term>
256272
<constant>PGSQL_COPY_OUT</constant>

reference/pgsql/functions/pg-result-status.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
&reftitle.returnvalues;
5252
<para>
5353
Possible return values are <constant>PGSQL_EMPTY_QUERY</constant>,
54-
<constant>PGSQL_COMMAND_OK</constant>, <constant>PGSQL_TUPLES_OK</constant>, <constant>PGSQL_COPY_OUT</constant>,
54+
<constant>PGSQL_COMMAND_OK</constant>, <constant>PGSQL_TUPLES_OK</constant>, <constant>PGSQL_TUPLES_CHUNK</constant>, <constant>PGSQL_COPY_OUT</constant>,
5555
<constant>PGSQL_COPY_IN</constant>, <constant>PGSQL_BAD_RESPONSE</constant>, <constant>PGSQL_NONFATAL_ERROR</constant> and
5656
<constant>PGSQL_FATAL_ERROR</constant> if <constant>PGSQL_STATUS_LONG</constant> is
5757
specified. Otherwise, a <type>string</type> containing the PostgreSQL command tag is returned.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- $Revision$ -->
3+
<refentry xml:id="function.pg-set-chunked-rows-size" xmlns="http://docbook.org/ns/docbook">
4+
<refnamediv>
5+
<refname>pg_set_chunked_rows_size</refname>
6+
<refpurpose>Set the query results to be retrieved in chunk mode</refpurpose>
7+
</refnamediv>
8+
9+
<refsect1 role="description">
10+
&reftitle.description;
11+
<methodsynopsis>
12+
<type>bool</type><methodname>pg_set_chunked_rows_size</methodname>
13+
<methodparam><type>PgSql\Connection</type><parameter>connection</parameter></methodparam>
14+
<methodparam><type>int</type><parameter>size</parameter></methodparam>
15+
</methodsynopsis>
16+
<simpara>
17+
Set the query results to be retrieved in chunk mode.
18+
The query results returned afterward will be divided into multiple chunks,
19+
each containing up to <parameter>size</parameter> rows.
20+
This function must be called before retrieving results with <function>pg_get_result</function>.
21+
This function is only available when libpq is version 17 or higher.
22+
</simpara>
23+
</refsect1>
24+
25+
<refsect1 role="parameters">
26+
&reftitle.parameters;
27+
<variablelist>
28+
<varlistentry>
29+
<term><parameter>connection</parameter></term>
30+
<listitem>
31+
&pgsql.parameter.connection;
32+
</listitem>
33+
</varlistentry>
34+
<varlistentry>
35+
<term><parameter>size</parameter></term>
36+
<listitem>
37+
<simpara>
38+
The number of rows to be retrieved in each chunk.
39+
</simpara>
40+
</listitem>
41+
</varlistentry>
42+
</variablelist>
43+
</refsect1>
44+
45+
<refsect1 role="returnvalues">
46+
&reftitle.returnvalues;
47+
<simpara>
48+
&return.success;
49+
</simpara>
50+
</refsect1>
51+
52+
<refsect1 role="errors">
53+
&reftitle.errors;
54+
<simpara>
55+
If <parameter>size</parameter> is less than <literal>1</literal>,
56+
a <classname>ValueError</classname> will be thrown.
57+
</simpara>
58+
</refsect1>
59+
60+
<refsect1 role="examples">
61+
&reftitle.examples;
62+
<example>
63+
<title><function>pg_result_memory_size</function> example</title>
64+
<programlisting role="php">
65+
<![CDATA[
66+
<?php
67+
68+
$conn = pg_connect($conn_str);
69+
70+
for ($i = 0; $i < 10; $i ++) {
71+
pg_query($conn, "INSERT INTO users DEFAULT VALUES");
72+
}
73+
74+
pg_send_query($conn, "SELECT * FROM users");
75+
pg_set_chunked_rows_size($conn, 1);
76+
77+
$result = pg_get_result($conn);
78+
var_dump(pg_num_rows($result));
79+
80+
// No effect after the result is retrieved
81+
var_dump(pg_set_chunked_rows_size($conn, 10));
82+
]]>
83+
</programlisting>
84+
&example.outputs;
85+
<screen>
86+
<![CDATA[
87+
int(1)
88+
bool(false)
89+
]]>
90+
</screen>
91+
</example>
92+
</refsect1>
93+
94+
<refsect1 role="seealso">
95+
&reftitle.seealso;
96+
<simplelist>
97+
<member><function>pg_get_result</function></member>
98+
<member><function>pg_result_status</function></member>
99+
</simplelist>
100+
</refsect1>
101+
</refentry>
102+
<!-- Keep this comment at the end of the file
103+
Local variables:
104+
mode: sgml
105+
sgml-omittag:t
106+
sgml-shorttag:t
107+
sgml-minimize-attributes:nil
108+
sgml-always-quote-attributes:t
109+
sgml-indent-step:1
110+
sgml-indent-data:t
111+
indent-tabs-mode:nil
112+
sgml-parent-document:nil
113+
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
114+
sgml-exposed-tags:nil
115+
sgml-local-catalogs:nil
116+
sgml-local-ecat-files:nil
117+
End:
118+
vim600: syn=xml fen fdm=syntax fdl=2 si
119+
vim: et tw=78 syn=sgml
120+
vi: ts=1 sw=1
121+
-->

reference/pgsql/versions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<function name="pg_set_client_encoding" from="PHP 4 &gt;= 4.0.3, PHP 5, PHP 7, PHP 8"/>
8989
<function name="pg_set_error_context_visibility" from="PHP 8 &gt;= 8.3.0"/>
9090
<function name="pg_set_error_verbosity" from="PHP 5 &gt;= 5.1.0, PHP 7, PHP 8"/>
91+
<function name="pg_set_chunked_rows_size" from="PHP 8 &gt;= 8.4.0"/>
9192
<function name="pg_socket" from="PHP 5 &gt;= 5.6.0, PHP 7, PHP 8"/>
9293
<function name="pg_trace" from="PHP 4 &gt;= 4.0.1, PHP 5, PHP 7, PHP 8"/>
9394
<function name="pg_transaction_status" from="PHP 5 &gt;= 5.1.0, PHP 7, PHP 8"/>

0 commit comments

Comments
 (0)