Skip to content
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
4 changes: 4 additions & 0 deletions decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2803,6 +2803,10 @@ func TestDecimal_Scan(t *testing.T) {
if err == nil {
t.Errorf("a.Scan(Foo{}) should have thrown an error but did not")
}

if err := a.Scan(nil); err == nil || !strings.Contains(err.Error(), "NullDecimal") {
t.Errorf("a.Scan(nil): got %v, want an error that points to NullDecimal", err)
}
}

func TestDecimal_ScanTypes(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (d *Decimal) Scan(value interface{}) error {
// first try to see if the data is stored in database as a Numeric datatype
switch v := value.(type) {

case nil:
return fmt.Errorf("can't scan NULL into a Decimal, use NullDecimal or *Decimal")

case float32:
if math.IsNaN(float64(v)) || math.IsInf(float64(v), 0) {
return fmt.Errorf("could not convert value '%v' to decimal", v)
Expand Down
Loading