Browse Source

vendor changes, including mysql driver

tags/v2.0.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
c34477c937
37 changed files with 7157 additions and 14 deletions
  1. 9
    0
      vendor/github.com/go-sql-driver/mysql/.gitignore
  2. 129
    0
      vendor/github.com/go-sql-driver/mysql/.travis.yml
  3. 105
    0
      vendor/github.com/go-sql-driver/mysql/AUTHORS
  4. 206
    0
      vendor/github.com/go-sql-driver/mysql/CHANGELOG.md
  5. 373
    0
      vendor/github.com/go-sql-driver/mysql/LICENSE
  6. 501
    0
      vendor/github.com/go-sql-driver/mysql/README.md
  7. 422
    0
      vendor/github.com/go-sql-driver/mysql/auth.go
  8. 182
    0
      vendor/github.com/go-sql-driver/mysql/buffer.go
  9. 265
    0
      vendor/github.com/go-sql-driver/mysql/collations.go
  10. 54
    0
      vendor/github.com/go-sql-driver/mysql/conncheck.go
  11. 17
    0
      vendor/github.com/go-sql-driver/mysql/conncheck_dummy.go
  12. 651
    0
      vendor/github.com/go-sql-driver/mysql/connection.go
  13. 146
    0
      vendor/github.com/go-sql-driver/mysql/connector.go
  14. 174
    0
      vendor/github.com/go-sql-driver/mysql/const.go
  15. 107
    0
      vendor/github.com/go-sql-driver/mysql/driver.go
  16. 560
    0
      vendor/github.com/go-sql-driver/mysql/dsn.go
  17. 65
    0
      vendor/github.com/go-sql-driver/mysql/errors.go
  18. 194
    0
      vendor/github.com/go-sql-driver/mysql/fields.go
  19. 3
    0
      vendor/github.com/go-sql-driver/mysql/go.mod
  20. 182
    0
      vendor/github.com/go-sql-driver/mysql/infile.go
  21. 50
    0
      vendor/github.com/go-sql-driver/mysql/nulltime.go
  22. 31
    0
      vendor/github.com/go-sql-driver/mysql/nulltime_go113.go
  23. 34
    0
      vendor/github.com/go-sql-driver/mysql/nulltime_legacy.go
  24. 1342
    0
      vendor/github.com/go-sql-driver/mysql/packets.go
  25. 22
    0
      vendor/github.com/go-sql-driver/mysql/result.go
  26. 223
    0
      vendor/github.com/go-sql-driver/mysql/rows.go
  27. 204
    0
      vendor/github.com/go-sql-driver/mysql/statement.go
  28. 31
    0
      vendor/github.com/go-sql-driver/mysql/transaction.go
  29. 701
    0
      vendor/github.com/go-sql-driver/mysql/utils.go
  30. 1
    0
      vendor/golang.org/x/sys/unix/mkerrors.sh
  31. 11
    1
      vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go
  32. 11
    1
      vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go
  33. 1
    3
      vendor/golang.org/x/sys/windows/security_windows.go
  34. 55
    0
      vendor/golang.org/x/sys/windows/syscall_windows.go
  35. 33
    0
      vendor/golang.org/x/sys/windows/types_windows.go
  36. 52
    0
      vendor/golang.org/x/sys/windows/zsyscall_windows.go
  37. 10
    9
      vendor/modules.txt

+ 9
- 0
vendor/github.com/go-sql-driver/mysql/.gitignore View File

@@ -0,0 +1,9 @@
1
+.DS_Store
2
+.DS_Store?
3
+._*
4
+.Spotlight-V100
5
+.Trashes
6
+Icon?
7
+ehthumbs.db
8
+Thumbs.db
9
+.idea

+ 129
- 0
vendor/github.com/go-sql-driver/mysql/.travis.yml View File

@@ -0,0 +1,129 @@
1
+sudo: false
2
+language: go
3
+go:
4
+  - 1.10.x
5
+  - 1.11.x
6
+  - 1.12.x
7
+  - 1.13.x
8
+  - master
9
+
10
+before_install:
11
+  - go get golang.org/x/tools/cmd/cover
12
+  - go get github.com/mattn/goveralls
13
+
14
+before_script:
15
+  - echo -e "[server]\ninnodb_log_file_size=256MB\ninnodb_buffer_pool_size=512MB\nmax_allowed_packet=16MB" | sudo tee -a /etc/mysql/my.cnf
16
+  - sudo service mysql restart
17
+  - .travis/wait_mysql.sh
18
+  - mysql -e 'create database gotest;'
19
+
20
+matrix:
21
+  include:
22
+    - env: DB=MYSQL8
23
+      sudo: required
24
+      dist: trusty
25
+      go: 1.10.x
26
+      services:
27
+        - docker
28
+      before_install:
29
+        - go get golang.org/x/tools/cmd/cover
30
+        - go get github.com/mattn/goveralls
31
+        - docker pull mysql:8.0
32
+        - 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
33
+          mysql:8.0 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
34
+        - cp .travis/docker.cnf ~/.my.cnf
35
+        - .travis/wait_mysql.sh
36
+      before_script:
37
+        - export MYSQL_TEST_USER=gotest
38
+        - export MYSQL_TEST_PASS=secret
39
+        - export MYSQL_TEST_ADDR=127.0.0.1:3307
40
+        - export MYSQL_TEST_CONCURRENT=1
41
+
42
+    - env: DB=MYSQL57
43
+      sudo: required
44
+      dist: trusty
45
+      go: 1.10.x
46
+      services:
47
+        - docker
48
+      before_install:
49
+        - go get golang.org/x/tools/cmd/cover
50
+        - go get github.com/mattn/goveralls
51
+        - docker pull mysql:5.7
52
+        - 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
53
+          mysql:5.7 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
54
+        - cp .travis/docker.cnf ~/.my.cnf
55
+        - .travis/wait_mysql.sh
56
+      before_script:
57
+        - export MYSQL_TEST_USER=gotest
58
+        - export MYSQL_TEST_PASS=secret
59
+        - export MYSQL_TEST_ADDR=127.0.0.1:3307
60
+        - export MYSQL_TEST_CONCURRENT=1
61
+
62
+    - env: DB=MARIA55
63
+      sudo: required
64
+      dist: trusty
65
+      go: 1.10.x
66
+      services:
67
+        - docker
68
+      before_install:
69
+        - go get golang.org/x/tools/cmd/cover
70
+        - go get github.com/mattn/goveralls
71
+        - docker pull mariadb:5.5
72
+        - 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
73
+          mariadb:5.5 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
74
+        - cp .travis/docker.cnf ~/.my.cnf
75
+        - .travis/wait_mysql.sh
76
+      before_script:
77
+        - export MYSQL_TEST_USER=gotest
78
+        - export MYSQL_TEST_PASS=secret
79
+        - export MYSQL_TEST_ADDR=127.0.0.1:3307
80
+        - export MYSQL_TEST_CONCURRENT=1
81
+
82
+    - env: DB=MARIA10_1
83
+      sudo: required
84
+      dist: trusty
85
+      go: 1.10.x
86
+      services:
87
+        - docker
88
+      before_install:
89
+        - go get golang.org/x/tools/cmd/cover
90
+        - go get github.com/mattn/goveralls
91
+        - docker pull mariadb:10.1
92
+        - 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
93
+          mariadb:10.1 --innodb_log_file_size=256MB --innodb_buffer_pool_size=512MB --max_allowed_packet=16MB --local-infile=1
94
+        - cp .travis/docker.cnf ~/.my.cnf
95
+        - .travis/wait_mysql.sh
96
+      before_script:
97
+        - export MYSQL_TEST_USER=gotest
98
+        - export MYSQL_TEST_PASS=secret
99
+        - export MYSQL_TEST_ADDR=127.0.0.1:3307
100
+        - export MYSQL_TEST_CONCURRENT=1
101
+
102
+    - os: osx
103
+      osx_image: xcode10.1
104
+      addons:
105
+        homebrew:
106
+          packages:
107
+            - mysql
108
+          update: true
109
+      go: 1.12.x
110
+      before_install:
111
+        - go get golang.org/x/tools/cmd/cover
112
+        - go get github.com/mattn/goveralls
113
+      before_script:
114
+        - echo -e "[server]\ninnodb_log_file_size=256MB\ninnodb_buffer_pool_size=512MB\nmax_allowed_packet=16MB\nlocal_infile=1" >> /usr/local/etc/my.cnf
115
+        - mysql.server start
116
+        - mysql -uroot -e 'CREATE USER gotest IDENTIFIED BY "secret"'
117
+        - mysql -uroot -e 'GRANT ALL ON *.* TO gotest'
118
+        - mysql -uroot -e 'create database gotest;'
119
+        - export MYSQL_TEST_USER=gotest
120
+        - export MYSQL_TEST_PASS=secret
121
+        - export MYSQL_TEST_ADDR=127.0.0.1:3306
122
+        - export MYSQL_TEST_CONCURRENT=1
123
+
124
+script:
125
+  - go test -v -covermode=count -coverprofile=coverage.out
126
+  - go vet ./...
127
+  - .travis/gofmt.sh
128
+after_script:
129
+  - $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci

+ 105
- 0
vendor/github.com/go-sql-driver/mysql/AUTHORS View File

@@ -0,0 +1,105 @@
1
+# This is the official list of Go-MySQL-Driver authors for copyright purposes.
2
+
3
+# If you are submitting a patch, please add your name or the name of the
4
+# organization which holds the copyright to this list in alphabetical order.
5
+
6
+# Names should be added to this file as
7
+#	Name <email address>
8
+# The email address is not required for organizations.
9
+# Please keep the list sorted.
10
+
11
+
12
+# Individual Persons
13
+
14
+Aaron Hopkins <go-sql-driver at die.net>
15
+Achille Roussel <achille.roussel at gmail.com>
16
+Alexey Palazhchenko <alexey.palazhchenko at gmail.com>
17
+Andrew Reid <andrew.reid at tixtrack.com>
18
+Arne Hormann <arnehormann at gmail.com>
19
+Asta Xie <xiemengjun at gmail.com>
20
+Bulat Gaifullin <gaifullinbf at gmail.com>
21
+Carlos Nieto <jose.carlos at menteslibres.net>
22
+Chris Moos <chris at tech9computers.com>
23
+Craig Wilson <craiggwilson at gmail.com>
24
+Daniel Montoya <dsmontoyam at gmail.com>
25
+Daniel Nichter <nil at codenode.com>
26
+Daniël van Eeden <git at myname.nl>
27
+Dave Protasowski <dprotaso at gmail.com>
28
+DisposaBoy <disposaboy at dby.me>
29
+Egor Smolyakov <egorsmkv at gmail.com>
30
+Erwan Martin <hello at erwan.io>
31
+Evan Shaw <evan at vendhq.com>
32
+Frederick Mayle <frederickmayle at gmail.com>
33
+Gustavo Kristic <gkristic at gmail.com>
34
+Hajime Nakagami <nakagami at gmail.com>
35
+Hanno Braun <mail at hannobraun.com>
36
+Henri Yandell <flamefew at gmail.com>
37
+Hirotaka Yamamoto <ymmt2005 at gmail.com>
38
+Huyiguang <hyg at webterren.com>
39
+ICHINOSE Shogo <shogo82148 at gmail.com>
40
+Ilia Cimpoes <ichimpoesh at gmail.com>
41
+INADA Naoki <songofacandy at gmail.com>
42
+Jacek Szwec <szwec.jacek at gmail.com>
43
+James Harr <james.harr at gmail.com>
44
+Jeff Hodges <jeff at somethingsimilar.com>
45
+Jeffrey Charles <jeffreycharles at gmail.com>
46
+Jerome Meyer <jxmeyer at gmail.com>
47
+Jiajia Zhong <zhong2plus at gmail.com>
48
+Jian Zhen <zhenjl at gmail.com>
49
+Joshua Prunier <joshua.prunier at gmail.com>
50
+Julien Lefevre <julien.lefevr at gmail.com>
51
+Julien Schmidt <go-sql-driver at julienschmidt.com>
52
+Justin Li <jli at j-li.net>
53
+Justin Nuß <nuss.justin at gmail.com>
54
+Kamil Dziedzic <kamil at klecza.pl>
55
+Kevin Malachowski <kevin at chowski.com>
56
+Kieron Woodhouse <kieron.woodhouse at infosum.com>
57
+Lennart Rudolph <lrudolph at hmc.edu>
58
+Leonardo YongUk Kim <dalinaum at gmail.com>
59
+Linh Tran Tuan <linhduonggnu at gmail.com>
60
+Lion Yang <lion at aosc.xyz>
61
+Luca Looz <luca.looz92 at gmail.com>
62
+Lucas Liu <extrafliu at gmail.com>
63
+Luke Scott <luke at webconnex.com>
64
+Maciej Zimnoch <maciej.zimnoch at codilime.com>
65
+Michael Woolnough <michael.woolnough at gmail.com>
66
+Nathanial Murphy <nathanial.murphy at gmail.com>
67
+Nicola Peduzzi <thenikso at gmail.com>
68
+Olivier Mengué <dolmen at cpan.org>
69
+oscarzhao <oscarzhaosl at gmail.com>
70
+Paul Bonser <misterpib at gmail.com>
71
+Peter Schultz <peter.schultz at classmarkets.com>
72
+Rebecca Chin <rchin at pivotal.io>
73
+Reed Allman <rdallman10 at gmail.com>
74
+Richard Wilkes <wilkes at me.com>
75
+Robert Russell <robert at rrbrussell.com>
76
+Runrioter Wung <runrioter at gmail.com>
77
+Shuode Li <elemount at qq.com>
78
+Simon J Mudd <sjmudd at pobox.com>
79
+Soroush Pour <me at soroushjp.com>
80
+Stan Putrya <root.vagner at gmail.com>
81
+Stanley Gunawan <gunawan.stanley at gmail.com>
82
+Steven Hartland <steven.hartland at multiplay.co.uk>
83
+Thomas Wodarek <wodarekwebpage at gmail.com>
84
+Tim Ruffles <timruffles at gmail.com>
85
+Tom Jenkinson <tom at tjenkinson.me>
86
+Vladimir Kovpak <cn007b at gmail.com>
87
+Xiangyu Hu <xiangyu.hu at outlook.com>
88
+Xiaobing Jiang <s7v7nislands at gmail.com>
89
+Xiuming Chen <cc at cxm.cc>
90
+Zhenye Xie <xiezhenye at gmail.com>
91
+
92
+# Organizations
93
+
94
+Barracuda Networks, Inc.
95
+Counting Ltd.
96
+DigitalOcean Inc.
97
+Facebook Inc.
98
+GitHub Inc.
99
+Google Inc.
100
+InfoSum Ltd.
101
+Keybase Inc.
102
+Multiplay Ltd.
103
+Percona LLC
104
+Pivotal Inc.
105
+Stripe Inc.

+ 206
- 0
vendor/github.com/go-sql-driver/mysql/CHANGELOG.md View File

@@ -0,0 +1,206 @@
1
+## Version 1.5 (2020-01-07)
2
+
3
+Changes:
4
+
5
+  - Dropped support Go 1.9 and lower (#823, #829, #886, #1016, #1017)
6
+  - Improve buffer handling (#890)
7
+  - Document potentially insecure TLS configs (#901)
8
+  - Use a double-buffering scheme to prevent data races (#943)
9
+  - Pass uint64 values without converting them to string (#838, #955)
10
+  - Update collations and make utf8mb4 default (#877, #1054)
11
+  - Make NullTime compatible with sql.NullTime in Go 1.13+ (#995)
12
+  - Removed CloudSQL support (#993, #1007)
13
+  - Add Go Module support (#1003)
14
+
15
+New Features:
16
+
17
+  - Implement support of optional TLS (#900)
18
+  - Check connection liveness (#934, #964, #997, #1048, #1051, #1052)
19
+  - Implement Connector Interface (#941, #958, #1020, #1035)
20
+
21
+Bugfixes:
22
+
23
+  - Mark connections as bad on error during ping (#875)
24
+  - Mark connections as bad on error during dial (#867)
25
+  - Fix connection leak caused by rapid context cancellation (#1024)
26
+  - Mark connections as bad on error during Conn.Prepare (#1030)
27
+
28
+
29
+## Version 1.4.1 (2018-11-14)
30
+
31
+Bugfixes:
32
+
33
+ - Fix TIME format for binary columns (#818)
34
+ - Fix handling of empty auth plugin names (#835)
35
+ - Fix caching_sha2_password with empty password (#826)
36
+ - Fix canceled context broke mysqlConn (#862)
37
+ - Fix OldAuthSwitchRequest support (#870)
38
+ - Fix Auth Response packet for cleartext password (#887)
39
+
40
+## Version 1.4 (2018-06-03)
41
+
42
+Changes:
43
+
44
+ - Documentation fixes (#530, #535, #567)
45
+ - Refactoring (#575, #579, #580, #581, #603, #615, #704)
46
+ - Cache column names (#444)
47
+ - Sort the DSN parameters in DSNs generated from a config (#637)
48
+ - Allow native password authentication by default (#644)
49
+ - Use the default port if it is missing in the DSN (#668)
50
+ - Removed the `strict` mode (#676)
51
+ - Do not query `max_allowed_packet` by default (#680)
52
+ - Dropped support Go 1.6 and lower (#696)
53
+ - Updated `ConvertValue()` to match the database/sql/driver implementation (#760)
54
+ - Document the usage of `0000-00-00T00:00:00` as the time.Time zero value (#783)
55
+ - Improved the compatibility of the authentication system (#807)
56
+
57
+New Features:
58
+
59
+ - Multi-Results support (#537)
60
+ - `rejectReadOnly` DSN option (#604)
61
+ - `context.Context` support (#608, #612, #627, #761)
62
+ - Transaction isolation level support (#619, #744)
63
+ - Read-Only transactions support (#618, #634)
64
+ - `NewConfig` function which initializes a config with default values (#679)
65
+ - Implemented the `ColumnType` interfaces (#667, #724)
66
+ - Support for custom string types in `ConvertValue` (#623)
67
+ - Implemented `NamedValueChecker`, improving support for uint64 with high bit set (#690, #709, #710)
68
+ - `caching_sha2_password` authentication plugin support (#794, #800, #801, #802)
69
+ - Implemented `driver.SessionResetter` (#779)
70
+ - `sha256_password` authentication plugin support (#808)
71
+
72
+Bugfixes:
73
+
74
+ - Use the DSN hostname as TLS default ServerName if `tls=true` (#564, #718)
75
+ - Fixed LOAD LOCAL DATA INFILE for empty files (#590)
76
+ - Removed columns definition cache since it sometimes cached invalid data (#592)
77
+ - Don't mutate registered TLS configs (#600)
78
+ - Make RegisterTLSConfig concurrency-safe (#613)
79
+ - Handle missing auth data in the handshake packet correctly (#646)
80
+ - Do not retry queries when data was written to avoid data corruption (#302, #736)
81
+ - Cache the connection pointer for error handling before invalidating it (#678)
82
+ - Fixed imports for appengine/cloudsql (#700)
83
+ - Fix sending STMT_LONG_DATA for 0 byte data (#734)
84
+ - Set correct capacity for []bytes read from length-encoded strings (#766)
85
+ - Make RegisterDial concurrency-safe (#773)
86
+
87
+
88
+## Version 1.3 (2016-12-01)
89
+
90
+Changes:
91
+
92
+ - Go 1.1 is no longer supported
93
+ - Use decimals fields in MySQL to format time types (#249)
94
+ - Buffer optimizations (#269)
95
+ - TLS ServerName defaults to the host (#283)
96
+ - Refactoring (#400, #410, #437)
97
+ - Adjusted documentation for second generation CloudSQL (#485)
98
+ - Documented DSN system var quoting rules (#502)
99
+ - Made statement.Close() calls idempotent to avoid errors in Go 1.6+ (#512)
100
+
101
+New Features:
102
+
103
+ - Enable microsecond resolution on TIME, DATETIME and TIMESTAMP (#249)
104
+ - Support for returning table alias on Columns() (#289, #359, #382)
105
+ - Placeholder interpolation, can be actived with the DSN parameter `interpolateParams=true` (#309, #318, #490)
106
+ - Support for uint64 parameters with high bit set (#332, #345)
107
+ - Cleartext authentication plugin support (#327)
108
+ - Exported ParseDSN function and the Config struct (#403, #419, #429)
109
+ - Read / Write timeouts (#401)
110
+ - Support for JSON field type (#414)
111
+ - Support for multi-statements and multi-results (#411, #431)
112
+ - DSN parameter to set the driver-side max_allowed_packet value manually (#489)
113
+ - Native password authentication plugin support (#494, #524)
114
+
115
+Bugfixes:
116
+
117
+ - Fixed handling of queries without columns and rows (#255)
118
+ - Fixed a panic when SetKeepAlive() failed (#298)
119
+ - Handle ERR packets while reading rows (#321)
120
+ - Fixed reading NULL length-encoded integers in MySQL 5.6+ (#349)
121
+ - Fixed absolute paths support in LOAD LOCAL DATA INFILE (#356)
122
+ - Actually zero out bytes in handshake response (#378)
123
+ - Fixed race condition in registering LOAD DATA INFILE handler (#383)
124
+ - Fixed tests with MySQL 5.7.9+ (#380)
125
+ - QueryUnescape TLS config names (#397)
126
+ - Fixed "broken pipe" error by writing to closed socket (#390)
127
+ - Fixed LOAD LOCAL DATA INFILE buffering (#424)
128
+ - Fixed parsing of floats into float64 when placeholders are used (#434)
129
+ - Fixed DSN tests with Go 1.7+ (#459)
130
+ - Handle ERR packets while waiting for EOF (#473)
131
+ - Invalidate connection on error while discarding additional results (#513)
132
+ - Allow terminating packets of length 0 (#516)
133
+
134
+
135
+## Version 1.2 (2014-06-03)
136
+
137
+Changes:
138
+
139
+ - We switched back to a "rolling release". `go get` installs the current master branch again
140
+ - Version v1 of the driver will not be maintained anymore. Go 1.0 is no longer supported by this driver
141
+ - Exported errors to allow easy checking from application code
142
+ - Enabled TCP Keepalives on TCP connections
143
+ - Optimized INFILE handling (better buffer size calculation, lazy init, ...)
144
+ - The DSN parser also checks for a missing separating slash
145
+ - Faster binary date / datetime to string formatting
146
+ - Also exported the MySQLWarning type
147
+ - mysqlConn.Close returns the first error encountered instead of ignoring all errors
148
+ - writePacket() automatically writes the packet size to the header
149
+ - readPacket() uses an iterative approach instead of the recursive approach to merge splitted packets
150
+
151
+New Features:
152
+
153
+ - `RegisterDial` allows the usage of a custom dial function to establish the network connection
154
+ - Setting the connection collation is possible with the `collation` DSN parameter. This parameter should be preferred over the `charset` parameter
155
+ - Logging of critical errors is configurable with `SetLogger`
156
+ - Google CloudSQL support
157
+
158
+Bugfixes:
159
+
160
+ - Allow more than 32 parameters in prepared statements
161
+ - Various old_password fixes
162
+ - Fixed TestConcurrent test to pass Go's race detection
163
+ - Fixed appendLengthEncodedInteger for large numbers
164
+ - Renamed readLengthEnodedString to readLengthEncodedString and skipLengthEnodedString to skipLengthEncodedString (fixed typo)
165
+
166
+
167
+## Version 1.1 (2013-11-02)
168
+
169
+Changes:
170
+
171
+  - Go-MySQL-Driver now requires Go 1.1
172
+  - Connections now use the collation `utf8_general_ci` by default. Adding `&charset=UTF8` to the DSN should not be necessary anymore
173
+  - Made closing rows and connections error tolerant. This allows for example deferring rows.Close() without checking for errors
174
+  - `[]byte(nil)` is now treated as a NULL value. Before, it was treated like an empty string / `[]byte("")`
175
+  - DSN parameter values must now be url.QueryEscape'ed. This allows text values to contain special characters, such as '&'.
176
+  - Use the IO buffer also for writing. This results in zero allocations (by the driver) for most queries
177
+  - Optimized the buffer for reading
178
+  - stmt.Query now caches column metadata
179
+  - New Logo
180
+  - Changed the copyright header to include all contributors
181
+  - Improved the LOAD INFILE documentation
182
+  - The driver struct is now exported to make the driver directly accessible
183
+  - Refactored the driver tests
184
+  - Added more benchmarks and moved all to a separate file
185
+  - Other small refactoring
186
+
187
+New Features:
188
+
189
+  - Added *old_passwords* support: Required in some cases, but must be enabled by adding `allowOldPasswords=true` to the DSN since it is insecure
190
+  - Added a `clientFoundRows` parameter: Return the number of matching rows instead of the number of rows changed on UPDATEs
191
+  - Added TLS/SSL support: Use a TLS/SSL encrypted connection to the server. Custom TLS configs can be registered and used
192
+
193
+Bugfixes:
194
+
195
+  - Fixed MySQL 4.1 support: MySQL 4.1 sends packets with lengths which differ from the specification
196
+  - Convert to DB timezone when inserting `time.Time`
197
+  - Splitted packets (more than 16MB) are now merged correctly
198
+  - Fixed false positive `io.EOF` errors when the data was fully read
199
+  - Avoid panics on reuse of closed connections
200
+  - Fixed empty string producing false nil values
201
+  - Fixed sign byte for positive TIME fields
202
+
203
+
204
+## Version 1.0 (2013-05-14)
205
+
206
+Initial Release

+ 373
- 0
vendor/github.com/go-sql-driver/mysql/LICENSE View File

@@ -0,0 +1,373 @@
1
+Mozilla Public License Version 2.0
2
+==================================
3
+
4
+1. Definitions
5
+--------------
6
+
7
+1.1. "Contributor"
8
+    means each individual or legal entity that creates, contributes to
9
+    the creation of, or owns Covered Software.
10
+
11
+1.2. "Contributor Version"
12
+    means the combination of the Contributions of others (if any) used
13
+    by a Contributor and that particular Contributor's Contribution.
14
+
15
+1.3. "Contribution"
16
+    means Covered Software of a particular Contributor.
17
+
18
+1.4. "Covered Software"
19
+    means Source Code Form to which the initial Contributor has attached
20
+    the notice in Exhibit A, the Executable Form of such Source Code
21
+    Form, and Modifications of such Source Code Form, in each case
22
+    including portions thereof.
23
+
24
+1.5. "Incompatible With Secondary Licenses"
25
+    means
26
+
27
+    (a) that the initial Contributor has attached the notice described
28
+        in Exhibit B to the Covered Software; or
29
+
30
+    (b) that the Covered Software was made available under the terms of
31
+        version 1.1 or earlier of the License, but not also under the
32
+        terms of a Secondary License.
33
+
34
+1.6. "Executable Form"
35
+    means any form of the work other than Source Code Form.
36
+
37
+1.7. "Larger Work"
38
+    means a work that combines Covered Software with other material, in 
39
+    a separate file or files, that is not Covered Software.
40
+
41
+1.8. "License"
42
+    means this document.
43
+
44
+1.9. "Licensable"
45
+    means having the right to grant, to the maximum extent possible,
46
+    whether at the time of the initial grant or subsequently, any and
47
+    all of the rights conveyed by this License.
48
+
49
+1.10. "Modifications"
50
+    means any of the following:
51
+
52
+    (a) any file in Source Code Form that results from an addition to,
53
+        deletion from, or modification of the contents of Covered
54
+        Software; or
55
+
56
+    (b) any new file in Source Code Form that contains any Covered
57
+        Software.
58
+
59
+1.11. "Patent Claims" of a Contributor
60
+    means any patent claim(s), including without limitation, method,
61
+    process, and apparatus claims, in any patent Licensable by such
62
+    Contributor that would be infringed, but for the grant of the
63
+    License, by the making, using, selling, offering for sale, having
64
+    made, import, or transfer of either its Contributions or its
65
+    Contributor Version.
66
+
67
+1.12. "Secondary License"
68
+    means either the GNU General Public License, Version 2.0, the GNU
69
+    Lesser General Public License, Version 2.1, the GNU Affero General
70
+    Public License, Version 3.0, or any later versions of those
71
+    licenses.
72
+
73
+1.13. "Source Code Form"
74
+    means the form of the work preferred for making modifications.
75
+
76
+1.14. "You" (or "Your")
77
+    means an individual or a legal entity exercising rights under this
78
+    License. For legal entities, "You" includes any entity that
79
+    controls, is controlled by, or is under common control with You. For
80
+    purposes of this definition, "control" means (a) the power, direct
81
+    or indirect, to cause the direction or management of such entity,
82
+    whether by contract or otherwise, or (b) ownership of more than
83
+    fifty percent (50%) of the outstanding shares or beneficial
84
+    ownership of such entity.
85
+
86
+2. License Grants and Conditions
87
+--------------------------------
88
+
89
+2.1. Grants
90
+
91
+Each Contributor hereby grants You a world-wide, royalty-free,
92
+non-exclusive license:
93
+
94
+(a) under intellectual property rights (other than patent or trademark)
95
+    Licensable by such Contributor to use, reproduce, make available,
96
+    modify, display, perform, distribute, and otherwise exploit its
97
+    Contributions, either on an unmodified basis, with Modifications, or
98
+    as part of a Larger Work; and
99
+
100
+(b) under Patent Claims of such Contributor to make, use, sell, offer
101
+    for sale, have made, import, and otherwise transfer either its
102
+    Contributions or its Contributor Version.
103
+
104
+2.2. Effective Date
105
+
106
+The licenses granted in Section 2.1 with respect to any Contribution
107
+become effective for each Contribution on the date the Contributor first
108
+distributes such Contribution.
109
+
110
+2.3. Limitations on Grant Scope
111
+
112
+The licenses granted in this Section 2 are the only rights granted under
113
+this License. No additional rights or licenses will be implied from the
114
+distribution or licensing of Covered Software under this License.
115
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
116
+Contributor:
117
+
118
+(a) for any code that a Contributor has removed from Covered Software;
119
+    or
120
+
121
+(b) for infringements caused by: (i) Your and any other third party's
122
+    modifications of Covered Software, or (ii) the combination of its
123
+    Contributions with other software (except as part of its Contributor
124
+    Version); or
125
+
126
+(c) under Patent Claims infringed by Covered Software in the absence of
127
+    its Contributions.
128
+
129
+This License does not grant any rights in the trademarks, service marks,
130
+or logos of any Contributor (except as may be necessary to comply with
131
+the notice requirements in Section 3.4).
132
+
133
+2.4. Subsequent Licenses
134
+
135
+No Contributor makes additional grants as a result of Your choice to
136
+distribute the Covered Software under a subsequent version of this
137
+License (see Section 10.2) or under the terms of a Secondary License (if
138
+permitted under the terms of Section 3.3).
139
+
140
+2.5. Representation
141
+
142
+Each Contributor represents that the Contributor believes its
143
+Contributions are its original creation(s) or it has sufficient rights
144
+to grant the rights to its Contributions conveyed by this License.
145
+
146
+2.6. Fair Use
147
+
148
+This License is not intended to limit any rights You have under
149
+applicable copyright doctrines of fair use, fair dealing, or other
150
+equivalents.
151
+
152
+2.7. Conditions
153
+
154
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
+in Section 2.1.
156
+
157
+3. Responsibilities
158
+-------------------
159
+
160
+3.1. Distribution of Source Form
161
+
162
+All distribution of Covered Software in Source Code Form, including any
163
+Modifications that You create or to which You contribute, must be under
164
+the terms of this License. You must inform recipients that the Source
165
+Code Form of the Covered Software is governed by the terms of this
166
+License, and how they can obtain a copy of this License. You may not
167
+attempt to alter or restrict the recipients' rights in the Source Code
168
+Form.
169
+
170
+3.2. Distribution of Executable Form
171
+
172
+If You distribute Covered Software in Executable Form then:
173
+
174
+(a) such Covered Software must also be made available in Source Code
175
+    Form, as described in Section 3.1, and You must inform recipients of
176
+    the Executable Form how they can obtain a copy of such Source Code
177
+    Form by reasonable means in a timely manner, at a charge no more
178
+    than the cost of distribution to the recipient; and
179
+
180
+(b) You may distribute such Executable Form under the terms of this
181
+    License, or sublicense it under different terms, provided that the
182
+    license for the Executable Form does not attempt to limit or alter
183
+    the recipients' rights in the Source Code Form under this License.
184
+
185
+3.3. Distribution of a Larger Work
186
+
187
+You may create and distribute a Larger Work under terms of Your choice,
188
+provided that You also comply with the requirements of this License for
189
+the Covered Software. If the Larger Work is a combination of Covered
190
+Software with a work governed by one or more Secondary Licenses, and the
191
+Covered Software is not Incompatible With Secondary Licenses, this
192
+License permits You to additionally distribute such Covered Software
193
+under the terms of such Secondary License(s), so that the recipient of
194
+the Larger Work may, at their option, further distribute the Covered
195
+Software under the terms of either this License or such Secondary
196
+License(s).
197
+
198
+3.4. Notices
199
+
200
+You may not remove or alter the substance of any license notices
201
+(including copyright notices, patent notices, disclaimers of warranty,
202
+or limitations of liability) contained within the Source Code Form of
203
+the Covered Software, except that You may alter any license notices to
204
+the extent required to remedy known factual inaccuracies.
205
+
206
+3.5. Application of Additional Terms
207
+
208
+You may choose to offer, and to charge a fee for, warranty, support,
209
+indemnity or liability obligations to one or more recipients of Covered
210
+Software. However, You may do so only on Your own behalf, and not on
211
+behalf of any Contributor. You must make it absolutely clear that any
212
+such warranty, support, indemnity, or liability obligation is offered by
213
+You alone, and You hereby agree to indemnify every Contributor for any
214
+liability incurred by such Contributor as a result of warranty, support,
215
+indemnity or liability terms You offer. You may include additional
216
+disclaimers of warranty and limitations of liability specific to any
217
+jurisdiction.
218
+
219
+4. Inability to Comply Due to Statute or Regulation
220
+---------------------------------------------------
221
+
222
+If it is impossible for You to comply with any of the terms of this
223
+License with respect to some or all of the Covered Software due to
224
+statute, judicial order, or regulation then You must: (a) comply with
225
+the terms of this License to the maximum extent possible; and (b)
226
+describe the limitations and the code they affect. Such description must
227
+be placed in a text file included with all distributions of the Covered
228
+Software under this License. Except to the extent prohibited by statute
229
+or regulation, such description must be sufficiently detailed for a
230
+recipient of ordinary skill to be able to understand it.
231
+
232
+5. Termination
233
+--------------
234
+
235
+5.1. The rights granted under this License will terminate automatically
236
+if You fail to comply with any of its terms. However, if You become
237
+compliant, then the rights granted under this License from a particular
238
+Contributor are reinstated (a) provisionally, unless and until such
239
+Contributor explicitly and finally terminates Your grants, and (b) on an
240
+ongoing basis, if such Contributor fails to notify You of the
241
+non-compliance by some reasonable means prior to 60 days after You have
242
+come back into compliance. Moreover, Your grants from a particular
243
+Contributor are reinstated on an ongoing basis if such Contributor
244
+notifies You of the non-compliance by some reasonable means, this is the
245
+first time You have received notice of non-compliance with this License
246
+from such Contributor, and You become compliant prior to 30 days after
247
+Your receipt of the notice.
248
+
249
+5.2. If You initiate litigation against any entity by asserting a patent
250
+infringement claim (excluding declaratory judgment actions,
251
+counter-claims, and cross-claims) alleging that a Contributor Version
252
+directly or indirectly infringes any patent, then the rights granted to
253
+You by any and all Contributors for the Covered Software under Section
254
+2.1 of this License shall terminate.
255
+
256
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257
+end user license agreements (excluding distributors and resellers) which
258
+have been validly granted by You or Your distributors under this License
259
+prior to termination shall survive termination.
260
+
261
+************************************************************************
262
+*                                                                      *
263
+*  6. Disclaimer of Warranty                                           *
264
+*  -------------------------                                           *
265
+*                                                                      *
266
+*  Covered Software is provided under this License on an "as is"       *
267
+*  basis, without warranty of any kind, either expressed, implied, or  *
268
+*  statutory, including, without limitation, warranties that the       *
269
+*  Covered Software is free of defects, merchantable, fit for a        *
270
+*  particular purpose or non-infringing. The entire risk as to the     *
271
+*  quality and performance of the Covered Software is with You.        *
272
+*  Should any Covered Software prove defective in any respect, You     *
273
+*  (not any Contributor) assume the cost of any necessary servicing,   *
274
+*  repair, or correction. This disclaimer of warranty constitutes an   *
275
+*  essential part of this License. No use of any Covered Software is   *
276
+*  authorized under this License except under this disclaimer.         *
277
+*                                                                      *
278
+************************************************************************
279
+
280
+************************************************************************
281
+*                                                                      *
282
+*  7. Limitation of Liability                                          *
283
+*  --------------------------                                          *
284
+*                                                                      *
285
+*  Under no circumstances and under no legal theory, whether tort      *
286
+*  (including negligence), contract, or otherwise, shall any           *
287
+*  Contributor, or anyone who distributes Covered Software as          *
288
+*  permitted above, be liable to You for any direct, indirect,         *
289
+*  special, incidental, or consequential damages of any character      *
290
+*  including, without limitation, damages for lost profits, loss of    *
291
+*  goodwill, work stoppage, computer failure or malfunction, or any    *
292
+*  and all other commercial damages or losses, even if such party      *
293
+*  shall have been informed of the possibility of such damages. This   *
294
+*  limitation of liability shall not apply to liability for death or   *
295
+*  personal injury resulting from such party's negligence to the       *
296
+*  extent applicable law prohibits such limitation. Some               *
297
+*  jurisdictions do not allow the exclusion or limitation of           *
298
+*  incidental or consequential damages, so this exclusion and          *
299
+*  limitation may not apply to You.                                    *
300
+*                                                                      *
301
+************************************************************************
302
+
303
+8. Litigation
304
+-------------
305
+
306
+Any litigation relating to this License may be brought only in the
307
+courts of a jurisdiction where the defendant maintains its principal
308
+place of business and such litigation shall be governed by laws of that
309
+jurisdiction, without reference to its conflict-of-law provisions.
310
+Nothing in this Section shall prevent a party's ability to bring
311
+cross-claims or counter-claims.
312
+
313
+9. Miscellaneous
314
+----------------
315
+
316
+This License represents the complete agreement concerning the subject
317
+matter hereof. If any provision of this License is held to be
318
+unenforceable, such provision shall be reformed only to the extent
319
+necessary to make it enforceable. Any law or regulation which provides
320
+that the language of a contract shall be construed against the drafter
321
+shall not be used to construe this License against a Contributor.
322
+
323
+10. Versions of the License
324
+---------------------------
325
+
326
+10.1. New Versions
327
+
328
+Mozilla Foundation is the license steward. Except as provided in Section
329
+10.3, no one other than the license steward has the right to modify or
330
+publish new versions of this License. Each version will be given a
331
+distinguishing version number.
332
+
333
+10.2. Effect of New Versions
334
+
335
+You may distribute the Covered Software under the terms of the version
336
+of the License under which You originally received the Covered Software,
337
+or under the terms of any subsequent version published by the license
338
+steward.
339
+
340
+10.3. Modified Versions
341
+
342
+If you create software not governed by this License, and you want to
343
+create a new license for such software, you may create and use a
344
+modified version of this License if you rename the license and remove
345
+any references to the name of the license steward (except to note that
346
+such modified license differs from this License).
347
+
348
+10.4. Distributing Source Code Form that is Incompatible With Secondary
349
+Licenses
350
+
351
+If You choose to distribute Source Code Form that is Incompatible With
352
+Secondary Licenses under the terms of this version of the License, the
353
+notice described in Exhibit B of this License must be attached.
354
+
355
+Exhibit A - Source Code Form License Notice
356
+-------------------------------------------
357
+
358
+  This Source Code Form is subject to the terms of the Mozilla Public
359
+  License, v. 2.0. If a copy of the MPL was not distributed with this
360
+  file, You can obtain one at http://mozilla.org/MPL/2.0/.
361
+
362
+If it is not possible or desirable to put the notice in a particular
363
+file, then You may include the notice in a location (such as a LICENSE
364
+file in a relevant directory) where a recipient would be likely to look
365
+for such a notice.
366
+
367
+You may add additional accurate notices of copyright ownership.
368
+
369
+Exhibit B - "Incompatible With Secondary Licenses" Notice
370
+---------------------------------------------------------
371
+
372
+  This Source Code Form is "Incompatible With Secondary Licenses", as
373
+  defined by the Mozilla Public License, v. 2.0.

+ 501
- 0
vendor/github.com/go-sql-driver/mysql/README.md View File

@@ -0,0 +1,501 @@
1
+# Go-MySQL-Driver
2
+
3
+A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) package
4
+
5
+![Go-MySQL-Driver logo](https://raw.github.com/wiki/go-sql-driver/mysql/gomysql_m.png "Golang Gopher holding the MySQL Dolphin")
6
+
7
+---------------------------------------
8
+  * [Features](#features)
9
+  * [Requirements](#requirements)
10
+  * [Installation](#installation)
11
+  * [Usage](#usage)
12
+    * [DSN (Data Source Name)](#dsn-data-source-name)
13
+      * [Password](#password)
14
+      * [Protocol](#protocol)
15
+      * [Address](#address)
16
+      * [Parameters](#parameters)
17
+      * [Examples](#examples)
18
+    * [Connection pool and timeouts](#connection-pool-and-timeouts)
19
+    * [context.Context Support](#contextcontext-support)
20
+    * [ColumnType Support](#columntype-support)
21
+    * [LOAD DATA LOCAL INFILE support](#load-data-local-infile-support)
22
+    * [time.Time support](#timetime-support)
23
+    * [Unicode support](#unicode-support)
24
+  * [Testing / Development](#testing--development)
25
+  * [License](#license)
26
+
27
+---------------------------------------
28
+
29
+## Features
30
+  * Lightweight and [fast](https://github.com/go-sql-driver/sql-benchmark "golang MySQL-Driver performance")
31
+  * Native Go implementation. No C-bindings, just pure Go
32
+  * Connections over TCP/IPv4, TCP/IPv6, Unix domain sockets or [custom protocols](https://godoc.org/github.com/go-sql-driver/mysql#DialFunc)
33
+  * Automatic handling of broken connections
34
+  * Automatic Connection Pooling *(by database/sql package)*
35
+  * Supports queries larger than 16MB
36
+  * Full [`sql.RawBytes`](https://golang.org/pkg/database/sql/#RawBytes) support.
37
+  * Intelligent `LONG DATA` handling in prepared statements
38
+  * Secure `LOAD DATA LOCAL INFILE` support with file Whitelisting and `io.Reader` support
39
+  * Optional `time.Time` parsing
40
+  * Optional placeholder interpolation
41
+
42
+## Requirements
43
+  * Go 1.10 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+)
45
+
46
+---------------------------------------
47
+
48
+## Installation
49
+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:
50
+```bash
51
+$ go get -u github.com/go-sql-driver/mysql
52
+```
53
+Make sure [Git is installed](https://git-scm.com/downloads) on your machine and in your system's `PATH`.
54
+
55
+## Usage
56
+_Go MySQL Driver_ is an implementation of Go's `database/sql/driver` interface. You only need to import the driver and can use the full [`database/sql`](https://golang.org/pkg/database/sql/) API then.
57
+
58
+Use `mysql` as `driverName` and a valid [DSN](#dsn-data-source-name)  as `dataSourceName`:
59
+```go
60
+import "database/sql"
61
+import _ "github.com/go-sql-driver/mysql"
62
+
63
+db, err := sql.Open("mysql", "user:password@/dbname")
64
+```
65
+
66
+[Examples are available in our Wiki](https://github.com/go-sql-driver/mysql/wiki/Examples "Go-MySQL-Driver Examples").
67
+
68
+
69
+### DSN (Data Source Name)
70
+
71
+The Data Source Name has a common format, like e.g. [PEAR DB](http://pear.php.net/manual/en/package.database.db.intro-dsn.php) uses it, but without type-prefix (optional parts marked by squared brackets):
72
+```
73
+[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]
74
+```
75
+
76
+A DSN in its fullest form:
77
+```
78
+username:password@protocol(address)/dbname?param=value
79
+```
80
+
81
+Except for the databasename, all values are optional. So the minimal DSN is:
82
+```
83
+/dbname
84
+```
85
+
86
+If you do not want to preselect a database, leave `dbname` empty:
87
+```
88
+/
89
+```
90
+This has the same effect as an empty DSN string:
91
+```
92
+
93
+```
94
+
95
+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.
96
+
97
+#### Password
98
+Passwords can consist of any character. Escaping is **not** necessary.
99
+
100
+#### Protocol
101
+See [net.Dial](https://golang.org/pkg/net/#Dial) for more information which networks are available.
102
+In general you should use an Unix domain socket if available and TCP otherwise for best performance.
103
+
104
+#### Address
105
+For TCP and UDP networks, addresses have the form `host[:port]`.
106
+If `port` is omitted, the default port will be used.
107
+If `host` is a literal IPv6 address, it must be enclosed in square brackets.
108
+The functions [net.JoinHostPort](https://golang.org/pkg/net/#JoinHostPort) and [net.SplitHostPort](https://golang.org/pkg/net/#SplitHostPort) manipulate addresses in this form.
109
+
110
+For Unix domain sockets the address is the absolute path to the MySQL-Server-socket, e.g. `/var/run/mysqld/mysqld.sock` or `/tmp/mysql.sock`.
111
+
112
+#### Parameters
113
+*Parameters are case-sensitive!*
114
+
115
+Notice that any of `true`, `TRUE`, `True` or `1` is accepted to stand for a true boolean value. Not surprisingly, false can be specified as any of: `false`, `FALSE`, `False` or `0`.
116
+
117
+##### `allowAllFiles`
118
+
119
+```
120
+Type:           bool
121
+Valid Values:   true, false
122
+Default:        false
123
+```
124
+
125
+`allowAllFiles=true` disables the file Whitelist for `LOAD DATA LOCAL INFILE` and allows *all* files.
126
+[*Might be insecure!*](http://dev.mysql.com/doc/refman/5.7/en/load-data-local.html)
127
+
128
+##### `allowCleartextPasswords`
129
+
130
+```
131
+Type:           bool
132
+Valid Values:   true, false
133
+Default:        false
134
+```
135
+
136
+`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.
137
+
138
+##### `allowNativePasswords`
139
+
140
+```
141
+Type:           bool
142
+Valid Values:   true, false
143
+Default:        true
144
+```
145
+`allowNativePasswords=false` disallows the usage of MySQL native password method.
146
+
147
+##### `allowOldPasswords`
148
+
149
+```
150
+Type:           bool
151
+Valid Values:   true, false
152
+Default:        false
153
+```
154
+`allowOldPasswords=true` allows the usage of the insecure old password method. This should be avoided, but is necessary in some cases. See also [the old_passwords wiki page](https://github.com/go-sql-driver/mysql/wiki/old_passwords).
155
+
156
+##### `charset`
157
+
158
+```
159
+Type:           string
160
+Valid Values:   <name>
161
+Default:        none
162
+```
163
+
164
+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`).
165
+
166
+Usage of the `charset` parameter is discouraged because it issues additional queries to the server.
167
+Unless you need the fallback behavior, please use `collation` instead.
168
+
169
+##### `checkConnLiveness`
170
+
171
+```
172
+Type:           bool
173
+Valid Values:   true, false
174
+Default:        true
175
+```
176
+
177
+On supported platforms connections retrieved from the connection pool are checked for liveness before using them. If the check fails, the respective connection is marked as bad and the query retried with another connection.
178
+`checkConnLiveness=false` disables this liveness check of connections.
179
+
180
+##### `collation`
181
+
182
+```
183
+Type:           string
184
+Valid Values:   <name>
185
+Default:        utf8mb4_general_ci
186
+```
187
+
188
+Sets the collation used for client-server interaction on connection. In contrast to `charset`, `collation` does not issue additional queries. If the specified collation is unavailable on the target server, the connection will fail.
189
+
190
+A list of valid charsets for a server is retrievable with `SHOW COLLATION`.
191
+
192
+The default collation (`utf8mb4_general_ci`) is supported from MySQL 5.5.  You should use an older collation (e.g. `utf8_general_ci`) for older MySQL.
193
+
194
+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)).
195
+
196
+
197
+##### `clientFoundRows`
198
+
199
+```
200
+Type:           bool
201
+Valid Values:   true, false
202
+Default:        false
203
+```
204
+
205
+`clientFoundRows=true` causes an UPDATE to return the number of matching rows instead of the number of rows changed.
206
+
207
+##### `columnsWithAlias`
208
+
209
+```
210
+Type:           bool
211
+Valid Values:   true, false
212
+Default:        false
213
+```
214
+
215
+When `columnsWithAlias` is true, calls to `sql.Rows.Columns()` will return the table alias and the column name separated by a dot. For example:
216
+
217
+```
218
+SELECT u.id FROM users as u
219
+```
220
+
221
+will return `u.id` instead of just `id` if `columnsWithAlias=true`.
222
+
223
+##### `interpolateParams`
224
+
225
+```
226
+Type:           bool
227
+Valid Values:   true, false
228
+Default:        false
229
+```
230
+
231
+If `interpolateParams` is true, placeholders (`?`) in calls to `db.Query()` and `db.Exec()` are interpolated into a single query string with given parameters. This reduces the number of roundtrips, since the driver has to prepare a statement, execute it with given parameters and close the statement again with `interpolateParams=false`.
232
+
233
+*This can not be used together with the multibyte encodings BIG5, CP932, GB2312, GBK or SJIS. These are blacklisted as they may [introduce a SQL injection vulnerability](http://stackoverflow.com/a/12118602/3430118)!*
234
+
235
+##### `loc`
236
+
237
+```
238
+Type:           string
239
+Valid Values:   <escaped name>
240
+Default:        UTC
241
+```
242
+
243
+Sets the location for time.Time values (when using `parseTime=true`). *"Local"* sets the system's location. See [time.LoadLocation](https://golang.org/pkg/time/#LoadLocation) for details.
244
+
245
+Note that this sets the location for time.Time values but does not change MySQL's [time_zone setting](https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html). For that see the [time_zone system variable](#system-variables), which can also be set as a DSN parameter.
246
+
247
+Please keep in mind, that param values must be [url.QueryEscape](https://golang.org/pkg/net/url/#QueryEscape)'ed. Alternatively you can manually replace the `/` with `%2F`. For example `US/Pacific` would be `loc=US%2FPacific`.
248
+
249
+##### `maxAllowedPacket`
250
+```
251
+Type:          decimal number
252
+Default:       4194304
253
+```
254
+
255
+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*.
256
+
257
+##### `multiStatements`
258
+
259
+```
260
+Type:           bool
261
+Valid Values:   true, false
262
+Default:        false
263
+```
264
+
265
+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.
266
+
267
+When `multiStatements` is used, `?` parameters must only be used in the first statement.
268
+
269
+##### `parseTime`
270
+
271
+```
272
+Type:           bool
273
+Valid Values:   true, false
274
+Default:        false
275
+```
276
+
277
+`parseTime=true` changes the output type of `DATE` and `DATETIME` values to `time.Time` instead of `[]byte` / `string`
278
+The date or datetime like `0000-00-00 00:00:00` is converted into zero value of `time.Time`.
279
+
280
+
281
+##### `readTimeout`
282
+
283
+```
284
+Type:           duration
285
+Default:        0
286
+```
287
+
288
+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"*.
289
+
290
+##### `rejectReadOnly`
291
+
292
+```
293
+Type:           bool
294
+Valid Values:   true, false
295
+Default:        false
296
+```
297
+
298
+
299
+`rejectReadOnly=true` causes the driver to reject read-only connections. This
300
+is for a possible race condition during an automatic failover, where the mysql
301
+client gets connected to a read-only replica after the failover.
302
+
303
+Note that this should be a fairly rare case, as an automatic failover normally
304
+happens when the primary is down, and the race condition shouldn't happen
305
+unless it comes back up online as soon as the failover is kicked off. On the
306
+other hand, when this happens, a MySQL application can get stuck on a
307
+read-only connection until restarted. It is however fairly easy to reproduce,
308
+for example, using a manual failover on AWS Aurora's MySQL-compatible cluster.
309
+
310
+If you are not relying on read-only transactions to reject writes that aren't
311
+supposed to happen, setting this on some MySQL providers (such as AWS Aurora)
312
+is safer for failovers.
313
+
314
+Note that ERROR 1290 can be returned for a `read-only` server and this option will
315
+cause a retry for that error. However the same error number is used for some
316
+other cases. You should ensure your application will never cause an ERROR 1290
317
+except for `read-only` mode when enabling this option.
318
+
319
+
320
+##### `serverPubKey`
321
+
322
+```
323
+Type:           string
324
+Valid Values:   <name>
325
+Default:        none
326
+```
327
+
328
+Server public keys can be registered with [`mysql.RegisterServerPubKey`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterServerPubKey), which can then be used by the assigned name in the DSN.
329
+Public keys are used to transmit encrypted data, e.g. for authentication.
330
+If the server's public key is known, it should be set manually to avoid expensive and potentially insecure transmissions of the public key from the server to the client each time it is required.
331
+
332
+
333
+##### `timeout`
334
+
335
+```
336
+Type:           duration
337
+Default:        OS default
338
+```
339
+
340
+Timeout for establishing connections, aka dial timeout. The value must be a decimal number with a unit suffix (*"ms"*, *"s"*, *"m"*, *"h"*), such as *"30s"*, *"0.5m"* or *"1m30s"*.
341
+
342
+
343
+##### `tls`
344
+
345
+```
346
+Type:           bool / string
347
+Valid Values:   true, false, skip-verify, preferred, <name>
348
+Default:        false
349
+```
350
+
351
+`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) or use `preferred` to use TLS only when advertised by the server. This is similar to `skip-verify`, but additionally allows a fallback to a connection which is not encrypted. Neither `skip-verify` nor `preferred` add any reliable security. You can use a custom TLS config after registering it with [`mysql.RegisterTLSConfig`](https://godoc.org/github.com/go-sql-driver/mysql#RegisterTLSConfig).
352
+
353
+
354
+##### `writeTimeout`
355
+
356
+```
357
+Type:           duration
358
+Default:        0
359
+```
360
+
361
+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"*.
362
+
363
+
364
+##### System Variables
365
+
366
+Any other parameters are interpreted as system variables:
367
+  * `<boolean_var>=<value>`: `SET <boolean_var>=<value>`
368
+  * `<enum_var>=<value>`: `SET <enum_var>=<value>`
369
+  * `<string_var>=%27<value>%27`: `SET <string_var>='<value>'`
370
+
371
+Rules:
372
+* The values for string variables must be quoted with `'`.
373
+* The values must also be [url.QueryEscape](http://golang.org/pkg/net/url/#QueryEscape)'ed!
374
+ (which implies values of string variables must be wrapped with `%27`).
375
+
376
+Examples:
377
+  * `autocommit=1`: `SET autocommit=1`
378
+  * [`time_zone=%27Europe%2FParis%27`](https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html): `SET time_zone='Europe/Paris'`
379
+  * [`tx_isolation=%27REPEATABLE-READ%27`](https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_tx_isolation): `SET tx_isolation='REPEATABLE-READ'`
380
+
381
+
382
+#### Examples
383
+```
384
+user@unix(/path/to/socket)/dbname
385
+```
386
+
387
+```
388
+root:pw@unix(/tmp/mysql.sock)/myDatabase?loc=Local
389
+```
390
+
391
+```
392
+user:password@tcp(localhost:5555)/dbname?tls=skip-verify&autocommit=true
393
+```
394
+
395
+Treat warnings as errors by setting the system variable [`sql_mode`](https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html):
396
+```
397
+user:password@/dbname?sql_mode=TRADITIONAL
398
+```
399
+
400
+TCP via IPv6:
401
+```
402
+user:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?timeout=90s&collation=utf8mb4_unicode_ci
403
+```
404
+
405
+TCP on a remote host, e.g. Amazon RDS:
406
+```
407
+id:password@tcp(your-amazonaws-uri.com:3306)/dbname
408
+```
409
+
410
+Google Cloud SQL on App Engine:
411
+```
412
+user:password@unix(/cloudsql/project-id:region-name:instance-name)/dbname
413
+```
414
+
415
+TCP using default port (3306) on localhost:
416
+```
417
+user:password@tcp/dbname?charset=utf8mb4,utf8&sys_var=esc%40ped
418
+```
419
+
420
+Use the default protocol (tcp) and host (localhost:3306):
421
+```
422
+user:password@/dbname
423
+```
424
+
425
+No Database preselected:
426
+```
427
+user:password@/
428
+```
429
+
430
+
431
+### Connection pool and timeouts
432
+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.
433
+
434
+## `ColumnType` Support
435
+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.
436
+
437
+## `context.Context` Support
438
+Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.
439
+See [context support in the database/sql package](https://golang.org/doc/go1.8#database_sql) for more details.
440
+
441
+
442
+### `LOAD DATA LOCAL INFILE` support
443
+For this feature you need direct access to the package. Therefore you must change the import path (no `_`):
444
+```go
445
+import "github.com/go-sql-driver/mysql"
446
+```
447
+
448
+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)).
449
+
450
+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.
451
+
452
+See the [godoc of Go-MySQL-Driver](https://godoc.org/github.com/go-sql-driver/mysql "golang mysql driver documentation") for details.
453
+
454
+
455
+### `time.Time` support
456
+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.
457
+
458
+However, many want to scan MySQL `DATE` and `DATETIME` values into `time.Time` variables, which is the logical equivalent 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.
459
+
460
+**Caution:** As of Go 1.1, this makes `time.Time` the only variable type you can scan `DATE` and `DATETIME` values into. This breaks for example [`sql.RawBytes` support](https://github.com/go-sql-driver/mysql/wiki/Examples#rawbytes).
461
+
462
+Alternatively you can use the [`NullTime`](https://godoc.org/github.com/go-sql-driver/mysql#NullTime) type as the scan destination, which works with both `time.Time` and `string` / `[]byte`.
463
+
464
+
465
+### Unicode support
466
+Since version 1.5 Go-MySQL-Driver automatically uses the collation ` utf8mb4_general_ci` by default.
467
+
468
+Other collations / charsets can be set using the [`collation`](#collation) DSN parameter.
469
+
470
+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.
471
+
472
+See http://dev.mysql.com/doc/refman/8.0/en/charset-unicode.html for more details on MySQL's Unicode support.
473
+
474
+## Testing / Development
475
+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.
476
+
477
+Go-MySQL-Driver is not feature-complete yet. Your help is very appreciated.
478
+If you want to contribute, you can work on an [open issue](https://github.com/go-sql-driver/mysql/issues?state=open) or review a [pull request](https://github.com/go-sql-driver/mysql/pulls).
479
+
480
+See the [Contribution Guidelines](https://github.com/go-sql-driver/mysql/blob/master/CONTRIBUTING.md) for details.
481
+
482
+---------------------------------------
483
+
484
+## License
485
+Go-MySQL-Driver is licensed under the [Mozilla Public License Version 2.0](https://raw.github.com/go-sql-driver/mysql/master/LICENSE)
486
+
487
+Mozilla summarizes the license scope as follows:
488
+> MPL: The copyleft applies to any files containing MPLed code.
489
+
490
+
491
+That means:
492
+  * You can **use** the **unchanged** source code both in private and commercially.
493
+  * 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).
494
+  * You **needn't publish** the source code of your library as long as the files licensed under the MPL 2.0 are **unchanged**.
495
+
496
+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.
497
+
498
+You can read the full terms here: [LICENSE](https://raw.github.com/go-sql-driver/mysql/master/LICENSE).
499
+
500
+![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")
501
+

+ 422
- 0
vendor/github.com/go-sql-driver/mysql/auth.go View File

@@ -0,0 +1,422 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2018 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
+package mysql
10
+
11
+import (
12
+	"crypto/rand"
13
+	"crypto/rsa"
14
+	"crypto/sha1"
15
+	"crypto/sha256"
16
+	"crypto/x509"
17
+	"encoding/pem"
18
+	"sync"
19
+)
20
+
21
+// server pub keys registry
22
+var (
23
+	serverPubKeyLock     sync.RWMutex
24
+	serverPubKeyRegistry map[string]*rsa.PublicKey
25
+)
26
+
27
+// RegisterServerPubKey registers a server RSA public key which can be used to
28
+// send data in a secure manner to the server without receiving the public key
29
+// in a potentially insecure way from the server first.
30
+// Registered keys can afterwards be used adding serverPubKey=<name> to the DSN.
31
+//
32
+// Note: The provided rsa.PublicKey instance is exclusively owned by the driver
33
+// after registering it and may not be modified.
34
+//
35
+//  data, err := ioutil.ReadFile("mykey.pem")
36
+//  if err != nil {
37
+//  	log.Fatal(err)
38
+//  }
39
+//
40
+//  block, _ := pem.Decode(data)
41
+//  if block == nil || block.Type != "PUBLIC KEY" {
42
+//  	log.Fatal("failed to decode PEM block containing public key")
43
+//  }
44
+//
45
+//  pub, err := x509.ParsePKIXPublicKey(block.Bytes)
46
+//  if err != nil {
47
+//  	log.Fatal(err)
48
+//  }
49
+//
50
+//  if rsaPubKey, ok := pub.(*rsa.PublicKey); ok {
51
+//  	mysql.RegisterServerPubKey("mykey", rsaPubKey)
52
+//  } else {
53
+//  	log.Fatal("not a RSA public key")
54
+//  }
55
+//
56
+func RegisterServerPubKey(name string, pubKey *rsa.PublicKey) {
57
+	serverPubKeyLock.Lock()
58
+	if serverPubKeyRegistry == nil {
59
+		serverPubKeyRegistry = make(map[string]*rsa.PublicKey)
60
+	}
61
+
62
+	serverPubKeyRegistry[name] = pubKey
63
+	serverPubKeyLock.Unlock()
64
+}
65
+
66
+// DeregisterServerPubKey removes the public key registered with the given name.
67
+func DeregisterServerPubKey(name string) {
68
+	serverPubKeyLock.Lock()
69
+	if serverPubKeyRegistry != nil {
70
+		delete(serverPubKeyRegistry, name)
71
+	}
72
+	serverPubKeyLock.Unlock()
73
+}
74
+
75
+func getServerPubKey(name string) (pubKey *rsa.PublicKey) {
76
+	serverPubKeyLock.RLock()
77
+	if v, ok := serverPubKeyRegistry[name]; ok {
78
+		pubKey = v
79
+	}
80
+	serverPubKeyLock.RUnlock()
81
+	return
82
+}
83
+
84
+// Hash password using pre 4.1 (old password) method
85
+// https://github.com/atcurtis/mariadb/blob/master/mysys/my_rnd.c
86
+type myRnd struct {
87
+	seed1, seed2 uint32
88
+}
89
+
90
+const myRndMaxVal = 0x3FFFFFFF
91
+
92
+// Pseudo random number generator
93
+func newMyRnd(seed1, seed2 uint32) *myRnd {
94
+	return &myRnd{
95
+		seed1: seed1 % myRndMaxVal,
96
+		seed2: seed2 % myRndMaxVal,
97
+	}
98
+}
99
+
100
+// Tested to be equivalent to MariaDB's floating point variant
101
+// http://play.golang.org/p/QHvhd4qved
102
+// http://play.golang.org/p/RG0q4ElWDx
103
+func (r *myRnd) NextByte() byte {
104
+	r.seed1 = (r.seed1*3 + r.seed2) % myRndMaxVal
105
+	r.seed2 = (r.seed1 + r.seed2 + 33) % myRndMaxVal
106
+
107
+	return byte(uint64(r.seed1) * 31 / myRndMaxVal)
108
+}
109
+
110
+// Generate binary hash from byte string using insecure pre 4.1 method
111
+func pwHash(password []byte) (result [2]uint32) {
112
+	var add uint32 = 7
113
+	var tmp uint32
114
+
115
+	result[0] = 1345345333
116
+	result[1] = 0x12345671
117
+
118
+	for _, c := range password {
119
+		// skip spaces and tabs in password
120
+		if c == ' ' || c == '\t' {
121
+			continue
122
+		}
123
+
124
+		tmp = uint32(c)
125
+		result[0] ^= (((result[0] & 63) + add) * tmp) + (result[0] << 8)
126
+		result[1] += (result[1] << 8) ^ result[0]
127
+		add += tmp
128
+	}
129
+
130
+	// Remove sign bit (1<<31)-1)
131
+	result[0] &= 0x7FFFFFFF
132
+	result[1] &= 0x7FFFFFFF
133
+
134
+	return
135
+}
136
+
137
+// Hash password using insecure pre 4.1 method
138
+func scrambleOldPassword(scramble []byte, password string) []byte {
139
+	if len(password) == 0 {
140
+		return nil
141
+	}
142
+
143
+	scramble = scramble[:8]
144
+
145
+	hashPw := pwHash([]byte(password))
146
+	hashSc := pwHash(scramble)
147
+
148
+	r := newMyRnd(hashPw[0]^hashSc[0], hashPw[1]^hashSc[1])
149
+
150
+	var out [8]byte
151
+	for i := range out {
152
+		out[i] = r.NextByte() + 64
153
+	}
154
+
155
+	mask := r.NextByte()
156
+	for i := range out {
157
+		out[i] ^= mask
158
+	}
159
+
160
+	return out[:]
161
+}
162
+
163
+// Hash password using 4.1+ method (SHA1)
164
+func scramblePassword(scramble []byte, password string) []byte {
165
+	if len(password) == 0 {
166
+		return nil
167
+	}
168
+
169
+	// stage1Hash = SHA1(password)
170
+	crypt := sha1.New()
171
+	crypt.Write([]byte(password))
172
+	stage1 := crypt.Sum(nil)
173
+
174
+	// scrambleHash = SHA1(scramble + SHA1(stage1Hash))
175
+	// inner Hash
176
+	crypt.Reset()
177
+	crypt.Write(stage1)
178
+	hash := crypt.Sum(nil)
179
+
180
+	// outer Hash
181
+	crypt.Reset()
182
+	crypt.Write(scramble)
183
+	crypt.Write(hash)
184
+	scramble = crypt.Sum(nil)
185
+
186
+	// token = scrambleHash XOR stage1Hash
187
+	for i := range scramble {
188
+		scramble[i] ^= stage1[i]
189
+	}
190
+	return scramble
191
+}
192
+
193
+// Hash password using MySQL 8+ method (SHA256)
194
+func scrambleSHA256Password(scramble []byte, password string) []byte {
195
+	if len(password) == 0 {
196
+		return nil
197
+	}
198
+
199
+	// XOR(SHA256(password), SHA256(SHA256(SHA256(password)), scramble))
200
+
201
+	crypt := sha256.New()
202
+	crypt.Write([]byte(password))
203
+	message1 := crypt.Sum(nil)
204
+
205
+	crypt.Reset()
206
+	crypt.Write(message1)
207
+	message1Hash := crypt.Sum(nil)
208
+
209
+	crypt.Reset()
210
+	crypt.Write(message1Hash)
211
+	crypt.Write(scramble)
212
+	message2 := crypt.Sum(nil)
213
+
214
+	for i := range message1 {
215
+		message1[i] ^= message2[i]
216
+	}
217
+
218
+	return message1
219
+}
220
+
221
+func encryptPassword(password string, seed []byte, pub *rsa.PublicKey) ([]byte, error) {
222
+	plain := make([]byte, len(password)+1)
223
+	copy(plain, password)
224
+	for i := range plain {
225
+		j := i % len(seed)
226
+		plain[i] ^= seed[j]
227
+	}
228
+	sha1 := sha1.New()
229
+	return rsa.EncryptOAEP(sha1, rand.Reader, pub, plain, nil)
230
+}
231
+
232
+func (mc *mysqlConn) sendEncryptedPassword(seed []byte, pub *rsa.PublicKey) error {
233
+	enc, err := encryptPassword(mc.cfg.Passwd, seed, pub)
234
+	if err != nil {
235
+		return err
236
+	}
237
+	return mc.writeAuthSwitchPacket(enc)
238
+}
239
+
240
+func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
241
+	switch plugin {
242
+	case "caching_sha2_password":
243
+		authResp := scrambleSHA256Password(authData, mc.cfg.Passwd)
244
+		return authResp, nil
245
+
246
+	case "mysql_old_password":
247
+		if !mc.cfg.AllowOldPasswords {
248
+			return nil, ErrOldPassword
249
+		}
250
+		// Note: there are edge cases where this should work but doesn't;
251
+		// this is currently "wontfix":
252
+		// https://github.com/go-sql-driver/mysql/issues/184
253
+		authResp := append(scrambleOldPassword(authData[:8], mc.cfg.Passwd), 0)
254
+		return authResp, nil
255
+
256
+	case "mysql_clear_password":
257
+		if !mc.cfg.AllowCleartextPasswords {
258
+			return nil, ErrCleartextPassword
259
+		}
260
+		// http://dev.mysql.com/doc/refman/5.7/en/cleartext-authentication-plugin.html
261
+		// http://dev.mysql.com/doc/refman/5.7/en/pam-authentication-plugin.html
262
+		return append([]byte(mc.cfg.Passwd), 0), nil
263
+
264
+	case "mysql_native_password":
265
+		if !mc.cfg.AllowNativePasswords {
266
+			return nil, ErrNativePassword
267
+		}
268
+		// https://dev.mysql.com/doc/internals/en/secure-password-authentication.html
269
+		// Native password authentication only need and will need 20-byte challenge.
270
+		authResp := scramblePassword(authData[:20], mc.cfg.Passwd)
271
+		return authResp, nil
272
+
273
+	case "sha256_password":
274
+		if len(mc.cfg.Passwd) == 0 {
275
+			return []byte{0}, nil
276
+		}
277
+		if mc.cfg.tls != nil || mc.cfg.Net == "unix" {
278
+			// write cleartext auth packet
279
+			return append([]byte(mc.cfg.Passwd), 0), nil
280
+		}
281
+
282
+		pubKey := mc.cfg.pubKey
283
+		if pubKey == nil {
284
+			// request public key from server
285
+			return []byte{1}, nil
286
+		}
287
+
288
+		// encrypted password
289
+		enc, err := encryptPassword(mc.cfg.Passwd, authData, pubKey)
290
+		return enc, err
291
+
292
+	default:
293
+		errLog.Print("unknown auth plugin:", plugin)
294
+		return nil, ErrUnknownPlugin
295
+	}
296
+}
297
+
298
+func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
299
+	// Read Result Packet
300
+	authData, newPlugin, err := mc.readAuthResult()
301
+	if err != nil {
302
+		return err
303
+	}
304
+
305
+	// handle auth plugin switch, if requested
306
+	if newPlugin != "" {
307
+		// If CLIENT_PLUGIN_AUTH capability is not supported, no new cipher is
308
+		// sent and we have to keep using the cipher sent in the init packet.
309
+		if authData == nil {
310
+			authData = oldAuthData
311
+		} else {
312
+			// copy data from read buffer to owned slice
313
+			copy(oldAuthData, authData)
314
+		}
315
+
316
+		plugin = newPlugin
317
+
318
+		authResp, err := mc.auth(authData, plugin)
319
+		if err != nil {
320
+			return err
321
+		}
322
+		if err = mc.writeAuthSwitchPacket(authResp); err != nil {
323
+			return err
324
+		}
325
+
326
+		// Read Result Packet
327
+		authData, newPlugin, err = mc.readAuthResult()
328
+		if err != nil {
329
+			return err
330
+		}
331
+
332
+		// Do not allow to change the auth plugin more than once
333
+		if newPlugin != "" {
334
+			return ErrMalformPkt
335
+		}
336
+	}
337
+
338
+	switch plugin {
339
+
340
+	// https://insidemysql.com/preparing-your-community-connector-for-mysql-8-part-2-sha256/
341
+	case "caching_sha2_password":
342
+		switch len(authData) {
343
+		case 0:
344
+			return nil // auth successful
345
+		case 1:
346
+			switch authData[0] {
347
+			case cachingSha2PasswordFastAuthSuccess:
348
+				if err = mc.readResultOK(); err == nil {
349
+					return nil // auth successful
350
+				}
351
+
352
+			case cachingSha2PasswordPerformFullAuthentication:
353
+				if mc.cfg.tls != nil || mc.cfg.Net == "unix" {
354
+					// write cleartext auth packet
355
+					err = mc.writeAuthSwitchPacket(append([]byte(mc.cfg.Passwd), 0))
356
+					if err != nil {
357
+						return err
358
+					}
359
+				} else {
360
+					pubKey := mc.cfg.pubKey
361
+					if pubKey == nil {
362
+						// request public key from server
363
+						data, err := mc.buf.takeSmallBuffer(4 + 1)
364
+						if err != nil {
365
+							return err
366
+						}
367
+						data[4] = cachingSha2PasswordRequestPublicKey
368
+						mc.writePacket(data)
369
+
370
+						// parse public key
371
+						if data, err = mc.readPacket(); err != nil {
372
+							return err
373
+						}
374
+
375
+						block, _ := pem.Decode(data[1:])
376
+						pkix, err := x509.ParsePKIXPublicKey(block.Bytes)
377
+						if err != nil {
378
+							return err
379
+						}
380
+						pubKey = pkix.(*rsa.PublicKey)
381
+					}
382
+
383
+					// send encrypted password
384
+					err = mc.sendEncryptedPassword(oldAuthData, pubKey)
385
+					if err != nil {
386
+						return err
387
+					}
388
+				}
389
+				return mc.readResultOK()
390
+
391
+			default:
392
+				return ErrMalformPkt
393
+			}
394
+		default:
395
+			return ErrMalformPkt
396
+		}
397
+
398
+	case "sha256_password":
399
+		switch len(authData) {
400
+		case 0:
401
+			return nil // auth successful
402
+		default:
403
+			block, _ := pem.Decode(authData)
404
+			pub, err := x509.ParsePKIXPublicKey(block.Bytes)
405
+			if err != nil {
406
+				return err
407
+			}
408
+
409
+			// send encrypted password
410
+			err = mc.sendEncryptedPassword(oldAuthData, pub.(*rsa.PublicKey))
411
+			if err != nil {
412
+				return err
413
+			}
414
+			return mc.readResultOK()
415
+		}
416
+
417
+	default:
418
+		return nil // auth successful
419
+	}
420
+
421
+	return err
422
+}

+ 182
- 0
vendor/github.com/go-sql-driver/mysql/buffer.go View File

@@ -0,0 +1,182 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2013 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
+package mysql
10
+
11
+import (
12
+	"io"
13
+	"net"
14
+	"time"
15
+)
16
+
17
+const defaultBufSize = 4096
18
+const maxCachedBufSize = 256 * 1024
19
+
20
+// A buffer which is used for both reading and writing.
21
+// This is possible since communication on each connection is synchronous.
22
+// In other words, we can't write and read simultaneously on the same connection.
23
+// The buffer is similar to bufio.Reader / Writer but zero-copy-ish
24
+// Also highly optimized for this particular use case.
25
+// This buffer is backed by two byte slices in a double-buffering scheme
26
+type buffer struct {
27
+	buf     []byte // buf is a byte buffer who's length and capacity are equal.
28
+	nc      net.Conn
29
+	idx     int
30
+	length  int
31
+	timeout time.Duration
32
+	dbuf    [2][]byte // dbuf is an array with the two byte slices that back this buffer
33
+	flipcnt uint      // flipccnt is the current buffer counter for double-buffering
34
+}
35
+
36
+// newBuffer allocates and returns a new buffer.
37
+func newBuffer(nc net.Conn) buffer {
38
+	fg := make([]byte, defaultBufSize)
39
+	return buffer{
40
+		buf:  fg,
41
+		nc:   nc,
42
+		dbuf: [2][]byte{fg, nil},
43
+	}
44
+}
45
+
46
+// flip replaces the active buffer with the background buffer
47
+// this is a delayed flip that simply increases the buffer counter;
48
+// the actual flip will be performed the next time we call `buffer.fill`
49
+func (b *buffer) flip() {
50
+	b.flipcnt += 1
51
+}
52
+
53
+// fill reads into the buffer until at least _need_ bytes are in it
54
+func (b *buffer) fill(need int) error {
55
+	n := b.length
56
+	// fill data into its double-buffering target: if we've called
57
+	// flip on this buffer, we'll be copying to the background buffer,
58
+	// and then filling it with network data; otherwise we'll just move
59
+	// the contents of the current buffer to the front before filling it
60
+	dest := b.dbuf[b.flipcnt&1]
61
+
62
+	// grow buffer if necessary to fit the whole packet.
63
+	if need > len(dest) {
64
+		// Round up to the next multiple of the default size
65
+		dest = make([]byte, ((need/defaultBufSize)+1)*defaultBufSize)
66
+
67
+		// if the allocated buffer is not too large, move it to backing storage
68
+		// to prevent extra allocations on applications that perform large reads
69
+		if len(dest) <= maxCachedBufSize {
70
+			b.dbuf[b.flipcnt&1] = dest
71
+		}
72
+	}
73
+
74
+	// if we're filling the fg buffer, move the existing data to the start of it.
75
+	// if we're filling the bg buffer, copy over the data
76
+	if n > 0 {
77
+		copy(dest[:n], b.buf[b.idx:])
78
+	}
79
+
80
+	b.buf = dest
81
+	b.idx = 0
82
+
83
+	for {
84
+		if b.timeout > 0 {
85
+			if err := b.nc.SetReadDeadline(time.Now().Add(b.timeout)); err != nil {
86
+				return err
87
+			}
88
+		}
89
+
90
+		nn, err := b.nc.Read(b.buf[n:])
91
+		n += nn
92
+
93
+		switch err {
94
+		case nil:
95
+			if n < need {
96
+				continue
97
+			}
98
+			b.length = n
99
+			return nil
100
+
101
+		case io.EOF:
102
+			if n >= need {
103
+				b.length = n
104
+				return nil
105
+			}
106
+			return io.ErrUnexpectedEOF
107
+
108
+		default:
109
+			return err
110
+		}
111
+	}
112
+}
113
+
114
+// returns next N bytes from buffer.
115
+// The returned slice is only guaranteed to be valid until the next read
116
+func (b *buffer) readNext(need int) ([]byte, error) {
117
+	if b.length < need {
118
+		// refill
119
+		if err := b.fill(need); err != nil {
120
+			return nil, err
121
+		}
122
+	}
123
+
124
+	offset := b.idx
125
+	b.idx += need
126
+	b.length -= need
127
+	return b.buf[offset:b.idx], nil
128
+}
129
+
130
+// takeBuffer returns a buffer with the requested size.
131
+// If possible, a slice from the existing buffer is returned.
132
+// Otherwise a bigger buffer is made.
133
+// Only one buffer (total) can be used at a time.
134
+func (b *buffer) takeBuffer(length int) ([]byte, error) {
135
+	if b.length > 0 {
136
+		return nil, ErrBusyBuffer
137
+	}
138
+
139
+	// test (cheap) general case first
140
+	if length <= cap(b.buf) {
141
+		return b.buf[:length], nil
142
+	}
143
+
144
+	if length < maxPacketSize {
145
+		b.buf = make([]byte, length)
146
+		return b.buf, nil
147
+	}
148
+
149
+	// buffer is larger than we want to store.
150
+	return make([]byte, length), nil
151
+}
152
+
153
+// takeSmallBuffer is shortcut which can be used if length is
154
+// known to be smaller than defaultBufSize.
155
+// Only one buffer (total) can be used at a time.
156
+func (b *buffer) takeSmallBuffer(length int) ([]byte, error) {
157
+	if b.length > 0 {
158
+		return nil, ErrBusyBuffer
159
+	}
160
+	return b.buf[:length], nil
161
+}
162
+
163
+// takeCompleteBuffer returns the complete existing buffer.
164
+// This can be used if the necessary buffer size is unknown.
165
+// cap and len of the returned buffer will be equal.
166
+// Only one buffer (total) can be used at a time.
167
+func (b *buffer) takeCompleteBuffer() ([]byte, error) {
168
+	if b.length > 0 {
169
+		return nil, ErrBusyBuffer
170
+	}
171
+	return b.buf, nil
172
+}
173
+
174
+// store stores buf, an updated buffer, if its suitable to do so.
175
+func (b *buffer) store(buf []byte) error {
176
+	if b.length > 0 {
177
+		return ErrBusyBuffer
178
+	} else if cap(buf) <= maxPacketSize && cap(buf) > cap(b.buf) {
179
+		b.buf = buf[:cap(buf)]
180
+	}
181
+	return nil
182
+}

+ 265
- 0
vendor/github.com/go-sql-driver/mysql/collations.go View File

@@ -0,0 +1,265 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2014 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
+package mysql
10
+
11
+const defaultCollation = "utf8mb4_general_ci"
12
+const binaryCollation = "binary"
13
+
14
+// A list of available collations mapped to the internal ID.
15
+// To update this map use the following MySQL query:
16
+//     SELECT COLLATION_NAME, ID FROM information_schema.COLLATIONS WHERE ID<256 ORDER BY ID
17
+//
18
+// Handshake packet have only 1 byte for collation_id.  So we can't use collations with ID > 255.
19
+//
20
+// ucs2, utf16, and utf32 can't be used for connection charset.
21
+// https://dev.mysql.com/doc/refman/5.7/en/charset-connection.html#charset-connection-impermissible-client-charset
22
+// They are commented out to reduce this map.
23
+var collations = map[string]byte{
24
+	"big5_chinese_ci":      1,
25
+	"latin2_czech_cs":      2,
26
+	"dec8_swedish_ci":      3,
27
+	"cp850_general_ci":     4,
28
+	"latin1_german1_ci":    5,
29
+	"hp8_english_ci":       6,
30
+	"koi8r_general_ci":     7,
31
+	"latin1_swedish_ci":    8,
32
+	"latin2_general_ci":    9,
33
+	"swe7_swedish_ci":      10,
34
+	"ascii_general_ci":     11,
35
+	"ujis_japanese_ci":     12,
36
+	"sjis_japanese_ci":     13,
37
+	"cp1251_bulgarian_ci":  14,
38
+	"latin1_danish_ci":     15,
39
+	"hebrew_general_ci":    16,
40
+	"tis620_thai_ci":       18,
41
+	"euckr_korean_ci":      19,
42
+	"latin7_estonian_cs":   20,
43
+	"latin2_hungarian_ci":  21,
44
+	"koi8u_general_ci":     22,
45
+	"cp1251_ukrainian_ci":  23,
46
+	"gb2312_chinese_ci":    24,
47
+	"greek_general_ci":     25,
48
+	"cp1250_general_ci":    26,
49
+	"latin2_croatian_ci":   27,
50
+	"gbk_chinese_ci":       28,
51
+	"cp1257_lithuanian_ci": 29,
52
+	"latin5_turkish_ci":    30,
53
+	"latin1_german2_ci":    31,
54
+	"armscii8_general_ci":  32,
55
+	"utf8_general_ci":      33,
56
+	"cp1250_czech_cs":      34,
57
+	//"ucs2_general_ci":          35,
58
+	"cp866_general_ci":    36,
59
+	"keybcs2_general_ci":  37,
60
+	"macce_general_ci":    38,
61
+	"macroman_general_ci": 39,
62
+	"cp852_general_ci":    40,
63
+	"latin7_general_ci":   41,
64
+	"latin7_general_cs":   42,
65
+	"macce_bin":           43,
66
+	"cp1250_croatian_ci":  44,
67
+	"utf8mb4_general_ci":  45,
68
+	"utf8mb4_bin":         46,
69
+	"latin1_bin":          47,
70
+	"latin1_general_ci":   48,
71
+	"latin1_general_cs":   49,
72
+	"cp1251_bin":          50,
73
+	"cp1251_general_ci":   51,
74
+	"cp1251_general_cs":   52,
75
+	"macroman_bin":        53,
76
+	//"utf16_general_ci":         54,
77
+	//"utf16_bin":                55,
78
+	//"utf16le_general_ci":       56,
79
+	"cp1256_general_ci": 57,
80
+	"cp1257_bin":        58,
81
+	"cp1257_general_ci": 59,
82
+	//"utf32_general_ci":         60,
83
+	//"utf32_bin":                61,
84
+	//"utf16le_bin":              62,
85
+	"binary":          63,
86
+	"armscii8_bin":    64,
87
+	"ascii_bin":       65,
88
+	"cp1250_bin":      66,
89
+	"cp1256_bin":      67,
90
+	"cp866_bin":       68,
91
+	"dec8_bin":        69,
92
+	"greek_bin":       70,
93
+	"hebrew_bin":      71,
94
+	"hp8_bin":         72,
95
+	"keybcs2_bin":     73,
96
+	"koi8r_bin":       74,
97
+	"koi8u_bin":       75,
98
+	"utf8_tolower_ci": 76,
99
+	"latin2_bin":      77,
100
+	"latin5_bin":      78,
101
+	"latin7_bin":      79,
102
+	"cp850_bin":       80,
103
+	"cp852_bin":       81,
104
+	"swe7_bin":        82,
105
+	"utf8_bin":        83,
106
+	"big5_bin":        84,
107
+	"euckr_bin":       85,
108
+	"gb2312_bin":      86,
109
+	"gbk_bin":         87,
110
+	"sjis_bin":        88,
111
+	"tis620_bin":      89,
112
+	//"ucs2_bin":                 90,
113
+	"ujis_bin":            91,
114
+	"geostd8_general_ci":  92,
115
+	"geostd8_bin":         93,
116
+	"latin1_spanish_ci":   94,
117
+	"cp932_japanese_ci":   95,
118
+	"cp932_bin":           96,
119
+	"eucjpms_japanese_ci": 97,
120
+	"eucjpms_bin":         98,
121
+	"cp1250_polish_ci":    99,
122
+	//"utf16_unicode_ci":         101,
123
+	//"utf16_icelandic_ci":       102,
124
+	//"utf16_latvian_ci":         103,
125
+	//"utf16_romanian_ci":        104,
126
+	//"utf16_slovenian_ci":       105,
127
+	//"utf16_polish_ci":          106,
128
+	//"utf16_estonian_ci":        107,
129
+	//"utf16_spanish_ci":         108,
130
+	//"utf16_swedish_ci":         109,
131
+	//"utf16_turkish_ci":         110,
132
+	//"utf16_czech_ci":           111,
133
+	//"utf16_danish_ci":          112,
134
+	//"utf16_lithuanian_ci":      113,
135
+	//"utf16_slovak_ci":          114,
136
+	//"utf16_spanish2_ci":        115,
137
+	//"utf16_roman_ci":           116,
138
+	//"utf16_persian_ci":         117,
139
+	//"utf16_esperanto_ci":       118,
140
+	//"utf16_hungarian_ci":       119,
141
+	//"utf16_sinhala_ci":         120,
142
+	//"utf16_german2_ci":         121,
143
+	//"utf16_croatian_ci":        122,
144
+	//"utf16_unicode_520_ci":     123,
145
+	//"utf16_vietnamese_ci":      124,
146
+	//"ucs2_unicode_ci":          128,
147
+	//"ucs2_icelandic_ci":        129,
148
+	//"ucs2_latvian_ci":          130,
149
+	//"ucs2_romanian_ci":         131,
150
+	//"ucs2_slovenian_ci":        132,
151
+	//"ucs2_polish_ci":           133,
152
+	//"ucs2_estonian_ci":         134,
153
+	//"ucs2_spanish_ci":          135,
154
+	//"ucs2_swedish_ci":          136,
155
+	//"ucs2_turkish_ci":          137,
156
+	//"ucs2_czech_ci":            138,
157
+	//"ucs2_danish_ci":           139,
158
+	//"ucs2_lithuanian_ci":       140,
159
+	//"ucs2_slovak_ci":           141,
160
+	//"ucs2_spanish2_ci":         142,
161
+	//"ucs2_roman_ci":            143,
162
+	//"ucs2_persian_ci":          144,
163
+	//"ucs2_esperanto_ci":        145,
164
+	//"ucs2_hungarian_ci":        146,
165
+	//"ucs2_sinhala_ci":          147,
166
+	//"ucs2_german2_ci":          148,
167
+	//"ucs2_croatian_ci":         149,
168
+	//"ucs2_unicode_520_ci":      150,
169
+	//"ucs2_vietnamese_ci":       151,
170
+	//"ucs2_general_mysql500_ci": 159,
171
+	//"utf32_unicode_ci":         160,
172
+	//"utf32_icelandic_ci":       161,
173
+	//"utf32_latvian_ci":         162,
174
+	//"utf32_romanian_ci":        163,
175
+	//"utf32_slovenian_ci":       164,
176
+	//"utf32_polish_ci":          165,
177
+	//"utf32_estonian_ci":        166,
178
+	//"utf32_spanish_ci":         167,
179
+	//"utf32_swedish_ci":         168,
180
+	//"utf32_turkish_ci":         169,
181
+	//"utf32_czech_ci":           170,
182
+	//"utf32_danish_ci":          171,
183
+	//"utf32_lithuanian_ci":      172,
184
+	//"utf32_slovak_ci":          173,
185
+	//"utf32_spanish2_ci":        174,
186
+	//"utf32_roman_ci":           175,
187
+	//"utf32_persian_ci":         176,
188
+	//"utf32_esperanto_ci":       177,
189
+	//"utf32_hungarian_ci":       178,
190
+	//"utf32_sinhala_ci":         179,
191
+	//"utf32_german2_ci":         180,
192
+	//"utf32_croatian_ci":        181,
193
+	//"utf32_unicode_520_ci":     182,
194
+	//"utf32_vietnamese_ci":      183,
195
+	"utf8_unicode_ci":          192,
196
+	"utf8_icelandic_ci":        193,
197
+	"utf8_latvian_ci":          194,
198
+	"utf8_romanian_ci":         195,
199
+	"utf8_slovenian_ci":        196,
200
+	"utf8_polish_ci":           197,
201
+	"utf8_estonian_ci":         198,
202
+	"utf8_spanish_ci":          199,
203
+	"utf8_swedish_ci":          200,
204
+	"utf8_turkish_ci":          201,
205
+	"utf8_czech_ci":            202,
206
+	"utf8_danish_ci":           203,
207
+	"utf8_lithuanian_ci":       204,
208
+	"utf8_slovak_ci":           205,
209
+	"utf8_spanish2_ci":         206,
210
+	"utf8_roman_ci":            207,
211
+	"utf8_persian_ci":          208,
212
+	"utf8_esperanto_ci":        209,
213
+	"utf8_hungarian_ci":        210,
214
+	"utf8_sinhala_ci":          211,
215
+	"utf8_german2_ci":          212,
216
+	"utf8_croatian_ci":         213,
217
+	"utf8_unicode_520_ci":      214,
218
+	"utf8_vietnamese_ci":       215,
219
+	"utf8_general_mysql500_ci": 223,
220
+	"utf8mb4_unicode_ci":       224,
221
+	"utf8mb4_icelandic_ci":     225,
222
+	"utf8mb4_latvian_ci":       226,
223
+	"utf8mb4_romanian_ci":      227,
224
+	"utf8mb4_slovenian_ci":     228,
225
+	"utf8mb4_polish_ci":        229,
226
+	"utf8mb4_estonian_ci":      230,
227
+	"utf8mb4_spanish_ci":       231,
228
+	"utf8mb4_swedish_ci":       232,
229
+	"utf8mb4_turkish_ci":       233,
230
+	"utf8mb4_czech_ci":         234,
231
+	"utf8mb4_danish_ci":        235,
232
+	"utf8mb4_lithuanian_ci":    236,
233
+	"utf8mb4_slovak_ci":        237,
234
+	"utf8mb4_spanish2_ci":      238,
235
+	"utf8mb4_roman_ci":         239,
236
+	"utf8mb4_persian_ci":       240,
237
+	"utf8mb4_esperanto_ci":     241,
238
+	"utf8mb4_hungarian_ci":     242,
239
+	"utf8mb4_sinhala_ci":       243,
240
+	"utf8mb4_german2_ci":       244,
241
+	"utf8mb4_croatian_ci":      245,
242
+	"utf8mb4_unicode_520_ci":   246,
243
+	"utf8mb4_vietnamese_ci":    247,
244
+	"gb18030_chinese_ci":       248,
245
+	"gb18030_bin":              249,
246
+	"gb18030_unicode_520_ci":   250,
247
+	"utf8mb4_0900_ai_ci":       255,
248
+}
249
+
250
+// A blacklist of collations which is unsafe to interpolate parameters.
251
+// These multibyte encodings may contains 0x5c (`\`) in their trailing bytes.
252
+var unsafeCollations = map[string]bool{
253
+	"big5_chinese_ci":        true,
254
+	"sjis_japanese_ci":       true,
255
+	"gbk_chinese_ci":         true,
256
+	"big5_bin":               true,
257
+	"gb2312_bin":             true,
258
+	"gbk_bin":                true,
259
+	"sjis_bin":               true,
260
+	"cp932_japanese_ci":      true,
261
+	"cp932_bin":              true,
262
+	"gb18030_chinese_ci":     true,
263
+	"gb18030_bin":            true,
264
+	"gb18030_unicode_520_ci": true,
265
+}

+ 54
- 0
vendor/github.com/go-sql-driver/mysql/conncheck.go View File

@@ -0,0 +1,54 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2019 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 linux darwin dragonfly freebsd netbsd openbsd solaris illumos
10
+
11
+package mysql
12
+
13
+import (
14
+	"errors"
15
+	"io"
16
+	"net"
17
+	"syscall"
18
+)
19
+
20
+var errUnexpectedRead = errors.New("unexpected read from socket")
21
+
22
+func connCheck(conn net.Conn) error {
23
+	var sysErr error
24
+
25
+	sysConn, ok := conn.(syscall.Conn)
26
+	if !ok {
27
+		return nil
28
+	}
29
+	rawConn, err := sysConn.SyscallConn()
30
+	if err != nil {
31
+		return err
32
+	}
33
+
34
+	err = rawConn.Read(func(fd uintptr) bool {
35
+		var buf [1]byte
36
+		n, err := syscall.Read(int(fd), buf[:])
37
+		switch {
38
+		case n == 0 && err == nil:
39
+			sysErr = io.EOF
40
+		case n > 0:
41
+			sysErr = errUnexpectedRead
42
+		case err == syscall.EAGAIN || err == syscall.EWOULDBLOCK:
43
+			sysErr = nil
44
+		default:
45
+			sysErr = err
46
+		}
47
+		return true
48
+	})
49
+	if err != nil {
50
+		return err
51
+	}
52
+
53
+	return sysErr
54
+}

+ 17
- 0
vendor/github.com/go-sql-driver/mysql/conncheck_dummy.go View File

@@ -0,0 +1,17 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2019 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 !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!illumos
10
+
11
+package mysql
12
+
13
+import "net"
14
+
15
+func connCheck(conn net.Conn) error {
16
+	return nil
17
+}

+ 651
- 0
vendor/github.com/go-sql-driver/mysql/connection.go View File

@@ -0,0 +1,651 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2012 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
+package mysql
10
+
11
+import (
12
+	"context"
13
+	"database/sql"
14
+	"database/sql/driver"
15
+	"io"
16
+	"net"
17
+	"strconv"
18
+	"strings"
19
+	"time"
20
+)
21
+
22
+type mysqlConn struct {
23
+	buf              buffer
24
+	netConn          net.Conn
25
+	rawConn          net.Conn // underlying connection when netConn is TLS connection.
26
+	affectedRows     uint64
27
+	insertId         uint64
28
+	cfg              *Config
29
+	maxAllowedPacket int
30
+	maxWriteSize     int
31
+	writeTimeout     time.Duration
32
+	flags            clientFlag
33
+	status           statusFlag
34
+	sequence         uint8
35
+	parseTime        bool
36
+	reset            bool // set when the Go SQL package calls ResetSession
37
+
38
+	// for context support (Go 1.8+)
39
+	watching bool
40
+	watcher  chan<- context.Context
41
+	closech  chan struct{}
42
+	finished chan<- struct{}
43
+	canceled atomicError // set non-nil if conn is canceled
44
+	closed   atomicBool  // set when conn is closed, before closech is closed
45
+}
46
+
47
+// Handles parameters set in DSN after the connection is established
48
+func (mc *mysqlConn) handleParams() (err error) {
49
+	for param, val := range mc.cfg.Params {
50
+		switch param {
51
+		// Charset
52
+		case "charset":
53
+			charsets := strings.Split(val, ",")
54
+			for i := range charsets {
55
+				// ignore errors here - a charset may not exist
56
+				err = mc.exec("SET NAMES " + charsets[i])
57
+				if err == nil {
58
+					break
59
+				}
60
+			}
61
+			if err != nil {
62
+				return
63
+			}
64
+
65
+		// System Vars
66
+		default:
67
+			err = mc.exec("SET " + param + "=" + val + "")
68
+			if err != nil {
69
+				return
70
+			}
71
+		}
72
+	}
73
+
74
+	return
75
+}
76
+
77
+func (mc *mysqlConn) markBadConn(err error) error {
78
+	if mc == nil {
79
+		return err
80
+	}
81
+	if err != errBadConnNoWrite {
82
+		return err
83
+	}
84
+	return driver.ErrBadConn
85
+}
86
+
87
+func (mc *mysqlConn) Begin() (driver.Tx, error) {
88
+	return mc.begin(false)
89
+}
90
+
91
+func (mc *mysqlConn) begin(readOnly bool) (driver.Tx, error) {
92
+	if mc.closed.IsSet() {
93
+		errLog.Print(ErrInvalidConn)
94
+		return nil, driver.ErrBadConn
95
+	}
96
+	var q string
97
+	if readOnly {
98
+		q = "START TRANSACTION READ ONLY"
99
+	} else {
100
+		q = "START TRANSACTION"
101
+	}
102
+	err := mc.exec(q)
103
+	if err == nil {
104
+		return &mysqlTx{mc}, err
105
+	}
106
+	return nil, mc.markBadConn(err)
107
+}
108
+
109
+func (mc *mysqlConn) Close() (err error) {
110
+	// Makes Close idempotent
111
+	if !mc.closed.IsSet() {
112
+		err = mc.writeCommandPacket(comQuit)
113
+	}
114
+
115
+	mc.cleanup()
116
+
117
+	return
118
+}
119
+
120
+// Closes the network connection and unsets internal variables. Do not call this
121
+// function after successfully authentication, call Close instead. This function
122
+// is called before auth or on auth failure because MySQL will have already
123
+// closed the network connection.
124
+func (mc *mysqlConn) cleanup() {
125
+	if !mc.closed.TrySet(true) {
126
+		return
127
+	}
128
+
129
+	// Makes cleanup idempotent
130
+	close(mc.closech)
131
+	if mc.netConn == nil {
132
+		return
133
+	}
134
+	if err := mc.netConn.Close(); err != nil {
135
+		errLog.Print(err)
136
+	}
137
+}
138
+
139
+func (mc *mysqlConn) error() error {
140
+	if mc.closed.IsSet() {
141
+		if err := mc.canceled.Value(); err != nil {
142
+			return err
143
+		}
144
+		return ErrInvalidConn
145
+	}
146
+	return nil
147
+}
148
+
149
+func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) {
150
+	if mc.closed.IsSet() {
151
+		errLog.Print(ErrInvalidConn)
152
+		return nil, driver.ErrBadConn
153
+	}
154
+	// Send command
155
+	err := mc.writeCommandPacketStr(comStmtPrepare, query)
156
+	if err != nil {
157
+		// STMT_PREPARE is safe to retry.  So we can return ErrBadConn here.
158
+		errLog.Print(err)
159
+		return nil, driver.ErrBadConn
160
+	}
161
+
162
+	stmt := &mysqlStmt{
163
+		mc: mc,
164
+	}
165
+
166
+	// Read Result
167
+	columnCount, err := stmt.readPrepareResultPacket()
168
+	if err == nil {
169
+		if stmt.paramCount > 0 {
170
+			if err = mc.readUntilEOF(); err != nil {
171
+				return nil, err
172
+			}
173
+		}
174
+
175
+		if columnCount > 0 {
176
+			err = mc.readUntilEOF()
177
+		}
178
+	}
179
+
180
+	return stmt, err
181
+}
182
+
183
+func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (string, error) {
184
+	// Number of ? should be same to len(args)
185
+	if strings.Count(query, "?") != len(args) {
186
+		return "", driver.ErrSkip
187
+	}
188
+
189
+	buf, err := mc.buf.takeCompleteBuffer()
190
+	if err != nil {
191
+		// can not take the buffer. Something must be wrong with the connection
192
+		errLog.Print(err)
193
+		return "", ErrInvalidConn
194
+	}
195
+	buf = buf[:0]
196
+	argPos := 0
197
+
198
+	for i := 0; i < len(query); i++ {
199
+		q := strings.IndexByte(query[i:], '?')
200
+		if q == -1 {
201
+			buf = append(buf, query[i:]...)
202
+			break
203
+		}
204
+		buf = append(buf, query[i:i+q]...)
205
+		i += q
206
+
207
+		arg := args[argPos]
208
+		argPos++
209
+
210
+		if arg == nil {
211
+			buf = append(buf, "NULL"...)
212
+			continue
213
+		}
214
+
215
+		switch v := arg.(type) {
216
+		case int64:
217
+			buf = strconv.AppendInt(buf, v, 10)
218
+		case uint64:
219
+			// Handle uint64 explicitly because our custom ConvertValue emits unsigned values
220
+			buf = strconv.AppendUint(buf, v, 10)
221
+		case float64:
222
+			buf = strconv.AppendFloat(buf, v, 'g', -1, 64)
223
+		case bool:
224
+			if v {
225
+				buf = append(buf, '1')
226
+			} else {
227
+				buf = append(buf, '0')
228
+			}
229
+		case time.Time:
230
+			if v.IsZero() {
231
+				buf = append(buf, "'0000-00-00'"...)
232
+			} else {
233
+				v := v.In(mc.cfg.Loc)
234
+				v = v.Add(time.Nanosecond * 500) // To round under microsecond
235
+				year := v.Year()
236
+				year100 := year / 100
237
+				year1 := year % 100
238
+				month := v.Month()
239
+				day := v.Day()
240
+				hour := v.Hour()
241
+				minute := v.Minute()
242
+				second := v.Second()
243
+				micro := v.Nanosecond() / 1000
244
+
245
+				buf = append(buf, []byte{
246
+					'\'',
247
+					digits10[year100], digits01[year100],
248
+					digits10[year1], digits01[year1],
249
+					'-',
250
+					digits10[month], digits01[month],
251
+					'-',
252
+					digits10[day], digits01[day],
253
+					' ',
254
+					digits10[hour], digits01[hour],
255
+					':',
256
+					digits10[minute], digits01[minute],
257
+					':',
258
+					digits10[second], digits01[second],
259
+				}...)
260
+
261
+				if micro != 0 {
262
+					micro10000 := micro / 10000
263
+					micro100 := micro / 100 % 100
264
+					micro1 := micro % 100
265
+					buf = append(buf, []byte{
266
+						'.',
267
+						digits10[micro10000], digits01[micro10000],
268
+						digits10[micro100], digits01[micro100],
269
+						digits10[micro1], digits01[micro1],
270
+					}...)
271
+				}
272
+				buf = append(buf, '\'')
273
+			}
274
+		case []byte:
275
+			if v == nil {
276
+				buf = append(buf, "NULL"...)
277
+			} else {
278
+				buf = append(buf, "_binary'"...)
279
+				if mc.status&statusNoBackslashEscapes == 0 {
280
+					buf = escapeBytesBackslash(buf, v)
281
+				} else {
282
+					buf = escapeBytesQuotes(buf, v)
283
+				}
284
+				buf = append(buf, '\'')
285
+			}
286
+		case string:
287
+			buf = append(buf, '\'')
288
+			if mc.status&statusNoBackslashEscapes == 0 {
289
+				buf = escapeStringBackslash(buf, v)
290
+			} else {
291
+				buf = escapeStringQuotes(buf, v)
292
+			}
293
+			buf = append(buf, '\'')
294
+		default:
295
+			return "", driver.ErrSkip
296
+		}
297
+
298
+		if len(buf)+4 > mc.maxAllowedPacket {
299
+			return "", driver.ErrSkip
300
+		}
301
+	}
302
+	if argPos != len(args) {
303
+		return "", driver.ErrSkip
304
+	}
305
+	return string(buf), nil
306
+}
307
+
308
+func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, error) {
309
+	if mc.closed.IsSet() {
310
+		errLog.Print(ErrInvalidConn)
311
+		return nil, driver.ErrBadConn
312
+	}
313
+	if len(args) != 0 {
314
+		if !mc.cfg.InterpolateParams {
315
+			return nil, driver.ErrSkip
316
+		}
317
+		// try to interpolate the parameters to save extra roundtrips for preparing and closing a statement
318
+		prepared, err := mc.interpolateParams(query, args)
319
+		if err != nil {
320
+			return nil, err
321
+		}
322
+		query = prepared
323
+	}
324
+	mc.affectedRows = 0
325
+	mc.insertId = 0
326
+
327
+	err := mc.exec(query)
328
+	if err == nil {
329
+		return &mysqlResult{
330
+			affectedRows: int64(mc.affectedRows),
331
+			insertId:     int64(mc.insertId),
332
+		}, err
333
+	}
334
+	return nil, mc.markBadConn(err)
335
+}
336
+
337
+// Internal function to execute commands
338
+func (mc *mysqlConn) exec(query string) error {
339
+	// Send command
340
+	if err := mc.writeCommandPacketStr(comQuery, query); err != nil {
341
+		return mc.markBadConn(err)
342
+	}
343
+
344
+	// Read Result
345
+	resLen, err := mc.readResultSetHeaderPacket()
346
+	if err != nil {
347
+		return err
348
+	}
349
+
350
+	if resLen > 0 {
351
+		// columns
352
+		if err := mc.readUntilEOF(); err != nil {
353
+			return err
354
+		}
355
+
356
+		// rows
357
+		if err := mc.readUntilEOF(); err != nil {
358
+			return err
359
+		}
360
+	}
361
+
362
+	return mc.discardResults()
363
+}
364
+
365
+func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, error) {
366
+	return mc.query(query, args)
367
+}
368
+
369
+func (mc *mysqlConn) query(query string, args []driver.Value) (*textRows, error) {
370
+	if mc.closed.IsSet() {
371
+		errLog.Print(ErrInvalidConn)
372
+		return nil, driver.ErrBadConn
373
+	}
374
+	if len(args) != 0 {
375
+		if !mc.cfg.InterpolateParams {
376
+			return nil, driver.ErrSkip
377
+		}
378
+		// try client-side prepare to reduce roundtrip
379
+		prepared, err := mc.interpolateParams(query, args)
380
+		if err != nil {
381
+			return nil, err
382
+		}
383
+		query = prepared
384
+	}
385
+	// Send command
386
+	err := mc.writeCommandPacketStr(comQuery, query)
387
+	if err == nil {
388
+		// Read Result
389
+		var resLen int
390
+		resLen, err = mc.readResultSetHeaderPacket()
391
+		if err == nil {
392
+			rows := new(textRows)
393
+			rows.mc = mc
394
+
395
+			if resLen == 0 {
396
+				rows.rs.done = true
397
+
398
+				switch err := rows.NextResultSet(); err {
399
+				case nil, io.EOF:
400
+					return rows, nil
401
+				default:
402
+					return nil, err
403
+				}
404
+			}
405
+
406
+			// Columns
407
+			rows.rs.columns, err = mc.readColumns(resLen)
408
+			return rows, err
409
+		}
410
+	}
411
+	return nil, mc.markBadConn(err)
412
+}
413
+
414
+// Gets the value of the given MySQL System Variable
415
+// The returned byte slice is only valid until the next read
416
+func (mc *mysqlConn) getSystemVar(name string) ([]byte, error) {
417
+	// Send command
418
+	if err := mc.writeCommandPacketStr(comQuery, "SELECT @@"+name); err != nil {
419
+		return nil, err
420
+	}
421
+
422
+	// Read Result
423
+	resLen, err := mc.readResultSetHeaderPacket()
424
+	if err == nil {
425
+		rows := new(textRows)
426
+		rows.mc = mc
427
+		rows.rs.columns = []mysqlField{{fieldType: fieldTypeVarChar}}
428
+
429
+		if resLen > 0 {
430
+			// Columns
431
+			if err := mc.readUntilEOF(); err != nil {
432
+				return nil, err
433
+			}
434
+		}
435
+
436
+		dest := make([]driver.Value, resLen)
437
+		if err = rows.readRow(dest); err == nil {
438
+			return dest[0].([]byte), mc.readUntilEOF()
439
+		}
440
+	}
441
+	return nil, err
442
+}
443
+
444
+// finish is called when the query has canceled.
445
+func (mc *mysqlConn) cancel(err error) {
446
+	mc.canceled.Set(err)
447
+	mc.cleanup()
448
+}
449
+
450
+// finish is called when the query has succeeded.
451
+func (mc *mysqlConn) finish() {
452
+	if !mc.watching || mc.finished == nil {
453
+		return
454
+	}
455
+	select {
456
+	case mc.finished <- struct{}{}:
457
+		mc.watching = false
458
+	case <-mc.closech:
459
+	}
460
+}
461
+
462
+// Ping implements driver.Pinger interface
463
+func (mc *mysqlConn) Ping(ctx context.Context) (err error) {
464
+	if mc.closed.IsSet() {
465
+		errLog.Print(ErrInvalidConn)
466
+		return driver.ErrBadConn
467
+	}
468
+
469
+	if err = mc.watchCancel(ctx); err != nil {
470
+		return
471
+	}
472
+	defer mc.finish()
473
+
474
+	if err = mc.writeCommandPacket(comPing); err != nil {
475
+		return mc.markBadConn(err)
476
+	}
477
+
478
+	return mc.readResultOK()
479
+}
480
+
481
+// BeginTx implements driver.ConnBeginTx interface
482
+func (mc *mysqlConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
483
+	if err := mc.watchCancel(ctx); err != nil {
484
+		return nil, err
485
+	}
486
+	defer mc.finish()
487
+
488
+	if sql.IsolationLevel(opts.Isolation) != sql.LevelDefault {
489
+		level, err := mapIsolationLevel(opts.Isolation)
490
+		if err != nil {
491
+			return nil, err
492
+		}
493
+		err = mc.exec("SET TRANSACTION ISOLATION LEVEL " + level)
494
+		if err != nil {
495
+			return nil, err
496
+		}
497
+	}
498
+
499
+	return mc.begin(opts.ReadOnly)
500
+}
501
+
502
+func (mc *mysqlConn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
503
+	dargs, err := namedValueToValue(args)
504
+	if err != nil {
505
+		return nil, err
506
+	}
507
+
508
+	if err := mc.watchCancel(ctx); err != nil {
509
+		return nil, err
510
+	}
511
+
512
+	rows, err := mc.query(query, dargs)
513
+	if err != nil {
514
+		mc.finish()
515
+		return nil, err
516
+	}
517
+	rows.finish = mc.finish
518
+	return rows, err
519
+}
520
+
521
+func (mc *mysqlConn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
522
+	dargs, err := namedValueToValue(args)
523
+	if err != nil {
524
+		return nil, err
525
+	}
526
+
527
+	if err := mc.watchCancel(ctx); err != nil {
528
+		return nil, err
529
+	}
530
+	defer mc.finish()
531
+
532
+	return mc.Exec(query, dargs)
533
+}
534
+
535
+func (mc *mysqlConn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
536
+	if err := mc.watchCancel(ctx); err != nil {
537
+		return nil, err
538
+	}
539
+
540
+	stmt, err := mc.Prepare(query)
541
+	mc.finish()
542
+	if err != nil {
543
+		return nil, err
544
+	}
545
+
546
+	select {
547
+	default:
548
+	case <-ctx.Done():
549
+		stmt.Close()
550
+		return nil, ctx.Err()
551
+	}
552
+	return stmt, nil
553
+}
554
+
555
+func (stmt *mysqlStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
556
+	dargs, err := namedValueToValue(args)
557
+	if err != nil {
558
+		return nil, err
559
+	}
560
+
561
+	if err := stmt.mc.watchCancel(ctx); err != nil {
562
+		return nil, err
563
+	}
564
+
565
+	rows, err := stmt.query(dargs)
566
+	if err != nil {
567
+		stmt.mc.finish()
568
+		return nil, err
569
+	}
570
+	rows.finish = stmt.mc.finish
571
+	return rows, err
572
+}
573
+
574
+func (stmt *mysqlStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
575
+	dargs, err := namedValueToValue(args)
576
+	if err != nil {
577
+		return nil, err
578
+	}
579
+
580
+	if err := stmt.mc.watchCancel(ctx); err != nil {
581
+		return nil, err
582
+	}
583
+	defer stmt.mc.finish()
584
+
585
+	return stmt.Exec(dargs)
586
+}
587
+
588
+func (mc *mysqlConn) watchCancel(ctx context.Context) error {
589
+	if mc.watching {
590
+		// Reach here if canceled,
591
+		// so the connection is already invalid
592
+		mc.cleanup()
593
+		return nil
594
+	}
595
+	// When ctx is already cancelled, don't watch it.
596
+	if err := ctx.Err(); err != nil {
597
+		return err
598
+	}
599
+	// When ctx is not cancellable, don't watch it.
600
+	if ctx.Done() == nil {
601
+		return nil
602
+	}
603
+	// When watcher is not alive, can't watch it.
604
+	if mc.watcher == nil {
605
+		return nil
606
+	}
607
+
608
+	mc.watching = true
609
+	mc.watcher <- ctx
610
+	return nil
611
+}
612
+
613
+func (mc *mysqlConn) startWatcher() {
614
+	watcher := make(chan context.Context, 1)
615
+	mc.watcher = watcher
616
+	finished := make(chan struct{})
617
+	mc.finished = finished
618
+	go func() {
619
+		for {
620
+			var ctx context.Context
621
+			select {
622
+			case ctx = <-watcher:
623
+			case <-mc.closech:
624
+				return
625
+			}
626
+
627
+			select {
628
+			case <-ctx.Done():
629
+				mc.cancel(ctx.Err())
630
+			case <-finished:
631
+			case <-mc.closech:
632
+				return
633
+			}
634
+		}
635
+	}()
636
+}
637
+
638
+func (mc *mysqlConn) CheckNamedValue(nv *driver.NamedValue) (err error) {
639
+	nv.Value, err = converter{}.ConvertValue(nv.Value)
640
+	return
641
+}
642
+
643
+// ResetSession implements driver.SessionResetter.
644
+// (From Go 1.10)
645
+func (mc *mysqlConn) ResetSession(ctx context.Context) error {
646
+	if mc.closed.IsSet() {
647
+		return driver.ErrBadConn
648
+	}
649
+	mc.reset = true
650
+	return nil
651
+}

+ 146
- 0
vendor/github.com/go-sql-driver/mysql/connector.go View File

@@ -0,0 +1,146 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2018 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
+package mysql
10
+
11
+import (
12
+	"context"
13
+	"database/sql/driver"
14
+	"net"
15
+)
16
+
17
+type connector struct {
18
+	cfg *Config // immutable private copy.
19
+}
20
+
21
+// Connect implements driver.Connector interface.
22
+// Connect returns a connection to the database.
23
+func (c *connector) Connect(ctx context.Context) (driver.Conn, error) {
24
+	var err error
25
+
26
+	// New mysqlConn
27
+	mc := &mysqlConn{
28
+		maxAllowedPacket: maxPacketSize,
29
+		maxWriteSize:     maxPacketSize - 1,
30
+		closech:          make(chan struct{}),
31
+		cfg:              c.cfg,
32
+	}
33
+	mc.parseTime = mc.cfg.ParseTime
34
+
35
+	// Connect to Server
36
+	dialsLock.RLock()
37
+	dial, ok := dials[mc.cfg.Net]
38
+	dialsLock.RUnlock()
39
+	if ok {
40
+		dctx := ctx
41
+		if mc.cfg.Timeout > 0 {
42
+			var cancel context.CancelFunc
43
+			dctx, cancel = context.WithTimeout(ctx, c.cfg.Timeout)
44
+			defer cancel()
45
+		}
46
+		mc.netConn, err = dial(dctx, mc.cfg.Addr)
47
+	} else {
48
+		nd := net.Dialer{Timeout: mc.cfg.Timeout}
49
+		mc.netConn, err = nd.DialContext(ctx, mc.cfg.Net, mc.cfg.Addr)
50
+	}
51
+
52
+	if err != nil {
53
+		return nil, err
54
+	}
55
+
56
+	// Enable TCP Keepalives on TCP connections
57
+	if tc, ok := mc.netConn.(*net.TCPConn); ok {
58
+		if err := tc.SetKeepAlive(true); err != nil {
59
+			// Don't send COM_QUIT before handshake.
60
+			mc.netConn.Close()
61
+			mc.netConn = nil
62
+			return nil, err
63
+		}
64
+	}
65
+
66
+	// Call startWatcher for context support (From Go 1.8)
67
+	mc.startWatcher()
68
+	if err := mc.watchCancel(ctx); err != nil {
69
+		mc.cleanup()
70
+		return nil, err
71
+	}
72
+	defer mc.finish()
73
+
74
+	mc.buf = newBuffer(mc.netConn)
75
+
76
+	// Set I/O timeouts
77
+	mc.buf.timeout = mc.cfg.ReadTimeout
78
+	mc.writeTimeout = mc.cfg.WriteTimeout
79
+
80
+	// Reading Handshake Initialization Packet
81
+	authData, plugin, err := mc.readHandshakePacket()
82
+	if err != nil {
83
+		mc.cleanup()
84
+		return nil, err
85
+	}
86
+
87
+	if plugin == "" {
88
+		plugin = defaultAuthPlugin
89
+	}
90
+
91
+	// Send Client Authentication Packet
92
+	authResp, err := mc.auth(authData, plugin)
93
+	if err != nil {
94
+		// try the default auth plugin, if using the requested plugin failed
95
+		errLog.Print("could not use requested auth plugin '"+plugin+"': ", err.Error())
96
+		plugin = defaultAuthPlugin
97
+		authResp, err = mc.auth(authData, plugin)
98
+		if err != nil {
99
+			mc.cleanup()
100
+			return nil, err
101
+		}
102
+	}
103
+	if err = mc.writeHandshakeResponsePacket(authResp, plugin); err != nil {
104
+		mc.cleanup()
105
+		return nil, err
106
+	}
107
+
108
+	// Handle response to auth packet, switch methods if possible
109
+	if err = mc.handleAuthResult(authData, plugin); err != nil {
110
+		// Authentication failed and MySQL has already closed the connection
111
+		// (https://dev.mysql.com/doc/internals/en/authentication-fails.html).
112
+		// Do not send COM_QUIT, just cleanup and return the error.
113
+		mc.cleanup()
114
+		return nil, err
115
+	}
116
+
117
+	if mc.cfg.MaxAllowedPacket > 0 {
118
+		mc.maxAllowedPacket = mc.cfg.MaxAllowedPacket
119
+	} else {
120
+		// Get max allowed packet size
121
+		maxap, err := mc.getSystemVar("max_allowed_packet")
122
+		if err != nil {
123
+			mc.Close()
124
+			return nil, err
125
+		}
126
+		mc.maxAllowedPacket = stringToInt(maxap) - 1
127
+	}
128
+	if mc.maxAllowedPacket < maxPacketSize {
129
+		mc.maxWriteSize = mc.maxAllowedPacket
130
+	}
131
+
132
+	// Handle DSN Params
133
+	err = mc.handleParams()
134
+	if err != nil {
135
+		mc.Close()
136
+		return nil, err
137
+	}
138
+
139
+	return mc, nil
140
+}
141
+
142
+// Driver implements driver.Connector interface.
143
+// Driver returns &MySQLDriver{}.
144
+func (c *connector) Driver() driver.Driver {
145
+	return &MySQLDriver{}
146
+}

+ 174
- 0
vendor/github.com/go-sql-driver/mysql/const.go View File

@@ -0,0 +1,174 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2012 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
+package mysql
10
+
11
+const (
12
+	defaultAuthPlugin       = "mysql_native_password"
13
+	defaultMaxAllowedPacket = 4 << 20 // 4 MiB
14
+	minProtocolVersion      = 10
15
+	maxPacketSize           = 1<<24 - 1
16
+	timeFormat              = "2006-01-02 15:04:05.999999"
17
+)
18
+
19
+// MySQL constants documentation:
20
+// http://dev.mysql.com/doc/internals/en/client-server-protocol.html
21
+
22
+const (
23
+	iOK           byte = 0x00
24
+	iAuthMoreData byte = 0x01
25
+	iLocalInFile  byte = 0xfb
26
+	iEOF          byte = 0xfe
27
+	iERR          byte = 0xff
28
+)
29
+
30
+// https://dev.mysql.com/doc/internals/en/capability-flags.html#packet-Protocol::CapabilityFlags
31
+type clientFlag uint32
32
+
33
+const (
34
+	clientLongPassword clientFlag = 1 << iota
35
+	clientFoundRows
36
+	clientLongFlag
37
+	clientConnectWithDB
38
+	clientNoSchema
39
+	clientCompress
40
+	clientODBC
41
+	clientLocalFiles
42
+	clientIgnoreSpace
43
+	clientProtocol41
44
+	clientInteractive
45
+	clientSSL
46
+	clientIgnoreSIGPIPE
47
+	clientTransactions
48
+	clientReserved
49
+	clientSecureConn
50
+	clientMultiStatements
51
+	clientMultiResults
52
+	clientPSMultiResults
53
+	clientPluginAuth
54
+	clientConnectAttrs
55
+	clientPluginAuthLenEncClientData
56
+	clientCanHandleExpiredPasswords
57
+	clientSessionTrack
58
+	clientDeprecateEOF
59
+)
60
+
61
+const (
62
+	comQuit byte = iota + 1
63
+	comInitDB
64
+	comQuery
65
+	comFieldList
66
+	comCreateDB
67
+	comDropDB
68
+	comRefresh
69
+	comShutdown
70
+	comStatistics
71
+	comProcessInfo
72
+	comConnect
73
+	comProcessKill
74
+	comDebug
75
+	comPing
76
+	comTime
77
+	comDelayedInsert
78
+	comChangeUser
79
+	comBinlogDump
80
+	comTableDump
81
+	comConnectOut
82
+	comRegisterSlave
83
+	comStmtPrepare
84
+	comStmtExecute
85
+	comStmtSendLongData
86
+	comStmtClose
87
+	comStmtReset
88
+	comSetOption
89
+	comStmtFetch
90
+)
91
+
92
+// https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::ColumnType
93
+type fieldType byte
94
+
95
+const (
96
+	fieldTypeDecimal fieldType = iota
97
+	fieldTypeTiny
98
+	fieldTypeShort
99
+	fieldTypeLong
100
+	fieldTypeFloat
101
+	fieldTypeDouble
102
+	fieldTypeNULL
103
+	fieldTypeTimestamp
104
+	fieldTypeLongLong
105
+	fieldTypeInt24
106
+	fieldTypeDate
107
+	fieldTypeTime
108
+	fieldTypeDateTime
109
+	fieldTypeYear
110
+	fieldTypeNewDate
111
+	fieldTypeVarChar
112
+	fieldTypeBit
113
+)
114
+const (
115
+	fieldTypeJSON fieldType = iota + 0xf5
116
+	fieldTypeNewDecimal
117
+	fieldTypeEnum
118
+	fieldTypeSet
119
+	fieldTypeTinyBLOB
120
+	fieldTypeMediumBLOB
121
+	fieldTypeLongBLOB
122
+	fieldTypeBLOB
123
+	fieldTypeVarString
124
+	fieldTypeString
125
+	fieldTypeGeometry
126
+)
127
+
128
+type fieldFlag uint16
129
+
130
+const (
131
+	flagNotNULL fieldFlag = 1 << iota
132
+	flagPriKey
133
+	flagUniqueKey
134
+	flagMultipleKey
135
+	flagBLOB
136
+	flagUnsigned
137
+	flagZeroFill
138
+	flagBinary
139
+	flagEnum
140
+	flagAutoIncrement
141
+	flagTimestamp
142
+	flagSet
143
+	flagUnknown1
144
+	flagUnknown2
145
+	flagUnknown3
146
+	flagUnknown4
147
+)
148
+
149
+// http://dev.mysql.com/doc/internals/en/status-flags.html
150
+type statusFlag uint16
151
+
152
+const (
153
+	statusInTrans statusFlag = 1 << iota
154
+	statusInAutocommit
155
+	statusReserved // Not in documentation
156
+	statusMoreResultsExists
157
+	statusNoGoodIndexUsed
158
+	statusNoIndexUsed
159
+	statusCursorExists
160
+	statusLastRowSent
161
+	statusDbDropped
162
+	statusNoBackslashEscapes
163
+	statusMetadataChanged
164
+	statusQueryWasSlow
165
+	statusPsOutParams
166
+	statusInTransReadonly
167
+	statusSessionStateChanged
168
+)
169
+
170
+const (
171
+	cachingSha2PasswordRequestPublicKey          = 2
172
+	cachingSha2PasswordFastAuthSuccess           = 3
173
+	cachingSha2PasswordPerformFullAuthentication = 4
174
+)

+ 107
- 0
vendor/github.com/go-sql-driver/mysql/driver.go View File

@@ -0,0 +1,107 @@
1
+// Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
2
+//
3
+// This Source Code Form is subject to the terms of the Mozilla Public
4
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
+// You can obtain one at http://mozilla.org/MPL/2.0/.
6
+
7
+// Package mysql provides a MySQL driver for Go's database/sql package.
8
+//
9
+// The driver should be used via the database/sql package:
10
+//
11
+//  import "database/sql"
12
+//  import _ "github.com/go-sql-driver/mysql"
13
+//
14
+//  db, err := sql.Open("mysql", "user:password@/dbname")
15
+//
16
+// See https://github.com/go-sql-driver/mysql#usage for details
17
+package mysql
18
+
19
+import (
20
+	"context"
21
+	"database/sql"
22
+	"database/sql/driver"
23
+	"net"
24
+	"sync"
25
+)
26
+
27
+// MySQLDriver is exported to make the driver directly accessible.
28
+// In general the driver is used via the database/sql package.
29
+type MySQLDriver struct{}
30
+
31
+// DialFunc is a function which can be used to establish the network connection.
32
+// Custom dial functions must be registered with RegisterDial
33
+//
34
+// Deprecated: users should register a DialContextFunc instead
35
+type DialFunc func(addr string) (net.Conn, error)
36
+
37
+// DialContextFunc is a function which can be used to establish the network connection.
38
+// Custom dial functions must be registered with RegisterDialContext
39
+type DialContextFunc func(ctx context.Context, addr string) (net.Conn, error)
40
+
41
+var (
42
+	dialsLock sync.RWMutex
43
+	dials     map[string]DialContextFunc
44
+)
45
+
46
+// RegisterDialContext registers a custom dial function. It can then be used by the
47
+// network address mynet(addr), where mynet is the registered new network.
48
+// The current context for the connection and its address is passed to the dial function.
49
+func RegisterDialContext(net string, dial DialContextFunc) {
50
+	dialsLock.Lock()
51
+	defer dialsLock.Unlock()
52
+	if dials == nil {
53
+		dials = make(map[string]DialContextFunc)
54
+	}
55
+	dials[net] = dial
56
+}
57
+
58
+// RegisterDial registers a custom dial function. It can then be used by the
59
+// network address mynet(addr), where mynet is the registered new network.
60
+// addr is passed as a parameter to the dial function.
61
+//
62
+// Deprecated: users should call RegisterDialContext instead
63
+func RegisterDial(network string, dial DialFunc) {
64
+	RegisterDialContext(network, func(_ context.Context, addr string) (net.Conn, error) {
65
+		return dial(addr)
66
+	})
67
+}
68
+
69
+// Open new Connection.
70
+// See https://github.com/go-sql-driver/mysql#dsn-data-source-name for how
71
+// the DSN string is formatted
72
+func (d MySQLDriver) Open(dsn string) (driver.Conn, error) {
73
+	cfg, err := ParseDSN(dsn)
74
+	if err != nil {
75
+		return nil, err
76
+	}
77
+	c := &connector{
78
+		cfg: cfg,
79
+	}
80
+	return c.Connect(context.Background())
81
+}
82
+
83
+func init() {
84
+	sql.Register("mysql", &MySQLDriver{})
85
+}
86
+
87
+// NewConnector returns new driver.Connector.
88
+func NewConnector(cfg *Config) (driver.Connector, error) {
89
+	cfg = cfg.Clone()
90
+	// normalize the contents of cfg so calls to NewConnector have the same
91
+	// behavior as MySQLDriver.OpenConnector
92
+	if err := cfg.normalize(); err != nil {
93
+		return nil, err
94
+	}
95
+	return &connector{cfg: cfg}, nil
96
+}
97
+
98
+// OpenConnector implements driver.DriverContext.
99
+func (d MySQLDriver) OpenConnector(dsn string) (driver.Connector, error) {
100
+	cfg, err := ParseDSN(dsn)
101
+	if err != nil {
102
+		return nil, err
103
+	}
104
+	return &connector{
105
+		cfg: cfg,
106
+	}, nil
107
+}

+ 560
- 0
vendor/github.com/go-sql-driver/mysql/dsn.go View File

@@ -0,0 +1,560 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2016 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
+package mysql
10
+
11
+import (
12
+	"bytes"
13
+	"crypto/rsa"
14
+	"crypto/tls"
15
+	"errors"
16
+	"fmt"
17
+	"math/big"
18
+	"net"
19
+	"net/url"
20
+	"sort"
21
+	"strconv"
22
+	"strings"
23
+	"time"
24
+)
25
+
26
+var (
27
+	errInvalidDSNUnescaped       = errors.New("invalid DSN: did you forget to escape a param value?")
28
+	errInvalidDSNAddr            = errors.New("invalid DSN: network address not terminated (missing closing brace)")
29
+	errInvalidDSNNoSlash         = errors.New("invalid DSN: missing the slash separating the database name")
30
+	errInvalidDSNUnsafeCollation = errors.New("invalid DSN: interpolateParams can not be used with unsafe collations")
31
+)
32
+
33
+// Config is a configuration parsed from a DSN string.
34
+// If a new Config is created instead of being parsed from a DSN string,
35
+// the NewConfig function should be used, which sets default values.
36
+type Config struct {
37
+	User             string            // Username
38
+	Passwd           string            // Password (requires User)
39
+	Net              string            // Network type
40
+	Addr             string            // Network address (requires Net)
41
+	DBName           string            // Database name
42
+	Params           map[string]string // Connection parameters
43
+	Collation        string            // Connection collation
44
+	Loc              *time.Location    // Location for time.Time values
45
+	MaxAllowedPacket int               // Max packet size allowed
46
+	ServerPubKey     string            // Server public key name
47
+	pubKey           *rsa.PublicKey    // Server public key
48
+	TLSConfig        string            // TLS configuration name
49
+	tls              *tls.Config       // TLS configuration
50
+	Timeout          time.Duration     // Dial timeout
51
+	ReadTimeout      time.Duration     // I/O read timeout
52
+	WriteTimeout     time.Duration     // I/O write timeout
53
+
54
+	AllowAllFiles           bool // Allow all files to be used with LOAD DATA LOCAL INFILE
55
+	AllowCleartextPasswords bool // Allows the cleartext client side plugin
56
+	AllowNativePasswords    bool // Allows the native password authentication method
57
+	AllowOldPasswords       bool // Allows the old insecure password method
58
+	CheckConnLiveness       bool // Check connections for liveness before using them
59
+	ClientFoundRows         bool // Return number of matching rows instead of rows changed
60
+	ColumnsWithAlias        bool // Prepend table alias to column names
61
+	InterpolateParams       bool // Interpolate placeholders into query string
62
+	MultiStatements         bool // Allow multiple statements in one query
63
+	ParseTime               bool // Parse time values to time.Time
64
+	RejectReadOnly          bool // Reject read-only connections
65
+}
66
+
67
+// NewConfig creates a new Config and sets default values.
68
+func NewConfig() *Config {
69
+	return &Config{
70
+		Collation:            defaultCollation,
71
+		Loc:                  time.UTC,
72
+		MaxAllowedPacket:     defaultMaxAllowedPacket,
73
+		AllowNativePasswords: true,
74
+		CheckConnLiveness:    true,
75
+	}
76
+}
77
+
78
+func (cfg *Config) Clone() *Config {
79
+	cp := *cfg
80
+	if cp.tls != nil {
81
+		cp.tls = cfg.tls.Clone()
82
+	}
83
+	if len(cp.Params) > 0 {
84
+		cp.Params = make(map[string]string, len(cfg.Params))
85
+		for k, v := range cfg.Params {
86
+			cp.Params[k] = v
87
+		}
88
+	}
89
+	if cfg.pubKey != nil {
90
+		cp.pubKey = &rsa.PublicKey{
91
+			N: new(big.Int).Set(cfg.pubKey.N),
92
+			E: cfg.pubKey.E,
93
+		}
94
+	}
95
+	return &cp
96
+}
97
+
98
+func (cfg *Config) normalize() error {
99
+	if cfg.InterpolateParams && unsafeCollations[cfg.Collation] {
100
+		return errInvalidDSNUnsafeCollation
101
+	}
102
+
103
+	// Set default network if empty
104
+	if cfg.Net == "" {
105
+		cfg.Net = "tcp"
106
+	}
107
+
108
+	// Set default address if empty
109
+	if cfg.Addr == "" {
110
+		switch cfg.Net {
111
+		case "tcp":
112
+			cfg.Addr = "127.0.0.1:3306"
113
+		case "unix":
114
+			cfg.Addr = "/tmp/mysql.sock"
115
+		default:
116
+			return errors.New("default addr for network '" + cfg.Net + "' unknown")
117
+		}
118
+	} else if cfg.Net == "tcp" {
119
+		cfg.Addr = ensureHavePort(cfg.Addr)
120
+	}
121
+
122
+	switch cfg.TLSConfig {
123
+	case "false", "":
124
+		// don't set anything
125
+	case "true":
126
+		cfg.tls = &tls.Config{}
127
+	case "skip-verify", "preferred":
128
+		cfg.tls = &tls.Config{InsecureSkipVerify: true}
129
+	default:
130
+		cfg.tls = getTLSConfigClone(cfg.TLSConfig)
131
+		if cfg.tls == nil {
132
+			return errors.New("invalid value / unknown config name: " + cfg.TLSConfig)
133
+		}
134
+	}
135
+
136
+	if cfg.tls != nil && cfg.tls.ServerName == "" && !cfg.tls.InsecureSkipVerify {
137
+		host, _, err := net.SplitHostPort(cfg.Addr)
138
+		if err == nil {
139
+			cfg.tls.ServerName = host
140
+		}
141
+	}
142
+
143
+	if cfg.ServerPubKey != "" {
144
+		cfg.pubKey = getServerPubKey(cfg.ServerPubKey)
145
+		if cfg.pubKey == nil {
146
+			return errors.New("invalid value / unknown server pub key name: " + cfg.ServerPubKey)
147
+		}
148
+	}
149
+
150
+	return nil
151
+}
152
+
153
+func writeDSNParam(buf *bytes.Buffer, hasParam *bool, name, value string) {
154
+	buf.Grow(1 + len(name) + 1 + len(value))
155
+	if !*hasParam {
156
+		*hasParam = true
157
+		buf.WriteByte('?')
158
+	} else {
159
+		buf.WriteByte('&')
160
+	}
161
+	buf.WriteString(name)
162
+	buf.WriteByte('=')
163
+	buf.WriteString(value)
164
+}
165
+
166
+// FormatDSN formats the given Config into a DSN string which can be passed to
167
+// the driver.
168
+func (cfg *Config) FormatDSN() string {
169
+	var buf bytes.Buffer
170
+
171
+	// [username[:password]@]
172
+	if len(cfg.User) > 0 {
173
+		buf.WriteString(cfg.User)
174
+		if len(cfg.Passwd) > 0 {
175
+			buf.WriteByte(':')
176
+			buf.WriteString(cfg.Passwd)
177
+		}
178
+		buf.WriteByte('@')
179
+	}
180
+
181
+	// [protocol[(address)]]
182
+	if len(cfg.Net) > 0 {
183
+		buf.WriteString(cfg.Net)
184
+		if len(cfg.Addr) > 0 {
185
+			buf.WriteByte('(')
186
+			buf.WriteString(cfg.Addr)
187
+			buf.WriteByte(')')
188
+		}
189
+	}
190
+
191
+	// /dbname
192
+	buf.WriteByte('/')
193
+	buf.WriteString(cfg.DBName)
194
+
195
+	// [?param1=value1&...&paramN=valueN]
196
+	hasParam := false
197
+
198
+	if cfg.AllowAllFiles {
199
+		hasParam = true
200
+		buf.WriteString("?allowAllFiles=true")
201
+	}
202
+
203
+	if cfg.AllowCleartextPasswords {
204
+		writeDSNParam(&buf, &hasParam, "allowCleartextPasswords", "true")
205
+	}
206
+
207
+	if !cfg.AllowNativePasswords {
208
+		writeDSNParam(&buf, &hasParam, "allowNativePasswords", "false")
209
+	}
210
+
211
+	if cfg.AllowOldPasswords {
212
+		writeDSNParam(&buf, &hasParam, "allowOldPasswords", "true")
213
+	}
214
+
215
+	if !cfg.CheckConnLiveness {
216
+		writeDSNParam(&buf, &hasParam, "checkConnLiveness", "false")
217
+	}
218
+
219
+	if cfg.ClientFoundRows {
220
+		writeDSNParam(&buf, &hasParam, "clientFoundRows", "true")
221
+	}
222
+
223
+	if col := cfg.Collation; col != defaultCollation && len(col) > 0 {
224
+		writeDSNParam(&buf, &hasParam, "collation", col)
225
+	}
226
+
227
+	if cfg.ColumnsWithAlias {
228
+		writeDSNParam(&buf, &hasParam, "columnsWithAlias", "true")
229
+	}
230
+
231
+	if cfg.InterpolateParams {
232
+		writeDSNParam(&buf, &hasParam, "interpolateParams", "true")
233
+	}
234
+
235
+	if cfg.Loc != time.UTC && cfg.Loc != nil {
236
+		writeDSNParam(&buf, &hasParam, "loc", url.QueryEscape(cfg.Loc.String()))
237
+	}
238
+
239
+	if cfg.MultiStatements {
240
+		writeDSNParam(&buf, &hasParam, "multiStatements", "true")
241
+	}
242
+
243
+	if cfg.ParseTime {
244
+		writeDSNParam(&buf, &hasParam, "parseTime", "true")
245
+	}
246
+
247
+	if cfg.ReadTimeout > 0 {
248
+		writeDSNParam(&buf, &hasParam, "readTimeout", cfg.ReadTimeout.String())
249
+	}
250
+
251
+	if cfg.RejectReadOnly {
252
+		writeDSNParam(&buf, &hasParam, "rejectReadOnly", "true")
253
+	}
254
+
255
+	if len(cfg.ServerPubKey) > 0 {
256
+		writeDSNParam(&buf, &hasParam, "serverPubKey", url.QueryEscape(cfg.ServerPubKey))
257
+	}
258
+
259
+	if cfg.Timeout > 0 {
260
+		writeDSNParam(&buf, &hasParam, "timeout", cfg.Timeout.String())
261
+	}
262
+
263
+	if len(cfg.TLSConfig) > 0 {
264
+		writeDSNParam(&buf, &hasParam, "tls", url.QueryEscape(cfg.TLSConfig))
265
+	}
266
+
267
+	if cfg.WriteTimeout > 0 {
268
+		writeDSNParam(&buf, &hasParam, "writeTimeout", cfg.WriteTimeout.String())
269
+	}
270
+
271
+	if cfg.MaxAllowedPacket != defaultMaxAllowedPacket {
272
+		writeDSNParam(&buf, &hasParam, "maxAllowedPacket", strconv.Itoa(cfg.MaxAllowedPacket))
273
+	}
274
+
275
+	// other params
276
+	if cfg.Params != nil {
277
+		var params []string
278
+		for param := range cfg.Params {
279
+			params = append(params, param)
280
+		}
281
+		sort.Strings(params)
282
+		for _, param := range params {
283
+			writeDSNParam(&buf, &hasParam, param, url.QueryEscape(cfg.Params[param]))
284
+		}
285
+	}
286
+
287
+	return buf.String()
288
+}
289
+
290
+// ParseDSN parses the DSN string to a Config
291
+func ParseDSN(dsn string) (cfg *Config, err error) {
292
+	// New config with some default values
293
+	cfg = NewConfig()
294
+
295
+	// [user[:password]@][net[(addr)]]/dbname[?param1=value1&paramN=valueN]
296
+	// Find the last '/' (since the password or the net addr might contain a '/')
297
+	foundSlash := false
298
+	for i := len(dsn) - 1; i >= 0; i-- {
299
+		if dsn[i] == '/' {
300
+			foundSlash = true
301
+			var j, k int
302
+
303
+			// left part is empty if i <= 0
304
+			if i > 0 {
305
+				// [username[:password]@][protocol[(address)]]
306
+				// Find the last '@' in dsn[:i]
307
+				for j = i; j >= 0; j-- {
308
+					if dsn[j] == '@' {
309
+						// username[:password]
310
+						// Find the first ':' in dsn[:j]
311
+						for k = 0; k < j; k++ {
312
+							if dsn[k] == ':' {
313
+								cfg.Passwd = dsn[k+1 : j]
314
+								break
315
+							}
316
+						}
317
+						cfg.User = dsn[:k]
318
+
319
+						break
320
+					}
321
+				}
322
+
323
+				// [protocol[(address)]]
324
+				// Find the first '(' in dsn[j+1:i]
325
+				for k = j + 1; k < i; k++ {
326
+					if dsn[k] == '(' {
327
+						// dsn[i-1] must be == ')' if an address is specified
328
+						if dsn[i-1] != ')' {
329
+							if strings.ContainsRune(dsn[k+1:i], ')') {
330
+								return nil, errInvalidDSNUnescaped
331
+							}
332
+							return nil, errInvalidDSNAddr
333
+						}
334
+						cfg.Addr = dsn[k+1 : i-1]
335
+						break
336
+					}
337
+				}
338
+				cfg.Net = dsn[j+1 : k]
339
+			}
340
+
341
+			// dbname[?param1=value1&...&paramN=valueN]
342
+			// Find the first '?' in dsn[i+1:]
343
+			for j = i + 1; j < len(dsn); j++ {
344
+				if dsn[j] == '?' {
345
+					if err = parseDSNParams(cfg, dsn[j+1:]); err != nil {
346
+						return
347
+					}
348
+					break
349
+				}
350
+			}
351
+			cfg.DBName = dsn[i+1 : j]
352
+
353
+			break
354
+		}
355
+	}
356
+
357
+	if !foundSlash && len(dsn) > 0 {
358
+		return nil, errInvalidDSNNoSlash
359
+	}
360
+
361
+	if err = cfg.normalize(); err != nil {
362
+		return nil, err
363
+	}
364
+	return
365
+}
366
+
367
+// parseDSNParams parses the DSN "query string"
368
+// Values must be url.QueryEscape'ed
369
+func parseDSNParams(cfg *Config, params string) (err error) {
370
+	for _, v := range strings.Split(params, "&") {
371
+		param := strings.SplitN(v, "=", 2)
372
+		if len(param) != 2 {
373
+			continue
374
+		}
375
+
376
+		// cfg params
377
+		switch value := param[1]; param[0] {
378
+		// Disable INFILE whitelist / enable all files
379
+		case "allowAllFiles":
380
+			var isBool bool
381
+			cfg.AllowAllFiles, isBool = readBool(value)
382
+			if !isBool {
383
+				return errors.New("invalid bool value: " + value)
384
+			}
385
+
386
+		// Use cleartext authentication mode (MySQL 5.5.10+)
387
+		case "allowCleartextPasswords":
388
+			var isBool bool
389
+			cfg.AllowCleartextPasswords, isBool = readBool(value)
390
+			if !isBool {
391
+				return errors.New("invalid bool value: " + value)
392
+			}
393
+
394
+		// Use native password authentication
395
+		case "allowNativePasswords":
396
+			var isBool bool
397
+			cfg.AllowNativePasswords, isBool = readBool(value)
398
+			if !isBool {
399
+				return errors.New("invalid bool value: " + value)
400
+			}
401
+
402
+		// Use old authentication mode (pre MySQL 4.1)
403
+		case "allowOldPasswords":
404
+			var isBool bool
405
+			cfg.AllowOldPasswords, isBool = readBool(value)
406
+			if !isBool {
407
+				return errors.New("invalid bool value: " + value)
408
+			}
409
+
410
+		// Check connections for Liveness before using them
411
+		case "checkConnLiveness":
412
+			var isBool bool
413
+			cfg.CheckConnLiveness, isBool = readBool(value)
414
+			if !isBool {
415
+				return errors.New("invalid bool value: " + value)
416
+			}
417
+
418
+		// Switch "rowsAffected" mode
419
+		case "clientFoundRows":
420
+			var isBool bool
421
+			cfg.ClientFoundRows, isBool = readBool(value)
422
+			if !isBool {
423
+				return errors.New("invalid bool value: " + value)
424
+			}
425
+
426
+		// Collation
427
+		case "collation":
428
+			cfg.Collation = value
429
+			break
430
+
431
+		case "columnsWithAlias":
432
+			var isBool bool
433
+			cfg.ColumnsWithAlias, isBool = readBool(value)
434
+			if !isBool {
435
+				return errors.New("invalid bool value: " + value)
436
+			}
437
+
438
+		// Compression
439
+		case "compress":
440
+			return errors.New("compression not implemented yet")
441
+
442
+		// Enable client side placeholder substitution
443
+		case "interpolateParams":
444
+			var isBool bool
445
+			cfg.InterpolateParams, isBool = readBool(value)
446
+			if !isBool {
447
+				return errors.New("invalid bool value: " + value)
448
+			}
449
+
450
+		// Time Location
451
+		case "loc":
452
+			if value, err = url.QueryUnescape(value); err != nil {
453
+				return
454
+			}
455
+			cfg.Loc, err = time.LoadLocation(value)
456
+			if err != nil {
457
+				return
458
+			}
459
+
460
+		// multiple statements in one query
461
+		case "multiStatements":
462
+			var isBool bool
463
+			cfg.MultiStatements, isBool = readBool(value)
464
+			if !isBool {
465
+				return errors.New("invalid bool value: " + value)
466
+			}
467
+
468
+		// time.Time parsing
469
+		case "parseTime":
470
+			var isBool bool
471
+			cfg.ParseTime, isBool = readBool(value)
472
+			if !isBool {
473
+				return errors.New("invalid bool value: " + value)
474
+			}
475
+
476
+		// I/O read Timeout
477
+		case "readTimeout":
478
+			cfg.ReadTimeout, err = time.ParseDuration(value)
479
+			if err != nil {
480
+				return
481
+			}
482
+
483
+		// Reject read-only connections
484
+		case "rejectReadOnly":
485
+			var isBool bool
486
+			cfg.RejectReadOnly, isBool = readBool(value)
487
+			if !isBool {
488
+				return errors.New("invalid bool value: " + value)
489
+			}
490
+
491
+		// Server public key
492
+		case "serverPubKey":
493
+			name, err := url.QueryUnescape(value)
494
+			if err != nil {
495
+				return fmt.Errorf("invalid value for server pub key name: %v", err)
496
+			}
497
+			cfg.ServerPubKey = name
498
+
499
+		// Strict mode
500
+		case "strict":
501
+			panic("strict mode has been removed. See https://github.com/go-sql-driver/mysql/wiki/strict-mode")
502
+
503
+		// Dial Timeout
504
+		case "timeout":
505
+			cfg.Timeout, err = time.ParseDuration(value)
506
+			if err != nil {
507
+				return
508
+			}
509
+
510
+		// TLS-Encryption
511
+		case "tls":
512
+			boolValue, isBool := readBool(value)
513
+			if isBool {
514
+				if boolValue {
515
+					cfg.TLSConfig = "true"
516
+				} else {
517
+					cfg.TLSConfig = "false"
518
+				}
519
+			} else if vl := strings.ToLower(value); vl == "skip-verify" || vl == "preferred" {
520
+				cfg.TLSConfig = vl
521
+			} else {
522
+				name, err := url.QueryUnescape(value)
523
+				if err != nil {
524
+					return fmt.Errorf("invalid value for TLS config name: %v", err)
525
+				}
526
+				cfg.TLSConfig = name
527
+			}
528
+
529
+		// I/O write Timeout
530
+		case "writeTimeout":
531
+			cfg.WriteTimeout, err = time.ParseDuration(value)
532
+			if err != nil {
533
+				return
534
+			}
535
+		case "maxAllowedPacket":
536
+			cfg.MaxAllowedPacket, err = strconv.Atoi(value)
537
+			if err != nil {
538
+				return
539
+			}
540
+		default:
541
+			// lazy init
542
+			if cfg.Params == nil {
543
+				cfg.Params = make(map[string]string)
544
+			}
545
+
546
+			if cfg.Params[param[0]], err = url.QueryUnescape(value); err != nil {
547
+				return
548
+			}
549
+		}
550
+	}
551
+
552
+	return
553
+}
554
+
555
+func ensureHavePort(addr string) string {
556
+	if _, _, err := net.SplitHostPort(addr); err != nil {
557
+		return net.JoinHostPort(addr, "3306")
558
+	}
559
+	return addr
560
+}

+ 65
- 0
vendor/github.com/go-sql-driver/mysql/errors.go View File

@@ -0,0 +1,65 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2013 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
+package mysql
10
+
11
+import (
12
+	"errors"
13
+	"fmt"
14
+	"log"
15
+	"os"
16
+)
17
+
18
+// Various errors the driver might return. Can change between driver versions.
19
+var (
20
+	ErrInvalidConn       = errors.New("invalid connection")
21
+	ErrMalformPkt        = errors.New("malformed packet")
22
+	ErrNoTLS             = errors.New("TLS requested but server does not support TLS")
23
+	ErrCleartextPassword = errors.New("this user requires clear text authentication. If you still want to use it, please add 'allowCleartextPasswords=1' to your DSN")
24
+	ErrNativePassword    = errors.New("this user requires mysql native password authentication.")
25
+	ErrOldPassword       = errors.New("this user requires old password authentication. If you still want to use it, please add 'allowOldPasswords=1' to your DSN. See also https://github.com/go-sql-driver/mysql/wiki/old_passwords")
26
+	ErrUnknownPlugin     = errors.New("this authentication plugin is not supported")
27
+	ErrOldProtocol       = errors.New("MySQL server does not support required protocol 41+")
28
+	ErrPktSync           = errors.New("commands out of sync. You can't run this command now")
29
+	ErrPktSyncMul        = errors.New("commands out of sync. Did you run multiple statements at once?")
30
+	ErrPktTooLarge       = errors.New("packet for query is too large. Try adjusting the 'max_allowed_packet' variable on the server")
31
+	ErrBusyBuffer        = errors.New("busy buffer")
32
+
33
+	// errBadConnNoWrite is used for connection errors where nothing was sent to the database yet.
34
+	// If this happens first in a function starting a database interaction, it should be replaced by driver.ErrBadConn
35
+	// to trigger a resend.
36
+	// See https://github.com/go-sql-driver/mysql/pull/302
37
+	errBadConnNoWrite = errors.New("bad connection")
38
+)
39
+
40
+var errLog = Logger(log.New(os.Stderr, "[mysql] ", log.Ldate|log.Ltime|log.Lshortfile))
41
+
42
+// Logger is used to log critical error messages.
43
+type Logger interface {
44
+	Print(v ...interface{})
45
+}
46
+
47
+// SetLogger is used to set the logger for critical errors.
48
+// The initial logger is os.Stderr.
49
+func SetLogger(logger Logger) error {
50
+	if logger == nil {
51
+		return errors.New("logger is nil")
52
+	}
53
+	errLog = logger
54
+	return nil
55
+}
56
+
57
+// MySQLError is an error type which represents a single MySQL error
58
+type MySQLError struct {
59
+	Number  uint16
60
+	Message string
61
+}
62
+
63
+func (me *MySQLError) Error() string {
64
+	return fmt.Sprintf("Error %d: %s", me.Number, me.Message)
65
+}

+ 194
- 0
vendor/github.com/go-sql-driver/mysql/fields.go View File

@@ -0,0 +1,194 @@
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
+package mysql
10
+
11
+import (
12
+	"database/sql"
13
+	"reflect"
14
+)
15
+
16
+func (mf *mysqlField) typeDatabaseName() string {
17
+	switch mf.fieldType {
18
+	case fieldTypeBit:
19
+		return "BIT"
20
+	case fieldTypeBLOB:
21
+		if mf.charSet != collations[binaryCollation] {
22
+			return "TEXT"
23
+		}
24
+		return "BLOB"
25
+	case fieldTypeDate:
26
+		return "DATE"
27
+	case fieldTypeDateTime:
28
+		return "DATETIME"
29
+	case fieldTypeDecimal:
30
+		return "DECIMAL"
31
+	case fieldTypeDouble:
32
+		return "DOUBLE"
33
+	case fieldTypeEnum:
34
+		return "ENUM"
35
+	case fieldTypeFloat:
36
+		return "FLOAT"
37
+	case fieldTypeGeometry:
38
+		return "GEOMETRY"
39
+	case fieldTypeInt24:
40
+		return "MEDIUMINT"
41
+	case fieldTypeJSON:
42
+		return "JSON"
43
+	case fieldTypeLong:
44
+		return "INT"
45
+	case fieldTypeLongBLOB:
46
+		if mf.charSet != collations[binaryCollation] {
47
+			return "LONGTEXT"
48
+		}
49
+		return "LONGBLOB"
50
+	case fieldTypeLongLong:
51
+		return "BIGINT"
52
+	case fieldTypeMediumBLOB:
53
+		if mf.charSet != collations[binaryCollation] {
54
+			return "MEDIUMTEXT"
55
+		}
56
+		return "MEDIUMBLOB"
57
+	case fieldTypeNewDate:
58
+		return "DATE"
59
+	case fieldTypeNewDecimal:
60
+		return "DECIMAL"
61
+	case fieldTypeNULL:
62
+		return "NULL"
63
+	case fieldTypeSet:
64
+		return "SET"
65
+	case fieldTypeShort:
66
+		return "SMALLINT"
67
+	case fieldTypeString:
68
+		if mf.charSet == collations[binaryCollation] {
69
+			return "BINARY"
70
+		}
71
+		return "CHAR"
72
+	case fieldTypeTime:
73
+		return "TIME"
74
+	case fieldTypeTimestamp:
75
+		return "TIMESTAMP"
76
+	case fieldTypeTiny:
77
+		return "TINYINT"
78
+	case fieldTypeTinyBLOB:
79
+		if mf.charSet != collations[binaryCollation] {
80
+			return "TINYTEXT"
81
+		}
82
+		return "TINYBLOB"
83
+	case fieldTypeVarChar:
84
+		if mf.charSet == collations[binaryCollation] {
85
+			return "VARBINARY"
86
+		}
87
+		return "VARCHAR"
88
+	case fieldTypeVarString:
89
+		if mf.charSet == collations[binaryCollation] {
90
+			return "VARBINARY"
91
+		}
92
+		return "VARCHAR"
93
+	case fieldTypeYear:
94
+		return "YEAR"
95
+	default:
96
+		return ""
97
+	}
98
+}
99
+
100
+var (
101
+	scanTypeFloat32   = reflect.TypeOf(float32(0))
102
+	scanTypeFloat64   = reflect.TypeOf(float64(0))
103
+	scanTypeInt8      = reflect.TypeOf(int8(0))
104
+	scanTypeInt16     = reflect.TypeOf(int16(0))
105
+	scanTypeInt32     = reflect.TypeOf(int32(0))
106
+	scanTypeInt64     = reflect.TypeOf(int64(0))
107
+	scanTypeNullFloat = reflect.TypeOf(sql.NullFloat64{})
108
+	scanTypeNullInt   = reflect.TypeOf(sql.NullInt64{})
109
+	scanTypeNullTime  = reflect.TypeOf(NullTime{})
110
+	scanTypeUint8     = reflect.TypeOf(uint8(0))
111
+	scanTypeUint16    = reflect.TypeOf(uint16(0))
112
+	scanTypeUint32    = reflect.TypeOf(uint32(0))
113
+	scanTypeUint64    = reflect.TypeOf(uint64(0))
114
+	scanTypeRawBytes  = reflect.TypeOf(sql.RawBytes{})
115
+	scanTypeUnknown   = reflect.TypeOf(new(interface{}))
116
+)
117
+
118
+type mysqlField struct {
119
+	tableName string
120
+	name      string
121
+	length    uint32
122
+	flags     fieldFlag
123
+	fieldType fieldType
124
+	decimals  byte
125
+	charSet   uint8
126
+}
127
+
128
+func (mf *mysqlField) scanType() reflect.Type {
129
+	switch mf.fieldType {
130
+	case fieldTypeTiny:
131
+		if mf.flags&flagNotNULL != 0 {
132
+			if mf.flags&flagUnsigned != 0 {
133
+				return scanTypeUint8
134
+			}
135
+			return scanTypeInt8
136
+		}
137
+		return scanTypeNullInt
138
+
139
+	case fieldTypeShort, fieldTypeYear:
140
+		if mf.flags&flagNotNULL != 0 {
141
+			if mf.flags&flagUnsigned != 0 {
142
+				return scanTypeUint16
143
+			}
144
+			return scanTypeInt16
145
+		}
146
+		return scanTypeNullInt
147
+
148
+	case fieldTypeInt24, fieldTypeLong:
149
+		if mf.flags&flagNotNULL != 0 {
150
+			if mf.flags&flagUnsigned != 0 {
151
+				return scanTypeUint32
152
+			}
153
+			return scanTypeInt32
154
+		}
155
+		return scanTypeNullInt
156
+
157
+	case fieldTypeLongLong:
158
+		if mf.flags&flagNotNULL != 0 {
159
+			if mf.flags&flagUnsigned != 0 {
160
+				return scanTypeUint64
161
+			}
162
+			return scanTypeInt64
163
+		}
164
+		return scanTypeNullInt
165
+
166
+	case fieldTypeFloat:
167
+		if mf.flags&flagNotNULL != 0 {
168
+			return scanTypeFloat32
169
+		}
170
+		return scanTypeNullFloat
171
+
172
+	case fieldTypeDouble:
173
+		if mf.flags&flagNotNULL != 0 {
174
+			return scanTypeFloat64
175
+		}
176
+		return scanTypeNullFloat
177
+
178
+	case fieldTypeDecimal, fieldTypeNewDecimal, fieldTypeVarChar,
179
+		fieldTypeBit, fieldTypeEnum, fieldTypeSet, fieldTypeTinyBLOB,
180
+		fieldTypeMediumBLOB, fieldTypeLongBLOB, fieldTypeBLOB,
181
+		fieldTypeVarString, fieldTypeString, fieldTypeGeometry, fieldTypeJSON,
182
+		fieldTypeTime:
183
+		return scanTypeRawBytes
184
+
185
+	case fieldTypeDate, fieldTypeNewDate,
186
+		fieldTypeTimestamp, fieldTypeDateTime:
187
+		// NullTime is always returned for more consistent behavior as it can
188
+		// handle both cases of parseTime regardless if the field is nullable.
189
+		return scanTypeNullTime
190
+
191
+	default:
192
+		return scanTypeUnknown
193
+	}
194
+}

+ 3
- 0
vendor/github.com/go-sql-driver/mysql/go.mod View File

@@ -0,0 +1,3 @@
1
+module github.com/go-sql-driver/mysql
2
+
3
+go 1.10

+ 182
- 0
vendor/github.com/go-sql-driver/mysql/infile.go View File

@@ -0,0 +1,182 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2013 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
+package mysql
10
+
11
+import (
12
+	"fmt"
13
+	"io"
14
+	"os"
15
+	"strings"
16
+	"sync"
17
+)
18
+
19
+var (
20
+	fileRegister       map[string]bool
21
+	fileRegisterLock   sync.RWMutex
22
+	readerRegister     map[string]func() io.Reader
23
+	readerRegisterLock sync.RWMutex
24
+)
25
+
26
+// RegisterLocalFile adds the given file to the file whitelist,
27
+// so that it can be used by "LOAD DATA LOCAL INFILE <filepath>".
28
+// Alternatively you can allow the use of all local files with
29
+// the DSN parameter 'allowAllFiles=true'
30
+//
31
+//  filePath := "/home/gopher/data.csv"
32
+//  mysql.RegisterLocalFile(filePath)
33
+//  err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo")
34
+//  if err != nil {
35
+//  ...
36
+//
37
+func RegisterLocalFile(filePath string) {
38
+	fileRegisterLock.Lock()
39
+	// lazy map init
40
+	if fileRegister == nil {
41
+		fileRegister = make(map[string]bool)
42
+	}
43
+
44
+	fileRegister[strings.Trim(filePath, `"`)] = true
45
+	fileRegisterLock.Unlock()
46
+}
47
+
48
+// DeregisterLocalFile removes the given filepath from the whitelist.
49
+func DeregisterLocalFile(filePath string) {
50
+	fileRegisterLock.Lock()
51
+	delete(fileRegister, strings.Trim(filePath, `"`))
52
+	fileRegisterLock.Unlock()
53
+}
54
+
55
+// RegisterReaderHandler registers a handler function which is used
56
+// to receive a io.Reader.
57
+// The Reader can be used by "LOAD DATA LOCAL INFILE Reader::<name>".
58
+// If the handler returns a io.ReadCloser Close() is called when the
59
+// request is finished.
60
+//
61
+//  mysql.RegisterReaderHandler("data", func() io.Reader {
62
+//  	var csvReader io.Reader // Some Reader that returns CSV data
63
+//  	... // Open Reader here
64
+//  	return csvReader
65
+//  })
66
+//  err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo")
67
+//  if err != nil {
68
+//  ...
69
+//
70
+func RegisterReaderHandler(name string, handler func() io.Reader) {
71
+	readerRegisterLock.Lock()
72
+	// lazy map init
73
+	if readerRegister == nil {
74
+		readerRegister = make(map[string]func() io.Reader)
75
+	}
76
+
77
+	readerRegister[name] = handler
78
+	readerRegisterLock.Unlock()
79
+}
80
+
81
+// DeregisterReaderHandler removes the ReaderHandler function with
82
+// the given name from the registry.
83
+func DeregisterReaderHandler(name string) {
84
+	readerRegisterLock.Lock()
85
+	delete(readerRegister, name)
86
+	readerRegisterLock.Unlock()
87
+}
88
+
89
+func deferredClose(err *error, closer io.Closer) {
90
+	closeErr := closer.Close()
91
+	if *err == nil {
92
+		*err = closeErr
93
+	}
94
+}
95
+
96
+func (mc *mysqlConn) handleInFileRequest(name string) (err error) {
97
+	var rdr io.Reader
98
+	var data []byte
99
+	packetSize := 16 * 1024 // 16KB is small enough for disk readahead and large enough for TCP
100
+	if mc.maxWriteSize < packetSize {
101
+		packetSize = mc.maxWriteSize
102
+	}
103
+
104
+	if idx := strings.Index(name, "Reader::"); idx == 0 || (idx > 0 && name[idx-1] == '/') { // io.Reader
105
+		// The server might return an an absolute path. See issue #355.
106
+		name = name[idx+8:]
107
+
108
+		readerRegisterLock.RLock()
109
+		handler, inMap := readerRegister[name]
110
+		readerRegisterLock.RUnlock()
111
+
112
+		if inMap {
113
+			rdr = handler()
114
+			if rdr != nil {
115
+				if cl, ok := rdr.(io.Closer); ok {
116
+					defer deferredClose(&err, cl)
117
+				}
118
+			} else {
119
+				err = fmt.Errorf("Reader '%s' is <nil>", name)
120
+			}
121
+		} else {
122
+			err = fmt.Errorf("Reader '%s' is not registered", name)
123
+		}
124
+	} else { // File
125
+		name = strings.Trim(name, `"`)
126
+		fileRegisterLock.RLock()
127
+		fr := fileRegister[name]
128
+		fileRegisterLock.RUnlock()
129
+		if mc.cfg.AllowAllFiles || fr {
130
+			var file *os.File
131
+			var fi os.FileInfo
132
+
133
+			if file, err = os.Open(name); err == nil {
134
+				defer deferredClose(&err, file)
135
+
136
+				// get file size
137
+				if fi, err = file.Stat(); err == nil {
138
+					rdr = file
139
+					if fileSize := int(fi.Size()); fileSize < packetSize {
140
+						packetSize = fileSize
141
+					}
142
+				}
143
+			}
144
+		} else {
145
+			err = fmt.Errorf("local file '%s' is not registered", name)
146
+		}
147
+	}
148
+
149
+	// send content packets
150
+	// if packetSize == 0, the Reader contains no data
151
+	if err == nil && packetSize > 0 {
152
+		data := make([]byte, 4+packetSize)
153
+		var n int
154
+		for err == nil {
155
+			n, err = rdr.Read(data[4:])
156
+			if n > 0 {
157
+				if ioErr := mc.writePacket(data[:4+n]); ioErr != nil {
158
+					return ioErr
159
+				}
160
+			}
161
+		}
162
+		if err == io.EOF {
163
+			err = nil
164
+		}
165
+	}
166
+
167
+	// send empty packet (termination)
168
+	if data == nil {
169
+		data = make([]byte, 4)
170
+	}
171
+	if ioErr := mc.writePacket(data[:4]); ioErr != nil {
172
+		return ioErr
173
+	}
174
+
175
+	// read OK packet
176
+	if err == nil {
177
+		return mc.readResultOK()
178
+	}
179
+
180
+	mc.readPacket()
181
+	return err
182
+}

+ 50
- 0
vendor/github.com/go-sql-driver/mysql/nulltime.go View File

@@ -0,0 +1,50 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2013 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
+package mysql
10
+
11
+import (
12
+	"database/sql/driver"
13
+	"fmt"
14
+	"time"
15
+)
16
+
17
+// Scan implements the Scanner interface.
18
+// The value type must be time.Time or string / []byte (formatted time-string),
19
+// otherwise Scan fails.
20
+func (nt *NullTime) Scan(value interface{}) (err error) {
21
+	if value == nil {
22
+		nt.Time, nt.Valid = time.Time{}, false
23
+		return
24
+	}
25
+
26
+	switch v := value.(type) {
27
+	case time.Time:
28
+		nt.Time, nt.Valid = v, true
29
+		return
30
+	case []byte:
31
+		nt.Time, err = parseDateTime(string(v), time.UTC)
32
+		nt.Valid = (err == nil)
33
+		return
34
+	case string:
35
+		nt.Time, err = parseDateTime(v, time.UTC)
36
+		nt.Valid = (err == nil)
37
+		return
38
+	}
39
+
40
+	nt.Valid = false
41
+	return fmt.Errorf("Can't convert %T to time.Time", value)
42
+}
43
+
44
+// Value implements the driver Valuer interface.
45
+func (nt NullTime) Value() (driver.Value, error) {
46
+	if !nt.Valid {
47
+		return nil, nil
48
+	}
49
+	return nt.Time, nil
50
+}

+ 31
- 0
vendor/github.com/go-sql-driver/mysql/nulltime_go113.go View File

@@ -0,0 +1,31 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2013 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.13
10
+
11
+package mysql
12
+
13
+import (
14
+	"database/sql"
15
+)
16
+
17
+// NullTime represents a time.Time that may be NULL.
18
+// NullTime implements the Scanner interface so
19
+// it can be used as a scan destination:
20
+//
21
+//  var nt NullTime
22
+//  err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
23
+//  ...
24
+//  if nt.Valid {
25
+//     // use nt.Time
26
+//  } else {
27
+//     // NULL value
28
+//  }
29
+//
30
+// This NullTime implementation is not driver-specific
31
+type NullTime sql.NullTime

+ 34
- 0
vendor/github.com/go-sql-driver/mysql/nulltime_legacy.go View File

@@ -0,0 +1,34 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2013 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.13
10
+
11
+package mysql
12
+
13
+import (
14
+	"time"
15
+)
16
+
17
+// NullTime represents a time.Time that may be NULL.
18
+// NullTime implements the Scanner interface so
19
+// it can be used as a scan destination:
20
+//
21
+//  var nt NullTime
22
+//  err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
23
+//  ...
24
+//  if nt.Valid {
25
+//     // use nt.Time
26
+//  } else {
27
+//     // NULL value
28
+//  }
29
+//
30
+// This NullTime implementation is not driver-specific
31
+type NullTime struct {
32
+	Time  time.Time
33
+	Valid bool // Valid is true if Time is not NULL
34
+}

+ 1342
- 0
vendor/github.com/go-sql-driver/mysql/packets.go
File diff suppressed because it is too large
View File


+ 22
- 0
vendor/github.com/go-sql-driver/mysql/result.go View File

@@ -0,0 +1,22 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2012 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
+package mysql
10
+
11
+type mysqlResult struct {
12
+	affectedRows int64
13
+	insertId     int64
14
+}
15
+
16
+func (res *mysqlResult) LastInsertId() (int64, error) {
17
+	return res.insertId, nil
18
+}
19
+
20
+func (res *mysqlResult) RowsAffected() (int64, error) {
21
+	return res.affectedRows, nil
22
+}

+ 223
- 0
vendor/github.com/go-sql-driver/mysql/rows.go View File

@@ -0,0 +1,223 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2012 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
+package mysql
10
+
11
+import (
12
+	"database/sql/driver"
13
+	"io"
14
+	"math"
15
+	"reflect"
16
+)
17
+
18
+type resultSet struct {
19
+	columns     []mysqlField
20
+	columnNames []string
21
+	done        bool
22
+}
23
+
24
+type mysqlRows struct {
25
+	mc     *mysqlConn
26
+	rs     resultSet
27
+	finish func()
28
+}
29
+
30
+type binaryRows struct {
31
+	mysqlRows
32
+}
33
+
34
+type textRows struct {
35
+	mysqlRows
36
+}
37
+
38
+func (rows *mysqlRows) Columns() []string {
39
+	if rows.rs.columnNames != nil {
40
+		return rows.rs.columnNames
41
+	}
42
+
43
+	columns := make([]string, len(rows.rs.columns))
44
+	if rows.mc != nil && rows.mc.cfg.ColumnsWithAlias {
45
+		for i := range columns {
46
+			if tableName := rows.rs.columns[i].tableName; len(tableName) > 0 {
47
+				columns[i] = tableName + "." + rows.rs.columns[i].name
48
+			} else {
49
+				columns[i] = rows.rs.columns[i].name
50
+			}
51
+		}
52
+	} else {
53
+		for i := range columns {
54
+			columns[i] = rows.rs.columns[i].name
55
+		}
56
+	}
57
+
58
+	rows.rs.columnNames = columns
59
+	return columns
60
+}
61
+
62
+func (rows *mysqlRows) ColumnTypeDatabaseTypeName(i int) string {
63
+	return rows.rs.columns[i].typeDatabaseName()
64
+}
65
+
66
+// func (rows *mysqlRows) ColumnTypeLength(i int) (length int64, ok bool) {
67
+// 	return int64(rows.rs.columns[i].length), true
68
+// }
69
+
70
+func (rows *mysqlRows) ColumnTypeNullable(i int) (nullable, ok bool) {
71
+	return rows.rs.columns[i].flags&flagNotNULL == 0, true
72
+}
73
+
74
+func (rows *mysqlRows) ColumnTypePrecisionScale(i int) (int64, int64, bool) {
75
+	column := rows.rs.columns[i]
76
+	decimals := int64(column.decimals)
77
+
78
+	switch column.fieldType {
79
+	case fieldTypeDecimal, fieldTypeNewDecimal:
80
+		if decimals > 0 {
81
+			return int64(column.length) - 2, decimals, true
82
+		}
83
+		return int64(column.length) - 1, decimals, true
84
+	case fieldTypeTimestamp, fieldTypeDateTime, fieldTypeTime:
85
+		return decimals, decimals, true
86
+	case fieldTypeFloat, fieldTypeDouble:
87
+		if decimals == 0x1f {
88
+			return math.MaxInt64, math.MaxInt64, true
89
+		}
90
+		return math.MaxInt64, decimals, true
91
+	}
92
+
93
+	return 0, 0, false
94
+}
95
+
96
+func (rows *mysqlRows) ColumnTypeScanType(i int) reflect.Type {
97
+	return rows.rs.columns[i].scanType()
98
+}
99
+
100
+func (rows *mysqlRows) Close() (err error) {
101
+	if f := rows.finish; f != nil {
102
+		f()
103
+		rows.finish = nil
104
+	}
105
+
106
+	mc := rows.mc
107
+	if mc == nil {
108
+		return nil
109
+	}
110
+	if err := mc.error(); err != nil {
111
+		return err
112
+	}
113
+
114
+	// flip the buffer for this connection if we need to drain it.
115
+	// note that for a successful query (i.e. one where rows.next()
116
+	// has been called until it returns false), `rows.mc` will be nil
117
+	// by the time the user calls `(*Rows).Close`, so we won't reach this
118
+	// see: https://github.com/golang/go/commit/651ddbdb5056ded455f47f9c494c67b389622a47
119
+	mc.buf.flip()
120
+
121
+	// Remove unread packets from stream
122
+	if !rows.rs.done {
123
+		err = mc.readUntilEOF()
124
+	}
125
+	if err == nil {
126
+		if err = mc.discardResults(); err != nil {
127
+			return err
128
+		}
129
+	}
130
+
131
+	rows.mc = nil
132
+	return err
133
+}
134
+
135
+func (rows *mysqlRows) HasNextResultSet() (b bool) {
136
+	if rows.mc == nil {
137
+		return false
138
+	}
139
+	return rows.mc.status&statusMoreResultsExists != 0
140
+}
141
+
142
+func (rows *mysqlRows) nextResultSet() (int, error) {
143
+	if rows.mc == nil {
144
+		return 0, io.EOF
145
+	}
146
+	if err := rows.mc.error(); err != nil {
147
+		return 0, err
148
+	}
149
+
150
+	// Remove unread packets from stream
151
+	if !rows.rs.done {
152
+		if err := rows.mc.readUntilEOF(); err != nil {
153
+			return 0, err
154
+		}
155
+		rows.rs.done = true
156
+	}
157
+
158
+	if !rows.HasNextResultSet() {
159
+		rows.mc = nil
160
+		return 0, io.EOF
161
+	}
162
+	rows.rs = resultSet{}
163
+	return rows.mc.readResultSetHeaderPacket()
164
+}
165
+
166
+func (rows *mysqlRows) nextNotEmptyResultSet() (int, error) {
167
+	for {
168
+		resLen, err := rows.nextResultSet()
169
+		if err != nil {
170
+			return 0, err
171
+		}
172
+
173
+		if resLen > 0 {
174
+			return resLen, nil
175
+		}
176
+
177
+		rows.rs.done = true
178
+	}
179
+}
180
+
181
+func (rows *binaryRows) NextResultSet() error {
182
+	resLen, err := rows.nextNotEmptyResultSet()
183
+	if err != nil {
184
+		return err
185
+	}
186
+
187
+	rows.rs.columns, err = rows.mc.readColumns(resLen)
188
+	return err
189
+}
190
+
191
+func (rows *binaryRows) Next(dest []driver.Value) error {
192
+	if mc := rows.mc; mc != nil {
193
+		if err := mc.error(); err != nil {
194
+			return err
195
+		}
196
+
197
+		// Fetch next row from stream
198
+		return rows.readRow(dest)
199
+	}
200
+	return io.EOF
201
+}
202
+
203
+func (rows *textRows) NextResultSet() (err error) {
204
+	resLen, err := rows.nextNotEmptyResultSet()
205
+	if err != nil {
206
+		return err
207
+	}
208
+
209
+	rows.rs.columns, err = rows.mc.readColumns(resLen)
210
+	return err
211
+}
212
+
213
+func (rows *textRows) Next(dest []driver.Value) error {
214
+	if mc := rows.mc; mc != nil {
215
+		if err := mc.error(); err != nil {
216
+			return err
217
+		}
218
+
219
+		// Fetch next row from stream
220
+		return rows.readRow(dest)
221
+	}
222
+	return io.EOF
223
+}

+ 204
- 0
vendor/github.com/go-sql-driver/mysql/statement.go View File

@@ -0,0 +1,204 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2012 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
+package mysql
10
+
11
+import (
12
+	"database/sql/driver"
13
+	"fmt"
14
+	"io"
15
+	"reflect"
16
+)
17
+
18
+type mysqlStmt struct {
19
+	mc         *mysqlConn
20
+	id         uint32
21
+	paramCount int
22
+}
23
+
24
+func (stmt *mysqlStmt) Close() error {
25
+	if stmt.mc == nil || stmt.mc.closed.IsSet() {
26
+		// driver.Stmt.Close can be called more than once, thus this function
27
+		// has to be idempotent.
28
+		// See also Issue #450 and golang/go#16019.
29
+		//errLog.Print(ErrInvalidConn)
30
+		return driver.ErrBadConn
31
+	}
32
+
33
+	err := stmt.mc.writeCommandPacketUint32(comStmtClose, stmt.id)
34
+	stmt.mc = nil
35
+	return err
36
+}
37
+
38
+func (stmt *mysqlStmt) NumInput() int {
39
+	return stmt.paramCount
40
+}
41
+
42
+func (stmt *mysqlStmt) ColumnConverter(idx int) driver.ValueConverter {
43
+	return converter{}
44
+}
45
+
46
+func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) {
47
+	if stmt.mc.closed.IsSet() {
48
+		errLog.Print(ErrInvalidConn)
49
+		return nil, driver.ErrBadConn
50
+	}
51
+	// Send command
52
+	err := stmt.writeExecutePacket(args)
53
+	if err != nil {
54
+		return nil, stmt.mc.markBadConn(err)
55
+	}
56
+
57
+	mc := stmt.mc
58
+
59
+	mc.affectedRows = 0
60
+	mc.insertId = 0
61
+
62
+	// Read Result
63
+	resLen, err := mc.readResultSetHeaderPacket()
64
+	if err != nil {
65
+		return nil, err
66
+	}
67
+
68
+	if resLen > 0 {
69
+		// Columns
70
+		if err = mc.readUntilEOF(); err != nil {
71
+			return nil, err
72
+		}
73
+
74
+		// Rows
75
+		if err := mc.readUntilEOF(); err != nil {
76
+			return nil, err
77
+		}
78
+	}
79
+
80
+	if err := mc.discardResults(); err != nil {
81
+		return nil, err
82
+	}
83
+
84
+	return &mysqlResult{
85
+		affectedRows: int64(mc.affectedRows),
86
+		insertId:     int64(mc.insertId),
87
+	}, nil
88
+}
89
+
90
+func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {
91
+	return stmt.query(args)
92
+}
93
+
94
+func (stmt *mysqlStmt) query(args []driver.Value) (*binaryRows, error) {
95
+	if stmt.mc.closed.IsSet() {
96
+		errLog.Print(ErrInvalidConn)
97
+		return nil, driver.ErrBadConn
98
+	}
99
+	// Send command
100
+	err := stmt.writeExecutePacket(args)
101
+	if err != nil {
102
+		return nil, stmt.mc.markBadConn(err)
103
+	}
104
+
105
+	mc := stmt.mc
106
+
107
+	// Read Result
108
+	resLen, err := mc.readResultSetHeaderPacket()
109
+	if err != nil {
110
+		return nil, err
111
+	}
112
+
113
+	rows := new(binaryRows)
114
+
115
+	if resLen > 0 {
116
+		rows.mc = mc
117
+		rows.rs.columns, err = mc.readColumns(resLen)
118
+	} else {
119
+		rows.rs.done = true
120
+
121
+		switch err := rows.NextResultSet(); err {
122
+		case nil, io.EOF:
123
+			return rows, nil
124
+		default:
125
+			return nil, err
126
+		}
127
+	}
128
+
129
+	return rows, err
130
+}
131
+
132
+type converter struct{}
133
+
134
+// ConvertValue mirrors the reference/default converter in database/sql/driver
135
+// with _one_ exception.  We support uint64 with their high bit and the default
136
+// implementation does not.  This function should be kept in sync with
137
+// database/sql/driver defaultConverter.ConvertValue() except for that
138
+// deliberate difference.
139
+func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
140
+	if driver.IsValue(v) {
141
+		return v, nil
142
+	}
143
+
144
+	if vr, ok := v.(driver.Valuer); ok {
145
+		sv, err := callValuerValue(vr)
146
+		if err != nil {
147
+			return nil, err
148
+		}
149
+		if !driver.IsValue(sv) {
150
+			return nil, fmt.Errorf("non-Value type %T returned from Value", sv)
151
+		}
152
+		return sv, nil
153
+	}
154
+
155
+	rv := reflect.ValueOf(v)
156
+	switch rv.Kind() {
157
+	case reflect.Ptr:
158
+		// indirect pointers
159
+		if rv.IsNil() {
160
+			return nil, nil
161
+		} else {
162
+			return c.ConvertValue(rv.Elem().Interface())
163
+		}
164
+	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
165
+		return rv.Int(), nil
166
+	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
167
+		return rv.Uint(), nil
168
+	case reflect.Float32, reflect.Float64:
169
+		return rv.Float(), nil
170
+	case reflect.Bool:
171
+		return rv.Bool(), nil
172
+	case reflect.Slice:
173
+		ek := rv.Type().Elem().Kind()
174
+		if ek == reflect.Uint8 {
175
+			return rv.Bytes(), nil
176
+		}
177
+		return nil, fmt.Errorf("unsupported type %T, a slice of %s", v, ek)
178
+	case reflect.String:
179
+		return rv.String(), nil
180
+	}
181
+	return nil, fmt.Errorf("unsupported type %T, a %s", v, rv.Kind())
182
+}
183
+
184
+var valuerReflectType = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
185
+
186
+// callValuerValue returns vr.Value(), with one exception:
187
+// If vr.Value is an auto-generated method on a pointer type and the
188
+// pointer is nil, it would panic at runtime in the panicwrap
189
+// method. Treat it like nil instead.
190
+//
191
+// This is so people can implement driver.Value on value types and
192
+// still use nil pointers to those types to mean nil/NULL, just like
193
+// string/*string.
194
+//
195
+// This is an exact copy of the same-named unexported function from the
196
+// database/sql package.
197
+func callValuerValue(vr driver.Valuer) (v driver.Value, err error) {
198
+	if rv := reflect.ValueOf(vr); rv.Kind() == reflect.Ptr &&
199
+		rv.IsNil() &&
200
+		rv.Type().Elem().Implements(valuerReflectType) {
201
+		return nil, nil
202
+	}
203
+	return vr.Value()
204
+}

+ 31
- 0
vendor/github.com/go-sql-driver/mysql/transaction.go View File

@@ -0,0 +1,31 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2012 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
+package mysql
10
+
11
+type mysqlTx struct {
12
+	mc *mysqlConn
13
+}
14
+
15
+func (tx *mysqlTx) Commit() (err error) {
16
+	if tx.mc == nil || tx.mc.closed.IsSet() {
17
+		return ErrInvalidConn
18
+	}
19
+	err = tx.mc.exec("COMMIT")
20
+	tx.mc = nil
21
+	return
22
+}
23
+
24
+func (tx *mysqlTx) Rollback() (err error) {
25
+	if tx.mc == nil || tx.mc.closed.IsSet() {
26
+		return ErrInvalidConn
27
+	}
28
+	err = tx.mc.exec("ROLLBACK")
29
+	tx.mc = nil
30
+	return
31
+}

+ 701
- 0
vendor/github.com/go-sql-driver/mysql/utils.go View File

@@ -0,0 +1,701 @@
1
+// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
2
+//
3
+// Copyright 2012 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
+package mysql
10
+
11
+import (
12
+	"crypto/tls"
13
+	"database/sql"
14
+	"database/sql/driver"
15
+	"encoding/binary"
16
+	"errors"
17
+	"fmt"
18
+	"io"
19
+	"strconv"
20
+	"strings"
21
+	"sync"
22
+	"sync/atomic"
23
+	"time"
24
+)
25
+
26
+// Registry for custom tls.Configs
27
+var (
28
+	tlsConfigLock     sync.RWMutex
29
+	tlsConfigRegistry map[string]*tls.Config
30
+)
31
+
32
+// RegisterTLSConfig registers a custom tls.Config to be used with sql.Open.
33
+// Use the key as a value in the DSN where tls=value.
34
+//
35
+// Note: The provided tls.Config is exclusively owned by the driver after
36
+// registering it.
37
+//
38
+//  rootCertPool := x509.NewCertPool()
39
+//  pem, err := ioutil.ReadFile("/path/ca-cert.pem")
40
+//  if err != nil {
41
+//      log.Fatal(err)
42
+//  }
43
+//  if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
44
+//      log.Fatal("Failed to append PEM.")
45
+//  }
46
+//  clientCert := make([]tls.Certificate, 0, 1)
47
+//  certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
48
+//  if err != nil {
49
+//      log.Fatal(err)
50
+//  }
51
+//  clientCert = append(clientCert, certs)
52
+//  mysql.RegisterTLSConfig("custom", &tls.Config{
53
+//      RootCAs: rootCertPool,
54
+//      Certificates: clientCert,
55
+//  })
56
+//  db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
57
+//
58
+func RegisterTLSConfig(key string, config *tls.Config) error {
59
+	if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" || strings.ToLower(key) == "preferred" {
60
+		return fmt.Errorf("key '%s' is reserved", key)
61
+	}
62
+
63
+	tlsConfigLock.Lock()
64
+	if tlsConfigRegistry == nil {
65
+		tlsConfigRegistry = make(map[string]*tls.Config)
66
+	}
67
+
68
+	tlsConfigRegistry[key] = config
69
+	tlsConfigLock.Unlock()
70
+	return nil
71
+}
72
+
73
+// DeregisterTLSConfig removes the tls.Config associated with key.
74
+func DeregisterTLSConfig(key string) {
75
+	tlsConfigLock.Lock()
76
+	if tlsConfigRegistry != nil {
77
+		delete(tlsConfigRegistry, key)
78
+	}
79
+	tlsConfigLock.Unlock()
80
+}
81
+
82
+func getTLSConfigClone(key string) (config *tls.Config) {
83
+	tlsConfigLock.RLock()
84
+	if v, ok := tlsConfigRegistry[key]; ok {
85
+		config = v.Clone()
86
+	}
87
+	tlsConfigLock.RUnlock()
88
+	return
89
+}
90
+
91
+// Returns the bool value of the input.
92
+// The 2nd return value indicates if the input was a valid bool value
93
+func readBool(input string) (value bool, valid bool) {
94
+	switch input {
95
+	case "1", "true", "TRUE", "True":
96
+		return true, true
97
+	case "0", "false", "FALSE", "False":
98
+		return false, true
99
+	}
100
+
101
+	// Not a valid bool value
102
+	return
103
+}
104
+
105
+/******************************************************************************
106
+*                           Time related utils                                *
107
+******************************************************************************/
108
+
109
+func parseDateTime(str string, loc *time.Location) (t time.Time, err error) {
110
+	base := "0000-00-00 00:00:00.0000000"
111
+	switch len(str) {
112
+	case 10, 19, 21, 22, 23, 24, 25, 26: // up to "YYYY-MM-DD HH:MM:SS.MMMMMM"
113
+		if str == base[:len(str)] {
114
+			return
115
+		}
116
+		t, err = time.Parse(timeFormat[:len(str)], str)
117
+	default:
118
+		err = fmt.Errorf("invalid time string: %s", str)
119
+		return
120
+	}
121
+
122
+	// Adjust location
123
+	if err == nil && loc != time.UTC {
124
+		y, mo, d := t.Date()
125
+		h, mi, s := t.Clock()
126
+		t, err = time.Date(y, mo, d, h, mi, s, t.Nanosecond(), loc), nil
127
+	}
128
+
129
+	return
130
+}
131
+
132
+func parseBinaryDateTime(num uint64, data []byte, loc *time.Location) (driver.Value, error) {
133
+	switch num {
134
+	case 0:
135
+		return time.Time{}, nil
136
+	case 4:
137
+		return time.Date(
138
+			int(binary.LittleEndian.Uint16(data[:2])), // year
139
+			time.Month(data[2]),                       // month
140
+			int(data[3]),                              // day
141
+			0, 0, 0, 0,
142
+			loc,
143
+		), nil
144
+	case 7:
145
+		return time.Date(
146
+			int(binary.LittleEndian.Uint16(data[:2])), // year
147
+			time.Month(data[2]),                       // month
148
+			int(data[3]),                              // day
149
+			int(data[4]),                              // hour
150
+			int(data[5]),                              // minutes
151
+			int(data[6]),                              // seconds
152
+			0,
153
+			loc,
154
+		), nil
155
+	case 11:
156
+		return time.Date(
157
+			int(binary.LittleEndian.Uint16(data[:2])), // year
158
+			time.Month(data[2]),                       // month
159
+			int(data[3]),                              // day
160
+			int(data[4]),                              // hour
161
+			int(data[5]),                              // minutes
162
+			int(data[6]),                              // seconds
163
+			int(binary.LittleEndian.Uint32(data[7:11]))*1000, // nanoseconds
164
+			loc,
165
+		), nil
166
+	}
167
+	return nil, fmt.Errorf("invalid DATETIME packet length %d", num)
168
+}
169
+
170
+// zeroDateTime is used in formatBinaryDateTime to avoid an allocation
171
+// if the DATE or DATETIME has the zero value.
172
+// It must never be changed.
173
+// The current behavior depends on database/sql copying the result.
174
+var zeroDateTime = []byte("0000-00-00 00:00:00.000000")
175
+
176
+const digits01 = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
177
+const digits10 = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
178
+
179
+func appendMicrosecs(dst, src []byte, decimals int) []byte {
180
+	if decimals <= 0 {
181
+		return dst
182
+	}
183
+	if len(src) == 0 {
184
+		return append(dst, ".000000"[:decimals+1]...)
185
+	}
186
+
187
+	microsecs := binary.LittleEndian.Uint32(src[:4])
188
+	p1 := byte(microsecs / 10000)
189
+	microsecs -= 10000 * uint32(p1)
190
+	p2 := byte(microsecs / 100)
191
+	microsecs -= 100 * uint32(p2)
192
+	p3 := byte(microsecs)
193
+
194
+	switch decimals {
195
+	default:
196
+		return append(dst, '.',
197
+			digits10[p1], digits01[p1],
198
+			digits10[p2], digits01[p2],
199
+			digits10[p3], digits01[p3],
200
+		)
201
+	case 1:
202
+		return append(dst, '.',
203
+			digits10[p1],
204
+		)
205
+	case 2:
206
+		return append(dst, '.',
207
+			digits10[p1], digits01[p1],
208
+		)
209
+	case 3:
210
+		return append(dst, '.',
211
+			digits10[p1], digits01[p1],
212
+			digits10[p2],
213
+		)
214
+	case 4:
215
+		return append(dst, '.',
216
+			digits10[p1], digits01[p1],
217
+			digits10[p2], digits01[p2],
218
+		)
219
+	case 5:
220
+		return append(dst, '.',
221
+			digits10[p1], digits01[p1],
222
+			digits10[p2], digits01[p2],
223
+			digits10[p3],
224
+		)
225
+	}
226
+}
227
+
228
+func formatBinaryDateTime(src []byte, length uint8) (driver.Value, error) {
229
+	// length expects the deterministic length of the zero value,
230
+	// negative time and 100+ hours are automatically added if needed
231
+	if len(src) == 0 {
232
+		return zeroDateTime[:length], nil
233
+	}
234
+	var dst []byte      // return value
235
+	var p1, p2, p3 byte // current digit pair
236
+
237
+	switch length {
238
+	case 10, 19, 21, 22, 23, 24, 25, 26:
239
+	default:
240
+		t := "DATE"
241
+		if length > 10 {
242
+			t += "TIME"
243
+		}
244
+		return nil, fmt.Errorf("illegal %s length %d", t, length)
245
+	}
246
+	switch len(src) {
247
+	case 4, 7, 11:
248
+	default:
249
+		t := "DATE"
250
+		if length > 10 {
251
+			t += "TIME"
252
+		}
253
+		return nil, fmt.Errorf("illegal %s packet length %d", t, len(src))
254
+	}
255
+	dst = make([]byte, 0, length)
256
+	// start with the date
257
+	year := binary.LittleEndian.Uint16(src[:2])
258
+	pt := year / 100
259
+	p1 = byte(year - 100*uint16(pt))
260
+	p2, p3 = src[2], src[3]
261
+	dst = append(dst,
262
+		digits10[pt], digits01[pt],
263
+		digits10[p1], digits01[p1], '-',
264
+		digits10[p2], digits01[p2], '-',
265
+		digits10[p3], digits01[p3],
266
+	)
267
+	if length == 10 {
268
+		return dst, nil
269
+	}
270
+	if len(src) == 4 {
271
+		return append(dst, zeroDateTime[10:length]...), nil
272
+	}
273
+	dst = append(dst, ' ')
274
+	p1 = src[4] // hour
275
+	src = src[5:]
276
+
277
+	// p1 is 2-digit hour, src is after hour
278
+	p2, p3 = src[0], src[1]
279
+	dst = append(dst,
280
+		digits10[p1], digits01[p1], ':',
281
+		digits10[p2], digits01[p2], ':',
282
+		digits10[p3], digits01[p3],
283
+	)
284
+	return appendMicrosecs(dst, src[2:], int(length)-20), nil
285
+}
286
+
287
+func formatBinaryTime(src []byte, length uint8) (driver.Value, error) {
288
+	// length expects the deterministic length of the zero value,
289
+	// negative time and 100+ hours are automatically added if needed
290
+	if len(src) == 0 {
291
+		return zeroDateTime[11 : 11+length], nil
292
+	}
293
+	var dst []byte // return value
294
+
295
+	switch length {
296
+	case
297
+		8,                      // time (can be up to 10 when negative and 100+ hours)
298
+		10, 11, 12, 13, 14, 15: // time with fractional seconds
299
+	default:
300
+		return nil, fmt.Errorf("illegal TIME length %d", length)
301
+	}
302
+	switch len(src) {
303
+	case 8, 12:
304
+	default:
305
+		return nil, fmt.Errorf("invalid TIME packet length %d", len(src))
306
+	}
307
+	// +2 to enable negative time and 100+ hours
308
+	dst = make([]byte, 0, length+2)
309
+	if src[0] == 1 {
310
+		dst = append(dst, '-')
311
+	}
312
+	days := binary.LittleEndian.Uint32(src[1:5])
313
+	hours := int64(days)*24 + int64(src[5])
314
+
315
+	if hours >= 100 {
316
+		dst = strconv.AppendInt(dst, hours, 10)
317
+	} else {
318
+		dst = append(dst, digits10[hours], digits01[hours])
319
+	}
320
+
321
+	min, sec := src[6], src[7]
322
+	dst = append(dst, ':',
323
+		digits10[min], digits01[min], ':',
324
+		digits10[sec], digits01[sec],
325
+	)
326
+	return appendMicrosecs(dst, src[8:], int(length)-9), nil
327
+}
328
+
329
+/******************************************************************************
330
+*                       Convert from and to bytes                             *
331
+******************************************************************************/
332
+
333
+func uint64ToBytes(n uint64) []byte {
334
+	return []byte{
335
+		byte(n),
336
+		byte(n >> 8),
337
+		byte(n >> 16),
338
+		byte(n >> 24),
339
+		byte(n >> 32),
340
+		byte(n >> 40),
341
+		byte(n >> 48),
342
+		byte(n >> 56),
343
+	}
344
+}
345
+
346
+func uint64ToString(n uint64) []byte {
347
+	var a [20]byte
348
+	i := 20
349
+
350
+	// U+0030 = 0
351
+	// ...
352
+	// U+0039 = 9
353
+
354
+	var q uint64
355
+	for n >= 10 {
356
+		i--
357
+		q = n / 10
358
+		a[i] = uint8(n-q*10) + 0x30
359
+		n = q
360
+	}
361
+
362
+	i--
363
+	a[i] = uint8(n) + 0x30
364
+
365
+	return a[i:]
366
+}
367
+
368
+// treats string value as unsigned integer representation
369
+func stringToInt(b []byte) int {
370
+	val := 0
371
+	for i := range b {
372
+		val *= 10
373
+		val += int(b[i] - 0x30)
374
+	}
375
+	return val
376
+}
377
+
378
+// returns the string read as a bytes slice, wheter the value is NULL,
379
+// the number of bytes read and an error, in case the string is longer than
380
+// the input slice
381
+func readLengthEncodedString(b []byte) ([]byte, bool, int, error) {
382
+	// Get length
383
+	num, isNull, n := readLengthEncodedInteger(b)
384
+	if num < 1 {
385
+		return b[n:n], isNull, n, nil
386
+	}
387
+
388
+	n += int(num)
389
+
390
+	// Check data length
391
+	if len(b) >= n {
392
+		return b[n-int(num) : n : n], false, n, nil
393
+	}
394
+	return nil, false, n, io.EOF
395
+}
396
+
397
+// returns the number of bytes skipped and an error, in case the string is
398
+// longer than the input slice
399
+func skipLengthEncodedString(b []byte) (int, error) {
400
+	// Get length
401
+	num, _, n := readLengthEncodedInteger(b)
402
+	if num < 1 {
403
+		return n, nil
404
+	}
405
+
406
+	n += int(num)
407
+
408
+	// Check data length
409
+	if len(b) >= n {
410
+		return n, nil
411
+	}
412
+	return n, io.EOF
413
+}
414
+
415
+// returns the number read, whether the value is NULL and the number of bytes read
416
+func readLengthEncodedInteger(b []byte) (uint64, bool, int) {
417
+	// See issue #349
418
+	if len(b) == 0 {
419
+		return 0, true, 1
420
+	}
421
+
422
+	switch b[0] {
423
+	// 251: NULL
424
+	case 0xfb:
425
+		return 0, true, 1
426
+
427
+	// 252: value of following 2
428
+	case 0xfc:
429
+		return uint64(b[1]) | uint64(b[2])<<8, false, 3
430
+
431
+	// 253: value of following 3
432
+	case 0xfd:
433
+		return uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16, false, 4
434
+
435
+	// 254: value of following 8
436
+	case 0xfe:
437
+		return uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16 |
438
+				uint64(b[4])<<24 | uint64(b[5])<<32 | uint64(b[6])<<40 |
439
+				uint64(b[7])<<48 | uint64(b[8])<<56,
440
+			false, 9
441
+	}
442
+
443
+	// 0-250: value of first byte
444
+	return uint64(b[0]), false, 1
445
+}
446
+
447
+// encodes a uint64 value and appends it to the given bytes slice
448
+func appendLengthEncodedInteger(b []byte, n uint64) []byte {
449
+	switch {
450
+	case n <= 250:
451
+		return append(b, byte(n))
452
+
453
+	case n <= 0xffff:
454
+		return append(b, 0xfc, byte(n), byte(n>>8))
455
+
456
+	case n <= 0xffffff:
457
+		return append(b, 0xfd, byte(n), byte(n>>8), byte(n>>16))
458
+	}
459
+	return append(b, 0xfe, byte(n), byte(n>>8), byte(n>>16), byte(n>>24),
460
+		byte(n>>32), byte(n>>40), byte(n>>48), byte(n>>56))
461
+}
462
+
463
+// reserveBuffer checks cap(buf) and expand buffer to len(buf) + appendSize.
464
+// If cap(buf) is not enough, reallocate new buffer.
465
+func reserveBuffer(buf []byte, appendSize int) []byte {
466
+	newSize := len(buf) + appendSize
467
+	if cap(buf) < newSize {
468
+		// Grow buffer exponentially
469
+		newBuf := make([]byte, len(buf)*2+appendSize)
470
+		copy(newBuf, buf)
471
+		buf = newBuf
472
+	}
473
+	return buf[:newSize]
474
+}
475
+
476
+// escapeBytesBackslash escapes []byte with backslashes (\)
477
+// This escapes the contents of a string (provided as []byte) by adding backslashes before special
478
+// characters, and turning others into specific escape sequences, such as
479
+// turning newlines into \n and null bytes into \0.
480
+// https://github.com/mysql/mysql-server/blob/mysql-5.7.5/mysys/charset.c#L823-L932
481
+func escapeBytesBackslash(buf, v []byte) []byte {
482
+	pos := len(buf)
483
+	buf = reserveBuffer(buf, len(v)*2)
484
+
485
+	for _, c := range v {
486
+		switch c {
487
+		case '\x00':
488
+			buf[pos] = '\\'
489
+			buf[pos+1] = '0'
490
+			pos += 2
491
+		case '\n':
492
+			buf[pos] = '\\'
493
+			buf[pos+1] = 'n'
494
+			pos += 2
495
+		case '\r':
496
+			buf[pos] = '\\'
497
+			buf[pos+1] = 'r'
498
+			pos += 2
499
+		case '\x1a':
500
+			buf[pos] = '\\'
501
+			buf[pos+1] = 'Z'
502
+			pos += 2
503
+		case '\'':
504
+			buf[pos] = '\\'
505
+			buf[pos+1] = '\''
506
+			pos += 2
507
+		case '"':
508
+			buf[pos] = '\\'
509
+			buf[pos+1] = '"'
510
+			pos += 2
511
+		case '\\':
512
+			buf[pos] = '\\'
513
+			buf[pos+1] = '\\'
514
+			pos += 2
515
+		default:
516
+			buf[pos] = c
517
+			pos++
518
+		}
519
+	}
520
+
521
+	return buf[:pos]
522
+}
523
+
524
+// escapeStringBackslash is similar to escapeBytesBackslash but for string.
525
+func escapeStringBackslash(buf []byte, v string) []byte {
526
+	pos := len(buf)
527
+	buf = reserveBuffer(buf, len(v)*2)
528
+
529
+	for i := 0; i < len(v); i++ {
530
+		c := v[i]
531
+		switch c {
532
+		case '\x00':
533
+			buf[pos] = '\\'
534
+			buf[pos+1] = '0'
535
+			pos += 2
536
+		case '\n':
537
+			buf[pos] = '\\'
538
+			buf[pos+1] = 'n'
539
+			pos += 2
540
+		case '\r':
541
+			buf[pos] = '\\'
542
+			buf[pos+1] = 'r'
543
+			pos += 2
544
+		case '\x1a':
545
+			buf[pos] = '\\'
546
+			buf[pos+1] = 'Z'
547
+			pos += 2
548
+		case '\'':
549
+			buf[pos] = '\\'
550
+			buf[pos+1] = '\''
551
+			pos += 2
552
+		case '"':
553
+			buf[pos] = '\\'
554
+			buf[pos+1] = '"'
555
+			pos += 2
556
+		case '\\':
557
+			buf[pos] = '\\'
558
+			buf[pos+1] = '\\'
559
+			pos += 2
560
+		default:
561
+			buf[pos] = c
562
+			pos++
563
+		}
564
+	}
565
+
566
+	return buf[:pos]
567
+}
568
+
569
+// escapeBytesQuotes escapes apostrophes in []byte by doubling them up.
570
+// This escapes the contents of a string by doubling up any apostrophes that
571
+// it contains. This is used when the NO_BACKSLASH_ESCAPES SQL_MODE is in
572
+// effect on the server.
573
+// https://github.com/mysql/mysql-server/blob/mysql-5.7.5/mysys/charset.c#L963-L1038
574
+func escapeBytesQuotes(buf, v []byte) []byte {
575
+	pos := len(buf)
576
+	buf = reserveBuffer(buf, len(v)*2)
577
+
578
+	for _, c := range v {
579
+		if c == '\'' {
580
+			buf[pos] = '\''
581
+			buf[pos+1] = '\''
582
+			pos += 2
583
+		} else {
584
+			buf[pos] = c
585
+			pos++
586
+		}
587
+	}
588
+
589
+	return buf[:pos]
590
+}
591
+
592
+// escapeStringQuotes is similar to escapeBytesQuotes but for string.
593
+func escapeStringQuotes(buf []byte, v string) []byte {
594
+	pos := len(buf)
595
+	buf = reserveBuffer(buf, len(v)*2)
596
+
597
+	for i := 0; i < len(v); i++ {
598
+		c := v[i]
599
+		if c == '\'' {
600
+			buf[pos] = '\''
601
+			buf[pos+1] = '\''
602
+			pos += 2
603
+		} else {
604
+			buf[pos] = c
605
+			pos++
606
+		}
607
+	}
608
+
609
+	return buf[:pos]
610
+}
611
+
612
+/******************************************************************************
613
+*                               Sync utils                                    *
614
+******************************************************************************/
615
+
616
+// noCopy may be embedded into structs which must not be copied
617
+// after the first use.
618
+//
619
+// See https://github.com/golang/go/issues/8005#issuecomment-190753527
620
+// for details.
621
+type noCopy struct{}
622
+
623
+// Lock is a no-op used by -copylocks checker from `go vet`.
624
+func (*noCopy) Lock() {}
625
+
626
+// atomicBool is a wrapper around uint32 for usage as a boolean value with
627
+// atomic access.
628
+type atomicBool struct {
629
+	_noCopy noCopy
630
+	value   uint32
631
+}
632
+
633
+// IsSet returns whether the current boolean value is true
634
+func (ab *atomicBool) IsSet() bool {
635
+	return atomic.LoadUint32(&ab.value) > 0
636
+}
637
+
638
+// Set sets the value of the bool regardless of the previous value
639
+func (ab *atomicBool) Set(value bool) {
640
+	if value {
641
+		atomic.StoreUint32(&ab.value, 1)
642
+	} else {
643
+		atomic.StoreUint32(&ab.value, 0)
644
+	}
645
+}
646
+
647
+// TrySet sets the value of the bool and returns whether the value changed
648
+func (ab *atomicBool) TrySet(value bool) bool {
649
+	if value {
650
+		return atomic.SwapUint32(&ab.value, 1) == 0
651
+	}
652
+	return atomic.SwapUint32(&ab.value, 0) > 0
653
+}
654
+
655
+// atomicError is a wrapper for atomically accessed error values
656
+type atomicError struct {
657
+	_noCopy noCopy
658
+	value   atomic.Value
659
+}
660
+
661
+// Set sets the error value regardless of the previous value.
662
+// The value must not be nil
663
+func (ae *atomicError) Set(value error) {
664
+	ae.value.Store(value)
665
+}
666
+
667
+// Value returns the current error value
668
+func (ae *atomicError) Value() error {
669
+	if v := ae.value.Load(); v != nil {
670
+		// this will panic if the value doesn't implement the error interface
671
+		return v.(error)
672
+	}
673
+	return nil
674
+}
675
+
676
+func namedValueToValue(named []driver.NamedValue) ([]driver.Value, error) {
677
+	dargs := make([]driver.Value, len(named))
678
+	for n, param := range named {
679
+		if len(param.Name) > 0 {
680
+			// TODO: support the use of Named Parameters #561
681
+			return nil, errors.New("mysql: driver does not support the use of Named Parameters")
682
+		}
683
+		dargs[n] = param.Value
684
+	}
685
+	return dargs, nil
686
+}
687
+
688
+func mapIsolationLevel(level driver.IsolationLevel) (string, error) {
689
+	switch sql.IsolationLevel(level) {
690
+	case sql.LevelRepeatableRead:
691
+		return "REPEATABLE READ", nil
692
+	case sql.LevelReadCommitted:
693
+		return "READ COMMITTED", nil
694
+	case sql.LevelReadUncommitted:
695
+		return "READ UNCOMMITTED", nil
696
+	case sql.LevelSerializable:
697
+		return "SERIALIZABLE", nil
698
+	default:
699
+		return "", fmt.Errorf("mysql: unsupported isolation level: %v", level)
700
+	}
701
+}

+ 1
- 0
vendor/golang.org/x/sys/unix/mkerrors.sh View File

@@ -44,6 +44,7 @@ includes_AIX='
44 44
 #include <sys/stropts.h>
45 45
 #include <sys/mman.h>
46 46
 #include <sys/poll.h>
47
+#include <sys/select.h>
47 48
 #include <sys/termio.h>
48 49
 #include <termios.h>
49 50
 #include <fcntl.h>

+ 11
- 1
vendor/golang.org/x/sys/unix/zerrors_aix_ppc.go View File

@@ -459,6 +459,15 @@ const (
459 459
 	MAP_SHARED                    = 0x1
460 460
 	MAP_TYPE                      = 0xf0
461 461
 	MAP_VARIABLE                  = 0x0
462
+	MCAST_BLOCK_SOURCE            = 0x40
463
+	MCAST_EXCLUDE                 = 0x2
464
+	MCAST_INCLUDE                 = 0x1
465
+	MCAST_JOIN_GROUP              = 0x3e
466
+	MCAST_JOIN_SOURCE_GROUP       = 0x42
467
+	MCAST_LEAVE_GROUP             = 0x3f
468
+	MCAST_LEAVE_SOURCE_GROUP      = 0x43
469
+	MCAST_SOURCE_FILTER           = 0x49
470
+	MCAST_UNBLOCK_SOURCE          = 0x41
462 471
 	MCL_CURRENT                   = 0x100
463 472
 	MCL_FUTURE                    = 0x200
464 473
 	MSG_ANY                       = 0x4
@@ -483,6 +492,7 @@ const (
483 492
 	MS_INVALIDATE                 = 0x40
484 493
 	MS_PER_SEC                    = 0x3e8
485 494
 	MS_SYNC                       = 0x20
495
+	NFDBITS                       = 0x20
486 496
 	NL0                           = 0x0
487 497
 	NL1                           = 0x4000
488 498
 	NL2                           = 0x8000
@@ -688,7 +698,7 @@ const (
688 698
 	SIOCGHIWAT                    = 0x40047301
689 699
 	SIOCGIFADDR                   = -0x3fd796df
690 700
 	SIOCGIFADDRS                  = 0x2000698c
691
-	SIOCGIFBAUDRATE               = -0x3fd79693
701
+	SIOCGIFBAUDRATE               = -0x3fdf9669
692 702
 	SIOCGIFBRDADDR                = -0x3fd796dd
693 703
 	SIOCGIFCONF                   = -0x3ff796bb
694 704
 	SIOCGIFCONFGLOB               = -0x3ff79670

+ 11
- 1
vendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go View File

@@ -459,6 +459,15 @@ const (
459 459
 	MAP_SHARED                    = 0x1
460 460
 	MAP_TYPE                      = 0xf0
461 461
 	MAP_VARIABLE                  = 0x0
462
+	MCAST_BLOCK_SOURCE            = 0x40
463
+	MCAST_EXCLUDE                 = 0x2
464
+	MCAST_INCLUDE                 = 0x1
465
+	MCAST_JOIN_GROUP              = 0x3e
466
+	MCAST_JOIN_SOURCE_GROUP       = 0x42
467
+	MCAST_LEAVE_GROUP             = 0x3f
468
+	MCAST_LEAVE_SOURCE_GROUP      = 0x43
469
+	MCAST_SOURCE_FILTER           = 0x49
470
+	MCAST_UNBLOCK_SOURCE          = 0x41
462 471
 	MCL_CURRENT                   = 0x100
463 472
 	MCL_FUTURE                    = 0x200
464 473
 	MSG_ANY                       = 0x4
@@ -483,6 +492,7 @@ const (
483 492
 	MS_INVALIDATE                 = 0x40
484 493
 	MS_PER_SEC                    = 0x3e8
485 494
 	MS_SYNC                       = 0x20
495
+	NFDBITS                       = 0x40
486 496
 	NL0                           = 0x0
487 497
 	NL1                           = 0x4000
488 498
 	NL2                           = 0x8000
@@ -688,7 +698,7 @@ const (
688 698
 	SIOCGHIWAT                    = 0x40047301
689 699
 	SIOCGIFADDR                   = -0x3fd796df
690 700
 	SIOCGIFADDRS                  = 0x2000698c
691
-	SIOCGIFBAUDRATE               = -0x3fd79693
701
+	SIOCGIFBAUDRATE               = -0x3fdf9669
692 702
 	SIOCGIFBRDADDR                = -0x3fd796dd
693 703
 	SIOCGIFCONF                   = -0x3fef96bb
694 704
 	SIOCGIFCONFGLOB               = -0x3fef9670

+ 1
- 3
vendor/golang.org/x/sys/windows/security_windows.go View File

@@ -229,15 +229,13 @@ func LookupSID(system, account string) (sid *SID, domain string, accType uint32,
229 229
 
230 230
 // String converts SID to a string format suitable for display, storage, or transmission.
231 231
 func (sid *SID) String() string {
232
-	// From https://docs.microsoft.com/en-us/windows/win32/secbiomet/general-constants
233
-	const SecurityMaxSidSize = 68
234 232
 	var s *uint16
235 233
 	e := ConvertSidToStringSid(sid, &s)
236 234
 	if e != nil {
237 235
 		return ""
238 236
 	}
239 237
 	defer LocalFree((Handle)(unsafe.Pointer(s)))
240
-	return UTF16ToString((*[SecurityMaxSidSize]uint16)(unsafe.Pointer(s))[:])
238
+	return UTF16ToString((*[256]uint16)(unsafe.Pointer(s))[:])
241 239
 }
242 240
 
243 241
 // Len returns the length, in bytes, of a valid security identifier SID.

+ 55
- 0
vendor/golang.org/x/sys/windows/syscall_windows.go View File

@@ -313,6 +313,10 @@ func NewCallbackCDecl(fn interface{}) uintptr {
313 313
 //sys	CoTaskMemFree(address unsafe.Pointer) = ole32.CoTaskMemFree
314 314
 //sys	rtlGetVersion(info *OsVersionInfoEx) (ret error) = ntdll.RtlGetVersion
315 315
 //sys	rtlGetNtVersionNumbers(majorVersion *uint32, minorVersion *uint32, buildNumber *uint32) = ntdll.RtlGetNtVersionNumbers
316
+//sys	getProcessPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) = kernel32.GetProcessPreferredUILanguages
317
+//sys	getThreadPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) = kernel32.GetThreadPreferredUILanguages
318
+//sys	getUserPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) = kernel32.GetUserPreferredUILanguages
319
+//sys	getSystemPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) = kernel32.GetSystemPreferredUILanguages
316 320
 
317 321
 // Process Status API (PSAPI)
318 322
 //sys	EnumProcesses(processIds []uint32, bytesReturned *uint32) (err error) = psapi.EnumProcesses
@@ -1378,3 +1382,54 @@ func RtlGetNtVersionNumbers() (majorVersion, minorVersion, buildNumber uint32) {
1378 1382
 	buildNumber &= 0xffff
1379 1383
 	return
1380 1384
 }
1385
+
1386
+// GetProcessPreferredUILanguages retrieves the process preferred UI languages.
1387
+func GetProcessPreferredUILanguages(flags uint32) ([]string, error) {
1388
+	return getUILanguages(flags, getProcessPreferredUILanguages)
1389
+}
1390
+
1391
+// GetThreadPreferredUILanguages retrieves the thread preferred UI languages for the current thread.
1392
+func GetThreadPreferredUILanguages(flags uint32) ([]string, error) {
1393
+	return getUILanguages(flags, getThreadPreferredUILanguages)
1394
+}
1395
+
1396
+// GetUserPreferredUILanguages retrieves information about the user preferred UI languages.
1397
+func GetUserPreferredUILanguages(flags uint32) ([]string, error) {
1398
+	return getUILanguages(flags, getUserPreferredUILanguages)
1399
+}
1400
+
1401
+// GetSystemPreferredUILanguages retrieves the system preferred UI languages.
1402
+func GetSystemPreferredUILanguages(flags uint32) ([]string, error) {
1403
+	return getUILanguages(flags, getSystemPreferredUILanguages)
1404
+}
1405
+
1406
+func getUILanguages(flags uint32, f func(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) error) ([]string, error) {
1407
+	size := uint32(128)
1408
+	for {
1409
+		var numLanguages uint32
1410
+		buf := make([]uint16, size)
1411
+		err := f(flags, &numLanguages, &buf[0], &size)
1412
+		if err == ERROR_INSUFFICIENT_BUFFER {
1413
+			continue
1414
+		}
1415
+		if err != nil {
1416
+			return nil, err
1417
+		}
1418
+		buf = buf[:size]
1419
+		if numLanguages == 0 || len(buf) == 0 { // GetProcessPreferredUILanguages may return numLanguages==0 with "\0\0"
1420
+			return []string{}, nil
1421
+		}
1422
+		if buf[len(buf)-1] == 0 {
1423
+			buf = buf[:len(buf)-1] // remove terminating null
1424
+		}
1425
+		languages := make([]string, 0, numLanguages)
1426
+		from := 0
1427
+		for i, c := range buf {
1428
+			if c == 0 {
1429
+				languages = append(languages, string(utf16.Decode(buf[from:i])))
1430
+				from = i + 1
1431
+			}
1432
+		}
1433
+		return languages, nil
1434
+	}
1435
+}

+ 33
- 0
vendor/golang.org/x/sys/windows/types_windows.go View File

@@ -1742,3 +1742,36 @@ const (
1742 1742
 	GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT = 2
1743 1743
 	GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS       = 4
1744 1744
 )
1745
+
1746
+// MUI function flag values
1747
+const (
1748
+	MUI_LANGUAGE_ID                    = 0x4
1749
+	MUI_LANGUAGE_NAME                  = 0x8
1750
+	MUI_MERGE_SYSTEM_FALLBACK          = 0x10
1751
+	MUI_MERGE_USER_FALLBACK            = 0x20
1752
+	MUI_UI_FALLBACK                    = MUI_MERGE_SYSTEM_FALLBACK | MUI_MERGE_USER_FALLBACK
1753
+	MUI_THREAD_LANGUAGES               = 0x40
1754
+	MUI_CONSOLE_FILTER                 = 0x100
1755
+	MUI_COMPLEX_SCRIPT_FILTER          = 0x200
1756
+	MUI_RESET_FILTERS                  = 0x001
1757
+	MUI_USER_PREFERRED_UI_LANGUAGES    = 0x10
1758
+	MUI_USE_INSTALLED_LANGUAGES        = 0x20
1759
+	MUI_USE_SEARCH_ALL_LANGUAGES       = 0x40
1760
+	MUI_LANG_NEUTRAL_PE_FILE           = 0x100
1761
+	MUI_NON_LANG_NEUTRAL_FILE          = 0x200
1762
+	MUI_MACHINE_LANGUAGE_SETTINGS      = 0x400
1763
+	MUI_FILETYPE_NOT_LANGUAGE_NEUTRAL  = 0x001
1764
+	MUI_FILETYPE_LANGUAGE_NEUTRAL_MAIN = 0x002
1765
+	MUI_FILETYPE_LANGUAGE_NEUTRAL_MUI  = 0x004
1766
+	MUI_QUERY_TYPE                     = 0x001
1767
+	MUI_QUERY_CHECKSUM                 = 0x002
1768
+	MUI_QUERY_LANGUAGE_NAME            = 0x004
1769
+	MUI_QUERY_RESOURCE_TYPES           = 0x008
1770
+	MUI_FILEINFO_VERSION               = 0x001
1771
+
1772
+	MUI_FULL_LANGUAGE      = 0x01
1773
+	MUI_PARTIAL_LANGUAGE   = 0x02
1774
+	MUI_LIP_LANGUAGE       = 0x04
1775
+	MUI_LANGUAGE_INSTALLED = 0x20
1776
+	MUI_LANGUAGE_LICENSED  = 0x40
1777
+)

+ 52
- 0
vendor/golang.org/x/sys/windows/zsyscall_windows.go View File

@@ -248,6 +248,10 @@ var (
248 248
 	procCoTaskMemFree                                        = modole32.NewProc("CoTaskMemFree")
249 249
 	procRtlGetVersion                                        = modntdll.NewProc("RtlGetVersion")
250 250
 	procRtlGetNtVersionNumbers                               = modntdll.NewProc("RtlGetNtVersionNumbers")
251
+	procGetProcessPreferredUILanguages                       = modkernel32.NewProc("GetProcessPreferredUILanguages")
252
+	procGetThreadPreferredUILanguages                        = modkernel32.NewProc("GetThreadPreferredUILanguages")
253
+	procGetUserPreferredUILanguages                          = modkernel32.NewProc("GetUserPreferredUILanguages")
254
+	procGetSystemPreferredUILanguages                        = modkernel32.NewProc("GetSystemPreferredUILanguages")
251 255
 	procEnumProcesses                                        = modpsapi.NewProc("EnumProcesses")
252 256
 	procWSAStartup                                           = modws2_32.NewProc("WSAStartup")
253 257
 	procWSACleanup                                           = modws2_32.NewProc("WSACleanup")
@@ -2760,6 +2764,54 @@ func rtlGetNtVersionNumbers(majorVersion *uint32, minorVersion *uint32, buildNum
2760 2764
 	return
2761 2765
 }
2762 2766
 
2767
+func getProcessPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) {
2768
+	r1, _, e1 := syscall.Syscall6(procGetProcessPreferredUILanguages.Addr(), 4, uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize)), 0, 0)
2769
+	if r1 == 0 {
2770
+		if e1 != 0 {
2771
+			err = errnoErr(e1)
2772
+		} else {
2773
+			err = syscall.EINVAL
2774
+		}
2775
+	}
2776
+	return
2777
+}
2778
+
2779
+func getThreadPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) {
2780
+	r1, _, e1 := syscall.Syscall6(procGetThreadPreferredUILanguages.Addr(), 4, uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize)), 0, 0)
2781
+	if r1 == 0 {
2782
+		if e1 != 0 {
2783
+			err = errnoErr(e1)
2784
+		} else {
2785
+			err = syscall.EINVAL
2786
+		}
2787
+	}
2788
+	return
2789
+}
2790
+
2791
+func getUserPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) {
2792
+	r1, _, e1 := syscall.Syscall6(procGetUserPreferredUILanguages.Addr(), 4, uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize)), 0, 0)
2793
+	if r1 == 0 {
2794
+		if e1 != 0 {
2795
+			err = errnoErr(e1)
2796
+		} else {
2797
+			err = syscall.EINVAL
2798
+		}
2799
+	}
2800
+	return
2801
+}
2802
+
2803
+func getSystemPreferredUILanguages(flags uint32, numLanguages *uint32, buf *uint16, bufSize *uint32) (err error) {
2804
+	r1, _, e1 := syscall.Syscall6(procGetSystemPreferredUILanguages.Addr(), 4, uintptr(flags), uintptr(unsafe.Pointer(numLanguages)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(bufSize)), 0, 0)
2805
+	if r1 == 0 {
2806
+		if e1 != 0 {
2807
+			err = errnoErr(e1)
2808
+		} else {
2809
+			err = syscall.EINVAL
2810
+		}
2811
+	}
2812
+	return
2813
+}
2814
+
2763 2815
 func EnumProcesses(processIds []uint32, bytesReturned *uint32) (err error) {
2764 2816
 	var _p0 *uint32
2765 2817
 	if len(processIds) > 0 {

+ 10
- 9
vendor/modules.txt View File

@@ -9,6 +9,9 @@ github.com/go-asn1-ber/asn1-ber
9 9
 # github.com/go-ldap/ldap/v3 v3.1.6
10 10
 ## explicit
11 11
 github.com/go-ldap/ldap/v3
12
+# github.com/go-sql-driver/mysql v1.5.0
13
+## explicit
14
+github.com/go-sql-driver/mysql
12 15
 # github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940
13 16
 ## explicit
14 17
 github.com/goshuirc/e-nfa
@@ -26,36 +29,35 @@ github.com/mattn/go-isatty
26 29
 # github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
27 30
 ## explicit
28 31
 github.com/mgutz/ansi
32
+# github.com/onsi/ginkgo v1.12.0
33
+## explicit
34
+# github.com/onsi/gomega v1.9.0
35
+## explicit
29 36
 # github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0
30 37
 ## explicit
31 38
 github.com/oragono/confusables
32 39
 # github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a
33 40
 ## explicit
34 41
 github.com/oragono/go-ident
35
-# github.com/tidwall/btree v0.0.0-20191029221954-400434d76274
42
+# github.com/stretchr/testify v1.4.0
36 43
 ## explicit
44
+# github.com/tidwall/btree v0.0.0-20191029221954-400434d76274
37 45
 github.com/tidwall/btree
38 46
 # github.com/tidwall/buntdb v1.1.2
39 47
 ## explicit
40 48
 github.com/tidwall/buntdb
41 49
 # github.com/tidwall/gjson v1.3.4
42
-## explicit
43 50
 github.com/tidwall/gjson
44 51
 # github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb
45
-## explicit
46 52
 github.com/tidwall/grect
47 53
 # github.com/tidwall/match v1.0.1
48
-## explicit
49 54
 github.com/tidwall/match
50 55
 # github.com/tidwall/pretty v1.0.0
51
-## explicit
52 56
 github.com/tidwall/pretty
53 57
 # github.com/tidwall/rtree v0.0.0-20180113144539-6cd427091e0e
54
-## explicit
55 58
 github.com/tidwall/rtree
56 59
 github.com/tidwall/rtree/base
57 60
 # github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563
58
-## explicit
59 61
 github.com/tidwall/tinyqueue
60 62
 # golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
61 63
 ## explicit
@@ -63,8 +65,7 @@ golang.org/x/crypto/bcrypt
63 65
 golang.org/x/crypto/blowfish
64 66
 golang.org/x/crypto/sha3
65 67
 golang.org/x/crypto/ssh/terminal
66
-# golang.org/x/sys v0.0.0-20191115151921-52ab43148777
67
-## explicit
68
+# golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e
68 69
 golang.org/x/sys/cpu
69 70
 golang.org/x/sys/unix
70 71
 golang.org/x/sys/windows

Loading…
Cancel
Save