Skip to content

Commit

Permalink
Merge b943152 into 536b539
Browse files Browse the repository at this point in the history
  • Loading branch information
playboyko committed Mar 22, 2018
2 parents 536b539 + b943152 commit eaf77de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,13 @@ func (d *textDecoder) Decode(t string, value []byte) (driver.Value, error) {
return unescape(unquote(v)), nil
}
if strings.HasPrefix(t, "Array") {
if len(v) > 0 && v[0] == '[' && v[len(value)-1] == ']' {
items := strings.Split(v[1:len(value)-1], ",")
if len(v) > 0 && v[0] == '[' && v[len(v)-1] == ']' {
var items []string
// check that array is not empty ([])
if len(v) > 2 {
items = strings.Split(v[1:len(v)-1], ",")
}

subType := t[6 : len(t)-1]
r := reflect.MakeSlice(reflect.SliceOf(columnType(subType)), len(items), len(items))
for i, item := range items {
Expand Down
2 changes: 2 additions & 0 deletions encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestTextEncoder(t *testing.T) {
{`\\'hello`, `'\\\\\'hello'`},
{[]byte(`\\'hello`), `\\'hello`},
{[]int32{1, 2}, "[1,2]"},
{[]int32{}, "[]"},
{&d, "'2012-05-31 00:00:00'"},
}

Expand Down Expand Up @@ -70,6 +71,7 @@ func TestTextDecoder(t *testing.T) {
{"Enum8('one'=1)", "'one'", "one"},
{"Enum16('one'=1)", "'one'", "one"},
{"Array(UInt32)", "[1,2]", []uint32{1, 2}},
{"Array(UInt32)", "[]", []uint32{}},
}

dec := &textDecoder{location: time.UTC}
Expand Down
1 change: 1 addition & 0 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestArray(t *testing.T) {
{[]uint16{1, 2}, []byte("[1,2]")},
{[]uint32{1, 2}, []byte("[1,2]")},
{[]uint64{1, 2}, []byte("[1,2]")},
{[]uint64{}, []byte("[]")},
}

for _, tc := range testCases {
Expand Down

0 comments on commit eaf77de

Please sign in to comment.