Skip to content

Small converter improvements #345

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 2 commits into from
Jun 5, 2015
Merged
Changes from all commits
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
7 changes: 4 additions & 3 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"database/sql/driver"
"fmt"
"reflect"
"strconv"
)

type mysqlStmt struct {
Expand Down Expand Up @@ -119,7 +120,7 @@ func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {

type converter struct{}

func (converter) ConvertValue(v interface{}) (driver.Value, error) {
func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
if driver.IsValue(v) {
return v, nil
}
Expand All @@ -131,15 +132,15 @@ func (converter) ConvertValue(v interface{}) (driver.Value, error) {
if rv.IsNil() {
return nil, nil
}
return driver.DefaultParameterConverter.ConvertValue(rv.Elem().Interface())
return c.ConvertValue(rv.Elem().Interface())
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 fmt.Sprintf("%d", u64), nil
return strconv.FormatUint(u64, 10), nil
}
return int64(u64), nil
case reflect.Float32, reflect.Float64:
Expand Down