8000 Allow "dbname" from connection string to be overridden in PQconnectDB… · leelingco/postgres@95be343 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95be343

Browse files
committed
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.
1 parent 5053ad2 commit 95be343

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,9 +4460,9 @@ conninfo_array_parse(const char **keywords, const char **values,
44604460
}
44614461

44624462
/*
4463-
* If we are on the dbname parameter, and we have a parsed
4464-
* conninfo string, copy those parameters across, overriding any
4465-
* existing previous settings
4463+
* If we are on the first dbname parameter, and we have a parsed
4464+
* connection string, copy those parameters across, overriding any
4465+
* existing previous settings.
44664466
*/
44674467
if (strcmp(pname, "dbname") == 0 && str_options)
44684468
{
@@ -4494,6 +4494,12 @@ conninfo_array_parse(const char **keywords, const char **values,
44944494
}
44954495
}
44964496
}
4497+
/*
4498+
* Forget the parsed connection string, so that any subsequent
4499+
* dbname parameters will not be expanded.
4500+
*/
4501+
PQconninfoFree(str_options);
4502+
str_options = NULL;
44974503
}
44984504
else
44994505
{

0 commit comments

Comments
 (0)
0