Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08cd4d9

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

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ PGconn *PQconnectdbParams(const char * const *keywords,
124124
<para>
125125
When <literal>expand_dbname</literal> is non-zero, the
126126
<parameter>dbname</parameter> key word value is allowed to be recognized
127-
as a connection string. More details on the possible formats appear in
127+
as a connection string. Only the first occurrence of
128+
<parameter>dbname</parameter> is expanded this way, any subsequent
129+
<parameter>dbname</parameter> value is processed as plain database name. More
130+
details on the possible connection string formats appear in
128131
<xref linkend="libpq-connstring">.
129132
</para>
130133

‎src/interfaces/libpq/fe-connect.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4393,10 +4393,11 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
43934393
* Defaults are supplied (from a service file, environment variables, etc)
43944394
* for unspecified options, but only if use_defaults is TRUE.
43954395
*
4396-
* If expand_dbname is non-zero, and the value passed for keyword "dbname" is a
4397-
* connection string (as indicated by recognized_connection_string) then parse
4398-
* and process it, overriding any previously processed conflicting
4399-
* keywords. Subsequent keywords will take precedence, however.
4396+
* If expand_dbname is non-zero, and the value passed for the first occurrence
4397+
* of "dbname" keyword is a connection string (as indicated by
4398+
* recognized_connection_string) then parse and process it, overriding any
4399+
* previously processed conflicting keywords. Subsequent keywords will take
4400+
* precedence, however.
44004401
*/
44014402
staticPQconninfoOption*
44024403
conninfo_array_parse(constchar*const*keywords,constchar*const*values,
@@ -4472,7 +4473,7 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
44724473
}
44734474

44744475
/*
4475-
* If we are on the dbname parameter, and we have a parsed
4476+
* If we are on thefirstdbname parameter, and we have a parsed
44764477
* connection string, copy those parameters across, overriding any
44774478
* existing previous settings.
44784479
*/
@@ -4506,6 +4507,12 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
45064507
}
45074508
}
45084509
}
4510+
/*
4511+
* Forget the parsed connection string, so that any subsequent
4512+
* dbname parameters will not be expanded.
4513+
*/
4514+
PQconninfoFree(dbname_options);
4515+
dbname_options=NULL;
45094516
}
45104517
else
45114518
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp