mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-23 04:40:49 +01:00
Merge e5ee5e5502
into a1bdfc355e
This commit is contained in:
commit
08c7c48074
2 changed files with 80 additions and 0 deletions
20
decimal.go
20
decimal.go
|
@ -1841,6 +1841,26 @@ func (d *Decimal) Scan(value interface{}) error {
|
||||||
*d = NewFromFloat(v)
|
*d = NewFromFloat(v)
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
case int:
|
||||||
|
// also better to implement to support all type of int.
|
||||||
|
// profitable to create another abstract layer for testing
|
||||||
|
// data access with no depends on real RDBMS.
|
||||||
|
|
||||||
|
*d = New(int64(v), 0)
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case int8:
|
||||||
|
*d = New(int64(v), 0)
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case int16:
|
||||||
|
*d = New(int64(v), 0)
|
||||||
|
return nil
|
||||||
|
|
||||||
|
case int32:
|
||||||
|
*d = New(int64(v), 0)
|
||||||
|
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 ...
|
||||||
|
|
|
@ -2471,6 +2471,66 @@ func TestDecimal_Scan(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("a.Scan(Foo{}) should have thrown an error but did not")
|
t.Errorf("a.Scan(Foo{}) should have thrown an error but did not")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbvalueInt8 := int8(32)
|
||||||
|
expected = New(int64(32), 0)
|
||||||
|
|
||||||
|
err = a.Scan(dbvalueInt8)
|
||||||
|
if err != nil {
|
||||||
|
// Scan failed... no need to test result value
|
||||||
|
t.Errorf("a.Scan(32) 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbvalueInt16 := int16(21)
|
||||||
|
expected = New(int64(21), 0)
|
||||||
|
|
||||||
|
err = a.Scan(dbvalueInt16)
|
||||||
|
if err != nil {
|
||||||
|
// Scan failed... no need to test result value
|
||||||
|
t.Errorf("a.Scan(21) 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbvalueInt32 := int32(32)
|
||||||
|
expected = New(int64(32), 0)
|
||||||
|
|
||||||
|
err = a.Scan(dbvalueInt32)
|
||||||
|
if err != nil {
|
||||||
|
// Scan failed... no need to test result value
|
||||||
|
t.Errorf("a.Scan(32) 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dbvalueIntNatural := 3264
|
||||||
|
expected = New(int64(3264), 0)
|
||||||
|
|
||||||
|
err = a.Scan(dbvalueIntNatural)
|
||||||
|
if err != nil {
|
||||||
|
// Scan failed... no need to test result value
|
||||||
|
t.Errorf("a.Scan(3264) 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecimal_Value(t *testing.T) {
|
func TestDecimal_Value(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue