mirror of https://github.com/jackc/pgx.git
pgtype Int2, Int4, and Int8 fields include bit size
e.g. Instead of Int it is Int64. This matches the pattern set by the database/sql types.query-exec-mode
parent
872a7a9315
commit
d723a4ab6f
|
@ -18,19 +18,19 @@ func (w *int8Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *int8")
|
||||
}
|
||||
|
||||
if v.Int < math.MinInt8 {
|
||||
return fmt.Errorf("%d is less than minimum value for int8", v.Int)
|
||||
if v.Int64 < math.MinInt8 {
|
||||
return fmt.Errorf("%d is less than minimum value for int8", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxInt8 {
|
||||
return fmt.Errorf("%d is greater than maximum value for int8", v.Int)
|
||||
if v.Int64 > math.MaxInt8 {
|
||||
return fmt.Errorf("%d is greater than maximum value for int8", v.Int64)
|
||||
}
|
||||
*w = int8Wrapper(v.Int)
|
||||
*w = int8Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w int8Wrapper) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type int16Wrapper int16
|
||||
|
@ -42,19 +42,19 @@ func (w *int16Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *int16")
|
||||
}
|
||||
|
||||
if v.Int < math.MinInt16 {
|
||||
return fmt.Errorf("%d is less than minimum value for int16", v.Int)
|
||||
if v.Int64 < math.MinInt16 {
|
||||
return fmt.Errorf("%d is less than minimum value for int16", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxInt16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for int16", v.Int)
|
||||
if v.Int64 > math.MaxInt16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for int16", v.Int64)
|
||||
}
|
||||
*w = int16Wrapper(v.Int)
|
||||
*w = int16Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w int16Wrapper) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type int32Wrapper int32
|
||||
|
@ -66,19 +66,19 @@ func (w *int32Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *int32")
|
||||
}
|
||||
|
||||
if v.Int < math.MinInt32 {
|
||||
return fmt.Errorf("%d is less than minimum value for int32", v.Int)
|
||||
if v.Int64 < math.MinInt32 {
|
||||
return fmt.Errorf("%d is less than minimum value for int32", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxInt32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for int32", v.Int)
|
||||
if v.Int64 > math.MaxInt32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for int32", v.Int64)
|
||||
}
|
||||
*w = int32Wrapper(v.Int)
|
||||
*w = int32Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w int32Wrapper) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type int64Wrapper int64
|
||||
|
@ -90,13 +90,13 @@ func (w *int64Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *int64")
|
||||
}
|
||||
|
||||
*w = int64Wrapper(v.Int)
|
||||
*w = int64Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w int64Wrapper) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type intWrapper int
|
||||
|
@ -108,20 +108,20 @@ func (w *intWrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *int")
|
||||
}
|
||||
|
||||
if v.Int < math.MinInt {
|
||||
return fmt.Errorf("%d is less than minimum value for int", v.Int)
|
||||
if v.Int64 < math.MinInt {
|
||||
return fmt.Errorf("%d is less than minimum value for int", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxInt {
|
||||
return fmt.Errorf("%d is greater than maximum value for int", v.Int)
|
||||
if v.Int64 > math.MaxInt {
|
||||
return fmt.Errorf("%d is greater than maximum value for int", v.Int64)
|
||||
}
|
||||
|
||||
*w = intWrapper(v.Int)
|
||||
*w = intWrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w intWrapper) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type uint8Wrapper uint8
|
||||
|
@ -133,19 +133,19 @@ func (w *uint8Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *uint8")
|
||||
}
|
||||
|
||||
if v.Int < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint8", v.Int)
|
||||
if v.Int64 < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint8", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxUint8 {
|
||||
return fmt.Errorf("%d is greater than maximum value for uint8", v.Int)
|
||||
if v.Int64 > math.MaxUint8 {
|
||||
return fmt.Errorf("%d is greater than maximum value for uint8", v.Int64)
|
||||
}
|
||||
*w = uint8Wrapper(v.Int)
|
||||
*w = uint8Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w uint8Wrapper) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type uint16Wrapper uint16
|
||||
|
@ -157,19 +157,19 @@ func (w *uint16Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *uint16")
|
||||
}
|
||||
|
||||
if v.Int < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint16", v.Int)
|
||||
if v.Int64 < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint16", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxUint16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for uint16", v.Int)
|
||||
if v.Int64 > math.MaxUint16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for uint16", v.Int64)
|
||||
}
|
||||
*w = uint16Wrapper(v.Int)
|
||||
*w = uint16Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w uint16Wrapper) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type uint32Wrapper uint32
|
||||
|
@ -181,19 +181,19 @@ func (w *uint32Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *uint32")
|
||||
}
|
||||
|
||||
if v.Int < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint32", v.Int)
|
||||
if v.Int64 < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint32", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxUint32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for uint32", v.Int)
|
||||
if v.Int64 > math.MaxUint32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for uint32", v.Int64)
|
||||
}
|
||||
*w = uint32Wrapper(v.Int)
|
||||
*w = uint32Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w uint32Wrapper) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type uint64Wrapper uint64
|
||||
|
@ -205,11 +205,11 @@ func (w *uint64Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *uint64")
|
||||
}
|
||||
|
||||
if v.Int < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint64", v.Int)
|
||||
if v.Int64 < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint64", v.Int64)
|
||||
}
|
||||
|
||||
*w = uint64Wrapper(v.Int)
|
||||
*w = uint64Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ func (w uint64Wrapper) Int64Value() (Int8, error) {
|
|||
return Int8{}, fmt.Errorf("%d is greater than maximum value for int64", w)
|
||||
}
|
||||
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type uintWrapper uint
|
||||
|
@ -231,15 +231,15 @@ func (w *uintWrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *uint64")
|
||||
}
|
||||
|
||||
if v.Int < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint64", v.Int)
|
||||
if v.Int64 < 0 {
|
||||
return fmt.Errorf("%d is less than minimum value for uint64", v.Int64)
|
||||
}
|
||||
|
||||
if uint64(v.Int) > math.MaxUint {
|
||||
return fmt.Errorf("%d is greater than maximum value for uint", v.Int)
|
||||
if uint64(v.Int64) > math.MaxUint {
|
||||
return fmt.Errorf("%d is greater than maximum value for uint", v.Int64)
|
||||
}
|
||||
|
||||
*w = uintWrapper(v.Int)
|
||||
*w = uintWrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ func (w uintWrapper) Int64Value() (Int8, error) {
|
|||
return Int8{}, fmt.Errorf("%d is greater than maximum value for int64", w)
|
||||
}
|
||||
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
type float32Wrapper float32
|
||||
|
@ -261,7 +261,7 @@ func (w *float32Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *float32")
|
||||
}
|
||||
|
||||
*w = float32Wrapper(v.Int)
|
||||
*w = float32Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ func (w float32Wrapper) Int64Value() (Int8, error) {
|
|||
return Int8{}, fmt.Errorf("%f is greater than maximum value for int64", w)
|
||||
}
|
||||
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
func (w *float32Wrapper) ScanFloat64(v Float8) error {
|
||||
|
@ -297,7 +297,7 @@ func (w *float64Wrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *float64")
|
||||
}
|
||||
|
||||
*w = float64Wrapper(v.Int)
|
||||
*w = float64Wrapper(v.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ func (w float64Wrapper) Int64Value() (Int8, error) {
|
|||
return Int8{}, fmt.Errorf("%f is greater than maximum value for int64", w)
|
||||
}
|
||||
|
||||
return Int8{Int: int64(w), Valid: true}, nil
|
||||
return Int8{Int64: int64(w), Valid: true}, nil
|
||||
}
|
||||
|
||||
func (w *float64Wrapper) ScanFloat64(v Float8) error {
|
||||
|
@ -346,7 +346,7 @@ func (w *stringWrapper) ScanInt64(v Int8) error {
|
|||
return fmt.Errorf("cannot scan NULL into *string")
|
||||
}
|
||||
|
||||
*w = stringWrapper(strconv.FormatInt(v.Int, 10))
|
||||
*w = stringWrapper(strconv.FormatInt(v.Int64, 10))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -357,7 +357,7 @@ func (w stringWrapper) Int64Value() (Int8, error) {
|
|||
return Int8{}, err
|
||||
}
|
||||
|
||||
return Int8{Int: int64(num), Valid: true}, nil
|
||||
return Int8{Int64: int64(num), Valid: true}, nil
|
||||
}
|
||||
|
||||
type timeWrapper time.Time
|
||||
|
|
|
@ -26,12 +26,12 @@ func (f Float4) Float64Value() (Float8, error) {
|
|||
}
|
||||
|
||||
func (f *Float4) ScanInt64(n Int8) error {
|
||||
*f = Float4{Float: float32(n.Int), Valid: n.Valid}
|
||||
*f = Float4{Float: float32(n.Int64), Valid: n.Valid}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f Float4) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(f.Float), Valid: f.Valid}, nil
|
||||
return Int8{Int64: int64(f.Float), Valid: f.Valid}, nil
|
||||
}
|
||||
|
||||
// Scan implements the database/sql Scanner interface.
|
||||
|
@ -141,7 +141,7 @@ func (encodePlanFloat4CodecBinaryInt64Valuer) Encode(value interface{}, buf []by
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
f := float32(n.Int)
|
||||
f := float32(n.Int64)
|
||||
return pgio.AppendUint32(buf, math.Float32bits(f)), nil
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ func (scanPlanBinaryFloat4ToInt64Scanner) Scan(src []byte, dst interface{}) erro
|
|||
return fmt.Errorf("cannot losslessly convert %v to int64", f32)
|
||||
}
|
||||
|
||||
return s.ScanInt64(Int8{Int: i64, Valid: true})
|
||||
return s.ScanInt64(Int8{Int64: i64, Valid: true})
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToFloat32 struct{}
|
||||
|
|
|
@ -34,12 +34,12 @@ func (f Float8) Float64Value() (Float8, error) {
|
|||
}
|
||||
|
||||
func (f *Float8) ScanInt64(n Int8) error {
|
||||
*f = Float8{Float: float64(n.Int), Valid: n.Valid}
|
||||
*f = Float8{Float: float64(n.Int64), Valid: n.Valid}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f Float8) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(f.Float), Valid: f.Valid}, nil
|
||||
return Int8{Int64: int64(f.Float), Valid: f.Valid}, nil
|
||||
}
|
||||
|
||||
// Scan implements the database/sql Scanner interface.
|
||||
|
@ -164,7 +164,7 @@ func (encodePlanFloat8CodecBinaryInt64Valuer) Encode(value interface{}, buf []by
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
f := float64(n.Int)
|
||||
f := float64(n.Int64)
|
||||
return pgio.AppendUint64(buf, math.Float64bits(f)), nil
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ func (encodePlanTextInt64Valuer) Encode(value interface{}, buf []byte) (newBuf [
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||
return append(buf, strconv.FormatInt(n.Int64, 10)...), nil
|
||||
}
|
||||
|
||||
func (Float8Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}) ScanPlan {
|
||||
|
@ -264,7 +264,7 @@ func (scanPlanBinaryFloat8ToInt64Scanner) Scan(src []byte, dst interface{}) erro
|
|||
return fmt.Errorf("cannot losslessly convert %v to int64", f64)
|
||||
}
|
||||
|
||||
return s.ScanInt64(Int8{Int: i64, Valid: true})
|
||||
return s.ScanInt64(Int8{Int64: i64, Valid: true})
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToFloat64 struct{}
|
||||
|
|
134
pgtype/int.go
134
pgtype/int.go
|
@ -21,7 +21,7 @@ type Int64Valuer interface {
|
|||
}
|
||||
|
||||
type Int2 struct {
|
||||
Int int16
|
||||
Int16 int16
|
||||
Valid bool
|
||||
}
|
||||
|
||||
|
@ -32,19 +32,19 @@ func (dst *Int2) ScanInt64(n Int8) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if n.Int < math.MinInt16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int2", n.Int)
|
||||
if n.Int64 < math.MinInt16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int2", n.Int64)
|
||||
}
|
||||
if n.Int > math.MaxInt16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int2", n.Int)
|
||||
if n.Int64 > math.MaxInt16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int2", n.Int64)
|
||||
}
|
||||
*dst = Int2{Int: int16(n.Int), Valid: true}
|
||||
*dst = Int2{Int16: int16(n.Int64), Valid: true}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n Int2) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(n.Int), Valid: n.Valid}, nil
|
||||
return Int8{Int64: int64(n.Int16), Valid: n.Valid}, nil
|
||||
}
|
||||
|
||||
// Scan implements the database/sql Scanner interface.
|
||||
|
@ -81,7 +81,7 @@ func (dst *Int2) Scan(src interface{}) error {
|
|||
if n > math.MaxInt16 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int2", n)
|
||||
}
|
||||
*dst = Int2{Int: int16(n), Valid: true}
|
||||
*dst = Int2{Int16: int16(n), Valid: true}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -91,14 +91,14 @@ func (src Int2) Value() (driver.Value, error) {
|
|||
if !src.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(src.Int), nil
|
||||
return int64(src.Int16), nil
|
||||
}
|
||||
|
||||
func (src Int2) MarshalJSON() ([]byte, error) {
|
||||
if !src.Valid {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(src.Int), 10)), nil
|
||||
return []byte(strconv.FormatInt(int64(src.Int16), 10)), nil
|
||||
}
|
||||
|
||||
func (dst *Int2) UnmarshalJSON(b []byte) error {
|
||||
|
@ -111,7 +111,7 @@ func (dst *Int2) UnmarshalJSON(b []byte) error {
|
|||
if n == nil {
|
||||
*dst = Int2{}
|
||||
} else {
|
||||
*dst = Int2{Int: *n, Valid: true}
|
||||
*dst = Int2{Int16: *n, Valid: true}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -174,14 +174,14 @@ func (encodePlanInt2CodecBinaryInt64Valuer) Encode(value interface{}, buf []byte
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.Int > math.MaxInt16 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int2", n.Int)
|
||||
if n.Int64 > math.MaxInt16 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int2", n.Int64)
|
||||
}
|
||||
if n.Int < math.MinInt16 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int2", n.Int)
|
||||
if n.Int64 < math.MinInt16 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int2", n.Int64)
|
||||
}
|
||||
|
||||
return pgio.AppendInt16(buf, int16(n.Int)), nil
|
||||
return pgio.AppendInt16(buf, int16(n.Int64)), nil
|
||||
}
|
||||
|
||||
type encodePlanInt2CodecTextInt64Valuer struct{}
|
||||
|
@ -196,14 +196,14 @@ func (encodePlanInt2CodecTextInt64Valuer) Encode(value interface{}, buf []byte)
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.Int > math.MaxInt16 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int2", n.Int)
|
||||
if n.Int64 > math.MaxInt16 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int2", n.Int64)
|
||||
}
|
||||
if n.Int < math.MinInt16 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int2", n.Int)
|
||||
if n.Int64 < math.MinInt16 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int2", n.Int64)
|
||||
}
|
||||
|
||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||
return append(buf, strconv.FormatInt(n.Int64, 10)...), nil
|
||||
}
|
||||
|
||||
func (Int2Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}) ScanPlan {
|
||||
|
@ -554,11 +554,11 @@ func (scanPlanBinaryInt2ToInt64Scanner) Scan(src []byte, dst interface{}) error
|
|||
|
||||
n := int64(int16(binary.BigEndian.Uint16(src)))
|
||||
|
||||
return s.ScanInt64(Int8{Int: n, Valid: true})
|
||||
return s.ScanInt64(Int8{Int64: n, Valid: true})
|
||||
}
|
||||
|
||||
type Int4 struct {
|
||||
Int int32
|
||||
Int32 int32
|
||||
Valid bool
|
||||
}
|
||||
|
||||
|
@ -569,19 +569,19 @@ func (dst *Int4) ScanInt64(n Int8) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if n.Int < math.MinInt32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int4", n.Int)
|
||||
if n.Int64 < math.MinInt32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int4", n.Int64)
|
||||
}
|
||||
if n.Int > math.MaxInt32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int4", n.Int)
|
||||
if n.Int64 > math.MaxInt32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int4", n.Int64)
|
||||
}
|
||||
*dst = Int4{Int: int32(n.Int), Valid: true}
|
||||
*dst = Int4{Int32: int32(n.Int64), Valid: true}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n Int4) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(n.Int), Valid: n.Valid}, nil
|
||||
return Int8{Int64: int64(n.Int32), Valid: n.Valid}, nil
|
||||
}
|
||||
|
||||
// Scan implements the database/sql Scanner interface.
|
||||
|
@ -618,7 +618,7 @@ func (dst *Int4) Scan(src interface{}) error {
|
|||
if n > math.MaxInt32 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int4", n)
|
||||
}
|
||||
*dst = Int4{Int: int32(n), Valid: true}
|
||||
*dst = Int4{Int32: int32(n), Valid: true}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -628,14 +628,14 @@ func (src Int4) Value() (driver.Value, error) {
|
|||
if !src.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(src.Int), nil
|
||||
return int64(src.Int32), nil
|
||||
}
|
||||
|
||||
func (src Int4) MarshalJSON() ([]byte, error) {
|
||||
if !src.Valid {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(src.Int), 10)), nil
|
||||
return []byte(strconv.FormatInt(int64(src.Int32), 10)), nil
|
||||
}
|
||||
|
||||
func (dst *Int4) UnmarshalJSON(b []byte) error {
|
||||
|
@ -648,7 +648,7 @@ func (dst *Int4) UnmarshalJSON(b []byte) error {
|
|||
if n == nil {
|
||||
*dst = Int4{}
|
||||
} else {
|
||||
*dst = Int4{Int: *n, Valid: true}
|
||||
*dst = Int4{Int32: *n, Valid: true}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -711,14 +711,14 @@ func (encodePlanInt4CodecBinaryInt64Valuer) Encode(value interface{}, buf []byte
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.Int > math.MaxInt32 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int4", n.Int)
|
||||
if n.Int64 > math.MaxInt32 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int4", n.Int64)
|
||||
}
|
||||
if n.Int < math.MinInt32 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int4", n.Int)
|
||||
if n.Int64 < math.MinInt32 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int4", n.Int64)
|
||||
}
|
||||
|
||||
return pgio.AppendInt32(buf, int32(n.Int)), nil
|
||||
return pgio.AppendInt32(buf, int32(n.Int64)), nil
|
||||
}
|
||||
|
||||
type encodePlanInt4CodecTextInt64Valuer struct{}
|
||||
|
@ -733,14 +733,14 @@ func (encodePlanInt4CodecTextInt64Valuer) Encode(value interface{}, buf []byte)
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.Int > math.MaxInt32 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int4", n.Int)
|
||||
if n.Int64 > math.MaxInt32 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int4", n.Int64)
|
||||
}
|
||||
if n.Int < math.MinInt32 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int4", n.Int)
|
||||
if n.Int64 < math.MinInt32 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int4", n.Int64)
|
||||
}
|
||||
|
||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||
return append(buf, strconv.FormatInt(n.Int64, 10)...), nil
|
||||
}
|
||||
|
||||
func (Int4Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}) ScanPlan {
|
||||
|
@ -1102,11 +1102,11 @@ func (scanPlanBinaryInt4ToInt64Scanner) Scan(src []byte, dst interface{}) error
|
|||
|
||||
n := int64(int32(binary.BigEndian.Uint32(src)))
|
||||
|
||||
return s.ScanInt64(Int8{Int: n, Valid: true})
|
||||
return s.ScanInt64(Int8{Int64: n, Valid: true})
|
||||
}
|
||||
|
||||
type Int8 struct {
|
||||
Int int64
|
||||
Int64 int64
|
||||
Valid bool
|
||||
}
|
||||
|
||||
|
@ -1117,19 +1117,19 @@ func (dst *Int8) ScanInt64(n Int8) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if n.Int < math.MinInt64 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int8", n.Int)
|
||||
if n.Int64 < math.MinInt64 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int8", n.Int64)
|
||||
}
|
||||
if n.Int > math.MaxInt64 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int8", n.Int)
|
||||
if n.Int64 > math.MaxInt64 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int8", n.Int64)
|
||||
}
|
||||
*dst = Int8{Int: int64(n.Int), Valid: true}
|
||||
*dst = Int8{Int64: int64(n.Int64), Valid: true}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n Int8) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(n.Int), Valid: n.Valid}, nil
|
||||
return Int8{Int64: int64(n.Int64), Valid: n.Valid}, nil
|
||||
}
|
||||
|
||||
// Scan implements the database/sql Scanner interface.
|
||||
|
@ -1166,7 +1166,7 @@ func (dst *Int8) Scan(src interface{}) error {
|
|||
if n > math.MaxInt64 {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int8", n)
|
||||
}
|
||||
*dst = Int8{Int: int64(n), Valid: true}
|
||||
*dst = Int8{Int64: int64(n), Valid: true}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -1176,14 +1176,14 @@ func (src Int8) Value() (driver.Value, error) {
|
|||
if !src.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(src.Int), nil
|
||||
return int64(src.Int64), nil
|
||||
}
|
||||
|
||||
func (src Int8) MarshalJSON() ([]byte, error) {
|
||||
if !src.Valid {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(src.Int), 10)), nil
|
||||
return []byte(strconv.FormatInt(int64(src.Int64), 10)), nil
|
||||
}
|
||||
|
||||
func (dst *Int8) UnmarshalJSON(b []byte) error {
|
||||
|
@ -1196,7 +1196,7 @@ func (dst *Int8) UnmarshalJSON(b []byte) error {
|
|||
if n == nil {
|
||||
*dst = Int8{}
|
||||
} else {
|
||||
*dst = Int8{Int: *n, Valid: true}
|
||||
*dst = Int8{Int64: *n, Valid: true}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1259,14 +1259,14 @@ func (encodePlanInt8CodecBinaryInt64Valuer) Encode(value interface{}, buf []byte
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.Int > math.MaxInt64 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int8", n.Int)
|
||||
if n.Int64 > math.MaxInt64 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int8", n.Int64)
|
||||
}
|
||||
if n.Int < math.MinInt64 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int8", n.Int)
|
||||
if n.Int64 < math.MinInt64 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int8", n.Int64)
|
||||
}
|
||||
|
||||
return pgio.AppendInt64(buf, int64(n.Int)), nil
|
||||
return pgio.AppendInt64(buf, int64(n.Int64)), nil
|
||||
}
|
||||
|
||||
type encodePlanInt8CodecTextInt64Valuer struct{}
|
||||
|
@ -1281,14 +1281,14 @@ func (encodePlanInt8CodecTextInt64Valuer) Encode(value interface{}, buf []byte)
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.Int > math.MaxInt64 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int8", n.Int)
|
||||
if n.Int64 > math.MaxInt64 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int8", n.Int64)
|
||||
}
|
||||
if n.Int < math.MinInt64 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int8", n.Int)
|
||||
if n.Int64 < math.MinInt64 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int8", n.Int64)
|
||||
}
|
||||
|
||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||
return append(buf, strconv.FormatInt(n.Int64, 10)...), nil
|
||||
}
|
||||
|
||||
func (Int8Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}) ScanPlan {
|
||||
|
@ -1672,7 +1672,7 @@ func (scanPlanBinaryInt8ToInt64Scanner) Scan(src []byte, dst interface{}) error
|
|||
|
||||
n := int64(int64(binary.BigEndian.Uint64(src)))
|
||||
|
||||
return s.ScanInt64(Int8{Int: n, Valid: true})
|
||||
return s.ScanInt64(Int8{Int64: n, Valid: true})
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToInt8 struct{}
|
||||
|
@ -1902,7 +1902,7 @@ func (scanPlanTextAnyToInt64Scanner) Scan(src []byte, dst interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = s.ScanInt64(Int8{Int: n, Valid: true})
|
||||
err = s.ScanInt64(Int8{Int64: n, Valid: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ type Int64Valuer interface {
|
|||
<% [2, 4, 8].each do |pg_byte_size| %>
|
||||
<% pg_bit_size = pg_byte_size * 8 %>
|
||||
type Int<%= pg_byte_size %> struct {
|
||||
Int int<%= pg_bit_size %>
|
||||
Int<%= pg_bit_size %> int<%= pg_bit_size %>
|
||||
Valid bool
|
||||
}
|
||||
|
||||
|
@ -33,19 +33,19 @@ func (dst *Int<%= pg_byte_size %>) ScanInt64(n Int8) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if n.Int < math.MinInt<%= pg_bit_size %> {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int<%= pg_byte_size %>", n.Int)
|
||||
if n.Int64 < math.MinInt<%= pg_bit_size %> {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int<%= pg_byte_size %>", n.Int64)
|
||||
}
|
||||
if n.Int > math.MaxInt<%= pg_bit_size %> {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int<%= pg_byte_size %>", n.Int)
|
||||
if n.Int64 > math.MaxInt<%= pg_bit_size %> {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int<%= pg_byte_size %>", n.Int64)
|
||||
}
|
||||
*dst = Int<%= pg_byte_size %>{Int: int<%= pg_bit_size %>(n.Int), Valid: true}
|
||||
*dst = Int<%= pg_byte_size %>{Int<%= pg_bit_size %>: int<%= pg_bit_size %>(n.Int64), Valid: true}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n Int<%= pg_byte_size %>) Int64Value() (Int8, error) {
|
||||
return Int8{Int: int64(n.Int), Valid: n.Valid}, nil
|
||||
return Int8{Int64: int64(n.Int<%= pg_bit_size %>), Valid: n.Valid}, nil
|
||||
}
|
||||
|
||||
// Scan implements the database/sql Scanner interface.
|
||||
|
@ -82,7 +82,7 @@ func (dst *Int<%= pg_byte_size %>) Scan(src interface{}) error {
|
|||
if n > math.MaxInt<%= pg_bit_size %> {
|
||||
return fmt.Errorf("%d is greater than maximum value for Int<%= pg_byte_size %>", n)
|
||||
}
|
||||
*dst = Int<%= pg_byte_size %>{Int: int<%= pg_bit_size %>(n), Valid: true}
|
||||
*dst = Int<%= pg_byte_size %>{Int<%= pg_bit_size %>: int<%= pg_bit_size %>(n), Valid: true}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -92,14 +92,14 @@ func (src Int<%= pg_byte_size %>) Value() (driver.Value, error) {
|
|||
if !src.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(src.Int), nil
|
||||
return int64(src.Int<%= pg_bit_size %>), nil
|
||||
}
|
||||
|
||||
func (src Int<%= pg_byte_size %>) MarshalJSON() ([]byte, error) {
|
||||
if !src.Valid {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(src.Int), 10)), nil
|
||||
return []byte(strconv.FormatInt(int64(src.Int<%= pg_bit_size %>), 10)), nil
|
||||
}
|
||||
|
||||
func (dst *Int<%= pg_byte_size %>) UnmarshalJSON(b []byte) error {
|
||||
|
@ -112,7 +112,7 @@ func (dst *Int<%= pg_byte_size %>) UnmarshalJSON(b []byte) error {
|
|||
if n == nil {
|
||||
*dst = Int<%= pg_byte_size %>{}
|
||||
} else {
|
||||
*dst = Int<%= pg_byte_size %>{Int: *n, Valid: true}
|
||||
*dst = Int<%= pg_byte_size %>{Int<%= pg_bit_size %>: *n, Valid: true}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -175,14 +175,14 @@ func (encodePlanInt<%= pg_byte_size %>CodecBinaryInt64Valuer) Encode(value inter
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.Int > math.MaxInt<%= pg_bit_size %> {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int<%= pg_byte_size %>", n.Int)
|
||||
if n.Int64 > math.MaxInt<%= pg_bit_size %> {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int<%= pg_byte_size %>", n.Int64)
|
||||
}
|
||||
if n.Int < math.MinInt<%= pg_bit_size %> {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int<%= pg_byte_size %>", n.Int)
|
||||
if n.Int64 < math.MinInt<%= pg_bit_size %> {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int<%= pg_byte_size %>", n.Int64)
|
||||
}
|
||||
|
||||
return pgio.AppendInt<%= pg_bit_size %>(buf, int<%= pg_bit_size %>(n.Int)), nil
|
||||
return pgio.AppendInt<%= pg_bit_size %>(buf, int<%= pg_bit_size %>(n.Int64)), nil
|
||||
}
|
||||
|
||||
type encodePlanInt<%= pg_byte_size %>CodecTextInt64Valuer struct{}
|
||||
|
@ -197,14 +197,14 @@ func (encodePlanInt<%= pg_byte_size %>CodecTextInt64Valuer) Encode(value interfa
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if n.Int > math.MaxInt<%= pg_bit_size %> {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int<%= pg_byte_size %>", n.Int)
|
||||
if n.Int64 > math.MaxInt<%= pg_bit_size %> {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for int<%= pg_byte_size %>", n.Int64)
|
||||
}
|
||||
if n.Int < math.MinInt<%= pg_bit_size %> {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int<%= pg_byte_size %>", n.Int)
|
||||
if n.Int64 < math.MinInt<%= pg_bit_size %> {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for int<%= pg_byte_size %>", n.Int64)
|
||||
}
|
||||
|
||||
return append(buf, strconv.FormatInt(n.Int, 10)...), nil
|
||||
return append(buf, strconv.FormatInt(n.Int64, 10)...), nil
|
||||
}
|
||||
|
||||
func (Int<%= pg_byte_size %>Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}) ScanPlan {
|
||||
|
@ -441,7 +441,7 @@ func (scanPlanBinaryInt<%= pg_byte_size %>ToInt64Scanner) Scan(src []byte, dst i
|
|||
|
||||
n := int64(int<%= pg_bit_size %>(binary.BigEndian.Uint<%= pg_bit_size %>(src)))
|
||||
|
||||
return s.ScanInt64(Int8{Int: n, Valid: true})
|
||||
return s.ScanInt64(Int8{Int64: n, Valid: true})
|
||||
}
|
||||
<% end %>
|
||||
|
||||
|
@ -513,7 +513,7 @@ func (scanPlanTextAnyToInt64Scanner) Scan(src []byte, dst interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = s.ScanInt64(Int8{Int: n, Valid: true})
|
||||
err = s.ScanInt64(Int8{Int64: n, Valid: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ func TestInt2Codec(t *testing.T) {
|
|||
{uint64(1), new(int16), isExpectedEq(int16(1))},
|
||||
{int(1), new(int16), isExpectedEq(int16(1))},
|
||||
{uint(1), new(int16), isExpectedEq(int16(1))},
|
||||
{pgtype.Int2{Int: 1, Valid: true}, new(int16), isExpectedEq(int16(1))},
|
||||
{int32(-1), new(pgtype.Int2), isExpectedEq(pgtype.Int2{Int: -1, Valid: true})},
|
||||
{pgtype.Int2{Int16: 1, Valid: true}, new(int16), isExpectedEq(int16(1))},
|
||||
{int32(-1), new(pgtype.Int2), isExpectedEq(pgtype.Int2{Int16: -1, Valid: true})},
|
||||
{1, new(int8), isExpectedEq(int8(1))},
|
||||
{1, new(int16), isExpectedEq(int16(1))},
|
||||
{1, new(int32), isExpectedEq(int32(1))},
|
||||
|
@ -43,7 +43,7 @@ func TestInt2Codec(t *testing.T) {
|
|||
{0, new(int16), isExpectedEq(int16(0))},
|
||||
{1, new(int16), isExpectedEq(int16(1))},
|
||||
{math.MaxInt16, new(int16), isExpectedEq(int16(math.MaxInt16))},
|
||||
{1, new(pgtype.Int2), isExpectedEq(pgtype.Int2{Int: 1, Valid: true})},
|
||||
{1, new(pgtype.Int2), isExpectedEq(pgtype.Int2{Int16: 1, Valid: true})},
|
||||
{pgtype.Int2{}, new(pgtype.Int2), isExpectedEq(pgtype.Int2{})},
|
||||
{nil, new(*int16), isExpectedEq((*int16)(nil))},
|
||||
})
|
||||
|
@ -54,8 +54,8 @@ func TestInt2MarshalJSON(t *testing.T) {
|
|||
source pgtype.Int2
|
||||
result string
|
||||
}{
|
||||
{source: pgtype.Int2{Int: 0}, result: "null"},
|
||||
{source: pgtype.Int2{Int: 1, Valid: true}, result: "1"},
|
||||
{source: pgtype.Int2{Int16: 0}, result: "null"},
|
||||
{source: pgtype.Int2{Int16: 1, Valid: true}, result: "1"},
|
||||
}
|
||||
for i, tt := range successfulTests {
|
||||
r, err := tt.source.MarshalJSON()
|
||||
|
@ -74,8 +74,8 @@ func TestInt2UnmarshalJSON(t *testing.T) {
|
|||
source string
|
||||
result pgtype.Int2
|
||||
}{
|
||||
{source: "null", result: pgtype.Int2{Int: 0}},
|
||||
{source: "1", result: pgtype.Int2{Int: 1, Valid: true}},
|
||||
{source: "null", result: pgtype.Int2{Int16: 0}},
|
||||
{source: "1", result: pgtype.Int2{Int16: 1, Valid: true}},
|
||||
}
|
||||
for i, tt := range successfulTests {
|
||||
var r pgtype.Int2
|
||||
|
@ -102,8 +102,8 @@ func TestInt4Codec(t *testing.T) {
|
|||
{uint64(1), new(int32), isExpectedEq(int32(1))},
|
||||
{int(1), new(int32), isExpectedEq(int32(1))},
|
||||
{uint(1), new(int32), isExpectedEq(int32(1))},
|
||||
{pgtype.Int4{Int: 1, Valid: true}, new(int32), isExpectedEq(int32(1))},
|
||||
{int32(-1), new(pgtype.Int4), isExpectedEq(pgtype.Int4{Int: -1, Valid: true})},
|
||||
{pgtype.Int4{Int32: 1, Valid: true}, new(int32), isExpectedEq(int32(1))},
|
||||
{int32(-1), new(pgtype.Int4), isExpectedEq(pgtype.Int4{Int32: -1, Valid: true})},
|
||||
{1, new(int8), isExpectedEq(int8(1))},
|
||||
{1, new(int16), isExpectedEq(int16(1))},
|
||||
{1, new(int32), isExpectedEq(int32(1))},
|
||||
|
@ -124,7 +124,7 @@ func TestInt4Codec(t *testing.T) {
|
|||
{0, new(int32), isExpectedEq(int32(0))},
|
||||
{1, new(int32), isExpectedEq(int32(1))},
|
||||
{math.MaxInt32, new(int32), isExpectedEq(int32(math.MaxInt32))},
|
||||
{1, new(pgtype.Int4), isExpectedEq(pgtype.Int4{Int: 1, Valid: true})},
|
||||
{1, new(pgtype.Int4), isExpectedEq(pgtype.Int4{Int32: 1, Valid: true})},
|
||||
{pgtype.Int4{}, new(pgtype.Int4), isExpectedEq(pgtype.Int4{})},
|
||||
{nil, new(*int32), isExpectedEq((*int32)(nil))},
|
||||
})
|
||||
|
@ -135,8 +135,8 @@ func TestInt4MarshalJSON(t *testing.T) {
|
|||
source pgtype.Int4
|
||||
result string
|
||||
}{
|
||||
{source: pgtype.Int4{Int: 0}, result: "null"},
|
||||
{source: pgtype.Int4{Int: 1, Valid: true}, result: "1"},
|
||||
{source: pgtype.Int4{Int32: 0}, result: "null"},
|
||||
{source: pgtype.Int4{Int32: 1, Valid: true}, result: "1"},
|
||||
}
|
||||
for i, tt := range successfulTests {
|
||||
r, err := tt.source.MarshalJSON()
|
||||
|
@ -155,8 +155,8 @@ func TestInt4UnmarshalJSON(t *testing.T) {
|
|||
source string
|
||||
result pgtype.Int4
|
||||
}{
|
||||
{source: "null", result: pgtype.Int4{Int: 0}},
|
||||
{source: "1", result: pgtype.Int4{Int: 1, Valid: true}},
|
||||
{source: "null", result: pgtype.Int4{Int32: 0}},
|
||||
{source: "1", result: pgtype.Int4{Int32: 1, Valid: true}},
|
||||
}
|
||||
for i, tt := range successfulTests {
|
||||
var r pgtype.Int4
|
||||
|
@ -183,8 +183,8 @@ func TestInt8Codec(t *testing.T) {
|
|||
{uint64(1), new(int64), isExpectedEq(int64(1))},
|
||||
{int(1), new(int64), isExpectedEq(int64(1))},
|
||||
{uint(1), new(int64), isExpectedEq(int64(1))},
|
||||
{pgtype.Int8{Int: 1, Valid: true}, new(int64), isExpectedEq(int64(1))},
|
||||
{int32(-1), new(pgtype.Int8), isExpectedEq(pgtype.Int8{Int: -1, Valid: true})},
|
||||
{pgtype.Int8{Int64: 1, Valid: true}, new(int64), isExpectedEq(int64(1))},
|
||||
{int32(-1), new(pgtype.Int8), isExpectedEq(pgtype.Int8{Int64: -1, Valid: true})},
|
||||
{1, new(int8), isExpectedEq(int8(1))},
|
||||
{1, new(int16), isExpectedEq(int16(1))},
|
||||
{1, new(int32), isExpectedEq(int32(1))},
|
||||
|
@ -205,7 +205,7 @@ func TestInt8Codec(t *testing.T) {
|
|||
{0, new(int64), isExpectedEq(int64(0))},
|
||||
{1, new(int64), isExpectedEq(int64(1))},
|
||||
{math.MaxInt64, new(int64), isExpectedEq(int64(math.MaxInt64))},
|
||||
{1, new(pgtype.Int8), isExpectedEq(pgtype.Int8{Int: 1, Valid: true})},
|
||||
{1, new(pgtype.Int8), isExpectedEq(pgtype.Int8{Int64: 1, Valid: true})},
|
||||
{pgtype.Int8{}, new(pgtype.Int8), isExpectedEq(pgtype.Int8{})},
|
||||
{nil, new(*int64), isExpectedEq((*int64)(nil))},
|
||||
})
|
||||
|
@ -216,8 +216,8 @@ func TestInt8MarshalJSON(t *testing.T) {
|
|||
source pgtype.Int8
|
||||
result string
|
||||
}{
|
||||
{source: pgtype.Int8{Int: 0}, result: "null"},
|
||||
{source: pgtype.Int8{Int: 1, Valid: true}, result: "1"},
|
||||
{source: pgtype.Int8{Int64: 0}, result: "null"},
|
||||
{source: pgtype.Int8{Int64: 1, Valid: true}, result: "1"},
|
||||
}
|
||||
for i, tt := range successfulTests {
|
||||
r, err := tt.source.MarshalJSON()
|
||||
|
@ -236,8 +236,8 @@ func TestInt8UnmarshalJSON(t *testing.T) {
|
|||
source string
|
||||
result pgtype.Int8
|
||||
}{
|
||||
{source: "null", result: pgtype.Int8{Int: 0}},
|
||||
{source: "1", result: pgtype.Int8{Int: 1, Valid: true}},
|
||||
{source: "null", result: pgtype.Int8{Int64: 0}},
|
||||
{source: "1", result: pgtype.Int8{Int64: 1, Valid: true}},
|
||||
}
|
||||
for i, tt := range successfulTests {
|
||||
var r pgtype.Int8
|
||||
|
|
|
@ -324,7 +324,7 @@ func (encodePlanNumericCodecBinaryInt64Valuer) Encode(value interface{}, buf []b
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
return encodeNumericBinary(Numeric{Int: big.NewInt(n.Int), Valid: true}, buf)
|
||||
return encodeNumericBinary(Numeric{Int: big.NewInt(n.Int64), Valid: true}, buf)
|
||||
}
|
||||
|
||||
func encodeNumericBinary(n Numeric, buf []byte) (newBuf []byte, err error) {
|
||||
|
@ -476,7 +476,7 @@ func (encodePlanNumericCodecTextInt64Valuer) Encode(value interface{}, buf []byt
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
return encodeNumericText(Numeric{Int: big.NewInt(n.Int), Valid: true}, buf)
|
||||
return encodeNumericText(Numeric{Int: big.NewInt(n.Int64), Valid: true}, buf)
|
||||
}
|
||||
|
||||
func encodeNumericText(n Numeric, buf []byte) (newBuf []byte, err error) {
|
||||
|
@ -682,7 +682,7 @@ func (scanPlanBinaryNumericToInt64Scanner) Scan(src []byte, dst interface{}) err
|
|||
return fmt.Errorf("%v is out of range for int64", bigInt)
|
||||
}
|
||||
|
||||
return scanner.ScanInt64(Int8{Int: bigInt.Int64(), Valid: true})
|
||||
return scanner.ScanInt64(Int8{Int64: bigInt.Int64(), Valid: true})
|
||||
}
|
||||
|
||||
type scanPlanTextAnyToNumericScanner struct{}
|
||||
|
|
|
@ -205,7 +205,7 @@ func BenchmarkTypeMapScanInt4IntoBinaryDecoder(b *testing.B) {
|
|||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if v != (pgtype.Int4{Int: 42, Valid: true}) {
|
||||
if v != (pgtype.Int4{Int32: 42, Valid: true}) {
|
||||
b.Fatal("scan failed due to bad value")
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ func BenchmarkScanPlanScanInt4IntoBinaryDecoder(b *testing.B) {
|
|||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if v != (pgtype.Int4{Int: 42, Valid: true}) {
|
||||
if v != (pgtype.Int4{Int32: 42, Valid: true}) {
|
||||
b.Fatal("scan failed due to bad value")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,15 @@ func TestRangeCodecTranscode(t *testing.T) {
|
|||
{
|
||||
pgtype.Int4range{
|
||||
LowerType: pgtype.Inclusive,
|
||||
Lower: pgtype.Int4{Int: 1, Valid: true},
|
||||
Upper: pgtype.Int4{Int: 5, Valid: true},
|
||||
Lower: pgtype.Int4{Int32: 1, Valid: true},
|
||||
Upper: pgtype.Int4{Int32: 5, Valid: true},
|
||||
UpperType: pgtype.Exclusive, Valid: true,
|
||||
},
|
||||
new(pgtype.Int4range),
|
||||
isExpectedEq(pgtype.Int4range{
|
||||
LowerType: pgtype.Inclusive,
|
||||
Lower: pgtype.Int4{Int: 1, Valid: true},
|
||||
Upper: pgtype.Int4{Int: 5, Valid: true},
|
||||
Lower: pgtype.Int4{Int32: 1, Valid: true},
|
||||
Upper: pgtype.Int4{Int32: 5, Valid: true},
|
||||
UpperType: pgtype.Exclusive, Valid: true,
|
||||
}),
|
||||
},
|
||||
|
@ -75,8 +75,8 @@ func TestRangeCodecScanRangeTwiceWithUnbounded(t *testing.T) {
|
|||
require.Equal(
|
||||
t,
|
||||
pgtype.Int4range{
|
||||
Lower: pgtype.Int4{Int: 1, Valid: true},
|
||||
Upper: pgtype.Int4{Int: 5, Valid: true},
|
||||
Lower: pgtype.Int4{Int32: 1, Valid: true},
|
||||
Upper: pgtype.Int4{Int32: 5, Valid: true},
|
||||
LowerType: pgtype.Inclusive,
|
||||
UpperType: pgtype.Exclusive,
|
||||
Valid: true,
|
||||
|
@ -90,7 +90,7 @@ func TestRangeCodecScanRangeTwiceWithUnbounded(t *testing.T) {
|
|||
require.Equal(
|
||||
t,
|
||||
pgtype.Int4range{
|
||||
Lower: pgtype.Int4{Int: 1, Valid: true},
|
||||
Lower: pgtype.Int4{Int32: 1, Valid: true},
|
||||
Upper: pgtype.Int4{},
|
||||
LowerType: pgtype.Inclusive,
|
||||
UpperType: pgtype.Unbounded,
|
||||
|
|
|
@ -142,14 +142,14 @@ func (encodePlanUint32CodecBinaryInt64Valuer) Encode(value interface{}, buf []by
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if v.Int < 0 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for uint32", v.Int)
|
||||
if v.Int64 < 0 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for uint32", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxUint32 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for uint32", v.Int)
|
||||
if v.Int64 > math.MaxUint32 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for uint32", v.Int64)
|
||||
}
|
||||
|
||||
return pgio.AppendUint32(buf, uint32(v.Int)), nil
|
||||
return pgio.AppendUint32(buf, uint32(v.Int64)), nil
|
||||
}
|
||||
|
||||
type encodePlanUint32CodecTextUint32 struct{}
|
||||
|
@ -186,14 +186,14 @@ func (encodePlanUint32CodecTextInt64Valuer) Encode(value interface{}, buf []byte
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if v.Int < 0 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for uint32", v.Int)
|
||||
if v.Int64 < 0 {
|
||||
return nil, fmt.Errorf("%d is less than minimum value for uint32", v.Int64)
|
||||
}
|
||||
if v.Int > math.MaxUint32 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for uint32", v.Int)
|
||||
if v.Int64 > math.MaxUint32 {
|
||||
return nil, fmt.Errorf("%d is greater than maximum value for uint32", v.Int64)
|
||||
}
|
||||
|
||||
return append(buf, strconv.FormatInt(v.Int, 10)...), nil
|
||||
return append(buf, strconv.FormatInt(v.Int64, 10)...), nil
|
||||
}
|
||||
|
||||
func (Uint32Codec) PlanScan(m *Map, oid uint32, format int16, target interface{}) ScanPlan {
|
||||
|
|
|
@ -44,7 +44,7 @@ func (dst *Int2) Scan(src interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
*dst = Int2(nullable.Int)
|
||||
*dst = Int2(nullable.Int16)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ func (dst *Int4) Scan(src interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
*dst = Int4(nullable.Int)
|
||||
*dst = Int4(nullable.Int32)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func (dst *Int8) Scan(src interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
*dst = Int8(nullable.Int)
|
||||
*dst = Int8(nullable.Int64)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func (dst *Int<%= pg_byte_size %>) Scan(src interface{}) error {
|
|||
return err
|
||||
}
|
||||
|
||||
*dst = Int<%= pg_byte_size %>(nullable.Int)
|
||||
*dst = Int<%= pg_byte_size %>(nullable.Int<%= pg_bit_size %>)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue