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

.github/workflows/test.yml

Lines changed: 6 additions & 9 deletions
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 }}

AUTHORS

Lines changed: 4 additions & 0 deletions
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>

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
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:

README.md

Lines changed: 4 additions & 4 deletions
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

auth.go

Lines changed: 1 addition & 1 deletion
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
}

connection.go

Lines changed: 11 additions & 11 deletions
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

connection_test.go

Lines changed: 1 addition & 0 deletions
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())

connector.go

Lines changed: 1 addition & 1 deletion
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 {

const.go

Lines changed: 1 addition & 1 deletion
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"

driver.go

Lines changed: 11 additions & 0 deletions
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.

0 commit comments

Comments
 (0)