Handles aclitem lists of 1+
This commit is contained in:
@@ -3000,8 +3000,15 @@ func decodeTextArray(vr *ValueReader) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX: encodeAclItemSlice; using text encoding, not binary
|
// XXX: encodeAclItemSlice; using text encoding, not binary
|
||||||
func encodeAclItemSlice(w *WriteBuf, oid Oid, value []AclItem) error {
|
func encodeAclItemSlice(w *WriteBuf, oid Oid, aclitems []AclItem) error {
|
||||||
str := "{" + value[0] + "}"
|
// 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.WriteInt32(int32(len(str)))
|
||||||
w.WriteBytes([]byte(str))
|
w.WriteBytes([]byte(str))
|
||||||
return nil
|
return nil
|
||||||
@@ -3017,7 +3024,14 @@ func decodeAclItemArray(vr *ValueReader) []AclItem {
|
|||||||
str := vr.ReadString(vr.Len())
|
str := vr.ReadString(vr.Len())
|
||||||
// remove the '{' at the front and the '}' at the end
|
// remove the '{' at the front and the '}' at the end
|
||||||
str = str[1 : len(str)-1]
|
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 {
|
func encodeStringSlice(w *WriteBuf, oid Oid, slice []string) error {
|
||||||
|
|||||||
@@ -665,6 +665,10 @@ func TestAclArrayDecoding(t *testing.T) {
|
|||||||
[]pgx.AclItem{"=r/postgres"},
|
[]pgx.AclItem{"=r/postgres"},
|
||||||
&[]pgx.AclItem{},
|
&[]pgx.AclItem{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
[]pgx.AclItem{"=r/postgres", "postgres=arwdDxt/postgres"},
|
||||||
|
&[]pgx.AclItem{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
err := conn.QueryRow(sql, tt.query).Scan(tt.scan)
|
err := conn.QueryRow(sql, tt.query).Scan(tt.scan)
|
||||||
|
|||||||
Reference in New Issue
Block a user