Skip to content

Commit cc60643

Browse files
committed
Merge branch 'master' of github.com:go-sql-driver/mysql into HEAD
2 parents 3661f81 + 66312f7 commit cc60643

23 files changed

+1308
-687
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ go:
44
- 1.2
55
- 1.3
66
- 1.4
7+
- 1.5
8+
- 1.6
79
- tip
810

911
before_script:

AUTHORS

+7
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,32 @@ Aaron Hopkins <go-sql-driver at die.net>
1515
Arne Hormann <arnehormann at gmail.com>
1616
Carlos Nieto <jose.carlos at menteslibres.net>
1717
Chris Moos <chris at tech9computers.com>
18+
Daniel Nichter <nil at codenode.com>
19+
Daniël van Eeden <git at myname.nl>
1820
DisposaBoy <disposaboy at dby.me>
1921
Frederick Mayle <frederickmayle at gmail.com>
2022
Gustavo Kristic <gkristic at gmail.com>
2123
Hanno Braun <mail at hannobraun.com>
2224
Henri Yandell <flamefew at gmail.com>
25+
Hirotaka Yamamoto <ymmt2005 at gmail.com>
2326
INADA Naoki <songofacandy at gmail.com>
2427
James Harr <james.harr at gmail.com>
2528
Jian Zhen <zhenjl at gmail.com>
2629
Joshua Prunier <joshua.prunier at gmail.com>
30+
Julien Lefevre <julien.lefevr at gmail.com>
2731
Julien Schmidt <go-sql-driver at julienschmidt.com>
2832
Kamil Dziedzic <kamil at klecza.pl>
33+
Kevin Malachowski <kevin at chowski.com>
2934
Leonardo YongUk Kim <dalinaum at gmail.com>
35+
Luca Looz <luca.looz92 at gmail.com>
3036
Lucas Liu <extrafliu at gmail.com>
3137
Luke Scott <luke at webconnex.com>
3238
Michael Woolnough <michael.woolnough at gmail.com>
3339
Nicola Peduzzi <thenikso at gmail.com>
3440
Runrioter Wung <runrioter at gmail.com>
3541
Soroush Pour <me at soroushjp.com>
3642
Stan Putrya <root.vagner at gmail.com>
43+
Stanley Gunawan <gunawan.stanley at gmail.com>
3744
Xiaobing Jiang <s7v7nislands at gmail.com>
3845
Xiuming Chen <cc at cxm.cc>
3946

CHANGELOG.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ Bugfixes:
1212
- Enable microsecond resolution on TIME, DATETIME and TIMESTAMP (#249)
1313
- Fixed handling of queries without columns and rows (#255)
1414
- Fixed a panic when SetKeepAlive() failed (#298)
15+
- Support receiving ERR packet while reading rows (#321)
16+
- Fixed reading NULL length-encoded integers in MySQL 5.6+ (#349)
17+
- Fixed absolute paths support in LOAD LOCAL DATA INFILE (#356)
18+
- Actually zero out bytes in handshake response (#378)
19+
- Fixed race condition in registering LOAD DATA INFILE handler (#383)
20+
- Fixed tests with MySQL 5.7.9+ (#380)
21+
- QueryUnescape TLS config names (#397)
22+
- Fixed "broken pipe" error by writing to closed socket (#390)
1523

1624
New Features:
17-
- Support for returning table alias on Columns() (#289)
25+
- Support for returning table alias on Columns() (#289, #359, #382)
1826
- Placeholder interpolation, can be actived with the DSN parameter `interpolateParams=true` (#309, #318)
27+
- Support for uint64 parameters with high bit set (#332, #345)
28+
- Cleartext authentication plugin support (#327)
29+
1930

2031

2132
## Version 1.2 (2014-06-03)

CONTRIBUTING.md

-17
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,11 @@
44

55
Before creating a new Issue, please check first if a similar Issue [already exists](https://github.com/go-sql-driver/mysql/issues?state=open) or was [recently closed](https://github.com/go-sql-driver/mysql/issues?direction=desc&page=1&sort=updated&state=closed).
66

7-
Please provide the following minimum information:
8-
* Your Go-MySQL-Driver version (or git SHA)
9-
* Your Go version (run `go version` in your console)
10-
* A detailed issue description
11-
* Error Log if present
12-
* If possible, a short example
13-
14-
157
## Contributing Code
168

179
By contributing to this project, you share your code under the Mozilla Public License 2, as specified in the LICENSE file.
1810
Don't forget to add yourself to the AUTHORS file.
1911

20-
### Pull Requests Checklist
21-
22-
Please check the following points before submitting your pull request:
23-
- [x] Code compiles correctly
24-
- [x] Created tests, if possible
25-
- [x] All tests pass
26-
- [x] Extended the README / documentation, if necessary
27-
- [x] Added yourself to the AUTHORS file
28-
2912
### Code Review
3013

3114
Everyone is invited to review and comment on pull requests.

ISSUE_TEMPLATE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Issue description
2+
Tell us what should happen and what happens instead
3+
4+
### Example code
5+
```go
6+
If possible, please enter some example code here to reproduce the issue.
7+
```
8+
9+
### Error log
10+
```
11+
If you have an error log, please paste it here.
12+
```
13+
14+
### Configuration
15+
*Driver version (or git SHA):*
16+
17+
*Go version:* run `go version` in your console
18+
19+
*Server version:* E.g. MySQL 5.6, MariaDB 10.0.20
20+
21+
*Server OS:* E.g. Debian 8.1 (Jessie), Windows 10

PULL_REQUEST_TEMPLATE.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Description
2+
Please explain the changes you made here.
3+
4+
### Checklist
5+
- [ ] Code compiles correctly
6+
- [ ] Created tests which fail without the change (if possible)
7+
- [ ] All tests passing
8+
- [ ] Extended the README / documentation, if necessary
9+
- [ ] Added myself / the copyright holder to the AUTHORS file

README.md

+36-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ This has the same effect as an empty DSN string:
9393
9494
```
9595

96+
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.
97+
9698
#### Password
9799
Passwords can consist of any character. Escaping is **not** necessary.
98100

@@ -219,6 +221,18 @@ Note that this sets the location for time.Time values but does not change MySQL'
219221

220222
Please keep in mind, that param values must be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed. Alternatively you can manually replace the `/` with `%2F`. For example `US/Pacific` would be `loc=US%2FPacific`.
221223

224+
##### `multiStatements`
225+
226+
```
227+
Type: bool
228+
Valid Values: true, false
229+
Default: false
230+
```
231+
232+
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.
233+
234+
When `multiStatements` is used, `?` parameters must only be used in the first statement.
235+
222236

223237
##### `parseTime`
224238

@@ -231,6 +245,16 @@ Default: false
231245
`parseTime=true` changes the output type of `DATE` and `DATETIME` values to `time.Time` instead of `[]byte` / `string`
232246

233247

248+
##### `readTimeout`
249+
250+
```
251+
Type: decimal number
252+
Default: 0
253+
```
254+
255+
I/O read timeout. The value must be a decimal number with an unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*.
256+
257+
234258
##### `strict`
235259

236260
```
@@ -251,7 +275,7 @@ Type: decimal number
251275
Default: OS default
252276
```
253277

254-
*Driver* side connection timeout. The value must be a string of decimal numbers, each with optional fraction and a unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*. To set a server side timeout, use the parameter [`wait_timeout`](http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_wait_timeout).
278+
*Driver* side connection timeout. The value must be a decimal number with an unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*. To set a server side timeout, use the parameter [`wait_timeout`](http://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_wait_timeout).
255279

256280

257281
##### `tls`
@@ -265,6 +289,16 @@ Default: false
265289
`tls=true` enables TLS / SSL encrypted connection to the server. Use `skip-verify` if you want to use a self-signed or invalid certificate (server side). Use a custom value registered with [`mysql.RegisterTLSConfig`](http://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
266290

267291

292+
##### `writeTimeout`
293+
294+
```
295+
Type: decimal number
296+
Default: 0
297+
```
298+
299+
I/O write timeout. The value must be a decimal number with an unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*.
300+
301+
268302
##### System Variables
269303

270304
All other parameters are interpreted as system variables:
@@ -331,7 +365,7 @@ import "github.com/go-sql-driver/mysql"
331365

332366
Files must be whitelisted by registering them with `mysql.RegisterLocalFile(filepath)` (recommended) or the Whitelist check must be deactivated by using the DSN parameter `allowAllFiles=true` ([*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)).
333367

334-
To use a `io.Reader` a handler function must be registered with `mysql.RegisterReaderHandler(name, handler)` which returns a `io.Reader` or `io.ReadCloser`. The Reader is available with the filepath `Reader::<name>` then.
368+
To use a `io.Reader` a handler function must be registered with `mysql.RegisterReaderHandler(name, handler)` which returns a `io.Reader` or `io.ReadCloser`. The Reader is available with the filepath `Reader::<name>` then. Choose different names for different handlers and `DeregisterReaderHandler` when you don't need it anymore.
335369

336370
See the [godoc of Go-MySQL-Driver](http://godoc.org/github.com/go-sql-driver/mysql "golang mysql driver documentation") for details.
337371

benchmark_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ func initDB(b *testing.B, queries ...string) *sql.DB {
4949
for _, query := range queries {
5050
if _, err := db.Exec(query); err != nil {
5151
if w, ok := err.(MySQLWarnings); ok {
52-
b.Logf("Warning on %q: %v", query, w)
52+
b.Logf("warning on %q: %v", query, w)
5353
} else {
54-
b.Fatalf("Error on %q: %v", query, err)
54+
b.Fatalf("error on %q: %v", query, err)
5555
}
5656
}
5757
}
@@ -216,9 +216,9 @@ func BenchmarkRoundtripBin(b *testing.B) {
216216

217217
func BenchmarkInterpolation(b *testing.B) {
218218
mc := &mysqlConn{
219-
cfg: &config{
220-
interpolateParams: true,
221-
loc: time.UTC,
219+
cfg: &Config{
220+
InterpolateParams: true,
221+
Loc: time.UTC,
222222
},
223223
maxPacketAllowed: maxPacketSize,
224224
maxWriteSize: maxPacketSize - 1,

buffer.go

+19-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
package mysql
1010

11-
import "io"
11+
import (
12+
"io"
13+
"net"
14+
"time"
15+
)
1216

1317
const defaultBufSize = 4096
1418

@@ -18,17 +22,18 @@ const defaultBufSize = 4096
1822
// The buffer is similar to bufio.Reader / Writer but zero-copy-ish
1923
// Also highly optimized for this particular use case.
2024
type buffer struct {
21-
buf []byte
22-
rd io.Reader
23-
idx int
24-
length int
25+
buf []byte
26+
nc net.Conn
27+
idx int
28+
length int
29+
timeout time.Duration
2530
}
2631

27-
func newBuffer(rd io.Reader) buffer {
32+
func newBuffer(nc net.Conn) buffer {
2833
var b [defaultBufSize]byte
2934
return buffer{
3035
buf: b[:],
31-
rd: rd,
36+
nc: nc,
3237
}
3338
}
3439

@@ -54,7 +59,13 @@ func (b *buffer) fill(need int) error {
5459
b.idx = 0
5560

5661
for {
57-
nn, err := b.rd.Read(b.buf[n:])
62+
if b.timeout > 0 {
63+
if err := b.nc.SetReadDeadline(time.Now().Add(b.timeout)); err != nil {
64+
return err
65+
}
66+
}
67+
68+
nn, err := b.nc.Read(b.buf[n:])
5869
n += nn
5970

6071
switch err {

collations.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
package mysql
1010

11-
const defaultCollation byte = 33 // utf8_general_ci
11+
const defaultCollation = "utf8_general_ci"
1212

1313
// A list of available collations mapped to the internal ID.
1414
// To update this map use the following MySQL query:
@@ -237,14 +237,14 @@ var collations = map[string]byte{
237237

238238
// A blacklist of collations which is unsafe to interpolate parameters.
239239
// These multibyte encodings may contains 0x5c (`\`) in their trailing bytes.
240-
var unsafeCollations = map[byte]bool{
241-
1: true, // big5_chinese_ci
242-
13: true, // sjis_japanese_ci
243-
28: true, // gbk_chinese_ci
244-
84: true, // big5_bin
245-
86: true, // gb2312_bin
246-
87: true, // gbk_bin
247-
88: true, // sjis_bin
248-
95: true, // cp932_japanese_ci
249-
96: true, // cp932_bin
240+
var unsafeCollations = map[string]bool{
241+
"big5_chinese_ci": true,
242+
"sjis_japanese_ci": true,
243+
"gbk_chinese_ci": true,
244+
"big5_bin": true,
245+
"gb2312_bin": true,
246+
"gbk_bin": true,
247+
"sjis_bin": true,
248+
"cp932_japanese_ci": true,
249+
"cp932_bin": true,
250250
}

0 commit comments

Comments
 (0)