mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
WAL mode, extensions.
This commit is contained in:
@@ -46,8 +46,9 @@ and WAL databases are not supported.
|
||||
- [x] nested transactions
|
||||
- [ ] incremental BLOB I/O
|
||||
- [ ] online backup
|
||||
- [ ] session extension
|
||||
- [ ] snapshots
|
||||
- [ ] session extension
|
||||
- [ ] resumable bulk update
|
||||
- [ ] SQL functions
|
||||
- [ ] custom VFSes
|
||||
- [ ] read-only VFS, wrapping an [`io.ReaderAt`](https://pkg.go.dev/io#ReaderAt)
|
||||
|
||||
9
conn.go
9
conn.go
@@ -267,17 +267,18 @@ func (c *Conn) sendInterrupt() {
|
||||
// Pragma executes a PRAGMA statement and returns any result as a string.
|
||||
//
|
||||
// https://www.sqlite.org/pragma.html
|
||||
func (c *Conn) Pragma(str string) string {
|
||||
func (c *Conn) Pragma(str string) []string {
|
||||
stmt := c.MustPrepare(`PRAGMA ` + str)
|
||||
defer stmt.Close()
|
||||
|
||||
if stmt.Step() {
|
||||
return stmt.ColumnText(0)
|
||||
var pragmas []string
|
||||
for stmt.Step() {
|
||||
pragmas = append(pragmas, stmt.ColumnText(0))
|
||||
}
|
||||
if err := stmt.Err(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ""
|
||||
return pragmas
|
||||
}
|
||||
|
||||
func (c *Conn) error(rc uint64, sql ...string) error {
|
||||
|
||||
@@ -94,7 +94,7 @@ func (c conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, er
|
||||
if opts.ReadOnly {
|
||||
c.txCommit = `
|
||||
ROLLBACK;
|
||||
PRAGMA query_only=` + c.conn.Pragma("query_only")
|
||||
PRAGMA query_only=` + c.conn.Pragma("query_only")[0]
|
||||
txBegin = `
|
||||
BEGIN deferred;
|
||||
PRAGMA query_only=on`
|
||||
|
||||
Binary file not shown.
14
sqlite3/qsort.c
Normal file
14
sqlite3/qsort.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stddef.h>
|
||||
|
||||
void qsort_r(void *, size_t, size_t,
|
||||
int (*)(const void *, const void *, void *), void *);
|
||||
|
||||
typedef int (*cmpfun)(const void *, const void *);
|
||||
|
||||
static int wrapper_cmp(const void *v1, const void *v2, void *cmp) {
|
||||
return ((cmpfun)cmp)(v1, v2);
|
||||
}
|
||||
|
||||
void qsort(void *base, size_t nel, size_t width, cmpfun cmp) {
|
||||
qsort_r(base, nel, width, wrapper_cmp, cmp);
|
||||
}
|
||||
@@ -28,18 +28,33 @@
|
||||
#define SQLITE_OMIT_AUTOINIT
|
||||
#define SQLITE_USE_ALLOCA
|
||||
|
||||
// Because WASM does not support shared memory,
|
||||
// SQLite disables it for WASM builds.
|
||||
// We set the default locking mode to EXCLUSIVE instead.
|
||||
// https://www.sqlite.org/wal.html#noshm
|
||||
#undef SQLITE_OMIT_WAL
|
||||
#define SQLITE_DEFAULT_LOCKING_MODE 1
|
||||
|
||||
// Recommended Extensions
|
||||
|
||||
// #define SQLITE_ENABLE_MATH_FUNCTIONS 1
|
||||
// #define SQLITE_ENABLE_FTS3 1
|
||||
// #define SQLITE_ENABLE_FTS3_PARENTHESIS 1
|
||||
// #define SQLITE_ENABLE_FTS4 1
|
||||
// #define SQLITE_ENABLE_FTS5 1
|
||||
// #define SQLITE_ENABLE_RTREE 1
|
||||
// #define SQLITE_ENABLE_GEOPOLY 1
|
||||
#define SQLITE_ENABLE_MATH_FUNCTIONS 1
|
||||
#define SQLITE_ENABLE_JSON1 1
|
||||
#define SQLITE_ENABLE_FTS3 1
|
||||
#define SQLITE_ENABLE_FTS3_PARENTHESIS 1
|
||||
#define SQLITE_ENABLE_FTS4 1
|
||||
#define SQLITE_ENABLE_FTS5 1
|
||||
#define SQLITE_ENABLE_RTREE 1
|
||||
#define SQLITE_ENABLE_GEOPOLY 1
|
||||
|
||||
// Need this to access WAL databases without the use of shared memory.
|
||||
#define SQLITE_DEFAULT_LOCKING_MODE 1
|
||||
// Snapshot
|
||||
// #define SQLITE_ENABLE_SNAPSHOT 1
|
||||
|
||||
// Session Extension
|
||||
// #define SQLITE_ENABLE_SESSION 1
|
||||
// #define SQLITE_ENABLE_PREUPDATE_HOOK 1
|
||||
|
||||
// Resumable Bulk Update Extension
|
||||
// #define SQLITE_ENABLE_RBU 1
|
||||
|
||||
// Implemented in Go.
|
||||
int localtime_s(struct tm *const pTm, time_t const *const pTime);
|
||||
Reference in New Issue
Block a user