Skip to content

Commit 88ff88b

Browse files
authored
Fix FormatDSN missing ConnectionAttributes (#1619)
Fix #1618
1 parent c879816 commit 88ff88b

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Artur Melanchyk <[email protected]>
2424
Asta Xie <xiemengjun at gmail.com>
2525
B Lamarche <blam413 at gmail.com>
2626
Bes Dollma <[email protected]>
27+
Bogdan Constantinescu <bog.con.bc at gmail.com>
2728
Brian Hendriks <brian at dolthub.com>
2829
Bulat Gaifullin <gaifullinbf at gmail.com>
2930
Caine Jette <jette at alum.mit.edu>

dsn.go

+4
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ func (cfg *Config) FormatDSN() string {
322322
writeDSNParam(&buf, &hasParam, "columnsWithAlias", "true")
323323
}
324324

325+
if cfg.ConnectionAttributes != "" {
326+
writeDSNParam(&buf, &hasParam, "connectionAttributes", url.QueryEscape(cfg.ConnectionAttributes))
327+
}
328+
325329
if cfg.compress {
326330
writeDSNParam(&buf, &hasParam, "compress", "true")
327331
}

dsn_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ var testDSNs = []struct {
7777
}, {
7878
"user:password@/dbname?loc=UTC&timeout=30s&parseTime=true&timeTruncate=1h",
7979
&Config{User: "user", Passwd: "password", Net: "tcp", Addr: "127.0.0.1:3306", DBName: "dbname", Loc: time.UTC, Timeout: 30 * time.Second, ParseTime: true, MaxAllowedPacket: defaultMaxAllowedPacket, Logger: defaultLogger, AllowNativePasswords: true, CheckConnLiveness: true, timeTruncate: time.Hour},
80+
}, {
81+
"foo:bar@tcp(192.168.1.50:3307)/baz?timeout=10s&connectionAttributes=program_name:MySQLGoDriver%2FTest,program_version:1.2.3",
82+
&Config{User: "foo", Passwd: "bar", Net: "tcp", Addr: "192.168.1.50:3307", DBName: "baz", Loc: time.UTC, Timeout: 10 * time.Second, MaxAllowedPacket: defaultMaxAllowedPacket, Logger: defaultLogger, AllowNativePasswords: true, CheckConnLiveness: true, ConnectionAttributes: "program_name:MySQLGoDriver/Test,program_version:1.2.3"},
8083
},
8184
}
8285

@@ -109,7 +112,8 @@ func TestDSNParserInvalid(t *testing.T) {
109112
"User:pass@tcp(1.2.3.4:3306)", // no trailing slash
110113
"net()/", // unknown default addr
111114
"user:pass@tcp(127.0.0.1:3306)/db/name", // invalid dbname
112-
"user:password@/dbname?allowFallbackToPlaintext=PREFERRED", // wrong bool flag
115+
"user:password@/dbname?allowFallbackToPlaintext=PREFERRED", // wrong bool flag
116+
"user:password@/dbname?connectionAttributes=attr1:/unescaped/value", // unescaped
113117
//"/dbname?arg=/some/unescaped/path",
114118
}
115119

0 commit comments

Comments
 (0)