Skip to content

Commit 7fcf04e

Browse files
methanejulienschmidt
authored andcommitted
Add test to reproduce #467
1 parent 127a48c commit 7fcf04e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

connection_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
"testing"
14+
)
15+
16+
func TestInterpolateParams(t *testing.T) {
17+
mc := &mysqlConn{
18+
buf: newBuffer(nil),
19+
maxPacketAllowed: maxPacketSize,
20+
cfg: &Config{
21+
InterpolateParams: true,
22+
},
23+
}
24+
25+
q, err := mc.interpolateParams("SELECT ?+?", []driver.Value{int64(42), "gopher"})
26+
if err != nil {
27+
t.Errorf("Expected err=nil, got %#v", err)
28+
return
29+
}
30+
expected := `SELECT 42+'gopher'`
31+
if q != expected {
32+
t.Errorf("Expected: %q\nGot: %q", expected, q)
33+
}
34+
}
35+
36+
func TestInterpolateParamsTooManyPlaceholders(t *testing.T) {
37+
mc := &mysqlConn{
38+
buf: newBuffer(nil),
39+
maxPacketAllowed: maxPacketSize,
40+
cfg: &Config{
41+
InterpolateParams: true,
42+
},
43+
}
44+
45+
q, err := mc.interpolateParams("SELECT ?+?", []driver.Value{int64(42)})
46+
if err != driver.ErrSkip {
47+
t.Errorf("Expected err=driver.ErrSkip, got err=%#v, q=%#v", err, q)
48+
}
49+
}

0 commit comments

Comments
 (0)