2
0

Fix Box, Circle, and Point NULL

This commit is contained in:
Jack Christensen
2022-01-08 13:29:47 -06:00
parent 58d2d8e453
commit 6a6878bafd
7 changed files with 43 additions and 0 deletions
+12
View File
@@ -85,6 +85,10 @@ func (dst *Point) Scan(src interface{}) error {
// Value implements the database/sql/driver Valuer interface.
func (src Point) Value() (driver.Value, error) {
if !src.Valid {
return nil, nil
}
buf, err := PointCodec{}.PlanEncode(nil, 0, TextFormatCode, src).Encode(src, nil)
if err != nil {
return nil, err
@@ -146,6 +150,10 @@ func (p *encodePlanPointCodecBinary) Encode(value interface{}, buf []byte) (newB
return nil, err
}
if !point.Valid {
return nil, nil
}
buf = pgio.AppendUint64(buf, math.Float64bits(point.P.X))
buf = pgio.AppendUint64(buf, math.Float64bits(point.P.Y))
return buf, nil
@@ -159,6 +167,10 @@ func (p *encodePlanPointCodecText) Encode(value interface{}, buf []byte) (newBuf
return nil, err
}
if !point.Valid {
return nil, nil
}
return append(buf, fmt.Sprintf(`(%s,%s)`,
strconv.FormatFloat(point.P.X, 'f', -1, 64),
strconv.FormatFloat(point.P.Y, 'f', -1, 64),