Skip to content

Commit 5b66fdb

Browse files
authored
Merge branch 'master' into master
2 parents cd621b1 + f43effa commit 5b66fdb

37 files changed

+900
-455
lines changed

.github/workflows/codeql.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
schedule:
9+
- cron: "18 19 * * 1"
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ go ]
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v2
31+
with:
32+
languages: ${{ matrix.language }}
33+
queries: +security-and-quality
34+
35+
- name: Autobuild
36+
uses: github/codeql-action/autobuild@v2
37+
38+
- name: Perform CodeQL Analysis
39+
uses: github/codeql-action/analyze@v2
40+
with:
41+
category: "/language:${{ matrix.language }}"

.github/workflows/test.yml

+12-11
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,19 @@ jobs:
2020
id: set-matrix
2121
run: |
2222
import json
23+
import os
2324
go = [
2425
# Keep the most recent production release at the top
25-
'1.18',
26+
'1.20',
2627
# Older production releases
27-
'1.17',
28-
'1.16',
29-
'1.15',
30-
'1.14',
31-
'1.13',
28+
'1.19',
29+
'1.18',
3230
]
3331
mysql = [
3432
'8.0',
3533
'5.7',
3634
'5.6',
35+
'mariadb-10.11',
3736
'mariadb-10.6',
3837
'mariadb-10.5',
3938
'mariadb-10.4',
@@ -43,7 +42,7 @@ jobs:
4342
includes = []
4443
# Go versions compatibility check
4544
for v in go[1:]:
46-
includes.append({'os': 'ubuntu-latest', 'go': v, 'mysql': mysql[0]})
45+
includes.append({'os': 'ubuntu-latest', 'go': v, 'mysql': mysql[0]})
4746
4847
matrix = {
4948
# OS vs MySQL versions
@@ -54,7 +53,8 @@ jobs:
5453
'include': includes
5554
}
5655
output = json.dumps(matrix, separators=(',', ':'))
57-
print('::set-output name=matrix::{0}'.format(output))
56+
with open(os.environ["GITHUB_OUTPUT"], 'a', encoding="utf-8") as f:
57+
f.write('matrix={0}\n'.format(output))
5858
shell: python
5959
test:
6060
needs: list
@@ -63,11 +63,11 @@ jobs:
6363
fail-fast: false
6464
matrix: ${{ fromJSON(needs.list.outputs.matrix) }}
6565
steps:
66-
- uses: actions/checkout@v2
67-
- uses: actions/setup-go@v2
66+
- uses: actions/checkout@v3
67+
- uses: actions/setup-go@v4
6868
with:
6969
go-version: ${{ matrix.go }}
70-
- uses: shogo82148/actions-setup-mysql@v1
70+
- uses: shogo82148/actions-setup-mysql@v1.16.0
7171
with:
7272
mysql-version: ${{ matrix.mysql }}
7373
user: ${{ env.MYSQL_TEST_USER }}
@@ -79,6 +79,7 @@ jobs:
7979
; TestConcurrent fails if max_connections is too large
8080
max_connections=50
8181
local_infile=1
82+
performance_schema=on
8283
- name: setup database
8384
run: |
8485
mysql --user 'root' --host '127.0.0.1' -e 'create database gotest;'

AUTHORS

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Dave Protasowski <dprotaso at gmail.com>
3333
DisposaBoy <disposaboy at dby.me>
3434
Egor Smolyakov <egorsmkv at gmail.com>
3535
Erwan Martin <hello at erwan.io>
36+
Evan Elias <evan at skeema.net>
3637
Evan Shaw <evan at vendhq.com>
3738
Frederick Mayle <frederickmayle at gmail.com>
3839
Gustavo Kristic <gkristic at gmail.com>
@@ -47,6 +48,7 @@ INADA Naoki <songofacandy at gmail.com>
4748
Jacek Szwec <szwec.jacek at gmail.com>
4849
James Harr <james.harr at gmail.com>
4950
Janek Vedock <janekvedock at comcast.net>
51+
Jean-Yves Pellé <jy at pelle.link>
5052
Jeff Hodges <jeff at somethingsimilar.com>
5153
Jeffrey Charles <jeffreycharles at gmail.com>
5254
Jerome Meyer <jxmeyer at gmail.com>
@@ -61,6 +63,7 @@ Kamil Dziedzic <kamil at klecza.pl>
6163
Kei Kamikawa <x00.x7f.x86 at gmail.com>
6264
Kevin Malachowski <kevin at chowski.com>
6365
Kieron Woodhouse <kieron.woodhouse at infosum.com>
66+
Lance Tian <lance6716 at gmail.com>
6467
Lennart Rudolph <lrudolph at hmc.edu>
6568
Leonardo YongUk Kim <dalinaum at gmail.com>
6669
Linh Tran Tuan <linhduonggnu at gmail.com>
@@ -77,11 +80,13 @@ Olivier Mengué <dolmen at cpan.org>
7780
oscarzhao <oscarzhaosl at gmail.com>
7881
Paul Bonser <misterpib at gmail.com>
7982
Peter Schultz <peter.schultz at classmarkets.com>
83+
Phil Porada <philporada at gmail.com>
8084
Rebecca Chin <rchin at pivotal.io>
8185
Reed Allman <rdallman10 at gmail.com>
8286
Richard Wilkes <wilkes at me.com>
8387
Robert Russell <robert at rrbrussell.com>
8488
Runrioter Wung <runrioter at gmail.com>
89+
Samantha Frank <hello at entropy.cat>
8590
Santhosh Kumar Tekuri <santhosh.tekuri at gmail.com>
8691
Sho Iizuka <sho.i518 at gmail.com>
8792
Sho Ikeda <suicaicoca at gmail.com>
@@ -92,6 +97,7 @@ Stan Putrya <root.vagner at gmail.com>
9297
Stanley Gunawan <gunawan.stanley at gmail.com>
9398
Steven Hartland <steven.hartland at multiplay.co.uk>
9499
Tan Jinhua <312841925 at qq.com>
100+
Tetsuro Aoki <t.aoki1130 at gmail.com>
95101
Thomas Wodarek <wodarekwebpage at gmail.com>
96102
Tim Ruffles <timruffles at gmail.com>
97103
Tom Jenkinson <tom at tjenkinson.me>
@@ -104,6 +110,7 @@ Xuehong Chan <chanxuehong at gmail.com>
104110
Zhenye Xie <xiezhenye at gmail.com>
105111
Zhixin Wen <john.wenzhixin at gmail.com>
106112
Ziheng Lyu <zihenglv at gmail.com>
113+
Brian Hendriks <brian at dolthub.com>
107114

108115
# Organizations
109116

@@ -121,3 +128,4 @@ Percona LLC
121128
Pivotal Inc.
122129
Stripe Inc.
123130
Zendesk Inc.
131+
Dolthub Inc.

CHANGELOG.md

+34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
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+
14+
## Version 1.7 (2022-11-29)
15+
16+
Changes:
17+
18+
- Drop support of Go 1.12 (#1211)
19+
- Refactoring `(*textRows).readRow` in a more clear way (#1230)
20+
- util: Reduce boundary check in escape functions. (#1316)
21+
- enhancement for mysqlConn handleAuthResult (#1250)
22+
23+
New Features:
24+
25+
- support Is comparison on MySQLError (#1210)
26+
- return unsigned in database type name when necessary (#1238)
27+
- Add API to express like a --ssl-mode=PREFERRED MySQL client (#1370)
28+
- Add SQLState to MySQLError (#1321)
29+
30+
Bugfixes:
31+
32+
- Fix parsing 0 year. (#1257)
33+
34+
135
## Version 1.6 (2021-04-01)
236

337
Changes:

README.md

+39-11
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

@@ -114,6 +114,12 @@ This has the same effect as an empty DSN string:
114114
115115
```
116116

117+
`dbname` is escaped by [PathEscape()]()https://pkg.go.dev/net/url#PathEscape) since v1.8.0. If your database name is `dbname/withslash`, it becomes:
118+
119+
```
120+
/dbname%2Fwithslash
121+
```
122+
117123
Alternatively, [Config.FormatDSN](https://godoc.org/github.com/go-sql-driver/mysql#Config.FormatDSN) can be used to create a DSN string by filling a struct.
118124

119125
#### Password
@@ -157,6 +163,17 @@ Default: false
157163

158164
`allowCleartextPasswords=true` allows using the [cleartext client side plugin](https://dev.mysql.com/doc/en/cleartext-pluggable-authentication.html) if required by an account, such as one defined with the [PAM authentication plugin](http://dev.mysql.com/doc/en/pam-authentication-plugin.html). Sending passwords in clear text may be a security problem in some configurations. To avoid problems if there is any possibility that the password would be intercepted, clients should connect to MySQL Server using a method that protects the password. Possibilities include [TLS / SSL](#tls), IPsec, or a private network.
159165

166+
167+
##### `allowFallbackToPlaintext`
168+
169+
```
170+
Type: bool
171+
Valid Values: true, false
172+
Default: false
173+
```
174+
175+
`allowFallbackToPlaintext=true` acts like a `--ssl-mode=PREFERRED` MySQL client as described in [Command Options for Connecting to the Server](https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode)
176+
160177
##### `allowNativePasswords`
161178

162179
```
@@ -185,8 +202,7 @@ Default: none
185202

186203
Sets the charset used for client-server interaction (`"SET NAMES <value>"`). If multiple charsets are set (separated by a comma), the following charset is used if setting the charset failes. This enables for example support for `utf8mb4` ([introduced in MySQL 5.5.3](http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html)) with fallback to `utf8` for older servers (`charset=utf8mb4,utf8`).
187204

188-
Usage of the `charset` parameter is discouraged because it issues additional queries to the server.
189-
Unless you need the fallback behavior, please use `collation` instead.
205+
See also [Unicode Support](#unicode-support).
190206

191207
##### `checkConnLiveness`
192208

@@ -215,6 +231,7 @@ The default collation (`utf8mb4_general_ci`) is supported from MySQL 5.5. You s
215231

216232
Collations for charset "ucs2", "utf16", "utf16le", and "utf32" can not be used ([ref](https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html#charset-connection-impermissible-client-charset)).
217233

234+
See also [Unicode Support](#unicode-support).
218235

219236
##### `clientFoundRows`
220237

@@ -271,10 +288,10 @@ Please keep in mind, that param values must be [url.QueryEscape](https://golang.
271288
##### `maxAllowedPacket`
272289
```
273290
Type: decimal number
274-
Default: 4194304
291+
Default: 64*1024*1024
275292
```
276293

277-
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*.
294+
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*.
278295

279296
##### `multiStatements`
280297

@@ -284,9 +301,9 @@ Valid Values: true, false
284301
Default: false
285302
```
286303

287-
Allow multiple statements in one query. While this allows batch queries, it also greatly increases the risk of SQL injections. Only the result of the first query is returned, all other results are silently discarded.
304+
Allow multiple statements in one query. This can be used to bach multiple queries. Use [Rows.NextResultSet()](https://pkg.go.dev/database/sql#Rows.NextResultSet) to get result of the second and subsequent queries.
288305

289-
When `multiStatements` is used, `?` parameters must only be used in the first statement.
306+
When `multiStatements` is used, `?` parameters must only be used in the first statement. [interpolateParams](#interpolateparams) can be used to avoid this limitation unless prepared statement is used explicitly.
290307

291308
It's possible to access the last inserted ID and number of affected rows for multiple statements by using `sql.Conn.Raw()` and the `mysql.Result`. For example:
292309

@@ -398,6 +415,15 @@ Default: 0
398415

399416
I/O write timeout. The value must be a decimal number with a unit suffix (*"ms"*, *"s"*, *"m"*, *"h"*), such as *"30s"*, *"0.5m"* or *"1m30s"*.
400417

418+
##### `connectionAttributes`
419+
420+
```
421+
Type: comma-delimited string of user-defined "key:value" pairs
422+
Valid Values: (<name1>:<value1>,<name2>:<value2>,...)
423+
Default: none
424+
```
425+
426+
[Connection attributes](https://dev.mysql.com/doc/refman/8.0/en/performance-schema-connection-attribute-tables.html) are key-value pairs that application programs can pass to the server at connect time.
401427

402428
##### System Variables
403429

@@ -470,7 +496,7 @@ user:password@/
470496
The connection pool is managed by Go's database/sql package. For details on how to configure the size of the pool and how long connections stay in the pool see `*DB.SetMaxOpenConns`, `*DB.SetMaxIdleConns`, and `*DB.SetConnMaxLifetime` in the [database/sql documentation](https://golang.org/pkg/database/sql/). The read, write, and dial timeouts for each individual connection are configured with the DSN parameters [`readTimeout`](#readtimeout), [`writeTimeout`](#writetimeout), and [`timeout`](#timeout), respectively.
471497

472498
## `ColumnType` Support
473-
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `BIGINT`.
499+
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `MEDIUMINT`, `BIGINT`.
474500

475501
## `context.Context` Support
476502
Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.
@@ -501,9 +527,11 @@ However, many want to scan MySQL `DATE` and `DATETIME` values into `time.Time` v
501527
### Unicode support
502528
Since version 1.5 Go-MySQL-Driver automatically uses the collation ` utf8mb4_general_ci` by default.
503529

504-
Other collations / charsets can be set using the [`collation`](#collation) DSN parameter.
530+
Other charsets / collations can be set using the [`charset`](#charset) or [`collation`](#collation) DSN parameter.
505531

506-
Version 1.0 of the driver recommended adding `&charset=utf8` (alias for `SET NAMES utf8`) to the DSN to enable proper UTF-8 support. This is not necessary anymore. The [`collation`](#collation) parameter should be preferred to set another collation / charset than the default.
532+
- When only the `charset` is specified, the `SET NAMES <charset>` query is sent and the server's default collation is used.
533+
- When both the `charset` and `collation` are specified, the `SET NAMES <charset> COLLATE <collation>` query is sent.
534+
- When only the `collation` is specified, the collation is specified in the protocol handshake and the `SET NAMES` query is not sent. This can save one roundtrip, but note that the server may ignore the specified collation silently and use the server's default charset/collation instead.
507535

508536
See http://dev.mysql.com/doc/refman/8.0/en/charset-unicode.html for more details on MySQL's Unicode support.
509537

atomic_bool.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package.
2+
//
3+
// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved.
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
7+
// You can obtain one at http://mozilla.org/MPL/2.0/.
8+
//go:build go1.19
9+
// +build go1.19
10+
11+
package mysql
12+
13+
import "sync/atomic"
14+
15+
/******************************************************************************
16+
* Sync utils *
17+
******************************************************************************/
18+
19+
type atomicBool = atomic.Bool

atomic_bool_go118.go

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package.
2+
//
3+
// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved.
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
7+
// You can obtain one at http://mozilla.org/MPL/2.0/.
8+
//go:build !go1.19
9+
// +build !go1.19
10+
11+
package mysql
12+
13+
import "sync/atomic"
14+
15+
/******************************************************************************
16+
* Sync utils *
17+
******************************************************************************/
18+
19+
// atomicBool is an implementation of atomic.Bool for older version of Go.
20+
// it is a wrapper around uint32 for usage as a boolean value with
21+
// atomic access.
22+
type atomicBool struct {
23+
_ noCopy
24+
value uint32
25+
}
26+
27+
// Load returns whether the current boolean value is true
28+
func (ab *atomicBool) Load() bool {
29+
return atomic.LoadUint32(&ab.value) > 0
30+
}
31+
32+
// Store sets the value of the bool regardless of the previous value
33+
func (ab *atomicBool) Store(value bool) {
34+
if value {
35+
atomic.StoreUint32(&ab.value, 1)
36+
} else {
37+
atomic.StoreUint32(&ab.value, 0)
38+
}
39+
}
40+
41+
// Swap sets the value of the bool and returns the old value.
42+
func (ab *atomicBool) Swap(value bool) bool {
43+
if value {
44+
return atomic.SwapUint32(&ab.value, 1) > 0
45+
}
46+
return atomic.SwapUint32(&ab.value, 0) > 0
47+
}

0 commit comments

Comments
 (0)