diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2006-12-19 01:53:36 +0000 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2006-12-19 01:53:36 +0000 |
commit | 5133dd786b0041114ba4da6b174ade8c33917e68 (patch) | |
tree | 28aebae4a92136e92ebf1b3b390d416c823a2221 /src/interfaces/libpq/fe-connect.c | |
parent | 93b4f0ff7711d42b8c10e48b0a7575e2847e30b3 (diff) | |
download | postgresql-5133dd786b0041114ba4da6b174ade8c33917e68.tar.gz postgresql-5133dd786b0041114ba4da6b174ade8c33917e68.zip |
Interpret a dbName param to PQsetdbLogin as a conninfo string if it contains an = sign. Tom Lane and Andrew Dunstan.
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index eb6ab6127df..5b29b60a6e1 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.339 2006/11/21 16:28:00 tgl Exp $ + * $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.340 2006/12/19 01:53:36 adunstan Exp $ * *------------------------------------------------------------------------- */ @@ -574,16 +574,36 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, conn = makeEmptyPGconn(); if (conn == NULL) return NULL; - - /* - * Parse an empty conninfo string in order to set up the same defaults - * that PQconnectdb() would use. - */ - if (!connectOptions1(conn, "")) - return conn; - - /* - * Absorb specified options into conn structure, overriding defaults + /* + * If the dbName parameter contains '=', assume it's a conninfo + * string. + */ + if (dbName && strchr(dbName,'=')) + { + if (!connectOptions1(conn, dbName)) + return conn; + } + else + { + /* + * Old-style path: first, parse an empty conninfo string in + * order to set up the same defaults that PQconnectdb() would use. + */ + if (!connectOptions1(conn, "")) + return conn; + + /* Insert dbName parameter value into struct */ + if (dbName && dbName[0] != '\0') + { + if (conn->dbName) + free(conn->dbName); + conn->dbName = strdup(dbName); + } + } + + /* + * Insert remaining parameters into struct, overriding defaults + * (as well as any conflicting data from dbName taken as a conninfo). */ if (pghost && pghost[0] != '\0') { @@ -613,13 +633,6 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, conn->pgtty = strdup(pgtty); } - if (dbName && dbName[0] != '\0') - { - if (conn->dbName) - free(conn->dbName); - conn->dbName = strdup(dbName); - } - if (login && login[0] != '\0') { if (conn->pguser) |