Skip to content

Commit e728f55

Browse files
authored
Merge pull request #20 from rqlite/merge-upstream-20221026
Merge upstream 20221026
2 parents 339bb50 + 7d4a778 commit e728f55

18 files changed

+6214
-3640
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
test:
88
docker:
99
# specify the version
10-
- image: circleci/golang:1.14
10+
- image: cimg/go:1.18.0
1111

1212
# Specify service dependencies here if necessary
1313
# CircleCI maintains a library of pre-built images
@@ -18,11 +18,11 @@ jobs:
1818
#### expecting it in the form of
1919
#### /go/src/github.com/circleci/go-tool
2020
#### /go/src/bitbucket.org/circleci/go-tool
21-
working_directory: /go/src/github.com/rqlite/go-sqlite3
2221
steps:
2322
- checkout
2423

2524
# specify any bash command here prefixed with `run: `
25+
- run: go version
2626
- run: go get -v -t -d ./...
2727
- run: go vet
2828
- run: go test -v ./...

.github/workflows/docker.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: dockerfile
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v*'
8+
pull_request:
9+
branches: [ master ]
10+
11+
jobs:
12+
dockerfile:
13+
name: Run Dockerfiles in examples
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Run example - simple
19+
run: |
20+
cd ./_example/simple
21+
docker build -t simple .
22+
docker run simple | grep 99\ こんにちは世界099

_example/limit/limit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func createBulkInsertQuery(n int, start int) (query string, args []interface{})
1717
for i := 0; i < n; i++ {
1818
values[i] = "(?, ?)"
1919
args[pos] = start + i
20-
args[pos+1] = fmt.Sprintf("こんにちわ世界%03d", i)
20+
args[pos+1] = fmt.Sprintf("こんにちは世界%03d", i)
2121
pos += 2
2222
}
2323
query = fmt.Sprintf(

_example/simple/Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# =============================================================================
2+
# Multi-stage Dockerfile Example
3+
# =============================================================================
4+
# This is a simple Dockerfile that will build an image of scratch-base image.
5+
# Usage:
6+
# docker build -t simple:local . && docker run --rm simple:local
7+
# =============================================================================
8+
9+
# -----------------------------------------------------------------------------
10+
# Build Stage
11+
# -----------------------------------------------------------------------------
12+
FROM golang:alpine AS build
13+
14+
# Important:
15+
# Because this is a CGO enabled package, you are required to set it as 1.
16+
ENV CGO_ENABLED=1
17+
18+
RUN apk add --no-cache \
19+
# Important: required for go-sqlite3
20+
gcc \
21+
# Required for Alpine
22+
musl-dev
23+
24+
WORKDIR /workspace
25+
26+
COPY . /workspace/
27+
28+
RUN \
29+
go mod init github.com/mattn/sample && \
30+
go mod tidy && \
31+
go install -ldflags='-s -w -extldflags "-static"' ./simple.go
32+
33+
RUN \
34+
# Smoke test
35+
set -o pipefail; \
36+
/go/bin/simple | grep 99\ こんにちは世界099
37+
38+
# -----------------------------------------------------------------------------
39+
# Main Stage
40+
# -----------------------------------------------------------------------------
41+
FROM scratch
42+
43+
COPY --from=build /go/bin/simple /usr/local/bin/simple
44+
45+
ENTRYPOINT [ "/usr/local/bin/simple" ]

_example/simple/simple.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ func main() {
3737
}
3838
defer stmt.Close()
3939
for i := 0; i < 100; i++ {
40-
_, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i))
40+
_, err = stmt.Exec(i, fmt.Sprintf("こんにちは世界%03d", i))
4141
if err != nil {
4242
log.Fatal(err)
4343
}
4444
}
45-
tx.Commit()
45+
err = tx.Commit()
46+
if err != nil {
47+
log.Fatal(err)
48+
}
4649

4750
rows, err := db.Query("select id, name from foo")
4851
if err != nil {

_example/vtable/vtable.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ func (v *ghRepoTable) Open() (sqlite3.VTabCursor, error) {
6363
}
6464

6565
func (v *ghRepoTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
66-
return &sqlite3.IndexResult{}, nil
66+
used := make([]bool, len(csts))
67+
return &sqlite3.IndexResult{
68+
IdxNum: 0,
69+
IdxStr: "default",
70+
Used: used,
71+
}, nil
6772
}
6873

6974
func (v *ghRepoTable) Disconnect() error { return nil }

callback.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,32 @@ func callbackRetNil(ctx *C.sqlite3_context, v reflect.Value) error {
353353
return nil
354354
}
355355

356+
func callbackRetGeneric(ctx *C.sqlite3_context, v reflect.Value) error {
357+
if v.IsNil() {
358+
C.sqlite3_result_null(ctx)
359+
return nil
360+
}
361+
362+
cb, err := callbackRet(v.Elem().Type())
363+
if err != nil {
364+
return err
365+
}
366+
367+
return cb(ctx, v.Elem())
368+
}
369+
356370
func callbackRet(typ reflect.Type) (callbackRetConverter, error) {
357371
switch typ.Kind() {
358372
case reflect.Interface:
359373
errorInterface := reflect.TypeOf((*error)(nil)).Elem()
360374
if typ.Implements(errorInterface) {
361375
return callbackRetNil, nil
362376
}
377+
378+
if typ.NumMethod() == 0 {
379+
return callbackRetGeneric, nil
380+
}
381+
363382
fallthrough
364383
case reflect.Slice:
365384
if typ.Elem().Kind() != reflect.Uint8 {

callback_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,15 @@ func TestCallbackConverters(t *testing.T) {
102102
}
103103
}
104104
}
105+
106+
func TestCallbackReturnAny(t *testing.T) {
107+
udf := func() interface{} {
108+
return 1
109+
}
110+
111+
typ := reflect.TypeOf(udf)
112+
_, err := callbackRet(typ.Out(0))
113+
if err != nil {
114+
t.Errorf("Expected valid callback for any return type, got: %s", err)
115+
}
116+
}

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module github.com/rqlite/go-sqlite3
22

3-
go 1.12
3+
go 1.16
4+
5+
retract (
6+
[v2.0.0+incompatible, v2.0.6+incompatible] // Accidental; no major changes or features.
7+
)

0 commit comments

Comments
 (0)