diff options
author | Joe Conway <mail@joeconway.com> | 2010-01-28 06:28:26 +0000 |
---|---|---|
committer | Joe Conway <mail@joeconway.com> | 2010-01-28 06:28:26 +0000 |
commit | e3f36838e5b2666a15286b137bb11f35a7245848 (patch) | |
tree | bcdcad4eabf09755a2835985265332900c2cecb4 /src/bin/psql/startup.c | |
parent | 83cb7da7dcd11f658a7fc4aff198923bf76ff8f5 (diff) |
Introduce two new libpq connection functions, PQconnectdbParams and
PQconnectStartParams. These are analogous to PQconnectdb and PQconnectStart
respectively. They differ from the legacy functions in that they accept
two NULL-terminated arrays, keywords and values, rather than conninfo
strings. This avoids the need to build the conninfo string in cases
where it might be inconvenient to do so. Includes documentation.
Also modify psql to utilize PQconnectdbParams rather than PQsetdbLogin.
This allows the new config parameter application_name to be set, which
in turn is displayed in the pg_stat_activity view and included in CSV
log entries. This will also ensure both new functions get regularly
exercised.
Patch by Guillaume Lelarge with review and minor adjustments by
Joe Conway.
Diffstat (limited to 'src/bin/psql/startup.c')
-rw-r--r-- | src/bin/psql/startup.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 6ffe593786a..b29c84fdaec 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2010, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.158 2010/01/02 16:57:59 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.159 2010/01/28 06:28:26 joe Exp $ */ #include "postgres_fe.h" @@ -90,6 +90,8 @@ main(int argc, char *argv[]) char *password = NULL; char *password_prompt = NULL; bool new_pass; + const char *keywords[] = {"host","port","dbname","user", + "password","application_name",NULL}; set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("psql")); @@ -171,11 +173,20 @@ main(int argc, char *argv[]) /* loop until we have a password if requested by backend */ do { - new_pass = false; - pset.db = PQsetdbLogin(options.host, options.port, NULL, NULL, - options.action == ACT_LIST_DB && options.dbname == NULL ? - "postgres" : options.dbname, - options.username, password); + const char *values[] = { + options.host, + options.port, + (options.action == ACT_LIST_DB && + options.dbname == NULL) ? "postgres" : options.dbname, + options.username, + password, + pset.progname, + NULL + }; + + new_pass = false; + + pset.db = PQconnectdbParams(keywords, values); if (PQstatus(pset.db) == CONNECTION_BAD && PQconnectionNeedsPassword(pset.db) && |