mirror of https://github.com/jackc/pgx.git
Handles aclitem lists of 1+
parent
d9ab219753
commit
104c01df21
20
values.go
20
values.go
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue