Skip to content

Commit 01e7b59

Browse files
Merge branch 'master' into columntype
2 parents 10f216a + 7785c74 commit 01e7b59

25 files changed

+1470
-156
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
Icon?
77
ehthumbs.db
88
Thumbs.db
9+
.idea

.travis.yml

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
sudo: false
22
language: go
33
go:
4-
- 1.2
5-
- 1.3
6-
- 1.4
74
- 1.5
85
- 1.6
96
- 1.7
107
- 1.8
8+
- 1.9
119
- tip
1210

11+
before_install:
12+
- go get golang.org/x/tools/cmd/cover
13+
- go get github.com/mattn/goveralls
14+
15+
before_script:
16+
- echo -e "[server]\ninnodb_log_file_size=256MB\ninnodb_buffer_pool_size=512MB\nmax_allowed_packet=16MB" | sudo tee -a /etc/mysql/my.cnf
17+
- sudo service mysql restart
18+
- .travis/wait_mysql.sh
19+
- mysql -e 'create database gotest;'
20+
1321
matrix:
1422
include:
1523
- env: DB=MYSQL57
1624
sudo: required
1725
dist: trusty
18-
go: 1.8
26+
go: 1.9
1927
services:
2028
- docker
2129
before_install:
30+
- go get golang.org/x/tools/cmd/cover
31+
- go get github.com/mattn/goveralls
2232
- docker pull mysql:5.7
2333
- docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_DATABASE=gotest -e MYSQL_USER=gotest -e MYSQL_PASSWORD=secret -e MYSQL_ROOT_PASSWORD=verysecret
2434
mysql:5.7 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB
@@ -35,10 +45,12 @@ matrix:
3545
- env: DB=MARIA55
3646
sudo: required
3747
dist: trusty
38-
go: 1.8
48+
go: 1.9
3949
services:
4050
- docker
4151
before_install:
52+
- go get golang.org/x/tools/cmd/cover
53+
- go get github.com/mattn/goveralls
4254
- docker pull mariadb:5.5
4355
- docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_DATABASE=gotest -e MYSQL_USER=gotest -e MYSQL_PASSWORD=secret -e MYSQL_ROOT_PASSWORD=verysecret
4456
mariadb:5.5 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB
@@ -55,10 +67,12 @@ matrix:
5567
- env: DB=MARIA10_1
5668
sudo: required
5769
dist: trusty
58-
go: 1.8
70+
go: 1.9
5971
services:
6072
- docker
6173
before_install:
74+
- go get golang.org/x/tools/cmd/cover
75+
- go get github.com/mattn/goveralls
6276
- docker pull mariadb:10.1
6377
- docker run -d -p 127.0.0.1:3307:3306 --name mysqld -e MYSQL_DATABASE=gotest -e MYSQL_USER=gotest -e MYSQL_PASSWORD=secret -e MYSQL_ROOT_PASSWORD=verysecret
6478
mariadb:10.1 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB
@@ -72,10 +86,8 @@ matrix:
7286
- export MYSQL_TEST_ADDR=127.0.0.1:3307
7387
- export MYSQL_TEST_CONCURRENT=1
7488

75-
76-
before_script:
77-
- mysql -e 'create database gotest;'
7889
script:
79-
- go test -v
90+
- go test -v -covermode=count -coverprofile=coverage.out
8091
- go vet ./...
8192
- test -z "$(gofmt -d -s . | tee /dev/stderr)"
93+
- $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci

AUTHORS

+13
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,33 @@
1212
# Individual Persons
1313

1414
Aaron Hopkins <go-sql-driver at die.net>
15+
Achille Roussel <achille.roussel at gmail.com>
1516
Arne Hormann <arnehormann at gmail.com>
1617
Asta Xie <xiemengjun at gmail.com>
18+
Bulat Gaifullin <gaifullinbf at gmail.com>
1719
Carlos Nieto <jose.carlos at menteslibres.net>
1820
Chris Moos <chris at tech9computers.com>
1921
Daniel Nichter <nil at codenode.com>
2022
Daniël van Eeden <git at myname.nl>
23+
Dave Protasowski <dprotaso at gmail.com>
2124
DisposaBoy <disposaboy at dby.me>
2225
Egor Smolyakov <egorsmkv at gmail.com>
26+
Evan Shaw <evan at vendhq.com>
2327
Frederick Mayle <frederickmayle at gmail.com>
2428
Gustavo Kristic <gkristic at gmail.com>
2529
Hanno Braun <mail at hannobraun.com>
2630
Henri Yandell <flamefew at gmail.com>
2731
Hirotaka Yamamoto <ymmt2005 at gmail.com>
32+
ICHINOSE Shogo <shogo82148 at gmail.com>
2833
INADA Naoki <songofacandy at gmail.com>
2934
Jacek Szwec <szwec.jacek at gmail.com>
3035
James Harr <james.harr at gmail.com>
36+
Jeff Hodges <jeff at somethingsimilar.com>
3137
Jian Zhen <zhenjl at gmail.com>
3238
Joshua Prunier <joshua.prunier at gmail.com>
3339
Julien Lefevre <julien.lefevr at gmail.com>
3440
Julien Schmidt <go-sql-driver at julienschmidt.com>
41+
Justin Nuß <nuss.justin at gmail.com>
3542
Kamil Dziedzic <kamil at klecza.pl>
3643
Kevin Malachowski <kevin at chowski.com>
3744
Lennart Rudolph <lrudolph at hmc.edu>
@@ -40,13 +47,17 @@ Lion Yang <lion at aosc.xyz>
4047
Luca Looz <luca.looz92 at gmail.com>
4148
Lucas Liu <extrafliu at gmail.com>
4249
Luke Scott <luke at webconnex.com>
50+
Maciej Zimnoch <[email protected]>
4351
Michael Woolnough <michael.woolnough at gmail.com>
4452
Nicola Peduzzi <thenikso at gmail.com>
4553
Olivier Mengué <dolmen at cpan.org>
4654
Omid Aladini <omidaladini at gmail.com>
55+
oscarzhao <oscarzhaosl at gmail.com>
4756
Paul Bonser <misterpib at gmail.com>
4857
Peter Schultz <peter.schultz at classmarkets.com>
58+
Rebecca Chin <rchin at pivotal.io>
4959
Runrioter Wung <runrioter at gmail.com>
60+
Shuode Li <elemount at qq.com>
5061
Soroush Pour <me at soroushjp.com>
5162
Stan Putrya <root.vagner at gmail.com>
5263
Stanley Gunawan <gunawan.stanley at gmail.com>
@@ -59,4 +70,6 @@ Zhenye Xie <xiezhenye at gmail.com>
5970

6071
Barracuda Networks, Inc.
6172
Google Inc.
73+
Keybase Inc.
74+
Pivotal Inc.
6275
Stripe Inc.

README.md

+42-12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac
1919
* [LOAD DATA LOCAL INFILE support](#load-data-local-infile-support)
2020
* [time.Time support](#timetime-support)
2121
* [Unicode support](#unicode-support)
22+
* [context.Context Support](#contextcontext-support)
2223
* [Testing / Development](#testing--development)
2324
* [License](#license)
2425

@@ -38,15 +39,15 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac
3839
* Optional placeholder interpolation
3940

4041
## Requirements
41-
* Go 1.2 or higher
42+
* Go 1.5 or higher
4243
* MySQL (4.1+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
4344

4445
---------------------------------------
4546

4647
## Installation
4748
Simple install the package to your [$GOPATH](https://github.com/golang/go/wiki/GOPATH "GOPATH") with the [go tool](https://golang.org/cmd/go/ "go command") from shell:
4849
```bash
49-
$ go get github.com/go-sql-driver/mysql
50+
$ go get -u github.com/go-sql-driver/mysql
5051
```
5152
Make sure [Git is installed](https://git-scm.com/downloads) on your machine and in your system's `PATH`.
5253

@@ -100,7 +101,8 @@ See [net.Dial](https://golang.org/pkg/net/#Dial) for more information which netw
100101
In general you should use an Unix domain socket if available and TCP otherwise for best performance.
101102

102103
#### Address
103-
For TCP and UDP networks, addresses have the form `host:port`.
104+
For TCP and UDP networks, addresses have the form `host[:port]`.
105+
If `port` is omitted, the default port will be used.
104106
If `host` is a literal IPv6 address, it must be enclosed in square brackets.
105107
The functions [net.JoinHostPort](https://golang.org/pkg/net/#JoinHostPort) and [net.SplitHostPort](https://golang.org/pkg/net/#SplitHostPort) manipulate addresses in this form.
106108

@@ -137,9 +139,9 @@ Default: false
137139
```
138140
Type: bool
139141
Valid Values: true, false
140-
Default: false
142+
Default: true
141143
```
142-
`allowNativePasswords=true` allows the usage of the mysql native password method.
144+
`allowNativePasswords=false` disallows the usage of MySQL native password method.
143145

144146
##### `allowOldPasswords`
145147

@@ -267,6 +269,31 @@ Default: 0
267269

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

272+
##### `rejectReadOnly`
273+
274+
```
275+
Type: bool
276+
Valid Values: true, false
277+
Default: false
278+
```
279+
280+
281+
`rejectreadOnly=true` causes the driver to reject read-only connections. This
282+
is for a possible race condition during an automatic failover, where the mysql
283+
client gets connected to a read-only replica after the failover.
284+
285+
Note that this should be a fairly rare case, as an automatic failover normally
286+
happens when the primary is down, and the race condition shouldn't happen
287+
unless it comes back up online as soon as the failover is kicked off. On the
288+
other hand, when this happens, a MySQL application can get stuck on a
289+
read-only connection until restarted. It is however fairly easy to reproduce,
290+
for example, using a manual failover on AWS Aurora's MySQL-compatible cluster.
291+
292+
If you are not relying on read-only transactions to reject writes that aren't
293+
supposed to happen, setting this on some MySQL providers (such as AWS Aurora)
294+
is safer for failovers.
295+
296+
270297
##### `strict`
271298

272299
```
@@ -318,9 +345,9 @@ Any other parameters are interpreted as system variables:
318345
* `<string_var>=%27<value>%27`: `SET <string_var>='<value>'`
319346

320347
Rules:
321-
* The values for string variables must be quoted with '
348+
* The values for string variables must be quoted with `'`.
322349
* The values must also be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed!
323-
(which implies values of string variables must be wrapped with `%27`)
350+
(which implies values of string variables must be wrapped with `%27`).
324351

325352
Examples:
326353
* `autocommit=1`: `SET autocommit=1`
@@ -400,7 +427,7 @@ See the [godoc of Go-MySQL-Driver](https://godoc.org/github.com/go-sql-driver/my
400427

401428

402429
### `time.Time` support
403-
The default internal output type of MySQL `DATE` and `DATETIME` values is `[]byte` which allows you to scan the value into a `[]byte`, `string` or `sql.RawBytes` variable in your programm.
430+
The default internal output type of MySQL `DATE` and `DATETIME` values is `[]byte` which allows you to scan the value into a `[]byte`, `string` or `sql.RawBytes` variable in your program.
404431

405432
However, many want to scan MySQL `DATE` and `DATETIME` values into `time.Time` variables, which is the logical opposite in Go to `DATE` and `DATETIME` in MySQL. You can do that by changing the internal output type from `[]byte` to `time.Time` with the DSN parameter `parseTime=true`. You can set the default [`time.Time` location](https://golang.org/pkg/time/#Location) with the `loc` DSN parameter.
406433

@@ -418,6 +445,9 @@ Version 1.0 of the driver recommended adding `&charset=utf8` (alias for `SET NAM
418445

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

448+
## `context.Context` Support
449+
Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.
450+
See [context support in the database/sql package](https://golang.org/doc/go1.8#database_sql) for more details.
421451

422452
## Testing / Development
423453
To run the driver tests you may need to adjust the configuration. See the [Testing Wiki-Page](https://github.com/go-sql-driver/mysql/wiki/Testing "Testing") for details.
@@ -437,13 +467,13 @@ Mozilla summarizes the license scope as follows:
437467
438468

439469
That means:
440-
* You can **use** the **unchanged** source code both in private and commercially
441-
* When distributing, you **must publish** the source code of any **changed files** licensed under the MPL 2.0 under a) the MPL 2.0 itself or b) a compatible license (e.g. GPL 3.0 or Apache License 2.0)
442-
* You **needn't publish** the source code of your library as long as the files licensed under the MPL 2.0 are **unchanged**
470+
* You can **use** the **unchanged** source code both in private and commercially.
471+
* When distributing, you **must publish** the source code of any **changed files** licensed under the MPL 2.0 under a) the MPL 2.0 itself or b) a compatible license (e.g. GPL 3.0 or Apache License 2.0).
472+
* You **needn't publish** the source code of your library as long as the files licensed under the MPL 2.0 are **unchanged**.
443473

444474
Please read the [MPL 2.0 FAQ](https://www.mozilla.org/en-US/MPL/2.0/FAQ/) if you have further questions regarding the license.
445475

446-
You can read the full terms here: [LICENSE](https://raw.github.com/go-sql-driver/mysql/master/LICENSE)
476+
You can read the full terms here: [LICENSE](https://raw.github.com/go-sql-driver/mysql/master/LICENSE).
447477

448478
![Go Gopher and MySQL Dolphin](https://raw.github.com/wiki/go-sql-driver/mysql/go-mysql-driver_m.jpg "Golang Gopher transporting the MySQL Dolphin in a wheelbarrow")
449479

benchmark_go18_test.go

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2+
//
3+
// Copyright 2017 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+
9+
// +build go1.8
10+
11+
package mysql
12+
13+
import (
14+
"context"
15+
"database/sql"
16+
"fmt"
17+
"runtime"
18+
"testing"
19+
)
20+
21+
func benchmarkQueryContext(b *testing.B, db *sql.DB, p int) {
22+
ctx, cancel := context.WithCancel(context.Background())
23+
defer cancel()
24+
db.SetMaxIdleConns(p * runtime.GOMAXPROCS(0))
25+
26+
tb := (*TB)(b)
27+
stmt := tb.checkStmt(db.PrepareContext(ctx, "SELECT val FROM foo WHERE id=?"))
28+
defer stmt.Close()
29+
30+
b.SetParallelism(p)
31+
b.ReportAllocs()
32+
b.ResetTimer()
33+
b.RunParallel(func(pb *testing.PB) {
34+
var got string
35+
for pb.Next() {
36+
tb.check(stmt.QueryRow(1).Scan(&got))
37+
if got != "one" {
38+
b.Fatalf("query = %q; want one", got)
39+
}
40+
}
41+
})
42+
}
43+
44+
func BenchmarkQueryContext(b *testing.B) {
45+
db := initDB(b,
46+
"DROP TABLE IF EXISTS foo",
47+
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))",
48+
`INSERT INTO foo VALUES (1, "one")`,
49+
`INSERT INTO foo VALUES (2, "two")`,
50+
)
51+
defer db.Close()
52+
for _, p := range []int{1, 2, 3, 4} {
53+
b.Run(fmt.Sprintf("%d", p), func(b *testing.B) {
54+
benchmarkQueryContext(b, db, p)
55+
})
56+
}
57+
}
58+
59+
func benchmarkExecContext(b *testing.B, db *sql.DB, p int) {
60+
ctx, cancel := context.WithCancel(context.Background())
61+
defer cancel()
62+
db.SetMaxIdleConns(p * runtime.GOMAXPROCS(0))
63+
64+
tb := (*TB)(b)
65+
stmt := tb.checkStmt(db.PrepareContext(ctx, "DO 1"))
66+
defer stmt.Close()
67+
68+
b.SetParallelism(p)
69+
b.ReportAllocs()
70+
b.ResetTimer()
71+
b.RunParallel(func(pb *testing.PB) {
72+
for pb.Next() {
73+
if _, err := stmt.ExecContext(ctx); err != nil {
74+
b.Fatal(err)
75+
}
76+
}
77+
})
78+
}
79+
80+
func BenchmarkExecContext(b *testing.B) {
81+
db := initDB(b,
82+
"DROP TABLE IF EXISTS foo",
83+
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))",
84+
`INSERT INTO foo VALUES (1, "one")`,
85+
`INSERT INTO foo VALUES (2, "two")`,
86+
)
87+
defer db.Close()
88+
for _, p := range []int{1, 2, 3, 4} {
89+
b.Run(fmt.Sprintf("%d", p), func(b *testing.B) {
90+
benchmarkQueryContext(b, db, p)
91+
})
92+
}
93+
}

0 commit comments

Comments
 (0)