support float64, float32 convert to int2, int4, int8
This commit is contained in:
@@ -85,6 +85,16 @@ func (dst *Int2) Set(src interface{}) error {
|
||||
return err
|
||||
}
|
||||
*dst = Int2{Int: int16(num), Status: Present}
|
||||
case float32:
|
||||
if value > math.MaxInt16 {
|
||||
return errors.Errorf("%d is greater than maximum value for Int2", value)
|
||||
}
|
||||
*dst = Int2{Int: int16(value), Status: Present}
|
||||
case float64:
|
||||
if value > math.MaxInt16 {
|
||||
return errors.Errorf("%d is greater than maximum value for Int2", value)
|
||||
}
|
||||
*dst = Int2{Int: int16(value), Status: Present}
|
||||
case *int8:
|
||||
if value == nil {
|
||||
*dst = Int2{Status: Null}
|
||||
@@ -151,6 +161,18 @@ func (dst *Int2) Set(src interface{}) error {
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
case *float32:
|
||||
if value == nil {
|
||||
*dst = Int2{Status: Null}
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
case *float64:
|
||||
if value == nil {
|
||||
*dst = Int2{Status: Null}
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
default:
|
||||
if originalSrc, ok := underlyingNumberType(src); ok {
|
||||
return dst.Set(originalSrc)
|
||||
|
||||
@@ -77,6 +77,16 @@ func (dst *Int4) Set(src interface{}) error {
|
||||
return err
|
||||
}
|
||||
*dst = Int4{Int: int32(num), Status: Present}
|
||||
case float32:
|
||||
if value > math.MaxInt32 {
|
||||
return errors.Errorf("%d is greater than maximum value for Int4", value)
|
||||
}
|
||||
*dst = Int4{Int: int32(value), Status: Present}
|
||||
case float64:
|
||||
if value > math.MaxInt32 {
|
||||
return errors.Errorf("%d is greater than maximum value for Int4", value)
|
||||
}
|
||||
*dst = Int4{Int: int32(value), Status: Present}
|
||||
case *int8:
|
||||
if value == nil {
|
||||
*dst = Int4{Status: Null}
|
||||
@@ -143,6 +153,18 @@ func (dst *Int4) Set(src interface{}) error {
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
case *float32:
|
||||
if value == nil {
|
||||
*dst = Int4{Status: Null}
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
case *float64:
|
||||
if value == nil {
|
||||
*dst = Int4{Status: Null}
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
default:
|
||||
if originalSrc, ok := underlyingNumberType(src); ok {
|
||||
return dst.Set(originalSrc)
|
||||
|
||||
@@ -68,6 +68,16 @@ func (dst *Int8) Set(src interface{}) error {
|
||||
return err
|
||||
}
|
||||
*dst = Int8{Int: num, Status: Present}
|
||||
case float32:
|
||||
if value > math.MaxInt64 {
|
||||
return errors.Errorf("%d is greater than maximum value for Int8", value)
|
||||
}
|
||||
*dst = Int8{Int: int64(value), Status: Present}
|
||||
case float64:
|
||||
if value > math.MaxInt64 {
|
||||
return errors.Errorf("%d is greater than maximum value for Int8", value)
|
||||
}
|
||||
*dst = Int8{Int: int64(value), Status: Present}
|
||||
case *int8:
|
||||
if value == nil {
|
||||
*dst = Int8{Status: Null}
|
||||
@@ -134,6 +144,18 @@ func (dst *Int8) Set(src interface{}) error {
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
case *float32:
|
||||
if value == nil {
|
||||
*dst = Int8{Status: Null}
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
case *float64:
|
||||
if value == nil {
|
||||
*dst = Int8{Status: Null}
|
||||
} else {
|
||||
return dst.Set(*value)
|
||||
}
|
||||
default:
|
||||
if originalSrc, ok := underlyingNumberType(src); ok {
|
||||
return dst.Set(originalSrc)
|
||||
|
||||
Reference in New Issue
Block a user