postgres.git / summary / log / commit / refs

commit    9880fea4fd0003087302be22cd7bbf63c4548c0c
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Tue Nov 25 15:12:07 2014 +0000
First released in: 9.5.0, 9.0.19, 9.1.15, 9.2.10, 9.3.6, 9.4.0

    Allow "dbname" from connection string to be overridden in PQconnectDBParams
    
    If the "dbname" attribute in PQconnectDBParams contained a connection string
    or URI (and expand_dbname = TRUE), the database name from the connection
    string could not be overridden by a subsequent "dbname" keyword in the
    array. That was not intentional; all other options can be overridden.
    Furthermore, any subsequent "dbname" caused the connection string from the
    first dbname value to be processed again, overriding any values for the same
    options that were given between the connection string and the second dbname
    option.
    
    In the passing, clarify in the docs that only the first dbname option in the
    array is parsed as a connection string.
    
    Alex Shulgin. Backpatch to all supported versions.


src/interfaces/libpq/fe-connect.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index d08705f70e8..f24bb03e84b 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -4221,9 +4221,9 @@ conninfo_array_parse(const char **keywords, const char **values, } /* - * If we are on the dbname parameter, and we have a parsed - * conninfo string, copy those parameters across, overriding any - * existing previous settings + * If we are on the first dbname parameter, and we have a parsed + * connection string, copy those parameters across, overriding any + * existing previous settings. */ if (strcmp(pname, "dbname") == 0 && str_options) { @@ -4255,6 +4255,12 @@ conninfo_array_parse(const char **keywords, const char **values, } } } + /* + * Forget the parsed connection string, so that any subsequent + * dbname parameters will not be expanded. + */ + PQconninfoFree(str_options); + str_options = NULL; } else { [parent: 1f35170395b7]