From 8331c11f3f6d9f4b9a194b928f7d8380e8a16e5b Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 8 Jul 2007 19:07:38 +0000 Subject: 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. --- src/bin/scripts/common.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/bin/scripts/common.c') 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); -- cgit v1.2.3