Skip to content

Commit f4db846

Browse files
authored
fix(contrib/drivers/pgsql): connection fails when postgres database password is empty (#3900)
1 parent e7cc2c3 commit f4db846

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

contrib/drivers/pgsql/pgsql_open.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,12 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) {
3434
source, _ = gregex.ReplaceString(`dbname=([\w\.\-]+)+`, "dbname="+config.Name, source)
3535
}
3636
} else {
37+
source = fmt.Sprintf(
38+
"user=%s password='%s' host=%s port=%s sslmode=disable",
39+
config.User, config.Pass, config.Host, config.Port)
40+
3741
if config.Name != "" {
38-
source = fmt.Sprintf(
39-
"user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
40-
config.User, config.Pass, config.Host, config.Port, config.Name,
41-
)
42-
} else {
43-
source = fmt.Sprintf(
44-
"user=%s password=%s host=%s port=%s sslmode=disable",
45-
config.User, config.Pass, config.Host, config.Port,
46-
)
42+
source = fmt.Sprintf("%s dbname=%s", source, config.Name)
4743
}
4844

4945
if config.Namespace != "" {

0 commit comments

Comments
 (0)