Skip to content

Commit 5a05762

Browse files
committed
Merge branch 'master' into sqlite-amalgamation-3450000
2 parents 846832a + d3c3333 commit 5a05762

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+329
-278
lines changed

.github/workflows/go.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest, macos-latest]
17-
go: ['1.18', '1.19', '1.20']
17+
go: ['1.19', '1.20', '1.21']
1818
fail-fast: false
1919
env:
2020
OS: ${{ matrix.os }}
@@ -64,7 +64,7 @@ jobs:
6464

6565
strategy:
6666
matrix:
67-
go: ['1.18', '1.19', '1.20']
67+
go: ['1.19', '1.20', '1.21']
6868
fail-fast: false
6969
env:
7070
OS: windows-latest

_example/limit/limit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"github.com/mattn/go-sqlite3"
1111
)
1212

13-
func createBulkInsertQuery(n int, start int) (query string, args []interface{}) {
13+
func createBulkInsertQuery(n int, start int) (query string, args []any) {
1414
values := make([]string, n)
15-
args = make([]interface{}, n*2)
15+
args = make([]any, n*2)
1616
pos := 0
1717
for i := 0; i < n; i++ {
1818
values[i] = "(?, ?)"
@@ -27,7 +27,7 @@ func createBulkInsertQuery(n int, start int) (query string, args []interface{})
2727
return
2828
}
2929

30-
func bulkInsert(db *sql.DB, query string, args []interface{}) (err error) {
30+
func bulkInsert(db *sql.DB, query string, args []any) (err error) {
3131
stmt, err := db.Prepare(query)
3232
if err != nil {
3333
return

_example/vtable/vtable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (vc *ghRepoCursor) Column(c *sqlite3.SQLiteContext, col int) error {
9393
return nil
9494
}
9595

96-
func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
96+
func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []any) error {
9797
vc.index = 0
9898
return nil
9999
}

_example/vtable_eponymous_only/vtable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (vc *seriesCursor) Column(c *sqlite3.SQLiteContext, col int) error {
7777
return nil
7878
}
7979

80-
func (vc *seriesCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
80+
func (vc *seriesCursor) Filter(idxNum int, idxStr string, vals []any) error {
8181
switch {
8282
case len(vals) < 1:
8383
vc.seriesTable.start = 0

backup_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build cgo
67
// +build cgo
78

89
package sqlite3

callback.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ func preUpdateHookTrampoline(handle unsafe.Pointer, dbHandle uintptr, op int, db
100100
// Use handles to avoid passing Go pointers to C.
101101
type handleVal struct {
102102
db *SQLiteConn
103-
val interface{}
103+
val any
104104
}
105105

106106
var handleLock sync.Mutex
107107
var handleVals = make(map[unsafe.Pointer]handleVal)
108108

109-
func newHandle(db *SQLiteConn, v interface{}) unsafe.Pointer {
109+
func newHandle(db *SQLiteConn, v any) unsafe.Pointer {
110110
handleLock.Lock()
111111
defer handleLock.Unlock()
112112
val := handleVal{db: db, val: v}
@@ -124,7 +124,7 @@ func lookupHandleVal(handle unsafe.Pointer) handleVal {
124124
return handleVals[handle]
125125
}
126126

127-
func lookupHandle(handle unsafe.Pointer) interface{} {
127+
func lookupHandle(handle unsafe.Pointer) any {
128128
return lookupHandleVal(handle).val
129129
}
130130

@@ -238,7 +238,7 @@ func callbackArg(typ reflect.Type) (callbackArgConverter, error) {
238238
switch typ.Kind() {
239239
case reflect.Interface:
240240
if typ.NumMethod() != 0 {
241-
return nil, errors.New("the only supported interface type is interface{}")
241+
return nil, errors.New("the only supported interface type is any")
242242
}
243243
return callbackArgGeneric, nil
244244
case reflect.Slice:
@@ -360,11 +360,11 @@ func callbackRetGeneric(ctx *C.sqlite3_context, v reflect.Value) error {
360360
}
361361

362362
cb, err := callbackRet(v.Elem().Type())
363-
if err != nil {
364-
return err
365-
}
363+
if err != nil {
364+
return err
365+
}
366366

367-
return cb(ctx, v.Elem())
367+
return cb(ctx, v.Elem())
368368
}
369369

370370
func callbackRet(typ reflect.Type) (callbackRetConverter, error) {

callback_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build cgo
67
// +build cgo
78

89
package sqlite3
@@ -53,7 +54,7 @@ func TestCallbackArgCast(t *testing.T) {
5354

5455
func TestCallbackConverters(t *testing.T) {
5556
tests := []struct {
56-
v interface{}
57+
v any
5758
err bool
5859
}{
5960
// Unfortunately, we can't tell which converter was returned,
@@ -104,7 +105,7 @@ func TestCallbackConverters(t *testing.T) {
104105
}
105106

106107
func TestCallbackReturnAny(t *testing.T) {
107-
udf := func() interface{} {
108+
udf := func() any {
108109
return 1
109110
}
110111

convert.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var errNilPtr = errors.New("destination pointer is nil") // embedded in descript
2323
// convertAssign copies to dest the value in src, converting it if possible.
2424
// An error is returned if the copy would result in loss of information.
2525
// dest should be a pointer type.
26-
func convertAssign(dest, src interface{}) error {
26+
func convertAssign(dest, src any) error {
2727
// Common cases, without reflect.
2828
switch s := src.(type) {
2929
case string:
@@ -55,7 +55,7 @@ func convertAssign(dest, src interface{}) error {
5555
}
5656
*d = string(s)
5757
return nil
58-
case *interface{}:
58+
case *any:
5959
if d == nil {
6060
return errNilPtr
6161
}
@@ -97,7 +97,7 @@ func convertAssign(dest, src interface{}) error {
9797
}
9898
case nil:
9999
switch d := dest.(type) {
100-
case *interface{}:
100+
case *any:
101101
if d == nil {
102102
return errNilPtr
103103
}
@@ -149,7 +149,7 @@ func convertAssign(dest, src interface{}) error {
149149
*d = bv.(bool)
150150
}
151151
return err
152-
case *interface{}:
152+
case *any:
153153
*d = src
154154
return nil
155155
}
@@ -256,7 +256,7 @@ func cloneBytes(b []byte) []byte {
256256
return c
257257
}
258258

259-
func asString(src interface{}) string {
259+
func asString(src any) string {
260260
switch v := src.(type) {
261261
case string:
262262
return v

doc.go

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,63 @@ This works as a driver for database/sql.
55
66
Installation
77
8-
go get github.com/mattn/go-sqlite3
8+
go get github.com/mattn/go-sqlite3
99
10-
Supported Types
10+
# Supported Types
1111
1212
Currently, go-sqlite3 supports the following data types.
1313
14-
+------------------------------+
15-
|go | sqlite3 |
16-
|----------|-------------------|
17-
|nil | null |
18-
|int | integer |
19-
|int64 | integer |
20-
|float64 | float |
21-
|bool | integer |
22-
|[]byte | blob |
23-
|string | text |
24-
|time.Time | timestamp/datetime|
25-
+------------------------------+
26-
27-
SQLite3 Extension
14+
+------------------------------+
15+
|go | sqlite3 |
16+
|----------|-------------------|
17+
|nil | null |
18+
|int | integer |
19+
|int64 | integer |
20+
|float64 | float |
21+
|bool | integer |
22+
|[]byte | blob |
23+
|string | text |
24+
|time.Time | timestamp/datetime|
25+
+------------------------------+
26+
27+
# SQLite3 Extension
2828
2929
You can write your own extension module for sqlite3. For example, below is an
3030
extension for a Regexp matcher operation.
3131
32-
#include <pcre.h>
33-
#include <string.h>
34-
#include <stdio.h>
35-
#include <sqlite3ext.h>
36-
37-
SQLITE_EXTENSION_INIT1
38-
static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
39-
if (argc >= 2) {
40-
const char *target = (const char *)sqlite3_value_text(argv[1]);
41-
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
42-
const char* errstr = NULL;
43-
int erroff = 0;
44-
int vec[500];
45-
int n, rc;
46-
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
47-
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
48-
if (rc <= 0) {
49-
sqlite3_result_error(context, errstr, 0);
50-
return;
51-
}
52-
sqlite3_result_int(context, 1);
53-
}
54-
}
55-
56-
#ifdef _WIN32
57-
__declspec(dllexport)
58-
#endif
59-
int sqlite3_extension_init(sqlite3 *db, char **errmsg,
60-
const sqlite3_api_routines *api) {
61-
SQLITE_EXTENSION_INIT2(api);
62-
return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8,
63-
(void*)db, regexp_func, NULL, NULL);
64-
}
32+
#include <pcre.h>
33+
#include <string.h>
34+
#include <stdio.h>
35+
#include <sqlite3ext.h>
36+
37+
SQLITE_EXTENSION_INIT1
38+
static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv) {
39+
if (argc >= 2) {
40+
const char *target = (const char *)sqlite3_value_text(argv[1]);
41+
const char *pattern = (const char *)sqlite3_value_text(argv[0]);
42+
const char* errstr = NULL;
43+
int erroff = 0;
44+
int vec[500];
45+
int n, rc;
46+
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
47+
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
48+
if (rc <= 0) {
49+
sqlite3_result_error(context, errstr, 0);
50+
return;
51+
}
52+
sqlite3_result_int(context, 1);
53+
}
54+
}
55+
56+
#ifdef _WIN32
57+
__declspec(dllexport)
58+
#endif
59+
int sqlite3_extension_init(sqlite3 *db, char **errmsg,
60+
const sqlite3_api_routines *api) {
61+
SQLITE_EXTENSION_INIT2(api);
62+
return sqlite3_create_function(db, "regexp", 2, SQLITE_UTF8,
63+
(void*)db, regexp_func, NULL, NULL);
64+
}
6565
6666
It needs to be built as a so/dll shared library. And you need to register
6767
the extension module like below.
@@ -77,7 +77,7 @@ Then, you can use this extension.
7777
7878
rows, err := db.Query("select text from mytable where name regexp '^golang'")
7979
80-
Connection Hook
80+
# Connection Hook
8181
8282
You can hook and inject your code when the connection is established by setting
8383
ConnectHook to get the SQLiteConn.
@@ -95,13 +95,13 @@ You can also use database/sql.Conn.Raw (Go >= 1.13):
9595
conn, err := db.Conn(context.Background())
9696
// if err != nil { ... }
9797
defer conn.Close()
98-
err = conn.Raw(func (driverConn interface{}) error {
98+
err = conn.Raw(func (driverConn any) error {
9999
sqliteConn := driverConn.(*sqlite3.SQLiteConn)
100100
// ... use sqliteConn
101101
})
102102
// if err != nil { ... }
103103
104-
Go SQlite3 Extensions
104+
# Go SQlite3 Extensions
105105
106106
If you want to register Go functions as SQLite extension functions
107107
you can make a custom driver by calling RegisterFunction from
@@ -130,6 +130,5 @@ You can then use the custom driver by passing its name to sql.Open.
130130
}
131131
132132
See the documentation of RegisterFunc for more details.
133-
134133
*/
135134
package sqlite3

error_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
55

6+
//go:build cgo
67
// +build cgo
78

89
package sqlite3

0 commit comments

Comments
 (0)