Skip to content

Commit 40aed26

Browse files
authored
Merge branch 'master' into connect_attr
2 parents de51e0d + 191a7c4 commit 40aed26

19 files changed

+110
-71
lines changed

Diff for: .github/workflows/test.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,16 @@ jobs:
2323
import os
2424
go = [
2525
# Keep the most recent production release at the top
26-
'1.19',
26+
'1.20',
2727
# Older production releases
28+
'1.19',
2829
'1.18',
29-
'1.17',
30-
'1.16',
31-
'1.15',
32-
'1.14',
33-
'1.13',
3430
]
3531
mysql = [
3632
'8.0',
3733
'5.7',
3834
'5.6',
35+
'mariadb-10.11',
3936
'mariadb-10.6',
4037
'mariadb-10.5',
4138
'mariadb-10.4',
@@ -45,7 +42,7 @@ jobs:
4542
includes = []
4643
# Go versions compatibility check
4744
for v in go[1:]:
48-
includes.append({'os': 'ubuntu-latest', 'go': v, 'mysql': mysql[0]})
45+
includes.append({'os': 'ubuntu-latest', 'go': v, 'mysql': mysql[0]})
4946
5047
matrix = {
5148
# OS vs MySQL versions
@@ -67,10 +64,10 @@ jobs:
6764
matrix: ${{ fromJSON(needs.list.outputs.matrix) }}
6865
steps:
6966
- uses: actions/checkout@v3
70-
- uses: actions/setup-go@v3
67+
- uses: actions/setup-go@v4
7168
with:
7269
go-version: ${{ matrix.go }}
73-
- uses: shogo82148/actions-setup-mysql@v1
70+
- uses: shogo82148/actions-setup-mysql@v1.16.0
7471
with:
7572
mysql-version: ${{ matrix.mysql }}
7673
user: ${{ env.MYSQL_TEST_USER }}

Diff for: AUTHORS

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ INADA Naoki <songofacandy at gmail.com>
4747
Jacek Szwec <szwec.jacek at gmail.com>
4848
James Harr <james.harr at gmail.com>
4949
Janek Vedock <janekvedock at comcast.net>
50+
Jean-Yves Pellé <jy at pelle.link>
5051
Jeff Hodges <jeff at somethingsimilar.com>
5152
Jeffrey Charles <jeffreycharles at gmail.com>
5253
Jerome Meyer <jxmeyer at gmail.com>
@@ -78,11 +79,13 @@ Olivier Mengué <dolmen at cpan.org>
7879
oscarzhao <oscarzhaosl at gmail.com>
7980
Paul Bonser <misterpib at gmail.com>
8081
Peter Schultz <peter.schultz at classmarkets.com>
82+
Phil Porada <philporada at gmail.com>
8183
Rebecca Chin <rchin at pivotal.io>
8284
Reed Allman <rdallman10 at gmail.com>
8385
Richard Wilkes <wilkes at me.com>
8486
Robert Russell <robert at rrbrussell.com>
8587
Runrioter Wung <runrioter at gmail.com>
88+
Samantha Frank <hello at entropy.cat>
8689
Santhosh Kumar Tekuri <santhosh.tekuri at gmail.com>
8790
Sho Iizuka <sho.i518 at gmail.com>
8891
Sho Ikeda <suicaicoca at gmail.com>
@@ -93,6 +96,7 @@ Stan Putrya <root.vagner at gmail.com>
9396
Stanley Gunawan <gunawan.stanley at gmail.com>
9497
Steven Hartland <steven.hartland at multiplay.co.uk>
9598
Tan Jinhua <312841925 at qq.com>
99+
Tetsuro Aoki <t.aoki1130 at gmail.com>
96100
Thomas Wodarek <wodarekwebpage at gmail.com>
97101
Tim Ruffles <timruffles at gmail.com>
98102
Tom Jenkinson <tom at tjenkinson.me>

Diff for: CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## Version 1.7.1 (2023-04-25)
2+
3+
Changes:
4+
5+
- bump actions/checkout@v3 and actions/setup-go@v3 (#1375)
6+
- Add go1.20 and mariadb10.11 to the testing matrix (#1403)
7+
- Increase default maxAllowedPacket size. (#1411)
8+
9+
Bugfixes:
10+
11+
- Use SET syntax as specified in the MySQL documentation (#1402)
12+
13+
114
## Version 1.7 (2022-11-29)
215

316
Changes:

Diff for: README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac
4040
* Optional placeholder interpolation
4141

4242
## Requirements
43-
* Go 1.13 or higher. We aim to support the 3 latest versions of Go.
44-
* MySQL (4.1+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
43+
* Go 1.18 or higher. We aim to support the 3 latest versions of Go.
44+
* MySQL (5.6+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
4545

4646
---------------------------------------
4747

@@ -282,10 +282,10 @@ Please keep in mind, that param values must be [url.QueryEscape](https://golang.
282282
##### `maxAllowedPacket`
283283
```
284284
Type: decimal number
285-
Default: 4194304
285+
Default: 64*1024*1024
286286
```
287287

288-
Max packet size allowed in bytes. The default value is 4 MiB and should be adjusted to match the server settings. `maxAllowedPacket=0` can be used to automatically fetch the `max_allowed_packet` variable from server *on every connection*.
288+
Max packet size allowed in bytes. The default value is 64 MiB and should be adjusted to match the server settings. `maxAllowedPacket=0` can be used to automatically fetch the `max_allowed_packet` variable from server *on every connection*.
289289

290290
##### `multiStatements`
291291

Diff for: auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
291291
return enc, err
292292

293293
default:
294-
errLog.Print("unknown auth plugin:", plugin)
294+
mc.cfg.Logger.Print("unknown auth plugin:", plugin)
295295
return nil, ErrUnknownPlugin
296296
}
297297
}

Diff for: connection.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ func (mc *mysqlConn) handleParams() (err error) {
6868
default:
6969
if cmdSet.Len() == 0 {
7070
// Heuristic: 29 chars for each other key=value to reduce reallocations
71-
cmdSet.Grow(4 + len(param) + 1 + len(val) + 30*(len(mc.cfg.Params)-1))
71+
cmdSet.Grow(4 + len(param) + 3 + len(val) + 30*(len(mc.cfg.Params)-1))
7272
cmdSet.WriteString("SET ")
7373
} else {
74-
cmdSet.WriteByte(',')
74+
cmdSet.WriteString(", ")
7575
}
7676
cmdSet.WriteString(param)
77-
cmdSet.WriteByte('=')
77+
cmdSet.WriteString(" = ")
7878
cmdSet.WriteString(val)
7979
}
8080
}
@@ -105,7 +105,7 @@ func (mc *mysqlConn) Begin() (driver.Tx, error) {
105105

106106
func (mc *mysqlConn) begin(readOnly bool) (driver.Tx, error) {
107107
if mc.closed.Load() {
108-
errLog.Print(ErrInvalidConn)
108+
mc.cfg.Logger.Print(ErrInvalidConn)
109109
return nil, driver.ErrBadConn
110110
}
111111
var q string
@@ -147,7 +147,7 @@ func (mc *mysqlConn) cleanup() {
147147
return
148148
}
149149
if err := mc.netConn.Close(); err != nil {
150-
errLog.Print(err)
150+
mc.cfg.Logger.Print(err)
151151
}
152152
}
153153

@@ -163,14 +163,14 @@ func (mc *mysqlConn) error() error {
163163

164164
func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) {
165165
if mc.closed.Load() {
166-
errLog.Print(ErrInvalidConn)
166+
mc.cfg.Logger.Print(ErrInvalidConn)
167167
return nil, driver.ErrBadConn
168168
}
169169
// Send command
170170
err := mc.writeCommandPacketStr(comStmtPrepare, query)
171171
if err != nil {
172172
// STMT_PREPARE is safe to retry. So we can return ErrBadConn here.
173-
errLog.Print(err)
173+
mc.cfg.Logger.Print(err)
174174
return nil, driver.ErrBadConn
175175
}
176176

@@ -204,7 +204,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
204204
buf, err := mc.buf.takeCompleteBuffer()
205205
if err != nil {
206206
// can not take the buffer. Something must be wrong with the connection
207-
errLog.Print(err)
207+
mc.cfg.Logger.Print(err)
208208
return "", ErrInvalidConn
209209
}
210210
buf = buf[:0]
@@ -296,7 +296,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
296296

297297
func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, error) {
298298
if mc.closed.Load() {
299-
errLog.Print(ErrInvalidConn)
299+
mc.cfg.Logger.Print(ErrInvalidConn)
300300
return nil, driver.ErrBadConn
301301
}
302302
if len(args) != 0 {
@@ -357,7 +357,7 @@ func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, erro
357357

358358
func (mc *mysqlConn) query(query string, args []driver.Value) (*textRows, error) {
359359
if mc.closed.Load() {
360-
errLog.Print(ErrInvalidConn)
360+
mc.cfg.Logger.Print(ErrInvalidConn)
361361
return nil, driver.ErrBadConn
362362
}
363363
if len(args) != 0 {
@@ -451,7 +451,7 @@ func (mc *mysqlConn) finish() {
451451
// Ping implements driver.Pinger interface
452452
func (mc *mysqlConn) Ping(ctx context.Context) (err error) {
453453
if mc.closed.Load() {
454-
errLog.Print(ErrInvalidConn)
454+
mc.cfg.Logger.Print(ErrInvalidConn)
455455
return driver.ErrBadConn
456456
}
457457

Diff for: connection_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ func TestPingErrInvalidConn(t *testing.T) {
179179
buf: newBuffer(nc),
180180
maxAllowedPacket: defaultMaxAllowedPacket,
181181
closech: make(chan struct{}),
182+
cfg: NewConfig(),
182183
}
183184

184185
err := ms.Ping(context.Background())

Diff for: connector.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
9292
authResp, err := mc.auth(authData, plugin)
9393
if err != nil {
9494
// try the default auth plugin, if using the requested plugin failed
95-
errLog.Print("could not use requested auth plugin '"+plugin+"': ", err.Error())
95+
c.cfg.Logger.Print("could not use requested auth plugin '"+plugin+"': ", err.Error())
9696
plugin = defaultAuthPlugin
9797
authResp, err = mc.auth(authData, plugin)
9898
if err != nil {

Diff for: const.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import "runtime"
1212

1313
const (
1414
defaultAuthPlugin = "mysql_native_password"
15-
defaultMaxAllowedPacket = 4 << 20 // 4 MiB
15+
defaultMaxAllowedPacket = 64 << 20 // 64 MiB. See https://github.com/go-sql-driver/mysql/issues/1355
1616
minProtocolVersion = 10
1717
maxPacketSize = 1<<24 - 1
1818
timeFormat = "2006-01-02 15:04:05.999999"

Diff for: driver.go

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ func RegisterDialContext(net string, dial DialContextFunc) {
5555
dials[net] = dial
5656
}
5757

58+
// DeregisterDialContext removes the custom dial function registered with the given net.
59+
func DeregisterDialContext(net string) {
60+
dialsLock.Lock()
61+
defer dialsLock.Unlock()
62+
if dials != nil {
63+
if _, ok := dials[net]; ok {
64+
delete(dials, net)
65+
}
66+
}
67+
}
68+
5869
// RegisterDial registers a custom dial function. It can then be used by the
5970
// network address mynet(addr), where mynet is the registered new network.
6071
// addr is passed as a parameter to the dial function.

Diff for: driver_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ func TestInsertRetrieveEscapedData(t *testing.T) {
19951995
func TestUnixSocketAuthFail(t *testing.T) {
19961996
runTests(t, dsn, func(dbt *DBTest) {
19971997
// Save the current logger so we can restore it.
1998-
oldLogger := errLog
1998+
oldLogger := defaultLogger
19991999

20002000
// Set a new logger so we can capture its output.
20012001
buffer := bytes.NewBuffer(make([]byte, 0, 64))
@@ -2703,7 +2703,7 @@ func TestContextBeginIsolationLevel(t *testing.T) {
27032703
if err := row.Scan(&v); err != nil {
27042704
dbt.Fatal(err)
27052705
}
2706-
// Because writer transaction wasn't commited yet, it should be available
2706+
// Because writer transaction wasn't committed yet, it should be available
27072707
if v != 0 {
27082708
dbt.Errorf("expected val to be 0, got %d", v)
27092709
}
@@ -2717,7 +2717,7 @@ func TestContextBeginIsolationLevel(t *testing.T) {
27172717
if err := row.Scan(&v); err != nil {
27182718
dbt.Fatal(err)
27192719
}
2720-
// Data written by writer transaction is already commited, it should be selectable
2720+
// Data written by writer transaction is already committed, it should be selectable
27212721
if v != 1 {
27222722
dbt.Errorf("expected val to be 1, got %d", v)
27232723
}

Diff for: dsn.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Config struct {
4040
Addr string // Network address (requires Net)
4141
DBName string // Database name
4242
Params map[string]string // Connection parameters
43+
ConnectionAttributes string // Connection Attributes, comma-delimited string of user-defined "key:value" pairs
4344
Collation string // Connection collation
4445
Loc *time.Location // Location for time.Time values
4546
MaxAllowedPacket int // Max packet size allowed
@@ -50,7 +51,7 @@ type Config struct {
5051
Timeout time.Duration // Dial timeout
5152
ReadTimeout time.Duration // I/O read timeout
5253
WriteTimeout time.Duration // I/O write timeout
53-
ConnectionAttributes string // Connection Attributes, comma-delimited string of user-defined "key:value" pairs
54+
Logger Logger // Logger
5455

5556
AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE
5657
AllowCleartextPasswords bool // Allows the cleartext client side plugin
@@ -72,6 +73,7 @@ func NewConfig() *Config {
7273
Collation: defaultCollation,
7374
Loc: time.UTC,
7475
MaxAllowedPacket: defaultMaxAllowedPacket,
76+
Logger: defaultLogger,
7577
AllowNativePasswords: true,
7678
CheckConnLiveness: true,
7779
}
@@ -154,6 +156,10 @@ func (cfg *Config) normalize() error {
154156
}
155157
}
156158

159+
if cfg.Logger == nil {
160+
cfg.Logger = defaultLogger
161+
}
162+
157163
return nil
158164
}
159165

0 commit comments

Comments
 (0)