Skip to content

Commit 0cdc5aa

Browse files
committed
merged current master and adapted connection
2 parents 7ad5f6e + 200c80b commit 0cdc5aa

12 files changed

+686
-68
lines changed

Diff for: .travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
sudo: false
12
language: go
23
go:
3-
- 1.1
44
- 1.2
55
- 1.3
6+
- 1.4
67
- tip
78

89
before_script:

Diff for: AUTHORS

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Aaron Hopkins <go-sql-driver at die.net>
1515
Arne Hormann <arnehormann at gmail.com>
1616
Carlos Nieto <jose.carlos at menteslibres.net>
17+
Chris Moos <chris at tech9computers.com>
1718
DisposaBoy <disposaboy at dby.me>
1819
Frederick Mayle <frederickmayle at gmail.com>
1920
Gustavo Kristic <gkristic at gmail.com>
@@ -23,11 +24,13 @@ INADA Naoki <songofacandy at gmail.com>
2324
James Harr <james.harr at gmail.com>
2425
Jian Zhen <zhenjl at gmail.com>
2526
Julien Schmidt <go-sql-driver at julienschmidt.com>
27+
Kamil Dziedzic <kamil at klecza.pl>
2628
Leonardo YongUk Kim <dalinaum at gmail.com>
2729
Lucas Liu <extrafliu at gmail.com>
2830
Luke Scott <luke at webconnex.com>
2931
Michael Woolnough <michael.woolnough at gmail.com>
3032
Nicola Peduzzi <thenikso at gmail.com>
33+
Runrioter Wung <runrioter at gmail.com>
3134
Xiaobing Jiang <s7v7nislands at gmail.com>
3235
Xiuming Chen <cc at cxm.cc>
3336

Diff for: README.md

+28
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,34 @@ Default: false
166166

167167
`clientFoundRows=true` causes an UPDATE to return the number of matching rows instead of the number of rows changed.
168168

169+
##### `columnsWithAlias`
170+
171+
```
172+
Type: bool
173+
Valid Values: true, false
174+
Default: false
175+
```
176+
177+
When `columnsWithAlias` is true, calls to `sql.Rows.Columns()` will return the table alias and the column name separated by a dot. For example:
178+
179+
```
180+
SELECT u.id FROM users as u
181+
```
182+
183+
will return `u.id` instead of just `id` if `columnsWithAlias=true`.
184+
185+
##### `interpolateParams`
186+
187+
```
188+
Type: bool
189+
Valid Values: true, false
190+
Default: false
191+
```
192+
193+
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`.
194+
195+
NOTE: *This may introduce a SQL injection vulnerability when connection encoding is multibyte encoding except for UTF-8 (e.g. CP932)!*
196+
(See http://stackoverflow.com/a/12118602/3430118)
169197

170198
##### `loc`
171199

Diff for: benchmark_test.go

+38-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ package mysql
1111
import (
1212
"bytes"
1313
"database/sql"
14+
"database/sql/driver"
15+
"math"
1416
"strings"
1517
"sync"
1618
"sync/atomic"
1719
"testing"
20+
"time"
1821
)
1922

2023
type TB testing.B
@@ -45,7 +48,11 @@ func initDB(b *testing.B, queries ...string) *sql.DB {
4548
db := tb.checkDB(sql.Open("mysql", dsn))
4649
for _, query := range queries {
4750
if _, err := db.Exec(query); err != nil {
48-
b.Fatalf("Error on %q: %v", query, err)
51+
if w, ok := err.(MySQLWarnings); ok {
52+
b.Logf("Warning on %q: %v", query, w)
53+
} else {
54+
b.Fatalf("Error on %q: %v", query, err)
55+
}
4956
}
5057
}
5158
return db
@@ -206,3 +213,33 @@ func BenchmarkRoundtripBin(b *testing.B) {
206213
rows.Close()
207214
}
208215
}
216+
217+
func BenchmarkInterpolation(b *testing.B) {
218+
mc := &mysqlConn{
219+
cfg: &config{
220+
interpolateParams: true,
221+
loc: time.UTC,
222+
},
223+
maxPacketAllowed: maxPacketSize,
224+
maxWriteSize: maxPacketSize - 1,
225+
}
226+
227+
args := []driver.Value{
228+
int64(42424242),
229+
float64(math.Pi),
230+
false,
231+
time.Unix(1423411542, 807015000),
232+
[]byte("bytes containing special chars ' \" \a \x00"),
233+
"string containing special chars ' \" \a \x00",
234+
}
235+
q := "SELECT ?, ?, ?, ?, ?, ?"
236+
237+
b.ReportAllocs()
238+
b.ResetTimer()
239+
for i := 0; i < b.N; i++ {
240+
_, err := mc.interpolateParams(q, args)
241+
if err != nil {
242+
b.Fatal(err)
243+
}
244+
}
245+
}

Diff for: collations.go

+14
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,17 @@ var collations = map[string]byte{
234234
"utf8mb4_unicode_520_ci": 246,
235235
"utf8mb4_vietnamese_ci": 247,
236236
}
237+
238+
// A blacklist of collations which is unsafe to interpolate parameters.
239+
// These multibyte encodings may contains 0x5c (`\`) in their trailing bytes.
240+
var unsafeCollations = map[byte]bool{
241+
1: true, // big5_chinese_ci
242+
13: true, // sjis_japanese_ci
243+
28: true, // gbk_chinese_ci
244+
84: true, // big5_bin
245+
86: true, // gb2312_bin
246+
87: true, // gbk_bin
247+
88: true, // sjis_bin
248+
95: true, // cp932_japanese_ci
249+
96: true, // cp932_bin
250+
}

0 commit comments

Comments
 (0)