Skip to content

Commit 40fb371

Browse files
committed
Upgrade the SQLCipher to the latest version.
2 parents e2b0cbb + 61ad8da commit 40fb371

Some content is hidden

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

57 files changed

+15179
-8931
lines changed

.github/FUNDING.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: mattn # Replace with a single Patreon username
5+
open_collective: mattn # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
custom: # Replace with a single custom sponsorship URL

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ go:
1111
- 1.9.x
1212
- 1.10.x
1313
- 1.11.x
14+
- 1.12.x
15+
- 1.13.x
1416
- master
1517

1618
before_install:
@@ -25,6 +27,5 @@ before_install:
2527
script:
2628
- $HOME/gopath/bin/goveralls -repotoken PfqH9iFyzW3daUxflzllSougjTxvFwQZE
2729
- go test -race -v . -tags ""
28-
- go test -race -v . -tags "libsqlite3"
29-
- go test -race -v . -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_userauth sqlite_vacuum_incr sqlite_vtable sqlite_unlock_notify"
30+
- go test -race -v . -tags "sqlite_allow_uri_authority sqlite_app_armor sqlite_foreign_keys sqlite_fts5 sqlite_icu sqlite_introspect sqlite_json sqlite_preupdate_hook sqlite_secure_delete sqlite_see sqlite_stat4 sqlite_trace sqlite_vacuum_incr sqlite_vtable sqlite_unlock_notify"
3031
- go test -race -v . -tags "sqlite_vacuum_full"

README.md

+101-14
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ go-sqlcipher
44

55
SQLCipher driver conforming to the built-in database/sql interface and using the latest sqlite3 code.
66

7+
[![GoDoc Reference](https://godoc.org/github.com/xeodou/go-sqlcipher?status.svg)](http://godoc.org/github.com/xeodou/go-sqlcipher)
8+
[![Build Status](https://travis-ci.org/xeodou/go-sqlcipher.svg?branch=master)](https://travis-ci.org/xeodou/go-sqlcipher)
9+
[![Coverage Status](https://coveralls.io/repos/xeodou/go-sqlcipher/badge.svg?branch=master)](https://coveralls.io/r/xeodou/go-sqlcipher?branch=master)
10+
[![Go Report Card](https://goreportcard.com/badge/github.com/xeodou/go-sqlcipher)](https://goreportcard.com/report/github.com/xeodou/go-sqlcipher)
11+
12+
NOTE: v2.0.1 or higher is unfortunatal release. So there are no big changes. And does not provide v2 feature.
13+
14+
# Description
715

816
which is
9-
`3.26.0`
17+
`3.31.0`
1018

1119
Working with sqlcipher version which is
12-
`4.0.1`
20+
`4.3.0`
1321

1422
It's wrapper with
1523
* [go-sqlite3](https://github.com/mattn/go-sqlite3) sqlite3 driver for go that using database/sql.
@@ -34,15 +42,21 @@ To upgrade SQLCipher from 3.x to 4.x, please take a look of:
3442

3543
### Overview
3644

45+
- [go-sqlite3](#go-sqlite3)
46+
- [Description](#description)
47+
- [Overview](#overview)
3748
- [Installation](#installation)
3849
- [API Reference](#api-reference)
3950
- [Connection String](#connection-string)
51+
- [DSN Examples](#dsn-examples)
4052
- [Features](#features)
53+
- [Usage](#usage)
54+
- [Feature / Extension List](#feature--extension-list)
4155
- [Compilation](#compilation)
4256
- [Android](#android)
43-
- [ARM](#arm)
44-
- [Cross Compile](#cross-compile)
45-
- [Google Cloud Platform](#google-cloud-platform)
57+
- [ARM](#arm)
58+
- [Cross Compile](#cross-compile)
59+
- [Google Cloud Platform](#google-cloud-platform)
4660
- [Linux](#linux)
4761
- [Alpine](#alpine)
4862
- [Fedora](#fedora)
@@ -52,11 +66,22 @@ To upgrade SQLCipher from 3.x to 4.x, please take a look of:
5266
- [Errors](#errors)
5367
- [User Authentication](#user-authentication)
5468
- [Compile](#compile)
55-
- [Usage](#usage)
69+
- [Usage](#usage-1)
70+
- [Create protected database](#create-protected-database)
71+
- [Password Encoding](#password-encoding)
72+
- [Available Encoders](#available-encoders)
73+
- [Restrictions](#restrictions)
74+
- [Support](#support)
75+
- [User Management](#user-management)
76+
- [SQL](#sql)
77+
- [Examples](#examples)
78+
- [*SQLiteConn](#sqliteconn)
79+
- [Attached database](#attached-database)
5680
- [Extensions](#extensions)
5781
- [Spatialite](#spatialite)
5882
- [FAQ](#faq)
5983
- [License](#license)
84+
- [Author](#author)
6085

6186
# Installation
6287

@@ -134,6 +159,9 @@ This package allows additional configuration of features available within SQLite
134159

135160
[Click here for more information about build tags / constraints.](https://golang.org/pkg/go/build/#hdr-Build_Constraints)
136161

162+
**Please notice**
163+
The `userAuthentication` extention is not support the library, since the SQLCipher is already let you create the encrypted database.
164+
137165
### Usage
138166

139167
If you wish to build this library with additional extensions / features.
@@ -145,7 +173,7 @@ go build --tags "<FEATURE>"
145173

146174
If you want to build the project without the `libcrypto`, you could specific the openssl library by using the command.
147175
```bash
148-
CGO_ENABLE=0 CGO_LDFLAGS="-L/usr/local/opt/openssl/lib" CGO_CPPFLAGS="-I/usr/local/opt/openssl/include" go build build _example/encrypto/encrypto.go
176+
CGO_ENABLE=1 CGO_LDFLAGS="-L/usr/local/opt/openssl/lib" CGO_CPPFLAGS="-I/usr/local/opt/openssl/include" go build _example/encrypto/encrypto.go
149177
```
150178

151179
For available features see the extension list.
@@ -172,6 +200,7 @@ go build --tags "icu json1 fts5 secure_delete"
172200
| International Components for Unicode | sqlite_icu | This option causes the International Components for Unicode or "ICU" extension to SQLite to be added to the build |
173201
| Introspect PRAGMAS | sqlite_introspect | This option adds some extra PRAGMA statements. <ul><li>PRAGMA function_list</li><li>PRAGMA module_list</li><li>PRAGMA pragma_list</li></ul> |
174202
| JSON SQL Functions | sqlite_json | When this option is defined in the amalgamation, the JSON SQL functions are added to the build automatically |
203+
| Pre Update Hook | sqlite_preupdate_hook | Registers a callback function that is invoked prior to each INSERT, UPDATE, and DELETE operation on a database table. |
175204
| Secure Delete | sqlite_secure_delete | This compile-time option changes the default setting of the secure_delete pragma.<br><br>When this option is not used, secure_delete defaults to off. When this option is present, secure_delete defaults to on.<br><br>The secure_delete setting causes deleted content to be overwritten with zeros. There is a small performance penalty since additional I/O must occur.<br><br>On the other hand, secure_delete can prevent fragments of sensitive information from lingering in unused parts of the database file after it has been deleted. See the documentation on the secure_delete pragma for additional information |
176205
| Secure Delete (FAST) | sqlite_secure_delete_fast | For more information see [PRAGMA secure_delete](https://www.sqlite.org/pragma.html#pragma_secure_delete) |
177206
| Tracing / Debug | sqlite_trace | Activate trace functions |
@@ -270,7 +299,7 @@ Required dependency
270299
brew install sqlite3
271300
```
272301

273-
For OSX there is an additional package install which is required if you whish to build the `icu` extension.
302+
For OSX there is an additional package install which is required if you wish to build the `icu` extension.
274303

275304
This additional package can be installed with `homebrew`.
276305

@@ -460,6 +489,16 @@ If you want your own extension to be listed here or you want to add a reference
460489
Spatialite is available as an extension to SQLite, and can be used in combination with this repository.
461490
For an example see [shaxbee/go-spatialite](https://github.com/shaxbee/go-spatialite).
462491
492+
## extension-functions.c from SQLite3 Contrib
493+
494+
extension-functions.c is available as an extension to SQLite, and provides the following functions:
495+
496+
- Math: acos, asin, atan, atn2, atan2, acosh, asinh, atanh, difference, degrees, radians, cos, sin, tan, cot, cosh, sinh, tanh, coth, exp, log, log10, power, sign, sqrt, square, ceil, floor, pi.
497+
- String: replicate, charindex, leftstr, rightstr, ltrim, rtrim, trim, replace, reverse, proper, padl, padr, padc, strfilter.
498+
- Aggregate: stdev, variance, mode, median, lower_quartile, upper_quartile
499+
500+
For an example see [dinedal/go-sqlite3-extension-functions](https://github.com/dinedal/go-sqlite3-extension-functions).
501+
463502
# FAQ
464503
465504
- Getting insert error while query is opened.
@@ -484,15 +523,19 @@ For an example see [shaxbee/go-spatialite](https://github.com/shaxbee/go-spatial
484523

485524
Why is it racy if I use a `sql.Open("sqlite3", ":memory:")` database?
486525

487-
Each connection to :memory: opens a brand new in-memory sql database, so if
526+
Each connection to `":memory:"` opens a brand new in-memory sql database, so if
488527
the stdlib's sql engine happens to open another connection and you've only
489-
specified ":memory:", that connection will see a brand new database. A
490-
workaround is to use "file::memory:?mode=memory&cache=shared". Every
528+
specified `":memory:"`, that connection will see a brand new database. A
529+
workaround is to use `"file::memory:?cache=shared"` (or `"file:foobar?mode=memory&cache=shared"`). Every
491530
connection to this string will point to the same in-memory database.
492531

532+
Note that if the last database connection in the pool closes, the in-memory database is deleted. Make sure the [max idle connection limit](https://golang.org/pkg/database/sql/#DB.SetMaxIdleConns) is > 0, and the [connection lifetime](https://golang.org/pkg/database/sql/#DB.SetConnMaxLifetime) is infinite.
533+
493534
For more information see
494535
* [#204](https://github.com/mattn/go-sqlite3/issues/204)
495536
* [#511](https://github.com/mattn/go-sqlite3/issues/511)
537+
* https://www.sqlite.org/sharedcache.html#shared_cache_and_in_memory_databases
538+
* https://www.sqlite.org/inmemorydb.html#sharedmemdb
496539

497540
- Reading from database with large amount of goroutines fails on OSX.
498541

@@ -507,12 +550,56 @@ For an example see [shaxbee/go-spatialite](https://github.com/shaxbee/go-spatial
507550

508551
You need to implement the feature or call the sqlite3 cli.
509552

510-
* Print some waring messages like `warning: 'RAND_add' is deprecated: first deprecated in OS X 10.7`
553+
More information see [#305](https://github.com/mattn/go-sqlite3/issues/305)
554+
555+
- Error: `database is locked`
511556

512557
You can ignore these messages.
513558

514-
License
515-
-------
559+
Example:
560+
```go
561+
db, err := sql.Open("sqlite3", "file:locked.sqlite?cache=shared")
562+
```
563+
564+
Second please set the database connections of the SQL package to 1.
565+
566+
```go
567+
db.SetMaxOpenConns(1)
568+
```
569+
570+
More information see [#209](https://github.com/mattn/go-sqlite3/issues/209)
571+
572+
## Contributors
573+
574+
### Code Contributors
575+
576+
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
577+
<a href="https://github.com/mattn/go-sqlite3/graphs/contributors"><img src="https://opencollective.com/mattn-go-sqlite3/contributors.svg?width=890&button=false" /></a>
578+
579+
### Financial Contributors
580+
581+
Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/mattn-go-sqlite3/contribute)]
582+
583+
#### Individuals
584+
585+
<a href="https://opencollective.com/mattn-go-sqlite3"><img src="https://opencollective.com/mattn-go-sqlite3/individuals.svg?width=890"></a>
586+
587+
#### Organizations
588+
589+
Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/mattn-go-sqlite3/contribute)]
590+
591+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/0/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/0/avatar.svg"></a>
592+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/1/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/1/avatar.svg"></a>
593+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/2/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/2/avatar.svg"></a>
594+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/3/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/3/avatar.svg"></a>
595+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/4/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/4/avatar.svg"></a>
596+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/5/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/5/avatar.svg"></a>
597+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/6/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/6/avatar.svg"></a>
598+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/7/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/7/avatar.svg"></a>
599+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/8/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/8/avatar.svg"></a>
600+
<a href="https://opencollective.com/mattn-go-sqlite3/organization/9/website"><img src="https://opencollective.com/mattn-go-sqlite3/organization/9/avatar.svg"></a>
601+
602+
# License
516603

517604
MIT:
518605

_example/limit/limit.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func createBulkInsertQuery(n int, start int) (query string, args []interface{})
2727
return
2828
}
2929

30-
func bukInsert(db *sql.DB, query string, args []interface{}) (err error) {
30+
func bulkInsert(db *sql.DB, query string, args []interface{}) (err error) {
3131
stmt, err := db.Prepare(query)
3232
if err != nil {
3333
return
@@ -76,7 +76,7 @@ func main() {
7676

7777
num := 400
7878
query, args := createBulkInsertQuery(num, 0)
79-
err = bukInsert(db, query, args)
79+
err = bulkInsert(db, query, args)
8080
if err != nil {
8181
log.Fatal(err)
8282
}
@@ -88,7 +88,7 @@ func main() {
8888
log.Printf("updated SQLITE_LIMIT_VARIABLE_NUMBER: %d", limitVariableNumber)
8989

9090
query, args = createBulkInsertQuery(num, num)
91-
err = bukInsert(db, query, args)
91+
err = bulkInsert(db, query, args)
9292
if err != nil {
9393
if err != nil {
9494
log.Printf("expect failed since SQLITE_LIMIT_VARIABLE_NUMBER is too small: %v", err)
@@ -102,7 +102,7 @@ func main() {
102102
log.Printf("updated SQLITE_LIMIT_VARIABLE_NUMBER: %d", limitVariableNumber)
103103

104104
query, args = createBulkInsertQuery(500, num+num)
105-
err = bukInsert(db, query, args)
105+
err = bulkInsert(db, query, args)
106106
if err != nil {
107107
if err != nil {
108108
log.Fatal(err)

_example/mod_regexp/Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
ifeq ($(OS),Windows_NT)
22
EXE=extension.exe
3-
EXT=sqlite3_mod_regexp.dll
3+
LIB_EXT=dll
44
RM=cmd /c del
55
LDFLAG=
66
else
77
EXE=extension
8-
EXT=sqlite3_mod_regexp.so
9-
RM=rm
8+
ifeq ($(shell uname -s),Darwin)
9+
LIB_EXT=dylib
10+
else
11+
LIB_EXT=so
12+
endif
13+
RM=rm -f
1014
LDFLAG=-fPIC
1115
endif
16+
LIB=sqlite3_mod_regexp.$(LIB_EXT)
1217

13-
all : $(EXE) $(EXT)
18+
all : $(EXE) $(LIB)
1419

1520
$(EXE) : extension.go
1621
go build $<
1722

18-
$(EXT) : sqlite3_mod_regexp.c
23+
$(LIB) : sqlite3_mod_regexp.c
1924
gcc $(LDFLAG) -shared -o $@ $< -lsqlite3 -lpcre
2025

2126
clean :
22-
@-$(RM) $(EXE) $(EXT)
27+
@-$(RM) $(EXE) $(LIB)

_example/mod_regexp/sqlite3_mod_regexp.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv
1313
int vec[500];
1414
int n, rc;
1515
pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL);
16+
if (!re) {
17+
sqlite3_result_error(context, errstr, 0);
18+
return;
19+
}
1620
rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500);
1721
if (rc <= 0) {
18-
sqlite3_result_error(context, errstr, 0);
22+
sqlite3_result_int(context, 0);
1923
return;
2024
}
2125
sqlite3_result_int(context, 1);

_example/mod_vtable/Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
ifeq ($(OS),Windows_NT)
22
EXE=extension.exe
3-
EXT=sqlite3_mod_vtable.dll
3+
LIB_EXT=dll
44
RM=cmd /c del
55
LIBCURL=-lcurldll
66
LDFLAG=
77
else
88
EXE=extension
9-
EXT=sqlite3_mod_vtable.so
10-
RM=rm
9+
ifeq ($(shell uname -s),Darwin)
10+
LIB_EXT=dylib
11+
else
12+
LIB_EXT=so
13+
endif
14+
RM=rm -f
1115
LDFLAG=-fPIC
1216
LIBCURL=-lcurl
1317
endif
18+
LIB=sqlite3_mod_vtable.$(LIB_EXT)
1419

15-
all : $(EXE) $(EXT)
20+
all : $(EXE) $(LIB)
1621

1722
$(EXE) : extension.go
1823
go build $<
1924

20-
$(EXT) : sqlite3_mod_vtable.cc
25+
$(LIB) : sqlite3_mod_vtable.cc
2126
g++ $(LDFLAG) -shared -o $@ $< -lsqlite3 $(LIBCURL)
2227

2328
clean :
24-
@-$(RM) $(EXE) $(EXT)
29+
@-$(RM) $(EXE) $(LIB)

_example/mod_vtable/sqlite3_mod_vtable.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <string>
22
#include <sstream>
3-
#include <sqlite3-binding.h>
3+
#include <sqlite3.h>
44
#include <sqlite3ext.h>
55
#include <curl/curl.h>
66
#include "picojson.h"

backup.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2014 Yasuhiro Matsumoto <[email protected]>.
1+
// Copyright (C) 2019 Yasuhiro Matsumoto <[email protected]>.
22
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file.
@@ -25,18 +25,18 @@ type SQLiteBackup struct {
2525
}
2626

2727
// Backup make backup from src to dest.
28-
func (c *SQLiteConn) Backup(dest string, conn *SQLiteConn, src string) (*SQLiteBackup, error) {
28+
func (destConn *SQLiteConn) Backup(dest string, srcConn *SQLiteConn, src string) (*SQLiteBackup, error) {
2929
destptr := C.CString(dest)
3030
defer C.free(unsafe.Pointer(destptr))
3131
srcptr := C.CString(src)
3232
defer C.free(unsafe.Pointer(srcptr))
3333

34-
if b := C.sqlite3_backup_init(c.db, destptr, conn.db, srcptr); b != nil {
34+
if b := C.sqlite3_backup_init(destConn.db, destptr, srcConn.db, srcptr); b != nil {
3535
bb := &SQLiteBackup{b: b}
3636
runtime.SetFinalizer(bb, (*SQLiteBackup).Finish)
3737
return bb, nil
3838
}
39-
return nil, c.lastError()
39+
return nil, destConn.lastError()
4040
}
4141

4242
// Step to backs up for one step. Calls the underlying `sqlite3_backup_step`

0 commit comments

Comments
 (0)