Skip to content

Commit 417ff88

Browse files
Document PGSQL
Co-authored-by: KentarouTakeda <takeda@youmind.jp>
1 parent bf29540 commit 417ff88

File tree

4 files changed

+72
-56
lines changed

4 files changed

+72
-56
lines changed

reference/pdo_pgsql/pdo/pgsql/escapeidentifier.xml

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<refentry xml:id="pdo-pgsql.escapeidentifier" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
33
<refnamediv>
44
<refname>Pdo\Pgsql::escapeIdentifier</refname>
5-
<refpurpose>Description</refpurpose>
5+
<refpurpose>Escapes a string for use as an SQL identifier</refpurpose>
66
</refnamediv>
77

88
<refsect1 role="description">
@@ -13,7 +13,11 @@
1313
</methodsynopsis>
1414
&warn.undocumented.func;
1515
<simpara>
16-
Description.
16+
Escapes a string for use as an SQL identifier, such as a table, column, or function name.
17+
This is useful when a user-supplied identifier might contain special characters
18+
that would otherwise not be interpreted as part of the identifier by the SQL parser,
19+
or when the identifier might contain upper case characters
20+
whose case should be preserved.
1721
</simpara>
1822
</refsect1>
1923

@@ -24,7 +28,7 @@
2428
<term><parameter>input</parameter></term>
2529
<listitem>
2630
<simpara>
27-
Description.
31+
A <type>string</type> containing text to be escaped.
2832
</simpara>
2933
</listitem>
3034
</varlistentry>
@@ -34,15 +38,7 @@
3438
<refsect1 role="returnvalues">
3539
&reftitle.returnvalues;
3640
<simpara>
37-
Description.
38-
</simpara>
39-
</refsect1>
40-
41-
<refsect1 role="errors">
42-
&reftitle.errors;
43-
<simpara>
44-
When does this function issue <constant>E_*</constant> level errors,
45-
and/or throw <exceptionname>Exception</exceptionname>s.
41+
A <type>string</type> containing the escaped data.
4642
</simpara>
4743
</refsect1>
4844

@@ -56,14 +52,34 @@
5652
<programlisting role="php">
5753
<![CDATA[
5854
<?php
59-
echo "Code example";
55+
$pdo = new Pdo\Pgsql('pgsql:dbname=test host=localhost', $user, $pass);
56+
57+
$unescapedTableName = 'UnescapedTableName';
58+
$pdo->exec("CREATE TABLE $unescapedTableName ()");
59+
60+
$escapedTableName = $pdo->escapeIdentifier('EscapedTableName');
61+
$pdo->exec("CREATE TABLE $escapedTableName ()");
62+
63+
$statement = $pdo->query(
64+
"SELECT relname FROM pg_stat_user_tables WHERE relname ilike '%tablename'"
65+
);
66+
67+
var_export($statement->fetchAll(PDO::FETCH_COLUMN, 0));
68+
69+
$tableNameWithSymbols = 'Table-Name-With-Symbols';
70+
$pdo->exec("CREATE TABLE $tableNameWithSymbols ()");
6071
?>
6172
]]>
6273
</programlisting>
63-
&example.outputs;
74+
&example.outputs.similar;
6475
<screen>
6576
<![CDATA[
66-
Code example
77+
array (
78+
0 => 'unescapedtablename',
79+
1 => 'EscapedTableName',
80+
)
81+
Fatal error: Uncaught PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "Table"
82+
LINE 1: CREATE TABLE Table-Name-With-Symbols ()
6783
]]>
6884
</screen>
6985
</example>

reference/pdo_pgsql/pdo/pgsql/getpid.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<refentry xml:id="pdo-pgsql.getpid" xmlns="http://docbook.org/ns/docbook">
33
<refnamediv>
44
<refname>Pdo\Pgsql::getPid</refname>
5-
<refpurpose>Get the server PID</refpurpose>
5+
<refpurpose>Get the PID of the backend process handling this connection</refpurpose>
66
</refnamediv>
77

88
<refsect1 role="description">
@@ -12,7 +12,9 @@
1212
<void/>
1313
</methodsynopsis>
1414
<simpara>
15-
Returns the server's PID.
15+
Returns the PID of the backend process handling this connection.
16+
Note that the PID belongs to a process executing on the database server host,
17+
not the local host.
1618
</simpara>
1719
</refsect1>
1820

@@ -24,7 +26,7 @@
2426
<refsect1 role="returnvalues">
2527
&reftitle.returnvalues;
2628
<simpara>
27-
Returns the server's PID as an <type>int</type>.
29+
Returns the PID as an <type>int</type>.
2830
</simpara>
2931
</refsect1>
3032
</refentry>

reference/pdo_pgsql/pdo/pgsql/lobcreate.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</methodsynopsis>
1414
<simpara>
1515
<methodname>Pdo\Pgsql::lobCreate</methodname> creates a large object
16-
and returns the ODI which refers to it.
16+
and returns the OID which refers to it.
1717
It can be opened to read or write data with
1818
<methodname>Pdo\Pgsql::lobOpen</methodname>.
1919
</simpara>
@@ -26,10 +26,11 @@
2626
<simpara>
2727
Large objects are cumbersome to use.
2828
Indeed, it is required that <methodname>Pdo\Pgsql::lobUnlink</methodname>
29-
is called prior to deleting the last row referencing the OID in the whole database.
29+
is called prior to deleting the last row referencing the OID in the entire database;
30+
otherwise, unreferenced large objects will remain on the server indefinitely.
3031
Moreover, large objects have no access controls.
3132
An alternative is the bytea column type, which can be up to 1GB in size,
32-
and this row type transparently manage the storage for optimal row size.
33+
and this column type transparently manages the storage for optimal row size.
3334
</simpara>
3435
<note>
3536
<simpara>

reference/pdo_pgsql/pdo/pgsql/setnoticecallback.xml

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<refentry xml:id="pdo-pgsql.setnoticecallback" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
33
<refnamediv>
44
<refname>Pdo\Pgsql::setNoticeCallback</refname>
5-
<refpurpose>Description</refpurpose>
5+
<refpurpose>Set a callback to handle notice and warning messages generated by the backend</refpurpose>
66
</refnamediv>
77

88
<refsect1 role="description">
@@ -11,7 +11,6 @@
1111
<modifier>public</modifier> <type>void</type><methodname>Pdo\Pgsql::setNoticeCallback</methodname>
1212
<methodparam><type class="union"><type>callable</type><type>null</type></type><parameter>callback</parameter></methodparam>
1313
</methodsynopsis>
14-
&warn.undocumented.func;
1514
<simpara>
1615
Description.
1716
</simpara>
@@ -24,8 +23,25 @@
2423
<term><parameter>callback</parameter></term>
2524
<listitem>
2625
<simpara>
27-
Description.
26+
If &null; is passed, the handler is reset to its default state.
27+
Otherwise, the handler is a callback with the following signature:
2828
</simpara>
29+
30+
<methodsynopsis>
31+
<type>void</type><methodname><replaceable>handler</replaceable></methodname>
32+
<methodparam><type>string</type><parameter>message</parameter></methodparam>
33+
</methodsynopsis>
34+
35+
<variablelist>
36+
<varlistentry>
37+
<term><parameter>message</parameter></term>
38+
<listitem>
39+
<simpara>
40+
A message generated by the backend.
41+
</simpara>
42+
</listitem>
43+
</varlistentry>
44+
<variablelist>
2945
</listitem>
3046
</varlistentry>
3147
</variablelist>
@@ -38,55 +54,36 @@
3854
</simpara>
3955
</refsect1>
4056

41-
<refsect1 role="errors">
42-
&reftitle.errors;
43-
<simpara>
44-
When does this function issue <constant>E_*</constant> level errors,
45-
and/or throw <exceptionname>Exception</exceptionname>s.
46-
</simpara>
47-
</refsect1>
48-
4957
<refsect1 role="examples">
5058
&reftitle.examples;
5159
<example xml:id="pdo-pgsql.setnoticecallback.example.basic">
5260
<title><methodname>Pdo\Pgsql::setNoticeCallback</methodname> example</title>
53-
<simpara>
54-
Description.
55-
</simpara>
5661
<programlisting role="php">
5762
<![CDATA[
5863
<?php
59-
echo "Code example";
64+
<?php
65+
$pdo = new Pdo\Pgsql('pgsql:dbname=test host=localhost', $user, $pass);
66+
67+
$pdo->exec('CREATE TABLE parent(id int primary key)');
68+
$pdo->exec('CREATE TABLE child(id int references parent)');
69+
70+
$pdo->setNoticeCallback(function ($message) {
71+
echo $message;
72+
});
73+
74+
$pdo->exec('TRUNCATE parent CASCADE');
6075
?>
6176
]]>
6277
</programlisting>
63-
&example.outputs;
78+
&example.outputs.similar;
6479
<screen>
6580
<![CDATA[
66-
Code example
81+
NOTICE: truncate cascades to table "child"
6782
]]>
6883
</screen>
6984
</example>
7085
</refsect1>
7186

72-
<refsect1 role="notes">
73-
&reftitle.notes;
74-
<note>
75-
<simpara>
76-
Any notes that don't fit anywhere else should go here.
77-
</simpara>
78-
</note>
79-
</refsect1>
80-
81-
<refsect1 role="seealso">
82-
&reftitle.seealso;
83-
<simplelist>
84-
<member><methodname>ClassName::otherMethodName</methodname></member>
85-
<member><function>some_function</function></member>
86-
<!-- <member><link linkend="some.id.chunk.to.link">something appendix</link></member> -->
87-
</simplelist>
88-
</refsect1>
89-
9087
</refentry>
9188
<!-- Keep this comment at the end of the file
9289
Local variables:

0 commit comments

Comments
 (0)