Skip to content

Merge changes from original repo #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 84 commits into from
Nov 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
7ec062f
Fix issue with NO_AUTO_CREATE_USER option in sql_mode
luizpvas Nov 8, 2015
0da0f4e
Fixes #389 by not sending COM_QUIT until authenticated. Also refactor…
daniel-nichter Dec 6, 2015
0874761
QueryUnescape the tlsConfig name during DSN parsing.
Carrotman42 Dec 24, 2015
bb006fd
Merge pull request #380 from refl/master
julienschmidt Jan 6, 2016
5e93316
Update AUTHORS
Carrotman42 Jan 6, 2016
c9c5955
Merge pull request #397 from Carrotman42/master
julienschmidt Jan 6, 2016
0f5d83a
Use explicit return in handleAuthResult.
daniel-nichter Jan 6, 2016
d8a5f6c
Merge pull request #390 from daniel-nichter/fix-389-socket-auth-fail-…
julienschmidt Jan 6, 2016
de5a0de
Merge pull request #2 from go-sql-driver/master
Carrotman42 Jan 7, 2016
a4041c6
Use Errorf instead of Error in the correct places
Carrotman42 Jan 7, 2016
7a8740a
Merge pull request #400 from Carrotman42/master
arnehormann Jan 7, 2016
d164b60
Update CHANGELOG
julienschmidt Jan 12, 2016
481fa10
Travis: Test with Go 1.5
julienschmidt Jan 13, 2016
6fd058c
Merge pull request #402 from go-sql-driver/go1.5
julienschmidt Jan 13, 2016
c2d7e96
Export ParseDSN and Config
julienschmidt Jan 13, 2016
ec658e9
Fix getSystemVar with parseTime=true
julienschmidt Jan 13, 2016
809154b
Merge pull request #403 from go-sql-driver/dsn
julienschmidt Jan 18, 2016
de0bbfa
read_timeout and write_timeout
chakrit Sep 25, 2015
68ca989
Improve timeouts implementation
julienschmidt Jan 12, 2016
2cd96dd
Update README.md
julienschmidt Jan 12, 2016
f7f9f33
Update README.md
julienschmidt Jan 19, 2016
72ea5d0
Merge pull request #401 from go-sql-driver/timeout
julienschmidt Jan 19, 2016
618fbd9
lint
julienschmidt Jan 19, 2016
ca130be
lazy init tlsConfigRegister
julienschmidt Jan 19, 2016
a059889
reformat errors
julienschmidt Jan 19, 2016
4cad0fb
Revert formating of MySQLError.Error()
julienschmidt Jan 19, 2016
11d51ab
reformat errors in tests
julienschmidt Jan 19, 2016
280e61d
packets: grammar in err message
julienschmidt Jan 20, 2016
acb04ff
Merge pull request #410 from go-sql-driver/lint
julienschmidt Jan 20, 2016
8cbeffa
Enable Multi Results support and discard additional results
lucalooz Apr 12, 2015
5ce0b98
Add Idhor (Luca Looz) to AUTHORS for multi-results
lucalooz Jan 20, 2016
1bdf5bd
added the multiStatements param to the dsn parameter
badoet May 11, 2015
71c5db6
add test for the new dsn param
badoet May 11, 2015
4aa920d
TestMultiQuery
badoet May 12, 2015
acb3ebd
Fix driver tests
julienschmidt Jan 20, 2016
c1e44c4
check discardMoreResultsIfExists err
julienschmidt Jan 20, 2016
023343e
README: add multiStatements
julienschmidt Jan 20, 2016
416bd11
README: Add note on discarded results
julienschmidt Jan 22, 2016
8d8957e
Add field type JSON support
julienschmidt Jan 23, 2016
7c7f556
Merge pull request #414 from go-sql-driver/json
julienschmidt Jan 25, 2016
bba2f88
Rename discardMoreResultsIfExists
julienschmidt Jan 29, 2016
b4db83c
Merge pull request #411 from go-sql-driver/multistmt
julienschmidt Jan 30, 2016
8b688fb
DSN: Add cfg.Format method
julienschmidt Jan 31, 2016
edc7880
README: Add reference to Config.FormatDSN
julienschmidt Feb 3, 2016
acdcb22
Merge pull request #419 from go-sql-driver/dsn
julienschmidt Feb 3, 2016
267b128
README: Fix Config.FormatDSN url
julienschmidt Feb 3, 2016
8675221
Create ISSUE_TEMPLATE.md
julienschmidt Feb 17, 2016
56df6f7
CONTRIBUTING.md: remove issue template
julienschmidt Feb 17, 2016
97f01d0
Create PULL_REQUEST_TEMPLATE.md
julienschmidt Feb 17, 2016
1309049
CONTRIBUTING.md: remove PR checklist
julienschmidt Feb 17, 2016
e294c69
LOAD LOCAL can send file larger than max_allowed_packet
methane Feb 23, 2016
71f003c
Merge pull request #424 from methane/feature/load-local
arnehormann Feb 24, 2016
5ec60c2
add requirements to Config field comments
arnehormann Mar 1, 2016
fcfd2fe
doc: tests should fail without the change
arnehormann Mar 1, 2016
1e1fb86
Merge pull request #430 from arnehormann/improve-commit-reqs
arnehormann Mar 1, 2016
193c826
comment formatting
arnehormann Mar 1, 2016
44e7035
Merge pull request #429 from arnehormann/doc-config-reqs
arnehormann Mar 1, 2016
922457a
document multiStatement parameter restriction, fixes #426
arnehormann Mar 1, 2016
1fca743
Merge pull request #431 from arnehormann/fix-426
arnehormann Mar 1, 2016
5e1ab9e
Travis: Test with Go 1.6
appleboy Mar 2, 2016
0e81889
test and fix for MysSQL float parsing into float64 when placeholders …
pib Mar 3, 2016
f47acb0
Add myself to AUTHORS
pib Mar 3, 2016
0f2db9e
Merge pull request #432 from appleboy/patch-2
julienschmidt Mar 4, 2016
5a9482c
Fix error reported by `go vet`
dveeden Mar 7, 2016
66312f7
Merge pull request #437 from dveeden/fix_go_vet_driver_test
julienschmidt Mar 10, 2016
82cddef
Add support for connection attributes.
dveeden Apr 26, 2015
2625e19
Merge pull request #350 from dveeden/connattrs_v4
arnehormann Mar 29, 2016
1421caf
Revert "Merge pull request #350 from dveeden/connattrs_v4"
julienschmidt Mar 29, 2016
7ebe0a5
Merge pull request #434 from pib/fix_float_with_placeholder
julienschmidt Apr 11, 2016
152796f
Fix dsn_test.go to work with Go 1.7
dsnet Jun 1, 2016
3654d25
Merge pull request #459 from dsnet/master
julienschmidt Jun 2, 2016
c6f6102
readUntilEOF should support ERR packet
methane Aug 2, 2016
0b58b37
Merge pull request #473 from methane/fix-464
julienschmidt Aug 2, 2016
127a48c
travis.yml: Test with Go 1.7
julienschmidt Oct 20, 2016
7fcf04e
Add test to reproduce #467
methane Oct 20, 2016
a044747
Fix index out of range in interpolateParams.
methane Oct 20, 2016
82e447e
fixup
methane Oct 20, 2016
dbc3fe2
add comment
methane Oct 20, 2016
1983bc3
README: Include Difference in Connection Strings depending on Cloud S…
lennrt Oct 25, 2016
b81e73c
Add maxAllowedPacket DSN Parameter
xiezhenye Oct 26, 2016
68ea39f
README: Clarify strict mode (#500)
julienschmidt Oct 26, 2016
de9c517
README: Sort variables alphabetically
julienschmidt Oct 26, 2016
2a6c607
Update CHANGELOG
julienschmidt Oct 26, 2016
ce924a4
Support authentication switch with mysql_native_password authenticati…
twocode Nov 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ go:
- 1.2
- 1.3
- 1.4
- 1.5
- 1.6
- 1.7
- tip

before_script:
Expand Down
11 changes: 10 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Aaron Hopkins <go-sql-driver at die.net>
Arne Hormann <arnehormann at gmail.com>
Carlos Nieto <jose.carlos at menteslibres.net>
Chris Moos <chris at tech9computers.com>
Daniel Nichter <nil at codenode.com>
Daniël van Eeden <git at myname.nl>
DisposaBoy <disposaboy at dby.me>
Frederick Mayle <frederickmayle at gmail.com>
Gustavo Kristic <gkristic at gmail.com>
Expand All @@ -25,19 +27,26 @@ INADA Naoki <songofacandy at gmail.com>
James Harr <james.harr at gmail.com>
Jian Zhen <zhenjl at gmail.com>
Joshua Prunier <joshua.prunier at gmail.com>
Julien Lefevre <julien.lefevr at gmail.com>
Julien Schmidt <go-sql-driver at julienschmidt.com>
Kamil Dziedzic <kamil at klecza.pl>
Kevin Malachowski <kevin at chowski.com>
Lennart Rudolph <lrudolph at hmc.edu>
Leonardo YongUk Kim <dalinaum at gmail.com>
Luca Looz <luca.looz92 at gmail.com>
Lucas Liu <extrafliu at gmail.com>
Luke Scott <luke at webconnex.com>
Michael Woolnough <michael.woolnough at gmail.com>
Nicola Peduzzi <thenikso at gmail.com>
Paul Bonser <misterpib at gmail.com>
Runrioter Wung <runrioter at gmail.com>
Soroush Pour <me at soroushjp.com>
Stan Putrya <root.vagner at gmail.com>
Stanley Gunawan <gunawan.stanley at gmail.com>
Xiangyu Hu <xiangyu.hu at outlook.com>
Xiaobing Jiang <s7v7nislands at gmail.com>
Xiuming Chen <cc at cxm.cc>
Julien Lefevre <julien.lefevr at gmail.com>
Zhenye Xie <xiezhenye at gmail.com>

# Organizations

Expand Down
34 changes: 28 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,41 @@
Changes:

- Go 1.1 is no longer supported
- Use decimals field from MySQL to format time types (#249)
- Use decimals fields in MySQL to format time types (#249)
- Buffer optimizations (#269)
- TLS ServerName defaults to the host (#283)
- Refactoring (#400, #410, #437)
- Adjusted documentation for second generation CloudSQL (#485)

Bugfixes:
New Features:

- Enable microsecond resolution on TIME, DATETIME and TIMESTAMP (#249)
- Support for returning table alias on Columns() (#289, #359, #382)
- Placeholder interpolation, can be actived with the DSN parameter `interpolateParams=true` (#309, #318, #490)
- Support for uint64 parameters with high bit set (#332, #345)
- Cleartext authentication plugin support (#327)
- Exported ParseDSN function and the Config struct (#403, #419, #429)
- Read / Write timeouts (#401)
- Support for JSON field type (#414)
- Support for multi-statements and multi-results (#411, #431)
- DSN parameter to set the driver-side max_allowed_packet value manually (#489)

Bugfixes:

- Fixed handling of queries without columns and rows (#255)
- Fixed a panic when SetKeepAlive() failed (#298)

New Features:
- Support for returning table alias on Columns() (#289)
- Placeholder interpolation, can be actived with the DSN parameter `interpolateParams=true` (#309, #318)
- Handle ERR packets while reading rows (#321)
- Fixed reading NULL length-encoded integers in MySQL 5.6+ (#349)
- Fixed absolute paths support in LOAD LOCAL DATA INFILE (#356)
- Actually zero out bytes in handshake response (#378)
- Fixed race condition in registering LOAD DATA INFILE handler (#383)
- Fixed tests with MySQL 5.7.9+ (#380)
- QueryUnescape TLS config names (#397)
- Fixed "broken pipe" error by writing to closed socket (#390)
- Fixed LOAD LOCAL DATA INFILE buffering (#424)
- Fixed parsing of floats into float64 when placeholders are used (#434)
- Fixed DSN tests with Go 1.7+ (#459)
- Handle ERR packets while waiting for EOF (#473)


## Version 1.2 (2014-06-03)
Expand Down
17 changes: 0 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,11 @@

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).

Please provide the following minimum information:
* Your Go-MySQL-Driver version (or git SHA)
* Your Go version (run `go version` in your console)
* A detailed issue description
* Error Log if present
* If possible, a short example


## Contributing Code

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

### Pull Requests Checklist

Please check the following points before submitting your pull request:
- [x] Code compiles correctly
- [x] Created tests, if possible
- [x] All tests pass
- [x] Extended the README / documentation, if necessary
- [x] Added yourself to the AUTHORS file

### Code Review

Everyone is invited to review and comment on pull requests.
Expand Down
21 changes: 21 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Issue description
Tell us what should happen and what happens instead

### Example code
```go
If possible, please enter some example code here to reproduce the issue.
```

### Error log
```
If you have an error log, please paste it here.
```

### Configuration
*Driver version (or git SHA):*

*Go version:* run `go version` in your console

*Server version:* E.g. MySQL 5.6, MariaDB 10.0.20

*Server OS:* E.g. Debian 8.1 (Jessie), Windows 10
9 changes: 9 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Description
Please explain the changes you made here.

### Checklist
- [ ] Code compiles correctly
- [ ] Created tests which fail without the change (if possible)
- [ ] All tests passing
- [ ] Extended the README / documentation, if necessary
- [ ] Added myself / the copyright holder to the AUTHORS file
67 changes: 60 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ This has the same effect as an empty DSN string:

```

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.

#### Password
Passwords can consist of any character. Escaping is **not** necessary.

Expand Down Expand Up @@ -133,6 +135,15 @@ Default: false

`allowCleartextPasswords=true` allows using the [cleartext client side plugin](http://dev.mysql.com/doc/en/cleartext-authentication-plugin.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.

##### `allowNativePasswords`

```
Type: bool
Valid Values: true, false
Default: false
```
`allowNativePasswords=true` allows the usage of the mysql native password method.

##### `allowOldPasswords`

```
Expand Down Expand Up @@ -219,6 +230,25 @@ Note that this sets the location for time.Time values but does not change MySQL'

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`.

##### `maxAllowedPacket`
```
Type: decimal number
Default: 0
```

Max packet size allowed in bytes. Use `maxAllowedPacket=0` to automatically fetch the `max_allowed_packet` variable from server.

##### `multiStatements`

```
Type: bool
Valid Values: true, false
Default: false
```

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.

When `multiStatements` is used, `?` parameters must only be used in the first statement.

##### `parseTime`

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


##### `readTimeout`

```
Type: decimal number
Default: 0
```

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"*.

##### `strict`

```
Expand All @@ -239,10 +278,11 @@ Valid Values: true, false
Default: false
```

`strict=true` enables the strict mode in which MySQL warnings are treated as errors.
`strict=true` enables a driver-side strict mode in which MySQL warnings are treated as errors. This mode should not be used in production as it may lead to data corruption in certain situations.

By default MySQL also treats notes as warnings. Use [`sql_notes=false`](http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_sql_notes) to ignore notes. See the [examples](#examples) for an DSN example.
A server-side strict mode, which is safe for production use, can be set via the [`sql_mode`](https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html) system variable.

By default MySQL also treats notes as warnings. Use [`sql_notes=false`](http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_sql_notes) to ignore notes.

##### `timeout`

Expand All @@ -251,8 +291,7 @@ Type: decimal number
Default: OS default
```

*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).

*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).

##### `tls`

Expand All @@ -264,6 +303,15 @@ Default: false

`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).

##### `writeTimeout`

```
Type: decimal number
Default: 0
```

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"*.


##### System Variables

Expand All @@ -288,9 +336,9 @@ root:pw@unix(/tmp/mysql.sock)/myDatabase?loc=Local
user:password@tcp(localhost:5555)/dbname?tls=skip-verify&autocommit=true
```

Use the [strict mode](#strict) but ignore notes:
Treat warnings as errors by setting the system variable [`sql_mode`](https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html):
```
user:password@/dbname?strict=true&sql_notes=false
user:password@/dbname?sql_mode=TRADITIONAL
```

TCP via IPv6:
Expand All @@ -303,11 +351,16 @@ TCP on a remote host, e.g. Amazon RDS:
id:password@tcp(your-amazonaws-uri.com:3306)/dbname
```

Google Cloud SQL on App Engine:
Google Cloud SQL on App Engine (First Generation MySQL Server):
```
user@cloudsql(project-id:instance-name)/dbname
```

Google Cloud SQL on App Engine (Second Generation MySQL Server):
```
user@cloudsql(project-id:regionname:instance-name)/dbname
```

TCP using default port (3306) on localhost:
```
user:password@tcp/dbname?charset=utf8mb4,utf8&sys_var=esc%40ped
Expand Down
12 changes: 6 additions & 6 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func initDB(b *testing.B, queries ...string) *sql.DB {
for _, query := range queries {
if _, err := db.Exec(query); err != nil {
if w, ok := err.(MySQLWarnings); ok {
b.Logf("Warning on %q: %v", query, w)
b.Logf("warning on %q: %v", query, w)
} else {
b.Fatalf("Error on %q: %v", query, err)
b.Fatalf("error on %q: %v", query, err)
}
}
}
Expand Down Expand Up @@ -216,11 +216,11 @@ func BenchmarkRoundtripBin(b *testing.B) {

func BenchmarkInterpolation(b *testing.B) {
mc := &mysqlConn{
cfg: &config{
interpolateParams: true,
loc: time.UTC,
cfg: &Config{
InterpolateParams: true,
Loc: time.UTC,
},
maxPacketAllowed: maxPacketSize,
maxAllowedPacket: maxPacketSize,
maxWriteSize: maxPacketSize - 1,
buf: newBuffer(nil),
}
Expand Down
27 changes: 19 additions & 8 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

package mysql

import "io"
import (
"io"
"net"
"time"
)

const defaultBufSize = 4096

Expand All @@ -18,17 +22,18 @@ const defaultBufSize = 4096
// The buffer is similar to bufio.Reader / Writer but zero-copy-ish
// Also highly optimized for this particular use case.
type buffer struct {
buf []byte
rd io.Reader
idx int
length int
buf []byte
nc net.Conn
idx int
length int
timeout time.Duration
}

func newBuffer(rd io.Reader) buffer {
func newBuffer(nc net.Conn) buffer {
var b [defaultBufSize]byte
return buffer{
buf: b[:],
rd: rd,
nc: nc,
}
}

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

for {
nn, err := b.rd.Read(b.buf[n:])
if b.timeout > 0 {
if err := b.nc.SetReadDeadline(time.Now().Add(b.timeout)); err != nil {
return err
}
}

nn, err := b.nc.Read(b.buf[n:])
n += nn

switch err {
Expand Down
Loading