Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version upgrades #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions MAINTENANCE
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ tracked for changes (maintenance details below):
Update code from https://github.com/mattn/go-sqlite3
----------------------------------------------------

Current release: v1.14.5
Current release: v1.14.16

Use ./track_go-sqlite3.sh


Update code from https://github.com/sqlcipher/sqlcipher
-------------------------------------------------------

Current release: v4.4.2
Current release: v4.5.4

Execute:
./configure
Expand All @@ -31,7 +31,7 @@ sqlite3.c
Update code from https://github.com/libtom/libtomcrypt
------------------------------------------------------

Current HEAD: cfbd7f8d364e1438555ff2a247f7e17add11840e
(from develop branch, 2020-08-29)
Current HEAD: 1e629e6f64661a01b9f6164a50080c43cd4d7b84
(from develop branch, 2023-06-22)

Use ./track_libtomcrypt.sh
12 changes: 12 additions & 0 deletions _example/custom_driver_name/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TARGET = custom_driver_name
ifeq ($(OS),Windows_NT)
TARGET := $(TARGET).exe
endif

all : $(TARGET)

$(TARGET) : main.go
go build -ldflags="-X 'github.com/mattn/go-sqlite3.driverName=my-sqlite3'"

clean :
rm -f $(TARGET)
13 changes: 13 additions & 0 deletions _example/custom_driver_name/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"database/sql"

_ "github.com/mutecomm/go-sqlcipher/v4"
)

func main() {
for _, driver := range sql.Drivers() {
println(driver)
}
}
30 changes: 30 additions & 0 deletions _example/fuzz/fuzz_openexec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package sqlite3_fuzz

import (
"bytes"
"database/sql"
"io/ioutil"

_ "github.com/mutecomm/go-sqlcipher/v4"
)

func FuzzOpenExec(data []byte) int {
sep := bytes.IndexByte(data, 0)
if sep <= 0 {
return 0
}
err := ioutil.WriteFile("/tmp/fuzz.db", data[sep+1:], 0644)
if err != nil {
return 0
}
db, err := sql.Open("sqlite3", "/tmp/fuzz.db")
if err != nil {
return 0
}
defer db.Close()
_, err = db.Exec(string(data[:sep-1]))
if err != nil {
return 0
}
return 1
}
2 changes: 1 addition & 1 deletion _example/limit/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func createBulkInsertQuery(n int, start int) (query string, args []interface{})
for i := 0; i < n; i++ {
values[i] = "(?, ?)"
args[pos] = start + i
args[pos+1] = fmt.Sprintf("こんにちわ世界%03d", i)
args[pos+1] = fmt.Sprintf("こんにちは世界%03d", i)
pos += 2
}
query = fmt.Sprintf(
Expand Down
45 changes: 45 additions & 0 deletions _example/simple/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# =============================================================================
# Multi-stage Dockerfile Example
# =============================================================================
# This is a simple Dockerfile that will build an image of scratch-base image.
# Usage:
# docker build -t simple:local . && docker run --rm simple:local
# =============================================================================

# -----------------------------------------------------------------------------
# Build Stage
# -----------------------------------------------------------------------------
FROM golang:alpine AS build

# Important:
# Because this is a CGO enabled package, you are required to set it as 1.
ENV CGO_ENABLED=1

RUN apk add --no-cache \
# Important: required for go-sqlite3
gcc \
# Required for Alpine
musl-dev

WORKDIR /workspace

COPY . /workspace/

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

RUN \
# Smoke test
set -o pipefail; \
/go/bin/simple | grep 99\ こんにちは世界099

# -----------------------------------------------------------------------------
# Main Stage
# -----------------------------------------------------------------------------
FROM scratch

COPY --from=build /go/bin/simple /usr/local/bin/simple

ENTRYPOINT [ "/usr/local/bin/simple" ]
7 changes: 5 additions & 2 deletions _example/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ func main() {
}
defer stmt.Close()
for i := 0; i < 100; i++ {
_, err = stmt.Exec(i, fmt.Sprintf("こんにちわ世界%03d", i))
_, err = stmt.Exec(i, fmt.Sprintf("こんにちは世界%03d", i))
if err != nil {
log.Fatal(err)
}
}
tx.Commit()
err = tx.Commit()
if err != nil {
log.Fatal(err)
}

rows, err := db.Query("select id, name from foo")
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion _example/vtable/vtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ func (v *ghRepoTable) Open() (sqlite3.VTabCursor, error) {
}

func (v *ghRepoTable) BestIndex(cst []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
return &sqlite3.IndexResult{}, nil
used := make([]bool, len(csts))
return &sqlite3.IndexResult{
IdxNum: 0,
IdxStr: "default",
Used: used,
}, nil
}

func (v *ghRepoTable) Disconnect() error { return nil }
Expand Down
33 changes: 33 additions & 0 deletions _example/vtable_eponymous_only/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"database/sql"
"fmt"
"log"

sqlite3 "github.com/mutecomm/go-sqlcipher/v4"
)

func main() {
sql.Register("sqlite3_with_extensions", &sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
return conn.CreateModule("series", &seriesModule{})
},
})
db, err := sql.Open("sqlite3_with_extensions", ":memory:")
if err != nil {
log.Fatal(err)
}
defer db.Close()

rows, err := db.Query("select * from series")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var value int
rows.Scan(&value)
fmt.Printf("value: %d\n", value)
}
}
118 changes: 118 additions & 0 deletions _example/vtable_eponymous_only/vtable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package main

import (
"fmt"

sqlite3 "github.com/mutecomm/go-sqlcipher/v4"
)

type seriesModule struct{}

func (m *seriesModule) EponymousOnlyModule() {}

func (m *seriesModule) Create(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
err := c.DeclareVTab(fmt.Sprintf(`
CREATE TABLE %s (
value INT,
start HIDDEN,
stop HIDDEN,
step HIDDEN
)`, args[0]))
if err != nil {
return nil, err
}
return &seriesTable{0, 0, 1}, nil
}

func (m *seriesModule) Connect(c *sqlite3.SQLiteConn, args []string) (sqlite3.VTab, error) {
return m.Create(c, args)
}

func (m *seriesModule) DestroyModule() {}

type seriesTable struct {
start int64
stop int64
step int64
}

func (v *seriesTable) Open() (sqlite3.VTabCursor, error) {
return &seriesCursor{v, 0}, nil
}

func (v *seriesTable) BestIndex(csts []sqlite3.InfoConstraint, ob []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
used := make([]bool, len(csts))
for c, cst := range csts {
if cst.Usable && cst.Op == sqlite3.OpEQ {
used[c] = true
}
}

return &sqlite3.IndexResult{
IdxNum: 0,
IdxStr: "default",
Used: used,
}, nil
}

func (v *seriesTable) Disconnect() error { return nil }
func (v *seriesTable) Destroy() error { return nil }

type seriesCursor struct {
*seriesTable
value int64
}

func (vc *seriesCursor) Column(c *sqlite3.SQLiteContext, col int) error {
switch col {
case 0:
c.ResultInt64(vc.value)
case 1:
c.ResultInt64(vc.seriesTable.start)
case 2:
c.ResultInt64(vc.seriesTable.stop)
case 3:
c.ResultInt64(vc.seriesTable.step)
}
return nil
}

func (vc *seriesCursor) Filter(idxNum int, idxStr string, vals []interface{}) error {
switch {
case len(vals) < 1:
vc.seriesTable.start = 0
vc.seriesTable.stop = 1000
vc.value = vc.seriesTable.start
case len(vals) < 2:
vc.seriesTable.start = vals[0].(int64)
vc.seriesTable.stop = 1000
vc.value = vc.seriesTable.start
case len(vals) < 3:
vc.seriesTable.start = vals[0].(int64)
vc.seriesTable.stop = vals[1].(int64)
vc.value = vc.seriesTable.start
case len(vals) < 4:
vc.seriesTable.start = vals[0].(int64)
vc.seriesTable.stop = vals[1].(int64)
vc.seriesTable.step = vals[2].(int64)
}

return nil
}

func (vc *seriesCursor) Next() error {
vc.value += vc.step
return nil
}

func (vc *seriesCursor) EOF() bool {
return vc.value > vc.stop
}

func (vc *seriesCursor) Rowid() (int64, error) {
return int64(vc.value), nil
}

func (vc *seriesCursor) Close() error {
return nil
}
18 changes: 0 additions & 18 deletions aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ const struct ltc_cipher_descriptor rijndael_desc =
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};

const struct ltc_cipher_descriptor aes_desc =
{
"aes",
6,
16, 32, 16, 10,
SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};

#else

#define SETUP rijndael_enc_setup
Expand All @@ -69,15 +60,6 @@ const struct ltc_cipher_descriptor rijndael_enc_desc =
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};

const struct ltc_cipher_descriptor aes_enc_desc =
{
"aes",
6,
16, 32, 16, 10,
SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};

#endif

#define LTC_AES_TAB_C
Expand Down
2 changes: 1 addition & 1 deletion backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package sqlite3

/*
#ifndef USE_LIBSQLITE3
#include <sqlite3-binding.h>
#include "sqlite3-binding.h"
#else
#include <sqlite3.h>
#endif
Expand Down
Loading