Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: go-sql-driver/mysql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.9.0
Choose a base ref
...
head repository: go-sql-driver/mysql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.9.1
Choose a head ref
  • 4 commits
  • 5 files changed
  • 2 contributors

Commits on Mar 10, 2025

  1. add Charset() option (#1679)

    Fix #1664.
    methane authored Mar 10, 2025
    Copy the full SHA
    c879816 View commit details
  2. Fix FormatDSN missing ConnectionAttributes (#1619)

    Fix #1618
    bogcon authored Mar 10, 2025
    Copy the full SHA
    88ff88b View commit details

Commits on Mar 14, 2025

  1. go.mod: fix go version format (#1682)

    As of Go 1.21, toolchain versions must use the 1.N.P syntax.
    https://go.dev/doc/toolchain#version
    methane authored Mar 14, 2025
    Copy the full SHA
    b84ac5a View commit details

Commits on Mar 21, 2025

  1. release v1.9.1 (#1683)

    methane authored Mar 21, 2025
    Copy the full SHA
    1fbafa8 View commit details
Showing with 38 additions and 3 deletions.
  1. +1 −0 AUTHORS
  2. +11 −0 CHANGELOG.md
  3. +20 −1 dsn.go
  4. +5 −1 dsn_test.go
  5. +1 −1 go.mod
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ Artur Melanchyk <artur.melanchyk@gmail.com>
Asta Xie <xiemengjun at gmail.com>
B Lamarche <blam413 at gmail.com>
Bes Dollma <bdollma@thousandeyes.com>
Bogdan Constantinescu <bog.con.bc at gmail.com>
Brian Hendriks <brian at dolthub.com>
Bulat Gaifullin <gaifullinbf at gmail.com>
Caine Jette <jette at alum.mit.edu>
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v1.9.1 (2025-03-21)

### Major Changes

* Add Charset() option. (#1679)

### Bugfixes

* go.mod: fix go version format (#1682)
* Fix FormatDSN missing ConnectionAttributes (#1619)

## v1.9.0 (2025-02-18)

### Major Changes
21 changes: 20 additions & 1 deletion dsn.go
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ type Config struct {
DBName string // Database name
Params map[string]string // Connection parameters
ConnectionAttributes string // Connection Attributes, comma-delimited string of user-defined "key:value" pairs
charsets []string // Connection charset. When set, this will be set in SET NAMES <charset> query
Collation string // Connection collation. When set, this will be set in SET NAMES <charset> COLLATE <collation> query
Loc *time.Location // Location for time.Time values
MaxAllowedPacket int // Max packet size allowed
@@ -81,6 +80,7 @@ type Config struct {
beforeConnect func(context.Context, *Config) error // Invoked before a connection is established
pubKey *rsa.PublicKey // Server public key
timeTruncate time.Duration // Truncate time.Time values to the specified duration
charsets []string // Connection charset. When set, this will be set in SET NAMES <charset> query
}

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

// Charset sets the connection charset and collation.
//
// charset is the connection charset.
// collation is the connection collation. It can be null or empty string.
//
// When collation is not specified, `SET NAMES <charset>` command is sent when the connection is established.
// When collation is specified, `SET NAMES <charset> COLLATE <collation>` command is sent when the connection is established.
func Charset(charset, collation string) Option {
return func(cfg *Config) error {
cfg.charsets = []string{charset}
cfg.Collation = collation
return nil
}
}

func (cfg *Config) Clone() *Config {
cp := *cfg
if cp.TLS != nil {
@@ -307,6 +322,10 @@ func (cfg *Config) FormatDSN() string {
writeDSNParam(&buf, &hasParam, "columnsWithAlias", "true")
}

if cfg.ConnectionAttributes != "" {
writeDSNParam(&buf, &hasParam, "connectionAttributes", url.QueryEscape(cfg.ConnectionAttributes))
}

if cfg.compress {
writeDSNParam(&buf, &hasParam, "compress", "true")
}
6 changes: 5 additions & 1 deletion dsn_test.go
Original file line number Diff line number Diff line change
@@ -77,6 +77,9 @@ var testDSNs = []struct {
}, {
"user:password@/dbname?loc=UTC&timeout=30s&parseTime=true&timeTruncate=1h",
&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},
}, {
"foo:bar@tcp(192.168.1.50:3307)/baz?timeout=10s&connectionAttributes=program_name:MySQLGoDriver%2FTest,program_version:1.2.3",
&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"},
},
}

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

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/go-sql-driver/mysql

go 1.21
go 1.21.0

require filippo.io/edwards25519 v1.1.0