summaryrefslogtreecommitdiff
path: root/src/bin/scripts/common.c
diff options
context:
space:
mode:
authorJoe Conway2010-02-05 03:09:05 +0000
committerJoe Conway2010-02-05 03:09:05 +0000
commitf419a82c704ec33fe5b861f914935b233a54bcee (patch)
tree4c32bd4b142b4c76d6fa17e403eaa189df835e7b /src/bin/scripts/common.c
parenta141ec13de1b2ee4ff7ec1e6b0da03ce7eb7dbbb (diff)
Modify recently added PQconnectdbParams() with new argument, expand_dbname.
If expand_dbname is non-zero and dbname contains an = sign, it is taken as a conninfo string in exactly the same way as if it had been passed to PQconnectdb. This is equivalent to the way PQsetdbLogin() works, allowing PQconnectdbParams() to be a complete alternative. Also improve the way the new function is called from psql and replace a previously missed call to PQsetdbLogin() in psql. Additionally use PQconnectdbParams() for pg_dump and friends, and the bin/scripts command line utilities such as vacuumdb, createdb, etc. Finally, update the documentation for the new parameter, as well as the nuances of precedence in cases where key words are repeated or duplicated in the conninfo string.
Diffstat (limited to 'src/bin/scripts/common.c')
-rw-r--r--src/bin/scripts/common.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c
index 27aafa102c4..026eb80a025 100644
--- a/src/bin/scripts/common.c
+++ b/src/bin/scripts/common.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.38 2010/01/02 16:58:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.39 2010/02/05 03:09:05 joe Exp $
*
*-------------------------------------------------------------------------
*/
@@ -108,8 +108,36 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
*/
do
{
+#define PARAMS_ARRAY_SIZE 7
+ const char **keywords = malloc(PARAMS_ARRAY_SIZE * sizeof(*keywords));
+ const char **values = malloc(PARAMS_ARRAY_SIZE * sizeof(*values));
+
+ if (!keywords || !values)
+ {
+ fprintf(stderr, _("%s: out of memory\n"), progname);
+ exit(1);
+ }
+
+ keywords[0] = "host";
+ values[0] = pghost;
+ keywords[1] = "port";
+ values[1] = pgport;
+ keywords[2] = "user";
+ values[2] = pguser;
+ keywords[3] = "password";
+ values[3] = password;
+ keywords[4] = "dbname";
+ values[4] = dbname;
+ keywords[5] = "fallback_application_name";
+ values[5] = progname;
+ keywords[6] = NULL;
+ values[6] = NULL;
+
new_pass = false;
- conn = PQsetdbLogin(pghost, pgport, NULL, NULL, dbname, pguser, password);
+ conn = PQconnectdbParams(keywords, values, true);
+
+ free(keywords);
+ free(values);
if (!conn)
{