Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5690b1a

Browse files
committed
Minor updates to libpq documentation.
1 parent 3de11d6 commit 5690b1a

File tree

2 files changed

+92
-36
lines changed

2 files changed

+92
-36
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,24 @@ PGRES_FATAL_ERROR
430430
</Para>
431431
</ListItem>
432432

433+
<ListItem>
434+
<Para>
435+
<Function>PQresStatus</Function>
436+
Converts the enumerated type returned by PQresultStatus into
437+
a string constant describing the status code.
438+
<synopsis>
439+
const char *PQresStatus(ExecStatusType status);
440+
</synopsis>
441+
Older code may perform this same operation by direct access to a constant
442+
string array inside libpq,
443+
<synopsis>
444+
extern const char * const pgresStatus[];
445+
</synopsis>
446+
However, using the function is recommended instead, since it is more portable
447+
and will not fail on out-of-range values.
448+
</Para>
449+
</ListItem>
450+
433451
<ListItem>
434452
<Para>
435453
<Function>PQresultErrorMessage</Function>
@@ -910,8 +928,7 @@ terms is readable data on the file descriptor identified by PQsocket.
910928
When the main loop detects input ready, it should call PQconsumeInput
911929
to read the input. It can then call PQisBusy, followed by PQgetResult
912930
if PQisBusy returns FALSE. It can also call PQnotifies to detect NOTIFY
913-
messages (see "Asynchronous Notification", below). An example is given
914-
in the sample programs section.
931+
messages (see "Asynchronous Notification", below).
915932
</Para>
916933

917934
<Para>
@@ -1230,10 +1247,10 @@ int PQendcopy(PGconn *conn);
12301247
As an example:
12311248

12321249
<ProgramListing>
1233-
PQexec(conn, "create table foo (a int4, b char16, d float8)");
1250+
PQexec(conn, "create table foo (a int4, b char(16), d float8)");
12341251
PQexec(conn, "copy foo from stdin");
1235-
PQputline(conn, "3&lt;TAB&gt;hello world&lt;TAB&gt;4.5\n");
1236-
PQputline(conn,"4&lt;TAB&gt;goodbye world&lt;TAB&gt;7.11\n");
1252+
PQputline(conn, "3\thello world\t4.5\n");
1253+
PQputline(conn,"4\tgoodbye world\t7.11\n");
12371254
...
12381255
PQputline(conn,"\\.\n");
12391256
PQendcopy(conn);
@@ -1671,22 +1688,25 @@ main()
16711688
<Para>
16721689
<ProgramListing>
16731690
/*
1674-
* testlibpq2.c Test of the asynchronous notification interface
1675-
*
1676-
* populate a database with the following:
1691+
* testlibpq2.c
1692+
* Test of the asynchronous notification interface
16771693
*
1678-
* CREATE TABLE TBL1 (i int4);
1694+
* Start this program, then from psql in another window do
1695+
* NOTIFY TBL2;
16791696
*
1680-
* CREATE TABLE TBL2 (i int4);
1697+
* Or, if you want to get fancy, try this:
1698+
* Populate a database with the following:
16811699
*
1682-
* CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values
1683-
* (new.i); NOTIFY TBL2];
1700+
* CREATE TABLE TBL1 (i int4);
16841701
*
1685-
* Then start up this program After the program has begun, do
1702+
* CREATE TABLE TBL2 (i int4);
16861703
*
1687-
* INSERT INTO TBL1 values (10);
1704+
* CREATE RULE r1 AS ON INSERT TO TBL1 DO
1705+
* (INSERT INTO TBL2 values (new.i); NOTIFY TBL2);
16881706
*
1707+
* and do
16891708
*
1709+
* INSERT INTO TBL1 values (10);
16901710
*
16911711
*/
16921712
#include &lt;stdio.h&gt;

src/man/libpq.3

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/libpq.3,v 1.26 1999/04/17 17:18:41 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/libpq.3,v 1.27 1999/05/21 00:36:01 tgl Exp $
44
.TH LIBPQ INTRO 08/08/98 PostgreSQL PostgreSQL
55
.SH DESCRIPTION
66
Current documentation for this topic is available in the new Programmer's Guide
@@ -266,9 +266,44 @@ PGRES_NONFATAL_ERROR,
266266
PGRES_FATAL_ERROR
267267
.fi
268268
.IP
269-
If the result status is PGRES_TUPLES_OK, then the following routines can
270-
be used to retrieve the tuples returned by the query.
269+
If the result status is PGRES_TUPLES_OK, then the
270+
routines described below can be used to retrieve the
271+
tuples returned by the query. Note that a SELECT that
272+
happens to retrieve zero tuples still shows PGRES_TUPLES_OK.
273+
PGRES_COMMAND_OK is for commands that can never return tuples.
274+
.PP
275+
.B PQresStatus
276+
.IP
277+
Converts the enumerated type returned by PQresultStatus into
278+
a string constant describing the status code.
279+
.nf
280+
const char *PQresStatus(ExecStatusType status);
281+
.fi
282+
.IP
283+
Older code may perform this same operation by direct access to a constant
284+
string array inside libpq,
285+
.nf
286+
extern const char * const pgresStatus[];
287+
.fi
288+
.IP
289+
However, using the function is recommended instead, since it is more portable
290+
and will not fail on out-of-range values.
291+
.PP
292+
.B PQresultErrorMessage
293+
.IP
294+
returns the error message associated with the query, or an empty string
295+
if there was no error.
296+
.nf
297+
const char *PQresultErrorMessage(PGresult *res);
298+
.fi
271299
.IP
300+
Immediately following a PQexec or PQgetResult call, PQerrorMessage
301+
(on the connection) will return the same string as PQresultErrorMessage
302+
(on the result). However, a PGresult will retain its error message
303+
until destroyed, whereas the connection's error message will change when
304+
subsequent operations are done. Use PQresultErrorMessage when you want to
305+
know the status associated with a particular PGresult; use PQerrorMessage
306+
when you want to know the status from the latest operation on the connection.
272307

273308
.B PQntuples
274309
returns the number of tuples (instances) in the query result.
@@ -558,8 +593,7 @@ terms is readable data on the file descriptor identified by PQsocket.
558593
When the main loop detects input ready, it should call PQconsumeInput
559594
to read the input. It can then call PQisBusy, followed by PQgetResult
560595
if PQisBusy returns FALSE. It can also call PQnotifies to detect NOTIFY
561-
messages (see "Asynchronous Notification", below). An example is given
562-
in the sample programs section.
596+
messages (see "Asynchronous Notification", below).
563597

564598
.PP
565599
A frontend that uses PQsendQuery/PQgetResult can also attempt to cancel
@@ -789,12 +823,12 @@ int PQendcopy(PGconn *conn);
789823
.fi
790824
As an example:
791825
.nf
792-
PQexec(conn, "create table foo (a int4, b name, d float8)");
826+
PQexec(conn, "create table foo (a int4, b char(16), d float8)");
793827
PQexec(conn, "copy foo from stdin");
794-
PQputline(conn, "3<TAB>hello world<TAB>4.5\en");
795-
PQputline(conn,"4<TAB>goodbye world<TAB>7.11\en");
828+
PQputline(conn, "3\ethello world\et4.5\en");
829+
PQputline(conn,"4\etgoodbye world\et7.11\en");
796830
\&...
797-
PQputline(conn,"\\.\en");
831+
PQputline(conn,"\e\e.\en");
798832
PQendcopy(conn);
799833
.fi
800834
.PP
@@ -1048,20 +1082,22 @@ main()
10481082
* testlibpq2.c
10491083
* Test of the asynchronous notification interface
10501084
*
1051-
populate a database with the following:
1052-
1053-
CREATE TABLE TBL1 (i int4);
1054-
1055-
CREATE TABLE TBL2 (i int4);
1056-
1057-
CREATE RULE r1 AS ON INSERT TO TBL1 DO [INSERT INTO TBL2 values (new.i); NOTIFY TBL2];
1058-
1059-
* Then start up this program
1060-
* After the program has begun, do
1061-
1062-
INSERT INTO TBL1 values (10);
1063-
1085+
* Start this program, then from psql in another window do
1086+
* NOTIFY TBL2;
1087+
*
1088+
* Or, if you want to get fancy, try this:
1089+
* Populate a database with the following:
1090+
*
1091+
* CREATE TABLE TBL1 (i int4);
1092+
*
1093+
* CREATE TABLE TBL2 (i int4);
1094+
*
1095+
* CREATE RULE r1 AS ON INSERT TO TBL1 DO
1096+
* (INSERT INTO TBL2 values (new.i); NOTIFY TBL2);
1097+
*
1098+
* and do
10641099
*
1100+
* INSERT INTO TBL1 values (10);
10651101
*
10661102
*/
10671103
#include <stdio.h>

0 commit comments

Comments
 (0)