Skip to content

fix bigint unsigned null column scan to err type int64 #1612

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
Show file tree
Hide file tree
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 AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Alex Snast <alexsn at fb.com>
Alexey Palazhchenko <alexey.palazhchenko at gmail.com>
Andrew Reid <andrew.reid at tixtrack.com>
Animesh Ray <mail.rayanimesh at gmail.com>
Arne Hormann <arnehormann at gmail.com>
Ariel Mashraki <ariel at mashraki.co.il>
Arne Hormann <arnehormann at gmail.com>
Artur Melanchyk <[email protected]>
Asta Xie <xiemengjun at gmail.com>
B Lamarche <blam413 at gmail.com>
Expand Down Expand Up @@ -62,6 +62,7 @@ Jeff Hodges <jeff at somethingsimilar.com>
Jeffrey Charles <jeffreycharles at gmail.com>
Jennifer Purevsuren <jennifer at dolthub.com>
Jerome Meyer <jxmeyer at gmail.com>
Jiabin Zhang <jiabin.z at qq.com>
Jiajia Zhong <zhong2plus at gmail.com>
Jian Zhen <zhenjl at gmail.com>
Joe Mann <contact at joemann.co.uk>
Expand All @@ -81,10 +82,11 @@ Linh Tran Tuan <linhduonggnu at gmail.com>
Lion Yang <lion at aosc.xyz>
Luca Looz <luca.looz92 at gmail.com>
Lucas Liu <extrafliu at gmail.com>
Lunny Xiao <xiaolunwen at gmail.com>
Luke Scott <luke at webconnex.com>
Lunny Xiao <xiaolunwen at gmail.com>
Maciej Zimnoch <maciej.zimnoch at codilime.com>
Michael Woolnough <michael.woolnough at gmail.com>
Minh Quang <minhquang4334 at gmail.com>
Nao Yokotsuka <yokotukanao at gmail.com>
Nathanial Murphy <nathanial.murphy at gmail.com>
Nicola Peduzzi <thenikso at gmail.com>
Expand All @@ -95,7 +97,6 @@ Paul Bonser <misterpib at gmail.com>
Paulius Lozys <pauliuslozys at gmail.com>
Peter Schultz <peter.schultz at classmarkets.com>
Phil Porada <philporada at gmail.com>
Minh Quang <minhquang4334 at gmail.com>
Rebecca Chin <rchin at pivotal.io>
Reed Allman <rdallman10 at gmail.com>
Richard Wilkes <wilkes at me.com>
Expand Down
4 changes: 4 additions & 0 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ var (
scanTypeInt64 = reflect.TypeOf(int64(0))
scanTypeNullFloat = reflect.TypeOf(sql.NullFloat64{})
scanTypeNullInt = reflect.TypeOf(sql.NullInt64{})
scanTypeNullUint = reflect.TypeOf(sql.Null[uint64]{})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Breaking change: sql.Null requires Go 1.22.

As mentioned in the PR discussion, Go 1.21 support hasn't been dropped yet. Using sql.Null[uint64] would break compatibility with Go 1.21 and earlier versions.

Consider one of these alternatives:

  1. Use build tags to conditionally include this for Go 1.22+
  2. Create a custom NullUint64 type that implements the required interfaces:
// NullUint64 represents a uint64 that may be null
type NullUint64 struct {
    Uint64 uint64
    Valid  bool
}

// Implement Scanner and Valuer interfaces
func (n *NullUint64) Scan(value any) error {
    if value == nil {
        n.Uint64, n.Valid = 0, false
        return nil
    }
    n.Valid = true
    return convertAssign(&n.Uint64, value)
}

func (n NullUint64) Value() (driver.Value, error) {
    if !n.Valid {
        return nil, nil
    }
    return n.Uint64, nil
}

scanTypeNullTime = reflect.TypeOf(sql.NullTime{})
scanTypeUint8 = reflect.TypeOf(uint8(0))
scanTypeUint16 = reflect.TypeOf(uint16(0))
Expand Down Expand Up @@ -185,6 +186,9 @@ func (mf *mysqlField) scanType() reflect.Type {
}
return scanTypeInt64
}
if mf.flags&flagUnsigned != 0 {
return scanTypeNullUint
}
Comment on lines +189 to +191
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Based on the test content examination, I can now provide a final response:

Test coverage for unsigned bigint nulls is insufficient

The codebase has tests for unsigned bigint (biguint) but only covers the non-null case with basic values (0, 65535, 42). There are no specific test cases for:

  • Null unsigned bigint values
  • Edge cases near uint64 maximum values
  • Values exceeding int64 range
  • Add test cases in driver_test.go for scanTypeNullUint similar to existing bigintnull tests
  • Include edge cases testing uint64 values > math.MaxInt64
🔗 Analysis chain

Verify test coverage for unsigned bigint nulls.

Let's ensure the changes are properly tested, especially for edge cases where uint64 values exceed int64 range.


Let's examine the specific test content in driver_test.go since it appears in both searches.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests involving unsigned bigint columns
echo "Searching for tests with unsigned bigint columns..."
rg -l --type go "(?i)(unsigned.*bigint|uint64.*null)" *_test.go

# Search for existing null scanning tests
echo "Searching for null scanning tests..."
rg -l --type go "(?i)(nullint|nulluint|null.*scan)" *_test.go

Length of output: 755


Script:

#!/bin/bash
# Check the content of driver_test.go for unsigned bigint and null scanning tests
echo "Examining driver_test.go for unsigned bigint and null scanning tests..."
rg -A 10 -B 2 "(?i)(unsigned.*bigint|uint64.*null|nullint|nulluint|null.*scan)" driver_test.go

Length of output: 11427

return scanTypeNullInt

case fieldTypeFloat:
Expand Down