+5
-9
@@ -16,8 +16,8 @@ import (
|
|||||||
const nbase = 10000
|
const nbase = 10000
|
||||||
|
|
||||||
const (
|
const (
|
||||||
pgNumericNaN = 0x000000000c000000
|
pgNumericNaN = 0x00000000c0000000
|
||||||
pgNumericNaNSign = 0x0c00
|
pgNumericNaNSign = 0xc000
|
||||||
)
|
)
|
||||||
|
|
||||||
var big0 *big.Int = big.NewInt(0)
|
var big0 *big.Int = big.NewInt(0)
|
||||||
@@ -406,7 +406,7 @@ func (dst *Numeric) DecodeText(ci *ConnInfo, src []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(src) == "'NaN'" { // includes single quotes, see EncodeText for details.
|
if string(src) == "NaN" {
|
||||||
*dst = Numeric{Status: Present, NaN: true}
|
*dst = Numeric{Status: Present, NaN: true}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -456,7 +456,7 @@ func (dst *Numeric) DecodeBinary(ci *ConnInfo, src []byte) error {
|
|||||||
rp += 2
|
rp += 2
|
||||||
weight := int16(binary.BigEndian.Uint16(src[rp:]))
|
weight := int16(binary.BigEndian.Uint16(src[rp:]))
|
||||||
rp += 2
|
rp += 2
|
||||||
sign := int16(binary.BigEndian.Uint16(src[rp:]))
|
sign := uint16(binary.BigEndian.Uint16(src[rp:]))
|
||||||
rp += 2
|
rp += 2
|
||||||
dscale := int16(binary.BigEndian.Uint16(src[rp:]))
|
dscale := int16(binary.BigEndian.Uint16(src[rp:]))
|
||||||
rp += 2
|
rp += 2
|
||||||
@@ -573,11 +573,7 @@ func (src Numeric) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if src.NaN {
|
if src.NaN {
|
||||||
// encode as 'NaN' including single quotes,
|
buf = append(buf, "NaN"...)
|
||||||
// "When writing this value [NaN] as a constant in an SQL command,
|
|
||||||
// you must put quotes around it, for example UPDATE table SET x = 'NaN'"
|
|
||||||
// https://www.postgresql.org/docs/9.3/datatype-numeric.html
|
|
||||||
buf = append(buf, "'NaN'"...)
|
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -15,7 +15,8 @@ import (
|
|||||||
func numericEqual(left, right *pgtype.Numeric) bool {
|
func numericEqual(left, right *pgtype.Numeric) bool {
|
||||||
return left.Status == right.Status &&
|
return left.Status == right.Status &&
|
||||||
left.Exp == right.Exp &&
|
left.Exp == right.Exp &&
|
||||||
((left.Int == nil && right.Int == nil) || (left.Int != nil && right.Int != nil && left.Int.Cmp(right.Int) == 0))
|
((left.Int == nil && right.Int == nil) || (left.Int != nil && right.Int != nil && left.Int.Cmp(right.Int) == 0)) &&
|
||||||
|
left.NaN == right.NaN
|
||||||
}
|
}
|
||||||
|
|
||||||
// For test purposes only.
|
// For test purposes only.
|
||||||
@@ -117,6 +118,8 @@ func TestNumericNormalize(t *testing.T) {
|
|||||||
|
|
||||||
func TestNumericTranscode(t *testing.T) {
|
func TestNumericTranscode(t *testing.T) {
|
||||||
testutil.TestSuccessfulTranscodeEqFunc(t, "numeric", []interface{}{
|
testutil.TestSuccessfulTranscodeEqFunc(t, "numeric", []interface{}{
|
||||||
|
&pgtype.Numeric{NaN: true, Status: pgtype.Present},
|
||||||
|
|
||||||
&pgtype.Numeric{Int: big.NewInt(0), Exp: 0, Status: pgtype.Present},
|
&pgtype.Numeric{Int: big.NewInt(0), Exp: 0, Status: pgtype.Present},
|
||||||
&pgtype.Numeric{Int: big.NewInt(1), Exp: 0, Status: pgtype.Present},
|
&pgtype.Numeric{Int: big.NewInt(1), Exp: 0, Status: pgtype.Present},
|
||||||
&pgtype.Numeric{Int: big.NewInt(-1), Exp: 0, Status: pgtype.Present},
|
&pgtype.Numeric{Int: big.NewInt(-1), Exp: 0, Status: pgtype.Present},
|
||||||
|
|||||||
Reference in New Issue
Block a user