This commit is contained in:
Nuno Cruces
2023-11-23 09:54:18 +00:00
parent 9bb01d1f8b
commit f2d6bdb8b7
11 changed files with 349 additions and 16 deletions

View File

@@ -97,7 +97,7 @@ func (c *cursor) Column(ctx *sqlite3.Context, n int) error {
case k == reflect.String:
ctx.ResultText(v.String())
case (k == reflect.Slice || k == reflect.Array) &&
case (k == reflect.Slice || k == reflect.Array && v.CanAddr()) &&
v.Type().Elem().Kind() == reflect.Uint8:
ctx.ResultBlob(v.Bytes())

View File

@@ -3,6 +3,9 @@ package array_test
import (
"fmt"
"log"
"math"
"reflect"
"testing"
"github.com/ncruces/go-sqlite3"
"github.com/ncruces/go-sqlite3/driver"
@@ -47,3 +50,43 @@ func Example() {
// geopoly_contains_point
// geopoly_within
}
func Test_cursor_Column(t *testing.T) {
db, err := driver.Open(":memory:", func(c *sqlite3.Conn) error {
array.Register(c)
return nil
})
if err != nil {
t.Fatal(err)
}
defer db.Close()
rows, err := db.Query(`
SELECT rowid, value FROM array(?)`,
sqlite3.Pointer(&[...]any{nil, true, 1, uint(2), math.Pi, "text", []byte{1, 2, 3}}))
if err != nil {
t.Fatal(err)
}
defer rows.Close()
want := []string{"nil", "int64", "int64", "int64", "float64", "string", "[]uint8"}
for rows.Next() {
var id, val any
err := rows.Scan(&id, &val)
if err != nil {
t.Fatal(err)
}
if want := want[0]; val == nil {
if want != "nil" {
t.Errorf("got nil, want %s", want)
}
} else if got := reflect.TypeOf(val).String(); got != want {
t.Errorf("got %s, want %s", got, want)
}
want = want[1:]
}
if err := rows.Err(); err != nil {
log.Fatal(err)
}
}