mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-11 21:49:13 +00:00
Go 1.22.
This commit is contained in:
@@ -720,19 +720,19 @@ func (r *rows) ColumnTypeScanType(index int) (typ reflect.Type) {
|
||||
|
||||
switch scan {
|
||||
case _INT:
|
||||
return reflect.TypeOf(int64(0))
|
||||
return reflect.TypeFor[int64]()
|
||||
case _REAL:
|
||||
return reflect.TypeOf(float64(0))
|
||||
return reflect.TypeFor[float64]()
|
||||
case _TEXT:
|
||||
return reflect.TypeOf("")
|
||||
return reflect.TypeFor[string]()
|
||||
case _BLOB:
|
||||
return reflect.TypeOf([]byte{})
|
||||
return reflect.TypeFor[[]byte]()
|
||||
case _BOOL:
|
||||
return reflect.TypeOf(false)
|
||||
return reflect.TypeFor[bool]()
|
||||
case _TIME:
|
||||
return reflect.TypeOf(time.Time{})
|
||||
return reflect.TypeFor[time.Time]()
|
||||
default:
|
||||
return reflect.TypeOf((*any)(nil)).Elem()
|
||||
return reflect.TypeFor[any]()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -369,13 +369,13 @@ func Test_time(t *testing.T) {
|
||||
|
||||
func Test_ColumnType_ScanType(t *testing.T) {
|
||||
var (
|
||||
INT = reflect.TypeOf(int64(0))
|
||||
REAL = reflect.TypeOf(float64(0))
|
||||
TEXT = reflect.TypeOf("")
|
||||
BLOB = reflect.TypeOf([]byte{})
|
||||
BOOL = reflect.TypeOf(false)
|
||||
TIME = reflect.TypeOf(time.Time{})
|
||||
ANY = reflect.TypeOf((*any)(nil)).Elem()
|
||||
INT = reflect.TypeFor[int64]()
|
||||
REAL = reflect.TypeFor[float64]()
|
||||
TEXT = reflect.TypeFor[string]()
|
||||
BLOB = reflect.TypeFor[[]byte]()
|
||||
BOOL = reflect.TypeFor[bool]()
|
||||
TIME = reflect.TypeFor[time.Time]()
|
||||
ANY = reflect.TypeFor[any]()
|
||||
)
|
||||
|
||||
t.Parallel()
|
||||
|
||||
@@ -3,7 +3,7 @@ package driver
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"reflect"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
_ "github.com/ncruces/go-sqlite3/embed"
|
||||
@@ -16,7 +16,7 @@ func Test_namedValues(t *testing.T) {
|
||||
{Ordinal: 2, Value: false},
|
||||
}
|
||||
got := namedValues([]driver.Value{true, false})
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
if !slices.Equal(got, want) {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module github.com/ncruces/go-sqlite3/embed/bcw2
|
||||
|
||||
go 1.21
|
||||
go 1.22
|
||||
|
||||
toolchain go1.23.0
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -278,7 +278,7 @@ func Test_openblob(t *testing.T) {
|
||||
}
|
||||
|
||||
want := []string{"\xca\xfe", "\xba\xbe"}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
if !slices.Equal(got, want) {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func (b *bloom) Update(arg ...sqlite3.Value) (rowid int64, err error) {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
for n := 0; n < b.hashes; n++ {
|
||||
for n := range b.hashes {
|
||||
hash := calcHash(n, blob)
|
||||
hash %= uint64(b.bytes * 8)
|
||||
bitpos := byte(hash % 8)
|
||||
|
||||
@@ -210,7 +210,7 @@ func (c *cursor) Filter(idxNum int, idxStr string, arg ...sqlite3.Value) error {
|
||||
c.nodes = []node{{root, 0}}
|
||||
set := util.Set[int64]{}
|
||||
set.Add(root)
|
||||
for i := 0; i < len(c.nodes); i++ {
|
||||
for i := range c.nodes {
|
||||
curr := c.nodes[i]
|
||||
if curr.depth >= maxDepth {
|
||||
continue
|
||||
|
||||
@@ -207,7 +207,7 @@ func (c *cursor) Filter(idxNum int, idxStr string, arg ...sqlite3.Value) error {
|
||||
func (c *cursor) Next() error {
|
||||
if c.scan.Step() {
|
||||
count := c.scan.ColumnCount()
|
||||
for i := 0; i < count; i++ {
|
||||
for i := range count {
|
||||
err := c.cell.BindValue(i+1, c.scan.ColumnValue(i))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -44,7 +44,7 @@ func declare(db *sqlite3.Conn, _, _, _ string, arg ...string) (*table, error) {
|
||||
var str strings.Builder
|
||||
str.WriteString("CREATE TABLE x(")
|
||||
outputs := stmt.ColumnCount()
|
||||
for i := 0; i < outputs; i++ {
|
||||
for i := range outputs {
|
||||
name := sqlite3.QuoteIdentifier(stmt.ColumnName(i))
|
||||
str.WriteString(sep)
|
||||
str.WriteString(name)
|
||||
|
||||
@@ -2,7 +2,7 @@ package unicode
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"reflect"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/ncruces/go-sqlite3"
|
||||
@@ -121,7 +121,7 @@ func TestRegister_collation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
if !slices.Equal(got, want) {
|
||||
t.Error("not equal")
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func TestRegisterCollationsNeeded(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
if !slices.Equal(got, want) {
|
||||
t.Error("not equal")
|
||||
}
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/ncruces/go-sqlite3
|
||||
|
||||
go 1.21
|
||||
go 1.22
|
||||
|
||||
toolchain go1.23.0
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module github.com/ncruces/go-sqlite3/gormlite
|
||||
|
||||
go 1.21
|
||||
go 1.22
|
||||
|
||||
toolchain go1.23.0
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ func TestBlob_Reopen(t *testing.T) {
|
||||
}
|
||||
|
||||
var rowids []int64
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
err = db.Exec(`INSERT INTO test VALUES (zeroblob(10))`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -92,7 +92,7 @@ func testManyQueryRow(t params) {
|
||||
t.mustExec("create table " + TablePrefix + "foo (id integer primary key, name varchar(50))")
|
||||
t.mustExec("insert into "+TablePrefix+"foo (id, name) values(?,?)", 1, "bob")
|
||||
var name string
|
||||
for i := 0; i < 10000; i++ {
|
||||
for i := range 10000 {
|
||||
err := t.QueryRow("select name from "+TablePrefix+"foo where id = ?", 1).Scan(&name)
|
||||
if err != nil || name != "bob" {
|
||||
t.Fatalf("on query %d: err=%v, name=%q", i, err, name)
|
||||
@@ -164,11 +164,11 @@ func testPreparedStmt(t params) {
|
||||
|
||||
const nRuns = 10
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < nRuns; i++ {
|
||||
for range nRuns {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for j := 0; j < 10; j++ {
|
||||
for range 10 {
|
||||
count := 0
|
||||
if err := sel.QueryRow().Scan(&count); err != nil && err != sql.ErrNoRows {
|
||||
t.Errorf("Query: %v", err)
|
||||
|
||||
@@ -372,7 +372,7 @@ func testParallel(t testing.TB, name string, n int) {
|
||||
|
||||
var group errgroup.Group
|
||||
group.SetLimit(6)
|
||||
for i := 0; i < n; i++ {
|
||||
for i := range n {
|
||||
if i&7 != 7 {
|
||||
group.Go(reader)
|
||||
} else {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"math"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -52,8 +51,7 @@ func TestQuote(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
got := sqlite3.Quote(tt.val)
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
if got := sqlite3.Quote(tt.val); got != tt.want {
|
||||
t.Errorf("Quote(%v) = %q, want %q", tt.val, got, tt.want)
|
||||
}
|
||||
})
|
||||
@@ -81,8 +79,7 @@ func TestQuoteIdentifier(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
got := sqlite3.QuoteIdentifier(tt.id)
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
if got := sqlite3.QuoteIdentifier(tt.id); got != tt.want {
|
||||
t.Errorf("QuoteIdentifier(%v) = %q, want %q", tt.id, got, tt.want)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -56,7 +56,7 @@ func Benchmark_nokey(b *testing.B) {
|
||||
sqlite3.Initialize()
|
||||
b.ResetTimer()
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
for range b.N {
|
||||
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
@@ -70,7 +70,7 @@ func Benchmark_hexkey(b *testing.B) {
|
||||
sqlite3.Initialize()
|
||||
b.ResetTimer()
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
for range b.N {
|
||||
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" +
|
||||
"&vfs=adiantum&hexkey=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
||||
if err != nil {
|
||||
@@ -85,7 +85,7 @@ func Benchmark_textkey(b *testing.B) {
|
||||
sqlite3.Initialize()
|
||||
b.ResetTimer()
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
for range b.N {
|
||||
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" +
|
||||
"&vfs=adiantum&textkey=correct+horse+battery+staple")
|
||||
if err != nil {
|
||||
|
||||
@@ -56,7 +56,7 @@ func Benchmark_nokey(b *testing.B) {
|
||||
sqlite3.Initialize()
|
||||
b.ResetTimer()
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
for range b.N {
|
||||
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
@@ -70,7 +70,7 @@ func Benchmark_hexkey(b *testing.B) {
|
||||
sqlite3.Initialize()
|
||||
b.ResetTimer()
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
for range b.N {
|
||||
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" +
|
||||
"&vfs=xts&hexkey=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
||||
if err != nil {
|
||||
@@ -85,7 +85,7 @@ func Benchmark_textkey(b *testing.B) {
|
||||
sqlite3.Initialize()
|
||||
b.ResetTimer()
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
for range b.N {
|
||||
db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" +
|
||||
"&vfs=xts&textkey=correct+horse+battery+staple")
|
||||
if err != nil {
|
||||
|
||||
8
vtab.go
8
vtab.go
@@ -2,6 +2,7 @@ package sqlite3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"reflect"
|
||||
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
@@ -447,7 +448,7 @@ func vtabModuleCallback(i vtabConstructor) func(_ context.Context, _ api.Module,
|
||||
arg := make([]reflect.Value, 1+nArg)
|
||||
arg[0] = reflect.ValueOf(ctx.Value(connKey{}))
|
||||
|
||||
for i := int32(0); i < nArg; i++ {
|
||||
for i := range nArg {
|
||||
ptr := util.Read32[ptr_t](mod, pArg+ptr_t(i)*ptrlen)
|
||||
arg[i+1] = reflect.ValueOf(util.ReadString(mod, ptr, _MAX_SQL_LENGTH))
|
||||
}
|
||||
@@ -470,10 +471,7 @@ func vtabDisconnectCallback(ctx context.Context, mod api.Module, pVTab ptr_t) re
|
||||
|
||||
func vtabDestroyCallback(ctx context.Context, mod api.Module, pVTab ptr_t) res_t {
|
||||
vtab := vtabGetHandle(ctx, mod, pVTab).(VTabDestroyer)
|
||||
err := vtab.Destroy()
|
||||
if cerr := vtabDelHandle(ctx, mod, pVTab); err == nil {
|
||||
err = cerr
|
||||
}
|
||||
err := errors.Join(vtab.Destroy(), vtabDelHandle(ctx, mod, pVTab))
|
||||
return vtabError(ctx, mod, 0, _PTR_ERROR, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user