Skip to content

Commit 560eb04

Browse files
committed
Merge remote-tracking branch 'mattn/master' into merge-upstream
2 parents aaa444f + 64bbe62 commit 560eb04

File tree

65 files changed

+6220
-2838
lines changed

Some content is hidden

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

65 files changed

+6220
-2838
lines changed

.github/workflows/docker.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ jobs:
1717

1818
- name: Run example - simple
1919
run: |
20-
cd ./_example/simple
21-
docker build -t simple .
20+
docker build -t simple -f ./_example/simple/Dockerfile .
2221
docker run simple | grep 99\ こんにちは世界099

.github/workflows/go.yaml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Go
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
7+
test:
8+
name: Test
9+
runs-on: ${{ matrix.os }}
10+
defaults:
11+
run:
12+
shell: bash
13+
14+
strategy:
15+
matrix:
16+
os: [ubuntu-latest, macos-latest]
17+
go: ['1.19', '1.20', '1.21']
18+
fail-fast: false
19+
env:
20+
OS: ${{ matrix.os }}
21+
GO: ${{ matrix.go }}
22+
steps:
23+
- if: startsWith(matrix.os, 'macos')
24+
run: brew update
25+
26+
- uses: actions/setup-go@v2
27+
with:
28+
go-version: ${{ matrix.go }}
29+
30+
- name: Get Build Tools
31+
run: |
32+
GO111MODULE=on go install github.com/ory/go-acc@latest
33+
34+
- name: Add $GOPATH/bin to $PATH
35+
run: |
36+
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
37+
38+
- uses: actions/checkout@v2
39+
40+
- name: 'Tags: default'
41+
run: go-acc . -- -race -v -tags ""
42+
43+
- name: 'Tags: libsqlite3'
44+
run: go-acc . -- -race -v -tags "libsqlite3"
45+
46+
- name: 'Tags: full'
47+
run: go-acc . -- -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_column_metadata sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_math_functions sqlite_os_trace sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_unlock_notify sqlite_userauth sqlite_vacuum_incr sqlite_vtable"
48+
49+
- name: 'Tags: vacuum'
50+
run: go-acc . -- -race -v -tags "sqlite_vacuum_full"
51+
52+
- name: Upload coverage to Codecov
53+
uses: codecov/codecov-action@v1
54+
with:
55+
env_vars: OS,GO
56+
file: coverage.txt
57+
58+
test-windows:
59+
name: Test for Windows
60+
runs-on: windows-latest
61+
defaults:
62+
run:
63+
shell: bash
64+
65+
strategy:
66+
matrix:
67+
go: ['1.19', '1.20', '1.21']
68+
fail-fast: false
69+
env:
70+
OS: windows-latest
71+
GO: ${{ matrix.go }}
72+
steps:
73+
- uses: msys2/setup-msys2@v2
74+
with:
75+
update: true
76+
install: mingw-w64-x86_64-toolchain mingw-w64-x86_64-sqlite3
77+
msystem: MINGW64
78+
path-type: inherit
79+
80+
- uses: actions/setup-go@v2
81+
with:
82+
go-version: ${{ matrix.go }}
83+
84+
- name: Add $GOPATH/bin to $PATH
85+
run: |
86+
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
87+
shell: msys2 {0}
88+
89+
- uses: actions/checkout@v2
90+
91+
- name: 'Tags: default'
92+
run: go build -race -v -tags ""
93+
shell: msys2 {0}
94+
95+
- name: 'Tags: libsqlite3'
96+
run: go build -race -v -tags "libsqlite3"
97+
shell: msys2 {0}
98+
99+
- name: 'Tags: full'
100+
run: |
101+
echo 'skip this test'
102+
echo go build -race -v -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_column_metadata sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_math_functions sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_unlock_notify sqlite_userauth sqlite_vacuum_incr sqlite_vtable"
103+
shell: msys2 {0}
104+
105+
- name: 'Tags: vacuum'
106+
run: go build -race -v -tags "sqlite_vacuum_full"
107+
shell: msys2 {0}
108+
109+
- name: Upload coverage to Codecov
110+
uses: codecov/codecov-action@v2
111+
with:
112+
env_vars: OS,GO
113+
file: coverage.txt
114+
115+
# based on: github.com/koron-go/_skeleton/.github/workflows/go.yml

_example/json/json.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package main
2+
3+
import (
4+
"database/sql"
5+
"database/sql/driver"
6+
"encoding/json"
7+
"fmt"
8+
_ "github.com/mattn/go-sqlite3"
9+
"log"
10+
"os"
11+
)
12+
13+
type Tag struct {
14+
Name string `json:"name"`
15+
Country string `json:"country"`
16+
}
17+
18+
func (t *Tag) Scan(value interface{}) error {
19+
return json.Unmarshal([]byte(value.(string)), t)
20+
}
21+
22+
func (t *Tag) Value() (driver.Value, error) {
23+
b, err := json.Marshal(t)
24+
return string(b), err
25+
}
26+
27+
func main() {
28+
os.Remove("./foo.db")
29+
30+
db, err := sql.Open("sqlite3", "./foo.db")
31+
if err != nil {
32+
log.Fatal(err)
33+
}
34+
defer db.Close()
35+
36+
_, err = db.Exec(`create table foo (tag jsonb)`)
37+
if err != nil {
38+
log.Fatal(err)
39+
}
40+
41+
stmt, err := db.Prepare("insert into foo(tag) values(?)")
42+
if err != nil {
43+
log.Fatal(err)
44+
}
45+
defer stmt.Close()
46+
_, err = stmt.Exec(`{"name": "mattn", "country": "japan"}`)
47+
if err != nil {
48+
log.Fatal(err)
49+
}
50+
_, err = stmt.Exec(`{"name": "michael", "country": "usa"}`)
51+
if err != nil {
52+
log.Fatal(err)
53+
}
54+
55+
var country string
56+
err = db.QueryRow("select tag->>'country' from foo where tag->>'name' = 'mattn'").Scan(&country)
57+
if err != nil {
58+
log.Fatal(err)
59+
}
60+
fmt.Println(country)
61+
62+
var tag Tag
63+
err = db.QueryRow("select tag from foo where tag->>'name' = 'mattn'").Scan(&tag)
64+
if err != nil {
65+
log.Fatal(err)
66+
}
67+
68+
fmt.Println(tag.Name)
69+
70+
tag.Country = "日本"
71+
_, err = db.Exec(`update foo set tag = ? where tag->>'name' == 'mattn'`, &tag)
72+
if err != nil {
73+
log.Fatal(err)
74+
}
75+
76+
err = db.QueryRow("select tag->>'country' from foo where tag->>'name' = 'mattn'").Scan(&country)
77+
if err != nil {
78+
log.Fatal(err)
79+
}
80+
fmt.Println(country)
81+
}

_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/simple/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# -----------------------------------------------------------------------------
1010
# Build Stage
1111
# -----------------------------------------------------------------------------
12-
FROM golang:alpine AS build
12+
FROM golang:alpine3.18 AS build
1313

1414
# Important:
1515
# Because this is a CGO enabled package, you are required to set it as 1.
@@ -26,7 +26,9 @@ WORKDIR /workspace
2626
COPY . /workspace/
2727

2828
RUN \
29+
cd _example/simple && \
2930
go mod init github.com/mattn/sample && \
31+
go mod edit -replace=github.com/mattn/go-sqlite3=../.. && \
3032
go mod tidy && \
3133
go install -ldflags='-s -w -extldflags "-static"' ./simple.go
3234

_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

0 commit comments

Comments
 (0)