@@ -79,9 +79,6 @@ GetConnection(void)
79
79
/*
80
80
* Merge the connection info inputs given in form of connection string,
81
81
* options and default values (dbname=replication, replication=true, etc.)
82
- * Explicitly discard any dbname value in the connection string;
83
- * otherwise, PQconnectdbParams() would interpret that value as being
84
- * itself a connection string.
85
82
*/
86
83
i = 0 ;
87
84
if (connection_string )
@@ -92,18 +89,24 @@ GetConnection(void)
92
89
93
90
for (conn_opt = conn_opts ; conn_opt -> keyword != NULL ; conn_opt ++ )
94
91
{
95
- if (conn_opt -> val != NULL && conn_opt -> val [0 ] != '\0' &&
96
- strcmp (conn_opt -> keyword , "dbname" ) != 0 )
92
+ if (conn_opt -> val != NULL && conn_opt -> val [0 ] != '\0' )
97
93
argcount ++ ;
98
94
}
99
95
100
96
keywords = pg_malloc0 ((argcount + 1 ) * sizeof (* keywords ));
101
97
values = pg_malloc0 ((argcount + 1 ) * sizeof (* values ));
102
98
99
+ /*
100
+ * Set dbname here already, so it can be overridden by a dbname in the
101
+ * connection string.
102
+ */
103
+ keywords [i ] = "dbname" ;
104
+ values [i ] = "replication" ;
105
+ i ++ ;
106
+
103
107
for (conn_opt = conn_opts ; conn_opt -> keyword != NULL ; conn_opt ++ )
104
108
{
105
- if (conn_opt -> val != NULL && conn_opt -> val [0 ] != '\0' &&
106
- strcmp (conn_opt -> keyword , "dbname" ) != 0 )
109
+ if (conn_opt -> val != NULL && conn_opt -> val [0 ] != '\0' )
107
110
{
108
111
keywords [i ] = conn_opt -> keyword ;
109
112
values [i ] = conn_opt -> val ;
@@ -115,11 +118,11 @@ GetConnection(void)
115
118
{
116
119
keywords = pg_malloc0 ((argcount + 1 ) * sizeof (* keywords ));
117
120
values = pg_malloc0 ((argcount + 1 ) * sizeof (* values ));
121
+ keywords [i ] = "dbname" ;
122
+ values [i ] = dbname ;
123
+ i ++ ;
118
124
}
119
125
120
- keywords [i ] = "dbname" ;
121
- values [i ] = dbname == NULL ? "replication" : dbname ;
122
- i ++ ;
123
126
keywords [i ] = "replication" ;
124
127
values [i ] = dbname == NULL ? "true" : "database" ;
125
128
i ++ ;
@@ -171,7 +174,11 @@ GetConnection(void)
171
174
values [i ] = NULL ;
172
175
}
173
176
174
- tmpconn = PQconnectdbParams (keywords , values , true);
177
+ /*
178
+ * Only expand dbname when we did not already parse the argument as a
179
+ * connection string ourselves.
180
+ */
181
+ tmpconn = PQconnectdbParams (keywords , values , !connection_string );
175
182
176
183
/*
177
184
* If there is too little memory even to allocate the PGconn object
0 commit comments