Skip to content

Commit 82e447e

Browse files
methanejulienschmidt
authored andcommitted
fixup
1 parent a044747 commit 82e447e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

connection.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) {
135135
}
136136

137137
func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (string, error) {
138+
// Number of ? should be same to len(args)
139+
if strings.Count(query, "?") != len(args) {
140+
return "", driver.ErrSkip
141+
}
142+
138143
buf := mc.buf.takeCompleteBuffer()
139144
if buf == nil {
140145
// can not take the buffer. Something must be wrong with the connection
@@ -153,9 +158,6 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
153158
buf = append(buf, query[i:i+q]...)
154159
i += q
155160

156-
if argPos >= len(args) {
157-
return "", driver.ErrSkip
158-
}
159161
arg := args[argPos]
160162
argPos++
161163

connection_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
22
//
3-
// Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
3+
// Copyright 2016 The Go-MySQL-Driver Authors. All rights reserved.
44
//
55
// This Source Code Form is subject to the terms of the Mozilla Public
66
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
@@ -47,3 +47,19 @@ func TestInterpolateParamsTooManyPlaceholders(t *testing.T) {
4747
t.Errorf("Expected err=driver.ErrSkip, got err=%#v, q=%#v", err, q)
4848
}
4949
}
50+
51+
// We don't support placeholder in string literal for now.
52+
func TestInterpolateParamsPlaceholderInString(t *testing.T) {
53+
mc := &mysqlConn{
54+
buf: newBuffer(nil),
55+
maxPacketAllowed: maxPacketSize,
56+
cfg: &Config{
57+
InterpolateParams: true,
58+
},
59+
}
60+
61+
q, err := mc.interpolateParams("SELECT 'abc?xyz',?", []driver.Value{int64(42)})
62+
if err != driver.ErrSkip {
63+
t.Errorf("Expected err=driver.ErrSkip, got err=%#v, q=%#v", err, q)
64+
}
65+
}

0 commit comments

Comments
 (0)