From 532d05dce1aea73f095967c92b5d2ff22aceb5d3 Mon Sep 17 00:00:00 2001 From: hyg Date: Wed, 18 Jul 2018 21:47:47 +0800 Subject: [PATCH 1/3] pass unsigned int as it is without converting it to string --- connection_test.go | 4 ++-- packets.go | 16 ++++++++++++++++ statement.go | 3 +-- statement_test.go | 4 ++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/connection_test.go b/connection_test.go index dec376117..e3ed1f454 100644 --- a/connection_test.go +++ b/connection_test.go @@ -75,7 +75,7 @@ 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 f99934e73..f47d289cd 100644 --- a/packets.go +++ b/packets.go @@ -999,6 +999,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..e232e47a5 100644 --- a/statement.go +++ b/statement.go @@ -13,7 +13,6 @@ import ( "fmt" "io" "reflect" - "strconv" ) type mysqlStmt struct { @@ -169,7 +168,7 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) { case reflect.Uint64: u64 := rv.Uint() if u64 >= 1<<63 { - return strconv.FormatUint(u64, 10), nil + return u64, nil } return int64(u64), nil case reflect.Float32, reflect.Float64: diff --git a/statement_test.go b/statement_test.go index 98a6c1933..6b6db4b1f 100644 --- a/statement_test.go +++ b/statement_test.go @@ -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) } } From 18262fb0a86288586b5790480d0ebe5f0e403406 Mon Sep 17 00:00:00 2001 From: hyg Date: Wed, 18 Jul 2018 23:43:23 +0800 Subject: [PATCH 2/3] fix comment --- AUTHORS | 1 + statement.go | 10 ++-------- statement_test.go | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/AUTHORS b/AUTHORS index 73ff68fbc..94e46cd55 100644 --- a/AUTHORS +++ b/AUTHORS @@ -34,6 +34,7 @@ Hajime Nakagami Hanno Braun Henri Yandell Hirotaka Yamamoto +Huyiguang ICHINOSE Shogo INADA Naoki Jacek Szwec diff --git a/statement.go b/statement.go index e232e47a5..f7e370939 100644 --- a/statement.go +++ b/statement.go @@ -163,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 u64, 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 6b6db4b1f..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) } } From a3ccc30eb3c643e5df392f633cdd235746dfd199 Mon Sep 17 00:00:00 2001 From: hyg Date: Thu, 19 Jul 2018 00:07:29 +0800 Subject: [PATCH 3/3] fix me --- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 94e46cd55..0bfba1ae5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -34,7 +34,7 @@ Hajime Nakagami Hanno Braun Henri Yandell Hirotaka Yamamoto -Huyiguang +Huyiguang ICHINOSE Shogo INADA Naoki Jacek Szwec