Skip to content

Commit

Permalink
Document new Pdo\Pgsql methods which did not exist previously
Browse files Browse the repository at this point in the history
Co-authored-by: KentarouTakeda <[email protected]>
  • Loading branch information
Girgias and KentarouTakeda committed Nov 24, 2024
1 parent 50b5d3f commit 4231a4d
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 7 deletions.
110 changes: 110 additions & 0 deletions reference/pdo_pgsql/pdo/pgsql/escapeidentifier.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="pdo-pgsql.escapeidentifier" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Pdo\Pgsql::escapeIdentifier</refname>
<refpurpose>Escapes a string for use as an SQL identifier</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="Pdo\\Pgsql">
<modifier>public</modifier> <type>string</type><methodname>Pdo\Pgsql::escapeIdentifier</methodname>
<methodparam><type>string</type><parameter>input</parameter></methodparam>
</methodsynopsis>
<simpara>
Escapes a string for use as an SQL identifier, such as a table, column, or function name.
This is useful when a user-supplied identifier might contain special characters
that would otherwise not be interpreted as part of the identifier by the SQL parser,
or when the identifier might contain upper case characters whose case should be preserved.
</simpara>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>input</parameter></term>
<listitem>
<simpara>
A <type>string</type> containing text to be escaped.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
A <type>string</type> containing the escaped data.
</simpara>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example xml:id="pdo-pgsql.escapeidentifier.example.basic">
<title><methodname>Pdo\Pgsql::escapeIdentifier</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php
$pdo = new Pdo\Pgsql('pgsql:dbname=test host=localhost', $user, $pass);
$unescapedTableName = 'UnescapedTableName';
$pdo->exec("CREATE TABLE $unescapedTableName ()");
$escapedTableName = $pdo->escapeIdentifier('EscapedTableName');
$pdo->exec("CREATE TABLE $escapedTableName ()");
$statement = $pdo->query(
"SELECT relname FROM pg_stat_user_tables WHERE relname ilike '%tablename'"
);
var_export($statement->fetchAll(PDO::FETCH_COLUMN, 0));
$tableNameWithSymbols = 'Table-Name-With-Symbols';
$pdo->exec("CREATE TABLE $tableNameWithSymbols ()");
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
array (
0 => 'unescapedtablename',
1 => 'EscapedTableName',
)
Fatal error: Uncaught PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "Table"
LINE 1: CREATE TABLE Table-Name-With-Symbols ()
]]>
</screen>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><methodname>PDO::quote</methodname></member>
</simplelist>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
8 changes: 5 additions & 3 deletions reference/pdo_pgsql/pdo/pgsql/getpid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<refentry xml:id="pdo-pgsql.getpid" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Pdo\Pgsql::getPid</refname>
<refpurpose>Get the server PID</refpurpose>
<refpurpose>Get the PID of the backend process handling this connection</refpurpose>
</refnamediv>

<refsect1 role="description">
Expand All @@ -12,7 +12,9 @@
<void/>
</methodsynopsis>
<simpara>
Returns the server's PID.
Returns the PID of the backend process handling this connection.
Note that the PID belongs to a process executing on the database server host,
not the local host.
</simpara>
</refsect1>

Expand All @@ -24,7 +26,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
Returns the server's PID as an <type>int</type>.
Returns the PID as an <type>int</type>.
</simpara>
</refsect1>
</refentry>
Expand Down
7 changes: 4 additions & 3 deletions reference/pdo_pgsql/pdo/pgsql/lobcreate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</methodsynopsis>
<simpara>
<methodname>Pdo\Pgsql::lobCreate</methodname> creates a large object
and returns the ODI which refers to it.
and returns the OID which refers to it.
It can be opened to read or write data with
<methodname>Pdo\Pgsql::lobOpen</methodname>.
</simpara>
Expand All @@ -26,10 +26,11 @@
<simpara>
Large objects are cumbersome to use.
Indeed, it is required that <methodname>Pdo\Pgsql::lobUnlink</methodname>
is called prior to deleting the last row referencing the OID in the whole database.
is called prior to deleting the last row referencing the OID in the entire database;
otherwise, unreferenced large objects will remain on the server indefinitely.
Moreover, large objects have no access controls.
An alternative is the bytea column type, which can be up to 1GB in size,
and this row type transparently manage the storage for optimal row size.
and this column type transparently manages the storage for optimal row size.
</simpara>
<note>
<simpara>
Expand Down
1 change: 0 additions & 1 deletion reference/pdo_pgsql/pdo/pgsql/lobunlink.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<example xml:id="pdo-pgsql.lobunlink.example.basic">
<title><methodname>Pdo\Pgsql::lobUnlink</methodname> example</title>
<simpara>
Description.
This example unlinks a large object from the database prior to deleting
the row that references it from the blobs table are used in the examples of
<methodname>Pdo\Pgsql::lobCreate</methodname> and
Expand Down
107 changes: 107 additions & 0 deletions reference/pdo_pgsql/pdo/pgsql/setnoticecallback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="pdo-pgsql.setnoticecallback" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>Pdo\Pgsql::setNoticeCallback</refname>
<refpurpose>Set a callback to handle notice and warning messages generated by the backend</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="Pdo\\Pgsql">
<modifier>public</modifier> <type>void</type><methodname>Pdo\Pgsql::setNoticeCallback</methodname>
<methodparam><type class="union"><type>callable</type><type>null</type></type><parameter>callback</parameter></methodparam>
</methodsynopsis>
<simpara>
Description.
</simpara>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>callback</parameter></term>
<listitem>
<simpara>
If &null; is passed, the handler is reset to its default state.
</simpara>
<para>
Otherwise, the handler is a callback with the following signature:
<methodsynopsis>
<type>void</type><methodname><replaceable>handler</replaceable></methodname>
<methodparam><type>string</type><parameter>message</parameter></methodparam>
</methodsynopsis>
<variablelist role="function_parameters">
<varlistentry>
<term><parameter>message</parameter></term>
<listitem>
<simpara>
A message generated by the backend.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
&return.void;
</simpara>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example xml:id="pdo-pgsql.setnoticecallback.example.basic">
<title><methodname>Pdo\Pgsql::setNoticeCallback</methodname> example</title>
<programlisting role="php">
<![CDATA[
<?php
<?php
$pdo = new Pdo\Pgsql('pgsql:dbname=test host=localhost', $user, $pass);
$pdo->exec('CREATE TABLE parent(id int primary key)');
$pdo->exec('CREATE TABLE child(id int references parent)');
$pdo->setNoticeCallback(function ($message) {
echo $message;
});
$pdo->exec('TRUNCATE parent CASCADE');
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
NOTICE: truncate cascades to table "child"
]]>
</screen>
</example>
</refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
2 changes: 2 additions & 0 deletions reference/pdo_pgsql/versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
<function name="pdo\pgsql::copyfromfile" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::copytoarray" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::copytofile" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::escapeidentifier" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::getnotify" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::getpid" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::lobcreate" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::lobopen" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::lobunlink" from="PHP 8 &gt;= 8.4.0"/>
<function name="pdo\pgsql::setnoticecallback" from="PHP 8 &gt;= 8.4.0"/>
</versions>
<!-- Keep this comment at the end of the file
Local variables:
Expand Down

0 comments on commit 4231a4d

Please sign in to comment.