Skip to content

Commit fb025ae

Browse files
committed
Merge branch 'master' into go1.24-is-released
2 parents 6926e0a + 21ef4c6 commit fb025ae

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

Diff for: 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>

Diff for: CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Changelog
22

3+
## v1.9.2 (2025-04-07)
4+
5+
v1.9.2 is a re-release of v1.9.1 due to a release process issue; no changes were made to the content.
6+
7+
8+
## v1.9.1 (2025-03-21)
9+
10+
### Major Changes
11+
12+
* Add Charset() option. (#1679)
13+
14+
### Bugfixes
15+
16+
* go.mod: fix go version format (#1682)
17+
* Fix FormatDSN missing ConnectionAttributes (#1619)
18+
319
## v1.9.0 (2025-02-18)
420

521
### Major Changes

Diff for: dsn.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ type Config struct {
4444
DBName string // Database name
4545
Params map[string]string // Connection parameters
4646
ConnectionAttributes string // Connection Attributes, comma-delimited string of user-defined "key:value" pairs
47-
charsets []string // Connection charset. When set, this will be set in SET NAMES <charset> query
4847
Collation string // Connection collation. When set, this will be set in SET NAMES <charset> COLLATE <collation> query
4948
Loc *time.Location // Location for time.Time values
5049
MaxAllowedPacket int // Max packet size allowed
@@ -81,6 +80,7 @@ type Config struct {
8180
beforeConnect func(context.Context, *Config) error // Invoked before a connection is established
8281
pubKey *rsa.PublicKey // Server public key
8382
timeTruncate time.Duration // Truncate time.Time values to the specified duration
83+
charsets []string // Connection charset. When set, this will be set in SET NAMES <charset> query
8484
}
8585

8686
// Functional Options Pattern
@@ -135,6 +135,21 @@ func EnableCompression(yes bool) Option {
135135
}
136136
}
137137

138+
// Charset sets the connection charset and collation.
139+
//
140+
// charset is the connection charset.
141+
// collation is the connection collation. It can be null or empty string.
142+
//
143+
// When collation is not specified, `SET NAMES <charset>` command is sent when the connection is established.
144+
// When collation is specified, `SET NAMES <charset> COLLATE <collation>` command is sent when the connection is established.
145+
func Charset(charset, collation string) Option {
146+
return func(cfg *Config) error {
147+
cfg.charsets = []string{charset}
148+
cfg.Collation = collation
149+
return nil
150+
}
151+
}
152+
138153
func (cfg *Config) Clone() *Config {
139154
cp := *cfg
140155
if cp.TLS != nil {
@@ -307,6 +322,10 @@ func (cfg *Config) FormatDSN() string {
307322
writeDSNParam(&buf, &hasParam, "columnsWithAlias", "true")
308323
}
309324

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

Diff for: 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

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/go-sql-driver/mysql
22

3-
go 1.21
3+
go 1.21.0
44

55
require filippo.io/edwards25519 v1.1.0

0 commit comments

Comments
 (0)