-
Notifications
You must be signed in to change notification settings - Fork 88
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
fix uint64 high bit #28 #29
Conversation
Thank you for PR, I posted some comments. |
value_converter.go
Outdated
if rv.IsNil() { | ||
return nil, nil | ||
} | ||
return converter{}.ConvertValue(rv.Elem().Interface()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.ConvertValue(rv.Elem().Interface())
value_converter.go
Outdated
return converter{}.ConvertValue(rv.Elem().Interface()) | ||
case reflect.Uint64: | ||
u64 := rv.Uint() | ||
if u64 >= 1<<63 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets move 1<<63 into named constant. for the instance MaxAllowedUInt64
value_converter.go
Outdated
bytes := []byte(s) | ||
return bytes, nil | ||
} | ||
return int64(u64), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add comment, that is is the default behaviour to convert uint into int.
value_converter.go
Outdated
|
||
type converter struct{} | ||
|
||
func (c converter) ConvertValue(v interface{}) (driver.Value, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests to prove that your code works and the big uint64 is supported properly now.
Done ) |
{int64(maxAllowedUInt64), int64(9223372036854775807), "int64(maxAllowedUInt64)"}, | ||
{uint64(maxAllowedUInt64 + 1), []byte("9223372036854775808"), "uint64(maxAllowedUInt64+1)"}, | ||
{uint64(maxAllowedUInt64*2 + 1), []byte("18446744073709551615"), "uint64(maxUInt64)"}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, but need also check that other values (for the instance float, string, driver.Value, pointer do handled properly)
And it would be great to check that converter works when sql.DB is used.
type ConverterSuite struct {
chSuite
}
func (s * ConverterSuite) TestBigInt() {
result, err := s.conn.Exec("INSERT INTO data (u64) VALUES (?)", maxAllowedUInt64 + 1)
s.NoError(err)
rows, err := s.conn.Query("SELECT u64 FROM data WHERE u64=?", maxAllowedUInt64 + 1)
s.NoError(err)
v, err := scanValues(rows, tc.args)
s.NoError(err) {
s.Equal([][]interface{}{maxAllowedUInt64 + 1}, v)
s.NoError(rows.Close())
// the same for a statements
}
func TestConveter(t *testing.T) {
suite.Run(t, new(ConverterSuite))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but it do not corresponds whith uint64 high bit issue. Probably the better case is to merge fix actual code changes and then we extend tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ок
No description provided.