2
0

Add pgtype.HstoreArray

This required restructuring array types to lookup oid of element instead of
hard-coding it due to hstore having a variable oid.
This commit is contained in:
Jack Christensen
2017-03-18 12:40:54 -05:00
parent 19c6689752
commit cf70e6b9f4
18 changed files with 586 additions and 90 deletions
+6 -5
View File
@@ -237,10 +237,6 @@ func (src *<%= pgtype_array_type %>) EncodeText(ci *ConnInfo, w io.Writer) (bool
}
func (src *<%= pgtype_array_type %>) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
return src.encodeBinary(ci, w, <%= element_oid %>)
}
func (src *<%= pgtype_array_type %>) encodeBinary(ci *ConnInfo, w io.Writer, elementOid int32) (bool, error) {
switch src.Status {
case Null:
return true, nil
@@ -249,10 +245,15 @@ func (src *<%= pgtype_array_type %>) encodeBinary(ci *ConnInfo, w io.Writer, ele
}
arrayHeader := ArrayHeader{
ElementOid: elementOid,
Dimensions: src.Dimensions,
}
if dt, ok := ci.DataTypeForName("<%= element_type_name %>"); ok {
arrayHeader.ElementOid = int32(dt.Oid)
} else {
return false, fmt.Errorf("unable to find oid for type name %v", "<%= element_type_name %>")
}
for i := range src.Elements {
if src.Elements[i].Status == Null {
arrayHeader.ContainsNull = true