Skip to content

Commit 88aeb98

Browse files
committed
append string... to []byte without cast.
1 parent 916a1f2 commit 88aeb98

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

connection.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,19 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
210210
argPos := 0
211211

212212
for i := 0; i < len(query); i++ {
213-
c := query[i]
214-
if c != '?' {
215-
buf = append(buf, c)
216-
continue
213+
q := strings.IndexByte(query[i:], '?')
214+
if q == -1 {
215+
buf = append(buf, query[i:]...)
216+
break
217217
}
218+
buf = append(buf, query[i:i+q]...)
219+
i += q
218220

219221
arg := args[argPos]
220222
argPos++
221223

222224
if arg == nil {
223-
buf = append(buf, []byte("NULL")...)
225+
buf = append(buf, "NULL"...)
224226
continue
225227
}
226228

@@ -237,7 +239,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
237239
}
238240
case time.Time:
239241
if v.IsZero() {
240-
buf = append(buf, []byte("'0000-00-00'")...)
242+
buf = append(buf, "'0000-00-00'"...)
241243
} else {
242244
v := v.In(mc.cfg.loc)
243245
year := v.Year()
@@ -286,7 +288,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
286288
}
287289
case []byte:
288290
if v == nil {
289-
buf = append(buf, []byte("NULL")...)
291+
buf = append(buf, "NULL"...)
290292
} else {
291293
buf = mc.escapeBytes(buf, v)
292294
}

0 commit comments

Comments
 (0)