forked from mirrors/gotosocial
[chore]: Bump modernc.org/sqlite from 1.23.1 to 1.24.0 (#1993)
Bumps [modernc.org/sqlite](https://gitlab.com/cznic/sqlite) from 1.23.1 to 1.24.0. - [Commits](https://gitlab.com/cznic/sqlite/compare/v1.23.1...v1.24.0) --- updated-dependencies: - dependency-name: modernc.org/sqlite dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
da8282081c
commit
43a2753ef0
7 changed files with 289 additions and 88 deletions
2
go.mod
2
go.mod
|
@ -67,7 +67,7 @@ require (
|
|||
golang.org/x/text v0.11.0
|
||||
gopkg.in/mcuadros/go-syslog.v2 v2.3.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
modernc.org/sqlite v1.23.1
|
||||
modernc.org/sqlite v1.24.0
|
||||
mvdan.cc/xurls/v2 v2.5.0
|
||||
)
|
||||
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1100,8 +1100,8 @@ modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
|
|||
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
|
||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
|
||||
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
|
||||
modernc.org/sqlite v1.24.0 h1:EsClRIWHGhLTCX44p+Ri/JLD+vFGo0QGjasg2/F9TlI=
|
||||
modernc.org/sqlite v1.24.0/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
|
||||
modernc.org/strutil v1.1.3 h1:fNMm+oJklMGYfU9Ylcywl0CO5O6nTfaowNsh2wpPjzY=
|
||||
modernc.org/strutil v1.1.3/go.mod h1:MEHNA7PdEnEwLvspRMtWTNnp2nnyvMfkimT1NKNAGbw=
|
||||
modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY=
|
||||
|
|
1
vendor/modernc.org/sqlite/AUTHORS
generated
vendored
1
vendor/modernc.org/sqlite/AUTHORS
generated
vendored
|
@ -9,6 +9,7 @@
|
|||
# Please keep the list sorted.
|
||||
|
||||
Artyom Pervukhin <github@artyom.dev>
|
||||
Dan Kortschak <dan@kortschak.io>
|
||||
Dan Peterson <danp@danp.net>
|
||||
David Walton <david@davidwalton.com>
|
||||
Davsk Ltd Co <skinner.david@gmail.com>
|
||||
|
|
2
vendor/modernc.org/sqlite/CONTRIBUTORS
generated
vendored
2
vendor/modernc.org/sqlite/CONTRIBUTORS
generated
vendored
|
@ -9,6 +9,7 @@
|
|||
Alexander Menzhinsky <amenzhinsky@gmail.com>
|
||||
Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
|
||||
Artyom Pervukhin <github@artyom.dev>
|
||||
Dan Kortschak <dan@kortschak.io>
|
||||
Dan Peterson <danp@danp.net>
|
||||
David Skinner <skinner.david@gmail.com>
|
||||
David Walton <david@davidwalton.com>
|
||||
|
@ -22,6 +23,7 @@ Logan Snow <logansnow@protonmail.com>
|
|||
Matthew Gabeler-Lee <fastcat@gmail.com>
|
||||
Michael Hoffmann <mhoffm@posteo.de>
|
||||
Michael Rykov <mrykov@gmail.com>
|
||||
Romain Le Disez <r.gitlab@ledisez.net>
|
||||
Ross Light <ross@zombiezen.com>
|
||||
Saed SayedAhmed <saadmtsa@gmail.com>
|
||||
Sean McGivern <sean@mcgivern.me.uk>
|
||||
|
|
32
vendor/modernc.org/sqlite/doc.go
generated
vendored
32
vendor/modernc.org/sqlite/doc.go
generated
vendored
|
@ -8,12 +8,12 @@
|
|||
// SQLite is an in-process implementation of a self-contained, serverless,
|
||||
// zero-configuration, transactional SQL database engine.
|
||||
//
|
||||
// Thanks
|
||||
// # Thanks
|
||||
//
|
||||
// This project is sponsored by Schleibinger Geräte Teubert u. Greim GmbH by
|
||||
// allowing one of the maintainers to work on it also in office hours.
|
||||
//
|
||||
// Supported platforms and architectures
|
||||
// # Supported platforms and architectures
|
||||
//
|
||||
// These combinations of GOOS and GOARCH are currently supported
|
||||
//
|
||||
|
@ -33,13 +33,13 @@
|
|||
// windows amd64 3.41.2
|
||||
// windows arm64 3.41.2
|
||||
//
|
||||
// Builders
|
||||
// # Builders
|
||||
//
|
||||
// Builder results available at:
|
||||
//
|
||||
// https://modern-c.appspot.com/-/builder/?importpath=modernc.org%2fsqlite
|
||||
//
|
||||
// Speedtest1
|
||||
// # Speedtest1
|
||||
//
|
||||
// Numbers for the pure Go version were produced by
|
||||
//
|
||||
|
@ -92,11 +92,15 @@
|
|||
//
|
||||
// This particular test executes 16.1% faster in the C version.
|
||||
//
|
||||
// Changelog
|
||||
// # Changelog
|
||||
//
|
||||
// 2023-07-11 v1.24.0:
|
||||
//
|
||||
// Add (*conn).{Serialize,Deserialize,NewBackup,NewRestore} methods, add Backup type.
|
||||
//
|
||||
// 2023-06-01 v1.23.0:
|
||||
//
|
||||
// Allow registering aggregate functions
|
||||
// Allow registering aggregate functions.
|
||||
//
|
||||
// 2023-04-22 v1.22.0:
|
||||
//
|
||||
|
@ -142,8 +146,6 @@
|
|||
//
|
||||
// Support freebsd/amd64.
|
||||
//
|
||||
// Changelog
|
||||
//
|
||||
// 2021-06-23 v1.11.0:
|
||||
//
|
||||
// Upgrade to use sqlite 3.36.0, release notes at https://www.sqlite.org/releaselog/3_36_0.html.
|
||||
|
@ -231,7 +233,7 @@
|
|||
//
|
||||
// 2017-06-05 Linux/Intel no more uses the VM (cznic/virtual).
|
||||
//
|
||||
// Connecting to a database
|
||||
// # Connecting to a database
|
||||
//
|
||||
// To access a Sqlite database do something like
|
||||
//
|
||||
|
@ -248,7 +250,7 @@
|
|||
//
|
||||
// ...
|
||||
//
|
||||
// Debug and development versions
|
||||
// # Debug and development versions
|
||||
//
|
||||
// A comma separated list of options can be passed to `go generate` via the
|
||||
// environment variable GO_GENERATE. Some useful options include for example:
|
||||
|
@ -263,11 +265,10 @@
|
|||
//
|
||||
// Note: To run `go generate` you need to have modernc.org/ccgo/v3 installed.
|
||||
//
|
||||
// Hacking
|
||||
// # Hacking
|
||||
//
|
||||
// This is an example of how to use the debug logs in modernc.org/libc when hunting a bug.
|
||||
//
|
||||
//
|
||||
// 0:jnml@e5-1650:~/src/modernc.org/sqlite$ git status
|
||||
// On branch master
|
||||
// Your branch is up to date with 'origin/master'.
|
||||
|
@ -290,10 +291,8 @@
|
|||
// [10723 sqlite.test] 2023-04-06 11:22:48.288066057 +0200 CEST m=+0.000707150
|
||||
// 0:jnml@e5-1650:~/src/modernc.org/sqlite$
|
||||
//
|
||||
//
|
||||
// The /tmp/libc.log file is created as requested. No useful messages there because none are enabled in libc. Let's try to enable Xwrite as an example.
|
||||
//
|
||||
//
|
||||
// 0:jnml@e5-1650:~/src/modernc.org/libc$ git status
|
||||
// On branch master
|
||||
// Your branch is up to date with 'origin/master'.
|
||||
|
@ -344,14 +343,11 @@
|
|||
// }
|
||||
// 0:jnml@e5-1650:~/src/modernc.org/libc$
|
||||
//
|
||||
//
|
||||
// We need to tell the Go build system to use our local, patched/debug libc:
|
||||
//
|
||||
//
|
||||
// 0:jnml@e5-1650:~/src/modernc.org/sqlite$ go work use $(go env GOPATH)/src/modernc.org/libc
|
||||
// 0:jnml@e5-1650:~/src/modernc.org/sqlite$ go work use .
|
||||
//
|
||||
//
|
||||
// And run the test again:
|
||||
//
|
||||
// 0:jnml@e5-1650:~/src/modernc.org/sqlite$ rm -f /tmp/libc.log ; go test -v -tags=libc.dmesg -run TestScalar ; ls -l /tmp/libc.log
|
||||
|
@ -379,7 +375,7 @@
|
|||
// [11910 sqlite.test] libc_linux.go:337:Xwrite: 7 0x1000: 0x1000
|
||||
// 0:jnml@e5-1650:~/src/modernc.org/sqlite$
|
||||
//
|
||||
// Sqlite documentation
|
||||
// # Sqlite documentation
|
||||
//
|
||||
// See https://sqlite.org/docs.html
|
||||
package sqlite // import "modernc.org/sqlite"
|
||||
|
|
206
vendor/modernc.org/sqlite/sqlite.go
generated
vendored
206
vendor/modernc.org/sqlite/sqlite.go
generated
vendored
|
@ -440,7 +440,7 @@ func (r *rows) ColumnTypeScanType(index int) reflect.Type {
|
|||
case sqlite3.SQLITE_TEXT:
|
||||
return reflect.TypeOf("")
|
||||
case sqlite3.SQLITE_BLOB:
|
||||
return reflect.SliceOf(reflect.TypeOf([]byte{}))
|
||||
return reflect.TypeOf([]byte(nil))
|
||||
case sqlite3.SQLITE_NULL:
|
||||
return reflect.TypeOf(nil)
|
||||
default:
|
||||
|
@ -474,7 +474,6 @@ func (s *stmt) Close() (err error) {
|
|||
|
||||
// Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.
|
||||
//
|
||||
//
|
||||
// Deprecated: Drivers should implement StmtExecContext instead (or
|
||||
// additionally).
|
||||
func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { //TODO StmtExecContext
|
||||
|
@ -582,6 +581,13 @@ func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Ro
|
|||
}
|
||||
|
||||
var allocs []uintptr
|
||||
|
||||
defer func() {
|
||||
if r == nil && err == nil {
|
||||
r, err = newRows(s.c, pstmt, allocs, true)
|
||||
}
|
||||
}()
|
||||
|
||||
for psql := s.psql; *(*byte)(unsafe.Pointer(psql)) != 0 && atomic.LoadInt32(&done) == 0; {
|
||||
if pstmt, err = s.c.prepareV2(&psql); err != nil {
|
||||
return nil, err
|
||||
|
@ -850,6 +856,8 @@ func applyQueryParams(c *conn, query string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// const void *sqlite3_column_blob(sqlite3_stmt*, int iCol);
|
||||
func (c *conn) columnBlob(pstmt uintptr, iCol int) (v []byte, err error) {
|
||||
p := sqlite3.Xsqlite3_column_blob(c.tls, pstmt, int32(iCol))
|
||||
|
@ -867,12 +875,16 @@ func (c *conn) columnBlob(pstmt uintptr, iCol int) (v []byte, err error) {
|
|||
return v, nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_column_bytes(sqlite3_stmt*, int iCol);
|
||||
func (c *conn) columnBytes(pstmt uintptr, iCol int) (_ int, err error) {
|
||||
v := sqlite3.Xsqlite3_column_bytes(c.tls, pstmt, int32(iCol))
|
||||
return int(v), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol);
|
||||
func (c *conn) columnText(pstmt uintptr, iCol int) (v string, err error) {
|
||||
p := sqlite3.Xsqlite3_column_text(c.tls, pstmt, int32(iCol))
|
||||
|
@ -890,52 +902,70 @@ func (c *conn) columnText(pstmt uintptr, iCol int) (v string, err error) {
|
|||
return string(b), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// double sqlite3_column_double(sqlite3_stmt*, int iCol);
|
||||
func (c *conn) columnDouble(pstmt uintptr, iCol int) (v float64, err error) {
|
||||
v = sqlite3.Xsqlite3_column_double(c.tls, pstmt, int32(iCol))
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol);
|
||||
func (c *conn) columnInt64(pstmt uintptr, iCol int) (v int64, err error) {
|
||||
v = sqlite3.Xsqlite3_column_int64(c.tls, pstmt, int32(iCol))
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_column_type(sqlite3_stmt*, int iCol);
|
||||
func (c *conn) columnType(pstmt uintptr, iCol int) (_ int, err error) {
|
||||
v := sqlite3.Xsqlite3_column_type(c.tls, pstmt, int32(iCol))
|
||||
return int(v), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// const char *sqlite3_column_decltype(sqlite3_stmt*,int);
|
||||
func (c *conn) columnDeclType(pstmt uintptr, iCol int) string {
|
||||
return libc.GoString(sqlite3.Xsqlite3_column_decltype(c.tls, pstmt, int32(iCol)))
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// const char *sqlite3_column_name(sqlite3_stmt*, int N);
|
||||
func (c *conn) columnName(pstmt uintptr, n int) (string, error) {
|
||||
p := sqlite3.Xsqlite3_column_name(c.tls, pstmt, int32(n))
|
||||
return libc.GoString(p), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_column_count(sqlite3_stmt *pStmt);
|
||||
func (c *conn) columnCount(pstmt uintptr) (_ int, err error) {
|
||||
v := sqlite3.Xsqlite3_column_count(c.tls, pstmt)
|
||||
return int(v), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
|
||||
func (c *conn) lastInsertRowID() (v int64, _ error) {
|
||||
return sqlite3.Xsqlite3_last_insert_rowid(c.tls, c.db), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_changes(sqlite3*);
|
||||
func (c *conn) changes() (int, error) {
|
||||
v := sqlite3.Xsqlite3_changes(c.tls, c.db)
|
||||
return int(v), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_step(sqlite3_stmt*);
|
||||
func (c *conn) step(pstmt uintptr) (int, error) {
|
||||
for {
|
||||
|
@ -1090,6 +1120,8 @@ func (c *conn) bind(pstmt uintptr, n int, args []driver.NamedValue) (allocs []ui
|
|||
return allocs, nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_bind_null(sqlite3_stmt*, int);
|
||||
func (c *conn) bindNull(pstmt uintptr, idx1 int) (uintptr, error) {
|
||||
if rc := sqlite3.Xsqlite3_bind_null(c.tls, pstmt, int32(idx1)); rc != sqlite3.SQLITE_OK {
|
||||
|
@ -1099,6 +1131,8 @@ func (c *conn) bindNull(pstmt uintptr, idx1 int) (uintptr, error) {
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*));
|
||||
func (c *conn) bindText(pstmt uintptr, idx1 int, value string) (uintptr, error) {
|
||||
p, err := libc.CString(value)
|
||||
|
@ -1114,6 +1148,8 @@ func (c *conn) bindText(pstmt uintptr, idx1 int, value string) (uintptr, error)
|
|||
return p, nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void(*)(void*));
|
||||
func (c *conn) bindBlob(pstmt uintptr, idx1 int, value []byte) (uintptr, error) {
|
||||
if value != nil && len(value) == 0 {
|
||||
|
@ -1138,6 +1174,8 @@ func (c *conn) bindBlob(pstmt uintptr, idx1 int, value []byte) (uintptr, error)
|
|||
return p, nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_bind_int(sqlite3_stmt*, int, int);
|
||||
func (c *conn) bindInt(pstmt uintptr, idx1, value int) (err error) {
|
||||
if rc := sqlite3.Xsqlite3_bind_int(c.tls, pstmt, int32(idx1), int32(value)); rc != sqlite3.SQLITE_OK {
|
||||
|
@ -1147,6 +1185,8 @@ func (c *conn) bindInt(pstmt uintptr, idx1, value int) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_bind_double(sqlite3_stmt*, int, double);
|
||||
func (c *conn) bindDouble(pstmt uintptr, idx1 int, value float64) (err error) {
|
||||
if rc := sqlite3.Xsqlite3_bind_double(c.tls, pstmt, int32(idx1), value); rc != 0 {
|
||||
|
@ -1156,6 +1196,8 @@ func (c *conn) bindDouble(pstmt uintptr, idx1 int, value float64) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
|
||||
func (c *conn) bindInt64(pstmt uintptr, idx1 int, value int64) (err error) {
|
||||
if rc := sqlite3.Xsqlite3_bind_int64(c.tls, pstmt, int32(idx1), value); rc != sqlite3.SQLITE_OK {
|
||||
|
@ -1165,18 +1207,24 @@ func (c *conn) bindInt64(pstmt uintptr, idx1 int, value int64) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
|
||||
func (c *conn) bindParameterName(pstmt uintptr, i int) (string, error) {
|
||||
p := sqlite3.Xsqlite3_bind_parameter_name(c.tls, pstmt, int32(i))
|
||||
return libc.GoString(p), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_bind_parameter_count(sqlite3_stmt*);
|
||||
func (c *conn) bindParameterCount(pstmt uintptr) (_ int, err error) {
|
||||
r := sqlite3.Xsqlite3_bind_parameter_count(c.tls, pstmt)
|
||||
return int(r), nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_finalize(sqlite3_stmt *pStmt);
|
||||
func (c *conn) finalize(pstmt uintptr) error {
|
||||
if rc := sqlite3.Xsqlite3_finalize(c.tls, pstmt); rc != sqlite3.SQLITE_OK {
|
||||
|
@ -1186,6 +1234,8 @@ func (c *conn) finalize(pstmt uintptr) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_prepare_v2(
|
||||
// sqlite3 *db, /* Database handle */
|
||||
// const char *zSql, /* SQL statement, UTF-8 encoded */
|
||||
|
@ -1224,6 +1274,8 @@ func (c *conn) prepareV2(zSQL *uintptr) (pstmt uintptr, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// void sqlite3_interrupt(sqlite3*);
|
||||
func (c *conn) interrupt(pdb uintptr) (err error) {
|
||||
c.Lock() // Defend against race with .Close invoked by context handling.
|
||||
|
@ -1236,6 +1288,8 @@ func (c *conn) interrupt(pdb uintptr) (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_extended_result_codes(sqlite3*, int onoff);
|
||||
func (c *conn) extendedResultCodes(on bool) error {
|
||||
if rc := sqlite3.Xsqlite3_extended_result_codes(c.tls, c.db, libc.Bool32(on)); rc != sqlite3.SQLITE_OK {
|
||||
|
@ -1245,6 +1299,8 @@ func (c *conn) extendedResultCodes(on bool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_open_v2(
|
||||
// const char *filename, /* Database filename (UTF-8) */
|
||||
// sqlite3 **ppDb, /* OUT: SQLite db handle */
|
||||
|
@ -1302,6 +1358,8 @@ func (c *conn) free(p uintptr) {
|
|||
}
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// const char *sqlite3_errstr(int);
|
||||
func (c *conn) errstr(rc int32) error {
|
||||
p := sqlite3.Xsqlite3_errstr(c.tls, rc)
|
||||
|
@ -1366,6 +1424,8 @@ func (c *conn) Close() (err error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_close_v2(sqlite3*);
|
||||
func (c *conn) closeV2(db uintptr) error {
|
||||
if rc := sqlite3.Xsqlite3_close_v2(c.tls, db); rc != sqlite3.SQLITE_OK {
|
||||
|
@ -1559,6 +1619,146 @@ func (c *conn) query(ctx context.Context, query string, args []driver.NamedValue
|
|||
return s.(*stmt).query(ctx, args)
|
||||
}
|
||||
|
||||
// Serialize returns a serialization of the main database. For an ordinary on-disk
|
||||
// database file, the serialization is just a copy of the disk file. For an in-memory
|
||||
// database or a "TEMP" database, the serialization is the same sequence of bytes
|
||||
// which would be written to disk if that database where backed up to disk.
|
||||
func (c *conn) Serialize() (v []byte, err error) {
|
||||
pLen := c.tls.Alloc(8)
|
||||
defer c.tls.Free(8)
|
||||
|
||||
zSchema := sqlite3.Xsqlite3_db_name(c.tls, c.db, 0)
|
||||
if zSchema == 0 {
|
||||
return nil, fmt.Errorf("failed to get main db name")
|
||||
}
|
||||
|
||||
pBuf := sqlite3.Xsqlite3_serialize(c.tls, c.db, zSchema, pLen, 0)
|
||||
bufLen := *(*sqlite3.Sqlite3_int64)(unsafe.Pointer(pLen))
|
||||
if pBuf != 0 {
|
||||
defer sqlite3.Xsqlite3_free(c.tls, pBuf)
|
||||
}
|
||||
if bufLen <= 0 {
|
||||
return nil, fmt.Errorf("invalid length returned: %d", bufLen)
|
||||
} else if pBuf == 0 || bufLen == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
v = make([]byte, bufLen)
|
||||
copy(v, (*libc.RawMem)(unsafe.Pointer(pBuf))[:bufLen:bufLen])
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Deserialize restore a database from the content returned by Serialize.
|
||||
func (c *conn) Deserialize(buf []byte) (err error) {
|
||||
bufLen := len(buf)
|
||||
pBuf := c.tls.Alloc(bufLen) // free will be done if it fails or on close, must not be freed here
|
||||
|
||||
copy((*libc.RawMem)(unsafe.Pointer(pBuf))[:bufLen:bufLen], buf)
|
||||
|
||||
zSchema := sqlite3.Xsqlite3_db_name(c.tls, c.db, 0)
|
||||
if zSchema == 0 {
|
||||
return fmt.Errorf("failed to get main db name")
|
||||
}
|
||||
|
||||
rc := sqlite3.Xsqlite3_deserialize(c.tls, c.db, zSchema, pBuf, int64(bufLen), int64(bufLen), sqlite3.SQLITE_DESERIALIZE_RESIZEABLE|sqlite3.SQLITE_DESERIALIZE_FREEONCLOSE)
|
||||
if rc != sqlite3.SQLITE_OK {
|
||||
return c.errstr(rc)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Backup object is used to manage progress and cleanup an online backup. It
|
||||
// is returned by NewBackup or NewRestore.
|
||||
type Backup struct {
|
||||
srcConn *conn // source database connection
|
||||
dstConn *conn // destination database connection
|
||||
pBackup uintptr // sqlite3_backup object pointer
|
||||
}
|
||||
|
||||
// NewBackup returns a Backup object that will create an online backup of
|
||||
// current database to the databased pointed by the passed URI.
|
||||
func (c *conn) NewBackup(dstUri string) (*Backup, error) {
|
||||
dstConn, err := newConn(dstUri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
backup, err := c.backup(dstConn, false)
|
||||
if err != nil {
|
||||
dstConn.Close()
|
||||
}
|
||||
return backup, err
|
||||
}
|
||||
|
||||
// NewRestore returns a Backup object that will restore a backup to current
|
||||
// database from the databased pointed by the passed URI.
|
||||
func (c *conn) NewRestore(srcUri string) (*Backup, error) {
|
||||
srcConn, err := newConn(srcUri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
backup, err := c.backup(srcConn, true)
|
||||
if err != nil {
|
||||
srcConn.Close()
|
||||
}
|
||||
return backup, err
|
||||
}
|
||||
|
||||
func (c *conn) backup(remoteConn *conn, restore bool) (_ *Backup, finalErr error) {
|
||||
srcSchema := sqlite3.Xsqlite3_db_name(c.tls, c.db, 0)
|
||||
if srcSchema == 0 {
|
||||
return nil, fmt.Errorf("failed to get main source db name")
|
||||
}
|
||||
|
||||
dstSchema := sqlite3.Xsqlite3_db_name(remoteConn.tls, remoteConn.db, 0)
|
||||
if dstSchema == 0 {
|
||||
return nil, fmt.Errorf("failed to get main destination db name")
|
||||
}
|
||||
|
||||
var pBackup uintptr
|
||||
if restore {
|
||||
pBackup = sqlite3.Xsqlite3_backup_init(c.tls, c.db, srcSchema, remoteConn.db, dstSchema)
|
||||
} else {
|
||||
pBackup = sqlite3.Xsqlite3_backup_init(c.tls, remoteConn.db, dstSchema, c.db, srcSchema)
|
||||
}
|
||||
if pBackup <= 0 {
|
||||
rc := sqlite3.Xsqlite3_errcode(c.tls, remoteConn.db)
|
||||
return nil, c.errstr(rc)
|
||||
}
|
||||
|
||||
return &Backup{srcConn: c, dstConn: remoteConn, pBackup: pBackup}, nil
|
||||
}
|
||||
|
||||
// Step will copy up to n pages between the source and destination databases
|
||||
// specified by the backup object. If n is negative, all remaining source
|
||||
// pages are copied.
|
||||
// If it successfully copies n pages and there are still more pages to be
|
||||
// copied, then the function returns true with no error. If it successfully
|
||||
// finishes copying all pages from source to destination, then it returns
|
||||
// false with no error. If an error occurs while running, then an error is
|
||||
// returned.
|
||||
func (b *Backup) Step(n int32) (bool, error) {
|
||||
rc := sqlite3.Xsqlite3_backup_step(b.srcConn.tls, b.pBackup, n)
|
||||
if rc == sqlite3.SQLITE_OK {
|
||||
return true, nil
|
||||
} else if rc == sqlite3.SQLITE_DONE {
|
||||
return false, nil
|
||||
} else {
|
||||
return false, b.srcConn.errstr(rc)
|
||||
}
|
||||
}
|
||||
|
||||
// Finish releases all resources associated with the Backup object. The Backup
|
||||
// object is invalid and may not be used following a call to Finish.
|
||||
func (b *Backup) Finish() error {
|
||||
rc := sqlite3.Xsqlite3_backup_finish(b.srcConn.tls, b.pBackup)
|
||||
b.dstConn.Close()
|
||||
if rc == sqlite3.SQLITE_OK {
|
||||
return nil
|
||||
} else {
|
||||
return b.srcConn.errstr(rc)
|
||||
}
|
||||
}
|
||||
|
||||
// Driver implements database/sql/driver.Driver.
|
||||
type Driver struct {
|
||||
// user defined functions that are added to every new connection on Open
|
||||
|
@ -2067,6 +2267,8 @@ func finalTrampoline(tls *libc.TLS, ctx uintptr) {
|
|||
xAggregateContext.ids.reclaim(id)
|
||||
}
|
||||
|
||||
// C documentation
|
||||
//
|
||||
// int sqlite3_limit(sqlite3*, int id, int newVal);
|
||||
func (c *conn) limit(id int, newVal int) int {
|
||||
return int(sqlite3.Xsqlite3_limit(c.tls, c.db, int32(id), int32(newVal)))
|
||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -1097,7 +1097,7 @@ modernc.org/memory
|
|||
# modernc.org/opt v0.1.3
|
||||
## explicit; go 1.13
|
||||
modernc.org/opt
|
||||
# modernc.org/sqlite v1.23.1
|
||||
# modernc.org/sqlite v1.24.0
|
||||
## explicit; go 1.18
|
||||
modernc.org/sqlite
|
||||
modernc.org/sqlite/lib
|
||||
|
|
Loading…
Reference in a new issue