Skip to content

Commit

Permalink
Merge remote-tracking branch 'mattn/master' into merge-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
otoolep committed Jan 26, 2024
2 parents aaa444f + 64bbe62 commit 560eb04
Show file tree
Hide file tree
Showing 65 changed files with 6,220 additions and 2,838 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/docker.yaml
Expand Up @@ -17,6 +17,5 @@ jobs:

- name: Run example - simple
run: |
cd ./_example/simple
docker build -t simple .
docker build -t simple -f ./_example/simple/Dockerfile .
docker run simple | grep 99\ こんにちは世界099
115 changes: 115 additions & 0 deletions .github/workflows/go.yaml
@@ -0,0 +1,115 @@
name: Go

on: [push, pull_request]

jobs:

test:
name: Test
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash

strategy:
matrix:
os: [ubuntu-latest, macos-latest]
go: ['1.19', '1.20', '1.21']
fail-fast: false
env:
OS: ${{ matrix.os }}
GO: ${{ matrix.go }}
steps:
- if: startsWith(matrix.os, 'macos')
run: brew update

- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Get Build Tools
run: |
GO111MODULE=on go install github.com/ory/go-acc@latest
- name: Add $GOPATH/bin to $PATH
run: |
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- uses: actions/checkout@v2

- name: 'Tags: default'
run: go-acc . -- -race -v -tags ""

- name: 'Tags: libsqlite3'
run: go-acc . -- -race -v -tags "libsqlite3"

- name: 'Tags: full'
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"

- name: 'Tags: vacuum'
run: go-acc . -- -race -v -tags "sqlite_vacuum_full"

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
env_vars: OS,GO
file: coverage.txt

test-windows:
name: Test for Windows
runs-on: windows-latest
defaults:
run:
shell: bash

strategy:
matrix:
go: ['1.19', '1.20', '1.21']
fail-fast: false
env:
OS: windows-latest
GO: ${{ matrix.go }}
steps:
- uses: msys2/setup-msys2@v2
with:
update: true
install: mingw-w64-x86_64-toolchain mingw-w64-x86_64-sqlite3
msystem: MINGW64
path-type: inherit

- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Add $GOPATH/bin to $PATH
run: |
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
shell: msys2 {0}

- uses: actions/checkout@v2

- name: 'Tags: default'
run: go build -race -v -tags ""
shell: msys2 {0}

- name: 'Tags: libsqlite3'
run: go build -race -v -tags "libsqlite3"
shell: msys2 {0}

- name: 'Tags: full'
run: |
echo 'skip this test'
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"
shell: msys2 {0}

- name: 'Tags: vacuum'
run: go build -race -v -tags "sqlite_vacuum_full"
shell: msys2 {0}

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
env_vars: OS,GO
file: coverage.txt

# based on: github.com/koron-go/_skeleton/.github/workflows/go.yml
81 changes: 81 additions & 0 deletions _example/json/json.go
@@ -0,0 +1,81 @@
package main

import (
"database/sql"
"database/sql/driver"
"encoding/json"
"fmt"
_ "github.com/mattn/go-sqlite3"
"log"
"os"
)

type Tag struct {
Name string `json:"name"`
Country string `json:"country"`
}

func (t *Tag) Scan(value interface{}) error {
return json.Unmarshal([]byte(value.(string)), t)
}

func (t *Tag) Value() (driver.Value, error) {
b, err := json.Marshal(t)
return string(b), err
}

func main() {
os.Remove("./foo.db")

db, err := sql.Open("sqlite3", "./foo.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()

_, err = db.Exec(`create table foo (tag jsonb)`)
if err != nil {
log.Fatal(err)
}

stmt, err := db.Prepare("insert into foo(tag) values(?)")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
_, err = stmt.Exec(`{"name": "mattn", "country": "japan"}`)
if err != nil {
log.Fatal(err)
}
_, err = stmt.Exec(`{"name": "michael", "country": "usa"}`)
if err != nil {
log.Fatal(err)
}

var country string
err = db.QueryRow("select tag->>'country' from foo where tag->>'name' = 'mattn'").Scan(&country)
if err != nil {
log.Fatal(err)
}
fmt.Println(country)

var tag Tag
err = db.QueryRow("select tag from foo where tag->>'name' = 'mattn'").Scan(&tag)
if err != nil {
log.Fatal(err)
}

fmt.Println(tag.Name)

tag.Country = "日本"
_, err = db.Exec(`update foo set tag = ? where tag->>'name' == 'mattn'`, &tag)
if err != nil {
log.Fatal(err)
}

err = db.QueryRow("select tag->>'country' from foo where tag->>'name' = 'mattn'").Scan(&country)
if err != nil {
log.Fatal(err)
}
fmt.Println(country)
}
6 changes: 3 additions & 3 deletions _example/limit/limit.go
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/mattn/go-sqlite3"
)

func createBulkInsertQuery(n int, start int) (query string, args []interface{}) {
func createBulkInsertQuery(n int, start int) (query string, args []any) {
values := make([]string, n)
args = make([]interface{}, n*2)
args = make([]any, n*2)
pos := 0
for i := 0; i < n; i++ {
values[i] = "(?, ?)"
Expand All @@ -27,7 +27,7 @@ func createBulkInsertQuery(n int, start int) (query string, args []interface{})
return
}

func bulkInsert(db *sql.DB, query string, args []interface{}) (err error) {
func bulkInsert(db *sql.DB, query string, args []any) (err error) {
stmt, err := db.Prepare(query)
if err != nil {
return
Expand Down
4 changes: 3 additions & 1 deletion _example/simple/Dockerfile
Expand Up @@ -9,7 +9,7 @@
# -----------------------------------------------------------------------------
# Build Stage
# -----------------------------------------------------------------------------
FROM golang:alpine AS build
FROM golang:alpine3.18 AS build

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

RUN \
cd _example/simple && \
go mod init github.com/mattn/sample && \
go mod edit -replace=github.com/mattn/go-sqlite3=../.. && \
go mod tidy && \
go install -ldflags='-s -w -extldflags "-static"' ./simple.go

Expand Down
2 changes: 1 addition & 1 deletion _example/vtable/vtable.go
Expand Up @@ -93,7 +93,7 @@ func (vc *ghRepoCursor) Column(c *sqlite3.SQLiteContext, col int) error {
return nil
}

func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
func (vc *ghRepoCursor) Filter(idxNum int, idxStr string, vals []any) error {
vc.index = 0
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion _example/vtable_eponymous_only/vtable.go
Expand Up @@ -77,7 +77,7 @@ func (vc *seriesCursor) Column(c *sqlite3.SQLiteContext, col int) error {
return nil
}

func (vc *seriesCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
func (vc *seriesCursor) Filter(idxNum int, idxStr string, vals []any) error {
switch {
case len(vals) < 1:
vc.seriesTable.start = 0
Expand Down
1 change: 1 addition & 0 deletions backup_test.go
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

//go:build cgo
// +build cgo

package sqlite3
Expand Down
16 changes: 8 additions & 8 deletions callback.go
Expand Up @@ -100,13 +100,13 @@ func preUpdateHookTrampoline(handle unsafe.Pointer, dbHandle uintptr, op int, db
// Use handles to avoid passing Go pointers to C.
type handleVal struct {
db *SQLiteConn
val interface{}
val any
}

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

func newHandle(db *SQLiteConn, v interface{}) unsafe.Pointer {
func newHandle(db *SQLiteConn, v any) unsafe.Pointer {
handleLock.Lock()
defer handleLock.Unlock()
val := handleVal{db: db, val: v}
Expand All @@ -124,7 +124,7 @@ func lookupHandleVal(handle unsafe.Pointer) handleVal {
return handleVals[handle]
}

func lookupHandle(handle unsafe.Pointer) interface{} {
func lookupHandle(handle unsafe.Pointer) any {
return lookupHandleVal(handle).val
}

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

cb, err := callbackRet(v.Elem().Type())
if err != nil {
return err
}
if err != nil {
return err
}

return cb(ctx, v.Elem())
return cb(ctx, v.Elem())
}

func callbackRet(typ reflect.Type) (callbackRetConverter, error) {
Expand Down
5 changes: 3 additions & 2 deletions callback_test.go
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.

//go:build cgo
// +build cgo

package sqlite3
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestCallbackArgCast(t *testing.T) {

func TestCallbackConverters(t *testing.T) {
tests := []struct {
v interface{}
v any
err bool
}{
// Unfortunately, we can't tell which converter was returned,
Expand Down Expand Up @@ -104,7 +105,7 @@ func TestCallbackConverters(t *testing.T) {
}

func TestCallbackReturnAny(t *testing.T) {
udf := func() interface{} {
udf := func() any {
return 1
}

Expand Down
10 changes: 5 additions & 5 deletions convert.go
Expand Up @@ -23,7 +23,7 @@ var errNilPtr = errors.New("destination pointer is nil") // embedded in descript
// convertAssign copies to dest the value in src, converting it if possible.
// An error is returned if the copy would result in loss of information.
// dest should be a pointer type.
func convertAssign(dest, src interface{}) error {
func convertAssign(dest, src any) error {
// Common cases, without reflect.
switch s := src.(type) {
case string:
Expand Down Expand Up @@ -55,7 +55,7 @@ func convertAssign(dest, src interface{}) error {
}
*d = string(s)
return nil
case *interface{}:
case *any:
if d == nil {
return errNilPtr
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func convertAssign(dest, src interface{}) error {
}
case nil:
switch d := dest.(type) {
case *interface{}:
case *any:
if d == nil {
return errNilPtr
}
Expand Down Expand Up @@ -149,7 +149,7 @@ func convertAssign(dest, src interface{}) error {
*d = bv.(bool)
}
return err
case *interface{}:
case *any:
*d = src
return nil
}
Expand Down Expand Up @@ -256,7 +256,7 @@ func cloneBytes(b []byte) []byte {
return c
}

func asString(src interface{}) string {
func asString(src any) string {
switch v := src.(type) {
case string:
return v
Expand Down

0 comments on commit 560eb04

Please sign in to comment.