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

Commit 00a4196

Browse files
committed
Add res checking to libpq examples, from Dan Merillat.
1 parent 1b9f24c commit 00a4196

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ main()
16001600

16011601
/* start a transaction block */
16021602
res = PQexec(conn, "BEGIN");
1603-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
1603+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
16041604
{
16051605
fprintf(stderr, "BEGIN command failed\n");
16061606
PQclear(res);
@@ -1618,15 +1618,15 @@ main()
16181618
* databases
16191619
*/
16201620
res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from pg_database");
1621-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
1621+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
16221622
{
16231623
fprintf(stderr, "DECLARE CURSOR command failed\n");
16241624
PQclear(res);
16251625
exit_nicely(conn);
16261626
}
16271627
PQclear(res);
16281628
res = PQexec(conn, "FETCH ALL in mycursor");
1629-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1629+
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
16301630
{
16311631
fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
16321632
PQclear(res);
@@ -1742,7 +1742,7 @@ main()
17421742
}
17431743

17441744
res = PQexec(conn, "LISTEN TBL2");
1745-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
1745+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
17461746
{
17471747
fprintf(stderr, "LISTEN command failed\n");
17481748
PQclear(res);
@@ -1871,7 +1871,7 @@ main()
18711871

18721872
/* start a transaction block */
18731873
res = PQexec(conn, "BEGIN");
1874-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
1874+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
18751875
{
18761876
fprintf(stderr, "BEGIN command failed\n");
18771877
PQclear(res);
@@ -1889,7 +1889,7 @@ main()
18891889
* databases
18901890
*/
18911891
res = PQexec(conn, "DECLARE mycursor BINARY CURSOR FOR select * from test1");
1892-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
1892+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
18931893
{
18941894
fprintf(stderr, "DECLARE CURSOR command failed\n");
18951895
PQclear(res);
@@ -1898,7 +1898,7 @@ main()
18981898
PQclear(res);
18991899

19001900
res = PQexec(conn, "FETCH ALL in mycursor");
1901-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1901+
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
19021902
{
19031903
fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
19041904
PQclear(res);

src/man/libpq.3

Lines changed: 8 additions & 8 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.25 1998/10/14 05:31:50 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/libpq.3,v 1.26 1999/04/17 17:18:41 momjian 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
@@ -975,7 +975,7 @@ main()
975975

976976
/* start a transaction block */
977977
res = PQexec(conn, "BEGIN");
978-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
978+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
979979
{
980980
fprintf(stderr, "BEGIN command failed\\n");
981981
PQclear(res);
@@ -993,7 +993,7 @@ main()
993993
* databases
994994
*/
995995
res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from pg_database");
996-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
996+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
997997
{
998998
fprintf(stderr, "DECLARE CURSOR command failed\\n");
999999
PQclear(res);
@@ -1002,7 +1002,7 @@ main()
10021002
PQclear(res);
10031003

10041004
res = PQexec(conn, "FETCH ALL in mycursor");
1005-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1005+
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
10061006
{
10071007
fprintf(stderr, "FETCH ALL command didn't return tuples properly\\n");
10081008
PQclear(res);
@@ -1115,7 +1115,7 @@ main()
11151115
}
11161116

11171117
res = PQexec(conn, "LISTEN TBL2");
1118-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
1118+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
11191119
{
11201120
fprintf(stderr, "LISTEN command failed\\n");
11211121
PQclear(res);
@@ -1239,7 +1239,7 @@ main()
12391239

12401240
/* start a transaction block */
12411241
res = PQexec(conn, "BEGIN");
1242-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
1242+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
12431243
{
12441244
fprintf(stderr, "BEGIN command failed\\n");
12451245
PQclear(res);
@@ -1257,7 +1257,7 @@ main()
12571257
* databases
12581258
*/
12591259
res = PQexec(conn, "DECLARE mycursor BINARY CURSOR FOR select * from test1");
1260-
if (PQresultStatus(res) != PGRES_COMMAND_OK)
1260+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
12611261
{
12621262
fprintf(stderr, "DECLARE CURSOR command failed\\n");
12631263
PQclear(res);
@@ -1266,7 +1266,7 @@ main()
12661266
PQclear(res);
12671267

12681268
res = PQexec(conn, "FETCH ALL in mycursor");
1269-
if (PQresultStatus(res) != PGRES_TUPLES_OK)
1269+
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
12701270
{
12711271
fprintf(stderr, "FETCH ALL command didn't return tuples properly\\n");
12721272
PQclear(res);

0 commit comments

Comments
 (0)