Codebase list golang-github-mattn-go-sqlite3 / e34ca64
New upstream version 1.14.14~ds1 Mathias Gibbens 1 year, 10 months ago
10 changed file(s) with 164 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
0 name: dockerfile
1
2 on:
3 workflow_dispatch:
4 push:
5 tags:
6 - 'v*'
7 pull_request:
8 branches: [ master ]
9
10 jobs:
11 dockerfile:
12 name: Run Dockerfiles in examples
13 runs-on: ubuntu-latest
14 steps:
15 - uses: actions/checkout@v2
16
17 - name: Run example - simple
18 run: |
19 cd ./_example/simple
20 docker build -t simple .
21 docker run simple | grep 99\ こんにちわ世界099
1313 strategy:
1414 matrix:
1515 os: [ubuntu-latest, macos-latest]
16 go: ['1.15', '1.16', '1.17']
16 go: ['1.16', '1.17', '1.18']
1717 fail-fast: false
1818 env:
1919 OS: ${{ matrix.os }}
2828
2929 - name: Get Build Tools
3030 run: |
31 GO111MODULE=on go get github.com/ory/go-acc
31 GO111MODULE=on go install github.com/ory/go-acc@latest
3232
3333 - name: Add $GOPATH/bin to $PATH
3434 run: |
6363
6464 strategy:
6565 matrix:
66 go: ['1.15', '1.16', '1.17']
66 go: ['1.16', '1.17', '1.18']
6767 fail-fast: false
6868 env:
6969 OS: windows-latest
0 # =============================================================================
1 # Multi-stage Dockerfile Example
2 # =============================================================================
3 # This is a simple Dockerfile that will build an image of scratch-base image.
4 # Usage:
5 # docker build -t simple:local . && docker run --rm simple:local
6 # =============================================================================
7
8 # -----------------------------------------------------------------------------
9 # Build Stage
10 # -----------------------------------------------------------------------------
11 FROM golang:alpine AS build
12
13 # Important:
14 # Because this is a CGO enabled package, you are required to set it as 1.
15 ENV CGO_ENABLED=1
16
17 RUN apk add --no-cache \
18 # Important: required for go-sqlite3
19 gcc \
20 # Required for Alpine
21 musl-dev
22
23 WORKDIR /workspace
24
25 COPY . /workspace/
26
27 RUN \
28 go mod init github.com/mattn/sample && \
29 go mod tidy && \
30 go install -ldflags='-s -w -extldflags "-static"' ./simple.go
31
32 RUN \
33 # Smoke test
34 set -o pipefail; \
35 /go/bin/simple | grep 99\ こんにちわ世界099
36
37 # -----------------------------------------------------------------------------
38 # Main Stage
39 # -----------------------------------------------------------------------------
40 FROM scratch
41
42 COPY --from=build /go/bin/simple /usr/local/bin/simple
43
44 ENTRYPOINT [ "/usr/local/bin/simple" ]
4141 log.Fatal(err)
4242 }
4343 }
44 tx.Commit()
44 err = tx.Commit()
45 if err != nil {
46 log.Fatal(err)
47 }
4548
4649 rows, err := db.Query("select id, name from foo")
4750 if err != nil {
352352 return nil
353353 }
354354
355 func callbackRetGeneric(ctx *C.sqlite3_context, v reflect.Value) error {
356 if v.IsNil() {
357 C.sqlite3_result_null(ctx)
358 return nil
359 }
360
361 cb, err := callbackRet(v.Elem().Type())
362 if err != nil {
363 return err
364 }
365
366 return cb(ctx, v.Elem())
367 }
368
355369 func callbackRet(typ reflect.Type) (callbackRetConverter, error) {
356370 switch typ.Kind() {
357371 case reflect.Interface:
359373 if typ.Implements(errorInterface) {
360374 return callbackRetNil, nil
361375 }
376
377 if typ.NumMethod() == 0 {
378 return callbackRetGeneric, nil
379 }
380
362381 fallthrough
363382 case reflect.Slice:
364383 if typ.Elem().Kind() != reflect.Uint8 {
101101 }
102102 }
103103 }
104
105 func TestCallbackReturnAny(t *testing.T) {
106 udf := func() interface{} {
107 return 1
108 }
109
110 typ := reflect.TypeOf(udf)
111 _, err := callbackRet(typ.Out(0))
112 if err != nil {
113 t.Errorf("Expected valid callback for any return type, got: %s", err)
114 }
115 }
+0
-13
sqlite3_opt_json1.go less more
0 // Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
1 //
2 // Use of this source code is governed by an MIT-style
3 // license that can be found in the LICENSE file.
4
5 // +build sqlite_json sqlite_json1 json1
6
7 package sqlite3
8
9 /*
10 #cgo CFLAGS: -DSQLITE_ENABLE_JSON1
11 */
12 import "C"
3232 // The callback is passed a SQLitePreUpdateData struct with the data for
3333 // the update, as well as methods for fetching copies of impacted data.
3434 //
35 // If there is an existing update hook for this connection, it will be
35 // If there is an existing preupdate hook for this connection, it will be
3636 // removed. If callback is nil the existing hook (if any) will be removed
3737 // without creating a new one.
3838 func (c *SQLiteConn) RegisterPreUpdateHook(callback func(SQLitePreUpdateData)) {
1212 // The callback is passed a SQLitePreUpdateData struct with the data for
1313 // the update, as well as methods for fetching copies of impacted data.
1414 //
15 // If there is an existing update hook for this connection, it will be
15 // If there is an existing preupdate hook for this connection, it will be
1616 // removed. If callback is nil the existing hook (if any) will be removed
1717 // without creating a new one.
1818 func (c *SQLiteConn) RegisterPreUpdateHook(callback func(SQLitePreUpdateData)) {
14451445 if ret != test.sum {
14461446 t.Fatalf("Custom sum returned wrong value, got %d, want %d", ret, test.sum)
14471447 }
1448 }
1449 }
1450
1451 type mode struct {
1452 counts map[interface{}]int
1453 top interface{}
1454 topCount int
1455 }
1456
1457 func newMode() *mode {
1458 return &mode{
1459 counts: map[interface{}]int{},
1460 }
1461 }
1462
1463 func (m *mode) Step(x interface{}) {
1464 m.counts[x]++
1465 c := m.counts[x]
1466 if c > m.topCount {
1467 m.top = x
1468 m.topCount = c
1469 }
1470 }
1471
1472 func (m *mode) Done() interface{} {
1473 return m.top
1474 }
1475
1476 func TestAggregatorRegistration_GenericReturn(t *testing.T) {
1477 sql.Register("sqlite3_AggregatorRegistration_GenericReturn", &SQLiteDriver{
1478 ConnectHook: func(conn *SQLiteConn) error {
1479 return conn.RegisterAggregator("mode", newMode, true)
1480 },
1481 })
1482 db, err := sql.Open("sqlite3_AggregatorRegistration_GenericReturn", ":memory:")
1483 if err != nil {
1484 t.Fatal("Failed to open database:", err)
1485 }
1486 defer db.Close()
1487
1488 _, err = db.Exec("create table foo (department integer, profits integer)")
1489 if err != nil {
1490 t.Fatal("Failed to create table:", err)
1491 }
1492 _, err = db.Exec("insert into foo values (1, 10), (1, 20), (1, 45), (2, 42), (2, 115), (2, 20)")
1493 if err != nil {
1494 t.Fatal("Failed to insert records:", err)
1495 }
1496
1497 var mode int
1498 err = db.QueryRow("select mode(profits) from foo").Scan(&mode)
1499 if err != nil {
1500 t.Fatal("MODE query error:", err)
1501 }
1502
1503 if mode != 20 {
1504 t.Fatal("Got incorrect mode. Wanted 20, got: ", mode)
14481505 }
14491506 }
14501507