Skip to content

Commit f7ba29f

Browse files
committed
connection: interpolate uint64 parameters
PR go-sql-driver#838 introduced a fix for the driver's custom Value Converter that stopped emitting large uint64 `driver.Value`s as a string. Instead, now _all_ uint{8,16,32,64} values passed to the driver are returned as uint64, and `packets.c` now explicitly handles `driver.Value` instances that are uint64. However, the update in `packets.c` only applies when sending `driver.Value` arguments to the server. When a connection is set up using `InterpolateParams = true` and query interpolation happens inside of the driver, the `(*mysqlConn) interpolateParams` does **not** handle uint64 values (which, again, are now passed by `database/sql` because we've updated our value converter to generate them). Because of this, any `DB.Query` operations which have an uint argument (regardless of its size!!) will force the driver to return `driver.ErrSkip`, disabling client interpolation for such queries. We can fix this by updating `interpolateParams` like we previously updated `writeExecutePacket`.
1 parent 578c4c8 commit f7ba29f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

connection.go

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
213213
switch v := arg.(type) {
214214
case int64:
215215
buf = strconv.AppendInt(buf, v, 10)
216+
case uint64:
217+
// Handle uint64 explicitly because our custom ConvertValue emits unsigned values
218+
buf = strconv.AppendUint(buf, v, 10)
216219
case float64:
217220
buf = strconv.AppendFloat(buf, v, 'g', -1, 64)
218221
case bool:

connection_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ func TestInterpolateParamsPlaceholderInString(t *testing.T) {
6969
}
7070
}
7171

72+
func TestInterpolateParamsUint64(t *testing.T) {
73+
mc := &mysqlConn{
74+
buf: newBuffer(nil),
75+
maxAllowedPacket: maxPacketSize,
76+
cfg: &Config{
77+
InterpolateParams: true,
78+
},
79+
}
80+
81+
q, err := mc.interpolateParams("SELECT ?", []driver.Value{uint64(42)})
82+
if err != nil {
83+
t.Errorf("Expected err=nil, got err=%#v, q=%#v", err, q)
84+
}
85+
if q != "SELECT 42" {
86+
t.Errorf("Expected uint64 interpolation to work, got q=%#v", q)
87+
}
88+
}
89+
7290
func TestCheckNamedValue(t *testing.T) {
7391
value := driver.NamedValue{Value: ^uint64(0)}
7492
x := &mysqlConn{}

0 commit comments

Comments
 (0)