From 1d951ecd18bc2ada30732676a6999273eb4f7c96 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Fri, 24 Jan 2025 10:46:05 +0000 Subject: [PATCH] Go 1.22. --- driver/driver.go | 14 +++++++------- driver/driver_test.go | 14 +++++++------- driver/util_test.go | 4 ++-- embed/bcw2/go.mod | 2 +- ext/blobio/blob_test.go | 4 ++-- ext/bloom/bloom.go | 2 +- ext/closure/closure.go | 2 +- ext/pivot/pivot.go | 2 +- ext/statement/stmt.go | 2 +- ext/unicode/unicode_test.go | 6 +++--- go.mod | 2 +- go.work | 2 +- gormlite/go.mod | 2 +- tests/blob_test.go | 2 +- tests/bradfitz/sql_test.go | 6 +++--- tests/parallel/parallel_test.go | 2 +- tests/quote_test.go | 7 ++----- vfs/adiantum/adiantum_test.go | 6 +++--- vfs/xts/aes_test.go | 6 +++--- vtab.go | 8 +++----- 20 files changed, 45 insertions(+), 50 deletions(-) diff --git a/driver/driver.go b/driver/driver.go index cc132afe..21799aeb 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -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]() } } diff --git a/driver/driver_test.go b/driver/driver_test.go index 871b70e4..aa357712 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -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() diff --git a/driver/util_test.go b/driver/util_test.go index 562d850d..70c5ffc0 100644 --- a/driver/util_test.go +++ b/driver/util_test.go @@ -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) } } diff --git a/embed/bcw2/go.mod b/embed/bcw2/go.mod index 2115cf61..50f25a3c 100644 --- a/embed/bcw2/go.mod +++ b/embed/bcw2/go.mod @@ -1,6 +1,6 @@ module github.com/ncruces/go-sqlite3/embed/bcw2 -go 1.21 +go 1.22 toolchain go1.23.0 diff --git a/ext/blobio/blob_test.go b/ext/blobio/blob_test.go index 989bdddb..5bb868bc 100644 --- a/ext/blobio/blob_test.go +++ b/ext/blobio/blob_test.go @@ -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) } } diff --git a/ext/bloom/bloom.go b/ext/bloom/bloom.go index 3fcc73b9..e0654066 100644 --- a/ext/bloom/bloom.go +++ b/ext/bloom/bloom.go @@ -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) diff --git a/ext/closure/closure.go b/ext/closure/closure.go index 1eaae9cf..c8825082 100644 --- a/ext/closure/closure.go +++ b/ext/closure/closure.go @@ -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 diff --git a/ext/pivot/pivot.go b/ext/pivot/pivot.go index b669325d..e17a976e 100644 --- a/ext/pivot/pivot.go +++ b/ext/pivot/pivot.go @@ -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 diff --git a/ext/statement/stmt.go b/ext/statement/stmt.go index aca9aa37..6e1a0002 100644 --- a/ext/statement/stmt.go +++ b/ext/statement/stmt.go @@ -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) diff --git a/ext/unicode/unicode_test.go b/ext/unicode/unicode_test.go index 73a63143..c5bd4d80 100644 --- a/ext/unicode/unicode_test.go +++ b/ext/unicode/unicode_test.go @@ -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") } diff --git a/go.mod b/go.mod index 4ed5cb1c..8a92ebd3 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ncruces/go-sqlite3 -go 1.21 +go 1.22 toolchain go1.23.0 diff --git a/go.work b/go.work index ff5d6b51..3d0599c6 100644 --- a/go.work +++ b/go.work @@ -1,4 +1,4 @@ -go 1.21 +go 1.22 use ( . diff --git a/gormlite/go.mod b/gormlite/go.mod index 9f4b8b33..8b69cf74 100644 --- a/gormlite/go.mod +++ b/gormlite/go.mod @@ -1,6 +1,6 @@ module github.com/ncruces/go-sqlite3/gormlite -go 1.21 +go 1.22 toolchain go1.23.0 diff --git a/tests/blob_test.go b/tests/blob_test.go index 485b2b6f..9b1b5a34 100644 --- a/tests/blob_test.go +++ b/tests/blob_test.go @@ -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) diff --git a/tests/bradfitz/sql_test.go b/tests/bradfitz/sql_test.go index dc86207f..fca93723 100644 --- a/tests/bradfitz/sql_test.go +++ b/tests/bradfitz/sql_test.go @@ -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) diff --git a/tests/parallel/parallel_test.go b/tests/parallel/parallel_test.go index 2c8da8c0..be6ee8f4 100644 --- a/tests/parallel/parallel_test.go +++ b/tests/parallel/parallel_test.go @@ -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 { diff --git a/tests/quote_test.go b/tests/quote_test.go index 095d83e2..9096f330 100644 --- a/tests/quote_test.go +++ b/tests/quote_test.go @@ -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) } }) diff --git a/vfs/adiantum/adiantum_test.go b/vfs/adiantum/adiantum_test.go index 319742e6..3b66df26 100644 --- a/vfs/adiantum/adiantum_test.go +++ b/vfs/adiantum/adiantum_test.go @@ -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 { diff --git a/vfs/xts/aes_test.go b/vfs/xts/aes_test.go index 880fd5e1..ecc03095 100644 --- a/vfs/xts/aes_test.go +++ b/vfs/xts/aes_test.go @@ -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 { diff --git a/vtab.go b/vtab.go index 7b29a5e4..278195e9 100644 --- a/vtab.go +++ b/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) }