Commit 00a41961 authored by Bruce Momjian's avatar Bruce Momjian

Add res checking to libpq examples, from Dan Merillat.

parent 1b9f24c8
...@@ -1600,7 +1600,7 @@ main() ...@@ -1600,7 +1600,7 @@ main()
/* start a transaction block */ /* start a transaction block */
res = PQexec(conn, "BEGIN"); res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "BEGIN command failed\n"); fprintf(stderr, "BEGIN command failed\n");
PQclear(res); PQclear(res);
...@@ -1618,7 +1618,7 @@ main() ...@@ -1618,7 +1618,7 @@ main()
* databases * databases
*/ */
res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from pg_database"); res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from pg_database");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "DECLARE CURSOR command failed\n"); fprintf(stderr, "DECLARE CURSOR command failed\n");
PQclear(res); PQclear(res);
...@@ -1626,7 +1626,7 @@ main() ...@@ -1626,7 +1626,7 @@ main()
} }
PQclear(res); PQclear(res);
res = PQexec(conn, "FETCH ALL in mycursor"); res = PQexec(conn, "FETCH ALL in mycursor");
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, "FETCH ALL command didn't return tuples properly\n"); fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
PQclear(res); PQclear(res);
...@@ -1742,7 +1742,7 @@ main() ...@@ -1742,7 +1742,7 @@ main()
} }
res = PQexec(conn, "LISTEN TBL2"); res = PQexec(conn, "LISTEN TBL2");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "LISTEN command failed\n"); fprintf(stderr, "LISTEN command failed\n");
PQclear(res); PQclear(res);
...@@ -1871,7 +1871,7 @@ main() ...@@ -1871,7 +1871,7 @@ main()
/* start a transaction block */ /* start a transaction block */
res = PQexec(conn, "BEGIN"); res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "BEGIN command failed\n"); fprintf(stderr, "BEGIN command failed\n");
PQclear(res); PQclear(res);
...@@ -1889,7 +1889,7 @@ main() ...@@ -1889,7 +1889,7 @@ main()
* databases * databases
*/ */
res = PQexec(conn, "DECLARE mycursor BINARY CURSOR FOR select * from test1"); res = PQexec(conn, "DECLARE mycursor BINARY CURSOR FOR select * from test1");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "DECLARE CURSOR command failed\n"); fprintf(stderr, "DECLARE CURSOR command failed\n");
PQclear(res); PQclear(res);
...@@ -1898,7 +1898,7 @@ main() ...@@ -1898,7 +1898,7 @@ main()
PQclear(res); PQclear(res);
res = PQexec(conn, "FETCH ALL in mycursor"); res = PQexec(conn, "FETCH ALL in mycursor");
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, "FETCH ALL command didn't return tuples properly\n"); fprintf(stderr, "FETCH ALL command didn't return tuples properly\n");
PQclear(res); PQclear(res);
......
.\" This is -*-nroff-*- .\" This is -*-nroff-*-
.\" XXX standard disclaimer belongs here.... .\" XXX standard disclaimer belongs here....
.\" $Header: /cvsroot/pgsql/src/man/Attic/libpq.3,v 1.25 1998/10/14 05:31:50 momjian Exp $ .\" $Header: /cvsroot/pgsql/src/man/Attic/libpq.3,v 1.26 1999/04/17 17:18:41 momjian Exp $
.TH LIBPQ INTRO 08/08/98 PostgreSQL PostgreSQL .TH LIBPQ INTRO 08/08/98 PostgreSQL PostgreSQL
.SH DESCRIPTION .SH DESCRIPTION
Current documentation for this topic is available in the new Programmer's Guide Current documentation for this topic is available in the new Programmer's Guide
...@@ -975,7 +975,7 @@ main() ...@@ -975,7 +975,7 @@ main()
/* start a transaction block */ /* start a transaction block */
res = PQexec(conn, "BEGIN"); res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "BEGIN command failed\\n"); fprintf(stderr, "BEGIN command failed\\n");
PQclear(res); PQclear(res);
...@@ -993,7 +993,7 @@ main() ...@@ -993,7 +993,7 @@ main()
* databases * databases
*/ */
res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from pg_database"); res = PQexec(conn, "DECLARE mycursor CURSOR FOR select * from pg_database");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "DECLARE CURSOR command failed\\n"); fprintf(stderr, "DECLARE CURSOR command failed\\n");
PQclear(res); PQclear(res);
...@@ -1002,7 +1002,7 @@ main() ...@@ -1002,7 +1002,7 @@ main()
PQclear(res); PQclear(res);
res = PQexec(conn, "FETCH ALL in mycursor"); res = PQexec(conn, "FETCH ALL in mycursor");
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, "FETCH ALL command didn't return tuples properly\\n"); fprintf(stderr, "FETCH ALL command didn't return tuples properly\\n");
PQclear(res); PQclear(res);
...@@ -1115,7 +1115,7 @@ main() ...@@ -1115,7 +1115,7 @@ main()
} }
res = PQexec(conn, "LISTEN TBL2"); res = PQexec(conn, "LISTEN TBL2");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "LISTEN command failed\\n"); fprintf(stderr, "LISTEN command failed\\n");
PQclear(res); PQclear(res);
...@@ -1239,7 +1239,7 @@ main() ...@@ -1239,7 +1239,7 @@ main()
/* start a transaction block */ /* start a transaction block */
res = PQexec(conn, "BEGIN"); res = PQexec(conn, "BEGIN");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "BEGIN command failed\\n"); fprintf(stderr, "BEGIN command failed\\n");
PQclear(res); PQclear(res);
...@@ -1257,7 +1257,7 @@ main() ...@@ -1257,7 +1257,7 @@ main()
* databases * databases
*/ */
res = PQexec(conn, "DECLARE mycursor BINARY CURSOR FOR select * from test1"); res = PQexec(conn, "DECLARE mycursor BINARY CURSOR FOR select * from test1");
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
{ {
fprintf(stderr, "DECLARE CURSOR command failed\\n"); fprintf(stderr, "DECLARE CURSOR command failed\\n");
PQclear(res); PQclear(res);
...@@ -1266,7 +1266,7 @@ main() ...@@ -1266,7 +1266,7 @@ main()
PQclear(res); PQclear(res);
res = PQexec(conn, "FETCH ALL in mycursor"); res = PQexec(conn, "FETCH ALL in mycursor");
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
fprintf(stderr, "FETCH ALL command didn't return tuples properly\\n"); fprintf(stderr, "FETCH ALL command didn't return tuples properly\\n");
PQclear(res); PQclear(res);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment