diff --git a/AUTHORS b/AUTHORS index fb6668346..73b1e2e9b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -34,6 +34,7 @@ Hajime Nakagami Hanno Braun Henri Yandell Hirotaka Yamamoto +Huyiguang ICHINOSE Shogo Ilia Cimpoes INADA Naoki diff --git a/connection_test.go b/connection_test.go index 2a1c8e888..8e78f36c6 100644 --- a/connection_test.go +++ b/connection_test.go @@ -78,8 +78,8 @@ func TestCheckNamedValue(t *testing.T) { t.Fatal("uint64 high-bit not convertible", err) } - if value.Value != "18446744073709551615" { - t.Fatalf("uint64 high-bit not converted, got %#v %T", value.Value, value.Value) + if value.Value != ^uint64(0) { + t.Fatalf("uint64 high-bit converted, got %#v %T", value.Value, value.Value) } } diff --git a/packets.go b/packets.go index 70d0d71f5..cbed325f4 100644 --- a/packets.go +++ b/packets.go @@ -1011,6 +1011,22 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error { ) } + case uint64: + paramTypes[i+i] = byte(fieldTypeLongLong) + paramTypes[i+i+1] = 0x80 // type is unsigned + + if cap(paramValues)-len(paramValues)-8 >= 0 { + paramValues = paramValues[:len(paramValues)+8] + binary.LittleEndian.PutUint64( + paramValues[len(paramValues)-8:], + uint64(v), + ) + } else { + paramValues = append(paramValues, + uint64ToBytes(uint64(v))..., + ) + } + case float64: paramTypes[i+i] = byte(fieldTypeDouble) paramTypes[i+i+1] = 0x00 diff --git a/statement.go b/statement.go index ce7fe4cd0..f7e370939 100644 --- a/statement.go +++ b/statement.go @@ -13,7 +13,6 @@ import ( "fmt" "io" "reflect" - "strconv" ) type mysqlStmt struct { @@ -164,14 +163,8 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) { } case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return rv.Int(), nil - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32: - return int64(rv.Uint()), nil - case reflect.Uint64: - u64 := rv.Uint() - if u64 >= 1<<63 { - return strconv.FormatUint(u64, 10), nil - } - return int64(u64), nil + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return rv.Uint(), nil case reflect.Float32, reflect.Float64: return rv.Float(), nil case reflect.Bool: diff --git a/statement_test.go b/statement_test.go index 98a6c1933..4b9914f8e 100644 --- a/statement_test.go +++ b/statement_test.go @@ -110,7 +110,7 @@ func TestConvertUnsignedIntegers(t *testing.T) { t.Fatalf("%T type not convertible %s", value, err) } - if output != int64(42) { + if output != uint64(42) { t.Fatalf("%T type not converted, got %#v %T", value, output, output) } } @@ -120,7 +120,7 @@ func TestConvertUnsignedIntegers(t *testing.T) { t.Fatal("uint64 high-bit not convertible", err) } - if output != "18446744073709551615" { - t.Fatalf("uint64 high-bit not converted, got %#v %T", output, output) + if output != ^uint64(0) { + t.Fatalf("uint64 high-bit converted, got %#v %T", output, output) } }