Skip to content
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

Merged
merged 2 commits into from
Aug 14, 2018
Merged

fix uint64 high bit #28 #29

merged 2 commits into from
Aug 14, 2018

Conversation

al-tush
Copy link
Contributor

@al-tush al-tush commented Aug 2, 2018

No description provided.

@bgaifullin
Copy link
Contributor

Thank you for PR, I posted some comments.
Also please squash your commits.

if rv.IsNil() {
return nil, nil
}
return converter{}.ConvertValue(rv.Elem().Interface())
Copy link
Contributor

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())

return converter{}.ConvertValue(rv.Elem().Interface())
case reflect.Uint64:
u64 := rv.Uint()
if u64 >= 1<<63 {
Copy link
Contributor

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

bytes := []byte(s)
return bytes, nil
}
return int64(u64), nil
Copy link
Contributor

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.


type converter struct{}

func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
Copy link
Contributor

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.

@al-tush
Copy link
Contributor Author

al-tush commented Aug 7, 2018

Done )

{int64(maxAllowedUInt64), int64(9223372036854775807), "int64(maxAllowedUInt64)"},
{uint64(maxAllowedUInt64 + 1), []byte("9223372036854775808"), "uint64(maxAllowedUInt64+1)"},
{uint64(maxAllowedUInt64*2 + 1), []byte("18446744073709551615"), "uint64(maxUInt64)"},
}
Copy link
Contributor

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))
}

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ок

@bgaifullin bgaifullin merged commit 8c19f6f into mailru:master Aug 14, 2018
@al-tush al-tush deleted the issue28 branch August 14, 2018 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants