mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Fix same issue as #39 but without changing the Value() interface
This commit is contained in:
parent
ed31524af4
commit
77e6b496f6
2 changed files with 23 additions and 2 deletions
|
@ -631,6 +631,10 @@ func (d *Decimal) Scan(value interface{}) error {
|
||||||
// first try to see if the data is stored in database as a Numeric datatype
|
// first try to see if the data is stored in database as a Numeric datatype
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
|
|
||||||
|
case float32:
|
||||||
|
*d = NewFromFloat(float64(v))
|
||||||
|
return nil
|
||||||
|
|
||||||
case float64:
|
case float64:
|
||||||
// numeric in sqlite3 sends us float64
|
// numeric in sqlite3 sends us float64
|
||||||
*d = NewFromFloat(v)
|
*d = NewFromFloat(v)
|
||||||
|
@ -802,8 +806,8 @@ func unquoteIfQuoted(value interface{}) (string, error) {
|
||||||
case []byte:
|
case []byte:
|
||||||
bytes = v
|
bytes = v
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("Could not convert value '%+v' to byte array",
|
return "", fmt.Errorf("Could not convert value '%+v' to byte array of type '%T'",
|
||||||
value)
|
value, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the amount is quoted, strip the quotes
|
// If the amount is quoted, strip the quotes
|
||||||
|
|
|
@ -1175,6 +1175,23 @@ func TestDecimal_Scan(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apparently MySQL 5.7.16 and returns these as float32 so we need
|
||||||
|
// to handle these as well
|
||||||
|
dbvalueFloat32 := float32(54.33)
|
||||||
|
expected = NewFromFloat(float64(dbvalueFloat32))
|
||||||
|
|
||||||
|
err = a.Scan(dbvalueFloat32)
|
||||||
|
if err != nil {
|
||||||
|
// Scan failed... no need to test result value
|
||||||
|
t.Errorf("a.Scan(54.33) failed with message: %s", err)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Scan succeeded... test resulting values
|
||||||
|
if !a.Equal(expected) {
|
||||||
|
t.Errorf("%s does not equal to %s", a, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// at least SQLite returns an int64 when 0 is stored in the db
|
// at least SQLite returns an int64 when 0 is stored in the db
|
||||||
// and you specified a numeric format on the schema
|
// and you specified a numeric format on the schema
|
||||||
dbvalueInt := int64(0)
|
dbvalueInt := int64(0)
|
||||||
|
|
Loading…
Reference in a new issue