2
0

support inserting into bool[]

This commit is contained in:
Karl Seguin
2014-12-21 13:01:24 +07:00
parent 3c61b16776
commit d1b42d1c8e
3 changed files with 47 additions and 1 deletions
+28
View File
@@ -21,6 +21,7 @@ const (
OidOid = 26
Float4Oid = 700
Float8Oid = 701
BoolArrayOid = 1000
Int2ArrayOid = 1005
Int4ArrayOid = 1007
TextArrayOid = 1009
@@ -1232,6 +1233,33 @@ func decodeInt2Array(vr *ValueReader) []int16 {
return a
}
func encodeBoolArray(w *WriteBuf, value interface{}) error {
slice, ok := value.([]bool)
if !ok {
return fmt.Errorf("Expected []bool, received %T", value)
}
size := 20 + len(slice)*5
w.WriteInt32(int32(size))
w.WriteInt32(1) // number of dimensions
w.WriteInt32(0) // no nulls
w.WriteInt32(BoolOid) // type of elements
w.WriteInt32(int32(len(slice))) // number of elements
w.WriteInt32(1) // index of first element
for _, v := range slice {
w.WriteInt32(1)
var b byte
if v {
b = 1
}
w.WriteByte(b)
}
return nil
}
func encodeInt2Array(w *WriteBuf, value interface{}) error {
slice, ok := value.([]int16)
if !ok {