mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Return nil instead of empty err in Scan
This commit is contained in:
parent
c30673fb5f
commit
b873aa2b43
1 changed files with 2 additions and 3 deletions
|
@ -469,20 +469,19 @@ func (d Decimal) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
// Scan implements the sql.Scanner interface for database deserialization.
|
// Scan implements the sql.Scanner interface for database deserialization.
|
||||||
func (d *Decimal) Scan(value interface{}) error {
|
func (d *Decimal) Scan(value interface{}) error {
|
||||||
var err 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 float64:
|
case float64:
|
||||||
// numeric in sqlite3 sends us float64
|
// numeric in sqlite3 sends us float64
|
||||||
*d = NewFromFloat(v)
|
*d = NewFromFloat(v)
|
||||||
return err
|
return nil
|
||||||
|
|
||||||
case int64:
|
case int64:
|
||||||
// at least in sqlite3 when the value is 0 in db, the data is sent
|
// at least in sqlite3 when the value is 0 in db, the data is sent
|
||||||
// to us as an int64 instead of a float64 ...
|
// to us as an int64 instead of a float64 ...
|
||||||
*d = New(v, 0)
|
*d = New(v, 0)
|
||||||
return err
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// default is trying to interpret value stored as string
|
// default is trying to interpret value stored as string
|
||||||
|
|
Loading…
Reference in a new issue