Handles aclitem lists of 1+

pull/210/head
Manni Wood 2016-11-12 12:28:31 -05:00
parent d9ab219753
commit 104c01df21
2 changed files with 21 additions and 3 deletions

View File

@ -3000,8 +3000,15 @@ func decodeTextArray(vr *ValueReader) []string {
}
// XXX: encodeAclItemSlice; using text encoding, not binary
func encodeAclItemSlice(w *WriteBuf, oid Oid, value []AclItem) error {
str := "{" + value[0] + "}"
func encodeAclItemSlice(w *WriteBuf, oid Oid, aclitems []AclItem) error {
// cast aclitems into strings so we can use strings.Join
strs := make([]string, len(aclitems))
for i := range strs {
strs[i] = string(aclitems[i])
}
str := strings.Join(strs, ",")
str = "{" + str + "}"
w.WriteInt32(int32(len(str)))
w.WriteBytes([]byte(str))
return nil
@ -3017,7 +3024,14 @@ func decodeAclItemArray(vr *ValueReader) []AclItem {
str := vr.ReadString(vr.Len())
// remove the '{' at the front and the '}' at the end
str = str[1 : len(str)-1]
return []AclItem{AclItem(str)}
strs := strings.Split(str, ",")
// cast strings into AclItems before returning
aclitems := make([]AclItem, len(strs))
for i := range aclitems {
aclitems[i] = AclItem(strs[i])
}
return aclitems
}
func encodeStringSlice(w *WriteBuf, oid Oid, slice []string) error {

View File

@ -665,6 +665,10 @@ func TestAclArrayDecoding(t *testing.T) {
[]pgx.AclItem{"=r/postgres"},
&[]pgx.AclItem{},
},
{
[]pgx.AclItem{"=r/postgres", "postgres=arwdDxt/postgres"},
&[]pgx.AclItem{},
},
}
for i, tt := range tests {
err := conn.QueryRow(sql, tt.query).Scan(tt.scan)