Skip to content

pass unsigned int as it is without converting it to string #838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
16 changes: 16 additions & 0 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"fmt"
"io"
"reflect"
"strconv"
)

type mysqlStmt struct {
Expand Down Expand Up @@ -169,7 +168,7 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
case reflect.Uint64:
u64 := rv.Uint()
if u64 >= 1<<63 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to still do this check for the high bit instead of just always returning u64?

return strconv.FormatUint(u64, 10), nil
return u64, nil
}
return int64(u64), nil
case reflect.Float32, reflect.Float64:
Expand Down
4 changes: 2 additions & 2 deletions statement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}