summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2004-10-01 17:34:19 +0000
committerTom Lane2004-10-01 17:34:19 +0000
commit307161e21edc92cda6a9b70521606e98b0f7cf74 (patch)
tree2dd5fe89b30f85a40ee996ee3eaff7214c5a4526
parent269160c6881fd5f030696c44ed191970ae98a527 (diff)
Don't assume PQdb() will return a valid result from a failed connection.
-rw-r--r--doc/src/sgml/libpq.sgml12
-rw-r--r--src/test/examples/testlibpq.c4
-rw-r--r--src/test/examples/testlibpq2.c4
-rw-r--r--src/test/examples/testlibpq3.c4
-rw-r--r--src/test/examples/testlibpq4.c6
-rw-r--r--src/test/examples/testlo.c6
6 files changed, 18 insertions, 18 deletions
diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml
index de7101e591..4619167e40 100644
--- a/doc/src/sgml/libpq.sgml
+++ b/doc/src/sgml/libpq.sgml
@@ -3979,8 +3979,8 @@ main(int argc, char **argv)
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
- fprintf(stderr, "Connection to database '%s' failed.\n", PQdb(conn));
- fprintf(stderr, "%s", PQerrorMessage(conn));
+ fprintf(stderr, "Connection to database failed: %s",
+ PQerrorMessage(conn));
exit_nicely(conn);
}
@@ -4125,8 +4125,8 @@ main(int argc, char **argv)
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
- fprintf(stderr, "Connection to database '%s' failed.\n", PQdb(conn));
- fprintf(stderr, "%s", PQerrorMessage(conn));
+ fprintf(stderr, "Connection to database failed: %s",
+ PQerrorMessage(conn));
exit_nicely(conn);
}
@@ -4267,8 +4267,8 @@ main(int argc, char **argv)
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
- fprintf(stderr, "Connection to database '%s' failed.\n", PQdb(conn));
- fprintf(stderr, "%s", PQerrorMessage(conn));
+ fprintf(stderr, "Connection to database failed: %s",
+ PQerrorMessage(conn));
exit_nicely(conn);
}
diff --git a/src/test/examples/testlibpq.c b/src/test/examples/testlibpq.c
index f650118a29..b9d396a2dc 100644
--- a/src/test/examples/testlibpq.c
+++ b/src/test/examples/testlibpq.c
@@ -41,8 +41,8 @@ main(int argc, char **argv)
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
- fprintf(stderr, "Connection to database '%s' failed.\n", PQdb(conn));
- fprintf(stderr, "%s", PQerrorMessage(conn));
+ fprintf(stderr, "Connection to database failed: %s",
+ PQerrorMessage(conn));
exit_nicely(conn);
}
diff --git a/src/test/examples/testlibpq2.c b/src/test/examples/testlibpq2.c
index 928ffbb5b4..1cb7616f24 100644
--- a/src/test/examples/testlibpq2.c
+++ b/src/test/examples/testlibpq2.c
@@ -61,8 +61,8 @@ main(int argc, char **argv)
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
- fprintf(stderr, "Connection to database '%s' failed.\n", PQdb(conn));
- fprintf(stderr, "%s", PQerrorMessage(conn));
+ fprintf(stderr, "Connection to database failed: %s",
+ PQerrorMessage(conn));
exit_nicely(conn);
}
diff --git a/src/test/examples/testlibpq3.c b/src/test/examples/testlibpq3.c
index 43c1068a45..7036d3e81f 100644
--- a/src/test/examples/testlibpq3.c
+++ b/src/test/examples/testlibpq3.c
@@ -66,8 +66,8 @@ main(int argc, char **argv)
/* Check to see that the backend connection was successfully made */
if (PQstatus(conn) != CONNECTION_OK)
{
- fprintf(stderr, "Connection to database '%s' failed.\n", PQdb(conn));
- fprintf(stderr, "%s", PQerrorMessage(conn));
+ fprintf(stderr, "Connection to database failed: %s",
+ PQerrorMessage(conn));
exit_nicely(conn);
}
diff --git a/src/test/examples/testlibpq4.c b/src/test/examples/testlibpq4.c
index 0eda55352e..977e4edd99 100644
--- a/src/test/examples/testlibpq4.c
+++ b/src/test/examples/testlibpq4.c
@@ -22,10 +22,10 @@ static void
check_conn(PGconn *conn, const char *dbName)
{
/* check to see that the backend connection was successfully made */
- if (PQstatus(conn) == CONNECTION_BAD)
+ if (PQstatus(conn) != CONNECTION_OK)
{
- fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
- fprintf(stderr, "%s", PQerrorMessage(conn));
+ fprintf(stderr, "Connection to database \"%s\" failed: %s",
+ dbName, PQerrorMessage(conn));
exit(1);
}
}
diff --git a/src/test/examples/testlo.c b/src/test/examples/testlo.c
index 1f764bfbc0..4336c5adfd 100644
--- a/src/test/examples/testlo.c
+++ b/src/test/examples/testlo.c
@@ -225,10 +225,10 @@ main(int argc, char **argv)
conn = PQsetdb(NULL, NULL, NULL, NULL, database);
/* check to see that the backend connection was successfully made */
- if (PQstatus(conn) == CONNECTION_BAD)
+ if (PQstatus(conn) != CONNECTION_OK)
{
- fprintf(stderr, "Connection to database '%s' failed.\n", database);
- fprintf(stderr, "%s", PQerrorMessage(conn));
+ fprintf(stderr, "Connection to database failed: %s",
+ PQerrorMessage(conn));
exit_nicely(conn);
}