Skip to content

Commit

Permalink
Go 1.22.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Jan 24, 2025
1 parent c0298ad commit 1d951ec
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 50 deletions.
14 changes: 7 additions & 7 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]()
}
}

Expand Down
14 changes: 7 additions & 7 deletions driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions driver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package driver
import (
"context"
"database/sql/driver"
"reflect"
"slices"
"testing"

_ "github.com/ncruces/go-sqlite3/embed"
Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion embed/bcw2/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ncruces/go-sqlite3/embed/bcw2

go 1.21
go 1.22

toolchain go1.23.0

Expand Down
4 changes: 2 additions & 2 deletions ext/blobio/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"io"
"log"
"os"
"reflect"
"slices"
"strings"
"testing"

Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion ext/bloom/bloom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ext/closure/closure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/pivot/pivot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/statement/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ext/unicode/unicode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package unicode

import (
"errors"
"reflect"
"slices"
"testing"

"github.com/ncruces/go-sqlite3"
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ncruces/go-sqlite3

go 1.21
go 1.22

toolchain go1.23.0

Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.21
go 1.22

use (
.
Expand Down
2 changes: 1 addition & 1 deletion gormlite/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ncruces/go-sqlite3/gormlite

go 1.21
go 1.22

toolchain go1.23.0

Expand Down
2 changes: 1 addition & 1 deletion tests/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/bradfitz/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/parallel/parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions tests/quote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"database/sql"
"encoding/json"
"math"
"reflect"
"testing"
"time"

Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}
})
Expand Down
6 changes: 3 additions & 3 deletions vfs/adiantum/adiantum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions vfs/xts/aes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions vtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sqlite3

import (
"context"
"errors"
"reflect"

"github.com/tetratelabs/wazero/api"
Expand Down Expand Up @@ -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))
}
Expand All @@ -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)
}

Expand Down

0 comments on commit 1d951ec

Please sign in to comment.