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
|
||||
switch v := value.(type) {
|
||||
|
||||
case float32:
|
||||
*d = NewFromFloat(float64(v))
|
||||
return nil
|
||||
|
||||
case float64:
|
||||
// numeric in sqlite3 sends us float64
|
||||
*d = NewFromFloat(v)
|
||||
|
@ -802,8 +806,8 @@ func unquoteIfQuoted(value interface{}) (string, error) {
|
|||
case []byte:
|
||||
bytes = v
|
||||
default:
|
||||
return "", fmt.Errorf("Could not convert value '%+v' to byte array",
|
||||
value)
|
||||
return "", fmt.Errorf("Could not convert value '%+v' to byte array of type '%T'",
|
||||
value, value)
|
||||
}
|
||||
|
||||
// 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
|
||||
// and you specified a numeric format on the schema
|
||||
dbvalueInt := int64(0)
|
||||
|
|
Loading…
Reference in a new issue