Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8bbfa16

Browse files
committed
Don't assume PQdb() will return a valid result from a failed connection.
1 parentbbd1e1c commit8bbfa16

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.164 2004/09/26 22:51:49 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.165 2004/10/01 17:34:17 tgl Exp $
33
-->
44

55
<chapter id="libpq">
@@ -3979,8 +3979,8 @@ main(int argc, char **argv)
39793979
/* Check to see that the backend connection was successfully made */
39803980
if (PQstatus(conn) != CONNECTION_OK)
39813981
{
3982-
fprintf(stderr, "Connection to database'%s' failed.\n", PQdb(conn));
3983-
fprintf(stderr, "%s", PQerrorMessage(conn));
3982+
fprintf(stderr, "Connection to databasefailed: %s",
3983+
PQerrorMessage(conn));
39843984
exit_nicely(conn);
39853985
}
39863986

@@ -4125,8 +4125,8 @@ main(int argc, char **argv)
41254125
/* Check to see that the backend connection was successfully made */
41264126
if (PQstatus(conn) != CONNECTION_OK)
41274127
{
4128-
fprintf(stderr, "Connection to database'%s' failed.\n", PQdb(conn));
4129-
fprintf(stderr, "%s", PQerrorMessage(conn));
4128+
fprintf(stderr, "Connection to databasefailed: %s",
4129+
PQerrorMessage(conn));
41304130
exit_nicely(conn);
41314131
}
41324132

@@ -4267,8 +4267,8 @@ main(int argc, char **argv)
42674267
/* Check to see that the backend connection was successfully made */
42684268
if (PQstatus(conn) != CONNECTION_OK)
42694269
{
4270-
fprintf(stderr, "Connection to database'%s' failed.\n", PQdb(conn));
4271-
fprintf(stderr, "%s", PQerrorMessage(conn));
4270+
fprintf(stderr, "Connection to databasefailed: %s",
4271+
PQerrorMessage(conn));
42724272
exit_nicely(conn);
42734273
}
42744274

‎src/test/examples/testlibpq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ main(int argc, char **argv)
4141
/* Check to see that the backend connection was successfully made */
4242
if (PQstatus(conn)!=CONNECTION_OK)
4343
{
44-
fprintf(stderr,"Connection to database'%s' failed.\n",PQdb(conn));
45-
fprintf(stderr,"%s",PQerrorMessage(conn));
44+
fprintf(stderr,"Connection to databasefailed: %s",
45+
PQerrorMessage(conn));
4646
exit_nicely(conn);
4747
}
4848

‎src/test/examples/testlibpq2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ main(int argc, char **argv)
6161
/* Check to see that the backend connection was successfully made */
6262
if (PQstatus(conn)!=CONNECTION_OK)
6363
{
64-
fprintf(stderr,"Connection to database'%s' failed.\n",PQdb(conn));
65-
fprintf(stderr,"%s",PQerrorMessage(conn));
64+
fprintf(stderr,"Connection to databasefailed: %s",
65+
PQerrorMessage(conn));
6666
exit_nicely(conn);
6767
}
6868

‎src/test/examples/testlibpq3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ main(int argc, char **argv)
6666
/* Check to see that the backend connection was successfully made */
6767
if (PQstatus(conn)!=CONNECTION_OK)
6868
{
69-
fprintf(stderr,"Connection to database'%s' failed.\n",PQdb(conn));
70-
fprintf(stderr,"%s",PQerrorMessage(conn));
69+
fprintf(stderr,"Connection to databasefailed: %s",
70+
PQerrorMessage(conn));
7171
exit_nicely(conn);
7272
}
7373

‎src/test/examples/testlibpq4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ static void
2222
check_conn(PGconn*conn,constchar*dbName)
2323
{
2424
/* check to see that the backend connection was successfully made */
25-
if (PQstatus(conn)==CONNECTION_BAD)
25+
if (PQstatus(conn)!=CONNECTION_OK)
2626
{
27-
fprintf(stderr,"Connection to database'%s' failed.\n",dbName);
28-
fprintf(stderr,"%s",PQerrorMessage(conn));
27+
fprintf(stderr,"Connection to database\"%s\" failed: %s",
28+
dbName,PQerrorMessage(conn));
2929
exit(1);
3030
}
3131
}

‎src/test/examples/testlo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/test/examples/testlo.c,v 1.23 2004/09/22 05:12:45 neilc Exp $
11+
* $PostgreSQL: pgsql/src/test/examples/testlo.c,v 1.24 2004/10/01 17:34:19 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -225,10 +225,10 @@ main(int argc, char **argv)
225225
conn=PQsetdb(NULL,NULL,NULL,NULL,database);
226226

227227
/* check to see that the backend connection was successfully made */
228-
if (PQstatus(conn)==CONNECTION_BAD)
228+
if (PQstatus(conn)!=CONNECTION_OK)
229229
{
230-
fprintf(stderr,"Connection to database'%s' failed.\n",database);
231-
fprintf(stderr,"%s",PQerrorMessage(conn));
230+
fprintf(stderr,"Connection to databasefailed: %s",
231+
PQerrorMessage(conn));
232232
exit_nicely(conn);
233233
}
234234

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp