Skip to content

Commit 532d05d

Browse files
committed
pass unsigned int as it is without converting it to string
1 parent 749ddf1 commit 532d05d

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

connection_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestCheckNamedValue(t *testing.T) {
7575
t.Fatal("uint64 high-bit not convertible", err)
7676
}
7777

78-
if value.Value != "18446744073709551615" {
79-
t.Fatalf("uint64 high-bit not converted, got %#v %T", value.Value, value.Value)
78+
if value.Value != ^uint64(0) {
79+
t.Fatalf("uint64 high-bit converted, got %#v %T", value.Value, value.Value)
8080
}
8181
}

packets.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,22 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
999999
)
10001000
}
10011001

1002+
case uint64:
1003+
paramTypes[i+i] = byte(fieldTypeLongLong)
1004+
paramTypes[i+i+1] = 0x80 // type is unsigned
1005+
1006+
if cap(paramValues)-len(paramValues)-8 >= 0 {
1007+
paramValues = paramValues[:len(paramValues)+8]
1008+
binary.LittleEndian.PutUint64(
1009+
paramValues[len(paramValues)-8:],
1010+
uint64(v),
1011+
)
1012+
} else {
1013+
paramValues = append(paramValues,
1014+
uint64ToBytes(uint64(v))...,
1015+
)
1016+
}
1017+
10021018
case float64:
10031019
paramTypes[i+i] = byte(fieldTypeDouble)
10041020
paramTypes[i+i+1] = 0x00

statement.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"fmt"
1414
"io"
1515
"reflect"
16-
"strconv"
1716
)
1817

1918
type mysqlStmt struct {
@@ -169,7 +168,7 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
169168
case reflect.Uint64:
170169
u64 := rv.Uint()
171170
if u64 >= 1<<63 {
172-
return strconv.FormatUint(u64, 10), nil
171+
return u64, nil
173172
}
174173
return int64(u64), nil
175174
case reflect.Float32, reflect.Float64:

statement_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestConvertUnsignedIntegers(t *testing.T) {
120120
t.Fatal("uint64 high-bit not convertible", err)
121121
}
122122

123-
if output != "18446744073709551615" {
124-
t.Fatalf("uint64 high-bit not converted, got %#v %T", output, output)
123+
if output != ^uint64(0) {
124+
t.Fatalf("uint64 high-bit converted, got %#v %T", output, output)
125125
}
126126
}

0 commit comments

Comments
 (0)