summaryrefslogtreecommitdiff
path: root/src/bin/scripts/common.c
diff options
context:
space:
mode:
authorTom Lane2007-07-08 19:07:38 +0000
committerTom Lane2007-07-08 19:07:38 +0000
commit8331c11f3f6d9f4b9a194b928f7d8380e8a16e5b (patch)
treef7788bd98012ec1eec299d74e4b08d17a891d6ae /src/bin/scripts/common.c
parent5f7b1f8d9d835c6869637f0b0df184e6fc5e0d03 (diff)
Get rid of client-code dependencies on the exact text of the no-password
error message, by using PQconnectionUsedPassword() instead. Someday we might be able to localize that error message, but not until this coding technique has disappeared everywhere.
Diffstat (limited to 'src/bin/scripts/common.c')
-rw-r--r--src/bin/scripts/common.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c
index dfe9a52be43..6903fa6e033 100644
--- a/src/bin/scripts/common.c
+++ b/src/bin/scripts/common.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.26 2007/04/09 18:21:22 mha Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.27 2007/07/08 19:07:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -100,7 +100,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
{
PGconn *conn;
char *password = NULL;
- bool need_pass = false;
+ bool new_pass;
if (require_password)
password = simple_prompt("Password: ", 100, false);
@@ -111,7 +111,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
*/
do
{
- need_pass = false;
+ new_pass = false;
conn = PQsetdbLogin(pghost, pgport, NULL, NULL, dbname, pguser, password);
if (!conn)
@@ -122,16 +122,15 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
}
if (PQstatus(conn) == CONNECTION_BAD &&
- strcmp(PQerrorMessage(conn), PQnoPasswordSupplied) == 0 &&
+ PQconnectionUsedPassword(conn) &&
+ password == NULL &&
!feof(stdin))
{
PQfinish(conn);
- need_pass = true;
- free(password);
- password = NULL;
password = simple_prompt("Password: ", 100, false);
+ new_pass = true;
}
- } while (need_pass);
+ } while (new_pass);
if (password)
free(password);