Skip to content

Commit

Permalink
Fix: Scan uint and uint64 ScanNumeric
Browse files Browse the repository at this point in the history
fixes #1414
  • Loading branch information
jackc committed Dec 6, 2022
1 parent 88b373f commit f0a7342
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pgtype/builtin_wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (w *uint64Wrapper) ScanNumeric(v Numeric) error {
return fmt.Errorf("cannot scan %v into *uint64", bi.String())
}

*w = uint64Wrapper(v.Int.Uint64())
*w = uint64Wrapper(bi.Uint64())

return nil
}
Expand Down Expand Up @@ -291,7 +291,7 @@ func (w *uintWrapper) ScanNumeric(v Numeric) error {
return fmt.Errorf("cannot scan %v into *uint", bi.String())
}

ui := v.Int.Uint64()
ui := bi.Uint64()

if math.MaxUint < ui {
return fmt.Errorf("cannot scan %v into *uint", ui)
Expand Down
2 changes: 2 additions & 0 deletions pgtype/numeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ func TestNumericCodec(t *testing.T) {
{int64(math.MinInt64 + 1), new(pgtype.Numeric), isExpectedEqNumeric(mustParseNumeric(t, strconv.FormatInt(math.MinInt64+1, 10)))},
{int64(math.MaxInt64), new(pgtype.Numeric), isExpectedEqNumeric(mustParseNumeric(t, strconv.FormatInt(math.MaxInt64, 10)))},
{int64(math.MaxInt64 - 1), new(pgtype.Numeric), isExpectedEqNumeric(mustParseNumeric(t, strconv.FormatInt(math.MaxInt64-1, 10)))},
{uint64(100), new(uint64), isExpectedEq(uint64(100))},
{uint64(math.MaxUint64), new(uint64), isExpectedEq(uint64(math.MaxUint64))},
{uint(math.MaxUint), new(uint), isExpectedEq(uint(math.MaxUint))},
{uint(100), new(uint), isExpectedEq(uint(100))},
{"1.23", new(string), isExpectedEq("1.23")},
{pgtype.Numeric{}, new(pgtype.Numeric), isExpectedEq(pgtype.Numeric{})},
{nil, new(pgtype.Numeric), isExpectedEq(pgtype.Numeric{})},
Expand Down

0 comments on commit f0a7342

Please sign in to comment.