mirror of https://github.com/jackc/pgx.git
Encode* should be value, not pointer to value
parent
32a368a75b
commit
6eac791f51
20
values.go
20
values.go
|
@ -81,7 +81,7 @@ func (n *NullFloat32) Scan(rows *Rows, fd *FieldDescription, size int32) error {
|
|||
return rows.Err()
|
||||
}
|
||||
|
||||
func (n *NullFloat32) EncodeText() (string, error) {
|
||||
func (n NullFloat32) EncodeText() (string, error) {
|
||||
if n.Valid {
|
||||
return strconv.FormatFloat(float64(n.Float32), 'f', -1, 32), nil
|
||||
} else {
|
||||
|
@ -89,7 +89,7 @@ func (n *NullFloat32) EncodeText() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *NullFloat32) EncodeBinary(w *WriteBuf) error {
|
||||
func (n NullFloat32) EncodeBinary(w *WriteBuf) error {
|
||||
if !n.Valid {
|
||||
w.WriteInt32(-1)
|
||||
return nil
|
||||
|
@ -119,7 +119,7 @@ func (n *NullFloat64) Scan(rows *Rows, fd *FieldDescription, size int32) error {
|
|||
return rows.Err()
|
||||
}
|
||||
|
||||
func (n *NullFloat64) EncodeText() (string, error) {
|
||||
func (n NullFloat64) EncodeText() (string, error) {
|
||||
if n.Valid {
|
||||
return strconv.FormatFloat(n.Float64, 'f', -1, 64), nil
|
||||
} else {
|
||||
|
@ -127,7 +127,7 @@ func (n *NullFloat64) EncodeText() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *NullFloat64) EncodeBinary(w *WriteBuf) error {
|
||||
func (n NullFloat64) EncodeBinary(w *WriteBuf) error {
|
||||
if !n.Valid {
|
||||
w.WriteInt32(-1)
|
||||
return nil
|
||||
|
@ -157,7 +157,7 @@ func (n *NullInt16) Scan(rows *Rows, fd *FieldDescription, size int32) error {
|
|||
return rows.Err()
|
||||
}
|
||||
|
||||
func (n *NullInt16) EncodeText() (string, error) {
|
||||
func (n NullInt16) EncodeText() (string, error) {
|
||||
if n.Valid {
|
||||
return strconv.FormatInt(int64(n.Int16), 10), nil
|
||||
} else {
|
||||
|
@ -165,7 +165,7 @@ func (n *NullInt16) EncodeText() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *NullInt16) EncodeBinary(w *WriteBuf) error {
|
||||
func (n NullInt16) EncodeBinary(w *WriteBuf) error {
|
||||
if !n.Valid {
|
||||
w.WriteInt32(-1)
|
||||
return nil
|
||||
|
@ -195,7 +195,7 @@ func (n *NullInt32) Scan(rows *Rows, fd *FieldDescription, size int32) error {
|
|||
return rows.Err()
|
||||
}
|
||||
|
||||
func (n *NullInt32) EncodeText() (string, error) {
|
||||
func (n NullInt32) EncodeText() (string, error) {
|
||||
if n.Valid {
|
||||
return strconv.FormatInt(int64(n.Int32), 10), nil
|
||||
} else {
|
||||
|
@ -203,7 +203,7 @@ func (n *NullInt32) EncodeText() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *NullInt32) EncodeBinary(w *WriteBuf) error {
|
||||
func (n NullInt32) EncodeBinary(w *WriteBuf) error {
|
||||
if !n.Valid {
|
||||
w.WriteInt32(-1)
|
||||
return nil
|
||||
|
@ -233,7 +233,7 @@ func (n *NullInt64) Scan(rows *Rows, fd *FieldDescription, size int32) error {
|
|||
return rows.Err()
|
||||
}
|
||||
|
||||
func (n *NullInt64) EncodeText() (string, error) {
|
||||
func (n NullInt64) EncodeText() (string, error) {
|
||||
if n.Valid {
|
||||
return strconv.FormatInt(int64(n.Int64), 10), nil
|
||||
} else {
|
||||
|
@ -241,7 +241,7 @@ func (n *NullInt64) EncodeText() (string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (n *NullInt64) EncodeBinary(w *WriteBuf) error {
|
||||
func (n NullInt64) EncodeBinary(w *WriteBuf) error {
|
||||
if !n.Valid {
|
||||
w.WriteInt32(-1)
|
||||
return nil
|
||||
|
|
|
@ -209,16 +209,16 @@ func TestNullX(t *testing.T) {
|
|||
scanArgs []interface{}
|
||||
expected allTypes
|
||||
}{
|
||||
{"select $1::int2", []interface{}{&pgx.NullInt16{Int16: 1, Valid: true}}, []interface{}{&actual.i16}, allTypes{i16: pgx.NullInt16{Int16: 1, Valid: true}}},
|
||||
{"select $1::int2", []interface{}{&pgx.NullInt16{Int16: 1, Valid: false}}, []interface{}{&actual.i16}, allTypes{i16: pgx.NullInt16{Int16: 0, Valid: false}}},
|
||||
{"select $1::int4", []interface{}{&pgx.NullInt32{Int32: 1, Valid: true}}, []interface{}{&actual.i32}, allTypes{i32: pgx.NullInt32{Int32: 1, Valid: true}}},
|
||||
{"select $1::int4", []interface{}{&pgx.NullInt32{Int32: 1, Valid: false}}, []interface{}{&actual.i32}, allTypes{i32: pgx.NullInt32{Int32: 0, Valid: false}}},
|
||||
{"select $1::int8", []interface{}{&pgx.NullInt64{Int64: 1, Valid: true}}, []interface{}{&actual.i64}, allTypes{i64: pgx.NullInt64{Int64: 1, Valid: true}}},
|
||||
{"select $1::int8", []interface{}{&pgx.NullInt64{Int64: 1, Valid: false}}, []interface{}{&actual.i64}, allTypes{i64: pgx.NullInt64{Int64: 0, Valid: false}}},
|
||||
{"select $1::float4", []interface{}{&pgx.NullFloat32{Float32: 1.23, Valid: true}}, []interface{}{&actual.f32}, allTypes{f32: pgx.NullFloat32{Float32: 1.23, Valid: true}}},
|
||||
{"select $1::float4", []interface{}{&pgx.NullFloat32{Float32: 1.23, Valid: false}}, []interface{}{&actual.f32}, allTypes{f32: pgx.NullFloat32{Float32: 0, Valid: false}}},
|
||||
{"select $1::float8", []interface{}{&pgx.NullFloat64{Float64: 1.23, Valid: true}}, []interface{}{&actual.f64}, allTypes{f64: pgx.NullFloat64{Float64: 1.23, Valid: true}}},
|
||||
{"select $1::float8", []interface{}{&pgx.NullFloat64{Float64: 1.23, Valid: false}}, []interface{}{&actual.f64}, allTypes{f64: pgx.NullFloat64{Float64: 0, Valid: false}}},
|
||||
{"select $1::int2", []interface{}{pgx.NullInt16{Int16: 1, Valid: true}}, []interface{}{&actual.i16}, allTypes{i16: pgx.NullInt16{Int16: 1, Valid: true}}},
|
||||
{"select $1::int2", []interface{}{pgx.NullInt16{Int16: 1, Valid: false}}, []interface{}{&actual.i16}, allTypes{i16: pgx.NullInt16{Int16: 0, Valid: false}}},
|
||||
{"select $1::int4", []interface{}{pgx.NullInt32{Int32: 1, Valid: true}}, []interface{}{&actual.i32}, allTypes{i32: pgx.NullInt32{Int32: 1, Valid: true}}},
|
||||
{"select $1::int4", []interface{}{pgx.NullInt32{Int32: 1, Valid: false}}, []interface{}{&actual.i32}, allTypes{i32: pgx.NullInt32{Int32: 0, Valid: false}}},
|
||||
{"select $1::int8", []interface{}{pgx.NullInt64{Int64: 1, Valid: true}}, []interface{}{&actual.i64}, allTypes{i64: pgx.NullInt64{Int64: 1, Valid: true}}},
|
||||
{"select $1::int8", []interface{}{pgx.NullInt64{Int64: 1, Valid: false}}, []interface{}{&actual.i64}, allTypes{i64: pgx.NullInt64{Int64: 0, Valid: false}}},
|
||||
{"select $1::float4", []interface{}{pgx.NullFloat32{Float32: 1.23, Valid: true}}, []interface{}{&actual.f32}, allTypes{f32: pgx.NullFloat32{Float32: 1.23, Valid: true}}},
|
||||
{"select $1::float4", []interface{}{pgx.NullFloat32{Float32: 1.23, Valid: false}}, []interface{}{&actual.f32}, allTypes{f32: pgx.NullFloat32{Float32: 0, Valid: false}}},
|
||||
{"select $1::float8", []interface{}{pgx.NullFloat64{Float64: 1.23, Valid: true}}, []interface{}{&actual.f64}, allTypes{f64: pgx.NullFloat64{Float64: 1.23, Valid: true}}},
|
||||
{"select $1::float8", []interface{}{pgx.NullFloat64{Float64: 1.23, Valid: false}}, []interface{}{&actual.f64}, allTypes{f64: pgx.NullFloat64{Float64: 0, Valid: false}}},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
|
|
Loading…
Reference in New Issue