Skip to content

Commit 205c3b8

Browse files
philiplacatoire
andauthored
pdo_pgsql: document ATTR_PREFETCH lazy fetch, fix copyFromArray sig (#5629)
* pdo_pgsql: document ATTR_PREFETCH lazy fetch, fix copyFromArray signature * Apply suggestion from @lacatoire Co-authored-by: Louis-Arnaud <la.catoire@gmail.com> * pdo_pgsql: fix ATTR_PREFETCH link and copyFromArray rows whitespace --------- Co-authored-by: Louis-Arnaud <la.catoire@gmail.com>
1 parent 858400b commit 205c3b8

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

reference/pdo/constants.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@
251251
setting of the prefetch size. A larger prefetch size results in
252252
increased performance at the cost of higher memory usage.
253253
</simpara>
254+
<simpara>
255+
The PDO_PGSQL driver instead treats this attribute as a toggle: as of
256+
PHP 8.5.0, a value of <literal>0</literal> enables lazy (single-row)
257+
fetching; see the
258+
<link linkend="pdo-pgsql.constants.attr-prefetch">PDO_PGSQL driver docs</link>
259+
for details.
260+
</simpara>
254261
</listitem>
255262
</varlistentry>
256263
<varlistentry xml:id="pdo.constants.attr-timeout">

reference/pdo_pgsql/pdo-pgsql.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,32 @@
155155
</simpara>
156156
</listitem>
157157
</varlistentry>
158+
<varlistentry xml:id="pdo-pgsql.constants.attr-prefetch">
159+
<term><constant>PDO::ATTR_PREFETCH</constant></term>
160+
<listitem>
161+
<simpara>
162+
As of PHP 8.5.0, setting this attribute to <literal>0</literal> enables
163+
lazy (single-row) fetching: rows are retrieved from the server one at a
164+
time as they are fetched, instead of buffering the whole result set in
165+
memory before the first <methodname>PDOStatement::fetch</methodname>
166+
call. This reduces memory usage for large result sets. Any other value
167+
keeps the default buffered behavior.
168+
</simpara>
169+
<simpara>
170+
It can be set per connection with
171+
<methodname>PDO::setAttribute</methodname>, or per statement via
172+
the <methodname>PDO::prepare</methodname> or
173+
<methodname>PDO::query</methodname> driver options.
174+
</simpara>
175+
<caution>
176+
<simpara>
177+
In lazy mode, a connection can have only one active statement at a
178+
time. Running another statement silently discards any unread rows of
179+
the previous one; no error is raised.
180+
</simpara>
181+
</caution>
182+
</listitem>
183+
</varlistentry>
158184
<varlistentry xml:id="pdo-pgsql.constants.transaction-idle">
159185
<term><constant>Pdo\Pgsql::TRANSACTION_IDLE</constant></term>
160186
<listitem>

reference/pdo_pgsql/pdo/pgsql/copyfromarray.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<methodsynopsis role="Pdo\\Pgsql">
1111
<modifier>public</modifier> <type>bool</type><methodname>Pdo\Pgsql::copyFromArray</methodname>
1212
<methodparam><type>string</type><parameter>tableName</parameter></methodparam>
13-
<methodparam><type>array</type><parameter>rows</parameter></methodparam>
13+
<methodparam><type class="union"><type>array</type><type>Traversable</type></type><parameter>rows</parameter></methodparam>
1414
<methodparam choice="opt"><type>string</type><parameter>separator</parameter><initializer>"\t"</initializer></methodparam>
1515
<methodparam choice="opt"><type>string</type><parameter>nullAs</parameter><initializer>"\\\\N"</initializer></methodparam>
1616
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>fields</parameter><initializer>&null;</initializer></methodparam>
@@ -37,8 +37,9 @@
3737
<term><parameter>rows</parameter></term>
3838
<listitem>
3939
<simpara>
40-
An indexed <type>array</type> of <type>string</type>s with fields
41-
separated by <parameter>separator</parameter>.
40+
An indexed <type>array</type> (or <type>Traversable</type>) of
41+
<type>string</type>s with fields separated by
42+
<parameter>separator</parameter>.
4243
</simpara>
4344
</listitem>
4445
</varlistentry>

0 commit comments

Comments
 (0)