Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e671c4fbc0 | |||
| 8d71d50391 | |||
| 4edd69b97b | |||
| 4e6047a5ee | |||
| 0979ae5180 | |||
| 3722998e13 | |||
| 7f990bd3f8 | |||
| 32ccccf7ab | |||
| fd74c4b2d9 | |||
| d5a1e1967f | |||
| 2d4139dda5 | |||
| fe5751815b | |||
| a0e71193e5 | |||
| 9f773bfde6 | |||
| 11e8ff65b5 | |||
| 1a7d1ab06e | |||
| 73dd2b94e1 | |||
| 88894f2b5f | |||
| cd0b19a37f | |||
| 10e44bf373 | |||
| b08004d947 | |||
| 322b844815 | |||
| da1b094d95 | |||
| cc4f0f678d | |||
| 86ac593b84 | |||
| fe8d2d2497 | |||
| ec1533e366 | |||
| 9ebf799d5b | |||
| 5a7afccd51 | |||
| 74273c4369 | |||
| 7a83522677 | |||
| 843c71d748 | |||
| cbfa2269c4 | |||
| 0a64b581dd | |||
| 72e2aa5096 |
+13
-61
@@ -599,38 +599,20 @@ SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
FUZZERSHELL_OPT =
|
||||
FUZZERSHELL_OPT =
|
||||
FUZZCHECK_OPT += -I$(TOP)/test
|
||||
FUZZCHECK_OPT += -I$(TOP)/ext/recover
|
||||
FUZZCHECK_OPT += \
|
||||
-DSQLITE_OSS_FUZZ \
|
||||
-DSQLITE_ENABLE_BYTECODE_VTAB \
|
||||
-DSQLITE_ENABLE_DBPAGE_VTAB \
|
||||
-DSQLITE_ENABLE_DBSTAT_VTAB \
|
||||
-DSQLITE_ENABLE_BYTECODE_VTAB \
|
||||
-DSQLITE_ENABLE_DESERIALIZE \
|
||||
-DSQLITE_ENABLE_EXPLAIN_COMMENTS \
|
||||
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
|
||||
-DSQLITE_ENABLE_FTS4 \
|
||||
-DSQLITE_ENABLE_FTS5 \
|
||||
-DSQLITE_ENABLE_GEOPOLY \
|
||||
-DSQLITE_ENABLE_MATH_FUNCTIONS \
|
||||
-DSQLITE_ENABLE_MEMSYS5 \
|
||||
-DSQLITE_ENABLE_NORMALIZE \
|
||||
-DSQLITE_ENABLE_OFFSET_SQL_FUNC \
|
||||
-DSQLITE_ENABLE_PREUPDATE_HOOK \
|
||||
-DSQLITE_ENABLE_RTREE \
|
||||
-DSQLITE_ENABLE_SESSION \
|
||||
-DSQLITE_ENABLE_STMTVTAB \
|
||||
-DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION \
|
||||
-DSQLITE_ENABLE_STAT4 \
|
||||
-DSQLITE_ENABLE_STMT_SCANSTATUS \
|
||||
-DSQLITE_MAX_MEMORY=50000000 \
|
||||
-DSQLITE_MAX_MMAP_SIZE=0 \
|
||||
-DSQLITE_OMIT_LOAD_EXTENSION \
|
||||
-DSQLITE_PRINTF_PRECISION_LIMIT=1000 \
|
||||
-DSQLITE_PRIVATE=""
|
||||
|
||||
FUZZCHECK_OPT += -DSQLITE_OMIT_LOAD_EXTENSION
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
|
||||
FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
FUZZCHECK_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
FUZZCHECK_SRC += $(TOP)/test/fuzzcheck.c
|
||||
FUZZCHECK_SRC += $(TOP)/test/ossfuzz.c
|
||||
FUZZCHECK_SRC += $(TOP)/test/fuzzinvariants.c
|
||||
@@ -690,12 +672,6 @@ srcck1$(BEXE): $(TOP)/tool/srcck1.c
|
||||
sourcetest: srcck1$(BEXE) sqlite3.c
|
||||
./srcck1 sqlite3.c
|
||||
|
||||
src-verify: $(TOP)/tool/src-verify.c
|
||||
$(BCC) -o src-verify$(BEXE) $(TOP)/tool/src-verify.c
|
||||
|
||||
verify-source: ./src-verify
|
||||
./src-verify $(TOP)
|
||||
|
||||
fuzzershell$(TEXE): $(TOP)/tool/fuzzershell.c sqlite3.c sqlite3.h
|
||||
$(LTLINK) -o $@ $(FUZZERSHELL_OPT) \
|
||||
$(TOP)/tool/fuzzershell.c sqlite3.c $(TLIBS)
|
||||
@@ -703,9 +679,6 @@ fuzzershell$(TEXE): $(TOP)/tool/fuzzershell.c sqlite3.c sqlite3.h
|
||||
fuzzcheck$(TEXE): $(FUZZCHECK_SRC) sqlite3.c sqlite3.h $(FUZZCHECK_DEP)
|
||||
$(LTLINK) -o $@ $(FUZZCHECK_OPT) $(FUZZCHECK_SRC) sqlite3.c $(TLIBS)
|
||||
|
||||
fuzzcheck-asan$(TEXE): $(FUZZCHECK_SRC) sqlite3.c sqlite3.h $(FUZZCHECK_DEP)
|
||||
$(LTLINK) -o $@ -fsanitize=address $(FUZZCHECK_OPT) $(FUZZCHECK_SRC) sqlite3.c $(TLIBS)
|
||||
|
||||
ossshell$(TEXE): $(TOP)/test/ossfuzz.c $(TOP)/test/ossshell.c sqlite3.c sqlite3.h
|
||||
$(LTLINK) -o $@ $(FUZZCHECK_OPT) $(TOP)/test/ossshell.c \
|
||||
$(TOP)/test/ossfuzz.c sqlite3.c $(TLIBS)
|
||||
@@ -781,7 +754,7 @@ mptest: mptester$(TEXE)
|
||||
cp fts5.c fts5.h tsrc
|
||||
touch .target_source
|
||||
|
||||
sqlite3.c: .target_source $(TOP)/tool/mksqlite3c.tcl src-verify
|
||||
sqlite3.c: .target_source $(TOP)/tool/mksqlite3c.tcl
|
||||
$(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl $(AMALGAMATION_LINE_MACROS)
|
||||
cp tsrc/sqlite3ext.h .
|
||||
cp $(TOP)/ext/session/sqlite3session.h .
|
||||
@@ -1139,7 +1112,6 @@ SHELL_SRC = \
|
||||
$(TOP)/ext/expert/sqlite3expert.h \
|
||||
$(TOP)/ext/misc/zipfile.c \
|
||||
$(TOP)/ext/misc/memtrace.c \
|
||||
$(TOP)/ext/misc/pcachetrace.c \
|
||||
$(TOP)/ext/recover/dbdata.c \
|
||||
$(TOP)/ext/recover/sqlite3recover.c \
|
||||
$(TOP)/ext/recover/sqlite3recover.h \
|
||||
@@ -1528,8 +1500,6 @@ clean:
|
||||
rm -f dbhash dbhash.exe
|
||||
rm -f fts5.* fts5parse.*
|
||||
rm -f threadtest5
|
||||
rm -f src-verify
|
||||
rm -f custom.rws
|
||||
|
||||
distclean: clean
|
||||
rm -f sqlite_cfg.h config.log config.status libtool Makefile sqlite3.pc \
|
||||
@@ -1558,21 +1528,3 @@ sqlite3.dll: $(REAL_LIBOBJ) sqlite3.def
|
||||
#
|
||||
fiddle: sqlite3.c shell.c
|
||||
make -C ext/wasm fiddle emcc_opt=-Os
|
||||
|
||||
#
|
||||
# Spell-checking for source comments
|
||||
# The sources checked are either C sources or C source templates.
|
||||
# Their comments are extracted and processed through aspell using
|
||||
# a custom dictionary that contains scads of odd identifiers that
|
||||
# find their way into the comments.
|
||||
#
|
||||
# Currently, this target is setup to be "made" in-tree only.
|
||||
# The output is ephemeral. Redirect it to guide spelling fixups,
|
||||
# either to correct spelling or add words to tool/custom.txt.
|
||||
#
|
||||
./custom.rws: ./tool/custom.txt
|
||||
@echo 'Updating custom dictionary from tool/custom.txt'
|
||||
aspell --lang=en create master ./custom.rws < $<
|
||||
|
||||
misspell: ./custom.rws
|
||||
$(TCLSH_CMD) ./tool/spellsift.tcl ./src/*.c ./src/*.h ./src/*.in
|
||||
|
||||
@@ -22,6 +22,12 @@ TOP = ../sqlite
|
||||
BCC = gcc -g -O0
|
||||
#BCC = /opt/ancic/bin/c89 -0
|
||||
|
||||
#### If the target operating system supports the "usleep()" system
|
||||
# call, then define the HAVE_USLEEP macro for all C modules.
|
||||
#
|
||||
#USLEEP =
|
||||
USLEEP = -DHAVE_USLEEP=1
|
||||
|
||||
#### If you want the SQLite library to be safe for use within a
|
||||
# multi-threaded program, then define the following macro
|
||||
# appropriately:
|
||||
|
||||
+16
-54
@@ -1526,7 +1526,7 @@ TESTSRC = \
|
||||
$(TOP)\ext\fts3\fts3_term.c \
|
||||
$(TOP)\ext\fts3\fts3_test.c \
|
||||
$(TOP)\ext\rbu\test_rbu.c \
|
||||
$(TOP)\ext\session\test_session.c
|
||||
$(TOP)\ext\session\test_session.c
|
||||
|
||||
# Statically linked extensions.
|
||||
#
|
||||
@@ -1671,33 +1671,6 @@ FUZZERSHELL_COMPILE_OPTS =
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -I$(TOP)\test -I$(TOP)\ext\recover
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_OSS_FUZZ
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DESERIALIZE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS3_PARENTHESIS
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS4
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS5
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_GEOPOLY
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MATH_FUNCTIONS
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_MEMSYS5
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_NORMALIZE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_PREUPDATE_HOOK
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_SESSION
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_STMTVTAB
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_STAT4
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_STMT_SCANSTATUS
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_MAX_MMAP_SIZE=0
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_PRIVATE=""
|
||||
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_MAX_MEMORY=50000000
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_PRINTF_PRECISION_LIMIT=1000
|
||||
FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_OMIT_LOAD_EXTENSION
|
||||
@@ -1807,12 +1780,6 @@ srcck1.exe: $(TOP)\tool\srcck1.c
|
||||
sourcetest: srcck1.exe $(SQLITE3C)
|
||||
srcck1.exe $(SQLITE3C)
|
||||
|
||||
src-verify.exe: $(TOP)\tool\src-verify.c
|
||||
$(LTLINK) $(NO_WARN) $(TOP)\tool\src-verify.c
|
||||
|
||||
verify-source: src-verify.exe
|
||||
src-verify.exe $(TOP)
|
||||
|
||||
fuzzershell.exe: $(TOP)\tool\fuzzershell.c $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) $(FUZZERSHELL_COMPILE_OPTS) $(TOP)\tool\fuzzershell.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
@@ -1820,10 +1787,7 @@ dbfuzz.exe: $(TOP)\test\dbfuzz.c $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) $(DBFUZZ_COMPILE_OPTS) $(TOP)\test\dbfuzz.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
fuzzcheck.exe: $(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) /F 8388608 $(NO_WARN) $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
fuzzcheck-asan.exe: $(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) /fsanitize=address $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
|
||||
ossshell.exe: $(OSSSHELL_SRC) $(SQLITE3C) $(SQLITE3H)
|
||||
$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
|
||||
@@ -1876,7 +1840,7 @@ mptest: mptester.exe
|
||||
move vdbe.new tsrc\vdbe.c
|
||||
echo > .target_source
|
||||
|
||||
sqlite3.c: .target_source sqlite3ext.h sqlite3session.h $(MKSQLITE3C_TOOL) src-verify.exe
|
||||
sqlite3.c: .target_source sqlite3ext.h sqlite3session.h $(MKSQLITE3C_TOOL)
|
||||
$(TCLSH_CMD) $(MKSQLITE3C_TOOL) $(MKSQLITE3C_ARGS)
|
||||
|
||||
sqlite3-all.c: sqlite3.c $(TOP)\tool\split-sqlite3c.tcl
|
||||
@@ -2232,8 +2196,8 @@ SHELL_SRC = \
|
||||
$(TOP)\src\shell.c.in \
|
||||
$(TOP)\ext\misc\appendvfs.c \
|
||||
$(TOP)\ext\misc\completion.c \
|
||||
$(TOP)\ext\misc\base64.c \
|
||||
$(TOP)\ext\misc\base85.c \
|
||||
$(TOP)\ext\misc\base64.c \
|
||||
$(TOP)\ext\misc\base85.c \
|
||||
$(TOP)\ext\misc\decimal.c \
|
||||
$(TOP)\ext\misc\fileio.c \
|
||||
$(TOP)\ext\misc\ieee754.c \
|
||||
@@ -2244,10 +2208,9 @@ SHELL_SRC = \
|
||||
$(TOP)\ext\expert\sqlite3expert.c \
|
||||
$(TOP)\ext\expert\sqlite3expert.h \
|
||||
$(TOP)\ext\misc\memtrace.c \
|
||||
$(TOP)\ext\misc\pcachetrace.c \
|
||||
$(TOP)\ext\recover\dbdata.c \
|
||||
$(TOP)\ext\recover\sqlite3recover.c \
|
||||
$(TOP)\ext\recover\sqlite3recover.h \
|
||||
$(TOP)/ext/recover/dbdata.c \
|
||||
$(TOP)/ext/recover/sqlite3recover.c \
|
||||
$(TOP)/ext/recover/sqlite3recover.h \
|
||||
$(TOP)\src\test_windirent.c
|
||||
|
||||
# If use of zlib is enabled, add the "zipfile.c" source file.
|
||||
@@ -2494,7 +2457,7 @@ devtest: testfixture.exe fuzztest testrunner
|
||||
# Testing for a release
|
||||
#
|
||||
releasetest: testfixture.exe fuzztest
|
||||
testfixture.exe $(TOP)\test\testrunner.tcl release
|
||||
testfixture.exe $(TOP)/test/testrunner.tcl release
|
||||
|
||||
|
||||
smoketest: $(TESTPROGS)
|
||||
@@ -2522,14 +2485,14 @@ sqlite3_expert.exe: $(SQLITE3C) $(TOP)\ext\expert\sqlite3expert.h $(TOP)\ext\exp
|
||||
$(LTLINK) $(NO_WARN) $(TOP)\ext\expert\sqlite3expert.c $(TOP)\ext\expert\expert.c $(SQLITE3C) $(TLIBS)
|
||||
|
||||
CHECKER_DEPS =\
|
||||
$(TOP)\tool\mkccode.tcl \
|
||||
$(TOP)/tool/mkccode.tcl \
|
||||
sqlite3.c \
|
||||
$(TOP)\src\tclsqlite.c \
|
||||
$(TOP)\ext\repair\sqlite3_checker.tcl \
|
||||
$(TOP)\ext\repair\checkindex.c \
|
||||
$(TOP)\ext\repair\checkfreelist.c \
|
||||
$(TOP)\ext\misc\btreeinfo.c \
|
||||
$(TOP)\ext\repair\sqlite3_checker.c.in
|
||||
$(TOP)/src/tclsqlite.c \
|
||||
$(TOP)/ext/repair/sqlite3_checker.tcl \
|
||||
$(TOP)/ext/repair/checkindex.c \
|
||||
$(TOP)/ext/repair/checkfreelist.c \
|
||||
$(TOP)/ext/misc/btreeinfo.c \
|
||||
$(TOP)/ext/repair/sqlite3_checker.c.in
|
||||
|
||||
sqlite3_checker.c: $(CHECKER_DEPS)
|
||||
$(TCLSH_CMD) $(TOP)\tool\mkccode.tcl $(TOP)\ext\repair\sqlite3_checker.c.in > $@
|
||||
@@ -2668,5 +2631,4 @@ clean:
|
||||
del /Q showshm.exe sqlite3_checker.* sqlite3_expert.exe 2>NUL
|
||||
del /Q fts5.* fts5parse.* 2>NUL
|
||||
del /Q lsm.h lsm1.c 2>NUL
|
||||
del /q src-verify.exe 2>NUL
|
||||
# <</mark>>
|
||||
|
||||
@@ -7,7 +7,7 @@ and most of the documentation are managed separately.
|
||||
|
||||
## Version Control
|
||||
|
||||
SQLite sources are managed using
|
||||
SQLite sources are managed using the
|
||||
[Fossil](https://www.fossil-scm.org/), a distributed version control system
|
||||
that was specifically designed and written to support SQLite development.
|
||||
The [Fossil repository](https://sqlite.org/src/timeline) contains the urtext.
|
||||
@@ -25,29 +25,7 @@ If you pulled your SQLite source code from a secondary source and want to
|
||||
verify its integrity, there are hints on how to do that in the
|
||||
[Verifying Code Authenticity](#vauth) section below.
|
||||
|
||||
## Contacting The SQLite Developers
|
||||
|
||||
The preferred way to ask questions or make comments about SQLite or to
|
||||
report bugs against SQLite is to visit the
|
||||
[SQLite Forum](https://sqlite.org/forum) at <https://sqlite.org/forum/>.
|
||||
Anonymous postings are permitted.
|
||||
|
||||
If you think you have found a bug that has security implications and
|
||||
you do not want to report it on the public forum, you can send a private
|
||||
email to drh at sqlite dot org.
|
||||
|
||||
## Public Domain
|
||||
|
||||
The SQLite source code is in the public domain. See
|
||||
<https://sqlite.org/copyright.html> for details.
|
||||
|
||||
Because SQLite is in the public domain,
|
||||
we cannot accept pull requests, because
|
||||
if we did accept a pull request, the changes in that pull request would
|
||||
carry a copyright and the SQLite source code would no longer be fully in
|
||||
the public domain.
|
||||
|
||||
## Obtaining The SQLite Source Code
|
||||
## Obtaining The Code
|
||||
|
||||
If you do not want to use Fossil, you can download tarballs or ZIP
|
||||
archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
|
||||
@@ -312,13 +290,16 @@ Key files:
|
||||
is not part of the core SQLite library. But as most of the tests in this
|
||||
repository are written in Tcl, the Tcl language bindings are important.
|
||||
|
||||
* **test\*.c** - Files in the src/ folder that begin with "test" go into
|
||||
* **test*.c** - Files in the src/ folder that begin with "test" go into
|
||||
building the "testfixture.exe" program. The testfixture.exe program is
|
||||
an enhanced Tcl shell. The testfixture.exe program runs scripts in the
|
||||
test/ folder to validate the core SQLite code. The testfixture program
|
||||
(and some other test programs too) is built and run when you type
|
||||
"make test".
|
||||
|
||||
* **ext/misc/json1.c** - This file implements the various JSON functions
|
||||
that are built into SQLite.
|
||||
|
||||
There are many other source files. Each has a succinct header comment that
|
||||
describes its purpose and role within the larger system.
|
||||
|
||||
@@ -326,8 +307,8 @@ describes its purpose and role within the larger system.
|
||||
## Verifying Code Authenticity
|
||||
|
||||
The `manifest` file at the root directory of the source tree
|
||||
contains either a SHA3-256 hash or a SHA1 hash
|
||||
for every source file in the repository.
|
||||
contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for
|
||||
older files) for every source file in the repository.
|
||||
The name of the version of the entire source tree is just the
|
||||
SHA3-256 hash of the `manifest` file itself, possibly with the
|
||||
last line of that file omitted if the last line begins with
|
||||
@@ -335,25 +316,14 @@ last line of that file omitted if the last line begins with
|
||||
The `manifest.uuid` file should contain the SHA3-256 hash of the
|
||||
`manifest` file. If all of the above hash comparisons are correct, then
|
||||
you can be confident that your source tree is authentic and unadulterated.
|
||||
Details on the format for the `manifest` files are available
|
||||
[on the Fossil website](https://fossil-scm.org/fossil/doc/trunk/www/fileformat.wiki#manifest).
|
||||
|
||||
The process of checking source code authenticity is automated by the
|
||||
makefile:
|
||||
|
||||
> make verify-source
|
||||
|
||||
Or on windows:
|
||||
|
||||
> nmake /f Makefile.msc verify-source
|
||||
|
||||
Using the makefile to verify source integrity is good for detecting
|
||||
accidental changes to the source tree, but malicious changes could be
|
||||
hidden by also modifying the makefiles.
|
||||
The format of the `manifest` file should be mostly self-explanatory, but
|
||||
if you want details, they are available
|
||||
[here](https://fossil-scm.org/fossil/doc/trunk/www/fileformat.wiki#manifest).
|
||||
|
||||
## Contacts
|
||||
|
||||
The main SQLite website is [http:/sqlite.org/](http://sqlite.org/)
|
||||
The main SQLite website is [http://www.sqlite.org/](http://www.sqlite.org/)
|
||||
with geographically distributed backups at
|
||||
[http://www2.sqlite.org/](http://www2.sqlite.org) and
|
||||
[http://www3.sqlite.org/](http://www3.sqlite.org).
|
||||
|
||||
@@ -19,7 +19,7 @@ dnl to configure the system for the local environment.
|
||||
# so that we create the export library with the dll.
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
AC_INIT([sqlite],[3.42.0])
|
||||
AC_INIT([sqlite],[3.41.2])
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Call TEA_INIT as the first TEA_ macro to set up initial vars.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.43.0.
|
||||
# Generated by GNU Autoconf 2.69 for sqlite 3.41.2.
|
||||
#
|
||||
#
|
||||
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
|
||||
@@ -726,8 +726,8 @@ MAKEFLAGS=
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='sqlite'
|
||||
PACKAGE_TARNAME='sqlite'
|
||||
PACKAGE_VERSION='3.43.0'
|
||||
PACKAGE_STRING='sqlite 3.43.0'
|
||||
PACKAGE_VERSION='3.41.2'
|
||||
PACKAGE_STRING='sqlite 3.41.2'
|
||||
PACKAGE_BUGREPORT=''
|
||||
PACKAGE_URL=''
|
||||
|
||||
@@ -1470,7 +1470,7 @@ if test "$ac_init_help" = "long"; then
|
||||
# Omit some internal or obsolete options to make the list less imposing.
|
||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||
cat <<_ACEOF
|
||||
\`configure' configures sqlite 3.43.0 to adapt to many kinds of systems.
|
||||
\`configure' configures sqlite 3.41.2 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1535,7 +1535,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of sqlite 3.43.0:";;
|
||||
short | recursive ) echo "Configuration of sqlite 3.41.2:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1665,7 +1665,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
sqlite configure 3.43.0
|
||||
sqlite configure 3.41.2
|
||||
generated by GNU Autoconf 2.69
|
||||
|
||||
Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@@ -2084,7 +2084,7 @@ cat >config.log <<_ACEOF
|
||||
This file contains any messages produced by compilers while
|
||||
running configure, to aid debugging if configure makes a mistake.
|
||||
|
||||
It was created by sqlite $as_me 3.43.0, which was
|
||||
It was created by sqlite $as_me 3.41.2, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@@ -12457,7 +12457,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
||||
# report actual input values of CONFIG_FILES etc. instead of their
|
||||
# values after options handling.
|
||||
ac_log="
|
||||
This file was extended by sqlite $as_me 3.43.0, which was
|
||||
This file was extended by sqlite $as_me 3.41.2, which was
|
||||
generated by GNU Autoconf 2.69. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -12523,7 +12523,7 @@ _ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
|
||||
ac_cs_version="\\
|
||||
sqlite config.status 3.43.0
|
||||
sqlite config.status 3.41.2
|
||||
configured by $0, generated by GNU Autoconf 2.69,
|
||||
with options \\"\$ac_cs_config\\"
|
||||
|
||||
|
||||
+1
-1
@@ -322,7 +322,7 @@ These are the steps:
|
||||
<ul>
|
||||
<li> Declare a local variable of type "yyParser"
|
||||
<li> Initialize the variable using ParseInit()
|
||||
<li> Pass a pointer to the variable in calls to Parse()
|
||||
<li> Pass a pointer to the variable in calls ot Parse()
|
||||
<li> Deallocate substructure in the parse variable using ParseFinalize().
|
||||
</ul>
|
||||
|
||||
|
||||
@@ -4347,7 +4347,6 @@ static int fts3IncrmergeLoad(
|
||||
|
||||
for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){
|
||||
NodeReader reader;
|
||||
memset(&reader, 0, sizeof(reader));
|
||||
pNode = &pWriter->aNodeWriter[i];
|
||||
|
||||
if( pNode->block.a){
|
||||
|
||||
+4
-4
@@ -263,7 +263,7 @@ struct Fts5PhraseIter {
|
||||
** See xPhraseFirstColumn above.
|
||||
*/
|
||||
struct Fts5ExtensionApi {
|
||||
int iVersion; /* Currently always set to 2 */
|
||||
int iVersion; /* Currently always set to 3 */
|
||||
|
||||
void *(*xUserData)(Fts5Context*);
|
||||
|
||||
@@ -541,7 +541,7 @@ struct fts5_api {
|
||||
int (*xCreateTokenizer)(
|
||||
fts5_api *pApi,
|
||||
const char *zName,
|
||||
void *pUserData,
|
||||
void *pContext,
|
||||
fts5_tokenizer *pTokenizer,
|
||||
void (*xDestroy)(void*)
|
||||
);
|
||||
@@ -550,7 +550,7 @@ struct fts5_api {
|
||||
int (*xFindTokenizer)(
|
||||
fts5_api *pApi,
|
||||
const char *zName,
|
||||
void **ppUserData,
|
||||
void **ppContext,
|
||||
fts5_tokenizer *pTokenizer
|
||||
);
|
||||
|
||||
@@ -558,7 +558,7 @@ struct fts5_api {
|
||||
int (*xCreateFunction)(
|
||||
fts5_api *pApi,
|
||||
const char *zName,
|
||||
void *pUserData,
|
||||
void *pContext,
|
||||
fts5_extension_function xFunction,
|
||||
void (*xDestroy)(void*)
|
||||
);
|
||||
|
||||
+3
-24
@@ -154,10 +154,6 @@ typedef struct Fts5Config Fts5Config;
|
||||
** attempt to merge together. A value of 1 sets the object to use the
|
||||
** compile time default. Zero disables auto-merge altogether.
|
||||
**
|
||||
** bContentlessDelete:
|
||||
** True if the contentless_delete option was present in the CREATE
|
||||
** VIRTUAL TABLE statement.
|
||||
**
|
||||
** zContent:
|
||||
**
|
||||
** zContentRowid:
|
||||
@@ -192,7 +188,6 @@ struct Fts5Config {
|
||||
int nPrefix; /* Number of prefix indexes */
|
||||
int *aPrefix; /* Sizes in bytes of nPrefix prefix indexes */
|
||||
int eContent; /* An FTS5_CONTENT value */
|
||||
int bContentlessDelete; /* "contentless_delete=" option (dflt==0) */
|
||||
char *zContent; /* content table */
|
||||
char *zContentRowid; /* "content_rowid=" option value */
|
||||
int bColumnsize; /* "columnsize=" option value (dflt==1) */
|
||||
@@ -204,7 +199,6 @@ struct Fts5Config {
|
||||
int ePattern; /* FTS_PATTERN_XXX constant */
|
||||
|
||||
/* Values loaded from the %_config table */
|
||||
int iVersion; /* fts5 file format 'version' */
|
||||
int iCookie; /* Incremented when %_config is modified */
|
||||
int pgsz; /* Approximate page size used in %_data */
|
||||
int nAutomerge; /* 'automerge' setting */
|
||||
@@ -213,8 +207,6 @@ struct Fts5Config {
|
||||
int nHashSize; /* Bytes of memory for in-memory hash */
|
||||
char *zRank; /* Name of rank function */
|
||||
char *zRankArgs; /* Arguments to rank function */
|
||||
int bSecureDelete; /* 'secure-delete' */
|
||||
int nDeleteMerge; /* 'deletemerge' */
|
||||
|
||||
/* If non-NULL, points to sqlite3_vtab.base.zErrmsg. Often NULL. */
|
||||
char **pzErrmsg;
|
||||
@@ -224,11 +216,8 @@ struct Fts5Config {
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Current expected value of %_config table 'version' field. And
|
||||
** the expected version if the 'secure-delete' option has ever been
|
||||
** set on the table. */
|
||||
#define FTS5_CURRENT_VERSION 4
|
||||
#define FTS5_CURRENT_VERSION_SECUREDELETE 5
|
||||
/* Current expected value of %_config table 'version' field */
|
||||
#define FTS5_CURRENT_VERSION 4
|
||||
|
||||
#define FTS5_CONTENT_NORMAL 0
|
||||
#define FTS5_CONTENT_NONE 1
|
||||
@@ -394,7 +383,6 @@ struct Fts5IndexIter {
|
||||
** above. */
|
||||
#define FTS5INDEX_QUERY_SKIPEMPTY 0x0010
|
||||
#define FTS5INDEX_QUERY_NOOUTPUT 0x0020
|
||||
#define FTS5INDEX_QUERY_SKIPHASH 0x0040
|
||||
|
||||
/*
|
||||
** Create/destroy an Fts5Index object.
|
||||
@@ -537,9 +525,6 @@ int sqlite3Fts5IndexReset(Fts5Index *p);
|
||||
|
||||
int sqlite3Fts5IndexLoadConfig(Fts5Index *p);
|
||||
|
||||
int sqlite3Fts5IndexGetOrigin(Fts5Index *p, i64 *piOrigin);
|
||||
int sqlite3Fts5IndexContentlessDelete(Fts5Index *p, i64 iOrigin, i64 iRowid);
|
||||
|
||||
/*
|
||||
** End of interface to code in fts5_index.c.
|
||||
**************************************************************************/
|
||||
@@ -552,7 +537,7 @@ int sqlite3Fts5GetVarintLen(u32 iVal);
|
||||
u8 sqlite3Fts5GetVarint(const unsigned char*, u64*);
|
||||
int sqlite3Fts5PutVarint(unsigned char *p, u64 v);
|
||||
|
||||
#define fts5GetVarint32(a,b) sqlite3Fts5GetVarint32(a,(u32*)&(b))
|
||||
#define fts5GetVarint32(a,b) sqlite3Fts5GetVarint32(a,(u32*)&b)
|
||||
#define fts5GetVarint sqlite3Fts5GetVarint
|
||||
|
||||
#define fts5FastGetVarint32(a, iOff, nVal) { \
|
||||
@@ -624,11 +609,6 @@ int sqlite3Fts5HashWrite(
|
||||
*/
|
||||
void sqlite3Fts5HashClear(Fts5Hash*);
|
||||
|
||||
/*
|
||||
** Return true if the hash is empty, false otherwise.
|
||||
*/
|
||||
int sqlite3Fts5HashIsEmpty(Fts5Hash*);
|
||||
|
||||
int sqlite3Fts5HashQuery(
|
||||
Fts5Hash*, /* Hash table to query */
|
||||
int nPre,
|
||||
@@ -650,7 +630,6 @@ void sqlite3Fts5HashScanEntry(Fts5Hash *,
|
||||
);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** End of interface to code in fts5_hash.c.
|
||||
**************************************************************************/
|
||||
|
||||
+3
-5
@@ -163,7 +163,7 @@ static int fts5HighlightCb(
|
||||
if( tflags & FTS5_TOKEN_COLOCATED ) return SQLITE_OK;
|
||||
iPos = p->iPos++;
|
||||
|
||||
if( p->iRangeEnd>=0 ){
|
||||
if( p->iRangeEnd>0 ){
|
||||
if( iPos<p->iRangeStart || iPos>p->iRangeEnd ) return SQLITE_OK;
|
||||
if( p->iRangeStart && iPos==p->iRangeStart ) p->iOff = iStartOff;
|
||||
}
|
||||
@@ -175,7 +175,7 @@ static int fts5HighlightCb(
|
||||
}
|
||||
|
||||
if( iPos==p->iter.iEnd ){
|
||||
if( p->iRangeEnd>=0 && p->iter.iStart<p->iRangeStart ){
|
||||
if( p->iRangeEnd && p->iter.iStart<p->iRangeStart ){
|
||||
fts5HighlightAppend(&rc, p, p->zOpen, -1);
|
||||
}
|
||||
fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
|
||||
@@ -186,7 +186,7 @@ static int fts5HighlightCb(
|
||||
}
|
||||
}
|
||||
|
||||
if( p->iRangeEnd>=0 && iPos==p->iRangeEnd ){
|
||||
if( p->iRangeEnd>0 && iPos==p->iRangeEnd ){
|
||||
fts5HighlightAppend(&rc, p, &p->zIn[p->iOff], iEndOff - p->iOff);
|
||||
p->iOff = iEndOff;
|
||||
if( iPos>=p->iter.iStart && iPos<p->iter.iEnd ){
|
||||
@@ -221,7 +221,6 @@ static void fts5HighlightFunction(
|
||||
memset(&ctx, 0, sizeof(HighlightContext));
|
||||
ctx.zOpen = (const char*)sqlite3_value_text(apVal[1]);
|
||||
ctx.zClose = (const char*)sqlite3_value_text(apVal[2]);
|
||||
ctx.iRangeEnd = -1;
|
||||
rc = pApi->xColumnText(pFts, iCol, &ctx.zIn, &ctx.nIn);
|
||||
|
||||
if( ctx.zIn ){
|
||||
@@ -407,7 +406,6 @@ static void fts5SnippetFunction(
|
||||
iCol = sqlite3_value_int(apVal[0]);
|
||||
ctx.zOpen = fts5ValueToText(apVal[1]);
|
||||
ctx.zClose = fts5ValueToText(apVal[2]);
|
||||
ctx.iRangeEnd = -1;
|
||||
zEllips = fts5ValueToText(apVal[3]);
|
||||
nToken = sqlite3_value_int(apVal[4]);
|
||||
|
||||
|
||||
+4
-69
@@ -22,8 +22,6 @@
|
||||
#define FTS5_DEFAULT_CRISISMERGE 16
|
||||
#define FTS5_DEFAULT_HASHSIZE (1024*1024)
|
||||
|
||||
#define FTS5_DEFAULT_DELETE_AUTOMERGE 10 /* default 10% */
|
||||
|
||||
/* Maximum allowed page size */
|
||||
#define FTS5_MAX_PAGE_SIZE (64*1024)
|
||||
|
||||
@@ -354,16 +352,6 @@ static int fts5ConfigParseSpecial(
|
||||
return rc;
|
||||
}
|
||||
|
||||
if( sqlite3_strnicmp("contentless_delete", zCmd, nCmd)==0 ){
|
||||
if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1]!='\0' ){
|
||||
*pzErr = sqlite3_mprintf("malformed contentless_delete=... directive");
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
pConfig->bContentlessDelete = (zArg[0]=='1');
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
if( sqlite3_strnicmp("content_rowid", zCmd, nCmd)==0 ){
|
||||
if( pConfig->zContentRowid ){
|
||||
*pzErr = sqlite3_mprintf("multiple content_rowid=... directives");
|
||||
@@ -562,7 +550,6 @@ int sqlite3Fts5ConfigParse(
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
|
||||
assert( (pRet->abUnindexed && pRet->azCol) || rc!=SQLITE_OK );
|
||||
for(i=3; rc==SQLITE_OK && i<nArg; i++){
|
||||
const char *zOrig = azArg[i];
|
||||
const char *z;
|
||||
@@ -608,28 +595,6 @@ int sqlite3Fts5ConfigParse(
|
||||
sqlite3_free(zTwo);
|
||||
}
|
||||
|
||||
/* We only allow contentless_delete=1 if the table is indeed contentless. */
|
||||
if( rc==SQLITE_OK
|
||||
&& pRet->bContentlessDelete
|
||||
&& pRet->eContent!=FTS5_CONTENT_NONE
|
||||
){
|
||||
*pzErr = sqlite3_mprintf(
|
||||
"contentless_delete=1 requires a contentless table"
|
||||
);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
|
||||
/* We only allow contentless_delete=1 if columnsize=0 is not present.
|
||||
**
|
||||
** This restriction may be removed at some point.
|
||||
*/
|
||||
if( rc==SQLITE_OK && pRet->bContentlessDelete && pRet->bColumnsize==0 ){
|
||||
*pzErr = sqlite3_mprintf(
|
||||
"contentless_delete=1 is incompatible with columnsize=0"
|
||||
);
|
||||
rc = SQLITE_ERROR;
|
||||
}
|
||||
|
||||
/* If a tokenizer= option was successfully parsed, the tokenizer has
|
||||
** already been allocated. Otherwise, allocate an instance of the default
|
||||
** tokenizer (unicode61) now. */
|
||||
@@ -924,18 +889,6 @@ int sqlite3Fts5ConfigSetValue(
|
||||
}
|
||||
}
|
||||
|
||||
else if( 0==sqlite3_stricmp(zKey, "deletemerge") ){
|
||||
int nVal = -1;
|
||||
if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){
|
||||
nVal = sqlite3_value_int(pVal);
|
||||
}else{
|
||||
*pbBadkey = 1;
|
||||
}
|
||||
if( nVal<0 ) nVal = FTS5_DEFAULT_DELETE_AUTOMERGE;
|
||||
if( nVal>100 ) nVal = 0;
|
||||
pConfig->nDeleteMerge = nVal;
|
||||
}
|
||||
|
||||
else if( 0==sqlite3_stricmp(zKey, "rank") ){
|
||||
const char *zIn = (const char*)sqlite3_value_text(pVal);
|
||||
char *zRank;
|
||||
@@ -950,18 +903,6 @@ int sqlite3Fts5ConfigSetValue(
|
||||
rc = SQLITE_OK;
|
||||
*pbBadkey = 1;
|
||||
}
|
||||
}
|
||||
|
||||
else if( 0==sqlite3_stricmp(zKey, "secure-delete") ){
|
||||
int bVal = -1;
|
||||
if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){
|
||||
bVal = sqlite3_value_int(pVal);
|
||||
}
|
||||
if( bVal<0 ){
|
||||
*pbBadkey = 1;
|
||||
}else{
|
||||
pConfig->bSecureDelete = (bVal ? 1 : 0);
|
||||
}
|
||||
}else{
|
||||
*pbBadkey = 1;
|
||||
}
|
||||
@@ -984,7 +925,6 @@ int sqlite3Fts5ConfigLoad(Fts5Config *pConfig, int iCookie){
|
||||
pConfig->nUsermerge = FTS5_DEFAULT_USERMERGE;
|
||||
pConfig->nCrisisMerge = FTS5_DEFAULT_CRISISMERGE;
|
||||
pConfig->nHashSize = FTS5_DEFAULT_HASHSIZE;
|
||||
pConfig->nDeleteMerge = FTS5_DEFAULT_DELETE_AUTOMERGE;
|
||||
|
||||
zSql = sqlite3Fts5Mprintf(&rc, zSelect, pConfig->zDb, pConfig->zName);
|
||||
if( zSql ){
|
||||
@@ -1007,20 +947,15 @@ int sqlite3Fts5ConfigLoad(Fts5Config *pConfig, int iCookie){
|
||||
rc = sqlite3_finalize(p);
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK
|
||||
&& iVersion!=FTS5_CURRENT_VERSION
|
||||
&& iVersion!=FTS5_CURRENT_VERSION_SECUREDELETE
|
||||
){
|
||||
if( rc==SQLITE_OK && iVersion!=FTS5_CURRENT_VERSION ){
|
||||
rc = SQLITE_ERROR;
|
||||
if( pConfig->pzErrmsg ){
|
||||
assert( 0==*pConfig->pzErrmsg );
|
||||
*pConfig->pzErrmsg = sqlite3_mprintf("invalid fts5 file format "
|
||||
"(found %d, expected %d or %d) - run 'rebuild'",
|
||||
iVersion, FTS5_CURRENT_VERSION, FTS5_CURRENT_VERSION_SECUREDELETE
|
||||
*pConfig->pzErrmsg = sqlite3_mprintf(
|
||||
"invalid fts5 file format (found %d, expected %d) - run 'rebuild'",
|
||||
iVersion, FTS5_CURRENT_VERSION
|
||||
);
|
||||
}
|
||||
}else{
|
||||
pConfig->iVersion = iVersion;
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
|
||||
+5
-55
@@ -17,10 +17,6 @@
|
||||
#include "fts5Int.h"
|
||||
#include "fts5parse.h"
|
||||
|
||||
#ifndef SQLITE_FTS5_MAX_EXPR_DEPTH
|
||||
# define SQLITE_FTS5_MAX_EXPR_DEPTH 256
|
||||
#endif
|
||||
|
||||
/*
|
||||
** All token types in the generated fts5parse.h file are greater than 0.
|
||||
*/
|
||||
@@ -61,17 +57,11 @@ struct Fts5Expr {
|
||||
** FTS5_NOT (nChild, apChild valid)
|
||||
** FTS5_STRING (pNear valid)
|
||||
** FTS5_TERM (pNear valid)
|
||||
**
|
||||
** iHeight:
|
||||
** Distance from this node to furthest leaf. This is always 0 for nodes
|
||||
** of type FTS5_STRING and FTS5_TERM. For all other nodes it is one
|
||||
** greater than the largest child value.
|
||||
*/
|
||||
struct Fts5ExprNode {
|
||||
int eType; /* Node type */
|
||||
int bEof; /* True at EOF */
|
||||
int bNomatch; /* True if entry is not a match */
|
||||
int iHeight; /* Distance to tree leaf nodes */
|
||||
|
||||
/* Next method for this node. */
|
||||
int (*xNext)(Fts5Expr*, Fts5ExprNode*, int, i64);
|
||||
@@ -141,31 +131,6 @@ struct Fts5Parse {
|
||||
int bPhraseToAnd; /* Convert "a+b" to "a AND b" */
|
||||
};
|
||||
|
||||
/*
|
||||
** Check that the Fts5ExprNode.iHeight variables are set correctly in
|
||||
** the expression tree passed as the only argument.
|
||||
*/
|
||||
#ifndef NDEBUG
|
||||
static void assert_expr_depth_ok(int rc, Fts5ExprNode *p){
|
||||
if( rc==SQLITE_OK ){
|
||||
if( p->eType==FTS5_TERM || p->eType==FTS5_STRING || p->eType==0 ){
|
||||
assert( p->iHeight==0 );
|
||||
}else{
|
||||
int ii;
|
||||
int iMaxChild = 0;
|
||||
for(ii=0; ii<p->nChild; ii++){
|
||||
Fts5ExprNode *pChild = p->apChild[ii];
|
||||
iMaxChild = MAX(iMaxChild, pChild->iHeight);
|
||||
assert_expr_depth_ok(SQLITE_OK, pChild);
|
||||
}
|
||||
assert( p->iHeight==iMaxChild+1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define assert_expr_depth_ok(rc, p)
|
||||
#endif
|
||||
|
||||
void sqlite3Fts5ParseError(Fts5Parse *pParse, const char *zFmt, ...){
|
||||
va_list ap;
|
||||
va_start(ap, zFmt);
|
||||
@@ -280,8 +245,6 @@ int sqlite3Fts5ExprNew(
|
||||
}while( sParse.rc==SQLITE_OK && t!=FTS5_EOF );
|
||||
sqlite3Fts5ParserFree(pEngine, fts5ParseFree);
|
||||
|
||||
assert_expr_depth_ok(sParse.rc, sParse.pExpr);
|
||||
|
||||
/* If the LHS of the MATCH expression was a user column, apply the
|
||||
** implicit column-filter. */
|
||||
if( iCol<pConfig->nCol && sParse.pExpr && sParse.rc==SQLITE_OK ){
|
||||
@@ -444,7 +407,7 @@ int sqlite3Fts5ExprAnd(Fts5Expr **pp1, Fts5Expr *p2){
|
||||
Fts5Parse sParse;
|
||||
memset(&sParse, 0, sizeof(sParse));
|
||||
|
||||
if( *pp1 && p2 ){
|
||||
if( *pp1 ){
|
||||
Fts5Expr *p1 = *pp1;
|
||||
int nPhrase = p1->nPhrase + p2->nPhrase;
|
||||
|
||||
@@ -469,7 +432,7 @@ int sqlite3Fts5ExprAnd(Fts5Expr **pp1, Fts5Expr *p2){
|
||||
}
|
||||
sqlite3_free(p2->apExprPhrase);
|
||||
sqlite3_free(p2);
|
||||
}else if( p2 ){
|
||||
}else{
|
||||
*pp1 = p2;
|
||||
}
|
||||
|
||||
@@ -2243,7 +2206,6 @@ static void fts5ExprAssignXNext(Fts5ExprNode *pNode){
|
||||
}
|
||||
|
||||
static void fts5ExprAddChildren(Fts5ExprNode *p, Fts5ExprNode *pSub){
|
||||
int ii = p->nChild;
|
||||
if( p->eType!=FTS5_NOT && pSub->eType==p->eType ){
|
||||
int nByte = sizeof(Fts5ExprNode*) * pSub->nChild;
|
||||
memcpy(&p->apChild[p->nChild], pSub->apChild, nByte);
|
||||
@@ -2252,9 +2214,6 @@ static void fts5ExprAddChildren(Fts5ExprNode *p, Fts5ExprNode *pSub){
|
||||
}else{
|
||||
p->apChild[p->nChild++] = pSub;
|
||||
}
|
||||
for( ; ii<p->nChild; ii++){
|
||||
p->iHeight = MAX(p->iHeight, p->apChild[ii]->iHeight + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2285,7 +2244,6 @@ static Fts5ExprNode *fts5ParsePhraseToAnd(
|
||||
if( pRet ){
|
||||
pRet->eType = FTS5_AND;
|
||||
pRet->nChild = nTerm;
|
||||
pRet->iHeight = 1;
|
||||
fts5ExprAssignXNext(pRet);
|
||||
pParse->nPhrase--;
|
||||
for(ii=0; ii<nTerm; ii++){
|
||||
@@ -2391,14 +2349,6 @@ Fts5ExprNode *sqlite3Fts5ParseNode(
|
||||
}else{
|
||||
fts5ExprAddChildren(pRet, pLeft);
|
||||
fts5ExprAddChildren(pRet, pRight);
|
||||
if( pRet->iHeight>SQLITE_FTS5_MAX_EXPR_DEPTH ){
|
||||
sqlite3Fts5ParseError(pParse,
|
||||
"fts5 expression tree is too large (maximum depth %d)",
|
||||
SQLITE_FTS5_MAX_EXPR_DEPTH
|
||||
);
|
||||
sqlite3_free(pRet);
|
||||
pRet = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2477,7 +2427,7 @@ Fts5ExprNode *sqlite3Fts5ParseImplicitAnd(
|
||||
return pRet;
|
||||
}
|
||||
|
||||
#if defined(SQLITE_TEST) || defined(SQLITE_FTS5_DEBUG)
|
||||
#ifdef SQLITE_TEST
|
||||
static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
|
||||
sqlite3_int64 nByte = 0;
|
||||
Fts5ExprTerm *p;
|
||||
@@ -2844,14 +2794,14 @@ static void fts5ExprFold(
|
||||
sqlite3_result_int(pCtx, sqlite3Fts5UnicodeFold(iCode, bRemoveDiacritics));
|
||||
}
|
||||
}
|
||||
#endif /* if SQLITE_TEST || SQLITE_FTS5_DEBUG */
|
||||
#endif /* ifdef SQLITE_TEST */
|
||||
|
||||
/*
|
||||
** This is called during initialization to register the fts5_expr() scalar
|
||||
** UDF with the SQLite handle passed as the only argument.
|
||||
*/
|
||||
int sqlite3Fts5ExprInit(Fts5Global *pGlobal, sqlite3 *db){
|
||||
#if defined(SQLITE_TEST) || defined(SQLITE_FTS5_DEBUG)
|
||||
#ifdef SQLITE_TEST
|
||||
struct Fts5ExprFunc {
|
||||
const char *z;
|
||||
void (*x)(sqlite3_context*,int,sqlite3_value**);
|
||||
|
||||
+1
-22
@@ -475,6 +475,7 @@ static int fts5HashEntrySort(
|
||||
pList = fts5HashEntryMerge(pList, ap[i]);
|
||||
}
|
||||
|
||||
pHash->nEntry = 0;
|
||||
sqlite3_free(ap);
|
||||
*ppSorted = pList;
|
||||
return SQLITE_OK;
|
||||
@@ -528,28 +529,6 @@ int sqlite3Fts5HashScanInit(
|
||||
return fts5HashEntrySort(p, pTerm, nTerm, &p->pScan);
|
||||
}
|
||||
|
||||
#ifdef SQLITE_DEBUG
|
||||
static int fts5HashCount(Fts5Hash *pHash){
|
||||
int nEntry = 0;
|
||||
int ii;
|
||||
for(ii=0; ii<pHash->nSlot; ii++){
|
||||
Fts5HashEntry *p = 0;
|
||||
for(p=pHash->aSlot[ii]; p; p=p->pHashNext){
|
||||
nEntry++;
|
||||
}
|
||||
}
|
||||
return nEntry;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Return true if the hash table is empty, false otherwise.
|
||||
*/
|
||||
int sqlite3Fts5HashIsEmpty(Fts5Hash *pHash){
|
||||
assert( pHash->nEntry==fts5HashCount(pHash) );
|
||||
return pHash->nEntry==0;
|
||||
}
|
||||
|
||||
void sqlite3Fts5HashScanNext(Fts5Hash *p){
|
||||
assert( !sqlite3Fts5HashScanEof(p) );
|
||||
p->pScan = p->pScan->pScanNext;
|
||||
|
||||
+259
-1721
File diff suppressed because it is too large
Load Diff
+6
-45
@@ -1623,7 +1623,6 @@ static int fts5UpdateMethod(
|
||||
Fts5Config *pConfig = pTab->p.pConfig;
|
||||
int eType0; /* value_type() of apVal[0] */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
int bUpdateOrDelete = 0;
|
||||
|
||||
/* A transaction must be open when this is called. */
|
||||
assert( pTab->ts.eState==1 || pTab->ts.eState==2 );
|
||||
@@ -1634,11 +1633,6 @@ static int fts5UpdateMethod(
|
||||
|| sqlite3_value_type(apVal[0])==SQLITE_NULL
|
||||
);
|
||||
assert( pTab->p.pConfig->pzErrmsg==0 );
|
||||
if( pConfig->pgsz==0 ){
|
||||
rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
|
||||
pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
|
||||
|
||||
/* Put any active cursors into REQUIRE_SEEK state. */
|
||||
@@ -1653,14 +1647,7 @@ static int fts5UpdateMethod(
|
||||
if( pConfig->eContent!=FTS5_CONTENT_NORMAL
|
||||
&& 0==sqlite3_stricmp("delete", z)
|
||||
){
|
||||
if( pConfig->bContentlessDelete ){
|
||||
fts5SetVtabError(pTab,
|
||||
"'delete' may not be used with a contentless_delete=1 table"
|
||||
);
|
||||
rc = SQLITE_ERROR;
|
||||
}else{
|
||||
rc = fts5SpecialDelete(pTab, apVal);
|
||||
}
|
||||
rc = fts5SpecialDelete(pTab, apVal);
|
||||
}else{
|
||||
rc = fts5SpecialInsert(pTab, z, apVal[2 + pConfig->nCol + 1]);
|
||||
}
|
||||
@@ -1677,7 +1664,7 @@ static int fts5UpdateMethod(
|
||||
** Cases 3 and 4 may violate the rowid constraint.
|
||||
*/
|
||||
int eConflict = SQLITE_ABORT;
|
||||
if( pConfig->eContent==FTS5_CONTENT_NORMAL || pConfig->bContentlessDelete ){
|
||||
if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
|
||||
eConflict = sqlite3_vtab_on_conflict(pConfig->db);
|
||||
}
|
||||
|
||||
@@ -1685,12 +1672,8 @@ static int fts5UpdateMethod(
|
||||
assert( nArg!=1 || eType0==SQLITE_INTEGER );
|
||||
|
||||
/* Filter out attempts to run UPDATE or DELETE on contentless tables.
|
||||
** This is not suported. Except - DELETE is supported if the CREATE
|
||||
** VIRTUAL TABLE statement contained "contentless_delete=1". */
|
||||
if( eType0==SQLITE_INTEGER
|
||||
&& pConfig->eContent==FTS5_CONTENT_NONE
|
||||
&& pConfig->bContentlessDelete==0
|
||||
){
|
||||
** This is not suported. */
|
||||
if( eType0==SQLITE_INTEGER && fts5IsContentless(pTab) ){
|
||||
pTab->p.base.zErrMsg = sqlite3_mprintf(
|
||||
"cannot %s contentless fts5 table: %s",
|
||||
(nArg>1 ? "UPDATE" : "DELETE from"), pConfig->zName
|
||||
@@ -1702,7 +1685,6 @@ static int fts5UpdateMethod(
|
||||
else if( nArg==1 ){
|
||||
i64 iDel = sqlite3_value_int64(apVal[0]); /* Rowid to delete */
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0);
|
||||
bUpdateOrDelete = 1;
|
||||
}
|
||||
|
||||
/* INSERT or UPDATE */
|
||||
@@ -1718,7 +1700,6 @@ static int fts5UpdateMethod(
|
||||
if( eConflict==SQLITE_REPLACE && eType1==SQLITE_INTEGER ){
|
||||
i64 iNew = sqlite3_value_int64(apVal[1]); /* Rowid to delete */
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
|
||||
bUpdateOrDelete = 1;
|
||||
}
|
||||
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
||||
}
|
||||
@@ -1747,24 +1728,10 @@ static int fts5UpdateMethod(
|
||||
rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
|
||||
fts5StorageInsert(&rc, pTab, apVal, pRowid);
|
||||
}
|
||||
bUpdateOrDelete = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK
|
||||
&& bUpdateOrDelete
|
||||
&& pConfig->bSecureDelete
|
||||
&& pConfig->iVersion==FTS5_CURRENT_VERSION
|
||||
){
|
||||
rc = sqlite3Fts5StorageConfigValue(
|
||||
pTab->pStorage, "version", 0, FTS5_CURRENT_VERSION_SECUREDELETE
|
||||
);
|
||||
if( rc==SQLITE_OK ){
|
||||
pConfig->iVersion = FTS5_CURRENT_VERSION_SECUREDELETE;
|
||||
}
|
||||
}
|
||||
|
||||
pTab->p.pConfig->pzErrmsg = 0;
|
||||
return rc;
|
||||
}
|
||||
@@ -1777,7 +1744,8 @@ static int fts5SyncMethod(sqlite3_vtab *pVtab){
|
||||
Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
|
||||
fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
|
||||
pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
|
||||
rc = sqlite3Fts5FlushToDisk(&pTab->p);
|
||||
fts5TripCursors(pTab);
|
||||
rc = sqlite3Fts5StorageSync(pTab->pStorage);
|
||||
pTab->p.pConfig->pzErrmsg = 0;
|
||||
return rc;
|
||||
}
|
||||
@@ -2544,12 +2512,6 @@ static int fts5ColumnMethod(
|
||||
sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
|
||||
}
|
||||
pConfig->pzErrmsg = 0;
|
||||
}else if( pConfig->bContentlessDelete && sqlite3_vtab_nochange(pCtx) ){
|
||||
char *zErr = sqlite3_mprintf("cannot UPDATE a subset of "
|
||||
"columns on fts5 contentless-delete table: %s", pConfig->zName
|
||||
);
|
||||
sqlite3_result_error(pCtx, zErr, -1);
|
||||
sqlite3_free(zErr);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -2629,7 +2591,6 @@ static int fts5RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
|
||||
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
|
||||
fts5CheckTransactionState(pTab, FTS5_ROLLBACKTO, iSavepoint);
|
||||
fts5TripCursors(pTab);
|
||||
pTab->p.pConfig->pgsz = 0;
|
||||
return sqlite3Fts5StorageRollback(pTab->pStorage);
|
||||
}
|
||||
|
||||
|
||||
+12
-72
@@ -77,10 +77,10 @@ static int fts5StorageGetStmt(
|
||||
"INSERT INTO %Q.'%q_content' VALUES(%s)", /* INSERT_CONTENT */
|
||||
"REPLACE INTO %Q.'%q_content' VALUES(%s)", /* REPLACE_CONTENT */
|
||||
"DELETE FROM %Q.'%q_content' WHERE id=?", /* DELETE_CONTENT */
|
||||
"REPLACE INTO %Q.'%q_docsize' VALUES(?,?%s)", /* REPLACE_DOCSIZE */
|
||||
"REPLACE INTO %Q.'%q_docsize' VALUES(?,?)", /* REPLACE_DOCSIZE */
|
||||
"DELETE FROM %Q.'%q_docsize' WHERE id=?", /* DELETE_DOCSIZE */
|
||||
|
||||
"SELECT sz%s FROM %Q.'%q_docsize' WHERE id=?", /* LOOKUP_DOCSIZE */
|
||||
"SELECT sz FROM %Q.'%q_docsize' WHERE id=?", /* LOOKUP_DOCSIZE */
|
||||
|
||||
"REPLACE INTO %Q.'%q_config' VALUES(?,?)", /* REPLACE_CONFIG */
|
||||
"SELECT %s FROM %s AS T", /* SCAN */
|
||||
@@ -128,19 +128,6 @@ static int fts5StorageGetStmt(
|
||||
break;
|
||||
}
|
||||
|
||||
case FTS5_STMT_REPLACE_DOCSIZE:
|
||||
zSql = sqlite3_mprintf(azStmt[eStmt], pC->zDb, pC->zName,
|
||||
(pC->bContentlessDelete ? ",?" : "")
|
||||
);
|
||||
break;
|
||||
|
||||
case FTS5_STMT_LOOKUP_DOCSIZE:
|
||||
zSql = sqlite3_mprintf(azStmt[eStmt],
|
||||
(pC->bContentlessDelete ? ",origin" : ""),
|
||||
pC->zDb, pC->zName
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
zSql = sqlite3_mprintf(azStmt[eStmt], pC->zDb, pC->zName);
|
||||
break;
|
||||
@@ -330,11 +317,9 @@ int sqlite3Fts5StorageOpen(
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK && pConfig->bColumnsize ){
|
||||
const char *zCols = "id INTEGER PRIMARY KEY, sz BLOB";
|
||||
if( pConfig->bContentlessDelete ){
|
||||
zCols = "id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER";
|
||||
}
|
||||
rc = sqlite3Fts5CreateTable(pConfig, "docsize", zCols, 0, pzErr);
|
||||
rc = sqlite3Fts5CreateTable(
|
||||
pConfig, "docsize", "id INTEGER PRIMARY KEY, sz BLOB", 0, pzErr
|
||||
);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5CreateTable(
|
||||
@@ -411,7 +396,7 @@ static int fts5StorageDeleteFromIndex(
|
||||
){
|
||||
Fts5Config *pConfig = p->pConfig;
|
||||
sqlite3_stmt *pSeek = 0; /* SELECT to read row iDel from %_data */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
int rc; /* Return code */
|
||||
int rc2; /* sqlite3_reset() return code */
|
||||
int iCol;
|
||||
Fts5InsertCtx ctx;
|
||||
@@ -427,6 +412,7 @@ static int fts5StorageDeleteFromIndex(
|
||||
|
||||
ctx.pStorage = p;
|
||||
ctx.iCol = -1;
|
||||
rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel);
|
||||
for(iCol=1; rc==SQLITE_OK && iCol<=pConfig->nCol; iCol++){
|
||||
if( pConfig->abUnindexed[iCol-1]==0 ){
|
||||
const char *zText;
|
||||
@@ -463,37 +449,6 @@ static int fts5StorageDeleteFromIndex(
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called to process a DELETE on a contentless_delete=1
|
||||
** table. It adds the tombstone required to delete the entry with rowid
|
||||
** iDel. If successful, SQLITE_OK is returned. Or, if an error occurs,
|
||||
** an SQLite error code.
|
||||
*/
|
||||
static int fts5StorageContentlessDelete(Fts5Storage *p, i64 iDel){
|
||||
i64 iOrigin = 0;
|
||||
sqlite3_stmt *pLookup = 0;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
assert( p->pConfig->bContentlessDelete );
|
||||
assert( p->pConfig->eContent==FTS5_CONTENT_NONE );
|
||||
|
||||
/* Look up the origin of the document in the %_docsize table. Store
|
||||
** this in stack variable iOrigin. */
|
||||
rc = fts5StorageGetStmt(p, FTS5_STMT_LOOKUP_DOCSIZE, &pLookup, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_bind_int64(pLookup, 1, iDel);
|
||||
if( SQLITE_ROW==sqlite3_step(pLookup) ){
|
||||
iOrigin = sqlite3_column_int64(pLookup, 1);
|
||||
}
|
||||
rc = sqlite3_reset(pLookup);
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK && iOrigin!=0 ){
|
||||
rc = sqlite3Fts5IndexContentlessDelete(p->pIndex, iOrigin, iDel);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Insert a record into the %_docsize table. Specifically, do:
|
||||
@@ -514,17 +469,10 @@ static int fts5StorageInsertDocsize(
|
||||
rc = fts5StorageGetStmt(p, FTS5_STMT_REPLACE_DOCSIZE, &pReplace, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_bind_int64(pReplace, 1, iRowid);
|
||||
if( p->pConfig->bContentlessDelete ){
|
||||
i64 iOrigin = 0;
|
||||
rc = sqlite3Fts5IndexGetOrigin(p->pIndex, &iOrigin);
|
||||
sqlite3_bind_int64(pReplace, 3, iOrigin);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC);
|
||||
sqlite3_step(pReplace);
|
||||
rc = sqlite3_reset(pReplace);
|
||||
sqlite3_bind_null(pReplace, 2);
|
||||
}
|
||||
sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC);
|
||||
sqlite3_step(pReplace);
|
||||
rc = sqlite3_reset(pReplace);
|
||||
sqlite3_bind_null(pReplace, 2);
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
@@ -588,15 +536,7 @@ int sqlite3Fts5StorageDelete(Fts5Storage *p, i64 iDel, sqlite3_value **apVal){
|
||||
|
||||
/* Delete the index records */
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3Fts5IndexBeginWrite(p->pIndex, 1, iDel);
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
if( p->pConfig->bContentlessDelete ){
|
||||
rc = fts5StorageContentlessDelete(p, iDel);
|
||||
}else{
|
||||
rc = fts5StorageDeleteFromIndex(p, iDel, apVal);
|
||||
}
|
||||
rc = fts5StorageDeleteFromIndex(p, iDel, apVal);
|
||||
}
|
||||
|
||||
/* Delete the %_docsize record */
|
||||
|
||||
@@ -594,10 +594,6 @@ proc nearset_rc {aCol args} {
|
||||
list
|
||||
}
|
||||
|
||||
proc dump {tname} {
|
||||
execsql_pp "SELECT * FROM ${tname}_idx"
|
||||
execsql_pp "SELECT id, quote(block), fts5_decode(id,block) FROM ${tname}_data"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Code for a simple Tcl tokenizer that supports synonyms at query time.
|
||||
|
||||
@@ -180,11 +180,7 @@ if {[detail_is_full]} {
|
||||
} {1 2}
|
||||
}
|
||||
|
||||
do_execsql_test 4.5.1 {
|
||||
SELECT rowid FROM s1 WHERE s1 MATCH 'a AND x'
|
||||
} {1 2}
|
||||
|
||||
do_execsql_test 4.5.2 {
|
||||
do_execsql_test 4.5 {
|
||||
SELECT rowid FROM s1 WHERE s1 MATCH 'a x'
|
||||
} {1 2}
|
||||
|
||||
|
||||
@@ -193,34 +193,4 @@ do_execsql_test 5.6 {
|
||||
|
||||
} ;# foreach_detail_mode
|
||||
|
||||
reset_db
|
||||
do_execsql_test 6.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(colA, colB);
|
||||
INSERT INTO t1 VALUES('A B C', 'D E F');
|
||||
}
|
||||
|
||||
do_execsql_test 6.1 {
|
||||
SELECT colA, colB, snippet(t1,0,'[', ']','...',1) FROM t1 WHERE t1 MATCH 'B';
|
||||
} {{A B C} {D E F} ...[B]...}
|
||||
breakpoint
|
||||
do_execsql_test 6.2 {
|
||||
SELECT colA, colB, snippet(t1, 1,'[',']','...',2) FROM t1 WHERE t1 MATCH 'B';
|
||||
} {{A B C} {D E F} {D E...}}
|
||||
do_execsql_test 6.3 {
|
||||
SELECT colA, colB, snippet(t1, 1,'[',']','...',1) FROM t1 WHERE t1 MATCH 'B';
|
||||
} {{A B C} {D E F} {D...}}
|
||||
|
||||
do_execsql_test 6.1 {
|
||||
SELECT colA, colB, snippet(t1,0,'[', ']','...',1) FROM t1 WHERE t1 MATCH 'A';
|
||||
} {{A B C} {D E F} [A]...}
|
||||
breakpoint
|
||||
do_execsql_test 6.2 {
|
||||
SELECT colA, colB, snippet(t1, 1,'[',']','...',2) FROM t1 WHERE t1 MATCH 'A';
|
||||
} {{A B C} {D E F} {D E...}}
|
||||
do_execsql_test 6.3 {
|
||||
SELECT colA, colB, snippet(t1, 1,'[',']','...',1) FROM t1 WHERE t1 MATCH 'A';
|
||||
} {{A B C} {D E F} {D...}}
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -154,30 +154,4 @@ do_execsql_test 3.2 {
|
||||
|
||||
}
|
||||
|
||||
# 2023-04-06 https://sqlite.org/forum/forumpost/cae4367d9b
|
||||
#
|
||||
# This is not a test of FTS5, but rather a test of the of what happens to
|
||||
# prepared statements that encounter SQLITE_SCHEMA while other prepared
|
||||
# statements are running. The original problem POC used FTS5, and so
|
||||
# is seems reasonable to put the test here.
|
||||
#
|
||||
# The vdbeaux24.test module in TH3 also tests this same behavior but
|
||||
# without requiring FTS5 or an other extension.
|
||||
#
|
||||
reset_db
|
||||
db null NULL
|
||||
do_execsql_test 4.0 {
|
||||
CREATE TABLE t5(a PRIMARY KEY);
|
||||
INSERT INTO t5 VALUES(0);
|
||||
CREATE VIRTUAL TABLE t6 USING fts5(0);
|
||||
DELETE FROM t6;
|
||||
CREATE TABLE t7(x);
|
||||
WITH cte(a) AS (
|
||||
SELECT a FROM t5
|
||||
WHERE ((0,0) IN (SELECT 0, LAG(0) OVER (PARTITION BY 0) FROM t6), 0)
|
||||
< (a,0)
|
||||
)
|
||||
SELECT max(a) FROM cte;
|
||||
} NULL
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
# 2023 May 28
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5bigid
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
set nRow 20000
|
||||
|
||||
proc do_ascdesc_test {tn query} {
|
||||
set ::lAsc [db eval { SELECT rowid FROM x1($query) }]
|
||||
set ::lDesc [db eval { SELECT rowid FROM x1($query) ORDER BY rowid DESC }]
|
||||
do_test $tn.1 { lsort -integer $::lAsc } $::lAsc
|
||||
do_test $tn.2 { lsort -integer -decr $::lDesc } $::lDesc
|
||||
do_test $tn.3 { lsort -integer $::lDesc } $::lAsc
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE x1 USING fts5(a);
|
||||
}
|
||||
|
||||
do_test 1.1 {
|
||||
for {set ii 0} {$ii < $nRow} {incr ii} {
|
||||
db eval {
|
||||
REPLACE INTO x1(rowid, a) VALUES(random(), 'movement at the station');
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
do_ascdesc_test 1.2 "the"
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
DELETE FROM x1
|
||||
}
|
||||
|
||||
do_test 1.4 {
|
||||
for {set ii 0} {$ii < $nRow} {incr ii} {
|
||||
db eval {
|
||||
INSERT INTO x1(rowid, a) VALUES(
|
||||
$ii + 0x6FFFFFFFFFFFFFFF, 'movement at the station'
|
||||
);
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
do_ascdesc_test 1.5 "movement"
|
||||
|
||||
finish_test
|
||||
@@ -1,271 +0,0 @@
|
||||
# 2014 Dec 20
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file contains tests for the content= and content_rowid= options.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5contentless
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Check that it is not possible to specify "contentless_delete=1" for
|
||||
# anything other than a contentless table.
|
||||
#
|
||||
set res(0) {0 {}}
|
||||
set res(1) {1 {contentless_delete=1 requires a contentless table}}
|
||||
foreach {tn sql bError} {
|
||||
1 "(a, b, contentless_delete=1)" 1
|
||||
2 "(a, b, contentless_delete=1, content=abc)" 1
|
||||
3 "(a, b, contentless_delete=1, content=)" 0
|
||||
4 "(content=, contentless_delete=1, a)" 0
|
||||
5 "(content='', contentless_delete=1, hello)" 0
|
||||
} {
|
||||
execsql { BEGIN }
|
||||
do_catchsql_test 1.$tn "CREATE VIRTUAL TABLE t1 USING fts5 $sql" $res($bError)
|
||||
execsql { ROLLBACK }
|
||||
}
|
||||
|
||||
# Check that it is not possible to specify "contentless_delete=1"
|
||||
# along with columnsize=1.
|
||||
#
|
||||
set res(0) {0 {}}
|
||||
set res(1) {1 {contentless_delete=1 is incompatible with columnsize=0}}
|
||||
foreach {tn sql bError} {
|
||||
2 "(a, b, content='', contentless_delete=1, columnsize=0)" 1
|
||||
} {
|
||||
execsql { BEGIN }
|
||||
do_catchsql_test 1.$tn "CREATE VIRTUAL TABLE t1 USING fts5 $sql" $res($bError)
|
||||
execsql { ROLLBACK }
|
||||
}
|
||||
|
||||
# Check that if contentless_delete=1 is specified, then the "origin"
|
||||
# column is added to the %_docsize table.
|
||||
reset_db
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE x1 USING fts5(c, content='');
|
||||
CREATE VIRTUAL TABLE x2 USING fts5(c, content='', contentless_delete=1);
|
||||
}
|
||||
do_execsql_test 3.1 {
|
||||
SELECT sql FROM sqlite_schema WHERE name IN ('x1_docsize', 'x2_docsize');
|
||||
} {
|
||||
{CREATE TABLE 'x1_docsize'(id INTEGER PRIMARY KEY, sz BLOB)}
|
||||
{CREATE TABLE 'x2_docsize'(id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER)}
|
||||
}
|
||||
|
||||
do_execsql_test 3.2.1 {
|
||||
SELECT hex(block) FROM x1_data WHERE id=10
|
||||
} {00000000000000}
|
||||
do_execsql_test 3.2.2 {
|
||||
SELECT hex(block) FROM x2_data WHERE id=10
|
||||
} {00000000FF000001000000}
|
||||
|
||||
do_execsql_test 3.3 {
|
||||
INSERT INTO x2 VALUES('first text');
|
||||
INSERT INTO x2 VALUES('second text');
|
||||
}
|
||||
do_execsql_test 3.4 {
|
||||
SELECT id, origin FROM x2_docsize
|
||||
} {1 1 2 2}
|
||||
do_execsql_test 3.5 {
|
||||
SELECT level, segment, loc1, loc2 FROM fts5_structure(
|
||||
(SELECT block FROM x2_data WHERE id=10)
|
||||
)
|
||||
} {
|
||||
0 0 1 1
|
||||
0 1 2 2
|
||||
}
|
||||
do_execsql_test 3.6 {
|
||||
INSERT INTO x2(x2) VALUES('optimize');
|
||||
}
|
||||
do_execsql_test 3.7 {
|
||||
SELECT level, segment, loc1, loc2 FROM fts5_structure(
|
||||
(SELECT block FROM x2_data WHERE id=10)
|
||||
)
|
||||
} {
|
||||
1 0 1 2
|
||||
}
|
||||
|
||||
do_execsql_test 3.8 {
|
||||
DELETE FROM x2 WHERE rowid=2;
|
||||
}
|
||||
|
||||
do_execsql_test 3.9 {
|
||||
SELECT rowid FROM x2('text')
|
||||
} {1}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
reset_db
|
||||
proc document {n} {
|
||||
set vocab [list A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
|
||||
set ret [list]
|
||||
for {set ii 0} {$ii < $n} {incr ii} {
|
||||
lappend ret [lindex $vocab [expr int(rand()*[llength $vocab])]]
|
||||
}
|
||||
set ret
|
||||
}
|
||||
|
||||
set nRow 1000
|
||||
|
||||
do_execsql_test 4.0 {
|
||||
CREATE TABLE t1(x);
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
|
||||
INSERT INTO ft(ft, rank) VALUES('pgsz', 100);
|
||||
}
|
||||
do_test 4.1 {
|
||||
for {set ii 0} {$ii < $nRow} {incr ii} {
|
||||
set doc [document 6]
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES($doc);
|
||||
INSERT INTO ft VALUES($doc);
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
foreach v {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
|
||||
set L1 [execsql {SELECT rowid FROM t1 WHERE x LIKE '%'||$v||'%'}]
|
||||
set L2 [execsql {SELECT rowid FROM ft($v)}]
|
||||
do_test 4.2.$v { set L1 } $L2
|
||||
}
|
||||
|
||||
do_test 4.3 {
|
||||
for {set ii 1} {$ii < $nRow} {incr ii 2} {
|
||||
execsql {
|
||||
DELETE FROM ft WHERE rowid=$ii;
|
||||
DELETE FROM t1 WHERE rowid=$ii;
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
foreach v {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
|
||||
set L1 [execsql {SELECT rowid FROM t1 WHERE x LIKE '%'||$v||'%'}]
|
||||
set L2 [execsql {SELECT rowid FROM ft($v)}]
|
||||
do_test 4.4.$v { set L1 } $L2
|
||||
}
|
||||
|
||||
do_execsql_test 4.5 {
|
||||
INSERT INTO ft(ft) VALUES('optimize');
|
||||
} {}
|
||||
|
||||
foreach v {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
|
||||
set L1 [execsql {SELECT rowid FROM t1 WHERE x LIKE '%'||$v||'%'}]
|
||||
set L2 [execsql {SELECT rowid FROM ft($v)}]
|
||||
do_test 4.6.$v { set L1 } $L2
|
||||
}
|
||||
|
||||
#execsql_pp { SELECT fts5_decode(id, block) FROM ft_data }
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 5.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
|
||||
INSERT INTO ft(rowid, x) VALUES(1, 'one two three');
|
||||
INSERT INTO ft(rowid, x) VALUES(2, 'one two four');
|
||||
INSERT INTO ft(rowid, x) VALUES(3, 'one two five');
|
||||
INSERT INTO ft(rowid, x) VALUES(4, 'one two seven');
|
||||
INSERT INTO ft(rowid, x) VALUES(5, 'one two eight');
|
||||
}
|
||||
|
||||
do_execsql_test 5.1 {
|
||||
DELETE FROM ft WHERE rowid=2
|
||||
}
|
||||
|
||||
do_execsql_test 5.2 {
|
||||
SELECT rowid FROM ft
|
||||
} {1 3 4 5}
|
||||
|
||||
do_catchsql_test 5.3 {
|
||||
UPDATE ft SET x='four six' WHERE rowid=3
|
||||
} {0 {}}
|
||||
|
||||
do_execsql_test 5.4 {
|
||||
SELECT rowid FROM ft('one');
|
||||
} {1 4 5}
|
||||
|
||||
do_execsql_test 5.5 {
|
||||
REPLACE INTO ft(rowid, x) VALUES(3, 'four six');
|
||||
SELECT rowid FROM ft('one');
|
||||
} {1 4 5}
|
||||
|
||||
do_execsql_test 5.6 {
|
||||
REPLACE INTO ft(rowid, x) VALUES(6, 'one two eleven');
|
||||
SELECT rowid FROM ft('one');
|
||||
} {1 4 5 6}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 6.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
|
||||
INSERT INTO ft(rowid, x) VALUES(1, 'one two three');
|
||||
INSERT INTO ft(rowid, x) VALUES(2, 'one two four');
|
||||
}
|
||||
|
||||
do_test 6.1 {
|
||||
db eval { SELECT rowid FROM ft('one two') } {
|
||||
if {$rowid==1} {
|
||||
db eval { INSERT INTO ft(rowid, x) VALUES(3, 'one two four') }
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 7.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
|
||||
}
|
||||
|
||||
set lRowid [list -450 0 1 2 42]
|
||||
|
||||
do_test 7.1 {
|
||||
execsql BEGIN
|
||||
foreach r $lRowid {
|
||||
execsql { INSERT INTO ft(rowid, x) VALUES($r, 'one one one'); }
|
||||
}
|
||||
execsql COMMIT
|
||||
} {}
|
||||
|
||||
do_test 7.2 {
|
||||
execsql BEGIN
|
||||
foreach r $lRowid {
|
||||
execsql { REPLACE INTO ft(rowid, x) VALUES($r, 'two two two'); }
|
||||
}
|
||||
execsql COMMIT
|
||||
} {}
|
||||
|
||||
do_execsql_test 7.3 { SELECT rowid FROM ft('one'); } {}
|
||||
do_execsql_test 7.4 { SELECT rowid FROM ft('two'); } $lRowid
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 8.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
|
||||
INSERT INTO ft VALUES('hello world');
|
||||
INSERT INTO ft VALUES('one two three');
|
||||
}
|
||||
|
||||
do_catchsql_test 8.1 {
|
||||
INSERT INTO ft(ft, rowid, x) VALUES('delete', 1, 'hello world');
|
||||
} {1 {'delete' may not be used with a contentless_delete=1 table}}
|
||||
|
||||
do_execsql_test 8.2 {
|
||||
BEGIN;
|
||||
INSERT INTO ft(rowid, x) VALUES(3, 'four four four');
|
||||
DELETE FROM ft WHERE rowid=3;
|
||||
COMMIT;
|
||||
SELECT rowid FROM ft('four');
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,208 +0,0 @@
|
||||
# 2023 July 19
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file contains tests for the content= and content_rowid= options.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5contentless2
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
proc vocab {} {
|
||||
list aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp
|
||||
}
|
||||
|
||||
proc document {nToken} {
|
||||
set doc [list]
|
||||
set vocab [vocab]
|
||||
for {set ii 0} {$ii < $nToken} {incr ii} {
|
||||
lappend doc [lindex $vocab [expr int(rand()*[llength $vocab])]]
|
||||
}
|
||||
set doc
|
||||
}
|
||||
db func document document
|
||||
|
||||
proc contains {doc token} {
|
||||
expr {[lsearch $doc $token]>=0}
|
||||
}
|
||||
db func contains contains
|
||||
|
||||
proc do_compare_tables_test {tn} {
|
||||
uplevel [list do_test $tn {
|
||||
foreach v [vocab] {
|
||||
set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $v) }]
|
||||
set l2 [execsql { SELECT rowid FROM t2($v) }]
|
||||
if {$l1!=$l2} { error "1: query mismatch ($l1) ($l2)" }
|
||||
|
||||
set w "[string range $v 0 1]*"
|
||||
set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $w) }]
|
||||
set l2 [execsql { SELECT rowid FROM t2($w) }]
|
||||
if {$l1!=$l2} { error "2: query mismatch ($l1) ($l2)" }
|
||||
|
||||
set w "[string range $v 0 0]*"
|
||||
set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $w) }]
|
||||
set l2 [execsql { SELECT rowid FROM t2($w) }]
|
||||
if {$l1!=$l2} { error "2: query mismatch ($l1) ($l2)" }
|
||||
|
||||
set l1 [execsql {
|
||||
SELECT rowid FROM t1 WHERE contains(doc, $v) ORDER BY rowid DESC
|
||||
}]
|
||||
set l2 [execsql { SELECT rowid FROM t2($v) ORDER BY rowid DESC }]
|
||||
if {$l1!=$l2} { error "1: query mismatch ($l1) ($l2)" }
|
||||
}
|
||||
set {} {}
|
||||
} {}]
|
||||
}
|
||||
|
||||
proc lshuffle {in} {
|
||||
set L [list]
|
||||
set ret [list]
|
||||
foreach elem $in { lappend L [list [expr rand()] $elem] }
|
||||
foreach pair [lsort -index 0 $L] { lappend ret [lindex $pair 1] }
|
||||
set ret
|
||||
}
|
||||
|
||||
expr srand(0)
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE t2 USING fts5(
|
||||
doc, prefix=2, content=, contentless_delete=1
|
||||
);
|
||||
|
||||
CREATE TABLE t1(doc);
|
||||
CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN
|
||||
DELETE FROM t2 WHERE rowid = old.rowid;
|
||||
END;
|
||||
}
|
||||
|
||||
set SMALLEST64 -9223372036854775808
|
||||
set LARGEST64 9223372036854775807
|
||||
|
||||
foreach {tn r1 r2} {
|
||||
1 0 50
|
||||
2 $SMALLEST64 $SMALLEST64+50
|
||||
3 $LARGEST64-50 $LARGEST64
|
||||
4 -50 -1
|
||||
} {
|
||||
set r1 [expr $r1]
|
||||
set r2 [expr $r2]
|
||||
|
||||
do_test 1.1.$tn {
|
||||
execsql BEGIN
|
||||
for {set ii $r1} {$ii <= $r2} {incr ii} {
|
||||
execsql { INSERT INTO t1(rowid, doc) VALUES ($ii, document(8)); }
|
||||
}
|
||||
execsql COMMIT
|
||||
} {}
|
||||
}
|
||||
do_test 1.2 {
|
||||
db eval { SELECT rowid, doc FROM t1 } {
|
||||
execsql { INSERT INTO t2(rowid, doc) VALUES($rowid, $doc) }
|
||||
}
|
||||
} {}
|
||||
|
||||
foreach {tn rowid} {
|
||||
1 $SMALLEST64
|
||||
2 0
|
||||
3 -5
|
||||
4 -30
|
||||
5 $LARGEST64
|
||||
6 $LARGEST64-1
|
||||
} {
|
||||
set rowid [expr $rowid]
|
||||
do_execsql_test 1.3.$tn.1 {
|
||||
DELETE FROM t1 WHERE rowid=$rowid
|
||||
}
|
||||
do_compare_tables_test 1.3.$tn.2
|
||||
}
|
||||
|
||||
set iTest 1
|
||||
foreach r [lshuffle [execsql {SELECT rowid FROM t1}]] {
|
||||
if {($iTest % 50)==0} {
|
||||
execsql { INSERT INTO t2(t2) VALUES('optimize') }
|
||||
}
|
||||
if {($iTest % 5)==0} {
|
||||
execsql { INSERT INTO t2(t2, rank) VALUES('merge', 5) }
|
||||
}
|
||||
do_execsql_test 1.4.$iTest.1($r) {
|
||||
DELETE FROM t1 WHERE rowid=$r
|
||||
}
|
||||
do_compare_tables_test 1.4.$iTest.2
|
||||
incr iTest
|
||||
}
|
||||
|
||||
do_execsql_test 1.5 {
|
||||
SELECT * FROM t1
|
||||
} {}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
db func document document
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE t2 USING fts5(doc, content=, contentless_delete=1);
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
|
||||
)
|
||||
INSERT INTO t2(rowid, doc) SELECT i, i || ' ' || i FROM s;
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
BEGIN;
|
||||
DELETE FROM t2 WHERE rowid=32;
|
||||
DELETE FROM t2 WHERE rowid=64;
|
||||
DELETE FROM t2 WHERE rowid=96;
|
||||
DELETE FROM t2 WHERE rowid=128;
|
||||
DELETE FROM t2 WHERE rowid=160;
|
||||
DELETE FROM t2 WHERE rowid=192;
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
SELECT * FROM t2('128');
|
||||
} {}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
foreach {tn step} {
|
||||
1 3
|
||||
2 7
|
||||
3 15
|
||||
} {
|
||||
set step [expr $step]
|
||||
|
||||
reset_db
|
||||
db func document document
|
||||
do_execsql_test 3.$tn.0 {
|
||||
CREATE VIRTUAL TABLE t2 USING fts5(doc, content=, contentless_delete=1);
|
||||
INSERT INTO t2(t2, rank) VALUES('pgsz', 100);
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
|
||||
)
|
||||
INSERT INTO t2(rowid, doc) SELECT i, i || ' ' || i FROM s;
|
||||
}
|
||||
do_execsql_test 3.$tn.1 {
|
||||
DELETE FROM t2 WHERE (rowid % $step)==0
|
||||
}
|
||||
do_execsql_test 3.$tn.2 {
|
||||
SELECT * FROM t2( $step * 5 )
|
||||
} {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
# 2023 July 21
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file contains tests for the content= and content_rowid= options.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5contentless3
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content=, contentless_delete=1);
|
||||
BEGIN;
|
||||
INSERT INTO ft VALUES('one one one');
|
||||
INSERT INTO ft VALUES('two two two');
|
||||
INSERT INTO ft VALUES('three three three');
|
||||
INSERT INTO ft VALUES('four four four');
|
||||
INSERT INTO ft VALUES('five five five');
|
||||
INSERT INTO ft VALUES('six six six');
|
||||
INSERT INTO ft VALUES('seven seven seven');
|
||||
INSERT INTO ft VALUES('eight eight eight');
|
||||
INSERT INTO ft VALUES('nine nine nine');
|
||||
COMMIT;
|
||||
|
||||
DELETE FROM ft WHERE rowid=3;
|
||||
}
|
||||
|
||||
proc myhex {hex} { binary decode hex $hex }
|
||||
db func myhex myhex
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
UPDATE ft_data SET block =
|
||||
myhex('04000000 00000001' ||
|
||||
'01020304 01020304 01020304 01020304' ||
|
||||
'01020304 01020304 01020304 01020304'
|
||||
)
|
||||
WHERE id = (SELECT max(id) FROM ft_data);
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
DELETE FROM ft WHERE rowid=1
|
||||
}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
SELECT rowid FROM ft('two');
|
||||
} {2}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
UPDATE ft_data SET block =
|
||||
myhex('08000000 00000001' ||
|
||||
'0000000001020304 0000000001020304 0000000001020304 0000000001020304' ||
|
||||
'0000000001020304 0000000001020304 0000000001020304 0000000001020304'
|
||||
)
|
||||
WHERE id = (SELECT max(id) FROM ft_data);
|
||||
}
|
||||
|
||||
do_execsql_test 1.4 {
|
||||
SELECT rowid FROM ft('two');
|
||||
} {2}
|
||||
|
||||
do_execsql_test 1.5 {
|
||||
DELETE FROM ft WHERE rowid=4
|
||||
}
|
||||
|
||||
do_execsql_test 1.6 {
|
||||
UPDATE ft_data SET block = myhex('04000000 00000000')
|
||||
WHERE id = (SELECT max(id) FROM ft_data);
|
||||
}
|
||||
do_execsql_test 1.7 {
|
||||
SELECT rowid FROM ft('two');
|
||||
} {2}
|
||||
|
||||
do_execsql_test 1.8 {
|
||||
UPDATE ft_data SET block = myhex('04000000 00000000')
|
||||
WHERE id = (SELECT max(id) FROM ft_data);
|
||||
}
|
||||
do_execsql_test 1.9 {
|
||||
DELETE FROM ft WHERE rowid=8
|
||||
} {}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content=, contentless_delete=1);
|
||||
INSERT INTO ft VALUES('one one one');
|
||||
INSERT INTO ft VALUES('two two two');
|
||||
INSERT INTO ft VALUES('three three three');
|
||||
INSERT INTO ft VALUES('four four four');
|
||||
INSERT INTO ft VALUES('five five five');
|
||||
INSERT INTO ft VALUES('six six six');
|
||||
INSERT INTO ft VALUES('seven seven seven');
|
||||
INSERT INTO ft VALUES('eight eight eight');
|
||||
INSERT INTO ft VALUES('nine nine nine');
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
INSERT INTO ft(ft) VALUES('optimize');
|
||||
}
|
||||
do_execsql_test 2.2 {
|
||||
SELECT count(*) FROM ft_data
|
||||
} {3}
|
||||
do_execsql_test 2.3 {
|
||||
DELETE FROM ft WHERE rowid=5
|
||||
}
|
||||
do_execsql_test 2.4 {
|
||||
SELECT count(*) FROM ft_data
|
||||
} {4}
|
||||
|
||||
# Check that an 'optimize' works (rewrites the index) if there is a single
|
||||
# segment with one or more tombstone hash pages.
|
||||
do_execsql_test 2.5 {
|
||||
INSERT INTO ft(ft) VALUES('optimize');
|
||||
}
|
||||
do_execsql_test 2.6 {
|
||||
SELECT count(*) FROM ft_data
|
||||
} {3}
|
||||
|
||||
# Check that an 'optimize' is a no-op if there is a single segment
|
||||
# and no tombstone hash pages.
|
||||
do_execsql_test 2.7 {
|
||||
INSERT INTO ft(ft) VALUES('optimize');
|
||||
SELECT rowid FROM ft_data;
|
||||
} [db eval {SELECT rowid FROM ft_data}]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content=, contentless_delete=1);
|
||||
INSERT INTO ft(ft, rank) VALUES('pgsz', 64);
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
|
||||
)
|
||||
INSERT INTO ft(rowid, x) SELECT i, i||' '||i||' '||i||' '||i FROM s;
|
||||
INSERT INTO ft(ft) VALUES('optimize');
|
||||
}
|
||||
|
||||
do_execsql_test 3.1 {
|
||||
SELECT count(*) FROM ft_data
|
||||
} {200}
|
||||
|
||||
do_execsql_test 3.2 {
|
||||
DELETE FROM ft WHERE (rowid % 50)==0;
|
||||
SELECT count(*) FROM ft_data;
|
||||
} {203}
|
||||
|
||||
do_execsql_test 3.3 {
|
||||
INSERT INTO ft(ft, rank) VALUES('merge', 500);
|
||||
SELECT rowid FROM ft_data;
|
||||
} [db eval {SELECT rowid FROM ft_data}]
|
||||
|
||||
do_execsql_test 3.4 {
|
||||
INSERT INTO ft(ft, rank) VALUES('merge', -1000);
|
||||
SELECT count(*) FROM ft_data;
|
||||
} {197}
|
||||
|
||||
do_execsql_test 3.5 {
|
||||
DELETE FROM ft WHERE (rowid % 50)==1;
|
||||
SELECT count(*) FROM ft_data;
|
||||
} {200}
|
||||
|
||||
do_execsql_test 3.6 {
|
||||
SELECT level, segment, npgtombstone FROM fts5_structure(
|
||||
(SELECT block FROM ft_data WHERE id=10)
|
||||
)
|
||||
} {1 0 3}
|
||||
|
||||
do_test 3.6 {
|
||||
while 1 {
|
||||
set nChange [db total_changes]
|
||||
execsql { INSERT INTO ft(ft, rank) VALUES('merge', -5) }
|
||||
if {([db total_changes] - $nChange)<2} break
|
||||
}
|
||||
} {}
|
||||
|
||||
do_execsql_test 3.7 {
|
||||
SELECT level, segment, npgtombstone FROM fts5_structure(
|
||||
(SELECT block FROM ft_data WHERE id=10)
|
||||
)
|
||||
} {2 0 0}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
# 2023 July 21
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file contains tests for the content= and content_rowid= options.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5contentless4
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
proc document {n} {
|
||||
set vocab [list A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
|
||||
set ret [list]
|
||||
for {set ii 0} {$ii < $n} {incr ii} {
|
||||
lappend ret [lindex $vocab [expr int(rand()*[llength $vocab])]]
|
||||
}
|
||||
set ret
|
||||
}
|
||||
db func document document
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
|
||||
INSERT INTO ft(ft, rank) VALUES('pgsz', 240);
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
|
||||
)
|
||||
INSERT INTO ft SELECT document(12) FROM s;
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
INSERT INTO ft(ft) VALUES('optimize');
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
SELECT level, segment, nentry, nentrytombstone FROM fts5_structure((
|
||||
SELECT block FROM ft_data WHERE id=10
|
||||
))
|
||||
} {0 0 1000 0}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
DELETE FROM ft WHERE rowid < 50
|
||||
}
|
||||
|
||||
do_execsql_test 1.4 {
|
||||
SELECT level, segment, nentry, nentrytombstone FROM fts5_structure((
|
||||
SELECT block FROM ft_data WHERE id=10
|
||||
))
|
||||
} {0 0 1000 49}
|
||||
|
||||
do_execsql_test 1.5 {
|
||||
DELETE FROM ft WHERE rowid < 1000
|
||||
}
|
||||
|
||||
do_execsql_test 1.6 {
|
||||
SELECT level, segment, nentry, nentrytombstone FROM fts5_structure((
|
||||
SELECT block FROM ft_data WHERE id=10
|
||||
))
|
||||
} {1 0 1 0}
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
reset_db
|
||||
db func document document
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
|
||||
}
|
||||
|
||||
do_test 2.1 {
|
||||
for {set ii 0} {$ii < 5000} {incr ii} {
|
||||
execsql { INSERT INTO ft VALUES( document(12) ) }
|
||||
}
|
||||
} {}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
SELECT sum(nentry) - sum(nentrytombstone) FROM fts5_structure((
|
||||
SELECT block FROM ft_data WHERE id=10
|
||||
))
|
||||
} {5000}
|
||||
|
||||
for {set ii 5000} {$ii >= 0} {incr ii -100} {
|
||||
do_execsql_test 2.3.$ii {
|
||||
DELETE FROM ft WHERE rowid > $ii
|
||||
}
|
||||
do_execsql_test 2.3.$ii.2 {
|
||||
SELECT
|
||||
CAST((total(nentry) - total(nentrytombstone)) AS integer)
|
||||
FROM
|
||||
fts5_structure( (SELECT block FROM ft_data WHERE id=10) )
|
||||
} $ii
|
||||
}
|
||||
|
||||
execsql_pp {
|
||||
SELECT * FROM fts5_structure((
|
||||
SELECT block FROM ft_data WHERE id=10
|
||||
))
|
||||
}
|
||||
|
||||
do_test 2.4 {
|
||||
for {set ii 0} {$ii < 5000} {incr ii} {
|
||||
execsql { INSERT INTO ft VALUES( document(12) ) }
|
||||
}
|
||||
} {}
|
||||
|
||||
for {set ii 1} {$ii <= 5000} {incr ii 10} {
|
||||
do_execsql_test 2.3.$ii {
|
||||
DELETE FROM ft WHERE rowid = $ii;
|
||||
INSERT INTO ft VALUES( document(12) );
|
||||
INSERT INTO ft(ft, rank) VALUES('merge', -10);
|
||||
}
|
||||
|
||||
do_execsql_test 2.3.$ii.2 {
|
||||
SELECT
|
||||
CAST((total(nentry) - total(nentrytombstone)) AS integer)
|
||||
FROM
|
||||
fts5_structure( (SELECT block FROM ft_data WHERE id=10) )
|
||||
} 5000
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
db func document document
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
|
||||
)
|
||||
INSERT INTO ft SELECT document(12) FROM s;
|
||||
}
|
||||
|
||||
do_catchsql_test 3.1 {
|
||||
INSERT INTO ft(ft, rank) VALUES('deletemerge', 'text');
|
||||
} {1 {SQL logic error}}
|
||||
do_catchsql_test 3.2 {
|
||||
INSERT INTO ft(ft, rank) VALUES('deletemerge', 50);
|
||||
} {0 {}}
|
||||
do_execsql_test 3.3 {
|
||||
SELECT * FROM ft_config WHERE k='deletemerge'
|
||||
} {deletemerge 50}
|
||||
do_catchsql_test 3.4 {
|
||||
INSERT INTO ft(ft, rank) VALUES('deletemerge', 101);
|
||||
} {0 {}}
|
||||
do_execsql_test 3.5 {
|
||||
SELECT * FROM ft_config WHERE k='deletemerge'
|
||||
} {deletemerge 101}
|
||||
|
||||
do_execsql_test 3.6 {
|
||||
DELETE FROM ft WHERE rowid<95
|
||||
}
|
||||
|
||||
do_execsql_test 3.7 {
|
||||
SELECT nentrytombstone, nentry FROM fts5_structure((
|
||||
SELECT block FROM ft_data WHERE id=10
|
||||
))
|
||||
} {94 100}
|
||||
|
||||
do_execsql_test 3.8 {
|
||||
DELETE FROM ft WHERE rowid=95
|
||||
}
|
||||
|
||||
do_execsql_test 3.9 {
|
||||
SELECT nentrytombstone, nentry FROM fts5_structure((
|
||||
SELECT block FROM ft_data WHERE id=10
|
||||
))
|
||||
} {95 100}
|
||||
|
||||
do_execsql_test 3.10 {
|
||||
DELETE FROM ft;
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
|
||||
)
|
||||
INSERT INTO ft SELECT document(12) FROM s;
|
||||
INSERT INTO ft(ft, rank) VALUES('deletemerge', 50);
|
||||
}
|
||||
|
||||
do_execsql_test 3.11 {
|
||||
DELETE FROM ft WHERE rowid<95
|
||||
}
|
||||
|
||||
do_execsql_test 3.12 {
|
||||
SELECT nentrytombstone, nentry FROM fts5_structure((
|
||||
SELECT block FROM ft_data WHERE id=10
|
||||
))
|
||||
} {0 6}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
db func document document
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE x1 USING fts5(x, content='', contentless_delete=1);
|
||||
INSERT INTO x1(x1, rank) VALUES('usermerge', 16);
|
||||
INSERT INTO x1(x1, rank) VALUES('deletemerge', 40);
|
||||
INSERT INTO x1 VALUES('one');
|
||||
INSERT INTO x1 VALUES('two');
|
||||
INSERT INTO x1 VALUES('three');
|
||||
INSERT INTO x1 VALUES('four');
|
||||
INSERT INTO x1 VALUES('five');
|
||||
INSERT INTO x1 VALUES('six');
|
||||
INSERT INTO x1 VALUES('seven');
|
||||
INSERT INTO x1 VALUES('eight');
|
||||
INSERT INTO x1 VALUES('nine');
|
||||
INSERT INTO x1 VALUES('ten');
|
||||
}
|
||||
|
||||
do_execsql_test 4.1 {
|
||||
SELECT level, segment FROM fts5_structure((
|
||||
SELECT block FROM x1_data WHERE id=10
|
||||
))
|
||||
} {
|
||||
0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9
|
||||
}
|
||||
|
||||
for {set ii 1} {$ii < 4} {incr ii} {
|
||||
do_execsql_test 4.2.$ii {
|
||||
DELETE FROM x1 WHERE rowid = $ii;
|
||||
INSERT INTO x1(x1, rank) VALUES('merge', 5);
|
||||
SELECT level, segment FROM fts5_structure((
|
||||
SELECT block FROM x1_data WHERE id=10
|
||||
))
|
||||
} {
|
||||
0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9
|
||||
}
|
||||
}
|
||||
|
||||
do_execsql_test 4.3 {
|
||||
DELETE FROM x1 WHERE rowid = $ii;
|
||||
INSERT INTO x1(x1, rank) VALUES('merge', 5);
|
||||
SELECT level, segment, nentry FROM fts5_structure((
|
||||
SELECT block FROM x1_data WHERE id=10
|
||||
))
|
||||
} {
|
||||
1 0 6
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
# 2023 August 7
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file contains tests for the content= and content_rowid= options.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5contentless5
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, content='', contentless_delete=1);
|
||||
INSERT INTO t1 VALUES('A', 'B', 'C');
|
||||
INSERT INTO t1 VALUES('D', 'E', 'F');
|
||||
INSERT INTO t1 VALUES('G', 'H', 'I');
|
||||
}
|
||||
|
||||
do_execsql_test 1.01 {
|
||||
CREATE TABLE t2(x, y);
|
||||
INSERT INTO t2 VALUES('x', 'y');
|
||||
}
|
||||
|
||||
# explain_i "UPDATE t1 SET a='a' WHERE t1.rowid=1"
|
||||
breakpoint
|
||||
explain_i "UPDATE t1 SET a='a' FROM t2 WHERE t1.rowid=1 AND b IS NULL"
|
||||
|
||||
#breakpoint
|
||||
#explain_i "UPDATE t1 SET a='a' WHERE b IS NULL AND rowid=?"
|
||||
|
||||
foreach {tn up err} {
|
||||
1 "UPDATE t1 SET a='a', b='b', c='c' WHERE rowid=1" 0
|
||||
2 "UPDATE t1 SET a='a', b='b' WHERE rowid=1" 1
|
||||
3 "UPDATE t1 SET b='b', c='c' WHERE rowid=1" 1
|
||||
4 "UPDATE t1 SET a='a', c='c' WHERE rowid=1" 1
|
||||
5 "UPDATE t1 SET a='a', c='c' WHERE t1.rowid=1 AND b IS NULL" 1
|
||||
6 "UPDATE t1 SET a='a' FROM t2 WHERE t1.rowid=1" 1
|
||||
7 "UPDATE t1 SET a='a', b='b', c='c' FROM t2 WHERE t1.rowid=1" 0
|
||||
} {
|
||||
|
||||
set res(0) {0 {}}
|
||||
set res(1) {1 {cannot UPDATE a subset of columns on fts5 contentless-delete table: t1}}
|
||||
do_catchsql_test 1.$tn $up $res($err)
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5corrupt5
|
||||
set testprefix fts5corrupt3
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
@@ -793,94 +793,6 @@ do_catchsql_test 4.5 {
|
||||
REPLACE INTO t1(rowid,a,b,rowid) VALUES(200,1,2,3);
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_test 5.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
.open --hexdb
|
||||
| size 28672 pagesize 4096 filename crash-0c6d3451d11597.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07 .....@ ........
|
||||
| 32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 04 ................
|
||||
| 96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d ...............m
|
||||
| 112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00 .....N..........
|
||||
| 3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74 .........1tablet
|
||||
| 3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45 2t2.CREATE TABLE
|
||||
| 3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61 t2(x)V.......ta
|
||||
| 3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 blet1_configt1_c
|
||||
| 3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42 onfig.CREATE TAB
|
||||
| 3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b LE 't1_config'(k
|
||||
| 3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 PRIMARY KEY, v)
|
||||
| 3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05 WITHOUT ROWID[.
|
||||
| 3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64 ..!!...tablet1_d
|
||||
| 3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 ocsizet1_docsize
|
||||
| 3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 .CREATE TABLE 't
|
||||
| 3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 1_docsize'(id IN
|
||||
| 3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 TEGER PRIMARY KE
|
||||
| 3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21 Y, sz BLOB)U...!
|
||||
| 3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65 !.wtablet1_conte
|
||||
| 3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45 ntt1_content.CRE
|
||||
| 3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f ATE TABLE 't1_co
|
||||
| 3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45 ntent'(id INTEGE
|
||||
| 3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63 R PRIMARY KEY, c
|
||||
| 3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65 0)i.......-table
|
||||
| 3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45 t1_idxt1_idx.CRE
|
||||
| 3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64 ATE TABLE 't1_id
|
||||
| 3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 x'(segid, term,
|
||||
| 3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 pgno, PRIMARY KE
|
||||
| 3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 Y(segid, term))
|
||||
| 3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07 WITHOUT ROWIDU..
|
||||
| 3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61 ......tablet1_da
|
||||
| 3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45 tat1_data.CREATE
|
||||
| 3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27 TABLE 't1_data'
|
||||
| 4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d (id INTEGER PRIM
|
||||
| 4016: 41 52 b9 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 AR. KEY, block B
|
||||
| 4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c LOB):......ctabl
|
||||
| 4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54 et1t1CREATE VIRT
|
||||
| 4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49 UAL TABLE t1 USI
|
||||
| 4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29 NG fts5(content)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00 ................
|
||||
| 16: 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80 .............$..
|
||||
| 4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61 ......N.....0aba
|
||||
| 4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64 ck.....ft.....nd
|
||||
| 4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f on..............
|
||||
| 4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 11 ...$............
|
||||
| page 3 offset 8192
|
||||
| 0: 0a 00 00 00 01 0f 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02 ................
|
||||
| page 4 offset 12288
|
||||
| 0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00 ................
|
||||
| 4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00 .....abandon....
|
||||
| 4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b .abaft.....aback
|
||||
| page 5 offset 16384
|
||||
| 0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00 ................
|
||||
| 16: 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03 ................
|
||||
| 4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01 ................
|
||||
| page 6 offset 20480
|
||||
| 0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00 ................
|
||||
| 4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04 ........version.
|
||||
| page 7 offset 24576
|
||||
| 0: 0d 00 00 10 03 0f d6 00 0f f4 10 e1 0f d6 00 00 ................
|
||||
| 16: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 ................
|
||||
| 4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c ..........rebuil
|
||||
| 4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63 d...+integrity-c
|
||||
| 4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 00 00 00 heck....optim...
|
||||
| end crash-0c6d3451d11597.db
|
||||
}]} {}
|
||||
|
||||
do_execsql_test 5.1 {
|
||||
INSERT INTO t1(t1,rank) VALUES('secure-delete',1);
|
||||
}
|
||||
do_catchsql_test 5.4 {
|
||||
UPDATE t1 SET content=randomblob(500);
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
|
||||
sqlite3_fts5_may_be_corrupt 0
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
# 2023 April 30
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5corrupt7
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
sqlite3_fts5_may_be_corrupt 1
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
|
||||
}
|
||||
|
||||
set doc [string repeat "a b " 30]
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
BEGIN;
|
||||
INSERT INTO t1(rowid, x) VALUES(123, $doc);
|
||||
INSERT INTO t1(rowid, x) VALUES(124, $doc);
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
execsql_pp {
|
||||
SELECT id, fts5_decode(id, block), quote(block) FROM t1_data
|
||||
}
|
||||
|
||||
set rows [db eval { SELECT rowid FROM t1_data }]
|
||||
db_save_and_close
|
||||
|
||||
foreach r $rows {
|
||||
db_restore_and_reopen
|
||||
|
||||
proc edit_block {b} {
|
||||
binary scan $b c* in
|
||||
set out [lreplace $in 0 1 255 255]
|
||||
binary format c* $out
|
||||
}
|
||||
db func edit_block edit_block
|
||||
|
||||
do_execsql_test 1.2.$r.1 {
|
||||
UPDATE t1_data SET block = edit_block(block) WHERE rowid=$r;
|
||||
}
|
||||
|
||||
do_execsql_test 1.2.$r.2 {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_test 1.2.$r.3 {
|
||||
catchsql { DELETE FROM t1 WHERE rowid=123; }
|
||||
catchsql { DELETE FROM t1 WHERE rowid=124; }
|
||||
set {} {}
|
||||
} {}
|
||||
|
||||
db close
|
||||
}
|
||||
|
||||
foreach r $rows {
|
||||
set r 137438953475
|
||||
db_restore_and_reopen
|
||||
|
||||
proc edit_block {b} {
|
||||
binary scan $b c* in
|
||||
set out [lreplace $in end end 127]
|
||||
binary format c* $out
|
||||
}
|
||||
db func edit_block edit_block
|
||||
|
||||
do_execsql_test 1.2.$r.1 {
|
||||
UPDATE t1_data SET block = edit_block(block) WHERE rowid=$r;
|
||||
}
|
||||
|
||||
do_execsql_test 1.2.$r.2 {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_test 1.2.$r.3 {
|
||||
catchsql { DELETE FROM t1 WHERE rowid=124; }
|
||||
catchsql { DELETE FROM t1 WHERE rowid=123; }
|
||||
set {} {}
|
||||
} {}
|
||||
|
||||
db close
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x);
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES('abc');
|
||||
INSERT INTO t1 VALUES('b d d d');
|
||||
COMMIT;
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
execsql_pp {
|
||||
SELECT id, quote(block) FROM t1_data
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
SELECT quote(block) FROM t1_data WHERE id > 10;
|
||||
} {X'0000001A04306162630102020101620202020101640206030303040806'}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
UPDATE t1_data SET
|
||||
block=X'0000001A04306162630102025501620202020101640206030303040806'
|
||||
WHERE id>10
|
||||
}
|
||||
|
||||
do_catchsql_test 2.3 {
|
||||
DELETE FROM t1 WHERE rowid = 1
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
finish_test
|
||||
@@ -1,111 +0,0 @@
|
||||
# 2023 July 20
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
# This file is focused on OOM errors. Particularly those that may occur
|
||||
# when using contentless_delete=1 databases.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
source $testdir/malloc_common.tcl
|
||||
set testprefix fts5faultF
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
|
||||
ifcapable !fts5 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
faultsim_save_and_close
|
||||
do_faultsim_test 1 -prep {
|
||||
faultsim_restore_and_reopen
|
||||
} -body {
|
||||
execsql {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x, y, content=, contentless_delete=1)
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {}} {1 {vtable constructor failed: t1}}
|
||||
}
|
||||
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1);
|
||||
BEGIN;
|
||||
INSERT INTO t1(rowid, doc) VALUES(1, 'a b c d');
|
||||
INSERT INTO t1(rowid, doc) VALUES(2, 'a b c d');
|
||||
INSERT INTO t1(rowid, doc) VALUES(3, 'a b c d');
|
||||
INSERT INTO t1(rowid, doc) VALUES(4, 'a b c d');
|
||||
COMMIT;
|
||||
DELETE FROM t1 WHERE rowid IN (2, 4);
|
||||
}
|
||||
|
||||
do_faultsim_test 2 -prep {
|
||||
sqlite3 db test.db
|
||||
execsql { SELECT rowid FROM t1 }
|
||||
} -body {
|
||||
execsql {
|
||||
SELECT rowid FROM t1('b c');
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {1 3}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1);
|
||||
BEGIN;
|
||||
INSERT INTO t1(rowid, doc) VALUES(1, 'a b c d');
|
||||
INSERT INTO t1(rowid, doc) VALUES(2, 'a b c d');
|
||||
INSERT INTO t1(rowid, doc) VALUES(3, 'a b c d');
|
||||
INSERT INTO t1(rowid, doc) VALUES(4, 'a b c d');
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
faultsim_save_and_close
|
||||
do_faultsim_test 3 -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql { SELECT rowid FROM t1 }
|
||||
} -body {
|
||||
execsql {
|
||||
INSERT INTO t1(rowid, doc) VALUES(5, 'a b c d');
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(doc, content=, contentless_delete=1);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
|
||||
)
|
||||
INSERT INTO t1(rowid, doc) SELECT i, 'a b c d' FROM s;
|
||||
}
|
||||
|
||||
do_execsql_test 4.1 { DELETE FROM t1 WHERE rowid <= 25 }
|
||||
|
||||
faultsim_save_and_close
|
||||
do_faultsim_test 4 -faults oom-t* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql { SELECT rowid FROM t1 }
|
||||
} -body {
|
||||
execsql {
|
||||
DELETE FROM t1 WHERE rowid < 100
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
# 2023 May 16
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
set testprefix fts5limits
|
||||
return_if_no_fts5
|
||||
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x);
|
||||
}
|
||||
|
||||
# Default limit for expression depth is 256
|
||||
#
|
||||
foreach {tn nRepeat op bErr} {
|
||||
1 200 AND 0
|
||||
2 200 NOT 0
|
||||
3 200 OR 0
|
||||
|
||||
4 260 AND 0
|
||||
5 260 NOT 1
|
||||
6 260 OR 0
|
||||
} {
|
||||
set L [string repeat "abc " $nRepeat]
|
||||
set Q [join $L " $op "]
|
||||
|
||||
set res {0 {}}
|
||||
if {$bErr} {
|
||||
set res "1 {fts5 expression tree is too large (maximum depth 256)}"
|
||||
}
|
||||
|
||||
do_catchsql_test 1.$tn {
|
||||
SELECT * FROM ft($Q)
|
||||
} $res
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -329,7 +329,7 @@ do_execsql_test 12.3 {
|
||||
reset_db
|
||||
sqlite3_db_config db DEFENSIVE 1
|
||||
|
||||
do_execsql_test 13.1.0 {
|
||||
do_execsql_test 13.0 {
|
||||
CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT);
|
||||
CREATE VIRTUAL TABLE b USING fts5(name);
|
||||
CREATE TRIGGER a_trigger AFTER INSERT ON a BEGIN
|
||||
@@ -337,44 +337,18 @@ do_execsql_test 13.1.0 {
|
||||
END;
|
||||
}
|
||||
|
||||
do_test 13.1.1 {
|
||||
do_test 13.1 {
|
||||
set ::STMT [
|
||||
sqlite3_prepare db "INSERT INTO a VALUES (1, 'foo') RETURNING id;" -1 dummy
|
||||
]
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
|
||||
do_test 13.1.2 {
|
||||
do_test 13.2 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test 13.1.3 {
|
||||
sqlite3_errmsg db
|
||||
} {not an error}
|
||||
|
||||
reset_db
|
||||
sqlite3_db_config db DEFENSIVE 1
|
||||
do_execsql_test 13.2.0 {
|
||||
BEGIN;
|
||||
CREATE TABLE a (id INTEGER PRIMARY KEY, name TEXT);
|
||||
CREATE VIRTUAL TABLE b USING fts5(name);
|
||||
CREATE TRIGGER a_trigger AFTER INSERT ON a BEGIN
|
||||
INSERT INTO b (name) VALUES ('foo');
|
||||
END;
|
||||
}
|
||||
|
||||
do_test 13.2.1 {
|
||||
set ::STMT [
|
||||
sqlite3_prepare db "INSERT INTO a VALUES (1, 'foo') RETURNING id;" -1 dummy
|
||||
]
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
|
||||
do_test 13.2.2 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_test 13.2.3 {
|
||||
do_test 13.3 {
|
||||
sqlite3_errmsg db
|
||||
} {not an error}
|
||||
|
||||
@@ -469,33 +443,5 @@ do_execsql_test -db db2 16.6 {
|
||||
SELECT * FROM x1
|
||||
} {abc def}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 17.1 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(x, tokenize="unicode61 separators 'X'");
|
||||
}
|
||||
do_execsql_test 17.2 {
|
||||
SELECT 0 FROM ft WHERE ft MATCH 'X' AND ft MATCH 'X'
|
||||
}
|
||||
do_execsql_test 17.3 {
|
||||
SELECT 0 FROM ft('X')
|
||||
}
|
||||
|
||||
do_execsql_test 17.4 {
|
||||
CREATE VIRTUAL TABLE t0 USING fts5(c0, t="trigram");
|
||||
INSERT INTO t0 VALUES('assertionfaultproblem');
|
||||
}
|
||||
do_execsql_test 17.5 {
|
||||
SELECT 0 FROM t0(0) WHERE c0 GLOB 0;
|
||||
} {}
|
||||
|
||||
do_execsql_test 17.5 {
|
||||
SELECT c0 FROM t0 WHERE c0 GLOB '*f*';
|
||||
} {assertionfaultproblem}
|
||||
do_execsql_test 17.5 {
|
||||
SELECT c0 FROM t0 WHERE c0 GLOB '*faul*';
|
||||
} {assertionfaultproblem}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -1,278 +0,0 @@
|
||||
# 2023 Feb 17
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
ifcapable !fts5 { finish_test ; return }
|
||||
set ::testprefix fts5secure
|
||||
|
||||
proc dump {tname} {
|
||||
execsql_pp "SELECT * FROM ${tname}_idx"
|
||||
execsql_pp "SELECT id, quote(block), fts5_decode(id,block) FROM ${tname}_data"
|
||||
}
|
||||
|
||||
|
||||
do_execsql_test 0.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(ab);
|
||||
CREATE VIRTUAL TABLE v1 USING fts5vocab('t1', 'instance');
|
||||
INSERT INTO t1(rowid, ab) VALUES
|
||||
(0,'abc'), (1,'abc'), (2,'abc'), (3,'abc'), (4,'def');
|
||||
}
|
||||
|
||||
do_execsql_test 0.1 {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_execsql_test 0.2 {
|
||||
DELETE FROM t1 WHERE rowid=2;
|
||||
}
|
||||
|
||||
do_execsql_test 0.3 {
|
||||
SELECT count(*) FROM t1_data
|
||||
} 3
|
||||
|
||||
do_execsql_test 0.4 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 0.5 {
|
||||
DELETE FROM t1 WHERE rowid=3;
|
||||
}
|
||||
|
||||
do_execsql_test 0.6 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 0.7 {
|
||||
DELETE FROM t1 WHERE rowid=0;
|
||||
}
|
||||
|
||||
do_execsql_test 0.8 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#----------------------------------
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE t2 USING fts5(ab);
|
||||
INSERT INTO t2(rowid, ab) VALUES (5, 'key'), (6, 'value');
|
||||
INSERT INTO t2(t2, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
#execsql_pp { SELECT id, quote(block) FROM t1_data }
|
||||
#execsql_pp { SELECT segid, quote(term), pgno FROM t1_idx }
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
DELETE FROM t2 WHERE rowid = 5;
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
INSERT INTO t2(t2) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
DELETE FROM t2 WHERE rowid = 6;
|
||||
}
|
||||
|
||||
do_execsql_test 1.4 {
|
||||
INSERT INTO t2(t2) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 1.5 {
|
||||
SELECT * FROM t2('value');
|
||||
SELECT * FROM t2('v*');
|
||||
}
|
||||
|
||||
do_execsql_test 1.6 {
|
||||
SELECT * FROM t2('value') ORDER BY rowid DESC;
|
||||
SELECT * FROM t2('v*') ORDER BY rowid DESC;
|
||||
}
|
||||
execsql_pp {
|
||||
SELECT id, quote(block) FROM t2_data;
|
||||
}
|
||||
|
||||
#----------------------------------
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(ab);
|
||||
CREATE VIRTUAL TABLE vocab USING fts5vocab('ft', 'instance');
|
||||
INSERT INTO ft(rowid, ab) VALUES
|
||||
(1, 'one'),
|
||||
(2, 'two'),
|
||||
(3, 'three'),
|
||||
(4, 'four'),
|
||||
(5, 'one one'),
|
||||
(6, 'one two'),
|
||||
(7, 'one three'),
|
||||
(8, 'one four'),
|
||||
(9, 'two one'),
|
||||
(10, 'two two'),
|
||||
(11, 'two three'),
|
||||
(12, 'two four'),
|
||||
(13, 'three one'),
|
||||
(14, 'three two'),
|
||||
(15, 'three three'),
|
||||
(16, 'three four');
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
SELECT count(*) FROM ft_data;
|
||||
} {3}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
INSERT INTO ft(ft, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
DELETE FROM ft WHERE rowid=9;
|
||||
}
|
||||
|
||||
do_execsql_test 2.4 {
|
||||
INSERT INTO ft(ft) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 2.5 {
|
||||
DELETE FROM ft WHERE ab LIKE '%two%'
|
||||
}
|
||||
|
||||
do_execsql_test 2.6 {
|
||||
INSERT INTO ft(ft) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 2.7 {
|
||||
SELECT count(*) FROM ft_data;
|
||||
} {3}
|
||||
|
||||
#----------------------------------
|
||||
reset_db
|
||||
|
||||
set ::vocab {
|
||||
one two three four five six seven eight nine ten
|
||||
eleven twelve thirteen fourteen fifteen sixteen
|
||||
seventeen eighteen nineteen twenty
|
||||
}
|
||||
proc rnddoc {} {
|
||||
set nVocab [llength $::vocab]
|
||||
set ret [list]
|
||||
for {set ii 0} {$ii < 8} {incr ii} {
|
||||
lappend ret [lindex $::vocab [expr int(abs(rand()) * $nVocab)]]
|
||||
}
|
||||
set ret
|
||||
}
|
||||
|
||||
proc contains {list val} {
|
||||
expr {[lsearch $list $val]>=0}
|
||||
}
|
||||
|
||||
foreach {tn pgsz} {
|
||||
2 64
|
||||
1 1000
|
||||
} {
|
||||
reset_db
|
||||
db function rnddoc rnddoc
|
||||
db function contains contains
|
||||
|
||||
expr srand(1)
|
||||
|
||||
do_execsql_test 3.$tn.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', $pgsz);
|
||||
WITH s(i) AS (
|
||||
VALUES(1) UNION SELECT i+1 FROM s WHERE i<20
|
||||
)
|
||||
INSERT INTO t1 SELECT rnddoc() FROM s;
|
||||
}
|
||||
|
||||
do_execsql_test 3.$tn.1 {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
foreach {rowid} {
|
||||
6 16 3 4 9 14 13 7 20 15 19 10 11 2 5 18 17 1 12 8
|
||||
} {
|
||||
|
||||
do_execsql_test 3.$tn.2.$rowid {
|
||||
DELETE FROM t1 WHERE rowid=$rowid;
|
||||
}
|
||||
do_execsql_test 3.$tn.2.$rowid.ic {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
foreach v $::vocab {
|
||||
do_execsql_test 3.$tn.2.$rowid.q.$v {
|
||||
SELECT rowid FROM t1($v)
|
||||
} [db eval {SELECT rowid FROM t1 WHERE contains(x, $v)}]
|
||||
|
||||
do_execsql_test 3.$tn.2.$rowid.q.$v.DESC {
|
||||
SELECT rowid FROM t1($v) ORDER BY 1 DESC
|
||||
} [db eval {SELECT rowid FROM t1 WHERE contains(x, $v) ORDER BY 1 DESC}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_execsql_test 3.3 {
|
||||
INSERT INTO t1(x) VALUES('optimize');
|
||||
INSERT INTO t1(t1) VALUES('optimize');
|
||||
SELECT count(*) FROM t1_data;
|
||||
} {3}
|
||||
|
||||
#----------------------------------
|
||||
reset_db
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
set L1 [string repeat abcdefghij 10]
|
||||
set L2 [string repeat 1234567890 10]
|
||||
|
||||
do_execsql_test 4.1 {
|
||||
INSERT INTO t1 VALUES('aa' || $L1 || ' ' || $L2);
|
||||
}
|
||||
do_execsql_test 4.2 {
|
||||
DELETE FROM t1 WHERE rowid=1
|
||||
}
|
||||
do_execsql_test 4.3 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#----------------------------------
|
||||
reset_db
|
||||
do_execsql_test 5.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
set doc "aa [string repeat {abc } 60]"
|
||||
|
||||
do_execsql_test 5.1 {
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES($doc);
|
||||
INSERT INTO t1 VALUES('aa abc');
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_execsql_test 5.2 {
|
||||
DELETE FROM t1 WHERE rowid = 1;
|
||||
}
|
||||
|
||||
do_execsql_test 5.3 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 5.4 { SELECT rowid FROM t1('abc'); } 2
|
||||
do_execsql_test 5.5 { SELECT rowid FROM t1('aa'); } 2
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
# 2023 Feb 17
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
ifcapable !fts5 { finish_test ; return }
|
||||
set ::testprefix fts5secure2
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(col);
|
||||
INSERT INTO ft VALUES('data for the table');
|
||||
INSERT INTO ft VALUES('more of the same');
|
||||
INSERT INTO ft VALUES('and extra data');
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
SELECT * FROM ft_config
|
||||
} {version 4}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
INSERT INTO ft(ft, rank) VALUES('secure-delete', 1);
|
||||
SELECT * FROM ft_config;
|
||||
} {secure-delete 1 version 4}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
INSERT INTO ft(ft, rank) VALUES('secure-delete', 1);
|
||||
SELECT * FROM ft_config;
|
||||
} {secure-delete 1 version 4}
|
||||
|
||||
do_execsql_test 1.4 {
|
||||
DELETE FROM ft WHERE rowid=2;
|
||||
SELECT * FROM ft_config;
|
||||
} {secure-delete 1 version 5}
|
||||
|
||||
do_execsql_test 1.5 {
|
||||
SELECT rowid, col FROM ft('data');
|
||||
} {1 {data for the table} 3 {and extra data}}
|
||||
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
|
||||
do_execsql_test 1.6 {
|
||||
SELECT rowid, col FROM ft('data');
|
||||
} {1 {data for the table} 3 {and extra data}}
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(col);
|
||||
INSERT INTO ft VALUES('one zero one one zero');
|
||||
INSERT INTO ft(ft, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
SELECT count(*) FROM ft_data WHERE block=X'00000004';
|
||||
} {0}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
UPDATE ft SET col = 'zero one zero zero one' WHERE rowid=1;
|
||||
}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
SELECT count(*) FROM ft_data WHERE block=X'00000004';
|
||||
} {1}
|
||||
|
||||
do_execsql_test 2.4 {
|
||||
INSERT INTO ft VALUES('one zero zero one');
|
||||
DELETE FROM ft WHERE rowid=1;
|
||||
}
|
||||
|
||||
do_execsql_test 2.5 {
|
||||
SELECT count(*) FROM ft_data WHERE block=X'00000004';
|
||||
} {2}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
# 2023 Feb 17
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
# TESTRUNNER: slow
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
ifcapable !fts5 { finish_test ; return }
|
||||
set ::testprefix fts5secure3
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE ft USING fts5(col);
|
||||
INSERT INTO ft VALUES('data for the table');
|
||||
INSERT INTO ft VALUES('more of the same');
|
||||
INSERT INTO ft VALUES('and extra data');
|
||||
|
||||
INSERT INTO ft(ft, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
BEGIN;
|
||||
INSERT INTO ft(rowid, col) VALUES(0, 'the next data');
|
||||
DELETE FROM ft WHERE rowid=1;
|
||||
DELETE FROM ft WHERE rowid=2;
|
||||
INSERT INTO ft(rowid, col) VALUES(6, 'with some more of the same data');
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
INSERT INTO ft(ft) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES('the start');
|
||||
}
|
||||
do_test 2.1 {
|
||||
for {set i 0} {$i < 1000} {incr i} {
|
||||
execsql { INSERT INTO t1 VALUES('the ' || hex(randomblob(3))) }
|
||||
}
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES('the end');
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
DELETE FROM t1 WHERE rowid BETWEEN 2 AND 1000;
|
||||
}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 2.6 {
|
||||
INSERT INTO t1(rowid, x) VALUES(500, 'middle');
|
||||
INSERT INTO t1(rowid, x) VALUES(501, 'value');
|
||||
SELECT * FROM t1('the middle');
|
||||
}
|
||||
|
||||
do_execsql_test 2.7 {
|
||||
INSERT INTO t1(t1) VALUES('optimize');
|
||||
}
|
||||
|
||||
do_execsql_test 2.8 {
|
||||
SELECT count(*) FROM t1_data
|
||||
} 4
|
||||
|
||||
#execsql_pp { SELECT id, quote(block), fts5_decode(id, block) FROM t1_data; }
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Tests with large/small rowid values.
|
||||
#
|
||||
|
||||
reset_db
|
||||
|
||||
expr srand(0)
|
||||
|
||||
set vocab {
|
||||
Popper Poppins Popsicle Porfirio Porrima Porsche
|
||||
Porter Portia Portland Portsmouth Portugal Portuguese
|
||||
Poseidon Post PostgreSQL Potemkin Potomac Potsdam
|
||||
Pottawatomie Potter Potts Pound Poussin Powell
|
||||
PowerPC PowerPoint Powers Powhatan Poznan Prada
|
||||
Prado Praetorian Prague Praia Prakrit Pratchett
|
||||
Pratt Pravda Praxiteles Preakness Precambrian Preminger
|
||||
Premyslid Prensa Prentice Pres Presbyterian Presbyterianism
|
||||
}
|
||||
proc newdoc {} {
|
||||
for {set i 0} {$i<8} {incr i} {
|
||||
lappend ret [lindex $::vocab [expr int(abs(rand()) * [llength $::vocab])]]
|
||||
}
|
||||
set ret
|
||||
}
|
||||
db func newdoc newdoc
|
||||
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE fff USING fts5(y);
|
||||
INSERT INTO fff(fff, rank) VALUES('pgsz', 64);
|
||||
|
||||
WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 )
|
||||
INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s;
|
||||
|
||||
WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 )
|
||||
INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s;
|
||||
|
||||
WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 )
|
||||
INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s;
|
||||
|
||||
INSERT INTO fff(fff, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
proc lshuffle {in} {
|
||||
set out [list]
|
||||
while {[llength $in]>0} {
|
||||
set idx [expr int(abs(rand()) * [llength $in])]
|
||||
lappend out [lindex $in $idx]
|
||||
set in [lreplace $in $idx $idx]
|
||||
}
|
||||
set out
|
||||
}
|
||||
|
||||
#dump fff
|
||||
|
||||
set iTest 1
|
||||
foreach ii [lshuffle [db eval {SELECT rowid FROM fff}]] {
|
||||
#if {$iTest==1} { dump fff }
|
||||
#if {$iTest==1} { breakpoint }
|
||||
do_execsql_test 3.1.$iTest.$ii {
|
||||
DELETE FROM fff WHERE rowid=$ii;
|
||||
}
|
||||
#if {$iTest==1} { dump fff }
|
||||
if {($iTest % 20)==0} {
|
||||
do_execsql_test 3.1.$iTest.$ii.ic {
|
||||
INSERT INTO fff(fff) VALUES('integrity-check');
|
||||
}
|
||||
}
|
||||
#if {$iTest==1} { break }
|
||||
incr iTest
|
||||
}
|
||||
|
||||
#execsql_pp { SELECT rowid FROM fff('post') ORDER BY rowid ASC }
|
||||
#breakpoint
|
||||
#execsql_pp {
|
||||
# SELECT rowid FROM fff('post') ORDER BY rowid DESC
|
||||
#}
|
||||
#
|
||||
#dump fff
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,170 +0,0 @@
|
||||
# 2023 April 14
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
return_if_no_fts5
|
||||
set ::testprefix fts5secure4
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test using the 'delete' command to attempt to delete a token that
|
||||
# is not present in the index in secure-delete mode.
|
||||
#
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(a, b, content=x1);
|
||||
|
||||
CREATE TABLE x1(rowid INTEGER PRIMARY KEY, a, b);
|
||||
INSERT INTO x1 VALUES
|
||||
(1, 'hello world', 'today xyz'),
|
||||
(2, 'not the day', 'crunch crumble and chomp'),
|
||||
(3, 'one', 'two');
|
||||
INSERT INTO t1(t1) VALUES('rebuild');
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 4, 'nosuchtoken', '');
|
||||
}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 1.4 {
|
||||
INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 1, 'crunch', '');
|
||||
}
|
||||
|
||||
do_execsql_test 1.5 {
|
||||
INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 3, 'crunch', '');
|
||||
}
|
||||
|
||||
do_execsql_test 1.6 {
|
||||
INSERT INTO t1(t1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 1.7 {
|
||||
CREATE VIRTUAL TABLE y1 USING fts5(xx, prefix='1,2');
|
||||
INSERT INTO y1(y1, rank) VALUES('pgsz', 64);
|
||||
INSERT INTO y1(y1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
do_execsql_test 1.8 {
|
||||
BEGIN;
|
||||
INSERT INTO y1(rowid, xx) VALUES(1, 'abc def');
|
||||
INSERT INTO y1(rowid, xx) VALUES(2, 'reallyreallylongtoken');
|
||||
COMMIT;
|
||||
}
|
||||
do_execsql_test 1.9 {
|
||||
DELETE FROM y1 WHERE rowid=1;
|
||||
INSERT INTO y1(y1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 1.10 {
|
||||
CREATE VIRTUAL TABLE w1 USING fts5(ww, content="");
|
||||
INSERT INTO w1(rowid, ww) VALUES(123, '');
|
||||
}
|
||||
do_catchsql_test 1.11 {
|
||||
INSERT INTO w1(w1, rowid, ww) VALUES('delete', 123, 'xyz');
|
||||
} {1 {database disk image is malformed}}
|
||||
do_catchsql_test 1.12 {
|
||||
DROP TABLE w1;
|
||||
CREATE VIRTUAL TABLE w1 USING fts5(ww, content="");
|
||||
INSERT INTO w1(rowid, ww) VALUES(123, '');
|
||||
DELETE FROM w1_data WHERE id>10;
|
||||
INSERT INTO w1(w1, rowid, ww) VALUES('delete', 123, 'xyz');
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test using secure-delete with detail=none or detail=col.
|
||||
#
|
||||
foreach {tn d} {1 full 2 none 3 column} {
|
||||
reset_db
|
||||
do_execsql_test 2.$tn.1 "
|
||||
CREATE VIRTUAL TABLE x1 USING fts5(xx, yy, zz, detail=$d, prefix='10,20');
|
||||
INSERT INTO x1(x1, rank) VALUES('pgsz', 64);
|
||||
INSERT INTO x1(x1, rank) VALUES('secure-delete', 1);
|
||||
"
|
||||
|
||||
do_execsql_test 2.$tn.2 {
|
||||
BEGIN;
|
||||
INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
|
||||
INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
|
||||
INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
|
||||
INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
|
||||
INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
|
||||
COMMIT;
|
||||
INSERT INTO x1(x1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 2.$tn.3 {
|
||||
DELETE FROM x1 WHERE rowid IN (2, 4, 6);
|
||||
INSERT INTO x1(x1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 2.$tn.4 {
|
||||
DELETE FROM x1 WHERE rowid IN (1, 3, 5);
|
||||
INSERT INTO x1(x1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
do_execsql_test 2.$tn.5 {
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
|
||||
)
|
||||
INSERT INTO x1
|
||||
SELECT 'seems to be', 'used brew to', 'everything is working' FROM s
|
||||
UNION ALL
|
||||
SELECT 'used brew to', 'everything is working', 'seems to be' FROM s
|
||||
UNION ALL
|
||||
SELECT 'everything is working', 'seems to be', 'used brew to' FROM s
|
||||
UNION ALL
|
||||
SELECT 'abc', 'zzz', 'a b c d'
|
||||
UNION ALL
|
||||
SELECT 'z', 'z', 'z' FROM s
|
||||
}
|
||||
|
||||
do_test 2.$tn.6 {
|
||||
for {set i 300} {$i > 200} {incr i -1} {
|
||||
execsql {
|
||||
DELETE FROM x1 WHERE rowid=$i;
|
||||
INSERT INTO x1(x1) VALUES('integrity-check');
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test 2.$tn.7 {
|
||||
for {set i 1} {$i < 100} {incr i} {
|
||||
execsql {
|
||||
DELETE FROM x1 WHERE rowid=$i;
|
||||
INSERT INTO x1(x1) VALUES('integrity-check');
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
do_test 2.$tn.8 {
|
||||
foreach i [db eval {SELECT rowid FROM x1}] {
|
||||
execsql {
|
||||
DELETE FROM x1 WHERE rowid=$i;
|
||||
INSERT INTO x1(x1) VALUES('integrity-check');
|
||||
}
|
||||
}
|
||||
} {}
|
||||
|
||||
do_execsql_test 2.$tn.9 {
|
||||
SELECT * FROM x1
|
||||
} {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
# 2023 April 14
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
return_if_no_fts5
|
||||
set ::testprefix fts5secure5
|
||||
return_if_no_fts5
|
||||
|
||||
proc dump {} {
|
||||
execsql_pp {
|
||||
SELECT id, quote(block), fts5_decode_none(id, block) FROM ft1_data
|
||||
}
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
|
||||
INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
BEGIN;
|
||||
INSERT INTO ft1(rowid, a) VALUES(1, 'abcd');
|
||||
INSERT INTO ft1(rowid, a) VALUES(2, 'abcd');
|
||||
INSERT INTO ft1(rowid, a) VALUES(3, 'abcd');
|
||||
COMMIT;
|
||||
}
|
||||
do_execsql_test 1.2 {
|
||||
DELETE FROM ft1 WHERE rowid=1;
|
||||
}
|
||||
do_execsql_test 1.3 {
|
||||
INSERT INTO ft1(ft1) VALUES('integrity-check');
|
||||
}
|
||||
do_execsql_test 1.4 {
|
||||
DELETE FROM ft1 WHERE rowid=3;
|
||||
}
|
||||
do_execsql_test 1.5 {
|
||||
INSERT INTO ft1(ft1) VALUES('integrity-check');
|
||||
}
|
||||
do_execsql_test 1.6 {
|
||||
DELETE FROM ft1 WHERE rowid=3;
|
||||
}
|
||||
do_execsql_test 1.7 {
|
||||
INSERT INTO ft1(ft1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
|
||||
INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
BEGIN;
|
||||
INSERT INTO ft1(rowid, a) VALUES(1, 'abcd one');
|
||||
INSERT INTO ft1(rowid, a) VALUES(2, 'abcd two');
|
||||
INSERT INTO ft1(rowid, a) VALUES(3, 'abcd two');
|
||||
INSERT INTO ft1(rowid, a) VALUES(4, 'abcd two');
|
||||
INSERT INTO ft1(rowid, a) VALUES(5, 'abcd three');
|
||||
COMMIT;
|
||||
}
|
||||
|
||||
do_execsql_test 2.2a {
|
||||
DELETE FROM ft1 WHERE rowid=3;
|
||||
}
|
||||
do_execsql_test 2.2b {
|
||||
INSERT INTO ft1(ft1) VALUES('integrity-check');
|
||||
}
|
||||
do_execsql_test 2.3a {
|
||||
DELETE FROM ft1 WHERE rowid=2;
|
||||
}
|
||||
do_execsql_test 2.3b {
|
||||
INSERT INTO ft1(ft1) VALUES('integrity-check');
|
||||
}
|
||||
do_execsql_test 2.4a {
|
||||
DELETE FROM ft1 WHERE rowid=4;
|
||||
}
|
||||
do_execsql_test 2.4b {
|
||||
INSERT INTO ft1(ft1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none, prefix=1);
|
||||
INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
|
||||
INSERT INTO ft1(ft1, rank) VALUES('pgsz', 64);
|
||||
}
|
||||
do_execsql_test 3.1 {
|
||||
BEGIN;
|
||||
INSERT INTO ft1(a) VALUES('c');
|
||||
COMMIT;
|
||||
}
|
||||
do_execsql_test 3.2 {
|
||||
DELETE FROM ft1 WHERE rowid IN (1);
|
||||
INSERT INTO ft1(ft1) VALUES('integrity-check');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
|
||||
INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
|
||||
INSERT INTO ft1(ft1, rank) VALUES('pgsz', 64);
|
||||
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<500
|
||||
)
|
||||
INSERT INTO ft1 SELECT 'abcdefg' FROM s;
|
||||
}
|
||||
|
||||
do_test 4.1 {
|
||||
for {set i 500} {$i > 0} {incr i -1} {
|
||||
execsql { DELETE FROM ft1 WHERE rowid=$i }
|
||||
execsql { INSERT INTO ft1(ft1) VALUES('integrity-check') }
|
||||
}
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
# 2023 Feb 17
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
ifcapable !fts5 { finish_test ; return }
|
||||
set ::testprefix fts5secure6
|
||||
|
||||
db progress 1 progress_handler
|
||||
set ::PHC 0
|
||||
proc progress_handler {args} {
|
||||
incr ::PHC
|
||||
if {($::PHC % 100000)==0} breakpoint
|
||||
return 0
|
||||
}
|
||||
|
||||
proc setup {} {
|
||||
db eval {
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(x);
|
||||
WITH s(i) AS (
|
||||
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000
|
||||
)
|
||||
INSERT INTO t1 SELECT 'a b c d e f g h i j k' FROM s;
|
||||
}
|
||||
}
|
||||
|
||||
foreach {tn sd} {
|
||||
1 0
|
||||
2 1
|
||||
} {
|
||||
setup
|
||||
do_execsql_test 1.$tn.0 {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', $sd)
|
||||
}
|
||||
set PHC 0
|
||||
do_execsql_test 1.$tn.1 { DELETE FROM t1; }
|
||||
set phc($tn) $PHC
|
||||
}
|
||||
|
||||
do_test 1.3 {
|
||||
expr $phc(1)*5 < $phc(2)
|
||||
} {1}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
# 2023 April 14
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is testing the FTS5 module.
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] fts5_common.tcl]
|
||||
source $testdir/malloc_common.tcl
|
||||
set testprefix fts5securefault
|
||||
|
||||
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
|
||||
return_if_no_fts5
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(ab);
|
||||
INSERT INTO t1(rowid, ab) VALUES
|
||||
(0, 'abc'), (1, 'abc'), (2, 'abc'), (3, 'abc'), (4, 'def');
|
||||
}
|
||||
faultsim_save_and_close
|
||||
|
||||
do_faultsim_test 1.1 -faults oom* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
} -body {
|
||||
execsql { DELETE FROM t1 WHERE rowid=2 }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
do_faultsim_test 1.2 -faults oom* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
} -body {
|
||||
execsql { DELETE FROM t1 WHERE rowid IN(0, 1, 2, 3, 4) }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
set big [string repeat abcdefghij 5]
|
||||
set big2 [string repeat klmnopqrst 5]
|
||||
set doc "$big $big2"
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(ab);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<4
|
||||
)
|
||||
INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s;
|
||||
}
|
||||
faultsim_save_and_close
|
||||
|
||||
do_faultsim_test 2.1 -faults oom* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
} -body {
|
||||
execsql { DELETE FROM t1 WHERE rowid = 3 }
|
||||
execsql { DELETE FROM t1 WHERE rowid = 4 }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
set big [string repeat abcdefghij 5]
|
||||
set big2 [string repeat klmnopqrst 5]
|
||||
set doc "$big $big2"
|
||||
|
||||
do_execsql_test 3.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(ab);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
|
||||
WITH s(i) AS (
|
||||
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<25
|
||||
)
|
||||
INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s;
|
||||
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
DELETE FROM t1 WHERE rowid BETWEEN 3 AND 23;
|
||||
}
|
||||
faultsim_save_and_close
|
||||
|
||||
do_faultsim_test 3.1 -faults oom* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
} -body {
|
||||
execsql { DELETE FROM t1 WHERE rowid = 24 }
|
||||
execsql { DELETE FROM t1 WHERE rowid = 25 }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
set doc [string repeat "tok " 400]
|
||||
|
||||
do_execsql_test 4.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(ab);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
|
||||
INSERT INTO t1(rowid, ab) VALUES(1, $doc), (2, $doc), (3, $doc);
|
||||
}
|
||||
faultsim_save_and_close
|
||||
|
||||
do_faultsim_test 4.1 -faults oom* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
} -body {
|
||||
execsql { DELETE FROM t1 WHERE rowid = 2 }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
|
||||
set doc1 [string repeat "abc " 10]
|
||||
set doc2 [string repeat "def " 10]
|
||||
|
||||
do_test 5.0 {
|
||||
execsql {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(ab);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
|
||||
BEGIN;
|
||||
}
|
||||
for {set i 0} {$i < 50} {incr i} {
|
||||
execsql {
|
||||
INSERT INTO t1(rowid, ab) VALUES($i, 'abcdefg');
|
||||
}
|
||||
}
|
||||
execsql {
|
||||
INSERT INTO t1(rowid, ab) VALUES(105, 'def');
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
faultsim_save_and_close
|
||||
|
||||
do_faultsim_test 5.1 -faults oom* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
} -body {
|
||||
execsql { DELETE FROM t1 WHERE rowid = 105 }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_test 6.0 {
|
||||
execsql {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(ab);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
|
||||
BEGIN;
|
||||
INSERT INTO t1(rowid, ab) VALUES(1, 'abcdefg');
|
||||
INSERT INTO t1(rowid, ab) VALUES(2, 'abcdefg');
|
||||
INSERT INTO t1(rowid, ab) VALUES(3, 'abcdefg');
|
||||
COMMIT;
|
||||
}
|
||||
} {}
|
||||
faultsim_save_and_close
|
||||
|
||||
do_faultsim_test 6.1 -faults oom* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
execsql {
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
} -body {
|
||||
execsql {
|
||||
UPDATE t1 SET ab='abcdefg' WHERE rowid=2;
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_test 7.0 {
|
||||
execsql {
|
||||
CREATE VIRTUAL TABLE t1 USING fts5(ab);
|
||||
INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
|
||||
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
|
||||
}
|
||||
} {}
|
||||
faultsim_save_and_close
|
||||
|
||||
do_faultsim_test 7.1 -faults oom* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
set big1 "[string repeat x 50] [string repeat y 50] [string repeat z 50]"
|
||||
execsql {
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES($big1);
|
||||
}
|
||||
} -body {
|
||||
execsql { COMMIT }
|
||||
} -test {
|
||||
faultsim_test_result {0 {}}
|
||||
}
|
||||
|
||||
|
||||
finish_test
|
||||
@@ -38,20 +38,20 @@ do_execsql_test 1.3 {
|
||||
|
||||
sqlite3_db_config db DEFENSIVE 0
|
||||
do_execsql_test 1.4 {
|
||||
UPDATE t1_config set v=6 WHERE k='version';
|
||||
UPDATE t1_config set v=5 WHERE k='version';
|
||||
}
|
||||
|
||||
do_test 1.5 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' }
|
||||
} {1 {invalid fts5 file format (found 6, expected 4 or 5) - run 'rebuild'}}
|
||||
} {1 {invalid fts5 file format (found 5, expected 4) - run 'rebuild'}}
|
||||
|
||||
do_test 1.6 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
catchsql { INSERT INTO t1 VALUES('x y z') }
|
||||
} {1 {invalid fts5 file format (found 6, expected 4 or 5) - run 'rebuild'}}
|
||||
} {1 {invalid fts5 file format (found 5, expected 4) - run 'rebuild'}}
|
||||
|
||||
do_test 1.7 {
|
||||
sqlite3_db_config db DEFENSIVE 0
|
||||
@@ -59,75 +59,7 @@ do_test 1.7 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' }
|
||||
} {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}}
|
||||
|
||||
do_test 1.8 {
|
||||
sqlite3_db_config db DEFENSIVE 0
|
||||
execsql { INSERT INTO t1_config VALUES('version', 4) }
|
||||
execsql { INSERT INTO t1(t1, rank) VALUES('secure-delete', 1) }
|
||||
} {}
|
||||
|
||||
do_execsql_test 1.10 {
|
||||
SELECT * FROM t1_config
|
||||
} {secure-delete 1 version 4}
|
||||
|
||||
do_execsql_test 1.11 {
|
||||
INSERT INTO t1(rowid, one) VALUES(123, 'one two three');
|
||||
DELETE FROM t1 WHERE rowid=123;
|
||||
SELECT * FROM t1_config
|
||||
} {secure-delete 1 version 5}
|
||||
|
||||
do_execsql_test 1.11 {
|
||||
INSERT INTO t1(t1) VALUES('rebuild');
|
||||
SELECT * FROM t1_config
|
||||
} {secure-delete 1 version 4}
|
||||
|
||||
do_execsql_test 1.12 {
|
||||
SELECT * FROM t1_config
|
||||
} {secure-delete 1 version 4}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
CREATE VIRTUAL TABLE xyz USING fts5(x);
|
||||
INSERT INTO xyz(rowid, x) VALUES
|
||||
(1, 'one document'),
|
||||
(2, 'two document'),
|
||||
(3, 'three document'),
|
||||
(4, 'four document'),
|
||||
(5, 'five document'),
|
||||
(6, 'six document');
|
||||
|
||||
INSERT INTO xyz(xyz, rank) VALUES('secure-delete', 1);
|
||||
SELECT v FROM xyz_config WHERE k='version';
|
||||
} {4}
|
||||
|
||||
do_execsql_test 2.1 {
|
||||
BEGIN;
|
||||
INSERT INTO xyz(rowid, x) VALUES(7, 'seven document');
|
||||
SAVEPOINT one;
|
||||
DELETE FROM xyz WHERE rowid = 4;
|
||||
}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
SELECT v FROM xyz_config WHERE k='version';
|
||||
} {5}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
ROLLBACK TO one;
|
||||
SELECT v FROM xyz_config WHERE k='version';
|
||||
} {4}
|
||||
|
||||
|
||||
do_execsql_test 2.4 {
|
||||
DELETE FROM xyz WHERE rowid = 3;
|
||||
COMMIT;
|
||||
SELECT v FROM xyz_config WHERE k='version';
|
||||
} {5}
|
||||
|
||||
|
||||
} {1 {invalid fts5 file format (found 0, expected 4) - run 'rebuild'}}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
Regular → Executable
+5
-20
@@ -76,7 +76,6 @@ typedef unsigned char u8;
|
||||
#define U8_TYPEDEF
|
||||
#endif
|
||||
|
||||
/* Decoding table, ASCII (7-bit) value to base 64 digit value or other */
|
||||
static const u8 b64DigitValues[128] = {
|
||||
/* HT LF VT FF CR */
|
||||
ND,ND,ND,ND, ND,ND,ND,ND, ND,WS,WS,WS, WS,WS,ND,ND,
|
||||
@@ -148,9 +147,9 @@ static char* toBase64( u8 *pIn, int nbIn, char *pOut ){
|
||||
}
|
||||
|
||||
/* Skip over text which is not base64 numeral(s). */
|
||||
static char * skipNonB64( char *s, int nc ){
|
||||
static char * skipNonB64( char *s ){
|
||||
char c;
|
||||
while( nc-- > 0 && (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
|
||||
while( (c = *s) && !IS_BX_DIGIT(BX_DV_PROTO(c)) ) ++s;
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -159,7 +158,7 @@ static u8* fromBase64( char *pIn, int ncIn, u8 *pOut ){
|
||||
if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
|
||||
while( ncIn>0 && *pIn!=PAD_CHAR ){
|
||||
static signed char nboi[] = { 0, 0, 1, 2, 3 };
|
||||
char *pUse = skipNonB64(pIn, ncIn);
|
||||
char *pUse = skipNonB64(pIn);
|
||||
unsigned long qv = 0L;
|
||||
int nti, nbo, nac;
|
||||
ncIn -= (pUse - pIn);
|
||||
@@ -219,16 +218,9 @@ static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
|
||||
sqlite3_result_error(context, "blob expanded to base64 too big", -1);
|
||||
return;
|
||||
}
|
||||
bBuf = (u8*)sqlite3_value_blob(av[0]);
|
||||
if( !bBuf ){
|
||||
if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
|
||||
goto memFail;
|
||||
}
|
||||
sqlite3_result_text(context,"",-1,SQLITE_STATIC);
|
||||
break;
|
||||
}
|
||||
cBuf = sqlite3_malloc(nc);
|
||||
if( !cBuf ) goto memFail;
|
||||
bBuf = (u8*)sqlite3_value_blob(av[0]);
|
||||
nc = (int)(toBase64(bBuf, nb, cBuf) - cBuf);
|
||||
sqlite3_result_text(context, cBuf, nc, sqlite3_free);
|
||||
break;
|
||||
@@ -241,16 +233,9 @@ static void base64(sqlite3_context *context, int na, sqlite3_value *av[]){
|
||||
}else if( nb<1 ){
|
||||
nb = 1;
|
||||
}
|
||||
cBuf = (char *)sqlite3_value_text(av[0]);
|
||||
if( !cBuf ){
|
||||
if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
|
||||
goto memFail;
|
||||
}
|
||||
sqlite3_result_zeroblob(context, 0);
|
||||
break;
|
||||
}
|
||||
bBuf = sqlite3_malloc(nb);
|
||||
if( !bBuf ) goto memFail;
|
||||
cBuf = (char *)sqlite3_value_text(av[0]);
|
||||
nb = (int)(fromBase64(cBuf, nc, bBuf) - bBuf);
|
||||
sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
|
||||
break;
|
||||
|
||||
+5
-19
@@ -140,9 +140,9 @@ static u8 base85DigitValue( char c ){
|
||||
#define B85_DARK_MAX 80
|
||||
|
||||
|
||||
static char * skipNonB85( char *s, int nc ){
|
||||
static char * skipNonB85( char *s ){
|
||||
char c;
|
||||
while( nc-- > 0 && (c = *s) && !IS_B85(c) ) ++s;
|
||||
while( (c = *s) && !IS_B85(c) ) ++s;
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ static u8* fromBase85( char *pIn, int ncIn, u8 *pOut ){
|
||||
if( ncIn>0 && pIn[ncIn-1]=='\n' ) --ncIn;
|
||||
while( ncIn>0 ){
|
||||
static signed char nboi[] = { 0, 0, 1, 2, 3, 4 };
|
||||
char *pUse = skipNonB85(pIn, ncIn);
|
||||
char *pUse = skipNonB85(pIn);
|
||||
unsigned long qv = 0L;
|
||||
int nti, nbo;
|
||||
ncIn -= (pUse - pIn);
|
||||
@@ -297,16 +297,9 @@ static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
|
||||
sqlite3_result_error(context, "blob expanded to base85 too big", -1);
|
||||
return;
|
||||
}
|
||||
bBuf = (u8*)sqlite3_value_blob(av[0]);
|
||||
if( !bBuf ){
|
||||
if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
|
||||
goto memFail;
|
||||
}
|
||||
sqlite3_result_text(context,"",-1,SQLITE_STATIC);
|
||||
break;
|
||||
}
|
||||
cBuf = sqlite3_malloc(nc);
|
||||
if( !cBuf ) goto memFail;
|
||||
bBuf = (u8*)sqlite3_value_blob(av[0]);
|
||||
nc = (int)(toBase85(bBuf, nb, cBuf, "\n") - cBuf);
|
||||
sqlite3_result_text(context, cBuf, nc, sqlite3_free);
|
||||
break;
|
||||
@@ -319,16 +312,9 @@ static void base85(sqlite3_context *context, int na, sqlite3_value *av[]){
|
||||
}else if( nb<1 ){
|
||||
nb = 1;
|
||||
}
|
||||
cBuf = (char *)sqlite3_value_text(av[0]);
|
||||
if( !cBuf ){
|
||||
if( SQLITE_NOMEM==sqlite3_errcode(sqlite3_context_db_handle(context)) ){
|
||||
goto memFail;
|
||||
}
|
||||
sqlite3_result_zeroblob(context, 0);
|
||||
break;
|
||||
}
|
||||
bBuf = sqlite3_malloc(nb);
|
||||
if( !bBuf ) goto memFail;
|
||||
cBuf = (char *)sqlite3_value_text(av[0]);
|
||||
nb = (int)(fromBase85(cBuf, nc, bBuf) - bBuf);
|
||||
sqlite3_result_blob(context, bBuf, nb, sqlite3_free);
|
||||
break;
|
||||
|
||||
+2
-5
@@ -69,12 +69,9 @@ __declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_basexx_init(sqlite3 *db, char **pzErr,
|
||||
const sqlite3_api_routines *pApi){
|
||||
int rc1;
|
||||
int rc2;
|
||||
|
||||
init_api_ptr(pApi);
|
||||
rc1 = BASE64_INIT(db);
|
||||
rc2 = BASE85_INIT(db);
|
||||
int rc1 = BASE64_INIT(db);
|
||||
int rc2 = BASE85_INIT(db);
|
||||
|
||||
if( rc1==SQLITE_OK && rc2==SQLITE_OK ){
|
||||
BASE64_EXPOSE(db, pzErr);
|
||||
|
||||
+96
-345
@@ -58,24 +58,41 @@ static void decimal_free(Decimal *p){
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate a new Decimal object initialized to the text in zIn[].
|
||||
** Return NULL if any kind of error occurs.
|
||||
** Allocate a new Decimal object. Initialize it to the number given
|
||||
** by the input string.
|
||||
*/
|
||||
static Decimal *decimalNewFromText(const char *zIn, int n){
|
||||
Decimal *p = 0;
|
||||
int i;
|
||||
static Decimal *decimal_new(
|
||||
sqlite3_context *pCtx,
|
||||
sqlite3_value *pIn,
|
||||
int nAlt,
|
||||
const unsigned char *zAlt
|
||||
){
|
||||
Decimal *p;
|
||||
int n, i;
|
||||
const unsigned char *zIn;
|
||||
int iExp = 0;
|
||||
|
||||
p = sqlite3_malloc( sizeof(*p) );
|
||||
if( p==0 ) goto new_from_text_failed;
|
||||
if( p==0 ) goto new_no_mem;
|
||||
p->sign = 0;
|
||||
p->oom = 0;
|
||||
p->isInit = 1;
|
||||
p->isNull = 0;
|
||||
p->nDigit = 0;
|
||||
p->nFrac = 0;
|
||||
if( zAlt ){
|
||||
n = nAlt,
|
||||
zIn = zAlt;
|
||||
}else{
|
||||
if( sqlite3_value_type(pIn)==SQLITE_NULL ){
|
||||
p->a = 0;
|
||||
p->isNull = 1;
|
||||
return p;
|
||||
}
|
||||
n = sqlite3_value_bytes(pIn);
|
||||
zIn = sqlite3_value_text(pIn);
|
||||
}
|
||||
p->a = sqlite3_malloc64( n+1 );
|
||||
if( p->a==0 ) goto new_from_text_failed;
|
||||
if( p->a==0 ) goto new_no_mem;
|
||||
for(i=0; isspace(zIn[i]); i++){}
|
||||
if( zIn[i]=='-' ){
|
||||
p->sign = 1;
|
||||
@@ -126,7 +143,7 @@ static Decimal *decimalNewFromText(const char *zIn, int n){
|
||||
}
|
||||
if( iExp>0 ){
|
||||
p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
|
||||
if( p->a==0 ) goto new_from_text_failed;
|
||||
if( p->a==0 ) goto new_no_mem;
|
||||
memset(p->a+p->nDigit, 0, iExp);
|
||||
p->nDigit += iExp;
|
||||
}
|
||||
@@ -145,7 +162,7 @@ static Decimal *decimalNewFromText(const char *zIn, int n){
|
||||
}
|
||||
if( iExp>0 ){
|
||||
p->a = sqlite3_realloc64(p->a, p->nDigit + iExp + 1 );
|
||||
if( p->a==0 ) goto new_from_text_failed;
|
||||
if( p->a==0 ) goto new_no_mem;
|
||||
memmove(p->a+iExp, p->a, p->nDigit);
|
||||
memset(p->a, 0, iExp);
|
||||
p->nDigit += iExp;
|
||||
@@ -154,76 +171,7 @@ static Decimal *decimalNewFromText(const char *zIn, int n){
|
||||
}
|
||||
return p;
|
||||
|
||||
new_from_text_failed:
|
||||
if( p ){
|
||||
if( p->a ) sqlite3_free(p->a);
|
||||
sqlite3_free(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Forward reference */
|
||||
static Decimal *decimalFromDouble(double);
|
||||
|
||||
/*
|
||||
** Allocate a new Decimal object from an sqlite3_value. Return a pointer
|
||||
** to the new object, or NULL if there is an error. If the pCtx argument
|
||||
** is not NULL, then errors are reported on it as well.
|
||||
**
|
||||
** If the pIn argument is SQLITE_TEXT or SQLITE_INTEGER, it is converted
|
||||
** directly into a Decimal. For SQLITE_FLOAT or for SQLITE_BLOB of length
|
||||
** 8 bytes, the resulting double value is expanded into its decimal equivalent.
|
||||
** If pIn is NULL or if it is a BLOB that is not exactly 8 bytes in length,
|
||||
** then NULL is returned.
|
||||
*/
|
||||
static Decimal *decimal_new(
|
||||
sqlite3_context *pCtx, /* Report error here, if not null */
|
||||
sqlite3_value *pIn, /* Construct the decimal object from this */
|
||||
int bTextOnly /* Always interpret pIn as text if true */
|
||||
){
|
||||
Decimal *p = 0;
|
||||
int eType = sqlite3_value_type(pIn);
|
||||
if( bTextOnly && (eType==SQLITE_FLOAT || eType==SQLITE_BLOB) ){
|
||||
eType = SQLITE_TEXT;
|
||||
}
|
||||
switch( eType ){
|
||||
case SQLITE_TEXT:
|
||||
case SQLITE_INTEGER: {
|
||||
const char *zIn = (const char*)sqlite3_value_text(pIn);
|
||||
int n = sqlite3_value_bytes(pIn);
|
||||
p = decimalNewFromText(zIn, n);
|
||||
if( p==0 ) goto new_failed;
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_FLOAT: {
|
||||
p = decimalFromDouble(sqlite3_value_double(pIn));
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_BLOB: {
|
||||
const unsigned char *x;
|
||||
unsigned int i;
|
||||
sqlite3_uint64 v = 0;
|
||||
double r;
|
||||
|
||||
if( sqlite3_value_bytes(pIn)!=sizeof(r) ) break;
|
||||
x = sqlite3_value_blob(pIn);
|
||||
for(i=0; i<sizeof(r); i++){
|
||||
v = (v<<8) | x[i];
|
||||
}
|
||||
memcpy(&r, &v, sizeof(r));
|
||||
p = decimalFromDouble(r);
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_NULL: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
|
||||
new_failed:
|
||||
new_no_mem:
|
||||
if( pCtx ) sqlite3_result_error_nomem(pCtx);
|
||||
sqlite3_free(p);
|
||||
return 0;
|
||||
@@ -283,64 +231,19 @@ static void decimal_result(sqlite3_context *pCtx, Decimal *p){
|
||||
}
|
||||
|
||||
/*
|
||||
** Make the given Decimal the result in an format similar to '%+#e'.
|
||||
** In other words, show exponential notation with leading and trailing
|
||||
** zeros omitted.
|
||||
** SQL Function: decimal(X)
|
||||
**
|
||||
** Convert input X into decimal and then back into text
|
||||
*/
|
||||
static void decimal_result_sci(sqlite3_context *pCtx, Decimal *p){
|
||||
char *z; /* The output buffer */
|
||||
int i; /* Loop counter */
|
||||
int nZero; /* Number of leading zeros */
|
||||
int nDigit; /* Number of digits not counting trailing zeros */
|
||||
int nFrac; /* Digits to the right of the decimal point */
|
||||
int exp; /* Exponent value */
|
||||
signed char zero; /* Zero value */
|
||||
signed char *a; /* Array of digits */
|
||||
|
||||
if( p==0 || p->oom ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return;
|
||||
}
|
||||
if( p->isNull ){
|
||||
sqlite3_result_null(pCtx);
|
||||
return;
|
||||
}
|
||||
for(nDigit=p->nDigit; nDigit>0 && p->a[nDigit-1]==0; nDigit--){}
|
||||
for(nZero=0; nZero<nDigit && p->a[nZero]==0; nZero++){}
|
||||
nFrac = p->nFrac + (nDigit - p->nDigit);
|
||||
nDigit -= nZero;
|
||||
z = sqlite3_malloc( nDigit+20 );
|
||||
if( z==0 ){
|
||||
sqlite3_result_error_nomem(pCtx);
|
||||
return;
|
||||
}
|
||||
if( nDigit==0 ){
|
||||
zero = 0;
|
||||
a = &zero;
|
||||
nDigit = 1;
|
||||
nFrac = 0;
|
||||
}else{
|
||||
a = &p->a[nZero];
|
||||
}
|
||||
if( p->sign && nDigit>0 ){
|
||||
z[0] = '-';
|
||||
}else{
|
||||
z[0] = '+';
|
||||
}
|
||||
z[1] = a[0]+'0';
|
||||
z[2] = '.';
|
||||
if( nDigit==1 ){
|
||||
z[3] = '0';
|
||||
i = 4;
|
||||
}else{
|
||||
for(i=1; i<nDigit; i++){
|
||||
z[2+i] = a[i]+'0';
|
||||
}
|
||||
i = nDigit+2;
|
||||
}
|
||||
exp = nDigit - nFrac - 1;
|
||||
sqlite3_snprintf(nDigit+20-i, &z[i], "e%+03d", exp);
|
||||
sqlite3_result_text(pCtx, z, -1, sqlite3_free);
|
||||
static void decimalFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
Decimal *p = decimal_new(context, argv[0], 0, 0);
|
||||
UNUSED_PARAMETER(argc);
|
||||
decimal_result(context, p);
|
||||
decimal_free(p);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -393,9 +296,9 @@ static void decimalCmpFunc(
|
||||
int rc;
|
||||
|
||||
UNUSED_PARAMETER(argc);
|
||||
pA = decimal_new(context, argv[0], 1);
|
||||
pA = decimal_new(context, argv[0], 0, 0);
|
||||
if( pA==0 || pA->isNull ) goto cmp_done;
|
||||
pB = decimal_new(context, argv[1], 1);
|
||||
pB = decimal_new(context, argv[1], 0, 0);
|
||||
if( pB==0 || pB->isNull ) goto cmp_done;
|
||||
rc = decimal_cmp(pA, pB);
|
||||
if( rc<0 ) rc = -1;
|
||||
@@ -435,7 +338,7 @@ static void decimal_expand(Decimal *p, int nDigit, int nFrac){
|
||||
}
|
||||
|
||||
/*
|
||||
** Add the value pB into pA. A := A + B.
|
||||
** Add the value pB into pA.
|
||||
**
|
||||
** Both pA and pB might become denormalized by this routine.
|
||||
*/
|
||||
@@ -504,172 +407,6 @@ static void decimal_add(Decimal *pA, Decimal *pB){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Multiply A by B. A := A * B
|
||||
**
|
||||
** All significant digits after the decimal point are retained.
|
||||
** Trailing zeros after the decimal point are omitted as long as
|
||||
** the number of digits after the decimal point is no less than
|
||||
** either the number of digits in either input.
|
||||
*/
|
||||
static void decimalMul(Decimal *pA, Decimal *pB){
|
||||
signed char *acc = 0;
|
||||
int i, j, k;
|
||||
int minFrac;
|
||||
|
||||
if( pA==0 || pA->oom || pA->isNull
|
||||
|| pB==0 || pB->oom || pB->isNull
|
||||
){
|
||||
goto mul_end;
|
||||
}
|
||||
acc = sqlite3_malloc64( pA->nDigit + pB->nDigit + 2 );
|
||||
if( acc==0 ){
|
||||
pA->oom = 1;
|
||||
goto mul_end;
|
||||
}
|
||||
memset(acc, 0, pA->nDigit + pB->nDigit + 2);
|
||||
minFrac = pA->nFrac;
|
||||
if( pB->nFrac<minFrac ) minFrac = pB->nFrac;
|
||||
for(i=pA->nDigit-1; i>=0; i--){
|
||||
signed char f = pA->a[i];
|
||||
int carry = 0, x;
|
||||
for(j=pB->nDigit-1, k=i+j+3; j>=0; j--, k--){
|
||||
x = acc[k] + f*pB->a[j] + carry;
|
||||
acc[k] = x%10;
|
||||
carry = x/10;
|
||||
}
|
||||
x = acc[k] + carry;
|
||||
acc[k] = x%10;
|
||||
acc[k-1] += x/10;
|
||||
}
|
||||
sqlite3_free(pA->a);
|
||||
pA->a = acc;
|
||||
acc = 0;
|
||||
pA->nDigit += pB->nDigit + 2;
|
||||
pA->nFrac += pB->nFrac;
|
||||
pA->sign ^= pB->sign;
|
||||
while( pA->nFrac>minFrac && pA->a[pA->nDigit-1]==0 ){
|
||||
pA->nFrac--;
|
||||
pA->nDigit--;
|
||||
}
|
||||
|
||||
mul_end:
|
||||
sqlite3_free(acc);
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new Decimal object that contains an integer power of 2.
|
||||
*/
|
||||
static Decimal *decimalPow2(int N){
|
||||
Decimal *pA = 0; /* The result to be returned */
|
||||
Decimal *pX = 0; /* Multiplier */
|
||||
if( N<-20000 || N>20000 ) goto pow2_fault;
|
||||
pA = decimalNewFromText("1.0", 3);
|
||||
if( pA==0 || pA->oom ) goto pow2_fault;
|
||||
if( N==0 ) return pA;
|
||||
if( N>0 ){
|
||||
pX = decimalNewFromText("2.0", 3);
|
||||
}else{
|
||||
N = -N;
|
||||
pX = decimalNewFromText("0.5", 3);
|
||||
}
|
||||
if( pX==0 || pX->oom ) goto pow2_fault;
|
||||
while( 1 /* Exit by break */ ){
|
||||
if( N & 1 ){
|
||||
decimalMul(pA, pX);
|
||||
if( pA->oom ) goto pow2_fault;
|
||||
}
|
||||
N >>= 1;
|
||||
if( N==0 ) break;
|
||||
decimalMul(pX, pX);
|
||||
}
|
||||
decimal_free(pX);
|
||||
return pA;
|
||||
|
||||
pow2_fault:
|
||||
decimal_free(pA);
|
||||
decimal_free(pX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Use an IEEE754 binary64 ("double") to generate a new Decimal object.
|
||||
*/
|
||||
static Decimal *decimalFromDouble(double r){
|
||||
sqlite3_int64 m, a;
|
||||
int e;
|
||||
int isNeg;
|
||||
Decimal *pA;
|
||||
Decimal *pX;
|
||||
char zNum[100];
|
||||
if( r<0.0 ){
|
||||
isNeg = 1;
|
||||
r = -r;
|
||||
}else{
|
||||
isNeg = 0;
|
||||
}
|
||||
memcpy(&a,&r,sizeof(a));
|
||||
if( a==0 ){
|
||||
e = 0;
|
||||
m = 0;
|
||||
}else{
|
||||
e = a>>52;
|
||||
m = a & ((((sqlite3_int64)1)<<52)-1);
|
||||
if( e==0 ){
|
||||
m <<= 1;
|
||||
}else{
|
||||
m |= ((sqlite3_int64)1)<<52;
|
||||
}
|
||||
while( e<1075 && m>0 && (m&1)==0 ){
|
||||
m >>= 1;
|
||||
e++;
|
||||
}
|
||||
if( isNeg ) m = -m;
|
||||
e = e - 1075;
|
||||
if( e>971 ){
|
||||
return 0; /* A NaN or an Infinity */
|
||||
}
|
||||
}
|
||||
|
||||
/* At this point m is the integer significand and e is the exponent */
|
||||
sqlite3_snprintf(sizeof(zNum), zNum, "%lld", m);
|
||||
pA = decimalNewFromText(zNum, (int)strlen(zNum));
|
||||
pX = decimalPow2(e);
|
||||
decimalMul(pA, pX);
|
||||
decimal_free(pX);
|
||||
return pA;
|
||||
}
|
||||
|
||||
/*
|
||||
** SQL Function: decimal(X)
|
||||
** OR: decimal_sci(X)
|
||||
**
|
||||
** Convert input X into decimal and then back into text.
|
||||
**
|
||||
** If X is originally a float, then a full decimal expansion of that floating
|
||||
** point value is done. Or if X is an 8-byte blob, it is interpreted
|
||||
** as a float and similarly expanded.
|
||||
**
|
||||
** The decimal_sci(X) function returns the result in scientific notation.
|
||||
** decimal(X) returns a complete decimal, without the e+NNN at the end.
|
||||
*/
|
||||
static void decimalFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
Decimal *p = decimal_new(context, argv[0], 0);
|
||||
UNUSED_PARAMETER(argc);
|
||||
if( p ){
|
||||
if( sqlite3_user_data(context)!=0 ){
|
||||
decimal_result_sci(context, p);
|
||||
}else{
|
||||
decimal_result(context, p);
|
||||
}
|
||||
decimal_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Compare text in decimal order.
|
||||
*/
|
||||
@@ -680,8 +417,8 @@ static int decimalCollFunc(
|
||||
){
|
||||
const unsigned char *zA = (const unsigned char*)pKey1;
|
||||
const unsigned char *zB = (const unsigned char*)pKey2;
|
||||
Decimal *pA = decimalNewFromText((const char*)zA, nKey1);
|
||||
Decimal *pB = decimalNewFromText((const char*)zB, nKey2);
|
||||
Decimal *pA = decimal_new(0, 0, nKey1, zA);
|
||||
Decimal *pB = decimal_new(0, 0, nKey2, zB);
|
||||
int rc;
|
||||
UNUSED_PARAMETER(notUsed);
|
||||
if( pA==0 || pB==0 ){
|
||||
@@ -706,8 +443,8 @@ static void decimalAddFunc(
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
Decimal *pA = decimal_new(context, argv[0], 1);
|
||||
Decimal *pB = decimal_new(context, argv[1], 1);
|
||||
Decimal *pA = decimal_new(context, argv[0], 0, 0);
|
||||
Decimal *pB = decimal_new(context, argv[1], 0, 0);
|
||||
UNUSED_PARAMETER(argc);
|
||||
decimal_add(pA, pB);
|
||||
decimal_result(context, pA);
|
||||
@@ -719,8 +456,8 @@ static void decimalSubFunc(
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
Decimal *pA = decimal_new(context, argv[0], 1);
|
||||
Decimal *pB = decimal_new(context, argv[1], 1);
|
||||
Decimal *pA = decimal_new(context, argv[0], 0, 0);
|
||||
Decimal *pB = decimal_new(context, argv[1], 0, 0);
|
||||
UNUSED_PARAMETER(argc);
|
||||
if( pB ){
|
||||
pB->sign = !pB->sign;
|
||||
@@ -758,7 +495,7 @@ static void decimalSumStep(
|
||||
p->nFrac = 0;
|
||||
}
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
pArg = decimal_new(context, argv[0], 1);
|
||||
pArg = decimal_new(context, argv[0], 0, 0);
|
||||
decimal_add(p, pArg);
|
||||
decimal_free(pArg);
|
||||
}
|
||||
@@ -773,7 +510,7 @@ static void decimalSumInverse(
|
||||
p = sqlite3_aggregate_context(context, sizeof(*p));
|
||||
if( p==0 ) return;
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
pArg = decimal_new(context, argv[0], 1);
|
||||
pArg = decimal_new(context, argv[0], 0, 0);
|
||||
if( pArg ) pArg->sign = !pArg->sign;
|
||||
decimal_add(p, pArg);
|
||||
decimal_free(pArg);
|
||||
@@ -794,49 +531,66 @@ static void decimalSumFinalize(sqlite3_context *context){
|
||||
** SQL Function: decimal_mul(X, Y)
|
||||
**
|
||||
** Return the product of X and Y.
|
||||
**
|
||||
** All significant digits after the decimal point are retained.
|
||||
** Trailing zeros after the decimal point are omitted as long as
|
||||
** the number of digits after the decimal point is no less than
|
||||
** either the number of digits in either input.
|
||||
*/
|
||||
static void decimalMulFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
Decimal *pA = decimal_new(context, argv[0], 1);
|
||||
Decimal *pB = decimal_new(context, argv[1], 1);
|
||||
Decimal *pA = decimal_new(context, argv[0], 0, 0);
|
||||
Decimal *pB = decimal_new(context, argv[1], 0, 0);
|
||||
signed char *acc = 0;
|
||||
int i, j, k;
|
||||
int minFrac;
|
||||
UNUSED_PARAMETER(argc);
|
||||
if( pA==0 || pA->oom || pA->isNull
|
||||
|| pB==0 || pB->oom || pB->isNull
|
||||
){
|
||||
goto mul_end;
|
||||
}
|
||||
decimalMul(pA, pB);
|
||||
if( pA->oom ){
|
||||
acc = sqlite3_malloc64( pA->nDigit + pB->nDigit + 2 );
|
||||
if( acc==0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
goto mul_end;
|
||||
}
|
||||
memset(acc, 0, pA->nDigit + pB->nDigit + 2);
|
||||
minFrac = pA->nFrac;
|
||||
if( pB->nFrac<minFrac ) minFrac = pB->nFrac;
|
||||
for(i=pA->nDigit-1; i>=0; i--){
|
||||
signed char f = pA->a[i];
|
||||
int carry = 0, x;
|
||||
for(j=pB->nDigit-1, k=i+j+3; j>=0; j--, k--){
|
||||
x = acc[k] + f*pB->a[j] + carry;
|
||||
acc[k] = x%10;
|
||||
carry = x/10;
|
||||
}
|
||||
x = acc[k] + carry;
|
||||
acc[k] = x%10;
|
||||
acc[k-1] += x/10;
|
||||
}
|
||||
sqlite3_free(pA->a);
|
||||
pA->a = acc;
|
||||
acc = 0;
|
||||
pA->nDigit += pB->nDigit + 2;
|
||||
pA->nFrac += pB->nFrac;
|
||||
pA->sign ^= pB->sign;
|
||||
while( pA->nFrac>minFrac && pA->a[pA->nDigit-1]==0 ){
|
||||
pA->nFrac--;
|
||||
pA->nDigit--;
|
||||
}
|
||||
decimal_result(context, pA);
|
||||
|
||||
mul_end:
|
||||
sqlite3_free(acc);
|
||||
decimal_free(pA);
|
||||
decimal_free(pB);
|
||||
}
|
||||
|
||||
/*
|
||||
** SQL Function: decimal_pow2(N)
|
||||
**
|
||||
** Return the N-th power of 2. N must be an integer.
|
||||
*/
|
||||
static void decimalPow2Func(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
UNUSED_PARAMETER(argc);
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){
|
||||
Decimal *pA = decimalPow2(sqlite3_value_int(argv[0]));
|
||||
decimal_result_sci(context, pA);
|
||||
decimal_free(pA);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
@@ -849,16 +603,13 @@ int sqlite3_decimal_init(
|
||||
static const struct {
|
||||
const char *zFuncName;
|
||||
int nArg;
|
||||
int iArg;
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
|
||||
} aFunc[] = {
|
||||
{ "decimal", 1, 0, decimalFunc },
|
||||
{ "decimal_sci", 1, 1, decimalFunc },
|
||||
{ "decimal_cmp", 2, 0, decimalCmpFunc },
|
||||
{ "decimal_add", 2, 0, decimalAddFunc },
|
||||
{ "decimal_sub", 2, 0, decimalSubFunc },
|
||||
{ "decimal_mul", 2, 0, decimalMulFunc },
|
||||
{ "decimal_pow2", 1, 0, decimalPow2Func },
|
||||
{ "decimal", 1, decimalFunc },
|
||||
{ "decimal_cmp", 2, decimalCmpFunc },
|
||||
{ "decimal_add", 2, decimalAddFunc },
|
||||
{ "decimal_sub", 2, decimalSubFunc },
|
||||
{ "decimal_mul", 2, decimalMulFunc },
|
||||
};
|
||||
unsigned int i;
|
||||
(void)pzErrMsg; /* Unused parameter */
|
||||
@@ -868,7 +619,7 @@ int sqlite3_decimal_init(
|
||||
for(i=0; i<(int)(sizeof(aFunc)/sizeof(aFunc[0])) && rc==SQLITE_OK; i++){
|
||||
rc = sqlite3_create_function(db, aFunc[i].zFuncName, aFunc[i].nArg,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
aFunc[i].iArg ? db : 0, aFunc[i].xFunc, 0, 0);
|
||||
0, aFunc[i].xFunc, 0, 0);
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_window_function(db, "decimal_sum", 1,
|
||||
|
||||
+1
-32
@@ -256,37 +256,6 @@ static void ieee754func_to_blob(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** SQL Function: ieee754_inc(r,N)
|
||||
**
|
||||
** Move the floating point value r by N quantums and return the new
|
||||
** values.
|
||||
**
|
||||
** Behind the scenes: this routine merely casts r into a 64-bit unsigned
|
||||
** integer, adds N, then casts the value back into float.
|
||||
**
|
||||
** Example: To find the smallest positive number:
|
||||
**
|
||||
** SELECT ieee754_inc(0.0,+1);
|
||||
*/
|
||||
static void ieee754inc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
double r;
|
||||
sqlite3_int64 N;
|
||||
sqlite3_uint64 m1, m2;
|
||||
double r2;
|
||||
UNUSED_PARAMETER(argc);
|
||||
r = sqlite3_value_double(argv[0]);
|
||||
N = sqlite3_value_int64(argv[1]);
|
||||
memcpy(&m1, &r, 8);
|
||||
m2 = m1 + N;
|
||||
memcpy(&r2, &m2, 8);
|
||||
sqlite3_result_double(context, r2);
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
@@ -308,7 +277,7 @@ int sqlite3_ieee_init(
|
||||
{ "ieee754_exponent", 1, 2, ieee754func },
|
||||
{ "ieee754_to_blob", 1, 0, ieee754func_to_blob },
|
||||
{ "ieee754_from_blob", 1, 0, ieee754func_from_blob },
|
||||
{ "ieee754_inc", 2, 0, ieee754inc },
|
||||
|
||||
};
|
||||
unsigned int i;
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
** 2023-06-21
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** This file implements an extension that uses the SQLITE_CONFIG_PCACHE2
|
||||
** mechanism to add a tracing layer on top of pluggable page cache of
|
||||
** SQLite. If this extension is registered prior to sqlite3_initialize(),
|
||||
** it will cause all page cache activities to be logged on standard output,
|
||||
** or to some other FILE specified by the initializer.
|
||||
**
|
||||
** This file needs to be compiled into the application that uses it.
|
||||
**
|
||||
** This extension is used to implement the --pcachetrace option of the
|
||||
** command-line shell.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* The original page cache routines */
|
||||
static sqlite3_pcache_methods2 pcacheBase;
|
||||
static FILE *pcachetraceOut;
|
||||
|
||||
/* Methods that trace pcache activity */
|
||||
static int pcachetraceInit(void *pArg){
|
||||
int nRes;
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xInit(%p)\n", pArg);
|
||||
}
|
||||
nRes = pcacheBase.xInit(pArg);
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xInit(%p) -> %d\n", pArg, nRes);
|
||||
}
|
||||
return nRes;
|
||||
}
|
||||
static void pcachetraceShutdown(void *pArg){
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xShutdown(%p)\n", pArg);
|
||||
}
|
||||
pcacheBase.xShutdown(pArg);
|
||||
}
|
||||
static sqlite3_pcache *pcachetraceCreate(int szPage, int szExtra, int bPurge){
|
||||
sqlite3_pcache *pRes;
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xCreate(%d,%d,%d)\n",
|
||||
szPage, szExtra, bPurge);
|
||||
}
|
||||
pRes = pcacheBase.xCreate(szPage, szExtra, bPurge);
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xCreate(%d,%d,%d) -> %p\n",
|
||||
szPage, szExtra, bPurge, pRes);
|
||||
}
|
||||
return pRes;
|
||||
}
|
||||
static void pcachetraceCachesize(sqlite3_pcache *p, int nCachesize){
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xCachesize(%p, %d)\n", p, nCachesize);
|
||||
}
|
||||
pcacheBase.xCachesize(p, nCachesize);
|
||||
}
|
||||
static int pcachetracePagecount(sqlite3_pcache *p){
|
||||
int nRes;
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xPagecount(%p)\n", p);
|
||||
}
|
||||
nRes = pcacheBase.xPagecount(p);
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xPagecount(%p) -> %d\n", p, nRes);
|
||||
}
|
||||
return nRes;
|
||||
}
|
||||
static sqlite3_pcache_page *pcachetraceFetch(
|
||||
sqlite3_pcache *p,
|
||||
unsigned key,
|
||||
int crFg
|
||||
){
|
||||
sqlite3_pcache_page *pRes;
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xFetch(%p,%u,%d)\n", p, key, crFg);
|
||||
}
|
||||
pRes = pcacheBase.xFetch(p, key, crFg);
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xFetch(%p,%u,%d) -> %p\n",
|
||||
p, key, crFg, pRes);
|
||||
}
|
||||
return pRes;
|
||||
}
|
||||
static void pcachetraceUnpin(
|
||||
sqlite3_pcache *p,
|
||||
sqlite3_pcache_page *pPg,
|
||||
int bDiscard
|
||||
){
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xUnpin(%p, %p, %d)\n",
|
||||
p, pPg, bDiscard);
|
||||
}
|
||||
pcacheBase.xUnpin(p, pPg, bDiscard);
|
||||
}
|
||||
static void pcachetraceRekey(
|
||||
sqlite3_pcache *p,
|
||||
sqlite3_pcache_page *pPg,
|
||||
unsigned oldKey,
|
||||
unsigned newKey
|
||||
){
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xRekey(%p, %p, %u, %u)\n",
|
||||
p, pPg, oldKey, newKey);
|
||||
}
|
||||
pcacheBase.xRekey(p, pPg, oldKey, newKey);
|
||||
}
|
||||
static void pcachetraceTruncate(sqlite3_pcache *p, unsigned n){
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xTruncate(%p, %u)\n", p, n);
|
||||
}
|
||||
pcacheBase.xTruncate(p, n);
|
||||
}
|
||||
static void pcachetraceDestroy(sqlite3_pcache *p){
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xDestroy(%p)\n", p);
|
||||
}
|
||||
pcacheBase.xDestroy(p);
|
||||
}
|
||||
static void pcachetraceShrink(sqlite3_pcache *p){
|
||||
if( pcachetraceOut ){
|
||||
fprintf(pcachetraceOut, "PCACHETRACE: xShrink(%p)\n", p);
|
||||
}
|
||||
pcacheBase.xShrink(p);
|
||||
}
|
||||
|
||||
/* The substitute pcache methods */
|
||||
static sqlite3_pcache_methods2 ersaztPcacheMethods = {
|
||||
0,
|
||||
0,
|
||||
pcachetraceInit,
|
||||
pcachetraceShutdown,
|
||||
pcachetraceCreate,
|
||||
pcachetraceCachesize,
|
||||
pcachetracePagecount,
|
||||
pcachetraceFetch,
|
||||
pcachetraceUnpin,
|
||||
pcachetraceRekey,
|
||||
pcachetraceTruncate,
|
||||
pcachetraceDestroy,
|
||||
pcachetraceShrink
|
||||
};
|
||||
|
||||
/* Begin tracing memory allocations to out. */
|
||||
int sqlite3PcacheTraceActivate(FILE *out){
|
||||
int rc = SQLITE_OK;
|
||||
if( pcacheBase.xFetch==0 ){
|
||||
rc = sqlite3_config(SQLITE_CONFIG_GETPCACHE2, &pcacheBase);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_config(SQLITE_CONFIG_PCACHE2, &ersaztPcacheMethods);
|
||||
}
|
||||
}
|
||||
pcachetraceOut = out;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Deactivate memory tracing */
|
||||
int sqlite3PcacheTraceDeactivate(void){
|
||||
int rc = SQLITE_OK;
|
||||
if( pcacheBase.xFetch!=0 ){
|
||||
rc = sqlite3_config(SQLITE_CONFIG_PCACHE2, &pcacheBase);
|
||||
if( rc==SQLITE_OK ){
|
||||
memset(&pcacheBase, 0, sizeof(pcacheBase));
|
||||
}
|
||||
}
|
||||
pcachetraceOut = 0;
|
||||
return rc;
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
** 2023-04-28
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This SQLite extension implements a the random_json(SEED) and
|
||||
** random_json5(SEED) functions. Given a numeric SEED value, these
|
||||
** routines generate pseudo-random JSON or JSON5, respectively. The
|
||||
** same value is always generated for the same seed.
|
||||
**
|
||||
** These SQL functions are intended for testing. They do not have any
|
||||
** practical real-world use, that we know of.
|
||||
**
|
||||
** COMPILE:
|
||||
**
|
||||
** gcc --shared -fPIC -o randomjson.so -I. ext/misc/randomjson.c
|
||||
**
|
||||
** USING FROM THE CLI:
|
||||
**
|
||||
** .load ./randomjson
|
||||
** SELECT random_json(1);
|
||||
*/
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Pseudo-random number generator */
|
||||
typedef struct Prng {
|
||||
unsigned int x, y;
|
||||
} Prng;
|
||||
|
||||
/* Reseed the PRNG */
|
||||
static void prngSeed(Prng *p, unsigned int iSeed){
|
||||
p->x = iSeed | 1;
|
||||
p->y = iSeed;
|
||||
}
|
||||
|
||||
/* Extract a random number */
|
||||
static unsigned int prngInt(Prng *p){
|
||||
p->x = (p->x>>1) ^ ((1+~(p->x&1)) & 0xd0000001);
|
||||
p->y = p->y*1103515245 + 12345;
|
||||
return p->x ^ p->y;
|
||||
}
|
||||
|
||||
static const char *azJsonAtoms[] = {
|
||||
/* JSON /* JSON-5 */
|
||||
"0", "0",
|
||||
"1", "1",
|
||||
"-1", "-1",
|
||||
"2", "+2",
|
||||
"3", "3",
|
||||
"2.5", "2.5",
|
||||
"0.75", ".75",
|
||||
"-4.0e2", "-4.e2",
|
||||
"5.0e-3", "+5e-3",
|
||||
"0", "0x0",
|
||||
"512", "0x200",
|
||||
"256", "+0x100",
|
||||
"-2748", "-0xabc",
|
||||
"true", "true",
|
||||
"false", "false",
|
||||
"null", "null",
|
||||
"9.0e999", "Infinity",
|
||||
"-9.0e999", "-Infinity",
|
||||
"9.0e999", "+Infinity",
|
||||
"null", "NaN",
|
||||
"-0.0005123", "-0.0005123",
|
||||
"4.35e-3", "+4.35e-3",
|
||||
"\"gem\\\"hay\"", "\"gem\\\"hay\"",
|
||||
"\"icy'joy\"", "'icy\\'joy\'",
|
||||
"\"keylog\"", "\"key\\\nlog\"",
|
||||
"\"mix\\\\\\tnet\"", "\"mix\\\\\\tnet\"",
|
||||
"{}", "{}",
|
||||
"[]", "[]",
|
||||
"[]", "[/*empty*/]",
|
||||
"{}", "{//empty\n}",
|
||||
"\"ask\"", "\"ask\"",
|
||||
"\"bag\"", "\"bag\"",
|
||||
"\"can\"", "\"can\"",
|
||||
"\"day\"", "\"day\"",
|
||||
"\"end\"", "'end'",
|
||||
"\"fly\"", "\"fly\"",
|
||||
"\"\"", "\"\"",
|
||||
};
|
||||
static const char *azJsonTemplate[] = {
|
||||
/* JSON JSON-5 */
|
||||
"{\"a\":%,\"b\":%,\"c\":%}", "{a:%,b:%,c:%}",
|
||||
"{\"a\":%,\"b\":%,\"c\":%,\"d\":%,\"e\":%}", "{a:%,b:%,c:%,d:%,e:%}",
|
||||
"{\"a\":%,\"b\":%,\"c\":%,\"d\":%,\"\":%}", "{a:%,b:%,c:%,d:%,\"\":%}",
|
||||
"{\"d\":%}", "{d:%}",
|
||||
"{\"eeee\":%, \"ffff\":%}", "{eeee:% /*and*/, ffff:%}",
|
||||
"{\"$g\":%,\"_h_\":%}", "{$g:%,_h_:%,}",
|
||||
"{\"x\":%,\n \"y\":%}", "{\"x\":%,\n \"y\":%}",
|
||||
"{\"a b c d\":%,\"e\":%,\"f\":%,\"x\":%,\"y\":%}",
|
||||
"{\"a b c d\":%,e:%,f:%,x:%,y:%}",
|
||||
"{\"Z\":%}", "{Z:%,}",
|
||||
"[%]", "[%,]",
|
||||
"[%,%]", "[%,%]",
|
||||
"[%,%,%]", "[%,%,%,]",
|
||||
"[%,%,%,%]", "[%,%,%,%]",
|
||||
"[%,%,%,%,%]", "[%,%,%,%,%]",
|
||||
};
|
||||
|
||||
#define count(X) (sizeof(X)/sizeof(X[0]))
|
||||
|
||||
#define STRSZ 10000
|
||||
|
||||
static void jsonExpand(
|
||||
const char *zSrc,
|
||||
char *zDest,
|
||||
Prng *p,
|
||||
int eType, /* 0 for JSON, 1 for JSON5 */
|
||||
unsigned int r /* Growth probability 0..1000. 0 means no growth */
|
||||
){
|
||||
unsigned int i, j, k;
|
||||
const char *z;
|
||||
size_t n;
|
||||
|
||||
j = 0;
|
||||
if( zSrc==0 ){
|
||||
k = prngInt(p)%(count(azJsonTemplate)/2);
|
||||
k = k*2 + eType;
|
||||
zSrc = azJsonTemplate[k];
|
||||
}
|
||||
if( strlen(zSrc)>=STRSZ/10 ) r = 0;
|
||||
for(i=0; zSrc[i]; i++){
|
||||
if( zSrc[i]!='%' ){
|
||||
if( j<STRSZ ) zDest[j++] = zSrc[i];
|
||||
continue;
|
||||
}
|
||||
if( r==0 || (r<1000 && (prngInt(p)%1000)<=r) ){
|
||||
/* Fill in without values without any new % */
|
||||
k = prngInt(p)%(count(azJsonAtoms)/2);
|
||||
k = k*2 + eType;
|
||||
z = azJsonAtoms[k];
|
||||
}else{
|
||||
/* Add new % terms */
|
||||
k = prngInt(p)%(count(azJsonTemplate)/2);
|
||||
k = k*2 + eType;
|
||||
z = azJsonTemplate[k];
|
||||
}
|
||||
n = strlen(z);
|
||||
if( j+n<STRSZ ){
|
||||
memcpy(&zDest[j], z, n);
|
||||
j += n;
|
||||
}
|
||||
}
|
||||
zDest[STRSZ-1] = 0;
|
||||
if( j<STRSZ ) zDest[j] = 0;
|
||||
}
|
||||
|
||||
static void randJsonFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
unsigned int iSeed;
|
||||
int eType = *(int*)sqlite3_user_data(context);
|
||||
Prng prng;
|
||||
char z1[STRSZ+1], z2[STRSZ+1];
|
||||
|
||||
iSeed = (unsigned int)sqlite3_value_int(argv[0]);
|
||||
prngSeed(&prng, iSeed);
|
||||
jsonExpand(0, z2, &prng, eType, 1000);
|
||||
jsonExpand(z2, z1, &prng, eType, 1000);
|
||||
jsonExpand(z1, z2, &prng, eType, 100);
|
||||
jsonExpand(z2, z1, &prng, eType, 0);
|
||||
sqlite3_result_text(context, z1, -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_randomjson_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
static int cOne = 1;
|
||||
static int cZero = 0;
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg; /* Unused parameter */
|
||||
rc = sqlite3_create_function(db, "random_json", 1,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
&cZero, randJsonFunc, 0, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_create_function(db, "random_json5", 1,
|
||||
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
|
||||
&cOne, randJsonFunc, 0, 0);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
+2
-2
@@ -595,7 +595,7 @@ static const char *re_subcompile_string(ReCompiled *p){
|
||||
break;
|
||||
}
|
||||
case '[': {
|
||||
unsigned int iFirst = p->nState;
|
||||
int iFirst = p->nState;
|
||||
if( rePeek(p)=='^' ){
|
||||
re_append(p, RE_OP_CC_EXC, 0);
|
||||
p->sIn.i++;
|
||||
@@ -619,7 +619,7 @@ static const char *re_subcompile_string(ReCompiled *p){
|
||||
if( rePeek(p)==']' ){ p->sIn.i++; break; }
|
||||
}
|
||||
if( c==0 ) return "unclosed '['";
|
||||
if( p->nState>iFirst ) p->aArg[iFirst] = p->nState - iFirst;
|
||||
p->aArg[iFirst] = p->nState - iFirst;
|
||||
break;
|
||||
}
|
||||
case '\\': {
|
||||
|
||||
+50
-175
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** 2015-08-18, 2023-04-28
|
||||
** 2015-08-18
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
@@ -12,19 +12,7 @@
|
||||
**
|
||||
** This file demonstrates how to create a table-valued-function using
|
||||
** a virtual table. This demo implements the generate_series() function
|
||||
** which gives the same results as the eponymous function in PostgreSQL,
|
||||
** within the limitation that its arguments are signed 64-bit integers.
|
||||
**
|
||||
** Considering its equivalents to generate_series(start,stop,step): A
|
||||
** value V[n] sequence is produced for integer n ascending from 0 where
|
||||
** ( V[n] == start + n * step && sgn(V[n] - stop) * sgn(step) >= 0 )
|
||||
** for each produced value (independent of production time ordering.)
|
||||
**
|
||||
** All parameters must be either integer or convertable to integer.
|
||||
** The start parameter is required.
|
||||
** The stop parameter defaults to (1<<32)-1 (aka 4294967295 or 0xffffffff)
|
||||
** The step parameter defaults to 1 and 0 is treated as 1.
|
||||
**
|
||||
** which gives similar results to the eponymous function in PostgreSQL.
|
||||
** Examples:
|
||||
**
|
||||
** SELECT * FROM generate_series(0,100,5);
|
||||
@@ -40,14 +28,6 @@
|
||||
**
|
||||
** Integers 20 through 29.
|
||||
**
|
||||
** SELECT * FROM generate_series(0,-100,-5);
|
||||
**
|
||||
** Integers 0 -5 -10 ... -100.
|
||||
**
|
||||
** SELECT * FROM generate_series(0,-1);
|
||||
**
|
||||
** Empty sequence.
|
||||
**
|
||||
** HOW IT WORKS
|
||||
**
|
||||
** The generate_series "function" is really a virtual table with the
|
||||
@@ -60,9 +40,6 @@
|
||||
** step HIDDEN
|
||||
** );
|
||||
**
|
||||
** The virtual table also has a rowid, logically equivalent to n+1 where
|
||||
** "n" is the ascending integer in the aforesaid production definition.
|
||||
**
|
||||
** Function arguments in queries against this virtual table are translated
|
||||
** into equality constraints against successive hidden columns. In other
|
||||
** words, the following pairs of queries are equivalent to each other:
|
||||
@@ -95,126 +72,9 @@
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
/*
|
||||
** Return that member of a generate_series(...) sequence whose 0-based
|
||||
** index is ix. The 0th member is given by smBase. The sequence members
|
||||
** progress per ix increment by smStep.
|
||||
*/
|
||||
static sqlite3_int64 genSeqMember(sqlite3_int64 smBase,
|
||||
sqlite3_int64 smStep,
|
||||
sqlite3_uint64 ix){
|
||||
if( ix>=(sqlite3_uint64)LLONG_MAX ){
|
||||
/* Get ix into signed i64 range. */
|
||||
ix -= (sqlite3_uint64)LLONG_MAX;
|
||||
/* With 2's complement ALU, this next can be 1 step, but is split into
|
||||
* 2 for UBSAN's satisfaction (and hypothetical 1's complement ALUs.) */
|
||||
smBase += (LLONG_MAX/2) * smStep;
|
||||
smBase += (LLONG_MAX - LLONG_MAX/2) * smStep;
|
||||
}
|
||||
/* Under UBSAN (or on 1's complement machines), must do this last term
|
||||
* in steps to avoid the dreaded (and harmless) signed multiply overlow. */
|
||||
if( ix>=2 ){
|
||||
sqlite3_int64 ix2 = (sqlite3_int64)ix/2;
|
||||
smBase += ix2*smStep;
|
||||
ix -= ix2;
|
||||
}
|
||||
return smBase + ((sqlite3_int64)ix)*smStep;
|
||||
}
|
||||
|
||||
typedef unsigned char u8;
|
||||
|
||||
typedef struct SequenceSpec {
|
||||
sqlite3_int64 iBase; /* Starting value ("start") */
|
||||
sqlite3_int64 iTerm; /* Given terminal value ("stop") */
|
||||
sqlite3_int64 iStep; /* Increment ("step") */
|
||||
sqlite3_uint64 uSeqIndexMax; /* maximum sequence index (aka "n") */
|
||||
sqlite3_uint64 uSeqIndexNow; /* Current index during generation */
|
||||
sqlite3_int64 iValueNow; /* Current value during generation */
|
||||
u8 isNotEOF; /* Sequence generation not exhausted */
|
||||
u8 isReversing; /* Sequence is being reverse generated */
|
||||
} SequenceSpec;
|
||||
|
||||
/*
|
||||
** Prepare a SequenceSpec for use in generating an integer series
|
||||
** given initialized iBase, iTerm and iStep values. Sequence is
|
||||
** initialized per given isReversing. Other members are computed.
|
||||
*/
|
||||
static void setupSequence( SequenceSpec *pss ){
|
||||
int bSameSigns;
|
||||
pss->uSeqIndexMax = 0;
|
||||
pss->isNotEOF = 0;
|
||||
bSameSigns = (pss->iBase < 0)==(pss->iTerm < 0);
|
||||
if( pss->iTerm < pss->iBase ){
|
||||
sqlite3_uint64 nuspan = 0;
|
||||
if( bSameSigns ){
|
||||
nuspan = (sqlite3_uint64)(pss->iBase - pss->iTerm);
|
||||
}else{
|
||||
/* Under UBSAN (or on 1's complement machines), must do this in steps.
|
||||
* In this clause, iBase>=0 and iTerm<0 . */
|
||||
nuspan = 1;
|
||||
nuspan += pss->iBase;
|
||||
nuspan += -(pss->iTerm+1);
|
||||
}
|
||||
if( pss->iStep<0 ){
|
||||
pss->isNotEOF = 1;
|
||||
if( nuspan==ULONG_MAX ){
|
||||
pss->uSeqIndexMax = ( pss->iStep>LLONG_MIN )? nuspan/-pss->iStep : 1;
|
||||
}else if( pss->iStep>LLONG_MIN ){
|
||||
pss->uSeqIndexMax = nuspan/-pss->iStep;
|
||||
}
|
||||
}
|
||||
}else if( pss->iTerm > pss->iBase ){
|
||||
sqlite3_uint64 puspan = 0;
|
||||
if( bSameSigns ){
|
||||
puspan = (sqlite3_uint64)(pss->iTerm - pss->iBase);
|
||||
}else{
|
||||
/* Under UBSAN (or on 1's complement machines), must do this in steps.
|
||||
* In this clause, iTerm>=0 and iBase<0 . */
|
||||
puspan = 1;
|
||||
puspan += pss->iTerm;
|
||||
puspan += -(pss->iBase+1);
|
||||
}
|
||||
if( pss->iStep>0 ){
|
||||
pss->isNotEOF = 1;
|
||||
pss->uSeqIndexMax = puspan/pss->iStep;
|
||||
}
|
||||
}else if( pss->iTerm == pss->iBase ){
|
||||
pss->isNotEOF = 1;
|
||||
pss->uSeqIndexMax = 0;
|
||||
}
|
||||
pss->uSeqIndexNow = (pss->isReversing)? pss->uSeqIndexMax : 0;
|
||||
pss->iValueNow = (pss->isReversing)
|
||||
? genSeqMember(pss->iBase, pss->iStep, pss->uSeqIndexMax)
|
||||
: pss->iBase;
|
||||
}
|
||||
|
||||
/*
|
||||
** Progress sequence generator to yield next value, if any.
|
||||
** Leave its state to either yield next value or be at EOF.
|
||||
** Return whether there is a next value, or 0 at EOF.
|
||||
*/
|
||||
static int progressSequence( SequenceSpec *pss ){
|
||||
if( !pss->isNotEOF ) return 0;
|
||||
if( pss->isReversing ){
|
||||
if( pss->uSeqIndexNow > 0 ){
|
||||
pss->uSeqIndexNow--;
|
||||
pss->iValueNow -= pss->iStep;
|
||||
}else{
|
||||
pss->isNotEOF = 0;
|
||||
}
|
||||
}else{
|
||||
if( pss->uSeqIndexNow < pss->uSeqIndexMax ){
|
||||
pss->uSeqIndexNow++;
|
||||
pss->iValueNow += pss->iStep;
|
||||
}else{
|
||||
pss->isNotEOF = 0;
|
||||
}
|
||||
}
|
||||
return pss->isNotEOF;
|
||||
}
|
||||
|
||||
/* series_cursor is a subclass of sqlite3_vtab_cursor which will
|
||||
** serve as the underlying representation of a cursor that scans
|
||||
@@ -223,7 +83,12 @@ static int progressSequence( SequenceSpec *pss ){
|
||||
typedef struct series_cursor series_cursor;
|
||||
struct series_cursor {
|
||||
sqlite3_vtab_cursor base; /* Base class - must be first */
|
||||
SequenceSpec ss; /* (this) Derived class data */
|
||||
int isDesc; /* True to count down rather than up */
|
||||
sqlite3_int64 iRowid; /* The rowid */
|
||||
sqlite3_int64 iValue; /* Current value ("value") */
|
||||
sqlite3_int64 mnValue; /* Mimimum value ("start") */
|
||||
sqlite3_int64 mxValue; /* Maximum value ("stop") */
|
||||
sqlite3_int64 iStep; /* Increment ("step") */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -305,7 +170,12 @@ static int seriesClose(sqlite3_vtab_cursor *cur){
|
||||
*/
|
||||
static int seriesNext(sqlite3_vtab_cursor *cur){
|
||||
series_cursor *pCur = (series_cursor*)cur;
|
||||
progressSequence( & pCur->ss );
|
||||
if( pCur->isDesc ){
|
||||
pCur->iValue -= pCur->iStep;
|
||||
}else{
|
||||
pCur->iValue += pCur->iStep;
|
||||
}
|
||||
pCur->iRowid++;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -321,27 +191,23 @@ static int seriesColumn(
|
||||
series_cursor *pCur = (series_cursor*)cur;
|
||||
sqlite3_int64 x = 0;
|
||||
switch( i ){
|
||||
case SERIES_COLUMN_START: x = pCur->ss.iBase; break;
|
||||
case SERIES_COLUMN_STOP: x = pCur->ss.iTerm; break;
|
||||
case SERIES_COLUMN_STEP: x = pCur->ss.iStep; break;
|
||||
default: x = pCur->ss.iValueNow; break;
|
||||
case SERIES_COLUMN_START: x = pCur->mnValue; break;
|
||||
case SERIES_COLUMN_STOP: x = pCur->mxValue; break;
|
||||
case SERIES_COLUMN_STEP: x = pCur->iStep; break;
|
||||
default: x = pCur->iValue; break;
|
||||
}
|
||||
sqlite3_result_int64(ctx, x);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#ifndef LARGEST_UINT64
|
||||
#define LARGEST_UINT64 (0xffffffff|(((sqlite3_uint64)0xffffffff)<<32))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Return the rowid for the current row, logically equivalent to n+1 where
|
||||
** "n" is the ascending integer in the aforesaid production definition.
|
||||
** Return the rowid for the current row. In this implementation, the
|
||||
** first row returned is assigned rowid value 1, and each subsequent
|
||||
** row a value 1 more than that of the previous.
|
||||
*/
|
||||
static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
series_cursor *pCur = (series_cursor*)cur;
|
||||
sqlite3_uint64 n = pCur->ss.uSeqIndexNow;
|
||||
*pRowid = (sqlite3_int64)((n<LARGEST_UINT64)? n+1 : 0);
|
||||
*pRowid = pCur->iRowid;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -351,10 +217,14 @@ static int seriesRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
*/
|
||||
static int seriesEof(sqlite3_vtab_cursor *cur){
|
||||
series_cursor *pCur = (series_cursor*)cur;
|
||||
return !pCur->ss.isNotEOF;
|
||||
if( pCur->isDesc ){
|
||||
return pCur->iValue < pCur->mnValue;
|
||||
}else{
|
||||
return pCur->iValue > pCur->mxValue;
|
||||
}
|
||||
}
|
||||
|
||||
/* True to cause run-time checking of the start=, stop=, and/or step=
|
||||
/* True to cause run-time checking of the start=, stop=, and/or step=
|
||||
** parameters. The only reason to do this is for testing the
|
||||
** constraint checking logic for virtual tables in the SQLite core.
|
||||
*/
|
||||
@@ -365,7 +235,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
|
||||
/*
|
||||
** This method is called to "rewind" the series_cursor object back
|
||||
** to the first row of output. This method is always called at least
|
||||
** once prior to any call to seriesColumn() or seriesRowid() or
|
||||
** once prior to any call to seriesColumn() or seriesRowid() or
|
||||
** seriesEof().
|
||||
**
|
||||
** The query plan selected by seriesBestIndex is passed in the idxNum
|
||||
@@ -385,7 +255,7 @@ static int seriesEof(sqlite3_vtab_cursor *cur){
|
||||
** (so that seriesEof() will return true) if the table is empty.
|
||||
*/
|
||||
static int seriesFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStrUnused,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
@@ -393,41 +263,46 @@ static int seriesFilter(
|
||||
int i = 0;
|
||||
(void)idxStrUnused;
|
||||
if( idxNum & 1 ){
|
||||
pCur->ss.iBase = sqlite3_value_int64(argv[i++]);
|
||||
pCur->mnValue = sqlite3_value_int64(argv[i++]);
|
||||
}else{
|
||||
pCur->ss.iBase = 0;
|
||||
pCur->mnValue = 0;
|
||||
}
|
||||
if( idxNum & 2 ){
|
||||
pCur->ss.iTerm = sqlite3_value_int64(argv[i++]);
|
||||
pCur->mxValue = sqlite3_value_int64(argv[i++]);
|
||||
}else{
|
||||
pCur->ss.iTerm = 0xffffffff;
|
||||
pCur->mxValue = 0xffffffff;
|
||||
}
|
||||
if( idxNum & 4 ){
|
||||
pCur->ss.iStep = sqlite3_value_int64(argv[i++]);
|
||||
if( pCur->ss.iStep==0 ){
|
||||
pCur->ss.iStep = 1;
|
||||
}else if( pCur->ss.iStep<0 ){
|
||||
pCur->iStep = sqlite3_value_int64(argv[i++]);
|
||||
if( pCur->iStep==0 ){
|
||||
pCur->iStep = 1;
|
||||
}else if( pCur->iStep<0 ){
|
||||
pCur->iStep = -pCur->iStep;
|
||||
if( (idxNum & 16)==0 ) idxNum |= 8;
|
||||
}
|
||||
}else{
|
||||
pCur->ss.iStep = 1;
|
||||
pCur->iStep = 1;
|
||||
}
|
||||
for(i=0; i<argc; i++){
|
||||
if( sqlite3_value_type(argv[i])==SQLITE_NULL ){
|
||||
/* If any of the constraints have a NULL value, then return no rows.
|
||||
** See ticket https://www.sqlite.org/src/info/fac496b61722daf2 */
|
||||
pCur->ss.iBase = 1;
|
||||
pCur->ss.iTerm = 0;
|
||||
pCur->ss.iStep = 1;
|
||||
pCur->mnValue = 1;
|
||||
pCur->mxValue = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( idxNum & 8 ){
|
||||
pCur->ss.isReversing = pCur->ss.iStep > 0;
|
||||
pCur->isDesc = 1;
|
||||
pCur->iValue = pCur->mxValue;
|
||||
if( pCur->iStep>0 ){
|
||||
pCur->iValue -= (pCur->mxValue - pCur->mnValue)%pCur->iStep;
|
||||
}
|
||||
}else{
|
||||
pCur->ss.isReversing = pCur->ss.iStep < 0;
|
||||
pCur->isDesc = 0;
|
||||
pCur->iValue = pCur->mnValue;
|
||||
}
|
||||
setupSequence( &pCur->ss );
|
||||
pCur->iRowid = 1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -10,8 +10,7 @@
|
||||
**
|
||||
******************************************************************************
|
||||
**
|
||||
** This SQLite extension implements functions that compute SHA3 hashes
|
||||
** in the way described by the (U.S.) NIST FIPS 202 SHA-3 Standard.
|
||||
** This SQLite extension implements functions that compute SHA3 hashes.
|
||||
** Two SQL functions are implemented:
|
||||
**
|
||||
** sha3(X,SIZE)
|
||||
|
||||
+4
-17
@@ -1097,10 +1097,7 @@ static int zipfileColumn(
|
||||
** it to be a directory either if the mode suggests so, or if
|
||||
** the final character in the name is '/'. */
|
||||
u32 mode = pCDS->iExternalAttr >> 16;
|
||||
if( !(mode & S_IFDIR)
|
||||
&& pCDS->nFile>=1
|
||||
&& pCDS->zFile[pCDS->nFile-1]!='/'
|
||||
){
|
||||
if( !(mode & S_IFDIR) && pCDS->zFile[pCDS->nFile-1]!='/' ){
|
||||
sqlite3_result_blob(ctx, "", 0, SQLITE_STATIC);
|
||||
}
|
||||
}
|
||||
@@ -1537,19 +1534,9 @@ static u32 zipfileGetTime(sqlite3_value *pVal){
|
||||
*/
|
||||
static void zipfileRemoveEntryFromList(ZipfileTab *pTab, ZipfileEntry *pOld){
|
||||
if( pOld ){
|
||||
if( pTab->pFirstEntry==pOld ){
|
||||
pTab->pFirstEntry = pOld->pNext;
|
||||
if( pTab->pLastEntry==pOld ) pTab->pLastEntry = 0;
|
||||
}else{
|
||||
ZipfileEntry *p;
|
||||
for(p=pTab->pFirstEntry; p; p=p->pNext){
|
||||
if( p->pNext==pOld ){
|
||||
p->pNext = pOld->pNext;
|
||||
if( pTab->pLastEntry==pOld ) pTab->pLastEntry = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ZipfileEntry **pp;
|
||||
for(pp=&pTab->pFirstEntry; (*pp)!=pOld; pp=&((*pp)->pNext));
|
||||
*pp = (*pp)->pNext;
|
||||
zipfileEntryFree(pOld);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,86 +207,5 @@ do_test 3.4.0 {
|
||||
} SQLITE_OK
|
||||
rbu close
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
forcedelete rbu1.db
|
||||
forcedelete rbu2.db
|
||||
|
||||
sqlite3 rbu rbu1.db
|
||||
do_execsql_test -db rbu 4.1 {
|
||||
CREATE TABLE data_t1(a, b, rbu_control);
|
||||
INSERT INTO data_t1 VALUES(1, 'one', 0);
|
||||
}
|
||||
rbu close
|
||||
sqlite3 rbu rbu2.db
|
||||
do_execsql_test -db rbu 4.2 {
|
||||
CREATE TABLE data_t1(a, b, rbu_control);
|
||||
INSERT INTO data_t1 VALUES(2, 'two', 0);
|
||||
}
|
||||
rbu close
|
||||
|
||||
do_execsql_test 4.3 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b);
|
||||
}
|
||||
db close
|
||||
|
||||
do_test 4.4 {
|
||||
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=1 rbu1.db
|
||||
rbu step
|
||||
rbu state
|
||||
} {oal}
|
||||
|
||||
sqlite3 cons test.db
|
||||
do_execsql_test -db cons 4.5 {
|
||||
SELECT * FROM t1
|
||||
} {}
|
||||
|
||||
do_test 4.6 { rbu step ; rbu state } {oal}
|
||||
do_test 4.7 { rbu step ; rbu state } {move}
|
||||
do_execsql_test -db cons 4.8 {
|
||||
SELECT * FROM t1
|
||||
} {}
|
||||
do_test 4.9 { rbu step ; rbu state } {checkpoint}
|
||||
do_test 4.10 {
|
||||
catchsql { SELECT * FROM t1 } cons
|
||||
} {1 {database is locked}}
|
||||
do_test 4.11 { rbu step ; rbu state } {checkpoint}
|
||||
do_test 4.11 { rbu step ; rbu state } {done}
|
||||
rbu close
|
||||
|
||||
do_test 4.12 {
|
||||
catchsql { SELECT * FROM t1 } cons
|
||||
} {0 {1 one}}
|
||||
|
||||
do_test 4.13 {
|
||||
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=1 rbu2.db
|
||||
rbu step
|
||||
rbu state
|
||||
} {oal}
|
||||
|
||||
do_test 4.14 {
|
||||
catchsql { SELECT * FROM t1 } cons
|
||||
} {0 {1 one}}
|
||||
|
||||
do_test 4.15 { rbu step ; rbu state } {oal}
|
||||
do_test 4.16 { rbu step ; rbu state } {move}
|
||||
|
||||
do_test 4.17 {
|
||||
catchsql { SELECT * FROM t1 } cons
|
||||
} {0 {1 one}}
|
||||
|
||||
do_test 4.18 { rbu step ; rbu state } {checkpoint}
|
||||
do_test 4.19 {
|
||||
catchsql { SELECT * FROM t1 } cons
|
||||
} {1 {database is locked}}
|
||||
do_test 4.20 { rbu step ; rbu state } {checkpoint}
|
||||
do_test 4.21 { rbu step ; rbu state } {done}
|
||||
rbu close
|
||||
|
||||
do_test 4.22 {
|
||||
catchsql { SELECT * FROM t1 } cons
|
||||
} {0 {1 one 2 two}}
|
||||
|
||||
cons close
|
||||
|
||||
finish_test
|
||||
|
||||
+2
-18
@@ -3141,11 +3141,6 @@ static void rbuCheckpointFrame(sqlite3rbu *p, RbuFrame *pFrame){
|
||||
p->rc = pDb->pMethods->xWrite(pDb, p->aBuf, p->pgsz, iOff);
|
||||
}
|
||||
|
||||
/*
|
||||
** This value is copied from the definition of ZIPVFS_CTRL_FILE_POINTER
|
||||
** in zipvfs.h.
|
||||
*/
|
||||
#define RBU_ZIPVFS_CTRL_FILE_POINTER 230439
|
||||
|
||||
/*
|
||||
** Take an EXCLUSIVE lock on the database file. Return SQLITE_OK if
|
||||
@@ -3154,20 +3149,9 @@ static void rbuCheckpointFrame(sqlite3rbu *p, RbuFrame *pFrame){
|
||||
static int rbuLockDatabase(sqlite3 *db){
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3_file *fd = 0;
|
||||
sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
|
||||
|
||||
sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd);
|
||||
if( fd ){
|
||||
sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
|
||||
rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = fd->pMethods->xUnlock(fd, SQLITE_LOCK_NONE);
|
||||
}
|
||||
sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd);
|
||||
}else{
|
||||
sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd);
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK && fd->pMethods ){
|
||||
if( fd->pMethods ){
|
||||
rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE);
|
||||
|
||||
+9
-13
@@ -73,12 +73,13 @@
|
||||
*/
|
||||
|
||||
#if !defined(SQLITEINT_H)
|
||||
#include "sqlite3.h"
|
||||
#include "sqlite3ext.h"
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned int u32;
|
||||
|
||||
#endif
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
@@ -166,7 +167,6 @@ static int dbdataConnect(
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
(void)pzErr;
|
||||
sqlite3_vtab_config(db, SQLITE_VTAB_USES_ALL_SCHEMAS);
|
||||
if( rc==SQLITE_OK ){
|
||||
pTab = (DbdataTable*)sqlite3_malloc64(sizeof(DbdataTable));
|
||||
if( pTab==0 ){
|
||||
@@ -663,14 +663,8 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
|
||||
if( pCsr->pHdrPtr>&pCsr->pRec[pCsr->nRec] ){
|
||||
bNextPage = 1;
|
||||
}else{
|
||||
int szField = 0;
|
||||
pCsr->pHdrPtr += dbdataGetVarintU32(pCsr->pHdrPtr, &iType);
|
||||
szField = dbdataValueBytes(iType);
|
||||
if( (pCsr->nRec - (pCsr->pPtr - pCsr->pRec))<szField ){
|
||||
pCsr->pPtr = &pCsr->pRec[pCsr->nRec];
|
||||
}else{
|
||||
pCsr->pPtr += szField;
|
||||
}
|
||||
pCsr->pPtr += dbdataValueBytes(iType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -818,6 +812,8 @@ static int dbdataFilter(
|
||||
}
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_bind_text(pCsr->pStmt, 1, zSchema, -1, SQLITE_TRANSIENT);
|
||||
}else{
|
||||
pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db));
|
||||
}
|
||||
|
||||
/* Try to determine the encoding of the db by inspecting the header
|
||||
@@ -826,10 +822,6 @@ static int dbdataFilter(
|
||||
rc = dbdataGetEncoding(pCsr);
|
||||
}
|
||||
|
||||
if( rc!=SQLITE_OK ){
|
||||
pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db));
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = dbdataNext(pCursor);
|
||||
}
|
||||
@@ -943,11 +935,15 @@ static int sqlite3DbdataRegister(sqlite3 *db){
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_dbdata_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
(void)pzErrMsg;
|
||||
return sqlite3DbdataRegister(db);
|
||||
}
|
||||
|
||||
@@ -316,51 +316,5 @@ do_execsql_test 16.9 {
|
||||
COMMIT;
|
||||
} {1 2 3 4}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 17.1 {
|
||||
CREATE TABLE t(a, PRIMARY KEY(a, a COLLATE NOCASE)) WITHOUT ROWID;
|
||||
INSERT INTO t VALUES('abc');
|
||||
INSERT INTO t VALUES('def');
|
||||
}
|
||||
do_test 17.2 {
|
||||
set R [sqlite3_recover_init db main test.db2]
|
||||
$R run
|
||||
list [catch { $R finish } msg] $msg
|
||||
} {0 {}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
foreach enc {utf8 utf16 utf16le utf16be} {
|
||||
reset_db
|
||||
do_execsql_test 18.$enc.1 {
|
||||
PRAGMA auto_vacuum = 0;
|
||||
PRAGMA encoding='utf16';
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t2(a, b);
|
||||
INSERT INTO t1 VALUES('abc', 'def');
|
||||
PRAGMA writable_schema = 1;
|
||||
DELETE FROM sqlite_schema WHERE name='t1';
|
||||
}
|
||||
|
||||
proc my_sql_hook {sql} {
|
||||
if {[string match "INSERT INTO lostandfound*" $sql]} {
|
||||
lappend ::script $sql
|
||||
}
|
||||
return 0
|
||||
}
|
||||
do_test 18.$enc.2 {
|
||||
set ::script [list]
|
||||
set R [sqlite3_recover_init_sql db main my_sql_hook]
|
||||
$R config lostandfound lostandfound
|
||||
$R run
|
||||
$R finish
|
||||
set ::script
|
||||
} {{INSERT INTO lostandfound VALUES(2, 2, 2, 1, 'abc', 'def')}}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
# 2023 February 28
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
source [file join [file dirname [info script]] recover_common.tcl]
|
||||
set testprefix recoverbuild
|
||||
|
||||
|
||||
# The following tests verify that if the recovery extension is used with
|
||||
# a build that does not support the sqlite_dbpage table, the error message
|
||||
# is "no such table: sqlite_dbpage", and not something more generic.
|
||||
#
|
||||
reset_db
|
||||
create_null_module db sqlite_dbpage
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT);
|
||||
INSERT INTO t1 VALUES(123, 'one hundred and twenty three');
|
||||
}
|
||||
|
||||
forcedelete test.db2
|
||||
do_test 1.1 {
|
||||
set R [sqlite3_recover_init db main test.db2]
|
||||
} {/sqlite_recover.*/}
|
||||
|
||||
do_test 1.2 {
|
||||
$R run
|
||||
} {1}
|
||||
|
||||
do_test 1.3 {
|
||||
list [catch { $R finish } msg] $msg
|
||||
} {1 {no such table: sqlite_dbpage}}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -285,244 +285,5 @@ do_test 5.1 {
|
||||
list [catch { $R finish } msg] $msg
|
||||
} {0 {}}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_test 6.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
| size 8192 pagesize 4096 filename abc.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 02 00 00 00 02 .....@ ........
|
||||
| 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................
|
||||
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
|
||||
| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................
|
||||
| 96: 00 2e 6e b8 0d 00 00 00 01 0f dc 00 0f dc 00 00 ..n.............
|
||||
| 4048: 00 00 00 00 00 00 00 00 00 00 00 00 22 01 06 17 ................
|
||||
| 4064: 11 11 01 31 74 61 62 6c 65 74 31 74 31 02 43 52 ...1tablet1t1.CR
|
||||
| 4080: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 29 EATE TABLE t1(x)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 00 00 00 01 0f e2 00 0f e2 00 00 00 00 00 00 ................
|
||||
| 4064: 00 00 1c 01 02 41 61 62 63 64 65 66 67 68 69 6a .....Aabcdefghij
|
||||
| 4080: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a klmnopqrstuvwxyz
|
||||
| end abc.db
|
||||
}]} {}
|
||||
do_test 6.1 {
|
||||
set R [sqlite3_recover_init db main test.db2]
|
||||
catch { $R run }
|
||||
list [catch { $R finish } msg] $msg
|
||||
} {0 {}}
|
||||
|
||||
reset_db
|
||||
breakpoint
|
||||
do_test 6.2 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
| size 8192 pagesize 4096 filename abc.db
|
||||
| page 1 offset 0
|
||||
| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
|
||||
| 16: 10 00 01 01 00 40 20 20 00 00 00 02 00 00 00 02 .....@ ........
|
||||
| 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................
|
||||
| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
|
||||
| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................
|
||||
| 96: 00 2e 6e b8 0d 00 00 00 01 0f dc 00 0f dc 00 00 ..n.............
|
||||
| 4048: 00 00 00 00 00 00 00 00 00 00 00 00 22 01 06 17 ................
|
||||
| 4064: 11 11 01 31 74 61 62 6c 65 74 31 74 31 02 43 52 ...1tablet1t1.CR
|
||||
| 4080: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 29 EATE TABLE t1(x)
|
||||
| page 2 offset 4096
|
||||
| 0: 0d 00 00 00 01 0f e2 00 0f e2 00 00 00 00 00 00 ................
|
||||
| 4064: 00 00 1c 01 02 8F FF FF FF 7E 65 66 67 68 69 6a .....Aabcdefghij
|
||||
| 4080: 6b 6c 6d 6e 6f 70 71 72 73 74 75 76 77 78 79 7a klmnopqrstuvwxyz
|
||||
| end abc.db
|
||||
}]} {}
|
||||
do_test 6.3 {
|
||||
set R [sqlite3_recover_init db main test.db2]
|
||||
catch { $R run }
|
||||
list [catch { $R finish } msg] $msg
|
||||
} {0 {}}
|
||||
|
||||
reset_db
|
||||
breakpoint
|
||||
do_test 7.0 {
|
||||
sqlite3 db {}
|
||||
db deserialize [decode_hexdb {
|
||||
| size 4108 pagesize 4096 filename x1.db
|
||||
| page 1 offset 0
|
||||
| 0: 02 01 00 00 00 00 14 15 40 00 00 00 00 00 00 00 ........@.......
|
||||
| 16: 33 3a 6d 65 6d 6f 72 79 3a 02 02 02 02 02 02 02 3:memory:.......
|
||||
| 32: 02 02 02 02 02 02 12 02 02 02 63 6f 6c 6f 72 20 ..........color
|
||||
| 48: 73 70 61 63 00 f3 a0 81 a1 00 00 a0 02 02 02 02 spac............
|
||||
| 64: 69 95 73 6f 36 00 ff 0d 00 97 8c 90 3f 0a 70 02 i.so6.......?.p.
|
||||
| 80: 02 02 02 02 02 02 02 02 02 02 02 02 02 01 00 00 ................
|
||||
| 96: 06 02 02 02 02 5f 02 02 02 2c 02 02 02 02 02 02 ....._...,......
|
||||
| 112: 02 02 02 02 02 02 02 02 02 12 02 02 02 63 6f 6c .............col
|
||||
| 128: 6f 72 20 73 70 61 63 00 f3 a0 81 a1 00 00 a0 02 or spac.........
|
||||
| 144: 02 02 02 69 95 73 6f 36 00 ff 0d 00 97 8c 90 3f ...i.so6.......?
|
||||
| 160: 0a 70 02 02 02 02 02 02 02 02 02 02 02 02 02 02 .p..............
|
||||
| 176: 01 00 00 06 02 02 02 02 5f 02 02 02 2c 02 02 00 ........_...,...
|
||||
| 192: 00 01 00 01 00 00 00 01 00 02 fe 00 00 03 00 01 ................
|
||||
| 208: 00 00 00 01 c5 04 00 00 00 01 00 01 00 00 00 01 ................
|
||||
| 224: 00 fa 02 00 00 00 03 00 01 00 00 00 81 00 04 00 ................
|
||||
| 240: 00 00 01 00 01 00 00 00 01 00 02 00 fe 00 03 00 ................
|
||||
| 256: 01 00 00 00 01 00 04 00 00 00 01 00 01 00 00 00 ................
|
||||
| 272: 01 00 02 00 00 00 03 00 01 00 00 00 01 00 04 00 ................
|
||||
| 288: 00 00 01 00 01 00 00 00 01 00 02 00 00 00 03 00 ................
|
||||
| 304: 01 00 00 00 01 00 04 00 00 00 01 00 01 00 00 00 ................
|
||||
| 320: 01 00 02 00 00 00 03 00 01 00 00 00 40 00 84 00 ............@...
|
||||
| 336: 84 00 84 00 01 00 00 00 09 00 06 00 f5 00 01 00 ................
|
||||
| 352: 08 01 03 00 03 00 62 00 62 00 23 00 01 00 62 00 ......b.b.#...b.
|
||||
| 368: 04 00 1e 00 62 00 62 00 62 00 01 00 00 00 0a 00 ....b.b.b.......
|
||||
| 384: 01 00 03 00 01 00 03 00 04 00 02 00 01 00 01 00 ................
|
||||
| 400: 08 00 01 00 31 c6 00 03 00 0c 00 12 00 18 00 02 ....1...........
|
||||
| 416: 00 05 00 08 00 02 00 06 00 08 00 02 00 07 00 08 ................
|
||||
| 432: 00 02 00 01 00 01 00 08 00 01 00 0c 00 03 00 16 ................
|
||||
| 448: 00 1c 00 22 00 01 00 03 00 05 00 06 00 07 00 02 ................
|
||||
| 464: 00 05 00 09 00 02 00 06 00 09 00 02 00 07 00 09 ................
|
||||
| 480: 00 00 00 00 01 00 05 00 00 00 01 00 01 00 00 00 ................
|
||||
| 496: 01 00 02 00 00 00 03 00 01 00 00 00 01 00 04 00 ................
|
||||
| 512: 00 00 01 00 01 00 00 00 01 00 02 00 00 00 03 00 ................
|
||||
| 528: 01 00 00 00 01 00 04 00 00 00 01 00 01 00 00 00 ................
|
||||
| 544: 01 00 02 00 00 f6 03 00 00 02 00 00 01 00 04 00 ................
|
||||
| 560: 00 00 01 00 01 00 00 00 01 00 02 00 00 00 03 00 ................
|
||||
| 576: 01 00 00 00 01 00 04 00 00 00 01 00 01 00 00 00 ................
|
||||
| 592: 01 00 02 00 00 00 03 00 01 00 00 00 01 00 04 00 ................
|
||||
| 608: 00 00 01 00 01 00 00 00 01 00 02 00 00 00 03 00 ................
|
||||
| 624: 01 00 00 00 01 00 04 00 00 00 01 00 01 00 00 00 ................
|
||||
| 640: 01 3d 02 00 00 00 03 00 06 00 00 00 01 00 01 00 .=..............
|
||||
| 656: 00 00 01 00 01 00 00 00 01 00 02 00 00 00 03 00 ................
|
||||
| 672: 01 00 00 00 01 00 04 00 00 00 01 00 01 00 00 00 ................
|
||||
| 688: 01 00 02 00 00 00 55 52 4c 52 65 71 75 65 73 74 ......URLRequest
|
||||
| 704: 43 6f 6e 00 00 00 01 01 0e d4 00 04 00 00 00 01 Con.............
|
||||
| 720: 0e f8 00 04 00 00 00 01 0f 1c 00 04 00 00 00 01 ................
|
||||
| 736: 0f 00 00 01 00 00 00 01 0f 86 00 01 00 00 00 01 ................
|
||||
| 752: 0f 84 00 01 00 00 00 01 00 00 01 0f c0 00 01 00 ................
|
||||
| 768: 00 00 01 0f e8 00 d6 0f 00 01 6f 00 02 0f d6 00 ..........o.....
|
||||
| 784: 02 34 03 03 03 00 01 00 00 00 01 00 05 00 00 00 .4..............
|
||||
| 800: 01 00 01 00 00 00 01 00 02 00 00 00 03 00 01 00 ................
|
||||
| 816: 00 00 01 00 04 00 00 00 01 00 01 00 00 00 01 00 ................
|
||||
| 832: 02 00 00 00 03 00 01 00 10 00 01 00 04 00 00 00 ................
|
||||
| 848: 01 00 01 00 00 00 01 00 02 00 00 00 03 00 00 02 ................
|
||||
| 864: 00 00 01 40 04 00 00 03 01 00 01 00 00 00 01 00 ...@............
|
||||
| 880: 02 00 00 00 03 00 01 00 00 00 00 00 01 0e f8 00 ................
|
||||
| 896: 04 77 4f 46 32 73 40 23 70 00 00 00 70 00 1f 00 .wOF2s@#p...p...
|
||||
| 912: 00 00 d8 00 00 00 ff ff 00 00 00 00 43 00 00 00 ............C...
|
||||
| 928: 00 00 ff ff ff ff ff 00 00 a8 00 00 0c 00 00 00 ................
|
||||
| 1024: 00 00 00 00 00 00 00 00 00 00 10 22 00 22 0f 00 ................
|
||||
| 1040: 00 00 00 00 00 00 10 22 00 00 70 00 1f 00 00 0f ..........p.....
|
||||
| 1056: d8 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 ................
|
||||
| 1072: 00 01 00 00 00 3f 23 70 00 00 00 01 0f 1c 00 04 .....?#p........
|
||||
| 1088: 00 00 00 01 0f 40 00 01 00 00 00 01 0f 86 00 01 .....@..........
|
||||
| 1104: 00 00 00 01 0f 84 00 01 00 00 00 01 00 00 01 0f ................
|
||||
| 1120: c0 00 01 00 00 00 01 0f e8 00 01 0f d6 00 6f 00 ..............o.
|
||||
| 1136: 02 0f d6 00 03 02 31 03 2b 03 2a f2 00 0f d4 00 ......1.+.*.....
|
||||
| 1152: 01 00 08 00 01 00 04 03 2b 00 02 02 32 00 01 0f ........+...2...
|
||||
| 1168: c8 01 15 00 02 20 c8 00 02 12 ad 02 00 24 06 c0 ..... .......$..
|
||||
| 1184: 00 00 00 03 00 00 01 24 00 2a 06 e4 00 00 00 03 .......$.*......
|
||||
| 1200: 00 00 01 25 00 38 07 0e 00 00 00 03 00 00 01 26 ...%.8.........&
|
||||
| 1216: 00 34 07 46 00 00 00 03 00 00 01 27 00 1c 07 7a .4.F.......'...z
|
||||
| 1232: 00 00 00 03 00 00 01 28 00 2a 07 96 00 00 00 03 .......(.*......
|
||||
| 1248: 00 e5 01 29 00 34 07 c0 00 00 00 03 00 00 01 2a ...).4.........*
|
||||
| 1264: 67 34 07 f4 00 00 00 03 00 00 01 2b 00 22 08 28 g4.........+...(
|
||||
| 1280: 00 00 00 00 01 00 01 00 00 00 01 00 02 00 00 00 ................
|
||||
| 1296: 03 00 01 00 00 00 01 00 00 00 01 00 00 00 01 00 ................
|
||||
| 1312: 01 00 00 00 01 00 02 00 00 00 03 00 00 02 00 00 ................
|
||||
| 1328: 01 00 04 00 00 00 01 00 01 00 00 00 01 00 02 00 ................
|
||||
| 1344: 00 00 03 00 01 00 00 00 01 00 04 00 00 00 01 00 ................
|
||||
| 1360: 01 00 00 00 01 00 02 00 00 00 03 00 01 00 00 21 ...............!
|
||||
| 1376: 04 00 01 00 00 00 00 00 01 00 00 00 01 00 02 00 ................
|
||||
| 1392: 00 00 03 00 01 00 00 00 01 00 04 00 00 00 01 00 ................
|
||||
| 1408: 01 00 00 00 01 00 02 00 00 00 03 00 01 00 00 00 ................
|
||||
| 1424: 01 00 05 00 00 00 01 00 01 00 00 01 00 02 02 02 ................
|
||||
| 1440: 12 02 02 02 63 6f 6c 6f 72 20 73 70 61 63 00 f3 ....color spac..
|
||||
| 1456: a0 81 a1 00 00 a0 02 02 02 02 69 95 73 6f 36 00 ..........i.so6.
|
||||
| 1472: ff 0d 00 97 8c 90 3f 0a 70 02 02 02 02 02 02 02 ......?.p.......
|
||||
| 1488: 02 02 02 02 02 02 02 01 00 00 06 02 02 02 02 5f ..............._
|
||||
| 1504: 02 02 02 2c 02 02 00 00 01 00 01 00 00 00 01 00 ...,............
|
||||
| 1520: 02 fe 00 00 03 00 01 00 00 00 01 c5 04 00 00 00 ................
|
||||
| 1536: 01 00 01 00 00 00 01 00 02 00 00 00 03 00 01 00 ................
|
||||
| 1552: 00 00 81 00 04 00 00 00 01 00 01 00 00 00 01 00 ................
|
||||
| 1568: 02 00 fe 00 03 00 01 00 00 00 01 00 04 00 00 00 ................
|
||||
| 1584: 01 00 01 00 00 00 01 00 02 00 00 00 03 00 01 00 ................
|
||||
| 1600: 00 00 01 00 04 00 00 00 01 00 01 00 00 00 01 00 ................
|
||||
| 1616: 02 00 00 00 03 00 01 00 00 00 01 00 04 00 00 00 ................
|
||||
| 1632: 01 00 01 00 00 00 01 00 02 00 00 00 03 00 01 00 ................
|
||||
| 1648: 00 00 40 00 84 00 84 00 84 00 01 00 00 00 09 00 ..@.............
|
||||
| 1664: 06 00 f5 00 01 00 08 01 03 15 15 15 15 15 15 15 ................
|
||||
| 1680: 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 ................
|
||||
| 1696: 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 ................
|
||||
| 1712: 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 ................
|
||||
| 1728: 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 ................
|
||||
| 1744: 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 ................
|
||||
| 1760: 15 15 15 15 15 15 15 15 15 15 15 00 03 00 62 00 ..............b.
|
||||
| 1776: 62 00 23 00 01 00 62 00 04 00 1e 00 62 00 62 00 b.#...b.....b.b.
|
||||
| 1792: 62 00 01 00 00 00 0a 00 01 00 03 00 01 00 03 00 b...............
|
||||
| 1808: 04 00 02 00 01 00 01 00 08 00 01 00 31 c6 00 03 ............1...
|
||||
| 1824: 00 0c 00 12 00 18 00 02 00 05 00 08 00 02 00 06 ................
|
||||
| 1840: 00 08 00 02 00 07 00 08 00 02 00 01 00 01 00 08 ................
|
||||
| 1856: 00 01 00 0c 00 03 00 16 00 1c 00 22 00 01 00 03 ................
|
||||
| 1872: 00 05 00 06 00 07 00 02 00 05 00 09 00 02 00 06 ................
|
||||
| 1888: 00 09 00 02 00 07 00 09 00 00 00 00 01 00 05 00 ................
|
||||
| 1904: 00 00 01 00 01 00 00 00 01 00 02 00 00 00 03 00 ................
|
||||
| 1920: 01 00 00 00 01 00 04 00 00 00 01 00 01 00 00 00 ................
|
||||
| 1936: 01 00 02 00 00 00 03 00 01 00 00 00 01 00 04 00 ................
|
||||
| 1952: 00 00 01 0f d6 00 02 34 03 03 03 00 01 00 00 00 .......4........
|
||||
| 1968: 01 00 05 00 00 00 01 00 01 00 00 00 01 00 02 00 ................
|
||||
| 1984: 00 00 03 00 01 00 00 00 01 00 04 00 00 00 01 00 ................
|
||||
| 2000: 01 00 00 00 01 00 02 fc 42 dc 19 5c 74 23 18 cd ........B...t#..
|
||||
| 2016: b3 a5 a8 7a 90 40 1d 66 12 5d e5 4f 85 00 68 f4 ...z.@.f.].O..h.
|
||||
| 2032: 05 98 86 25 24 dd bc c2 f6 f6 4e a3 e2 61 d2 c6 ...%$.....N..a..
|
||||
| 2048: aa c1 56 50 d4 80 82 35 f1 e2 59 41 50 a6 da 51 ..VP...5..YAP..Q
|
||||
| 2064: d4 62 9c 19 94 58 aa 31 30 8a 22 c2 5f 33 2b c9 .b...X.10..._3+.
|
||||
| 2080: b6 e6 b4 11 4e 51 82 c4 d8 b6 d8 b4 06 04 fb 68 ....NQ.........h
|
||||
| 2096: f4 d2 6f e7 cb 8a a8 82 d5 74 00 00 00 00 00 00 ..o......t......
|
||||
| 2368: 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 ................
|
||||
| 2432: 00 00 00 00 00 03 00 01 00 10 00 01 00 04 00 00 ................
|
||||
| 2448: 00 01 00 01 00 00 00 01 00 02 00 00 00 03 00 00 ................
|
||||
| 2464: 02 00 00 01 40 04 00 00 03 01 00 01 00 00 00 01 ....@...........
|
||||
| 2480: 00 02 00 00 00 03 00 01 00 00 00 00 00 01 0e f8 ................
|
||||
| 2496: 00 04 77 4f 46 32 73 40 23 70 00 00 00 70 00 1f ..wOF2s@#p...p..
|
||||
| 2512: 00 00 00 d8 00 00 00 ff ff 00 00 00 00 43 00 00 .............C..
|
||||
| 2528: 00 00 00 ff ff ff ff ff 00 00 a8 00 00 0c 00 00 ................
|
||||
| 2624: 00 00 00 00 00 00 00 00 00 00 00 10 22 00 22 0f ................
|
||||
| 2640: 00 00 00 00 00 00 00 10 22 00 00 70 00 1f 00 00 ...........p....
|
||||
| 2656: 0f d8 00 00 00 00 00 00 00 00 00 03 00 00 00 00 ................
|
||||
| 2672: 00 00 01 00 00 00 3f 23 70 00 00 00 01 0f 1c 00 ......?#p.......
|
||||
| 2688: 04 00 00 00 01 0f 40 00 01 00 00 00 01 0f 86 00 ......@.........
|
||||
| 2704: 01 00 00 00 01 0f 84 00 01 00 00 00 01 00 00 01 ................
|
||||
| 2720: 0f c0 00 01 00 00 00 01 0f e8 00 01 0f d6 00 6f ...............o
|
||||
| 2736: 00 02 0f d6 00 03 02 31 03 2b 03 2a f2 00 0f d4 .......1.+.*....
|
||||
| 2752: 00 01 00 08 00 01 00 04 03 2b 00 02 02 32 00 01 .........+...2..
|
||||
| 2768: 0f c8 01 15 00 02 20 c8 00 02 12 ad 02 00 24 06 ...... .......$.
|
||||
| 2784: c0 00 00 5a 03 00 00 01 24 00 2a 06 e4 00 00 00 ...Z....$.*.....
|
||||
| 2800: 03 00 00 01 25 00 38 07 0e 00 00 00 03 00 00 01 ....%.8.........
|
||||
| 2816: 26 00 34 07 46 00 00 00 03 00 00 01 27 00 1c 07 &.4.F.......'...
|
||||
| 2832: 7a 00 00 00 03 00 00 01 28 00 2a 07 96 00 00 00 z.......(.*.....
|
||||
| 2848: 03 00 e5 01 29 00 34 07 c0 00 00 00 03 00 00 01 ....).4.........
|
||||
| 2864: 2a 67 34 07 f4 00 00 00 03 00 00 01 2b 00 22 08 *g4.........+...
|
||||
| 2880: 28 00 00 00 00 01 00 01 00 00 00 01 00 02 00 00 (...............
|
||||
| 2896: 00 03 00 01 00 00 00 01 00 00 00 01 00 00 00 01 ................
|
||||
| 2912: 00 01 00 00 00 01 00 02 00 00 00 03 00 00 02 00 ................
|
||||
| 2928: 00 01 00 04 00 00 00 01 00 01 00 00 00 00 00 00 ................
|
||||
| 2992: 00 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H..............
|
||||
| 3504: 00 00 00 00 00 00 00 00 00 00 00 97 00 00 00 00 ................
|
||||
| 3904: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 ................
|
||||
| 3920: 03 fe 00 00 01 36 00 3c 0a 38 00 00 00 03 00 00 .....6.<.8......
|
||||
| 3936: 01 37 00 20 0a 74 00 00 00 fb ff ff 00 38 00 2a .7. .t.......8.*
|
||||
| 3952: 0a 94 00 00 00 03 00 00 01 39 4f 54 54 4f 00 0e .........9OTTO..
|
||||
| 3968: 00 80 00 03 00 60 43 46 46 20 e3 ae 89 2a 00 00 .....`CFF ...*..
|
||||
| 3984: 02 b0 00 00 02 76 42 50 4f 53 00 15 00 0a 00 00 .....vBPOS......
|
||||
| 4000: 05 28 00 00 00 0c 54 53 55 42 c9 70 c3 06 00 00 .(....TSUB.p....
|
||||
| 4016: 05 34 1f 00 40 00 48 00 00 00 00 00 00 00 00 00 .4..@.H.........
|
||||
| 4064: 00 00 00 00 00 08 00 01 00 01 00 01 00 01 00 06 ................
|
||||
| 4080: 00 02 00 08 00 01 00 01 00 01 00 01 00 00 00 00 ................
|
||||
| end x1.db
|
||||
}]} {}
|
||||
do_test 7.1 {
|
||||
set R [sqlite3_recover_init db main test.db2]
|
||||
catch { $R run }
|
||||
list [catch { $R finish } msg] $msg
|
||||
} {1 {file is not a database}}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
@@ -1106,7 +1106,7 @@ static void recoverAddTable(
|
||||
int iField = sqlite3_column_int(pStmt, 0);
|
||||
int iCol = sqlite3_column_int(pStmt, 1);
|
||||
|
||||
assert( iCol<pNew->nCol );
|
||||
assert( iField<pNew->nCol && iCol<pNew->nCol );
|
||||
pNew->aCol[iCol].iField = iField;
|
||||
|
||||
pNew->bIntkey = 0;
|
||||
@@ -2103,7 +2103,7 @@ static int recoverIsValidPage(u8 *aTmp, const u8 *a, int n){
|
||||
if( iFree>(n-4) ) return 0;
|
||||
iNext = recoverGetU16(&a[iFree]);
|
||||
nByte = recoverGetU16(&a[iFree+2]);
|
||||
if( iFree+nByte>n || nByte<4 ) return 0;
|
||||
if( iFree+nByte>n ) return 0;
|
||||
if( iNext && iNext<iFree+nByte ) return 0;
|
||||
memset(&aUsed[iFree], 0xFF, nByte);
|
||||
iFree = iNext;
|
||||
|
||||
+19
-39
@@ -96,11 +96,6 @@ typedef unsigned int u32;
|
||||
#endif
|
||||
#endif /* !defined(SQLITE_AMALGAMATION) */
|
||||
|
||||
/* Macro to check for 4-byte alignment. Only used inside of assert() */
|
||||
#ifdef SQLITE_DEBUG
|
||||
# define FOUR_BYTE_ALIGNED(X) ((((char*)(X) - (char*)0) & 3)==0)
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
@@ -476,17 +471,16 @@ struct RtreeMatchArg {
|
||||
** at run-time.
|
||||
*/
|
||||
#ifndef SQLITE_BYTEORDER
|
||||
# if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
|
||||
defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
|
||||
defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
|
||||
defined(__ARMEL__) || defined(__AARCH64EL__) || defined(_M_ARM64)
|
||||
# define SQLITE_BYTEORDER 1234
|
||||
# elif defined(sparc) || defined(__ppc__) || \
|
||||
defined(__ARMEB__) || defined(__AARCH64EB__)
|
||||
# define SQLITE_BYTEORDER 4321
|
||||
# else
|
||||
# define SQLITE_BYTEORDER 0
|
||||
# endif
|
||||
#if defined(i386) || defined(__i386__) || defined(_M_IX86) || \
|
||||
defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \
|
||||
defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \
|
||||
defined(__arm__)
|
||||
# define SQLITE_BYTEORDER 1234
|
||||
#elif defined(sparc) || defined(__ppc__)
|
||||
# define SQLITE_BYTEORDER 4321
|
||||
#else
|
||||
# define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -507,7 +501,7 @@ static int readInt16(u8 *p){
|
||||
return (p[0]<<8) + p[1];
|
||||
}
|
||||
static void readCoord(u8 *p, RtreeCoord *pCoord){
|
||||
assert( FOUR_BYTE_ALIGNED(p) );
|
||||
assert( (((sqlite3_uint64)p)&3)==0 ); /* p is always 4-byte aligned */
|
||||
#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300
|
||||
pCoord->u = _byteswap_ulong(*(u32*)p);
|
||||
#elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
|
||||
@@ -561,7 +555,7 @@ static void writeInt16(u8 *p, int i){
|
||||
}
|
||||
static int writeCoord(u8 *p, RtreeCoord *pCoord){
|
||||
u32 i;
|
||||
assert( FOUR_BYTE_ALIGNED(p) );
|
||||
assert( (((sqlite3_uint64)p)&3)==0 ); /* p is always 4-byte aligned */
|
||||
assert( sizeof(RtreeCoord)==4 );
|
||||
assert( sizeof(u32)==4 );
|
||||
#if SQLITE_BYTEORDER==1234 && GCC_VERSION>=4003000
|
||||
@@ -1289,7 +1283,7 @@ static void rtreeNonleafConstraint(
|
||||
assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE
|
||||
|| p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
|
||||
|| p->op==RTREE_FALSE );
|
||||
assert( FOUR_BYTE_ALIGNED(pCellData) );
|
||||
assert( (((sqlite3_uint64)pCellData)&3)==0 ); /* 4-byte aligned */
|
||||
switch( p->op ){
|
||||
case RTREE_TRUE: return; /* Always satisfied */
|
||||
case RTREE_FALSE: break; /* Never satisfied */
|
||||
@@ -1342,7 +1336,7 @@ static void rtreeLeafConstraint(
|
||||
|| p->op==RTREE_GT || p->op==RTREE_EQ || p->op==RTREE_TRUE
|
||||
|| p->op==RTREE_FALSE );
|
||||
pCellData += 8 + p->iCoord*4;
|
||||
assert( FOUR_BYTE_ALIGNED(pCellData) );
|
||||
assert( (((sqlite3_uint64)pCellData)&3)==0 ); /* 4-byte aligned */
|
||||
RTREE_DECODE_COORD(eInt, pCellData, xN);
|
||||
switch( p->op ){
|
||||
case RTREE_TRUE: return; /* Always satisfied */
|
||||
@@ -1912,20 +1906,7 @@ static int rtreeFilter(
|
||||
p->pInfo->nCoord = pRtree->nDim2;
|
||||
p->pInfo->anQueue = pCsr->anQueue;
|
||||
p->pInfo->mxLevel = pRtree->iDepth + 1;
|
||||
}else if( eType==SQLITE_INTEGER ){
|
||||
sqlite3_int64 iVal = sqlite3_value_int64(argv[ii]);
|
||||
#ifdef SQLITE_RTREE_INT_ONLY
|
||||
p->u.rValue = iVal;
|
||||
#else
|
||||
p->u.rValue = (double)iVal;
|
||||
if( iVal>=((sqlite3_int64)1)<<48
|
||||
|| -iVal>=((sqlite3_int64)1)<<48
|
||||
){
|
||||
if( p->op==RTREE_LT ) p->op = RTREE_LE;
|
||||
if( p->op==RTREE_GT ) p->op = RTREE_GE;
|
||||
}
|
||||
#endif
|
||||
}else if( eType==SQLITE_FLOAT ){
|
||||
}else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
|
||||
#ifdef SQLITE_RTREE_INT_ONLY
|
||||
p->u.rValue = sqlite3_value_int64(argv[ii]);
|
||||
#else
|
||||
@@ -2056,12 +2037,11 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
|| p->op==SQLITE_INDEX_CONSTRAINT_MATCH)
|
||||
){
|
||||
u8 op;
|
||||
u8 doOmit = 1;
|
||||
switch( p->op ){
|
||||
case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; doOmit = 0; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; doOmit = 0; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; doOmit = 0; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break;
|
||||
case SQLITE_INDEX_CONSTRAINT_MATCH: op = RTREE_MATCH; break;
|
||||
default: op = 0; break;
|
||||
@@ -2070,7 +2050,7 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
||||
zIdxStr[iIdx++] = op;
|
||||
zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0');
|
||||
pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
|
||||
pIdxInfo->aConstraintUsage[ii].omit = doOmit;
|
||||
pIdxInfo->aConstraintUsage[ii].omit = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -756,32 +756,4 @@ do_execsql_test 20.4 {
|
||||
SELECT * FROM t1 JOIN t0 ON true RIGHT JOIN rt0 ON x0>a WHERE x0 = 0;
|
||||
} {- - 0 0.0 0.0}
|
||||
|
||||
# 2023-05-19 https://sqlite.org/forum/forumpost/da61c4a1b5b4af19
|
||||
# Do not omit constraints that involve equality comparisons of
|
||||
# floating-point values.
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 21.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING rtree(id, x0, x1);
|
||||
INSERT INTO t1 VALUES(0, 1, 9223372036854775807);
|
||||
SELECT count(*) FROM t1 WHERE x1=9223372036854775807;
|
||||
} {0}
|
||||
do_execsql_test 21.1 {
|
||||
SELECT x1=9223372036854775807 FROM t1;
|
||||
} {0}
|
||||
|
||||
# 2023-05-22 https://sqlite.org/forum/forumpost/da70ee0d0d
|
||||
# Round-off error associated with using large integer constraints on
|
||||
# a rtree search.
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 22.0 {
|
||||
CREATE VIRTUAL TABLE t1 USING rtree ( id, x0, x1 );
|
||||
INSERT INTO t1 VALUES (123, 9223372036854775799, 9223372036854775800);
|
||||
SELECT id FROM t1 WHERE x0 > 9223372036854775807;
|
||||
} {123}
|
||||
do_execsql_test 22.1 {
|
||||
SELECT id, x0 > 9223372036854775807 AS 'a0' FROM t1;
|
||||
} {123 1}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -104,7 +104,6 @@ do_eqp_test rtree6.2.4.1 {
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
|
||||
|--BLOOM FILTER ON t2 (v=?)
|
||||
`--SEARCH t2 USING AUTOMATIC COVERING INDEX (v=?)
|
||||
}
|
||||
do_eqp_test rtree6.2.4.2 {
|
||||
@@ -112,7 +111,6 @@ do_eqp_test rtree6.2.4.2 {
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
|
||||
|--BLOOM FILTER ON t2 (v=?)
|
||||
`--SEARCH t2 USING AUTOMATIC PARTIAL COVERING INDEX (v=?)
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ do_common_sql {
|
||||
}
|
||||
|
||||
foreach {tn sql} [string map {%T1% t1 %T2% t2 %T3% t3 %T4% t4} $set_of_tests] {
|
||||
do_then_apply_sql -ignorenoop $sql
|
||||
do_then_apply_sql $sql
|
||||
do_test 2.$tn { compare_db db db2 } {}
|
||||
}
|
||||
|
||||
@@ -598,7 +598,7 @@ do_common_sql {
|
||||
INSERT INTO t1 SELECT NULL, 0, 0, 0, 0, 0 FROM s
|
||||
}
|
||||
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t1 SET f=f+1 WHERE a=1;
|
||||
UPDATE t1 SET e=e+1 WHERE a=2;
|
||||
UPDATE t1 SET e=e+1, f=f+1 WHERE a=3;
|
||||
|
||||
@@ -41,6 +41,30 @@ proc scksum {db dbname} {
|
||||
return [md5 $txt]
|
||||
}
|
||||
|
||||
proc do_diff_test {tn setup} {
|
||||
reset_db
|
||||
forcedelete test.db2
|
||||
execsql { ATTACH 'test.db2' AS aux }
|
||||
execsql $setup
|
||||
|
||||
sqlite3session S db main
|
||||
foreach tbl [db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
|
||||
S attach $tbl
|
||||
S diff aux $tbl
|
||||
}
|
||||
|
||||
set C [S changeset]
|
||||
S delete
|
||||
|
||||
sqlite3 db2 test.db2
|
||||
sqlite3changeset_apply db2 $C ""
|
||||
uplevel do_test $tn.1 [list {execsql { PRAGMA integrity_check } db2}] ok
|
||||
db2 close
|
||||
|
||||
set cksum [scksum db main]
|
||||
uplevel do_test $tn.2 [list {scksum db aux}] [list $cksum]
|
||||
}
|
||||
|
||||
# Ensure that the diff produced by comparing the current contents of [db]
|
||||
# with itself is empty.
|
||||
proc do_empty_diff_test {tn} {
|
||||
|
||||
@@ -34,7 +34,7 @@ do_test 1.0 {
|
||||
INSERT INTO t1 VALUES(2, 'two');
|
||||
INSERT INTO t1 VALUES(3, 'three');
|
||||
}
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
DELETE FROM t1 WHERE a=1;
|
||||
INSERT INTO t1 VALUES(4, 'one');
|
||||
}
|
||||
@@ -42,7 +42,7 @@ do_test 1.0 {
|
||||
} {}
|
||||
|
||||
do_test 1.1 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
DELETE FROM t1 WHERE a=4;
|
||||
INSERT INTO t1 VALUES(1, 'one');
|
||||
}
|
||||
@@ -51,7 +51,7 @@ do_test 1.1 {
|
||||
|
||||
do_test 1.2 {
|
||||
execsql { INSERT INTO t1 VALUES(5, 'five') } db2
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t1 VALUES(11, 'eleven');
|
||||
INSERT INTO t1 VALUES(12, 'five');
|
||||
}
|
||||
@@ -82,7 +82,7 @@ do_test 2.2.1 {
|
||||
# It is not possible to apply the changeset generated by the following
|
||||
# SQL, as none of the three updated rows may be updated as part of the
|
||||
# first pass.
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t1 SET b=0 WHERE a=1;
|
||||
UPDATE t1 SET b=1 WHERE a=2;
|
||||
UPDATE t1 SET b=2 WHERE a=3;
|
||||
@@ -109,7 +109,7 @@ do_test 3.1 {
|
||||
} {}
|
||||
|
||||
do_test 3.3 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t1 SET b=4 WHERE a=3;
|
||||
UPDATE t1 SET b=3 WHERE a=2;
|
||||
UPDATE t1 SET b=2 WHERE a=1;
|
||||
@@ -118,7 +118,7 @@ do_test 3.3 {
|
||||
} {}
|
||||
|
||||
do_test 3.4 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t1 SET b=1 WHERE a=1;
|
||||
UPDATE t1 SET b=2 WHERE a=2;
|
||||
UPDATE t1 SET b=3 WHERE a=3;
|
||||
@@ -148,7 +148,7 @@ do_test 4.1 {
|
||||
} {}
|
||||
|
||||
do_test 4.2 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t1 SET b=4 WHERE a=3;
|
||||
UPDATE t1 SET b=3 WHERE a=2;
|
||||
UPDATE t1 SET b=2 WHERE a=1;
|
||||
@@ -161,7 +161,7 @@ do_test 4.2 {
|
||||
} {}
|
||||
|
||||
do_test 4.3 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t1 SET b=1 WHERE a=1;
|
||||
UPDATE t1 SET b=2 WHERE a=2;
|
||||
UPDATE t1 SET b=3 WHERE a=3;
|
||||
@@ -191,7 +191,7 @@ do_execsql_test -db db2 5.0.2 {
|
||||
}
|
||||
|
||||
do_test 5.1 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t2 VALUES(4, 5, 6);
|
||||
INSERT INTO t3 VALUES(7, 8, 9);
|
||||
|
||||
@@ -25,7 +25,7 @@ do_test 1.0 {
|
||||
do_common_sql {
|
||||
CREATE TABLE t1(a, b, c, PRIMARY KEY(a, b));
|
||||
}
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
WITH s(i) AS (
|
||||
VALUES(1) UNION ALL SELECT i+1 FROM s WHERe i<10000
|
||||
)
|
||||
|
||||
@@ -52,7 +52,6 @@ proc do_conflict_test {tn args} {
|
||||
proc bgerror {args} { set ::background_error $args }
|
||||
|
||||
sqlite3session S db main
|
||||
S object_config rowid 1
|
||||
foreach t $O(-tables) { S attach $t }
|
||||
execsql $O(-sql)
|
||||
|
||||
@@ -82,7 +81,6 @@ proc changeset_from_sql {sql {dbname main}} {
|
||||
}
|
||||
set rc [catch {
|
||||
sqlite3session S db $dbname
|
||||
S object_config rowid 1
|
||||
db eval "SELECT name FROM $dbname.sqlite_master WHERE type = 'table'" {
|
||||
S attach $name
|
||||
}
|
||||
@@ -114,59 +112,24 @@ proc patchset_from_sql {sql {dbname main}} {
|
||||
return $patchset
|
||||
}
|
||||
|
||||
# Usage: do_then_apply_sql ?-ignorenoop? SQL ?DBNAME?
|
||||
#
|
||||
proc do_then_apply_sql {args} {
|
||||
|
||||
set bIgnoreNoop 0
|
||||
set a1 [lindex $args 0]
|
||||
if {[string length $a1]>1 && [string first $a1 -ignorenoop]==0} {
|
||||
set bIgnoreNoop 1
|
||||
set args [lrange $args 1 end]
|
||||
}
|
||||
|
||||
if {[llength $args]!=1 && [llength $args]!=2} {
|
||||
error "usage: do_then_apply_sql ?-ignorenoop? SQL ?DBNAME?"
|
||||
}
|
||||
|
||||
set sql [lindex $args 0]
|
||||
if {[llength $args]==1} {
|
||||
set dbname main
|
||||
} else {
|
||||
set dbname [lindex $args 1]
|
||||
}
|
||||
|
||||
set ::n_conflict 0
|
||||
proc xConflict args { incr ::n_conflict ; return "OMIT" }
|
||||
proc do_then_apply_sql {sql {dbname main}} {
|
||||
proc xConflict args { return "OMIT" }
|
||||
set rc [catch {
|
||||
sqlite3session S db $dbname
|
||||
S object_config rowid 1
|
||||
db eval "SELECT name FROM $dbname.sqlite_master WHERE type = 'table'" {
|
||||
S attach $name
|
||||
}
|
||||
db eval $sql
|
||||
set ::changeset [S changeset]
|
||||
sqlite3changeset_apply db2 $::changeset xConflict
|
||||
sqlite3changeset_apply db2 [S changeset] xConflict
|
||||
} msg]
|
||||
|
||||
catch { S delete }
|
||||
if {$rc} {error $msg}
|
||||
|
||||
if {$bIgnoreNoop} {
|
||||
set nSave $::n_conflict
|
||||
set ::n_conflict 0
|
||||
proc xConflict args { incr ::n_conflict ; return "OMIT" }
|
||||
sqlite3changeset_apply_v2 -ignorenoop db2 $::changeset xConflict
|
||||
if {$::n_conflict!=$nSave} {
|
||||
error "-ignorenoop problem ($::n_conflict $nSave)..."
|
||||
}
|
||||
}
|
||||
if {$rc} {error $msg}
|
||||
}
|
||||
|
||||
proc do_iterator_test {tn tbl_list sql res} {
|
||||
sqlite3session S db main
|
||||
S object_config rowid 1
|
||||
|
||||
if {[llength $tbl_list]==0} { S attach * }
|
||||
foreach t $tbl_list {S attach $t}
|
||||
|
||||
@@ -176,7 +139,6 @@ proc do_iterator_test {tn tbl_list sql res} {
|
||||
foreach v $res { lappend r $v }
|
||||
|
||||
set x [list]
|
||||
# set ::c [S changeset] ; execsql_pp { SELECT quote($::c) }
|
||||
sqlite3session_foreach c [S changeset] { lappend x $c }
|
||||
uplevel do_test $tn [list [list set {} $x]] [list $r]
|
||||
|
||||
@@ -251,49 +213,3 @@ proc number_name {n} {
|
||||
if {$txt==""} {set txt zero}
|
||||
return $txt
|
||||
}
|
||||
|
||||
proc scksum {db dbname} {
|
||||
|
||||
if {$dbname=="temp"} {
|
||||
set master sqlite_temp_master
|
||||
} else {
|
||||
set master $dbname.sqlite_master
|
||||
}
|
||||
|
||||
set alltab [$db eval "SELECT name FROM $master WHERE type='table'"]
|
||||
set txt [$db eval "SELECT * FROM $master ORDER BY type,name,sql"]
|
||||
foreach tab $alltab {
|
||||
set cols [list]
|
||||
db eval "PRAGMA $dbname.table_info = $tab" x {
|
||||
lappend cols "quote($x(name))"
|
||||
}
|
||||
set cols [join $cols ,]
|
||||
append txt [db eval "SELECT $cols FROM $dbname.$tab ORDER BY $cols"]
|
||||
}
|
||||
return [md5 $txt]
|
||||
}
|
||||
|
||||
proc do_diff_test {tn setup} {
|
||||
reset_db
|
||||
forcedelete test.db2
|
||||
execsql { ATTACH 'test.db2' AS aux }
|
||||
execsql $setup
|
||||
|
||||
sqlite3session S db main
|
||||
S object_config rowid 1
|
||||
foreach tbl [db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
|
||||
S attach $tbl
|
||||
S diff aux $tbl
|
||||
}
|
||||
|
||||
set C [S changeset]
|
||||
S delete
|
||||
|
||||
sqlite3 db2 test.db2
|
||||
sqlite3changeset_apply db2 $C ""
|
||||
uplevel do_test $tn.1 [list {execsql { PRAGMA integrity_check } db2}] ok
|
||||
db2 close
|
||||
|
||||
set cksum [scksum db main]
|
||||
uplevel do_test $tn.2 [list {scksum db aux}] [list $cksum]
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ eval [string map [list %WR% $trailing] {
|
||||
CREATE TABLE t3(a, b, c DEFAULT 'D', PRIMARY KEY(b)) %WR%;
|
||||
}
|
||||
do_test $tn.3.2 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t3 VALUES(1, 2);
|
||||
INSERT INTO t3 VALUES(3, 4);
|
||||
INSERT INTO t3 VALUES(5, 6);
|
||||
@@ -118,7 +118,7 @@ eval [string map [list %WR% $trailing] {
|
||||
db2 eval {SELECT * FROM t3}
|
||||
} {1 2 D 3 4 D 5 6 D}
|
||||
do_test $tn.3.3 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t3 SET a=45 WHERE b=4;
|
||||
DELETE FROM t3 WHERE a=5;
|
||||
};
|
||||
@@ -253,7 +253,7 @@ eval [string map [list %WR% $trailing] {
|
||||
CREATE TABLE t8(a PRIMARY KEY, b, c, d DEFAULT 'D', e DEFAULT 'E');
|
||||
}
|
||||
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t8 VALUES(1, 2, 3);
|
||||
INSERT INTO t8 VALUES(4, 5, 6);
|
||||
}
|
||||
@@ -264,7 +264,7 @@ eval [string map [list %WR% $trailing] {
|
||||
SELECT * FROM t8
|
||||
} {1 2 3 D E 4 5 6 D E}
|
||||
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t8 SET c=45 WHERE a=4;
|
||||
}
|
||||
do_execsql_test $tn.7.3.1 {
|
||||
@@ -282,7 +282,7 @@ eval [string map [list %WR% $trailing] {
|
||||
do_execsql_test -db db2 $tn.8.1 {
|
||||
CREATE TABLE t9(a PRIMARY KEY, b, c, d, e, f, g, h, i, j, k, l);
|
||||
}
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t9 VALUES(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
}
|
||||
do_then_apply_sql {
|
||||
@@ -291,7 +291,7 @@ eval [string map [list %WR% $trailing] {
|
||||
do_execsql_test -db db2 $tn.8.2 {
|
||||
SELECT * FROM t9
|
||||
} {1 2 3 4 5 6 7 450 {} {} {} {}}
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
UPDATE t9 SET h=NULL
|
||||
}
|
||||
do_execsql_test -db db2 $tn.8.2 {
|
||||
|
||||
@@ -43,7 +43,7 @@ do_execsql_test -db db2 1.1 {
|
||||
}
|
||||
|
||||
do_test 1.2 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
@@ -71,7 +71,7 @@ do_test 1.3 {
|
||||
|
||||
do_test 1.4 {
|
||||
set rc [catch {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
INSERT INTO t1(b) VALUES( zeroblob(100*1000*1000) );
|
||||
|
||||
@@ -44,7 +44,7 @@ do_faultsim_test 1.1 -faults oom-* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
sqlite3 db2 test.db2
|
||||
} -body {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t1 VALUES('a string value', 8, 9);
|
||||
UPDATE t1 SET c = 10 WHERE a = 1;
|
||||
DELETE FROM t1 WHERE a = 4;
|
||||
|
||||
@@ -132,7 +132,7 @@ do_faultsim_test 1.1 -faults oom-* -prep {
|
||||
faultsim_restore_and_reopen
|
||||
sqlite3 db2 test.db2
|
||||
} -body {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO sqlite_stat1 VALUES('x', 'y', 45);
|
||||
UPDATE sqlite_stat1 SET stat = 123 WHERE tbl='t1' AND idx='i1';
|
||||
UPDATE sqlite_stat1 SET stat = 456 WHERE tbl='t2';
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
# 2011 March 07
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source [file join [file dirname [info script]] session_common.tcl]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !session {finish_test; return}
|
||||
|
||||
set testprefix sessionnoop2
|
||||
|
||||
foreach {tn wo} {
|
||||
1 ""
|
||||
2 " WITHOUT ROWID "
|
||||
} {
|
||||
reset_db
|
||||
eval [string map [list %WO% $wo] {
|
||||
do_execsql_test $tn.1.0 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b, c) %WO%;
|
||||
INSERT INTO t1 VALUES('a', 'A', 'AAA');
|
||||
INSERT INTO t1 VALUES('b', 'B', 'BBB');
|
||||
INSERT INTO t1 VALUES('c', 'C', 'CCC');
|
||||
INSERT INTO t1 VALUES('d', 'D', 'DDD');
|
||||
INSERT INTO t1 VALUES('e', 'E', 'EEE');
|
||||
}
|
||||
|
||||
forcedelete test.db2
|
||||
sqlite3 db2 test.db2
|
||||
|
||||
do_execsql_test -db db2 $tn.1.1 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b, c) %WO%;
|
||||
INSERT INTO t1 VALUES('a', 'A', 'AAA');
|
||||
INSERT INTO t1 VALUES('b', 'B', '123');
|
||||
INSERT INTO t1 VALUES('c', 'C', 'CCC');
|
||||
INSERT INTO t1 VALUES('e', 'E', 'EEE');
|
||||
INSERT INTO t1 VALUES('f', 'F', 'FFF');
|
||||
}
|
||||
|
||||
set C [changeset_from_sql {
|
||||
UPDATE t1 SET c='123' WHERE a='b';
|
||||
DELETE FROM t1 WHERE a='d';
|
||||
INSERT INTO t1 VALUES('f', 'F', 'FFF');
|
||||
}]
|
||||
|
||||
|
||||
set ::conflict_list [list]
|
||||
proc xConflict {args} {
|
||||
lappend ::conflict_list $args
|
||||
return "OMIT"
|
||||
}
|
||||
do_test $tn.1.2 {
|
||||
sqlite3changeset_apply_v2 db2 $C xConflict
|
||||
set ::conflict_list
|
||||
} [list {*}{
|
||||
{UPDATE t1 DATA {t b {} {} t BBB} {{} {} {} {} t 123} {t b t B t 123}}
|
||||
{INSERT t1 CONFLICT {t f t F t FFF} {t f t F t FFF}}
|
||||
{DELETE t1 NOTFOUND {t d t D t DDD}}
|
||||
}]
|
||||
do_test $tn.1.3 {
|
||||
set ::conflict_list [list]
|
||||
sqlite3changeset_apply_v2 db2 $C xConflict
|
||||
set ::conflict_list
|
||||
} [list {*}{
|
||||
{UPDATE t1 DATA {t b {} {} t BBB} {{} {} {} {} t 123} {t b t B t 123}}
|
||||
{INSERT t1 CONFLICT {t f t F t FFF} {t f t F t FFF}}
|
||||
{DELETE t1 NOTFOUND {t d t D t DDD}}
|
||||
}]
|
||||
|
||||
do_test $tn.1.4 {
|
||||
set ::conflict_list [list]
|
||||
sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
|
||||
set ::conflict_list
|
||||
} {}
|
||||
|
||||
do_execsql_test -db db2 1.5 {
|
||||
UPDATE t1 SET b='G' WHERE a='f';
|
||||
UPDATE t1 SET c='456' WHERE a='b';
|
||||
}
|
||||
|
||||
do_test $tn.1.6 {
|
||||
set ::conflict_list [list]
|
||||
sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
|
||||
set ::conflict_list
|
||||
} [list {*}{
|
||||
{UPDATE t1 DATA {t b {} {} t BBB} {{} {} {} {} t 123} {t b t B t 456}}
|
||||
{INSERT t1 CONFLICT {t f t F t FFF} {t f t G t FFF}}
|
||||
}]
|
||||
|
||||
db2 close
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
reset_db
|
||||
forcedelete test.db2
|
||||
sqlite3 db2 test.db2
|
||||
do_execsql_test $tn.2.0 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b) %WO%;
|
||||
}
|
||||
do_execsql_test -db db2 $tn.2.1 {
|
||||
CREATE TABLE t1(a PRIMARY KEY, b, c DEFAULT 'val') %WO%;
|
||||
}
|
||||
|
||||
do_test $tn.2.2 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
}
|
||||
do_then_apply_sql -ignorenoop {
|
||||
UPDATE t1 SET b=2 WHERE a=1
|
||||
}
|
||||
} {}
|
||||
|
||||
db2 close
|
||||
|
||||
}]
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
forcedelete test.db2
|
||||
do_execsql_test 3.0 {
|
||||
CREATE TABLE xyz(a, b, c, PRIMARY KEY(a, b), UNIQUE(c));
|
||||
ANALYZE;
|
||||
WITH s(i) AS (
|
||||
VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100
|
||||
)
|
||||
INSERT INTO xyz SELECT i, i, i FROM s;
|
||||
VACUUM INTO 'test.db2';
|
||||
}
|
||||
|
||||
set C [changeset_from_sql { ANALYZE }]
|
||||
sqlite3 db2 test.db2
|
||||
|
||||
set ::conflict_list [list]
|
||||
proc xConflict {args} { lappend ::conflict_list $args ; return "OMIT" }
|
||||
do_test 3.1 {
|
||||
sqlite3changeset_apply_v2 db2 $C xConflict
|
||||
set ::conflict_list
|
||||
} {}
|
||||
|
||||
do_test 3.2 {
|
||||
sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
|
||||
set ::conflict_list
|
||||
} {}
|
||||
|
||||
do_test 3.3 {
|
||||
sqlite3changeset_apply_v2 db2 $C xConflict
|
||||
set ::conflict_list
|
||||
} [list {*}{
|
||||
{INSERT sqlite_stat1 CONFLICT {t xyz t sqlite_autoindex_xyz_1 t {100 1 1}} {t xyz t sqlite_autoindex_xyz_1 t {100 1 1}}}
|
||||
{INSERT sqlite_stat1 CONFLICT {t xyz t sqlite_autoindex_xyz_2 t {100 1}} {t xyz t sqlite_autoindex_xyz_2 t {100 1}}}
|
||||
}]
|
||||
|
||||
do_execsql_test -db db2 3.4 {
|
||||
UPDATE sqlite_stat1 SET stat='200 1 1' WHERE idx='sqlite_autoindex_xyz_1';
|
||||
}
|
||||
|
||||
do_test 3.5 {
|
||||
set ::conflict_list [list]
|
||||
sqlite3changeset_apply_v2 -ignorenoop db2 $C xConflict
|
||||
set ::conflict_list
|
||||
} [list {*}{
|
||||
{INSERT sqlite_stat1 CONFLICT {t xyz t sqlite_autoindex_xyz_1 t {100 1 1}} {t xyz t sqlite_autoindex_xyz_1 t {200 1 1}}}
|
||||
}]
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -84,7 +84,6 @@ proc do_rebase_test {tn sql1 sql2 conflict_handler {testsql ""} {testres ""}} {
|
||||
db eval BEGIN
|
||||
|
||||
sqlite3session S1 db main
|
||||
S1 object_config rowid 1
|
||||
S1 attach *
|
||||
execsql $sql1 db
|
||||
set c1 [S1 changeset]
|
||||
@@ -92,7 +91,6 @@ proc do_rebase_test {tn sql1 sql2 conflict_handler {testsql ""} {testres ""}} {
|
||||
|
||||
if {$i==1} {
|
||||
sqlite3session S2 db2 main
|
||||
S2 object_config rowid 1
|
||||
S2 attach *
|
||||
execsql $sql2 db2
|
||||
set c2 [S2 changeset]
|
||||
@@ -102,7 +100,6 @@ proc do_rebase_test {tn sql1 sql2 conflict_handler {testsql ""} {testres ""}} {
|
||||
foreach sql [split $sql2 ";"] {
|
||||
if {[string is space $sql]} continue
|
||||
sqlite3session S2 db2 main
|
||||
S2 object_config rowid 1
|
||||
S2 attach *
|
||||
execsql $sql db2
|
||||
lappend c2 [S2 changeset]
|
||||
@@ -344,79 +341,6 @@ do_rebase_test 2.2.3 {
|
||||
OMIT
|
||||
} { SELECT * FROM t2 WHERE z='B' } { 1 one B }
|
||||
|
||||
|
||||
reset_db
|
||||
do_execsql_test 2.3.0 {
|
||||
CREATE TABLE t1 (b TEXT);
|
||||
INSERT INTO t1(rowid, b) VALUES(1, 'one');
|
||||
INSERT INTO t1(rowid, b) VALUES(2, 'two');
|
||||
INSERT INTO t1(rowid, b) VALUES(3, 'three');
|
||||
}
|
||||
do_rebase_test 2.3.1 {
|
||||
UPDATE t1 SET b = 'two.1' WHERE rowid=2
|
||||
} {
|
||||
UPDATE t1 SET b = 'two.2' WHERE rowid=2;
|
||||
} {
|
||||
OMIT
|
||||
} { SELECT rowid, * FROM t1 } {1 one 2 two.1 3 three}
|
||||
|
||||
do_rebase_test 2.3.2 {
|
||||
UPDATE t1 SET b = 'two.1' WHERE rowid=2
|
||||
} {
|
||||
UPDATE t1 SET b = 'two.2' WHERE rowid=2;
|
||||
} {
|
||||
REPLACE
|
||||
} { SELECT rowid, * FROM t1 } {1 one 2 two.2 3 three}
|
||||
|
||||
do_rebase_test 2.3.3 {
|
||||
DELETE FROM t1 WHERE rowid=3
|
||||
} {
|
||||
DELETE FROM t1 WHERE rowid=3;
|
||||
} {
|
||||
OMIT
|
||||
} { SELECT rowid, * FROM t1 } {1 one 2 two}
|
||||
|
||||
do_rebase_test 2.3.4 {
|
||||
DELETE FROM t1 WHERE rowid=1
|
||||
} {
|
||||
UPDATE t1 SET b='one.2' WHERE rowid=1
|
||||
} {
|
||||
OMIT
|
||||
} { SELECT rowid, * FROM t1 } {2 two 3 three}
|
||||
|
||||
do_rebase_test 2.3.6 {
|
||||
UPDATE t1 SET b='three.1' WHERE rowid=3
|
||||
} {
|
||||
DELETE FROM t1 WHERE rowid=3;
|
||||
} {
|
||||
OMIT
|
||||
} { SELECT rowid, * FROM t1 } {1 one 2 two 3 three.1}
|
||||
|
||||
do_rebase_test 2.3.7 {
|
||||
UPDATE t1 SET b='three.1' WHERE rowid=3
|
||||
} {
|
||||
DELETE FROM t1 WHERE rowid=3;
|
||||
} {
|
||||
REPLACE
|
||||
} { SELECT rowid, * FROM t1 } {1 one 2 two}
|
||||
|
||||
do_rebase_test 2.3.8 {
|
||||
INSERT INTO t1(rowid, b) VALUES(4, 'four.1')
|
||||
} {
|
||||
INSERT INTO t1(rowid, b) VALUES(4, 'four.2');
|
||||
} {
|
||||
REPLACE
|
||||
} { SELECT rowid, * FROM t1 } {1 one 2 two 3 three 4 four.2}
|
||||
|
||||
do_rebase_test 2.3.9 {
|
||||
INSERT INTO t1(rowid, b) VALUES(4, 'four.1')
|
||||
} {
|
||||
INSERT INTO t1(rowid, b) VALUES(4, 'four.2');
|
||||
} {
|
||||
OMIT
|
||||
} { SELECT rowid, * FROM t1 } {1 one 2 two 3 three 4 four.1}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 3.0 {
|
||||
|
||||
@@ -1,282 +0,0 @@
|
||||
# 2011 Mar 16
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# The focus of this file is testing the session module.
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source [file join [file dirname [info script]] session_common.tcl]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable !session {finish_test; return}
|
||||
|
||||
set testprefix sessionrowid
|
||||
|
||||
do_execsql_test 0.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
}
|
||||
|
||||
foreach {tn rowid bEmpty} {
|
||||
1 0 1
|
||||
2 1 0
|
||||
3 -1 1
|
||||
} {
|
||||
do_test 0.$tn {
|
||||
sqlite3session S db main
|
||||
if {$rowid>=0} { S object_config rowid $rowid }
|
||||
S attach t1
|
||||
execsql { INSERT INTO t1 VALUES(1, 2); }
|
||||
expr [string length [S changeset]]==0
|
||||
} $bEmpty
|
||||
S delete
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
}
|
||||
|
||||
do_iterator_test 1.1 t1 {
|
||||
INSERT INTO t1 VALUES('i', 'one');
|
||||
} {
|
||||
{INSERT t1 0 X.. {} {i 1 t i t one}}
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
SELECT rowid, * FROM t1
|
||||
} {1 i one}
|
||||
|
||||
do_iterator_test 1.3 t1 {
|
||||
UPDATE t1 SET b='two'
|
||||
} {
|
||||
{UPDATE t1 0 X.. {i 1 {} {} t one} {{} {} {} {} t two}}
|
||||
}
|
||||
|
||||
do_iterator_test 1.4 t1 {
|
||||
DELETE FROM t1;
|
||||
} {
|
||||
{DELETE t1 0 X.. {i 1 t i t two} {}}
|
||||
}
|
||||
|
||||
do_iterator_test 1.5 t1 {
|
||||
INSERT INTO t1(rowid, a, b) VALUES(14, 'hello', 'world');
|
||||
INSERT INTO t1(rowid, a, b) VALUES(NULL, 'yes', 'no');
|
||||
INSERT INTO t1(rowid, a, b) VALUES(-123, 'ii', 'iii');
|
||||
} {
|
||||
{INSERT t1 0 X.. {} {i -123 t ii t iii}}
|
||||
{INSERT t1 0 X.. {} {i 15 t yes t no}}
|
||||
{INSERT t1 0 X.. {} {i 14 t hello t world}}
|
||||
}
|
||||
|
||||
do_iterator_test 1.6 t1 {
|
||||
UPDATE t1 SET a='deluxe' WHERE rowid=14;
|
||||
DELETE FROM t1 WHERE rowid=-123;
|
||||
INSERT INTO t1 VALUES('x', 'xi');
|
||||
} {
|
||||
{DELETE t1 0 X.. {i -123 t ii t iii} {}}
|
||||
{UPDATE t1 0 X.. {i 14 t hello {} {}} {{} {} t deluxe {} {}}}
|
||||
{INSERT t1 0 X.. {} {i 16 t x t xi}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
forcedelete test.db2
|
||||
sqlite3 db2 test.db2
|
||||
|
||||
do_execsql_test 2.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
}
|
||||
do_execsql_test -db db2 2.0.1 {
|
||||
CREATE TABLE t1(a, b);
|
||||
}
|
||||
|
||||
proc xConflict {args} {
|
||||
puts "CONFLICT!"
|
||||
return "OMIT"
|
||||
}
|
||||
|
||||
do_test 2.1 {
|
||||
set C [changeset_from_sql {
|
||||
INSERT INTO t1 VALUES('abc', 'def');
|
||||
}]
|
||||
sqlite3changeset_apply db2 $C xConflict
|
||||
execsql { SELECT * FROM t1 } db2
|
||||
} {abc def}
|
||||
do_test 2.2 {
|
||||
set C [changeset_from_sql {
|
||||
UPDATE t1 SET b='hello'
|
||||
}]
|
||||
sqlite3changeset_apply db2 $C xConflict
|
||||
execsql { SELECT * FROM t1 } db2
|
||||
} {abc hello}
|
||||
do_test 2.3 {
|
||||
set C [changeset_from_sql {
|
||||
DELETE FROM t1 WHERE b='hello'
|
||||
}]
|
||||
sqlite3changeset_apply db2 $C xConflict
|
||||
execsql { SELECT * FROM t1 } db2
|
||||
} {}
|
||||
|
||||
do_test 2.4 {
|
||||
do_then_apply_sql {
|
||||
INSERT INTO t1 VALUES('i', 'one');
|
||||
INSERT INTO t1 VALUES('ii', 'two');
|
||||
INSERT INTO t1 VALUES('iii', 'three');
|
||||
INSERT INTO t1 VALUES('iv', 'four');
|
||||
}
|
||||
compare_db db db2
|
||||
} {}
|
||||
|
||||
do_test 2.5 {
|
||||
do_then_apply_sql {
|
||||
DELETE FROM t1 WHERE a='ii';
|
||||
UPDATE t1 SET b='THREE' WHERE a='iii';
|
||||
UPDATE t1 SET a='III' WHERE a='iii';
|
||||
INSERT INTO t1 VALUES('v', 'five');
|
||||
}
|
||||
compare_db db db2
|
||||
} {}
|
||||
|
||||
do_execsql_test 2.6 {SELECT * FROM t1} {i one III THREE iv four v five}
|
||||
do_execsql_test -db db2 2.7 {SELECT * FROM t1} {i one III THREE iv four v five}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
db2 close
|
||||
reset_db
|
||||
forcedelete test.db2
|
||||
sqlite3 db2 test.db2
|
||||
|
||||
set init_sql {
|
||||
CREATE TABlE t4(a, b);
|
||||
CREATE INDEX t4a ON t4(a);
|
||||
CREATE UNIQUE INDEX t4b ON t4(b);
|
||||
}
|
||||
|
||||
do_execsql_test 3.0 $init_sql
|
||||
do_execsql_test -db db2 3.0a $init_sql
|
||||
|
||||
do_execsql_test -db db2 3.1 {
|
||||
INSERT INTO t4(rowid, a, b) VALUES(43, 'hello', 'world');
|
||||
}
|
||||
do_conflict_test 3.2 -sql {
|
||||
INSERT INTO t4(rowid, a, b) VALUES(43, 'abc', 'def');
|
||||
} -tables t4 -conflicts {
|
||||
{INSERT t4 CONFLICT {i 43 t abc t def} {i 43 t hello t world}}
|
||||
}
|
||||
do_execsql_test -db db2 3.3 {
|
||||
SELECT * FROM t4
|
||||
} {hello world}
|
||||
|
||||
do_execsql_test 3.4 { DELETE FROM t4 }
|
||||
do_conflict_test 3.5 -sql {
|
||||
INSERT INTO t4(rowid, a, b) VALUES(43, 'abc', 'def');
|
||||
} -tables t4 -conflicts {
|
||||
{INSERT t4 CONFLICT {i 43 t abc t def} {i 43 t hello t world}}
|
||||
} -policy REPLACE
|
||||
do_execsql_test -db db2 3.6 {
|
||||
SELECT * FROM t4
|
||||
} {abc def}
|
||||
|
||||
do_execsql_test 3.7 { DELETE FROM t4 }
|
||||
do_conflict_test 3.8 -sql {
|
||||
INSERT INTO t4(rowid, a, b) VALUES(45, 'xyz', 'def');
|
||||
} -tables t4 -conflicts {
|
||||
{INSERT t4 CONSTRAINT {i 45 t xyz t def}}
|
||||
}
|
||||
do_execsql_test -db db2 3.9 {
|
||||
SELECT * FROM t4
|
||||
} {abc def}
|
||||
|
||||
|
||||
do_execsql_test -db db 3.10a { DELETE FROM t4 }
|
||||
do_execsql_test -db db2 3.10b { DELETE FROM t4 }
|
||||
|
||||
do_execsql_test -db db 3.11a {
|
||||
INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'one');
|
||||
INSERT INTO t4(rowid, a, b) VALUES(222, 'two', 'two');
|
||||
}
|
||||
do_execsql_test -db db2 3.11b {
|
||||
INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'blip');
|
||||
}
|
||||
|
||||
do_conflict_test 3.12 -sql {
|
||||
DELETE FROM t4 WHERE a='one';
|
||||
} -tables t4 -conflicts {
|
||||
{DELETE t4 DATA {i 111 t one t one} {i 111 t one t blip}}
|
||||
}
|
||||
do_execsql_test -db db2 3.13 {
|
||||
SELECT * FROM t4
|
||||
} {one blip}
|
||||
|
||||
do_conflict_test 3.14 -sql {
|
||||
DELETE FROM t4 WHERE a='two';
|
||||
} -tables t4 -conflicts {
|
||||
{DELETE t4 NOTFOUND {i 222 t two t two}}
|
||||
}
|
||||
do_execsql_test -db db2 3.15 {
|
||||
SELECT * FROM t4
|
||||
} {one blip}
|
||||
|
||||
do_execsql_test -db db 3.16a { DELETE FROM t4 }
|
||||
do_execsql_test -db db2 3.16b { DELETE FROM t4 }
|
||||
|
||||
do_execsql_test -db db 3.17a {
|
||||
INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'one');
|
||||
INSERT INTO t4(rowid, a, b) VALUES(222, 'two', 'two');
|
||||
}
|
||||
do_execsql_test -db db2 3.17b {
|
||||
INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'blip');
|
||||
}
|
||||
|
||||
do_conflict_test 3.18 -sql {
|
||||
UPDATE t4 SET b='xyz' WHERE a='one'
|
||||
} -tables t4 -conflicts {
|
||||
{UPDATE t4 DATA {i 111 {} {} t one} {{} {} {} {} t xyz} {i 111 t one t blip}}
|
||||
}
|
||||
do_execsql_test -db db2 3.19 {
|
||||
SELECT * FROM t4
|
||||
} {one blip}
|
||||
|
||||
do_conflict_test 3.20 -sql {
|
||||
UPDATE t4 SET b='123' WHERE a='two'
|
||||
} -tables t4 -conflicts {
|
||||
{UPDATE t4 NOTFOUND {i 222 {} {} t two} {{} {} {} {} t 123}}
|
||||
}
|
||||
do_execsql_test -db db2 3.21 {
|
||||
SELECT * FROM t4
|
||||
} {one blip}
|
||||
db2 close
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
breakpoint
|
||||
do_diff_test 4.0 {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE TABLE aux.t1(x, y);
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
}
|
||||
|
||||
do_diff_test 4.1 {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE TABLE aux.t1(x, y);
|
||||
INSERT INTO aux.t1 VALUES(1, 2);
|
||||
}
|
||||
|
||||
do_diff_test 4.2 {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE TABLE aux.t1(x, y);
|
||||
INSERT INTO t1(rowid, x, y) VALUES(413, 'hello', 'there');
|
||||
INSERT INTO aux.t1(rowid, x, y) VALUES(413, 'hello', 'world');
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -113,17 +113,17 @@ do_execsql_test 3.0 {
|
||||
|
||||
do_test 3.1 {
|
||||
sqlite3session S db main
|
||||
S object_config size -1
|
||||
S object_config_size -1
|
||||
} 1
|
||||
|
||||
do_test 3.2.1 { S object_config size 0 } 0
|
||||
do_test 3.2.2 { S object_config size -1 } 0
|
||||
do_test 3.2.3 { S object_config size 1 } 1
|
||||
do_test 3.2.4 { S object_config size -1 } 1
|
||||
do_test 3.2.1 { S object_config_size 0 } 0
|
||||
do_test 3.2.2 { S object_config_size -1 } 0
|
||||
do_test 3.2.3 { S object_config_size 1 } 1
|
||||
do_test 3.2.4 { S object_config_size -1 } 1
|
||||
|
||||
do_test 3.3 { S attach t1 } {}
|
||||
do_test 3.4 { S object_config size 1 } {SQLITE_MISUSE}
|
||||
do_test 3.4 { S object_config size -1 } {1}
|
||||
do_test 3.4 { S object_config_size 1 } {SQLITE_MISUSE}
|
||||
do_test 3.4 { S object_config_size -1 } {1}
|
||||
|
||||
S delete
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ do_test 2.0 {
|
||||
} {}
|
||||
|
||||
do_test 2.1 {
|
||||
do_then_apply_sql -ignorenoop {
|
||||
do_then_apply_sql {
|
||||
WITH s(i) AS (
|
||||
SELECT 0 UNION ALL SELECT i+1 FROM s WHERE (i+1)<32
|
||||
)
|
||||
@@ -100,7 +100,7 @@ do_execsql_test -db db2 2.2 {
|
||||
}
|
||||
|
||||
do_test 2.3 {
|
||||
do_then_apply_sql -ignorenoop { DROP INDEX t1c }
|
||||
do_then_apply_sql { DROP INDEX t1c }
|
||||
} {}
|
||||
|
||||
do_execsql_test -db db2 2.4 {
|
||||
@@ -111,7 +111,7 @@ do_execsql_test -db db2 2.4 {
|
||||
}
|
||||
|
||||
do_test 2.3 {
|
||||
do_then_apply_sql -ignorenoop { DROP TABLE t1 }
|
||||
do_then_apply_sql { DROP TABLE t1 }
|
||||
} {}
|
||||
|
||||
do_execsql_test -db db2 2.4 {
|
||||
@@ -153,16 +153,16 @@ do_execsql_test 3.2 {
|
||||
} {t1 null 4}
|
||||
do_test 3.3 {
|
||||
execsql { DELETE FROM sqlite_stat1 }
|
||||
do_then_apply_sql -ignorenoop { ANALYZE }
|
||||
do_then_apply_sql { ANALYZE }
|
||||
execsql { SELECT * FROM sqlite_stat1 } db2
|
||||
} {t1 null 4}
|
||||
do_test 3.4 {
|
||||
execsql { INSERT INTO t1 VALUES(5,5,5) }
|
||||
do_then_apply_sql -ignorenoop { ANALYZE }
|
||||
do_then_apply_sql { ANALYZE }
|
||||
execsql { SELECT * FROM sqlite_stat1 } db2
|
||||
} {t1 null 5}
|
||||
do_test 3.5 {
|
||||
do_then_apply_sql -ignorenoop { DROP TABLE t1 }
|
||||
do_then_apply_sql { DROP TABLE t1 }
|
||||
execsql { SELECT * FROM sqlite_stat1 } db2
|
||||
} {}
|
||||
|
||||
|
||||
+85
-294
@@ -25,8 +25,6 @@ typedef struct SessionInput SessionInput;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define SESSIONS_ROWID "_rowid_"
|
||||
|
||||
static int sessions_strm_chunk_size = SESSIONS_STRM_CHUNK_SIZE;
|
||||
|
||||
typedef struct SessionHook SessionHook;
|
||||
@@ -48,7 +46,6 @@ struct sqlite3_session {
|
||||
int bEnable; /* True if currently recording */
|
||||
int bIndirect; /* True if all changes are indirect */
|
||||
int bAutoAttach; /* True to auto-attach tables */
|
||||
int bImplicitPK; /* True to handle tables with implicit PK */
|
||||
int rc; /* Non-zero if an error has occurred */
|
||||
void *pFilterCtx; /* First argument to pass to xTableFilter */
|
||||
int (*xTableFilter)(void *pCtx, const char *zTab);
|
||||
@@ -125,7 +122,6 @@ struct SessionTable {
|
||||
char *zName; /* Local name of table */
|
||||
int nCol; /* Number of columns in table zName */
|
||||
int bStat1; /* True if this is sqlite_stat1 */
|
||||
int bRowid; /* True if this table uses rowid for PK */
|
||||
const char **azCol; /* Column names */
|
||||
u8 *abPK; /* Array of primary key flags */
|
||||
int nEntry; /* Total number of entries in hash table */
|
||||
@@ -518,7 +514,6 @@ static unsigned int sessionHashAppendType(unsigned int h, int eType){
|
||||
*/
|
||||
static int sessionPreupdateHash(
|
||||
sqlite3_session *pSession, /* Session object that owns pTab */
|
||||
i64 iRowid,
|
||||
SessionTable *pTab, /* Session table handle */
|
||||
int bNew, /* True to hash the new.* PK */
|
||||
int *piHash, /* OUT: Hash value */
|
||||
@@ -527,53 +522,48 @@ static int sessionPreupdateHash(
|
||||
unsigned int h = 0; /* Hash value to return */
|
||||
int i; /* Used to iterate through columns */
|
||||
|
||||
if( pTab->bRowid ){
|
||||
assert( pTab->nCol-1==pSession->hook.xCount(pSession->hook.pCtx) );
|
||||
h = sessionHashAppendI64(h, iRowid);
|
||||
}else{
|
||||
assert( *pbNullPK==0 );
|
||||
assert( pTab->nCol==pSession->hook.xCount(pSession->hook.pCtx) );
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( pTab->abPK[i] ){
|
||||
int rc;
|
||||
int eType;
|
||||
sqlite3_value *pVal;
|
||||
assert( *pbNullPK==0 );
|
||||
assert( pTab->nCol==pSession->hook.xCount(pSession->hook.pCtx) );
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
if( pTab->abPK[i] ){
|
||||
int rc;
|
||||
int eType;
|
||||
sqlite3_value *pVal;
|
||||
|
||||
if( bNew ){
|
||||
rc = pSession->hook.xNew(pSession->hook.pCtx, i, &pVal);
|
||||
}else{
|
||||
rc = pSession->hook.xOld(pSession->hook.pCtx, i, &pVal);
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
if( bNew ){
|
||||
rc = pSession->hook.xNew(pSession->hook.pCtx, i, &pVal);
|
||||
}else{
|
||||
rc = pSession->hook.xOld(pSession->hook.pCtx, i, &pVal);
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
eType = sqlite3_value_type(pVal);
|
||||
h = sessionHashAppendType(h, eType);
|
||||
if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
|
||||
i64 iVal;
|
||||
if( eType==SQLITE_INTEGER ){
|
||||
iVal = sqlite3_value_int64(pVal);
|
||||
}else{
|
||||
double rVal = sqlite3_value_double(pVal);
|
||||
assert( sizeof(iVal)==8 && sizeof(rVal)==8 );
|
||||
memcpy(&iVal, &rVal, 8);
|
||||
}
|
||||
h = sessionHashAppendI64(h, iVal);
|
||||
}else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
|
||||
const u8 *z;
|
||||
int n;
|
||||
if( eType==SQLITE_TEXT ){
|
||||
z = (const u8 *)sqlite3_value_text(pVal);
|
||||
}else{
|
||||
z = (const u8 *)sqlite3_value_blob(pVal);
|
||||
}
|
||||
n = sqlite3_value_bytes(pVal);
|
||||
if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
|
||||
h = sessionHashAppendBlob(h, n, z);
|
||||
eType = sqlite3_value_type(pVal);
|
||||
h = sessionHashAppendType(h, eType);
|
||||
if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
|
||||
i64 iVal;
|
||||
if( eType==SQLITE_INTEGER ){
|
||||
iVal = sqlite3_value_int64(pVal);
|
||||
}else{
|
||||
assert( eType==SQLITE_NULL );
|
||||
assert( pTab->bStat1==0 || i!=1 );
|
||||
*pbNullPK = 1;
|
||||
double rVal = sqlite3_value_double(pVal);
|
||||
assert( sizeof(iVal)==8 && sizeof(rVal)==8 );
|
||||
memcpy(&iVal, &rVal, 8);
|
||||
}
|
||||
h = sessionHashAppendI64(h, iVal);
|
||||
}else if( eType==SQLITE_TEXT || eType==SQLITE_BLOB ){
|
||||
const u8 *z;
|
||||
int n;
|
||||
if( eType==SQLITE_TEXT ){
|
||||
z = (const u8 *)sqlite3_value_text(pVal);
|
||||
}else{
|
||||
z = (const u8 *)sqlite3_value_blob(pVal);
|
||||
}
|
||||
n = sqlite3_value_bytes(pVal);
|
||||
if( !z && (eType!=SQLITE_BLOB || n>0) ) return SQLITE_NOMEM;
|
||||
h = sessionHashAppendBlob(h, n, z);
|
||||
}else{
|
||||
assert( eType==SQLITE_NULL );
|
||||
assert( pTab->bStat1==0 || i!=1 );
|
||||
*pbNullPK = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -856,7 +846,6 @@ static int sessionMergeUpdate(
|
||||
*/
|
||||
static int sessionPreupdateEqual(
|
||||
sqlite3_session *pSession, /* Session object that owns SessionTable */
|
||||
i64 iRowid, /* Rowid value if pTab->bRowid */
|
||||
SessionTable *pTab, /* Table associated with change */
|
||||
SessionChange *pChange, /* Change to compare to */
|
||||
int op /* Current pre-update operation */
|
||||
@@ -864,11 +853,6 @@ static int sessionPreupdateEqual(
|
||||
int iCol; /* Used to iterate through columns */
|
||||
u8 *a = pChange->aRecord; /* Cursor used to scan change record */
|
||||
|
||||
if( pTab->bRowid ){
|
||||
if( a[0]!=SQLITE_INTEGER ) return 0;
|
||||
return sessionGetI64(&a[1])==iRowid;
|
||||
}
|
||||
|
||||
assert( op==SQLITE_INSERT || op==SQLITE_UPDATE || op==SQLITE_DELETE );
|
||||
for(iCol=0; iCol<pTab->nCol; iCol++){
|
||||
if( !pTab->abPK[iCol] ){
|
||||
@@ -891,7 +875,6 @@ static int sessionPreupdateEqual(
|
||||
rc = pSession->hook.xOld(pSession->hook.pCtx, iCol, &pVal);
|
||||
}
|
||||
assert( rc==SQLITE_OK );
|
||||
(void)rc; /* Suppress warning about unused variable */
|
||||
if( sqlite3_value_type(pVal)!=eType ) return 0;
|
||||
|
||||
/* A SessionChange object never has a NULL value in a PK column */
|
||||
@@ -1014,8 +997,7 @@ static int sessionTableInfo(
|
||||
int *pnCol, /* OUT: number of columns */
|
||||
const char **pzTab, /* OUT: Copy of zThis */
|
||||
const char ***pazCol, /* OUT: Array of column names for table */
|
||||
u8 **pabPK, /* OUT: Array of booleans - true for PK col */
|
||||
int *pbRowid /* OUT: True if only PK is a rowid */
|
||||
u8 **pabPK /* OUT: Array of booleans - true for PK col */
|
||||
){
|
||||
char *zPragma;
|
||||
sqlite3_stmt *pStmt;
|
||||
@@ -1027,7 +1009,6 @@ static int sessionTableInfo(
|
||||
u8 *pAlloc = 0;
|
||||
char **azCol = 0;
|
||||
u8 *abPK = 0;
|
||||
int bRowid = 0; /* Set to true to use rowid as PK */
|
||||
|
||||
assert( pazCol && pabPK );
|
||||
|
||||
@@ -1072,15 +1053,10 @@ static int sessionTableInfo(
|
||||
}
|
||||
|
||||
nByte = nThis + 1;
|
||||
bRowid = (pbRowid!=0);
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
nByte += sqlite3_column_bytes(pStmt, 1);
|
||||
nDbCol++;
|
||||
if( sqlite3_column_int(pStmt, 5) ) bRowid = 0;
|
||||
}
|
||||
if( nDbCol==0 ) bRowid = 0;
|
||||
nDbCol += bRowid;
|
||||
nByte += strlen(SESSIONS_ROWID);
|
||||
rc = sqlite3_reset(pStmt);
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -1102,14 +1078,6 @@ static int sessionTableInfo(
|
||||
}
|
||||
|
||||
i = 0;
|
||||
if( bRowid ){
|
||||
size_t nName = strlen(SESSIONS_ROWID);
|
||||
memcpy(pAlloc, SESSIONS_ROWID, nName+1);
|
||||
azCol[i] = (char*)pAlloc;
|
||||
pAlloc += nName+1;
|
||||
abPK[i] = 1;
|
||||
i++;
|
||||
}
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
int nName = sqlite3_column_bytes(pStmt, 1);
|
||||
const unsigned char *zName = sqlite3_column_text(pStmt, 1);
|
||||
@@ -1121,6 +1089,7 @@ static int sessionTableInfo(
|
||||
i++;
|
||||
}
|
||||
rc = sqlite3_reset(pStmt);
|
||||
|
||||
}
|
||||
|
||||
/* If successful, populate the output variables. Otherwise, zero them and
|
||||
@@ -1137,7 +1106,6 @@ static int sessionTableInfo(
|
||||
if( pzTab ) *pzTab = 0;
|
||||
sessionFree(pSession, azCol);
|
||||
}
|
||||
if( pbRowid ) *pbRowid = bRowid;
|
||||
sqlite3_finalize(pStmt);
|
||||
return rc;
|
||||
}
|
||||
@@ -1159,8 +1127,7 @@ static int sessionInitTable(sqlite3_session *pSession, SessionTable *pTab){
|
||||
u8 *abPK;
|
||||
assert( pTab->azCol==0 || pTab->abPK==0 );
|
||||
pSession->rc = sessionTableInfo(pSession, pSession->db, pSession->zDb,
|
||||
pTab->zName, &pTab->nCol, 0, &pTab->azCol, &abPK,
|
||||
(pSession->bImplicitPK ? &pTab->bRowid : 0)
|
||||
pTab->zName, &pTab->nCol, 0, &pTab->azCol, &abPK
|
||||
);
|
||||
if( pSession->rc==SQLITE_OK ){
|
||||
int i;
|
||||
@@ -1232,7 +1199,6 @@ static int sessionUpdateMaxSize(
|
||||
){
|
||||
i64 nNew = 2;
|
||||
if( pC->op==SQLITE_INSERT ){
|
||||
if( pTab->bRowid ) nNew += 9;
|
||||
if( op!=SQLITE_DELETE ){
|
||||
int ii;
|
||||
for(ii=0; ii<pTab->nCol; ii++){
|
||||
@@ -1249,16 +1215,12 @@ static int sessionUpdateMaxSize(
|
||||
}else{
|
||||
int ii;
|
||||
u8 *pCsr = pC->aRecord;
|
||||
if( pTab->bRowid ){
|
||||
nNew += 9 + 1;
|
||||
pCsr += 9;
|
||||
}
|
||||
for(ii=pTab->bRowid; ii<pTab->nCol; ii++){
|
||||
for(ii=0; ii<pTab->nCol; ii++){
|
||||
int bChanged = 1;
|
||||
int nOld = 0;
|
||||
int eType;
|
||||
sqlite3_value *p = 0;
|
||||
pSession->hook.xNew(pSession->hook.pCtx, ii-pTab->bRowid, &p);
|
||||
pSession->hook.xNew(pSession->hook.pCtx, ii, &p);
|
||||
if( p==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
@@ -1337,7 +1299,6 @@ static int sessionUpdateMaxSize(
|
||||
*/
|
||||
static void sessionPreupdateOneChange(
|
||||
int op, /* One of SQLITE_UPDATE, INSERT, DELETE */
|
||||
i64 iRowid,
|
||||
sqlite3_session *pSession, /* Session object pTab is attached to */
|
||||
SessionTable *pTab /* Table that change applies to */
|
||||
){
|
||||
@@ -1353,7 +1314,7 @@ static void sessionPreupdateOneChange(
|
||||
|
||||
/* Check the number of columns in this xPreUpdate call matches the
|
||||
** number of columns in the table. */
|
||||
if( (pTab->nCol-pTab->bRowid)!=pSession->hook.xCount(pSession->hook.pCtx) ){
|
||||
if( pTab->nCol!=pSession->hook.xCount(pSession->hook.pCtx) ){
|
||||
pSession->rc = SQLITE_SCHEMA;
|
||||
return;
|
||||
}
|
||||
@@ -1386,16 +1347,14 @@ static void sessionPreupdateOneChange(
|
||||
/* Calculate the hash-key for this change. If the primary key of the row
|
||||
** includes a NULL value, exit early. Such changes are ignored by the
|
||||
** session module. */
|
||||
rc = sessionPreupdateHash(
|
||||
pSession, iRowid, pTab, op==SQLITE_INSERT, &iHash, &bNull
|
||||
);
|
||||
rc = sessionPreupdateHash(pSession, pTab, op==SQLITE_INSERT, &iHash, &bNull);
|
||||
if( rc!=SQLITE_OK ) goto error_out;
|
||||
|
||||
if( bNull==0 ){
|
||||
/* Search the hash table for an existing record for this row. */
|
||||
SessionChange *pC;
|
||||
for(pC=pTab->apChange[iHash]; pC; pC=pC->pNext){
|
||||
if( sessionPreupdateEqual(pSession, iRowid, pTab, pC, op) ) break;
|
||||
if( sessionPreupdateEqual(pSession, pTab, pC, op) ) break;
|
||||
}
|
||||
|
||||
if( pC==0 ){
|
||||
@@ -1410,7 +1369,7 @@ static void sessionPreupdateOneChange(
|
||||
|
||||
/* Figure out how large an allocation is required */
|
||||
nByte = sizeof(SessionChange);
|
||||
for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
sqlite3_value *p = 0;
|
||||
if( op!=SQLITE_INSERT ){
|
||||
TESTONLY(int trc = ) pSession->hook.xOld(pSession->hook.pCtx, i, &p);
|
||||
@@ -1425,9 +1384,6 @@ static void sessionPreupdateOneChange(
|
||||
rc = sessionSerializeValue(0, p, &nByte);
|
||||
if( rc!=SQLITE_OK ) goto error_out;
|
||||
}
|
||||
if( pTab->bRowid ){
|
||||
nByte += 9; /* Size of rowid field - an integer */
|
||||
}
|
||||
|
||||
/* Allocate the change object */
|
||||
pC = (SessionChange *)sessionMalloc64(pSession, nByte);
|
||||
@@ -1444,12 +1400,7 @@ static void sessionPreupdateOneChange(
|
||||
** required values and encodings have already been cached in memory.
|
||||
** It is not possible for an OOM to occur in this block. */
|
||||
nByte = 0;
|
||||
if( pTab->bRowid ){
|
||||
pC->aRecord[0] = SQLITE_INTEGER;
|
||||
sessionPutI64(&pC->aRecord[1], iRowid);
|
||||
nByte = 9;
|
||||
}
|
||||
for(i=0; i<(pTab->nCol-pTab->bRowid); i++){
|
||||
for(i=0; i<pTab->nCol; i++){
|
||||
sqlite3_value *p = 0;
|
||||
if( op!=SQLITE_INSERT ){
|
||||
pSession->hook.xOld(pSession->hook.pCtx, i, &p);
|
||||
@@ -1564,10 +1515,9 @@ static void xPreUpdate(
|
||||
pSession->rc = sessionFindTable(pSession, zName, &pTab);
|
||||
if( pTab ){
|
||||
assert( pSession->rc==SQLITE_OK );
|
||||
assert( op==SQLITE_UPDATE || iKey1==iKey2 );
|
||||
sessionPreupdateOneChange(op, iKey1, pSession, pTab);
|
||||
sessionPreupdateOneChange(op, pSession, pTab);
|
||||
if( op==SQLITE_UPDATE ){
|
||||
sessionPreupdateOneChange(SQLITE_INSERT, iKey2, pSession, pTab);
|
||||
sessionPreupdateOneChange(SQLITE_INSERT, pSession, pTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1606,7 +1556,6 @@ static void sessionPreupdateHooks(
|
||||
typedef struct SessionDiffCtx SessionDiffCtx;
|
||||
struct SessionDiffCtx {
|
||||
sqlite3_stmt *pStmt;
|
||||
int bRowid;
|
||||
int nOldOff;
|
||||
};
|
||||
|
||||
@@ -1615,17 +1564,17 @@ struct SessionDiffCtx {
|
||||
*/
|
||||
static int sessionDiffOld(void *pCtx, int iVal, sqlite3_value **ppVal){
|
||||
SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
|
||||
*ppVal = sqlite3_column_value(p->pStmt, iVal+p->nOldOff+p->bRowid);
|
||||
*ppVal = sqlite3_column_value(p->pStmt, iVal+p->nOldOff);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
static int sessionDiffNew(void *pCtx, int iVal, sqlite3_value **ppVal){
|
||||
SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
|
||||
*ppVal = sqlite3_column_value(p->pStmt, iVal+p->bRowid);
|
||||
*ppVal = sqlite3_column_value(p->pStmt, iVal);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
static int sessionDiffCount(void *pCtx){
|
||||
SessionDiffCtx *p = (SessionDiffCtx*)pCtx;
|
||||
return (p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt)) - p->bRowid;
|
||||
return p->nOldOff ? p->nOldOff : sqlite3_column_count(p->pStmt);
|
||||
}
|
||||
static int sessionDiffDepth(void *pCtx){
|
||||
(void)pCtx;
|
||||
@@ -1704,16 +1653,14 @@ static char *sessionExprCompareOther(
|
||||
static char *sessionSelectFindNew(
|
||||
const char *zDb1, /* Pick rows in this db only */
|
||||
const char *zDb2, /* But not in this one */
|
||||
int bRowid,
|
||||
const char *zTbl, /* Table name */
|
||||
const char *zExpr
|
||||
){
|
||||
const char *zSel = (bRowid ? SESSIONS_ROWID ", *" : "*");
|
||||
char *zRet = sqlite3_mprintf(
|
||||
"SELECT %s FROM \"%w\".\"%w\" WHERE NOT EXISTS ("
|
||||
"SELECT * FROM \"%w\".\"%w\" WHERE NOT EXISTS ("
|
||||
" SELECT 1 FROM \"%w\".\"%w\" WHERE %s"
|
||||
")",
|
||||
zSel, zDb1, zTbl, zDb2, zTbl, zExpr
|
||||
zDb1, zTbl, zDb2, zTbl, zExpr
|
||||
);
|
||||
return zRet;
|
||||
}
|
||||
@@ -1727,9 +1674,7 @@ static int sessionDiffFindNew(
|
||||
char *zExpr
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
char *zStmt = sessionSelectFindNew(
|
||||
zDb1, zDb2, pTab->bRowid, pTab->zName, zExpr
|
||||
);
|
||||
char *zStmt = sessionSelectFindNew(zDb1, zDb2, pTab->zName,zExpr);
|
||||
|
||||
if( zStmt==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
@@ -1740,10 +1685,8 @@ static int sessionDiffFindNew(
|
||||
SessionDiffCtx *pDiffCtx = (SessionDiffCtx*)pSession->hook.pCtx;
|
||||
pDiffCtx->pStmt = pStmt;
|
||||
pDiffCtx->nOldOff = 0;
|
||||
pDiffCtx->bRowid = pTab->bRowid;
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
|
||||
sessionPreupdateOneChange(op, iRowid, pSession, pTab);
|
||||
sessionPreupdateOneChange(op, pSession, pTab);
|
||||
}
|
||||
rc = sqlite3_finalize(pStmt);
|
||||
}
|
||||
@@ -1753,27 +1696,6 @@ static int sessionDiffFindNew(
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return a comma-separated list of the fully-qualified (with both database
|
||||
** and table name) column names from table pTab. e.g.
|
||||
**
|
||||
** "main"."t1"."a", "main"."t1"."b", "main"."t1"."c"
|
||||
*/
|
||||
static char *sessionAllCols(
|
||||
const char *zDb,
|
||||
SessionTable *pTab
|
||||
){
|
||||
int ii;
|
||||
char *zRet = 0;
|
||||
for(ii=0; ii<pTab->nCol; ii++){
|
||||
zRet = sqlite3_mprintf("%z%s\"%w\".\"%w\".\"%w\"",
|
||||
zRet, (zRet ? ", " : ""), zDb, pTab->zName, pTab->azCol[ii]
|
||||
);
|
||||
if( !zRet ) break;
|
||||
}
|
||||
return zRet;
|
||||
}
|
||||
|
||||
static int sessionDiffFindModified(
|
||||
sqlite3_session *pSession,
|
||||
SessionTable *pTab,
|
||||
@@ -1788,13 +1710,11 @@ static int sessionDiffFindModified(
|
||||
if( zExpr2==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
char *z1 = sessionAllCols(pSession->zDb, pTab);
|
||||
char *z2 = sessionAllCols(zFrom, pTab);
|
||||
char *zStmt = sqlite3_mprintf(
|
||||
"SELECT %s,%s FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)",
|
||||
z1, z2, pSession->zDb, pTab->zName, zFrom, pTab->zName, zExpr, zExpr2
|
||||
"SELECT * FROM \"%w\".\"%w\", \"%w\".\"%w\" WHERE %s AND (%z)",
|
||||
pSession->zDb, pTab->zName, zFrom, pTab->zName, zExpr, zExpr2
|
||||
);
|
||||
if( zStmt==0 || z1==0 || z2==0 ){
|
||||
if( zStmt==0 ){
|
||||
rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
sqlite3_stmt *pStmt;
|
||||
@@ -1805,15 +1725,12 @@ static int sessionDiffFindModified(
|
||||
pDiffCtx->pStmt = pStmt;
|
||||
pDiffCtx->nOldOff = pTab->nCol;
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
i64 iRowid = (pTab->bRowid ? sqlite3_column_int64(pStmt, 0) : 0);
|
||||
sessionPreupdateOneChange(SQLITE_UPDATE, iRowid, pSession, pTab);
|
||||
sessionPreupdateOneChange(SQLITE_UPDATE, pSession, pTab);
|
||||
}
|
||||
rc = sqlite3_finalize(pStmt);
|
||||
}
|
||||
sqlite3_free(zStmt);
|
||||
}
|
||||
sqlite3_free(zStmt);
|
||||
sqlite3_free(z1);
|
||||
sqlite3_free(z2);
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -1852,12 +1769,9 @@ int sqlite3session_diff(
|
||||
int bHasPk = 0;
|
||||
int bMismatch = 0;
|
||||
int nCol; /* Columns in zFrom.zTbl */
|
||||
int bRowid = 0;
|
||||
u8 *abPK;
|
||||
const char **azCol = 0;
|
||||
rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, &abPK,
|
||||
pSession->bImplicitPK ? &bRowid : 0
|
||||
);
|
||||
rc = sessionTableInfo(0, db, zFrom, zTbl, &nCol, 0, &azCol, &abPK);
|
||||
if( rc==SQLITE_OK ){
|
||||
if( pTo->nCol!=nCol ){
|
||||
bMismatch = 1;
|
||||
@@ -2199,10 +2113,9 @@ static void sessionAppendStr(
|
||||
int *pRc
|
||||
){
|
||||
int nStr = sqlite3Strlen30(zStr);
|
||||
if( 0==sessionBufferGrow(p, nStr+1, pRc) ){
|
||||
if( 0==sessionBufferGrow(p, nStr, pRc) ){
|
||||
memcpy(&p->aBuf[p->nBuf], zStr, nStr);
|
||||
p->nBuf += nStr;
|
||||
p->aBuf[p->nBuf] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2224,27 +2137,6 @@ static void sessionAppendInteger(
|
||||
sessionAppendStr(p, aBuf, pRc);
|
||||
}
|
||||
|
||||
static void sessionAppendPrintf(
|
||||
SessionBuffer *p, /* Buffer to append to */
|
||||
int *pRc,
|
||||
const char *zFmt,
|
||||
...
|
||||
){
|
||||
if( *pRc==SQLITE_OK ){
|
||||
char *zApp = 0;
|
||||
va_list ap;
|
||||
va_start(ap, zFmt);
|
||||
zApp = sqlite3_vmprintf(zFmt, ap);
|
||||
if( zApp==0 ){
|
||||
*pRc = SQLITE_NOMEM;
|
||||
}else{
|
||||
sessionAppendStr(p, zApp, pRc);
|
||||
}
|
||||
va_end(ap);
|
||||
sqlite3_free(zApp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is a no-op if *pRc is other than SQLITE_OK when it is
|
||||
** called. Otherwise, append the string zStr enclosed in quotes (") and
|
||||
@@ -2259,7 +2151,7 @@ static void sessionAppendIdent(
|
||||
const char *zStr, /* String to quote, escape and append */
|
||||
int *pRc /* IN/OUT: Error code */
|
||||
){
|
||||
int nStr = sqlite3Strlen30(zStr)*2 + 2 + 2;
|
||||
int nStr = sqlite3Strlen30(zStr)*2 + 2 + 1;
|
||||
if( 0==sessionBufferGrow(p, nStr, pRc) ){
|
||||
char *zOut = (char *)&p->aBuf[p->nBuf];
|
||||
const char *zIn = zStr;
|
||||
@@ -2270,7 +2162,6 @@ static void sessionAppendIdent(
|
||||
}
|
||||
*zOut++ = '"';
|
||||
p->nBuf = (int)((u8 *)zOut - p->aBuf);
|
||||
p->aBuf[p->nBuf] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2406,7 +2297,7 @@ static int sessionAppendUpdate(
|
||||
/* If at least one field has been modified, this is not a no-op. */
|
||||
if( bChanged ) bNoop = 0;
|
||||
|
||||
/* Add a field to the old.* record. This is omitted if this module is
|
||||
/* Add a field to the old.* record. This is omitted if this modules is
|
||||
** currently generating a patchset. */
|
||||
if( bPatchset==0 ){
|
||||
if( bChanged || abPK[i] ){
|
||||
@@ -2495,20 +2386,12 @@ static int sessionAppendDelete(
|
||||
** Formulate and prepare a SELECT statement to retrieve a row from table
|
||||
** zTab in database zDb based on its primary key. i.e.
|
||||
**
|
||||
** SELECT *, <noop-test> FROM zDb.zTab WHERE (pk1, pk2,...) IS (?1, ?2,...)
|
||||
**
|
||||
** where <noop-test> is:
|
||||
**
|
||||
** 1 AND (?A OR ?1 IS <column>) AND ...
|
||||
**
|
||||
** for each non-pk <column>.
|
||||
** SELECT * FROM zDb.zTab WHERE pk1 = ? AND pk2 = ? AND ...
|
||||
*/
|
||||
static int sessionSelectStmt(
|
||||
sqlite3 *db, /* Database handle */
|
||||
int bIgnoreNoop,
|
||||
const char *zDb, /* Database name */
|
||||
const char *zTab, /* Table name */
|
||||
int bRowid,
|
||||
int nCol, /* Number of columns in table */
|
||||
const char **azCol, /* Names of table columns */
|
||||
u8 *abPK, /* PRIMARY KEY array */
|
||||
@@ -2516,50 +2399,8 @@ static int sessionSelectStmt(
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
char *zSql = 0;
|
||||
const char *zSep = "";
|
||||
const char *zCols = bRowid ? SESSIONS_ROWID ", *" : "*";
|
||||
int nSql = -1;
|
||||
int i;
|
||||
|
||||
SessionBuffer nooptest = {0, 0, 0};
|
||||
SessionBuffer pkfield = {0, 0, 0};
|
||||
SessionBuffer pkvar = {0, 0, 0};
|
||||
|
||||
sessionAppendStr(&nooptest, ", 1", &rc);
|
||||
|
||||
if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
|
||||
sessionAppendStr(&nooptest, " AND (?6 OR ?3 IS stat)", &rc);
|
||||
sessionAppendStr(&pkfield, "tbl, idx", &rc);
|
||||
sessionAppendStr(&pkvar,
|
||||
"?1, (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", &rc
|
||||
);
|
||||
zCols = "tbl, ?2, stat";
|
||||
}else{
|
||||
for(i=0; i<nCol; i++){
|
||||
if( abPK[i] ){
|
||||
sessionAppendStr(&pkfield, zSep, &rc);
|
||||
sessionAppendStr(&pkvar, zSep, &rc);
|
||||
zSep = ", ";
|
||||
sessionAppendIdent(&pkfield, azCol[i], &rc);
|
||||
sessionAppendPrintf(&pkvar, &rc, "?%d", i+1);
|
||||
}else{
|
||||
sessionAppendPrintf(&nooptest, &rc,
|
||||
" AND (?%d OR ?%d IS %w.%w)", i+1+nCol, i+1, zTab, azCol[i]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT %s%s FROM %Q.%Q WHERE (%s) IS (%s)",
|
||||
zCols, (bIgnoreNoop ? (char*)nooptest.aBuf : ""),
|
||||
zDb, zTab, (char*)pkfield.aBuf, (char*)pkvar.aBuf
|
||||
);
|
||||
if( zSql==0 ) rc = SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT tbl, ?2, stat FROM %Q.sqlite_stat1 WHERE tbl IS ?1 AND "
|
||||
@@ -2567,6 +2408,7 @@ static int sessionSelectStmt(
|
||||
);
|
||||
if( zSql==0 ) rc = SQLITE_NOMEM;
|
||||
}else{
|
||||
int i;
|
||||
const char *zSep = "";
|
||||
SessionBuffer buf = {0, 0, 0};
|
||||
|
||||
@@ -2587,15 +2429,11 @@ static int sessionSelectStmt(
|
||||
zSql = (char*)buf.aBuf;
|
||||
nSql = buf.nBuf;
|
||||
}
|
||||
#endif
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_prepare_v2(db, zSql, nSql, ppStmt, 0);
|
||||
}
|
||||
sqlite3_free(zSql);
|
||||
sqlite3_free(nooptest.aBuf);
|
||||
sqlite3_free(pkfield.aBuf);
|
||||
sqlite3_free(pkvar.aBuf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2742,18 +2580,10 @@ static int sessionGenerateChangeset(
|
||||
sqlite3_stmt *pSel = 0; /* SELECT statement to query table pTab */
|
||||
int nRewind = buf.nBuf; /* Initial size of write buffer */
|
||||
int nNoop; /* Size of buffer after writing tbl header */
|
||||
int bRowid = 0;
|
||||
|
||||
/* Check the table schema is still Ok. */
|
||||
rc = sessionTableInfo(
|
||||
0, db, pSession->zDb, zName, &nCol, 0, &azCol, &abPK,
|
||||
(pSession->bImplicitPK ? &bRowid : 0)
|
||||
);
|
||||
if( rc==SQLITE_OK && (
|
||||
pTab->nCol!=nCol
|
||||
|| pTab->bRowid!=bRowid
|
||||
|| memcmp(abPK, pTab->abPK, nCol)
|
||||
)){
|
||||
rc = sessionTableInfo(0, db, pSession->zDb, zName, &nCol, 0,&azCol,&abPK);
|
||||
if( !rc && (pTab->nCol!=nCol || memcmp(abPK, pTab->abPK, nCol)) ){
|
||||
rc = SQLITE_SCHEMA;
|
||||
}
|
||||
|
||||
@@ -2763,8 +2593,7 @@ static int sessionGenerateChangeset(
|
||||
/* Build and compile a statement to execute: */
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sessionSelectStmt(
|
||||
db, 0, pSession->zDb, zName, bRowid, nCol, azCol, abPK, &pSel
|
||||
);
|
||||
db, pSession->zDb, zName, nCol, azCol, abPK, &pSel);
|
||||
}
|
||||
|
||||
nNoop = buf.nBuf;
|
||||
@@ -2847,7 +2676,7 @@ int sqlite3session_changeset(
|
||||
int rc;
|
||||
|
||||
if( pnChangeset==0 || ppChangeset==0 ) return SQLITE_MISUSE;
|
||||
rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset, ppChangeset);
|
||||
rc = sessionGenerateChangeset(pSession, 0, 0, 0, pnChangeset,ppChangeset);
|
||||
assert( rc || pnChangeset==0
|
||||
|| pSession->bEnableSize==0 || *pnChangeset<=pSession->nMaxChangesetSize
|
||||
);
|
||||
@@ -2965,19 +2794,6 @@ int sqlite3session_object_config(sqlite3_session *pSession, int op, void *pArg){
|
||||
break;
|
||||
}
|
||||
|
||||
case SQLITE_SESSION_OBJCONFIG_ROWID: {
|
||||
int iArg = *(int*)pArg;
|
||||
if( iArg>=0 ){
|
||||
if( pSession->pTable ){
|
||||
rc = SQLITE_MISUSE;
|
||||
}else{
|
||||
pSession->bImplicitPK = (iArg!=0);
|
||||
}
|
||||
}
|
||||
*(int*)pArg = pSession->bImplicitPK;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
rc = SQLITE_MISUSE;
|
||||
}
|
||||
@@ -3966,8 +3782,6 @@ struct SessionApplyCtx {
|
||||
SessionBuffer rebase; /* Rebase information (if any) here */
|
||||
u8 bRebaseStarted; /* If table header is already in rebase */
|
||||
u8 bRebase; /* True to collect rebase information */
|
||||
u8 bIgnoreNoop; /* True to ignore no-op conflicts */
|
||||
int bRowid;
|
||||
};
|
||||
|
||||
/* Number of prepared UPDATE statements to cache. */
|
||||
@@ -4218,10 +4032,8 @@ static int sessionSelectRow(
|
||||
const char *zTab, /* Table name */
|
||||
SessionApplyCtx *p /* Session changeset-apply context */
|
||||
){
|
||||
/* TODO */
|
||||
return sessionSelectStmt(db, p->bIgnoreNoop,
|
||||
"main", zTab, p->bRowid, p->nCol, p->azCol, p->abPK, &p->pSelect
|
||||
);
|
||||
return sessionSelectStmt(
|
||||
db, "main", zTab, p->nCol, p->azCol, p->abPK, &p->pSelect);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4380,33 +4192,20 @@ static int sessionBindRow(
|
||||
*/
|
||||
static int sessionSeekToRow(
|
||||
sqlite3_changeset_iter *pIter, /* Changeset iterator */
|
||||
SessionApplyCtx *p
|
||||
u8 *abPK, /* Primary key flags array */
|
||||
sqlite3_stmt *pSelect /* SELECT statement from sessionSelectRow() */
|
||||
){
|
||||
sqlite3_stmt *pSelect = p->pSelect;
|
||||
int rc; /* Return code */
|
||||
int nCol; /* Number of columns in table */
|
||||
int op; /* Changset operation (SQLITE_UPDATE etc.) */
|
||||
const char *zDummy; /* Unused */
|
||||
|
||||
sqlite3_clear_bindings(pSelect);
|
||||
sqlite3changeset_op(pIter, &zDummy, &nCol, &op, 0);
|
||||
rc = sessionBindRow(pIter,
|
||||
op==SQLITE_INSERT ? sqlite3changeset_new : sqlite3changeset_old,
|
||||
nCol, p->abPK, pSelect
|
||||
nCol, abPK, pSelect
|
||||
);
|
||||
|
||||
if( op!=SQLITE_DELETE && p->bIgnoreNoop ){
|
||||
int ii;
|
||||
for(ii=0; rc==SQLITE_OK && ii<nCol; ii++){
|
||||
if( p->abPK[ii]==0 ){
|
||||
sqlite3_value *pVal = 0;
|
||||
sqlite3changeset_new(pIter, ii, &pVal);
|
||||
sqlite3_bind_int(pSelect, ii+1+nCol, (pVal==0));
|
||||
if( pVal ) rc = sessionBindValue(pSelect, ii+1, pVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_step(pSelect);
|
||||
if( rc!=SQLITE_ROW ) rc = sqlite3_reset(pSelect);
|
||||
@@ -4521,22 +4320,16 @@ static int sessionConflictHandler(
|
||||
|
||||
/* Bind the new.* PRIMARY KEY values to the SELECT statement. */
|
||||
if( pbReplace ){
|
||||
rc = sessionSeekToRow(pIter, p);
|
||||
rc = sessionSeekToRow(pIter, p->abPK, p->pSelect);
|
||||
}else{
|
||||
rc = SQLITE_OK;
|
||||
}
|
||||
|
||||
if( rc==SQLITE_ROW ){
|
||||
/* There exists another row with the new.* primary key. */
|
||||
if( p->bIgnoreNoop
|
||||
&& sqlite3_column_int(p->pSelect, sqlite3_column_count(p->pSelect)-1)
|
||||
){
|
||||
res = SQLITE_CHANGESET_OMIT;
|
||||
}else{
|
||||
pIter->pConflict = p->pSelect;
|
||||
res = xConflict(pCtx, eType, pIter);
|
||||
pIter->pConflict = 0;
|
||||
}
|
||||
pIter->pConflict = p->pSelect;
|
||||
res = xConflict(pCtx, eType, pIter);
|
||||
pIter->pConflict = 0;
|
||||
rc = sqlite3_reset(p->pSelect);
|
||||
}else if( rc==SQLITE_OK ){
|
||||
if( p->bDeferConstraints && eType==SQLITE_CHANGESET_CONFLICT ){
|
||||
@@ -4644,7 +4437,7 @@ static int sessionApplyOneOp(
|
||||
|
||||
sqlite3_step(p->pDelete);
|
||||
rc = sqlite3_reset(p->pDelete);
|
||||
if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 && p->bIgnoreNoop==0 ){
|
||||
if( rc==SQLITE_OK && sqlite3_changes(p->db)==0 ){
|
||||
rc = sessionConflictHandler(
|
||||
SQLITE_CHANGESET_DATA, p, pIter, xConflict, pCtx, pbRetry
|
||||
);
|
||||
@@ -4701,7 +4494,7 @@ static int sessionApplyOneOp(
|
||||
/* Check if there is a conflicting row. For sqlite_stat1, this needs
|
||||
** to be done using a SELECT, as there is no PRIMARY KEY in the
|
||||
** database schema to throw an exception if a duplicate is inserted. */
|
||||
rc = sessionSeekToRow(pIter, p);
|
||||
rc = sessionSeekToRow(pIter, p->abPK, p->pSelect);
|
||||
if( rc==SQLITE_ROW ){
|
||||
rc = SQLITE_CONSTRAINT;
|
||||
sqlite3_reset(p->pSelect);
|
||||
@@ -4878,7 +4671,6 @@ static int sessionChangesetApply(
|
||||
memset(&sApply, 0, sizeof(sApply));
|
||||
sApply.bRebase = (ppRebase && pnRebase);
|
||||
sApply.bInvertConstraints = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
|
||||
sApply.bIgnoreNoop = !!(flags & SQLITE_CHANGESETAPPLY_IGNORENOOP);
|
||||
sqlite3_mutex_enter(sqlite3_db_mutex(db));
|
||||
if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
|
||||
rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
|
||||
@@ -4916,7 +4708,6 @@ static int sessionChangesetApply(
|
||||
sApply.bStat1 = 0;
|
||||
sApply.bDeferConstraints = 1;
|
||||
sApply.bRebaseStarted = 0;
|
||||
sApply.bRowid = 0;
|
||||
memset(&sApply.constraints, 0, sizeof(SessionBuffer));
|
||||
|
||||
/* If an xFilter() callback was specified, invoke it now. If the
|
||||
@@ -4936,8 +4727,8 @@ static int sessionChangesetApply(
|
||||
int i;
|
||||
|
||||
sqlite3changeset_pk(pIter, &abPK, 0);
|
||||
rc = sessionTableInfo(0, db, "main", zNew,
|
||||
&sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK, &sApply.bRowid
|
||||
rc = sessionTableInfo(0,
|
||||
db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK
|
||||
);
|
||||
if( rc!=SQLITE_OK ) break;
|
||||
for(i=0; i<sApply.nCol; i++){
|
||||
|
||||
@@ -80,20 +80,16 @@ int sqlite3session_create(
|
||||
void sqlite3session_delete(sqlite3_session *pSession);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Configure a Session Object
|
||||
** CAPIREF: Conigure a Session Object
|
||||
** METHOD: sqlite3_session
|
||||
**
|
||||
** This method is used to configure a session object after it has been
|
||||
** created. At present the only valid values for the second parameter are
|
||||
** [SQLITE_SESSION_OBJCONFIG_SIZE] and [SQLITE_SESSION_OBJCONFIG_ROWID].
|
||||
** created. At present the only valid value for the second parameter is
|
||||
** [SQLITE_SESSION_OBJCONFIG_SIZE].
|
||||
**
|
||||
*/
|
||||
int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Options for sqlite3session_object_config
|
||||
** Arguments for sqlite3session_object_config()
|
||||
**
|
||||
** The following values may passed as the the 2nd parameter to
|
||||
** The following values may passed as the the 4th parameter to
|
||||
** sqlite3session_object_config().
|
||||
**
|
||||
** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
|
||||
@@ -109,21 +105,12 @@ int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
|
||||
**
|
||||
** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
|
||||
** the first table has been attached to the session object.
|
||||
**
|
||||
** <dt>SQLITE_SESSION_OBJCONFIG_ROWID <dd>
|
||||
** This option is used to set, clear or query the flag that enables
|
||||
** collection of data for tables with no explicit PRIMARY KEY.
|
||||
**
|
||||
** Normally, tables with no explicit PRIMARY KEY are simply ignored
|
||||
** by the sessions module. However, if this flag is set, it behaves
|
||||
** as if such tables have a column "_rowid_ INTEGER PRIMARY KEY" inserted
|
||||
** as their leftmost columns.
|
||||
**
|
||||
** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
|
||||
** the first table has been attached to the session object.
|
||||
*/
|
||||
#define SQLITE_SESSION_OBJCONFIG_SIZE 1
|
||||
#define SQLITE_SESSION_OBJCONFIG_ROWID 2
|
||||
int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
|
||||
|
||||
/*
|
||||
*/
|
||||
#define SQLITE_SESSION_OBJCONFIG_SIZE 1
|
||||
|
||||
/*
|
||||
** CAPI3REF: Enable Or Disable A Session Object
|
||||
@@ -1256,23 +1243,9 @@ int sqlite3changeset_apply_v2(
|
||||
** Invert the changeset before applying it. This is equivalent to inverting
|
||||
** a changeset using sqlite3changeset_invert() before applying it. It is
|
||||
** an error to specify this flag with a patchset.
|
||||
**
|
||||
** <dt>SQLITE_CHANGESETAPPLY_IGNORENOOP <dd>
|
||||
** Do not invoke the conflict handler callback for any changes that
|
||||
** would not actually modify the database even if they were applied.
|
||||
** Specifically, this means that the conflict handler is not invoked
|
||||
** for:
|
||||
** <ul>
|
||||
** <li>a delete change if the row being deleted cannot be found,
|
||||
** <li>an update change if the modified fields are already set to
|
||||
** their new values in the conflicting row, or
|
||||
** <li>an insert change if all fields of the conflicting row match
|
||||
** the row being inserted.
|
||||
** </ul>
|
||||
*/
|
||||
#define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001
|
||||
#define SQLITE_CHANGESETAPPLY_INVERT 0x0002
|
||||
#define SQLITE_CHANGESETAPPLY_IGNORENOOP 0x0004
|
||||
|
||||
/*
|
||||
** CAPI3REF: Constants Passed To The Conflict Handler
|
||||
|
||||
+18
-31
@@ -76,11 +76,9 @@ int sql_exec_changeset(
|
||||
){
|
||||
sqlite3_session *pSession = 0;
|
||||
int rc;
|
||||
int val = 1;
|
||||
|
||||
/* Create a new session object */
|
||||
rc = sqlite3session_create(db, "main", &pSession);
|
||||
sqlite3session_object_config(pSession, SQLITE_SESSION_OBJCONFIG_ROWID, &val);
|
||||
|
||||
/* Configure the session object to record changes to all tables */
|
||||
if( rc==SQLITE_OK ) rc = sqlite3session_attach(pSession, NULL);
|
||||
@@ -262,7 +260,7 @@ static int SQLITE_TCLAPI test_session_cmd(
|
||||
{ "diff", 2, "FROMDB TBL", }, /* 8 */
|
||||
{ "memory_used", 0, "", }, /* 9 */
|
||||
{ "changeset_size", 0, "", }, /* 10 */
|
||||
{ "object_config", 2, "OPTION INTEGER", }, /* 11 */
|
||||
{ "object_config_size", 1, "INTEGER", }, /* 11 */
|
||||
{ 0 }
|
||||
};
|
||||
int iSub;
|
||||
@@ -381,27 +379,15 @@ static int SQLITE_TCLAPI test_session_cmd(
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(nSize));
|
||||
break;
|
||||
}
|
||||
case 11: { /* object_config */
|
||||
struct ObjConfOpt {
|
||||
const char *zName;
|
||||
int opt;
|
||||
} aOpt[] = {
|
||||
{ "size", SQLITE_SESSION_OBJCONFIG_SIZE },
|
||||
{ "rowid", SQLITE_SESSION_OBJCONFIG_ROWID },
|
||||
{ 0, 0 }
|
||||
};
|
||||
size_t sz = sizeof(aOpt[0]);
|
||||
|
||||
case 11: {
|
||||
int rc;
|
||||
int iArg;
|
||||
int iOpt;
|
||||
if( Tcl_GetIndexFromObjStruct(interp,objv[2],aOpt,sz,"option",0,&iOpt) ){
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &iArg) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetIntFromObj(interp, objv[3], &iArg) ){
|
||||
return TCL_ERROR;
|
||||
}
|
||||
rc = sqlite3session_object_config(pSession, aOpt[iOpt].opt, &iArg);
|
||||
rc = sqlite3session_object_config(
|
||||
pSession, SQLITE_SESSION_OBJCONFIG_SIZE, &iArg
|
||||
);
|
||||
if( rc!=SQLITE_OK ){
|
||||
extern const char *sqlite3ErrName(int);
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
|
||||
@@ -807,31 +793,32 @@ static int SQLITE_TCLAPI testSqlite3changesetApply(
|
||||
memset(&sStr, 0, sizeof(sStr));
|
||||
sStr.nStream = test_tcl_integer(interp, SESSION_STREAM_TCL_VAR);
|
||||
|
||||
/* Check for the -nosavepoint, -invert or -ignorenoop switches */
|
||||
/* Check for the -nosavepoint flag */
|
||||
if( bV2 ){
|
||||
while( objc>1 ){
|
||||
if( objc>1 ){
|
||||
const char *z1 = Tcl_GetString(objv[1]);
|
||||
int n = strlen(z1);
|
||||
if( n>1 && n<=12 && 0==sqlite3_strnicmp("-nosavepoint", z1, n) ){
|
||||
flags |= SQLITE_CHANGESETAPPLY_NOSAVEPOINT;
|
||||
objc--;
|
||||
objv++;
|
||||
}
|
||||
else if( n>2 && n<=7 && 0==sqlite3_strnicmp("-invert", z1, n) ){
|
||||
}
|
||||
if( objc>1 ){
|
||||
const char *z1 = Tcl_GetString(objv[1]);
|
||||
int n = strlen(z1);
|
||||
if( n>1 && n<=7 && 0==sqlite3_strnicmp("-invert", z1, n) ){
|
||||
flags |= SQLITE_CHANGESETAPPLY_INVERT;
|
||||
objc--;
|
||||
objv++;
|
||||
}
|
||||
else if( n>2 && n<=11 && 0==sqlite3_strnicmp("-ignorenoop", z1, n) ){
|
||||
flags |= SQLITE_CHANGESETAPPLY_IGNORENOOP;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
objc--;
|
||||
objv++;
|
||||
}
|
||||
}
|
||||
|
||||
if( objc!=4 && objc!=5 ){
|
||||
const char *zMsg;
|
||||
if( bV2 ){
|
||||
zMsg = "?-nosavepoint? ?-inverse? ?-ignorenoop? "
|
||||
zMsg = "?-nosavepoint? ?-inverse? "
|
||||
"DB CHANGESET CONFLICT-SCRIPT ?FILTER-SCRIPT?";
|
||||
}else{
|
||||
zMsg = "DB CHANGESET CONFLICT-SCRIPT ?FILTER-SCRIPT?";
|
||||
|
||||
+130
-246
@@ -18,6 +18,8 @@
|
||||
# quick, q = do just a minimal build (sqlite3.js/wasm, tester1) for
|
||||
# faster development-mode turnaround.
|
||||
#
|
||||
# qo2, qoz = a combination of quick+o2/oz.
|
||||
#
|
||||
# dist = create end user deliverables. Add dist.build=oX to build
|
||||
# with a specific optimization level, where oX is one of the
|
||||
# above-listed o? or qo? target names.
|
||||
@@ -42,18 +44,15 @@
|
||||
# 1) Consolidate the code generation for sqlite3*.*js into a script
|
||||
# which generates the makefile code, rather than using $(call) and
|
||||
# $(eval), or at least centralize the setup of the numerous vars
|
||||
# related to each build variant $(JS_BUILD_MODES).
|
||||
# related to each build variant (vanilla, esm, bundler-friendly).
|
||||
#
|
||||
default: all
|
||||
#default: quick
|
||||
SHELL := $(shell which bash 2>/dev/null)
|
||||
MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
||||
CLEAN_FILES :=
|
||||
DISTCLEAN_FILES := ./--dummy--
|
||||
default: all
|
||||
release: oz
|
||||
# JS_BUILD_MODES exists solely to reduce repetition in documentation
|
||||
# below.
|
||||
JS_BUILD_MODES := vanilla esm bunder-friendly node
|
||||
|
||||
# Emscripten SDK home dir and related binaries...
|
||||
EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/emsdk $(HOME)/src/emsdk))
|
||||
emcc.bin ?= $(word 1,$(wildcard $(EMSDK_HOME)/upstream/emscripten/emcc) $(shell which emcc))
|
||||
@@ -67,6 +66,13 @@ ifeq (,$(emcc.version))
|
||||
else
|
||||
$(info using emcc version [$(emcc.version)])
|
||||
endif
|
||||
emcc.version := $(shell "$(emcc.bin)" --version | sed -n 1p \
|
||||
| sed -e 's/^.* \([3-9][^ ]*\) .*$$/\1/;')
|
||||
ifeq (,$(emcc.version))
|
||||
$(warning Cannot determine emcc version. This might unduly impact build flags.)
|
||||
else
|
||||
$(info using emcc version [$(emcc.version)])
|
||||
endif
|
||||
|
||||
wasm-strip ?= $(shell which wasm-strip 2>/dev/null)
|
||||
ifeq (,$(filter clean,$(MAKECMDGOALS)))
|
||||
@@ -139,30 +145,8 @@ ifeq (,$(wildcard $(dir.tmp)))
|
||||
dir._tmp := $(shell mkdir -p $(dir.tmp))
|
||||
endif
|
||||
|
||||
########################################################################
|
||||
# Set up sqlite3.c and sqlite3.h...
|
||||
#
|
||||
# To build with SEE (https://sqlite.org/see), either put sqlite3-see.c
|
||||
# in the top of this build tree or pass
|
||||
# sqlite3.c=PATH_TO_sqlite3-see.c to the build. Note that only
|
||||
# encryption modules with no 3rd-party dependencies will currently
|
||||
# work here: AES256-OFB, AES128-OFB, and AES128-CCM. Not
|
||||
# coincidentally, those 3 modules are included in the sqlite3-see.c
|
||||
# bundle.
|
||||
#
|
||||
# A custom sqlite3.c must not have any spaces in its name.
|
||||
# $(sqlite3.canonical.c) must point to the sqlite3.c in
|
||||
# the sqlite3 canonical source tree, as that source file
|
||||
# is required for certain utility and test code.
|
||||
sqlite3.canonical.c := $(dir.top)/sqlite3.c
|
||||
sqlite3.c ?= $(firstword $(wildcard $(dir.top)/sqlite3-see.c) $(sqlite3.canonical.c))
|
||||
sqlite3.c := $(dir.top)/sqlite3.c
|
||||
sqlite3.h := $(dir.top)/sqlite3.h
|
||||
ifeq (,$(shell grep sqlite3_activate_see $(sqlite3.c) 2>/dev/null))
|
||||
SQLITE_C_IS_SEE := 0
|
||||
else
|
||||
SQLITE_C_IS_SEE := 1
|
||||
$(info This is an SEE build.)
|
||||
endif
|
||||
# Most SQLITE_OPT flags are set in sqlite3-wasm.c but we need them
|
||||
# made explicit here for building speedtest1.c.
|
||||
SQLITE_OPT = \
|
||||
@@ -181,17 +165,14 @@ SQLITE_OPT = \
|
||||
-DSQLITE_OMIT_SHARED_CACHE \
|
||||
-DSQLITE_OMIT_WAL \
|
||||
-DSQLITE_THREADSAFE=0 \
|
||||
-DSQLITE_TEMP_STORE=2 \
|
||||
-DSQLITE_TEMP_STORE=3 \
|
||||
-DSQLITE_OS_KV_OPTIONAL=1 \
|
||||
'-DSQLITE_DEFAULT_UNIX_VFS="unix-none"' \
|
||||
-DSQLITE_USE_URI=1 \
|
||||
-DSQLITE_WASM_ENABLE_C_TESTS \
|
||||
-DSQLITE_C=$(sqlite3.c)
|
||||
-DSQLITE_WASM_ENABLE_C_TESTS
|
||||
|
||||
.NOTPARALLEL: $(sqlite3.h)
|
||||
$(sqlite3.h):
|
||||
$(sqlite3.c) $(sqlite3.h):
|
||||
$(MAKE) -C $(dir.top) sqlite3.c
|
||||
$(sqlite3.c): $(sqlite3.h)
|
||||
|
||||
.PHONY: clean distclean
|
||||
clean:
|
||||
@@ -208,42 +189,13 @@ else
|
||||
$(info Development build. Use '$(MAKE) release' for a smaller release build.)
|
||||
endif
|
||||
|
||||
########################################################################
|
||||
# Adding custom C code via sqlite3_wasm_extra_init.c:
|
||||
#
|
||||
# If the canonical build process finds the file
|
||||
# sqlite3_wasm_extra_init.c in the main wasm build directory, it
|
||||
# arranges to include that file in the build of sqlite3.wasm and
|
||||
# defines SQLITE_EXTRA_INIT=sqlite3_wasm_extra_init.
|
||||
#
|
||||
# sqlite3_wasm_extra_init() must be a function with this signature:
|
||||
#
|
||||
# int sqlite3_wasm_extra_init(const char *)
|
||||
#
|
||||
# and the sqlite3 library will call it with an argument of NULL one
|
||||
# time during sqlite3_initialize(). If it returns non-0,
|
||||
# initialization of the library will fail.
|
||||
#
|
||||
# The filename can be overridden with:
|
||||
#
|
||||
# make sqlite3_wasm_extra_init.c=my_custom_stuff.c
|
||||
#
|
||||
# See example_extra_init.c for an example implementation.
|
||||
########################################################################
|
||||
sqlite3_wasm_extra_init.c ?= $(wildcard sqlite3_wasm_extra_init.c)
|
||||
cflags.wasm_extra_init :=
|
||||
ifneq (,$(sqlite3_wasm_extra_init.c))
|
||||
$(info Enabling SQLITE_EXTRA_INIT via $(sqlite3_wasm_extra_init.c).)
|
||||
cflags.wasm_extra_init := -DSQLITE_WASM_EXTRA_INIT
|
||||
endif
|
||||
|
||||
# bin.version-info = binary to output various sqlite3 version info for
|
||||
# embedding in the JS files and in building the distribution zip file.
|
||||
# It must NOT be in $(dir.tmp) because we need it to survive the
|
||||
# cleanup process for the dist build to work properly.
|
||||
bin.version-info := $(dir.wasm)/version-info
|
||||
$(bin.version-info): $(dir.wasm)/version-info.c $(sqlite3.h) $(MAKEFILE)
|
||||
$(CC) -O0 -I$(dir $(sqlite3.c)) -o $@ $<
|
||||
$(CC) -O0 -I$(dir.top) -o $@ $<
|
||||
DISTCLEAN_FILES += $(bin.version-info)
|
||||
|
||||
# bin.stripcomments is used for stripping C/C++-style comments from JS
|
||||
@@ -301,7 +253,7 @@ endef
|
||||
########################################################################
|
||||
|
||||
# cflags.common = C compiler flags for all builds
|
||||
cflags.common := -I. -I$(dir $(sqlite3.c))
|
||||
cflags.common := -I. -I.. -I$(dir.top)
|
||||
# emcc.WASM_BIGINT = 1 for BigInt (C int64) support, else 0. The API
|
||||
# disables certain features if BigInt is not enabled and such builds
|
||||
# _are not tested_ on any regular basis.
|
||||
@@ -344,14 +296,10 @@ emcc_opt_full := $(emcc_opt) -g3
|
||||
|
||||
# EXPORTED_FUNCTIONS.* = files for use with Emscripten's
|
||||
# -sEXPORTED_FUNCTION flag.
|
||||
EXPORTED_FUNCTIONS.api.main := $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api)
|
||||
EXPORTED_FUNCTIONS.api.in := $(EXPORTED_FUNCTIONS.api.main)
|
||||
ifeq (1,$(SQLITE_C_IS_SEE))
|
||||
EXPORTED_FUNCTIONS.api.in += $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see)
|
||||
endif
|
||||
EXPORTED_FUNCTIONS.api.in := $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api)
|
||||
EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api
|
||||
$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE)
|
||||
cat $(EXPORTED_FUNCTIONS.api.in) > $@
|
||||
$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE)
|
||||
cp $(EXPORTED_FUNCTIONS.api.in) $@
|
||||
|
||||
# sqlite3-license-version.js = generated JS file with the license
|
||||
# header and version info.
|
||||
@@ -374,17 +322,20 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-v-helper.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs.c-pp.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs-sahpool.c-pp.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js
|
||||
|
||||
# SOAP.js is an external API file which is part of our distribution
|
||||
# "External" API files which are part of our distribution
|
||||
# but not part of the sqlite3-api.js amalgamation.
|
||||
SOAP.js := $(dir.api)/sqlite3-opfs-async-proxy.js
|
||||
SOAP.js.bld := $(dir.dout)/$(notdir $(SOAP.js))
|
||||
sqlite3-api.ext.jses += $(SOAP.js.bld)
|
||||
$(SOAP.js.bld): $(SOAP.js)
|
||||
cp $< $@
|
||||
|
||||
# COPY_XAPI = a $(call)able function to copy $1 to $(dir.dout), where
|
||||
# $1 must be one of the "external" JS API files.
|
||||
define COPY_XAPI
|
||||
sqlite3-api.ext.jses += $$(dir.dout)/$$(notdir $(1))
|
||||
$$(dir.dout)/$$(notdir $(1)): $(1) $$(MAKEFILE)
|
||||
cp $$< $$@
|
||||
endef
|
||||
$(foreach X,$(SOAP.js),\
|
||||
$(eval $(call COPY_XAPI,$(X))))
|
||||
all quick: $(sqlite3-api.ext.jses)
|
||||
q: quick
|
||||
|
||||
@@ -451,27 +402,14 @@ emcc.exportedRuntimeMethods := \
|
||||
emcc.jsflags += $(emcc.exportedRuntimeMethods)
|
||||
emcc.jsflags += -sUSE_CLOSURE_COMPILER=0
|
||||
emcc.jsflags += -sIMPORTED_MEMORY
|
||||
#emcc.jsflags += -sASYNCIFY=2
|
||||
# ^^^ ASYNCIFY=2 is for experimental JSPI support
|
||||
# (https://v8.dev/blog/jspi), but enabling it causes the lib-level
|
||||
# init code to throw inexplicable complaints about C-level function
|
||||
# signatures not matching what we expect them to be. JSPI requires, as of
|
||||
# this writing, requires an experimental Chrome flag:
|
||||
# chrome://flags/#enable-experimental-webassembly-stack-switching
|
||||
emcc.jsflags += -sSTRICT_JS=0
|
||||
# STRICT_JS disabled due to:
|
||||
# https://github.com/emscripten-core/emscripten/issues/18610
|
||||
# TL;DR: does not work with MODULARIZE or EXPORT_ES6 as of version 3.1.31.
|
||||
|
||||
# -sENVIRONMENT values for the various build modes:
|
||||
emcc.environment.vanilla := web,worker
|
||||
emcc.environment.bundler-friendly := $(emcc.environment.vanilla)
|
||||
emcc.environment.esm := $(emcc.environment.vanilla)
|
||||
emcc.environment.node := node
|
||||
# Note that adding "node" to the list for the other builds causes
|
||||
# Emscripten to generate code which confuses node: it cannot reliably
|
||||
# determine whether the build is for a browser or for node.
|
||||
|
||||
ifeq (3.1.31,$(emcc.version))
|
||||
emcc.jsflags += -sSTRICT_JS=0
|
||||
$(warning Disabling -sSTRICT_JS for emcc $(emcc.version): \
|
||||
https://github.com/emscripten-core/emscripten/issues/18610)
|
||||
else
|
||||
emcc.jsflags += -sSTRICT_JS=1
|
||||
endif
|
||||
emcc.environment := -sENVIRONMENT=web,worker
|
||||
########################################################################
|
||||
# -sINITIAL_MEMORY: How much memory we need to start with is governed
|
||||
# at least in part by whether -sALLOW_MEMORY_GROWTH is enabled. If so,
|
||||
@@ -484,9 +422,9 @@ emcc.environment.node := node
|
||||
# such test results are inconsistent due to browser internals which
|
||||
# are opaque to us.
|
||||
emcc.jsflags += -sALLOW_MEMORY_GROWTH
|
||||
emcc.INITIAL_MEMORY.128 := 134217728
|
||||
emcc.INITIAL_MEMORY.128 := 13107200
|
||||
emcc.INITIAL_MEMORY.96 := 100663296
|
||||
emcc.INITIAL_MEMORY.64 := 67108864
|
||||
emcc.INITIAL_MEMORY.64 := 64225280
|
||||
emcc.INITIAL_MEMORY.32 := 33554432
|
||||
emcc.INITIAL_MEMORY.16 := 16777216
|
||||
emcc.INITIAL_MEMORY.8 := 8388608
|
||||
@@ -503,8 +441,6 @@ emcc.jsflags += -sSTACK_SIZE=512KB
|
||||
# ^^^ ACHTUNG: emsdk 3.1.27 reduced the default stack size from 5MB to
|
||||
# a mere 64KB, which leads to silent memory corruption via the kvvfs
|
||||
# VFS, which requires twice that for its xRead() and xWrite() methods.
|
||||
# 2023-03: those methods have since been adapted to use a malloc()'d
|
||||
# buffer.
|
||||
########################################################################
|
||||
# $(sqlite3.js.init-func) is the name Emscripten assigns our exported
|
||||
# module init/load function. This symbol name is hard-coded in
|
||||
@@ -573,7 +509,7 @@ emcc.jsflags += -sLLD_REPORT_UNDEFINED
|
||||
$(sqlite3-api-build-version.js): $(bin.version-info) $(MAKEFILE)
|
||||
@echo "Making $@..."
|
||||
@{ \
|
||||
echo 'globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \
|
||||
echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \
|
||||
echo -n ' sqlite3.version = '; \
|
||||
$(bin.version-info) --json; \
|
||||
echo ';'; \
|
||||
@@ -614,40 +550,25 @@ $(post-js.js.in): $(post-jses.js) $(MAKEFILE)
|
||||
|
||||
########################################################################
|
||||
# call-make-pre-post is a $(call)able which creates rules for
|
||||
# pre-js-$(1)-$(2).js. $1 = the base name of the JS file on whose
|
||||
# behalf this pre-js is for (one of: sqlite3, sqlite3-wasmfs). $2 is
|
||||
# the build mode: one of $(JS_BUILD_MODES). This sets up
|
||||
# --[extern-][pre/post]-js flags in $(pre-post-$(1)-$(2).flags) and
|
||||
# dependencies in $(pre-post-$(1)-$(2).deps). The resulting files get
|
||||
# filtered using $(C-PP.FILTER). Any flags necessary for such
|
||||
# filtering need to be set in $(c-pp.D.$(1)-$(2)) before $(call)ing
|
||||
# this.
|
||||
# pre-js-$(1).js. $1 = the base name of the JS file on whose behalf
|
||||
# this pre-js is for (one of: sqlite3, sqlite3-wasmfs). $2 is the build
|
||||
# mode: one of (vanilla, esm, bundler-friendly). This sets up
|
||||
# --[extern-][pre/post]-js flags in $(pre-post-$(1).flags.$(2)) and
|
||||
# dependencies in $(pre-post-$(1).deps.$(2)).
|
||||
define call-make-pre-post
|
||||
pre-post-$(1)-$(2).flags ?=
|
||||
pre-js.js.$(1)-$(2) := $$(dir.tmp)/pre-js.$(1)-$(2).intermediary.js
|
||||
$$(eval $$(call C-PP.FILTER,$$(pre-js.js.in),$$(pre-js.js.$(1)-$(2)),$$(c-pp.D.$(1)-$(2))))
|
||||
post-js.js.$(1)-$(2) := $$(dir.tmp)/post-js.$(1)-$(2).js
|
||||
$$(eval $$(call C-PP.FILTER,$$(post-js.js.in),$$(post-js.js.$(1)-$(2)),$$(c-pp.D.$(1)-$(2))))
|
||||
extern-post-js.js.$(1)-$(2) := $$(dir.tmp)/extern-post-js.$(1)-$(2).js
|
||||
$$(eval $$(call C-PP.FILTER,$$(extern-post-js.js.in),$$(extern-post-js.js.$(1)-$(2)),$$(c-pp.D.$(1)-$(2))))
|
||||
pre-post-common.flags.$(1)-$(2) := \
|
||||
$$(pre-post-common.flags) \
|
||||
--post-js=$$(post-js.js.$(1)-$(2)) \
|
||||
--extern-post-js=$$(extern-post-js.js.$(1)-$(2))
|
||||
pre-post-jses.$(1)-$(2).deps := $$(pre-post-jses.deps.common) \
|
||||
$$(post-js.js.$(1)-$(2)) $$(extern-post-js.js.$(1)-$(2))
|
||||
$$(dir.tmp)/pre-js-$(1)-$(2).js: $$(pre-js.js.$(1)-$(2)) $$(MAKEFILE)
|
||||
cp $$(pre-js.js.$(1)-$(2)) $$@
|
||||
pre-post-$(1).flags.$(2) ?=
|
||||
$$(dir.tmp)/pre-js-$(1)-$(2).js: $$(pre-js.js.$(2)) $$(MAKEFILE)
|
||||
cp $$(pre-js.js.$(2)) $$@
|
||||
@if [ sqlite3-wasmfs = $(1) ]; then \
|
||||
echo "delete Module[xNameOfInstantiateWasm] /*for WASMFS build*/;"; \
|
||||
elif [ sqlite3 != $(1) ]; then \
|
||||
echo "Module[xNameOfInstantiateWasm].uri = '$(1).wasm';"; \
|
||||
fi >> $$@
|
||||
pre-post-$(1)-$(2).deps := \
|
||||
$$(pre-post-jses.$(1)-$(2).deps) \
|
||||
pre-post-$(1).deps.$(2) := \
|
||||
$$(pre-post-jses.deps.$(2)) \
|
||||
$$(dir.tmp)/pre-js-$(1)-$(2).js
|
||||
pre-post-$(1)-$(2).flags += \
|
||||
$$(pre-post-common.flags.$(1)-$(2)) \
|
||||
pre-post-$(1).flags.$(2) += \
|
||||
$$(pre-post-common.flags.$(2)) \
|
||||
--pre-js=$$(dir.tmp)/pre-js-$(1)-$(2).js
|
||||
endef
|
||||
# /post-js and pre-js
|
||||
@@ -658,8 +579,6 @@ endef
|
||||
# https://github.com/emscripten-core/emscripten/issues/14383
|
||||
sqlite3.wasm := $(dir.dout)/sqlite3.wasm
|
||||
sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c
|
||||
sqlite3-wasm.cfiles := $(sqlite3-wasm.c) $(sqlite3_wasm_extra_init.c)
|
||||
sqlite3-wasmfs.cfiles := $(sqlite3-wasm.cfiles)
|
||||
# sqlite3-wasm.o vs sqlite3-wasm.c: building against the latter
|
||||
# (predictably) results in a slightly faster binary. We're close
|
||||
# enough to the target speed requirements that the 500ms makes a
|
||||
@@ -669,8 +588,7 @@ sqlite3-wasmfs.cfiles := $(sqlite3-wasm.cfiles)
|
||||
# SQLITE3.xJS.EXPORT-DEFAULT is part of SQLITE3-WASMFS.xJS.RECIPE and
|
||||
# SETUP_LIB_BUILD_MODE, factored into a separate piece to avoid code
|
||||
# duplication. $1 is 1 if the build mode needs this workaround (esm,
|
||||
# bundler-friendly, node) and 0 if not (vanilla). $2 must be empty for
|
||||
# all builds except sqlite3-wasmfs.mjs, in which case it must be 1.
|
||||
# bundler-friendly) and 0 if not (vanilla).
|
||||
#
|
||||
# Reminder for ESM builds: even if we use -sEXPORT_ES6=0, emcc _still_
|
||||
# adds:
|
||||
@@ -684,20 +602,13 @@ sqlite3-wasmfs.cfiles := $(sqlite3-wasm.cfiles)
|
||||
#
|
||||
# Upstream RFE:
|
||||
# https://github.com/emscripten-core/emscripten/issues/18237
|
||||
#
|
||||
# Maintenance reminder: Mac sed works differently than GNU sed, so
|
||||
# don't use sed for this.
|
||||
define SQLITE3.xJS.ESM-EXPORT-DEFAULT
|
||||
if [ x1 = x$(1) ]; then \
|
||||
echo "Fragile workaround for emscripten/issues/18237. See SQLITE3.xJS.RECIPE."; \
|
||||
{\
|
||||
awk '/^export default/ && !f{f=1; next} 1' $@ > $@.tmp && mv $@.tmp $@; \
|
||||
} || exit $$?; \
|
||||
if [ x != x$(2) ]; then \
|
||||
if ! grep -q '^export default' $@; then \
|
||||
echo "Cannot find export default." 1>&2; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
echo "Fragile workaround for an Emscripten annoyance. See SQLITE3.xJS.RECIPE."; \
|
||||
sed -i -e '0,/^export default/{/^export default/d;}' $@ || exit $$?; \
|
||||
if ! grep -q '^export default' $@; then \
|
||||
echo "Cannot find export default." 1>&2; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
fi
|
||||
endef
|
||||
@@ -715,59 +626,51 @@ pre-post-common.flags := \
|
||||
pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js)
|
||||
########################################################################
|
||||
# SETUP_LIB_BUILD_MODE is a $(call)'able which sets up numerous pieces
|
||||
# for one of the build modes.
|
||||
# for one of the build modes (vanilla, esm, bundler-friendly).
|
||||
#
|
||||
# $1 = one of: sqlite3, sqlite3-wasmfs
|
||||
# $2 = build mode name: one of $(JS_BUILD_MODES)
|
||||
# $3 = 1 for ESM build mode, else 0
|
||||
# $4 = resulting sqlite-api JS/MJS file
|
||||
# $5 = resulting JS/MJS file
|
||||
# $6 = -D... flags for $(bin.c-pp)
|
||||
# $7 = emcc -sXYZ flags (CURRENTLY UNUSED - was factored out)
|
||||
#
|
||||
# Maintenance reminder: be careful not to introduce spaces around args
|
||||
# ($1, $2), otherwise string concatenation will malfunction.
|
||||
#
|
||||
# emcc.environment.$(2) must be set to a value for the -sENVIRONMENT flag.
|
||||
#
|
||||
# $(cflags.$(1)) and $(cflags.$(1).$(2)) may be defined to append
|
||||
# CFLAGS to a given build mode.
|
||||
#
|
||||
# $(emcc.flags.$(1)) and $(emcc.flags.$(1).$(2)) may be defined to
|
||||
# append emcc-specific flags to a given build mode.
|
||||
# $1 = build mode name
|
||||
# $2 = 1 for ESM build mode, else 0
|
||||
# $3 = resulting sqlite-api JS/MJS file
|
||||
# $4 = resulting JS/MJS file
|
||||
# $5 = -D... flags for $(bin.c-pp)
|
||||
# $6 = emcc -sXYZ flags
|
||||
define SETUP_LIB_BUILD_MODE
|
||||
$(info Setting up build [$(1)-$(2)]: $(5))
|
||||
c-pp.D.$(1)-$(2) := $(6)
|
||||
$$(eval $$(call call-make-pre-post,$(1),$(2)))
|
||||
emcc.flags.$(1).$(2) ?=
|
||||
emcc.flags.$(1).$(2) += $(7)
|
||||
$$(eval $$(call C-PP.FILTER, $$(sqlite3-api.js.in), $(4), $(6)))
|
||||
$(5): $(4) $$(MAKEFILE) $$(sqlite3-wasm.cfiles) $$(EXPORTED_FUNCTIONS.api) $$(pre-post-$(1)-$(2).deps)
|
||||
$(info Setting up build [$(1)]: $(4))
|
||||
c-pp.D.$(1) := $(5)
|
||||
pre-js.js.$(1) := $$(dir.api)/pre-js.$(1).js
|
||||
$$(eval $$(call C-PP.FILTER,$$(pre-js.js.in),$$(pre-js.js.$(1)),$$(c-pp.D.$(1))))
|
||||
post-js.js.$(1) := $$(dir.tmp)/post-js.$(1).js
|
||||
$$(eval $$(call C-PP.FILTER,$$(post-js.js.in),$$(post-js.js.$(1)),$$(c-pp.D.$(1))))
|
||||
extern-post-js.js.$(1) := $$(dir.tmp)/extern-post-js.$(1).js
|
||||
$$(eval $$(call C-PP.FILTER,$$(extern-post-js.js.in),$$(extern-post-js.js.$(1)),$$(c-pp.D.$(1))))
|
||||
pre-post-common.flags.$(1) := \
|
||||
$$(pre-post-common.flags) \
|
||||
--post-js=$$(post-js.js.$(1)) \
|
||||
--extern-post-js=$$(extern-post-js.js.$(1))
|
||||
pre-post-jses.deps.$(1) := $$(pre-post-jses.deps.common) \
|
||||
$$(post-js.js.$(1)) $$(extern-post-js.js.$(1))
|
||||
$$(eval $$(call call-make-pre-post,sqlite3,$(1)))
|
||||
emcc.flags.sqlite3.$(1) := $(6)
|
||||
$$(eval $$(call C-PP.FILTER, $$(sqlite3-api.js.in), $(3), $(5)))
|
||||
$(4): $(3)
|
||||
$(4): $(3) $$(MAKEFILE) $$(sqlite3-wasm.c) $$(EXPORTED_FUNCTIONS.api) $$(pre-post-sqlite3.deps.$(1))
|
||||
@echo "Building $$@ ..."
|
||||
$$(emcc.bin) -o $$@ $$(emcc_opt_full) $$(emcc.flags) \
|
||||
$$(emcc.jsflags) \
|
||||
-sENVIRONMENT=$$(emcc.environment.$(2)) \
|
||||
$$(pre-post-$(1)-$(2).flags) \
|
||||
$$(emcc.flags.$(1)) $$(emcc.flags.$(1).$(2)) \
|
||||
$$(cflags.common) $$(SQLITE_OPT) \
|
||||
$$(cflags.$(1)) $$(cflags.$(1).$(2)) \
|
||||
$$(cflags.wasm_extra_init) $$(sqlite3-wasm.cfiles)
|
||||
@$$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(3))
|
||||
@dotwasm=$$(basename $$@).wasm; \
|
||||
chmod -x $$$$dotwasm; \
|
||||
$(maybe-wasm-strip) $$$$dotwasm; \
|
||||
case $(2) in \
|
||||
bundler-friendly|node) \
|
||||
echo "Patching $$@ for $(1).wasm..."; \
|
||||
rm -f $$$$dotwasm; \
|
||||
dotwasm=; \
|
||||
sed -i -e 's/$(1)-$(2).wasm/$(1).wasm/g' $$@ || exit $$$$?; \
|
||||
;; \
|
||||
esac; \
|
||||
ls -la $$$$dotwasm $$@
|
||||
all: $(5)
|
||||
#quick: $(5)
|
||||
CLEAN_FILES += $(4) $(5)
|
||||
$$(pre-post-sqlite3.flags.$(1)) $$(emcc.flags.sqlite3.$(1)) \
|
||||
$$(cflags.common) $$(SQLITE_OPT) $$(sqlite3-wasm.c)
|
||||
@$$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(2))
|
||||
@if [ bundler-friendly = $(1) ]; then \
|
||||
echo "Patching $(3) for sqlite3.wasm..."; \
|
||||
rm -f $$(dir.dout)/sqlite3-bundler-friendly.wasm; \
|
||||
sed -i -e 's/sqlite3-bundler-friendly.wasm/sqlite3.wasm/g' $$@ || exit $$$$?; \
|
||||
fi
|
||||
chmod -x $$(sqlite3.wasm)
|
||||
$$(maybe-wasm-strip) $$(sqlite3.wasm)
|
||||
@ls -la $@ $$(sqlite3.wasm)
|
||||
all: $(4)
|
||||
quick: $(4)
|
||||
CLEAN_FILES += $(3) $(4)
|
||||
endef
|
||||
# ^^^ /SETUP_LIB_BUILD_MODE
|
||||
########################################################################
|
||||
@@ -777,26 +680,18 @@ sqlite3-api.mjs := $(dir.dout)/sqlite3-api.mjs
|
||||
sqlite3.mjs := $(dir.dout)/sqlite3.mjs
|
||||
sqlite3-api-bundler-friendly.mjs := $(dir.dout)/sqlite3-api-bundler-friendly.mjs
|
||||
sqlite3-bundler-friendly.mjs := $(dir.dout)/sqlite3-bundler-friendly.mjs
|
||||
sqlite3-api-node.mjs := $(dir.dout)/sqlite3-api-node.mjs
|
||||
sqlite3-node.mjs := $(dir.dout)/sqlite3-node.mjs
|
||||
#$(info $(call SETUP_LIB_BUILD_MODE,sqlite3,vanilla,0, $(sqlite3-api.js), $(sqlite3.js)))
|
||||
$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,vanilla,0,\
|
||||
$(sqlite3-api.js), $(sqlite3.js)))
|
||||
$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,esm,1,\
|
||||
$(sqlite3-api.mjs), $(sqlite3.mjs), \
|
||||
# Maintenance reminder: careful not to introduce spaces around args $1, $2
|
||||
#$(info $(call SETUP_LIB_BUILD_MODE,vanilla,0, $(sqlite3-api.js), $(sqlite3.js)))
|
||||
$(eval $(call SETUP_LIB_BUILD_MODE,vanilla,0, $(sqlite3-api.js), $(sqlite3.js)))
|
||||
$(eval $(call SETUP_LIB_BUILD_MODE,esm,1, $(sqlite3-api.mjs), $(sqlite3.mjs), \
|
||||
-Dtarget=es6-module, -sEXPORT_ES6 -sUSE_ES6_IMPORT_META))
|
||||
$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,bundler-friendly,1,\
|
||||
$(eval $(call SETUP_LIB_BUILD_MODE,bundler-friendly,1,\
|
||||
$(sqlite3-api-bundler-friendly.mjs),$(sqlite3-bundler-friendly.mjs),\
|
||||
$(c-pp.D.sqlite3-esm) -Dtarget=es6-bundler-friendly))
|
||||
$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,node,1,\
|
||||
$(sqlite3-api-node.mjs),$(sqlite3-node.mjs),\
|
||||
$(c-pp.D.sqlite3-bundler-friendly) -Dtarget=node))
|
||||
$(c-pp.D.esm) -Dtarget=es6-bundler-friendly, $(emcc.flags.sqlite3.esm)))
|
||||
# The various -D... values used by *.c-pp.js include:
|
||||
#
|
||||
# -Dtarget=es6-module: for all ESM module builds
|
||||
#
|
||||
# -Dtarget=node: for node.js builds
|
||||
#
|
||||
# -Dtarget=es6-module -Dtarget=es6-bundler-friendly: intended for
|
||||
# "bundler-friendly" ESM module build. These have some restrictions
|
||||
# on how URL() objects are constructed in some contexts: URLs which
|
||||
@@ -804,26 +699,18 @@ $(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,node,1,\
|
||||
# as string literals so that bundlers' static-analysis tools can
|
||||
# find those files and include them in their bundles.
|
||||
#
|
||||
# -Dtarget=es6-module -Dtarget=es6-bundler-friendly -Dtarget=node: is
|
||||
# intended for use by node.js for node.js, as opposed to by
|
||||
# node.js on behalf of a browser. Mixing -sENVIRONMENT=web and
|
||||
# -sENVIRONMENT=node leads to ambiguity and confusion on node's
|
||||
# part, as it's unable to reliably determine whether the target is
|
||||
# a browser or node.
|
||||
#
|
||||
########################################################################
|
||||
########################################################################
|
||||
# We have to ensure that we do not build $(sqlite3*.*js) in parallel
|
||||
# because they all result in the creation of $(sqlite3.wasm). We have
|
||||
# no way to build just a .[m]js file without also building the .wasm
|
||||
# file because the generated .[m]js file has to include info about the
|
||||
# imports needed by the wasm file, so they have to be built
|
||||
# We have to ensure that we do not build both $(sqlite3*.*js) in
|
||||
# parallel because both result in the creation of $(sqlite3.wasm). We
|
||||
# have no way to build just the .mjs file without also building the
|
||||
# .wasm file because the generated .mjs file has to include info about
|
||||
# the imports needed by the wasm file, so they have to be built
|
||||
# together. i.e. we're building $(sqlite3.wasm) multiple times, but
|
||||
# that's unavoidable (and harmless, just a waste of build time).
|
||||
$(sqlite3.wasm): $(sqlite3.js)
|
||||
$(sqlite3.mjs): $(sqlite3.js)
|
||||
$(sqlite3-bundler-friendly.mjs): $(sqlite3.mjs)
|
||||
$(sqlite3-node.mjs): $(sqlite3.mjs)
|
||||
CLEAN_FILES += $(sqlite3.wasm)
|
||||
|
||||
########################################################################
|
||||
@@ -836,7 +723,7 @@ sqlite3-worker1.js.in := $(dir.api)/sqlite3-worker1.c-pp.js
|
||||
sqlite3-worker1-promiser.js.in := $(dir.api)/sqlite3-worker1-promiser.c-pp.js
|
||||
sqlite3-worker1.js := $(dir.dout)/sqlite3-worker1.js
|
||||
sqlite3-worker1-promiser.js := $(dir.dout)/sqlite3-worker1-promiser.js
|
||||
sqlite3-worker1-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-bundler-friendly.mjs
|
||||
sqlite3-worker1-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-bundler-friendly.js
|
||||
sqlite3-worker1-promiser-bundler-friendly.js := $(dir.dout)/sqlite3-worker1-promiser-bundler-friendly.js
|
||||
$(eval $(call C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1.js)))
|
||||
$(eval $(call C-PP.FILTER,$(sqlite3-worker1.js.in),$(sqlite3-worker1-bundler-friendly.js),\
|
||||
@@ -870,7 +757,7 @@ clean-batch:
|
||||
# a regular basis with different -Ox flags and rebuilding the batch
|
||||
# pieces each time is an unnecessary time sink.
|
||||
batch: batch-runner.list
|
||||
#all: batch
|
||||
all: batch
|
||||
# end batch-runner.js
|
||||
########################################################################
|
||||
# Wasmified speedtest1 is our primary benchmarking tool.
|
||||
@@ -878,14 +765,14 @@ batch: batch-runner.list
|
||||
# emcc.speedtest1.common = emcc flags used by multiple builds of speedtest1
|
||||
# emcc.speedtest1 = emcc flags used by main build of speedtest1
|
||||
emcc.speedtest1.common := $(emcc_opt_full)
|
||||
emcc.speedtest1 := -I. -I$(dir $(sqlite3.canonical.c))
|
||||
emcc.speedtest1 :=
|
||||
emcc.speedtest1 += -sENVIRONMENT=web
|
||||
emcc.speedtest1 += -sALLOW_MEMORY_GROWTH
|
||||
emcc.speedtest1 += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.$(emcc.INITIAL_MEMORY))
|
||||
emcc.speedtest1.common += -sINVOKE_RUN=0
|
||||
emcc.speedtest1.common += --no-entry
|
||||
emcc.speedtest1.common += -sABORTING_MALLOC
|
||||
emcc.speedtest1.common += -sSTRICT_JS=0
|
||||
emcc.speedtest1.common += -sSTRICT_JS
|
||||
emcc.speedtest1.common += -sMODULARIZE
|
||||
emcc.speedtest1.common += -Wno-limited-postlink-optimizations
|
||||
EXPORTED_FUNCTIONS.speedtest1 := $(abspath $(dir.tmp)/EXPORTED_FUNCTIONS.speedtest1)
|
||||
@@ -916,29 +803,25 @@ speedtest1.exit-runtime1 := -sEXIT_RUNTIME=1
|
||||
# -sEXIT_RUNTIME=1 but we need EXIT_RUNTIME=0 for the worker-based app
|
||||
# which runs speedtest1 multiple times.
|
||||
|
||||
$(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api.main)
|
||||
$(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api)
|
||||
@echo "Making $@ ..."
|
||||
@{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api.main); } > $@
|
||||
@{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api); } > $@
|
||||
speedtest1.js := $(dir.dout)/speedtest1.js
|
||||
speedtest1.wasm := $(dir.dout)/speedtest1.wasm
|
||||
emcc.flags.speedtest1-vanilla := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM
|
||||
|
||||
speedtest1.cfiles := $(speedtest1.c) $(sqlite3-wasm.c)
|
||||
cflags.speedtest1 := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM
|
||||
speedtest1.cses := $(speedtest1.c) $(sqlite3-wasm.c)
|
||||
$(eval $(call call-make-pre-post,speedtest1,vanilla))
|
||||
$(speedtest1.js): $(MAKEFILE) $(speedtest1.cfiles) \
|
||||
$(pre-post-speedtest1-vanilla.deps) \
|
||||
$(speedtest1.js): $(MAKEFILE) $(speedtest1.cses) \
|
||||
$(pre-post-speedtest1.deps.vanilla) \
|
||||
$(EXPORTED_FUNCTIONS.speedtest1)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) \
|
||||
$(emcc.speedtest1) \
|
||||
$(emcc.speedtest1.common) \
|
||||
$(emcc.flags.speedtest1-vanilla) $(pre-post-speedtest1-vanilla.flags) \
|
||||
$(emcc.speedtest1) $(emcc.speedtest1.common) \
|
||||
$(cflags.speedtest1) $(pre-post-speedtest1.flags.vanilla) \
|
||||
$(SQLITE_OPT) \
|
||||
-USQLITE_C -DSQLITE_C=$(sqlite3.canonical.c) \
|
||||
$(speedtest1.exit-runtime0) \
|
||||
-o $@ $(speedtest1.cfiles) -lm
|
||||
-o $@ $(speedtest1.cses) -lm
|
||||
$(maybe-wasm-strip) $(speedtest1.wasm)
|
||||
chmod -x $(speedtest1.wasm)
|
||||
ls -la $@ $(speedtest1.wasm)
|
||||
|
||||
speedtest1: $(speedtest1.js)
|
||||
@@ -964,14 +847,13 @@ CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm)
|
||||
#
|
||||
# To create those, we filter tester1.c-pp.js with $(bin.c-pp)...
|
||||
$(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1.js))
|
||||
$(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1.mjs,$(c-pp.D.sqlite3-esm)))
|
||||
$(eval $(call C-PP.FILTER,tester1.c-pp.js,tester1.mjs,$(c-pp.D.esm)))
|
||||
$(eval $(call C-PP.FILTER,tester1.c-pp.html,tester1.html))
|
||||
$(eval $(call C-PP.FILTER,tester1.c-pp.html,tester1-esm.html,$(c-pp.D.sqlite3-esm)))
|
||||
$(eval $(call C-PP.FILTER,tester1.c-pp.html,tester1-esm.html,$(c-pp.D.esm)))
|
||||
tester1: tester1.js tester1.mjs tester1.html tester1-esm.html
|
||||
# Note that we do not include $(sqlite3-bundler-friendly.mjs) in this
|
||||
# because bundlers are client-specific.
|
||||
all quick: tester1
|
||||
quick: $(sqlite3.js)
|
||||
|
||||
########################################################################
|
||||
# Convenience rules to rebuild with various -Ox levels. Much
|
||||
@@ -991,6 +873,8 @@ o1: clean
|
||||
$(MAKE) -e "emcc_opt=-O1 $(o-xtra)"
|
||||
o2: clean
|
||||
$(MAKE) -j2 -e "emcc_opt=-O2 $(o-xtra)"
|
||||
qo2: clean
|
||||
$(MAKE) -j2 -e "emcc_opt=-O2 $(o-xtra)" quick
|
||||
o3: clean
|
||||
$(MAKE) -e "emcc_opt=-O3 $(o-xtra)"
|
||||
os: clean
|
||||
@@ -998,6 +882,8 @@ os: clean
|
||||
$(MAKE) -e "emcc_opt=-Os $(o-xtra)"
|
||||
oz: clean
|
||||
$(MAKE) -j2 -e "emcc_opt=-Oz $(o-xtra)"
|
||||
qoz: clean
|
||||
$(MAKE) -j2 -e "emcc_opt=-Oz $(o-xtra)" quick
|
||||
|
||||
########################################################################
|
||||
# Sub-makes...
|
||||
@@ -1009,8 +895,6 @@ include fiddle.make
|
||||
ifneq (,$(filter wasmfs,$(MAKECMDGOALS)))
|
||||
wasmfs.enable ?= 1
|
||||
else
|
||||
# Unconditionally enable wasmfs for [dist]clean so that the wasmfs
|
||||
# sub-make can clean up.
|
||||
wasmfs.enable ?= $(if $(filter %clean,$(MAKECMDGOALS)),1,0)
|
||||
endif
|
||||
ifeq (1,$(wasmfs.enable))
|
||||
|
||||
+7
-8
@@ -82,7 +82,7 @@ features in the apps which use them.
|
||||
|
||||
# Testing on a remote machine that is accessed via SSH
|
||||
|
||||
*NB: The following are developer notes, last validated on 2023-07-19*
|
||||
*NB: The following are developer notes, last validated on 2022-08-18*
|
||||
|
||||
* Remote: Install git, emsdk, and althttpd
|
||||
* Use a [version of althttpd][althttpd] from
|
||||
@@ -93,14 +93,13 @@ features in the apps which use them.
|
||||
* Local: `ssh -L 8180:localhost:8080 remote`
|
||||
* Local: Point your web-browser at http://localhost:8180/index.html
|
||||
|
||||
In order to enable [SharedArrayBuffer][], the web-browser requires
|
||||
that the two extra Cross-Origin lines be present in HTTP reply headers
|
||||
and that the request must come from "localhost" (_or_ over an SSL
|
||||
connection). Since the web-server is on a different machine from the
|
||||
web-broser, the localhost requirement means that the connection must
|
||||
be tunneled using SSH.
|
||||
In order to enable [SharedArrayBuffers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer),
|
||||
the web-browser requires that the two extra Cross-Origin lines be present
|
||||
in HTTP reply headers and that the request must come from "localhost".
|
||||
Since the web-server is on a different machine from
|
||||
the web-broser, the localhost requirement means that the connection must be tunneled
|
||||
using SSH.
|
||||
|
||||
|
||||
[emscripten]: https://emscripten.org
|
||||
[althttpd]: https://sqlite.org/althttpd
|
||||
[SharedArrayBuffer]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
_sqlite3_key
|
||||
_sqlite3_key_v2
|
||||
_sqlite3_rekey
|
||||
_sqlite3_rekey_v2
|
||||
_sqlite3_activate_see
|
||||
+11
-16
@@ -83,18 +83,15 @@ browser client:
|
||||
helpers for use by downstream code which creates `sqlite3_vfs`
|
||||
and `sqlite3_module` implementations.
|
||||
- **`sqlite3-vfs-opfs.c-pp.js`**\
|
||||
is an sqlite3 VFS implementation which supports the Origin-Private
|
||||
FileSystem (OPFS) as a storage layer to provide persistent storage
|
||||
for database files in a browser. It requires...
|
||||
is an sqlite3 VFS implementation which supports Google Chrome's
|
||||
Origin-Private FileSystem (OPFS) as a storage layer to provide
|
||||
persistent storage for database files in a browser. It requires...
|
||||
- **`sqlite3-opfs-async-proxy.js`**\
|
||||
is the asynchronous backend part of the OPFS proxy. It speaks
|
||||
directly to the (async) OPFS API and channels those results back
|
||||
to its synchronous counterpart. This file, because it must be
|
||||
started in its own Worker, is not part of the amalgamation.
|
||||
- **`sqlite3-vfs-opfs-sahpool.c-pp.js`**\
|
||||
is another sqlite3 VFS supporting the OPFS, but uses a completely
|
||||
different approach that the above-listed one.
|
||||
- **`sqlite3-api-cleanup.js`**\
|
||||
- **`api/sqlite3-api-cleanup.js`**\
|
||||
The previous files do not immediately extend the library. Instead
|
||||
they add callback functions to be called during its
|
||||
bootstrapping. Some also temporarily create global objects in order
|
||||
@@ -111,15 +108,13 @@ browser client:
|
||||
with `c-pp`](#c-pp), noting that such preprocessing may be applied
|
||||
after all of the relevant files are concatenated. That extension is
|
||||
used primarily to keep the code maintainers cognisant of the fact that
|
||||
those files contain constructs which may not run as-is in any given
|
||||
JavaScript environment.
|
||||
those files contain constructs which will not run as-is in JavaScript.
|
||||
|
||||
The build process glues those files together, resulting in
|
||||
`sqlite3-api.js`, which is everything except for the
|
||||
`pre/post-js-*.js` files, and `sqlite3.js`, which is the
|
||||
Emscripten-generated amalgamated output and includes the
|
||||
`pre/post-js-*.js` parts, as well as the Emscripten-provided module
|
||||
loading pieces.
|
||||
`sqlite3-api.js`, which is everything except for the `post-js-*.js`
|
||||
files, and `sqlite3.js`, which is the Emscripten-generated amalgamated
|
||||
output and includes the `post-js-*.js` parts, as well as the
|
||||
Emscripten-provided module loading pieces.
|
||||
|
||||
The non-JS outlier file is `sqlite3-wasm.c`: it is a proxy for
|
||||
`sqlite3.c` which `#include`'s that file and adds a couple more
|
||||
@@ -157,8 +152,8 @@ Preprocessing of Source Files
|
||||
------------------------------------------------------------------------
|
||||
|
||||
Certain files in the build require preprocessing to filter in/out
|
||||
parts which differ between vanilla JS, ES6 Modules, and node.js
|
||||
builds. The preprocessor application itself is in
|
||||
parts which differ between vanilla JS builds and ES6 Module
|
||||
(a.k.a. esm) builds. The preprocessor application itself is in
|
||||
[`c-pp.c`](/file/ext/wasm/c-pp.c) and the complete technical details
|
||||
of such preprocessing are maintained in
|
||||
[`GNUMakefile`](/file/ext/wasm/GNUmakefile).
|
||||
|
||||
@@ -23,9 +23,12 @@ const toExportForESM =
|
||||
impls which Emscripten installs at some point in the file above
|
||||
this.
|
||||
*/
|
||||
const originalInit = sqlite3InitModule;
|
||||
const originalInit =
|
||||
/* Maintenance reminder: DO NOT use `self.` here. It's correct
|
||||
for non-ES6 Module cases but wrong for ES6 modules because those
|
||||
resolve this symbol differently. */ sqlite3InitModule;
|
||||
if(!originalInit){
|
||||
throw new Error("Expecting globalThis.sqlite3InitModule to be defined by the Emscripten build.");
|
||||
throw new Error("Expecting self.sqlite3InitModule to be defined by the Emscripten build.");
|
||||
}
|
||||
/**
|
||||
We need to add some state which our custom Module.locateFile()
|
||||
@@ -38,13 +41,11 @@ const toExportForESM =
|
||||
into the global scope and delete it when sqlite3InitModule()
|
||||
is called.
|
||||
*/
|
||||
const initModuleState = globalThis.sqlite3InitModuleState = Object.assign(Object.create(null),{
|
||||
moduleScript: globalThis?.document?.currentScript,
|
||||
const initModuleState = self.sqlite3InitModuleState = Object.assign(Object.create(null),{
|
||||
moduleScript: self?.document?.currentScript,
|
||||
isWorker: ('undefined' !== typeof WorkerGlobalScope),
|
||||
location: globalThis.location,
|
||||
urlParams: globalThis?.location?.href
|
||||
? new URL(globalThis.location.href).searchParams
|
||||
: new URLSearchParams()
|
||||
location: self.location,
|
||||
urlParams: new URL(self.location.href).searchParams
|
||||
});
|
||||
initModuleState.debugModule =
|
||||
initModuleState.urlParams.has('sqlite3.debugModule')
|
||||
@@ -59,22 +60,22 @@ const toExportForESM =
|
||||
initModuleState.sqlite3Dir = li.join('/') + '/';
|
||||
}
|
||||
|
||||
globalThis.sqlite3InitModule = function ff(...args){
|
||||
//console.warn("Using replaced sqlite3InitModule()",globalThis.location);
|
||||
self.sqlite3InitModule = function ff(...args){
|
||||
//console.warn("Using replaced sqlite3InitModule()",self.location);
|
||||
return originalInit(...args).then((EmscriptenModule)=>{
|
||||
//#if wasmfs
|
||||
if('undefined'!==typeof WorkerGlobalScope &&
|
||||
EmscriptenModule['ENVIRONMENT_IS_PTHREAD']){
|
||||
if(self.window!==self &&
|
||||
(EmscriptenModule['ENVIRONMENT_IS_PTHREAD']
|
||||
|| EmscriptenModule['_pthread_self']
|
||||
|| 'function'===typeof threadAlert
|
||||
|| self.location.pathname.endsWith('.worker.js')
|
||||
)){
|
||||
/** Workaround for wasmfs-generated worker, which calls this
|
||||
routine from each individual thread and requires that its
|
||||
argument be returned. The conditional criteria above are
|
||||
fragile, based solely on inspection of the offending code,
|
||||
not public Emscripten details. */
|
||||
//console.warn("sqlite3InitModule() returning E-module.",EmscriptenModule);
|
||||
argument be returned. All of the criteria above are fragile,
|
||||
based solely on inspection of the offending code, not public
|
||||
Emscripten details. */
|
||||
return EmscriptenModule;
|
||||
}
|
||||
//#endif
|
||||
//console.warn("sqlite3InitModule() returning sqlite3 object.");
|
||||
const s = EmscriptenModule.sqlite3;
|
||||
s.scriptInfo = initModuleState;
|
||||
//console.warn("sqlite3.scriptInfo =",s.scriptInfo);
|
||||
@@ -87,10 +88,10 @@ const toExportForESM =
|
||||
throw e;
|
||||
});
|
||||
};
|
||||
globalThis.sqlite3InitModule.ready = originalInit.ready;
|
||||
self.sqlite3InitModule.ready = originalInit.ready;
|
||||
|
||||
if(globalThis.sqlite3InitModuleState.moduleScript){
|
||||
const sim = globalThis.sqlite3InitModuleState;
|
||||
if(self.sqlite3InitModuleState.moduleScript){
|
||||
const sim = self.sqlite3InitModuleState;
|
||||
let src = sim.moduleScript.src.split('/');
|
||||
src.pop();
|
||||
sim.scriptDir = src.join('/') + '/';
|
||||
@@ -98,7 +99,7 @@ const toExportForESM =
|
||||
initModuleState.debugModule('sqlite3InitModuleState =',initModuleState);
|
||||
if(0){
|
||||
console.warn("Replaced sqlite3InitModule()");
|
||||
console.warn("globalThis.location.href =",globalThis.location.href);
|
||||
console.warn("self.location.href =",self.location.href);
|
||||
if('undefined' !== typeof document){
|
||||
console.warn("document.currentScript.src =",
|
||||
document?.currentScript?.src);
|
||||
@@ -118,9 +119,8 @@ const toExportForESM =
|
||||
/* AMD modules get injected in a way we cannot override,
|
||||
so we can't handle those here. */
|
||||
//#endif // !target=es6-module
|
||||
return globalThis.sqlite3InitModule /* required for ESM */;
|
||||
return self.sqlite3InitModule /* required for ESM */;
|
||||
})();
|
||||
//#if target=es6-module
|
||||
sqlite3InitModule = toExportForESM;
|
||||
export default sqlite3InitModule;
|
||||
export default toExportForESM;
|
||||
//#endif
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
*/
|
||||
|
||||
// See notes in extern-post-js.js
|
||||
const sqlite3InitModuleState = globalThis.sqlite3InitModuleState
|
||||
const sqlite3InitModuleState = self.sqlite3InitModuleState
|
||||
|| Object.assign(Object.create(null),{
|
||||
debugModule: ()=>{}
|
||||
});
|
||||
delete globalThis.sqlite3InitModuleState;
|
||||
sqlite3InitModuleState.debugModule('globalThis.location =',globalThis.location);
|
||||
delete self.sqlite3InitModuleState;
|
||||
sqlite3InitModuleState.debugModule('self.location =',self.location);
|
||||
|
||||
//#ifnot target=es6-bundler-friendly
|
||||
/**
|
||||
|
||||
@@ -22,12 +22,10 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build
|
||||
*/
|
||||
const SABC = Object.assign(
|
||||
Object.create(null), {
|
||||
exports: ('undefined'===typeof wasmExports)
|
||||
? Module['asm']/* emscripten <=3.1.43 */
|
||||
: wasmExports /* emscripten >=3.1.44 */,
|
||||
memory: Module.wasmMemory /* gets set if built with -sIMPORTED_MEMORY */
|
||||
exports: Module['asm'],
|
||||
memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */
|
||||
},
|
||||
globalThis.sqlite3ApiConfig || {}
|
||||
self.sqlite3ApiConfig || {}
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -35,29 +33,29 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build
|
||||
sqlite3ApiBootstrap(). That decision will be revisited at some
|
||||
point, as we really want client code to be able to call this to
|
||||
configure certain parts. Clients may modify
|
||||
globalThis.sqlite3ApiBootstrap.defaultConfig to tweak the default
|
||||
self.sqlite3ApiBootstrap.defaultConfig to tweak the default
|
||||
configuration used by a no-args call to sqlite3ApiBootstrap(),
|
||||
but must have first loaded their WASM module in order to be
|
||||
able to provide the necessary configuration state.
|
||||
*/
|
||||
//console.warn("globalThis.sqlite3ApiConfig = ",globalThis.sqlite3ApiConfig);
|
||||
globalThis.sqlite3ApiConfig = SABC;
|
||||
//console.warn("self.sqlite3ApiConfig = ",self.sqlite3ApiConfig);
|
||||
self.sqlite3ApiConfig = SABC;
|
||||
let sqlite3;
|
||||
try{
|
||||
sqlite3 = globalThis.sqlite3ApiBootstrap();
|
||||
sqlite3 = self.sqlite3ApiBootstrap();
|
||||
}catch(e){
|
||||
console.error("sqlite3ApiBootstrap() error:",e);
|
||||
throw e;
|
||||
}finally{
|
||||
delete globalThis.sqlite3ApiBootstrap;
|
||||
delete globalThis.sqlite3ApiConfig;
|
||||
delete self.sqlite3ApiBootstrap;
|
||||
delete self.sqlite3ApiConfig;
|
||||
}
|
||||
|
||||
Module.sqlite3 = sqlite3 /* Needed for customized sqlite3InitModule() to be able to
|
||||
pass the sqlite3 object off to the client. */;
|
||||
}else{
|
||||
console.warn("This is not running in an Emscripten module context, so",
|
||||
"globalThis.sqlite3ApiBootstrap() is _not_ being called due to lack",
|
||||
"self.sqlite3ApiBootstrap() is _not_ being called due to lack",
|
||||
"of config info for the WASM environment.",
|
||||
"It must be called manually.");
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
initializes the main API pieces so that the downstream components
|
||||
(e.g. sqlite3-api-oo1.js) have all that they need.
|
||||
*/
|
||||
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
'use strict';
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
const toss3 = sqlite3.SQLite3Error.toss;
|
||||
const capi = sqlite3.capi, wasm = sqlite3.wasm, util = sqlite3.util;
|
||||
globalThis.WhWasmUtilInstaller(wasm);
|
||||
delete globalThis.WhWasmUtilInstaller;
|
||||
self.WhWasmUtilInstaller(wasm);
|
||||
delete self.WhWasmUtilInstaller;
|
||||
|
||||
if(0){
|
||||
/**
|
||||
@@ -327,15 +327,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
wasm.bindingSignatures.push(["sqlite3_normalized_sql", "string", "sqlite3_stmt*"]);
|
||||
}
|
||||
|
||||
if(wasm.exports.sqlite3_activate_see instanceof Function){
|
||||
wasm.bindingSignatures.push(
|
||||
["sqlite3_key", "int", "sqlite3*", "string", "int"],
|
||||
["sqlite3_key_v2","int","sqlite3*","string","*","int"],
|
||||
["sqlite3_rekey", "int", "sqlite3*", "string", "int"],
|
||||
["sqlite3_rekey_v2", "int", "sqlite3*", "string", "*", "int"],
|
||||
["sqlite3_activate_see", undefined, "string"]
|
||||
);
|
||||
}
|
||||
/**
|
||||
Functions which require BigInt (int64) support are separated from
|
||||
the others because we need to conditionally bind them or apply
|
||||
@@ -614,7 +605,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
/**
|
||||
Install JS<->C struct bindings for the non-opaque struct types we
|
||||
need... */
|
||||
sqlite3.StructBinder = globalThis.Jaccwabyt({
|
||||
sqlite3.StructBinder = self.Jaccwabyt({
|
||||
heap: 0 ? wasm.memory : wasm.heap8u,
|
||||
alloc: wasm.alloc,
|
||||
dealloc: wasm.dealloc,
|
||||
@@ -622,7 +613,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
memberPrefix: /* Never change this: this prefix is baked into any
|
||||
amount of code and client-facing docs. */ '$'
|
||||
});
|
||||
delete globalThis.Jaccwabyt;
|
||||
delete self.Jaccwabyt;
|
||||
|
||||
{// wasm.xWrap() bindings...
|
||||
|
||||
@@ -728,15 +719,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
Populate api object with sqlite3_...() by binding the "raw" wasm
|
||||
exports into type-converting proxies using wasm.xWrap().
|
||||
*/
|
||||
if(0 === wasm.exports.sqlite3_step.length){
|
||||
/* This environment wraps exports in nullary functions, which means
|
||||
we must disable the arg-count validation we otherwise perform
|
||||
on the wrappers. */
|
||||
wasm.xWrap.doArgcCheck = false;
|
||||
sqlite3.config.warn(
|
||||
"Disabling sqlite3.wasm.xWrap.doArgcCheck due to environmental quirks."
|
||||
);
|
||||
}
|
||||
for(const e of wasm.bindingSignatures){
|
||||
capi[e[0]] = wasm.xWrap.apply(null, e);
|
||||
}
|
||||
|
||||
+77
-144
@@ -12,9 +12,9 @@
|
||||
|
||||
This file contains the so-called OO #1 API wrapper for the sqlite3
|
||||
WASM build. It requires that sqlite3-api-glue.js has already run
|
||||
and it installs its deliverable as globalThis.sqlite3.oo1.
|
||||
and it installs its deliverable as self.sqlite3.oo1.
|
||||
*/
|
||||
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
const toss3 = (...args)=>{throw new sqlite3.SQLite3Error(...args)};
|
||||
|
||||
@@ -55,7 +55,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
if(sqliteResultCode){
|
||||
if(dbPtr instanceof DB) dbPtr = dbPtr.pointer;
|
||||
toss3(
|
||||
sqliteResultCode,
|
||||
"sqlite3 result code",sqliteResultCode+":",
|
||||
(dbPtr
|
||||
? capi.sqlite3_errmsg(dbPtr)
|
||||
@@ -331,15 +330,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
|
||||
- `db`: the DB object which created the statement.
|
||||
|
||||
- `columnCount`: the number of result columns in the query, or 0
|
||||
for queries which cannot return results. This property is a proxy
|
||||
for sqlite3_column_count() and its use in loops should be avoided
|
||||
because of the call overhead associated with that. The
|
||||
`columnCount` is not cached when the Stmt is created because a
|
||||
schema change made via a separate db connection between this
|
||||
statement's preparation and when it is stepped may invalidate it.
|
||||
- `columnCount`: the number of result columns in the query, or 0 for
|
||||
queries which cannot return results.
|
||||
|
||||
- `parameterCount`: the number of bindable parameters in the query.
|
||||
- `parameterCount`: the number of bindable paramters in the query.
|
||||
*/
|
||||
const Stmt = function(){
|
||||
if(BindTypes!==arguments[2]){
|
||||
@@ -347,6 +341,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
}
|
||||
this.db = arguments[0];
|
||||
__ptrMap.set(this, arguments[1]);
|
||||
this.columnCount = capi.sqlite3_column_count(this.pointer);
|
||||
this.parameterCount = capi.sqlite3_bind_parameter_count(this.pointer);
|
||||
};
|
||||
|
||||
@@ -478,9 +473,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
const __selectFirstRow = (db, sql, bind, ...getArgs)=>{
|
||||
const stmt = db.prepare(sql);
|
||||
try {
|
||||
const rc = stmt.bind(bind).step() ? stmt.get(...getArgs) : undefined;
|
||||
stmt.reset(/*for INSERT...RETURNING locking case*/);
|
||||
return rc;
|
||||
return stmt.bind(bind).step() ? stmt.get(...getArgs) : undefined;
|
||||
}finally{
|
||||
stmt.finalize();
|
||||
}
|
||||
@@ -506,9 +499,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
"Not an error." The various non-0 non-error codes need to be
|
||||
checked for in client code where they are expected.
|
||||
|
||||
The thrown exception's `resultCode` property will be the value of
|
||||
the second argument to this function.
|
||||
|
||||
If it does not throw, it returns its first argument.
|
||||
*/
|
||||
DB.checkRc = (db,resultCode)=>checkSqlite3Rc(db,resultCode);
|
||||
@@ -556,10 +546,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
}
|
||||
const pDb = this.pointer;
|
||||
Object.keys(__stmtMap.get(this)).forEach((k,s)=>{
|
||||
if(s && s.pointer){
|
||||
try{s.finalize()}
|
||||
catch(e){/*ignore*/}
|
||||
}
|
||||
if(s && s.pointer) s.finalize();
|
||||
});
|
||||
__ptrMap.delete(this);
|
||||
__stmtMap.delete(this);
|
||||
@@ -714,18 +701,18 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
with identical names.
|
||||
|
||||
- `callback` = a function which gets called for each row of the
|
||||
result set, but only if that statement has any result rows. The
|
||||
callback's "this" is the options object, noting that this
|
||||
function synthesizes one if the caller does not pass one to
|
||||
exec(). The second argument passed to the callback is always
|
||||
the current Stmt object, as it's needed if the caller wants to
|
||||
fetch the column names or some such (noting that they could
|
||||
also be fetched via `this.columnNames`, if the client provides
|
||||
the `columnNames` option). If the callback returns a literal
|
||||
`false` (as opposed to any other falsy value, e.g. an implicit
|
||||
`undefined` return), any ongoing statement-`step()` iteration
|
||||
stops without an error. The return value of the callback is
|
||||
otherwise ignored.
|
||||
result set, but only if that statement has any result
|
||||
_rows_. The callback's "this" is the options object, noting
|
||||
that this function synthesizes one if the caller does not pass
|
||||
one to exec(). The second argument passed to the callback is
|
||||
always the current Stmt object, as it's needed if the caller
|
||||
wants to fetch the column names or some such (noting that they
|
||||
could also be fetched via `this.columnNames`, if the client
|
||||
provides the `columnNames` option). If the callback returns a
|
||||
literal `false` (as opposed to any other falsy value, e.g. an
|
||||
implicit `undefined` return), any ongoing statement-`step()`
|
||||
iteration stops without an error. The return value of the
|
||||
callback is otherwise ignored.
|
||||
|
||||
ACHTUNG: The callback MUST NOT modify the Stmt object. Calling
|
||||
any of the Stmt.get() variants, Stmt.getColumnName(), or
|
||||
@@ -746,7 +733,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
|
||||
A.1) `'array'` (the default) causes the results of
|
||||
`stmt.get([])` to be passed to the `callback` and/or appended
|
||||
to `resultRows`.
|
||||
to `resultRows`
|
||||
|
||||
A.2) `'object'` causes the results of
|
||||
`stmt.get(Object.create(null))` to be passed to the
|
||||
@@ -757,8 +744,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
|
||||
A.3) `'stmt'` causes the current Stmt to be passed to the
|
||||
callback, but this mode will trigger an exception if
|
||||
`resultRows` is an array because appending the transient
|
||||
statement to the array would be downright unhelpful.
|
||||
`resultRows` is an array because appending the statement to
|
||||
the array would be downright unhelpful.
|
||||
|
||||
B) An integer, indicating a zero-based column in the result
|
||||
row. Only that one single value will be passed on.
|
||||
@@ -788,7 +775,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
should return:
|
||||
|
||||
A) The default value is (usually) `"this"`, meaning that the
|
||||
DB object itself should be returned. The exception is if
|
||||
DB object itself should be returned. The exceptions is if
|
||||
the caller passes neither of `callback` nor `returnValue`
|
||||
but does pass an explicit `rowMode` then the default
|
||||
`returnValue` is `"resultRows"`, described below.
|
||||
@@ -870,53 +857,38 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
bind = null;
|
||||
}
|
||||
if(evalFirstResult && stmt.columnCount){
|
||||
/* Only forward SELECT-style results for the FIRST query
|
||||
/* Only forward SELECT results for the FIRST query
|
||||
in the SQL which potentially has them. */
|
||||
let gotColNames = Array.isArray(
|
||||
opt.columnNames
|
||||
/* As reported in
|
||||
https://sqlite.org/forum/forumpost/7774b773937cbe0a
|
||||
we need to delay fetching of the column names until
|
||||
after the first step() (if we step() at all) because
|
||||
a schema change between the prepare() and step(), via
|
||||
another connection, may invalidate the column count
|
||||
and names. */) ? 0 : 1;
|
||||
evalFirstResult = false;
|
||||
if(Array.isArray(opt.columnNames)){
|
||||
stmt.getColumnNames(opt.columnNames);
|
||||
}
|
||||
if(arg.cbArg || resultRows){
|
||||
for(; stmt.step(); stmt._lockedByExec = false){
|
||||
if(0===gotColNames++) stmt.getColumnNames(opt.columnNames);
|
||||
stmt._lockedByExec = true;
|
||||
for(; stmt.step(); stmt._isLocked = false){
|
||||
stmt._isLocked = true;
|
||||
const row = arg.cbArg(stmt);
|
||||
if(resultRows) resultRows.push(row);
|
||||
if(callback && false === callback.call(opt, row, stmt)){
|
||||
break;
|
||||
}
|
||||
}
|
||||
stmt._lockedByExec = false;
|
||||
}
|
||||
if(0===gotColNames){
|
||||
/* opt.columnNames was provided but we visited no result rows */
|
||||
stmt.getColumnNames(opt.columnNames);
|
||||
stmt._isLocked = false;
|
||||
}
|
||||
}else{
|
||||
stmt.step();
|
||||
}
|
||||
stmt.reset(
|
||||
/* In order to trigger an exception in the
|
||||
INSERT...RETURNING locking scenario:
|
||||
https://sqlite.org/forum/forumpost/36f7a2e7494897df
|
||||
*/).finalize();
|
||||
stmt.finalize();
|
||||
stmt = null;
|
||||
}/*prepare() loop*/
|
||||
}
|
||||
}/*catch(e){
|
||||
sqlite3.config.warn("DB.exec() is propagating exception",opt,e);
|
||||
throw e;
|
||||
}*/finally{
|
||||
wasm.scopedAllocPop(stack);
|
||||
if(stmt){
|
||||
delete stmt._lockedByExec;
|
||||
delete stmt._isLocked;
|
||||
stmt.finalize();
|
||||
}
|
||||
wasm.scopedAllocPop(stack);
|
||||
}
|
||||
return arg.returnVal();
|
||||
}/*exec()*/,
|
||||
@@ -1135,7 +1107,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
try {
|
||||
stmt.bind(bind);
|
||||
while(stmt.step()) rc.push(stmt.get(0,asType));
|
||||
stmt.reset(/*for INSERT...RETURNING locking case*/);
|
||||
}finally{
|
||||
stmt.finalize();
|
||||
}
|
||||
@@ -1270,7 +1241,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
not throw, it returns this object.
|
||||
*/
|
||||
checkRc: function(resultCode){
|
||||
return checkSqlite3Rc(this, resultCode);
|
||||
return DB.checkRc(this, resultCode);
|
||||
}
|
||||
}/*DB.prototype*/;
|
||||
|
||||
@@ -1331,15 +1302,15 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
};
|
||||
|
||||
/**
|
||||
If stmt._lockedByExec is truthy, this throws an exception
|
||||
If stmt._isLocked is truthy, this throws an exception
|
||||
complaining that the 2nd argument (an operation name,
|
||||
e.g. "bind()") is not legal while the statement is "locked".
|
||||
Locking happens before an exec()-like callback is passed a
|
||||
statement, to ensure that the callback does not mutate or
|
||||
finalize the statement. If it does not throw, it returns stmt.
|
||||
*/
|
||||
const affirmNotLockedByExec = function(stmt,currentOpName){
|
||||
if(stmt._lockedByExec){
|
||||
const affirmUnlocked = function(stmt,currentOpName){
|
||||
if(stmt._isLocked){
|
||||
toss3("Operation is illegal when statement is locked:",currentOpName);
|
||||
}
|
||||
return stmt;
|
||||
@@ -1352,11 +1323,14 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
success.
|
||||
*/
|
||||
const bindOne = function f(stmt,ndx,bindType,val){
|
||||
affirmNotLockedByExec(affirmStmtOpen(stmt), 'bind()');
|
||||
affirmUnlocked(affirmStmtOpen(stmt), 'bind()');
|
||||
if(!f._){
|
||||
f._tooBigInt = (v)=>toss3(
|
||||
"BigInt value is too big to store without precision loss:", v
|
||||
);
|
||||
/* Reminder: when not in BigInt mode, it's impossible for
|
||||
JS to represent a number out of the range we can bind,
|
||||
so we have no range checking. */
|
||||
f._ = {
|
||||
string: function(stmt, ndx, val, asBlob){
|
||||
const [pStr, n] = wasm.allocCString(val, true);
|
||||
@@ -1430,67 +1404,46 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
|
||||
Stmt.prototype = {
|
||||
/**
|
||||
"Finalizes" this statement. This is a no-op if the statement
|
||||
has already been finalized. Returns the result of
|
||||
sqlite3_finalize() (0 on success, non-0 on error), or the
|
||||
undefined value if the statement has already been
|
||||
finalized. Regardless of success or failure, most methods in
|
||||
this class will throw if called after this is.
|
||||
|
||||
This method always throws if called when it is illegal to do
|
||||
so. Namely, when triggered via a per-row callback handler of a
|
||||
DB.exec() call.
|
||||
"Finalizes" this statement. This is a no-op if the
|
||||
statement has already been finalizes. Returns
|
||||
undefined. Most methods in this class will throw if called
|
||||
after this is.
|
||||
*/
|
||||
finalize: function(){
|
||||
if(this.pointer){
|
||||
affirmNotLockedByExec(this,'finalize()');
|
||||
const rc = capi.sqlite3_finalize(this.pointer);
|
||||
affirmUnlocked(this,'finalize()');
|
||||
delete __stmtMap.get(this.db)[this.pointer];
|
||||
capi.sqlite3_finalize(this.pointer);
|
||||
__ptrMap.delete(this);
|
||||
delete this._mayGet;
|
||||
delete this.columnCount;
|
||||
delete this.parameterCount;
|
||||
delete this._lockedByExec;
|
||||
delete this.db;
|
||||
return rc;
|
||||
delete this._isLocked;
|
||||
}
|
||||
},
|
||||
/**
|
||||
Clears all bound values. Returns this object. Throws if this
|
||||
statement has been finalized or if modification of the
|
||||
statement is currently illegal (e.g. in the per-row callback of
|
||||
a DB.exec() call).
|
||||
*/
|
||||
/** Clears all bound values. Returns this object.
|
||||
Throws if this statement has been finalized. */
|
||||
clearBindings: function(){
|
||||
affirmNotLockedByExec(affirmStmtOpen(this), 'clearBindings()')
|
||||
affirmUnlocked(affirmStmtOpen(this), 'clearBindings()')
|
||||
capi.sqlite3_clear_bindings(this.pointer);
|
||||
this._mayGet = false;
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
Resets this statement so that it may be step()ed again from the
|
||||
beginning. Returns this object. Throws if this statement has
|
||||
been finalized, if it may not legally be reset because it is
|
||||
currently being used from a DB.exec() callback, or if the
|
||||
underlying call to sqlite3_reset() returns non-0.
|
||||
Resets this statement so that it may be step()ed again
|
||||
from the beginning. Returns this object. Throws if this
|
||||
statement has been finalized.
|
||||
|
||||
If passed a truthy argument then this.clearBindings() is
|
||||
also called, otherwise any existing bindings, along with
|
||||
any memory allocated for them, are retained.
|
||||
|
||||
In versions 3.42.0 and earlier, this function did not throw if
|
||||
sqlite3_reset() returns non-0, but it was discovered that
|
||||
throwing (or significant extra client-side code) is necessary
|
||||
in order to avoid certain silent failure scenarios, as
|
||||
discussed at:
|
||||
|
||||
https://sqlite.org/forum/forumpost/36f7a2e7494897df
|
||||
*/
|
||||
reset: function(alsoClearBinds){
|
||||
affirmNotLockedByExec(this,'reset()');
|
||||
affirmUnlocked(this,'reset()');
|
||||
if(alsoClearBinds) this.clearBindings();
|
||||
const rc = capi.sqlite3_reset(affirmStmtOpen(this).pointer);
|
||||
capi.sqlite3_reset(affirmStmtOpen(this).pointer);
|
||||
this._mayGet = false;
|
||||
checkSqlite3Rc(this.db, rc);
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
@@ -1639,7 +1592,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
value is returned. Throws on error.
|
||||
*/
|
||||
step: function(){
|
||||
affirmNotLockedByExec(this, 'step()');
|
||||
affirmUnlocked(this, 'step()');
|
||||
const rc = capi.sqlite3_step(affirmStmtOpen(this).pointer);
|
||||
switch(rc){
|
||||
case capi.SQLITE_DONE: return this._mayGet = false;
|
||||
@@ -1674,9 +1627,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
return this.reset();
|
||||
},
|
||||
/**
|
||||
Functions like step() except that it calls finalize() on this
|
||||
statement immediately after stepping, even if the step() call
|
||||
throws.
|
||||
Functions like step() except that it finalizes this statement
|
||||
immediately after stepping unless the step cannot be performed
|
||||
because the statement is locked. Throws on error, but any error
|
||||
other than the statement-is-locked case will also trigger
|
||||
finalization of this statement.
|
||||
|
||||
On success, it returns true if the step indicated that a row of
|
||||
data was available, else it returns false.
|
||||
@@ -1688,14 +1643,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
```
|
||||
*/
|
||||
stepFinalize: function(){
|
||||
try{
|
||||
const rc = this.step();
|
||||
this.reset(/*for INSERT...RETURNING locking case*/);
|
||||
return rc;
|
||||
}finally{
|
||||
try{this.finalize()}
|
||||
catch(e){/*ignored*/}
|
||||
}
|
||||
const rc = this.step();
|
||||
this.finalize();
|
||||
return rc;
|
||||
},
|
||||
/**
|
||||
Fetches the value from the given 0-based column index of
|
||||
@@ -1736,15 +1686,13 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
}
|
||||
if(Array.isArray(ndx)){
|
||||
let i = 0;
|
||||
const n = this.columnCount;
|
||||
while(i<n){
|
||||
while(i<this.columnCount){
|
||||
ndx[i] = this.get(i++);
|
||||
}
|
||||
return ndx;
|
||||
}else if(ndx && 'object'===typeof ndx){
|
||||
let i = 0;
|
||||
const n = this.columnCount;
|
||||
while(i<n){
|
||||
while(i<this.columnCount){
|
||||
ndx[capi.sqlite3_column_name(this.pointer,i)] = this.get(i++);
|
||||
}
|
||||
return ndx;
|
||||
@@ -1842,17 +1790,16 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
);
|
||||
},
|
||||
/**
|
||||
If this statement potentially has result columns, this function
|
||||
returns an array of all such names. If passed an array, it is
|
||||
used as the target and all names are appended to it. Returns
|
||||
the target array. Throws if this statement cannot have result
|
||||
columns. This object's columnCount property holds the number of
|
||||
columns.
|
||||
If this statement potentially has result columns, this
|
||||
function returns an array of all such names. If passed an
|
||||
array, it is used as the target and all names are appended
|
||||
to it. Returns the target array. Throws if this statement
|
||||
cannot have result columns. This object's columnCount member
|
||||
holds the number of columns.
|
||||
*/
|
||||
getColumnNames: function(tgt=[]){
|
||||
affirmColIndex(affirmStmtOpen(this),0);
|
||||
const n = this.columnCount;
|
||||
for(let i = 0; i < n; ++i){
|
||||
for(let i = 0; i < this.columnCount; ++i){
|
||||
tgt.push(capi.sqlite3_column_name(this.pointer, i));
|
||||
}
|
||||
return tgt;
|
||||
@@ -1879,20 +1826,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
Object.defineProperty(Stmt.prototype, 'pointer', prop);
|
||||
Object.defineProperty(DB.prototype, 'pointer', prop);
|
||||
}
|
||||
/**
|
||||
Stmt.columnCount is an interceptor for sqlite3_column_count().
|
||||
|
||||
This requires an unfortunate performance hit compared to caching
|
||||
columnCount when the Stmt is created/prepared (as was done in
|
||||
SQLite <=3.42.0), but is necessary in order to handle certain
|
||||
corner cases, as described in
|
||||
https://sqlite.org/forum/forumpost/7774b773937cbe0a.
|
||||
*/
|
||||
Object.defineProperty(Stmt.prototype, 'columnCount', {
|
||||
enumerable: false,
|
||||
get: function(){return capi.sqlite3_column_count(this.pointer)},
|
||||
set: ()=>toss3("The columnCount property is read-only.")
|
||||
});
|
||||
|
||||
/** The OO API's public namespace. */
|
||||
sqlite3.oo1 = {
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
exposed by this API. It is intended to be called one time at the
|
||||
end of the API amalgamation process, passed configuration details
|
||||
for the current environment, and then optionally be removed from
|
||||
the global object using `delete globalThis.sqlite3ApiBootstrap`.
|
||||
the global object using `delete self.sqlite3ApiBootstrap`.
|
||||
|
||||
This function is not intended for client-level use. It is intended
|
||||
for use in creating bundles configured for specific WASM
|
||||
@@ -53,12 +53,12 @@
|
||||
|
||||
- `memory`[^1]: optional WebAssembly.Memory object, defaulting to
|
||||
`exports.memory`. In Emscripten environments this should be set
|
||||
to `Module.wasmMemory` if the build uses `-sIMPORTED_MEMORY`, or be
|
||||
to `Module.wasmMemory` if the build uses `-sIMPORT_MEMORY`, or be
|
||||
left undefined/falsy to default to `exports.memory` when using
|
||||
WASM-exported memory.
|
||||
|
||||
- `bigIntEnabled`: true if BigInt support is enabled. Defaults to
|
||||
true if `globalThis.BigInt64Array` is available, else false. Some APIs
|
||||
true if `self.BigInt64Array` is available, else false. Some APIs
|
||||
will throw exceptions if called without BigInt support, as BigInt
|
||||
is required for marshalling C-side int64 into and out of JS.
|
||||
(Sidebar: it is technically possible to add int64 support via
|
||||
@@ -88,20 +88,20 @@
|
||||
can be replaced with (e.g.) empty functions to squelch all such
|
||||
output.
|
||||
|
||||
- `wasmfsOpfsDir`[^1]: Specifies the "mount point" of the OPFS-backed
|
||||
filesystem in WASMFS-capable builds.
|
||||
- `wasmfsOpfsDir`[^1]: As of 2022-12-17, this feature does not
|
||||
currently work due to incompatible Emscripten-side changes made
|
||||
in the WASMFS+OPFS combination. This option is currently ignored.
|
||||
|
||||
|
||||
[^1] = This property may optionally be a function, in which case
|
||||
this function calls that function to fetch the value,
|
||||
[^1] = This property may optionally be a function, in which case this
|
||||
function re-assigns calls that function to fetch the value,
|
||||
enabling delayed evaluation.
|
||||
|
||||
The returned object is the top-level sqlite3 namespace object.
|
||||
|
||||
*/
|
||||
'use strict';
|
||||
globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
apiConfig = (globalThis.sqlite3ApiConfig || sqlite3ApiBootstrap.defaultConfig)
|
||||
self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
apiConfig = (self.sqlite3ApiConfig || sqlite3ApiBootstrap.defaultConfig)
|
||||
){
|
||||
if(sqlite3ApiBootstrap.sqlite3){ /* already initalized */
|
||||
console.warn("sqlite3ApiBootstrap() called multiple times.",
|
||||
@@ -117,7 +117,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
-sWASM_BIGINT=1, else it will not. */
|
||||
return !!Module.HEAPU64;
|
||||
}
|
||||
return !!globalThis.BigInt64Array;
|
||||
return !!self.BigInt64Array;
|
||||
})(),
|
||||
debug: console.debug.bind(console),
|
||||
warn: console.warn.bind(console),
|
||||
@@ -125,11 +125,11 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
log: console.log.bind(console),
|
||||
wasmfsOpfsDir: '/opfs',
|
||||
/**
|
||||
useStdAlloc is just for testing allocator discrepancies. The
|
||||
useStdAlloc is just for testing an allocator discrepancy. The
|
||||
docs guarantee that this is false in the canonical builds. For
|
||||
99% of purposes it doesn't matter which allocators we use, but
|
||||
it becomes significant with, e.g., sqlite3_deserialize() and
|
||||
certain wasm.xWrap.resultAdapter()s.
|
||||
it becomes significant with, e.g., sqlite3_deserialize()
|
||||
and certain wasm.xWrap.resultAdapter()s.
|
||||
*/
|
||||
useStdAlloc: false
|
||||
}, apiConfig || {});
|
||||
@@ -149,6 +149,11 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
config[k] = config[k]();
|
||||
}
|
||||
});
|
||||
config.wasmOpfsDir =
|
||||
/* 2022-12-17: WASMFS+OPFS can no longer be activated from the
|
||||
main thread (aborts via a failed assert() if it's attempted),
|
||||
which eliminates any(?) benefit to supporting it. */ false;
|
||||
|
||||
/**
|
||||
The main sqlite3 binding API gets installed into this object,
|
||||
mimicking the C API as closely as we can. The numerous members
|
||||
@@ -767,7 +772,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
isBindableTypedArray,
|
||||
isInt32, isSQLableTypedArray, isTypedArray,
|
||||
typedArrayToString,
|
||||
isUIThread: ()=>(globalThis.window===globalThis && !!globalThis.document),
|
||||
isUIThread: ()=>(self.window===self && !!self.document),
|
||||
// is this true for ESM?: 'undefined'===typeof WorkerGlobalScope
|
||||
isSharedTypedArray,
|
||||
toss: function(...args){throw new Error(args.join(' '))},
|
||||
@@ -804,7 +809,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
|| toss3("Missing API config.exports (WASM module exports)."),
|
||||
|
||||
/**
|
||||
When Emscripten compiles with `-sIMPORTED_MEMORY`, it
|
||||
When Emscripten compiles with `-sIMPORT_MEMORY`, it
|
||||
initalizes the heap and imports it into wasm, as opposed to
|
||||
the other way around. In this case, the memory is not
|
||||
available via this.exports.memory.
|
||||
@@ -1172,35 +1177,35 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
/** State for sqlite3_wasmfs_opfs_dir(). */
|
||||
let __wasmfsOpfsDir = undefined;
|
||||
/**
|
||||
2022-12-17: incompatible WASMFS changes have made WASMFS+OPFS
|
||||
unavailable from the main thread, which eliminates the most
|
||||
significant benefit of supporting WASMFS. This function is now a
|
||||
no-op which always returns a falsy value. Before that change,
|
||||
this function behaved as documented below (and how it will again
|
||||
if we can find a compelling reason to support it).
|
||||
|
||||
If the wasm environment has a WASMFS/OPFS-backed persistent
|
||||
storage directory, its path is returned by this function. If it
|
||||
does not then it returns "" (noting that "" is a falsy value).
|
||||
|
||||
The first time this is called, this function inspects the current
|
||||
environment to determine whether persistence support is available
|
||||
and, if it is, enables it (if needed). After the first call it
|
||||
always returns the cached result.
|
||||
and, if it is, enables it (if needed).
|
||||
|
||||
If the returned string is not empty, any files stored under the
|
||||
given path (recursively) are housed in OPFS storage. If the
|
||||
returned string is empty, this particular persistent storage
|
||||
option is not available on the client.
|
||||
|
||||
Though the mount point name returned by this function is intended
|
||||
to remain stable, clients should not hard-coded it anywhere. Always call this function to get the path.
|
||||
|
||||
Note that this function is a no-op in must builds of this
|
||||
library, as the WASMFS capability requires a custom
|
||||
build.
|
||||
This function currently only recognizes the WASMFS/OPFS storage
|
||||
combination and its path refers to storage rooted in the
|
||||
Emscripten-managed virtual filesystem.
|
||||
*/
|
||||
capi.sqlite3_wasmfs_opfs_dir = function(){
|
||||
if(undefined !== __wasmfsOpfsDir) return __wasmfsOpfsDir;
|
||||
// If we have no OPFS, there is no persistent dir
|
||||
const pdir = config.wasmfsOpfsDir;
|
||||
console.error("sqlite3_wasmfs_opfs_dir() can no longer work due "+
|
||||
"to incompatible WASMFS changes. It will be removed.");
|
||||
if(!pdir
|
||||
|| !globalThis.FileSystemHandle
|
||||
|| !globalThis.FileSystemDirectoryHandle
|
||||
|| !globalThis.FileSystemFileHandle){
|
||||
|| !self.FileSystemHandle
|
||||
|| !self.FileSystemDirectoryHandle
|
||||
|| !self.FileSystemFileHandle){
|
||||
return __wasmfsOpfsDir = "";
|
||||
}
|
||||
try{
|
||||
@@ -1218,6 +1223,8 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
};
|
||||
|
||||
/**
|
||||
Experimental and subject to change or removal.
|
||||
|
||||
Returns true if sqlite3.capi.sqlite3_wasmfs_opfs_dir() is a
|
||||
non-empty string and the given name starts with (that string +
|
||||
'/'), else returns false.
|
||||
@@ -1227,6 +1234,13 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
return (p && name) ? name.startsWith(p+'/') : false;
|
||||
};
|
||||
|
||||
// This bit is highly arguable and is incompatible with the fiddle shell.
|
||||
if(false && 0===wasm.exports.sqlite3_vfs_find(0)){
|
||||
/* Assume that sqlite3_initialize() has not yet been called.
|
||||
This will be the case in an SQLITE_OS_KV build. */
|
||||
wasm.exports.sqlite3_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
Given an `sqlite3*`, an sqlite3_vfs name, and an optional db name
|
||||
(defaulting to "main"), returns a truthy value (see below) if
|
||||
@@ -1447,8 +1461,8 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
const rc = Object.create(null);
|
||||
rc.prefix = 'kvvfs-'+which;
|
||||
rc.stores = [];
|
||||
if('session'===which || ""===which) rc.stores.push(globalThis.sessionStorage);
|
||||
if('local'===which || ""===which) rc.stores.push(globalThis.localStorage);
|
||||
if('session'===which || ""===which) rc.stores.push(self.sessionStorage);
|
||||
if('local'===which || ""===which) rc.stores.push(self.localStorage);
|
||||
return rc;
|
||||
};
|
||||
|
||||
@@ -1523,11 +1537,8 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
Full docs: https://sqlite.org/c3ref/db_config.html
|
||||
|
||||
Returns capi.SQLITE_MISUSE if op is not a valid operation ID.
|
||||
|
||||
The variants which take `(int, int*)` arguments treat a
|
||||
missing or falsy pointer argument as 0.
|
||||
*/
|
||||
capi.sqlite3_db_config = function(pDb, op, ...args){
|
||||
capi.sqlite3_db_config = function f(pDb, op, ...args){
|
||||
if(!this.s){
|
||||
this.s = wasm.xWrap('sqlite3_wasm_db_config_s','int',
|
||||
['sqlite3*', 'int', 'string:static']
|
||||
@@ -1537,32 +1548,31 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
this.ip = wasm.xWrap('sqlite3_wasm_db_config_ip','int',
|
||||
['sqlite3*', 'int', 'int','*']);
|
||||
}
|
||||
const c = capi;
|
||||
switch(op){
|
||||
case capi.SQLITE_DBCONFIG_ENABLE_FKEY:
|
||||
case capi.SQLITE_DBCONFIG_ENABLE_TRIGGER:
|
||||
case capi.SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:
|
||||
case capi.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:
|
||||
case capi.SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:
|
||||
case capi.SQLITE_DBCONFIG_ENABLE_QPSG:
|
||||
case capi.SQLITE_DBCONFIG_TRIGGER_EQP:
|
||||
case capi.SQLITE_DBCONFIG_RESET_DATABASE:
|
||||
case capi.SQLITE_DBCONFIG_DEFENSIVE:
|
||||
case capi.SQLITE_DBCONFIG_WRITABLE_SCHEMA:
|
||||
case capi.SQLITE_DBCONFIG_LEGACY_ALTER_TABLE:
|
||||
case capi.SQLITE_DBCONFIG_DQS_DML:
|
||||
case capi.SQLITE_DBCONFIG_DQS_DDL:
|
||||
case capi.SQLITE_DBCONFIG_ENABLE_VIEW:
|
||||
case capi.SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:
|
||||
case capi.SQLITE_DBCONFIG_TRUSTED_SCHEMA:
|
||||
case capi.SQLITE_DBCONFIG_STMT_SCANSTATUS:
|
||||
case capi.SQLITE_DBCONFIG_REVERSE_SCANORDER:
|
||||
case c.SQLITE_DBCONFIG_ENABLE_FKEY:
|
||||
case c.SQLITE_DBCONFIG_ENABLE_TRIGGER:
|
||||
case c.SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:
|
||||
case c.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:
|
||||
case c.SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:
|
||||
case c.SQLITE_DBCONFIG_ENABLE_QPSG:
|
||||
case c.SQLITE_DBCONFIG_TRIGGER_EQP:
|
||||
case c.SQLITE_DBCONFIG_RESET_DATABASE:
|
||||
case c.SQLITE_DBCONFIG_DEFENSIVE:
|
||||
case c.SQLITE_DBCONFIG_WRITABLE_SCHEMA:
|
||||
case c.SQLITE_DBCONFIG_LEGACY_ALTER_TABLE:
|
||||
case c.SQLITE_DBCONFIG_DQS_DML:
|
||||
case c.SQLITE_DBCONFIG_DQS_DDL:
|
||||
case c.SQLITE_DBCONFIG_ENABLE_VIEW:
|
||||
case c.SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:
|
||||
case c.SQLITE_DBCONFIG_TRUSTED_SCHEMA:
|
||||
return this.ip(pDb, op, args[0], args[1] || 0);
|
||||
case capi.SQLITE_DBCONFIG_LOOKASIDE:
|
||||
case c.SQLITE_DBCONFIG_LOOKASIDE:
|
||||
return this.pii(pDb, op, args[0], args[1], args[2]);
|
||||
case capi.SQLITE_DBCONFIG_MAINDBNAME:
|
||||
case c.SQLITE_DBCONFIG_MAINDBNAME:
|
||||
return this.s(pDb, op, args[0]);
|
||||
default:
|
||||
return capi.SQLITE_MISUSE;
|
||||
return c.SQLITE_MISUSE;
|
||||
}
|
||||
}.bind(Object.create(null));
|
||||
|
||||
@@ -1645,8 +1655,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
do not.
|
||||
*/
|
||||
tgt.push(capi.sqlite3_value_to_js(
|
||||
wasm.peekPtr(pArgv + (wasm.ptrSizeof * i)),
|
||||
throwIfCannotConvert
|
||||
wasm.peekPtr(pArgv + (wasm.ptrSizeof * i))
|
||||
));
|
||||
}
|
||||
return tgt;
|
||||
@@ -1862,9 +1871,6 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
client: undefined,
|
||||
|
||||
/**
|
||||
This function is not part of the public interface, but a
|
||||
piece of internal bootstrapping infrastructure.
|
||||
|
||||
Performs any optional asynchronous library-level initialization
|
||||
which might be required. This function returns a Promise which
|
||||
resolves to the sqlite3 namespace object. Any error in the
|
||||
@@ -1880,19 +1886,27 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
then it must be called by client-level code, which must not use
|
||||
the library until the returned promise resolves.
|
||||
|
||||
If called multiple times it will return the same promise on
|
||||
subsequent calls. The current build setup precludes that
|
||||
possibility, so it's only a hypothetical problem if/when this
|
||||
function ever needs to be invoked by clients.
|
||||
Bug: if called while a prior call is still resolving, the 2nd
|
||||
call will resolve prematurely, before the 1st call has finished
|
||||
resolving. The current build setup precludes that possibility,
|
||||
so it's only a hypothetical problem if/when this function
|
||||
ever needs to be invoked by clients.
|
||||
|
||||
In Emscripten-based builds, this function is called
|
||||
automatically and deleted from this object.
|
||||
*/
|
||||
asyncPostInit: async function ff(){
|
||||
if(ff.isReady instanceof Promise) return ff.isReady;
|
||||
let lia = sqlite3ApiBootstrap.initializersAsync;
|
||||
asyncPostInit: async function(){
|
||||
let lip = sqlite3ApiBootstrap.initializersAsync;
|
||||
delete sqlite3ApiBootstrap.initializersAsync;
|
||||
const postInit = async ()=>{
|
||||
if(!lip || !lip.length) return Promise.resolve(sqlite3);
|
||||
lip = lip.map((f)=>{
|
||||
const p = (f instanceof Promise) ? f : f(sqlite3);
|
||||
return p.catch((e)=>{
|
||||
console.error("an async sqlite3 initializer failed:",e);
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
const postInit = ()=>{
|
||||
if(!sqlite3.__isUnderTest){
|
||||
/* Delete references to internal-only APIs which are used by
|
||||
some initializers. Retain them when running in test mode
|
||||
@@ -1901,25 +1915,23 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
/* It's conceivable that we might want to expose
|
||||
StructBinder to client-side code, but it's only useful if
|
||||
clients build their own sqlite3.wasm which contains their
|
||||
own C struct types. */
|
||||
one C struct types. */
|
||||
delete sqlite3.StructBinder;
|
||||
}
|
||||
return sqlite3;
|
||||
};
|
||||
const catcher = (e)=>{
|
||||
config.error("an async sqlite3 initializer failed:",e);
|
||||
throw e;
|
||||
};
|
||||
if(!lia || !lia.length){
|
||||
return ff.isReady = postInit().catch(catcher);
|
||||
if(1){
|
||||
/* Run all initializers in sequence. The advantage is that it
|
||||
allows us to have post-init cleanup defined outside of this
|
||||
routine at the end of the list and have it run at a
|
||||
well-defined time. */
|
||||
let p = lip.shift();
|
||||
while(lip.length) p = p.then(lip.shift());
|
||||
return p.then(postInit);
|
||||
}else{
|
||||
/* Run them in an arbitrary order. */
|
||||
return Promise.all(lip).then(postInit);
|
||||
}
|
||||
lia = lia.map((f)=>{
|
||||
return (f instanceof Function) ? async x=>f(sqlite3) : f;
|
||||
});
|
||||
lia.push(postInit);
|
||||
let p = Promise.resolve(sqlite3);
|
||||
while(lia.length) p = p.then(lia.shift());
|
||||
return ff.isReady = p.catch(catcher);
|
||||
},
|
||||
/**
|
||||
scriptInfo ideally gets injected into this object by the
|
||||
@@ -1950,7 +1962,7 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
return sqlite3;
|
||||
}/*sqlite3ApiBootstrap()*/;
|
||||
/**
|
||||
globalThis.sqlite3ApiBootstrap.initializers is an internal detail used by
|
||||
self.sqlite3ApiBootstrap.initializers is an internal detail used by
|
||||
the various pieces of the sqlite3 API's amalgamation process. It
|
||||
must not be modified by client code except when plugging such code
|
||||
into the amalgamation process.
|
||||
@@ -1968,18 +1980,18 @@ globalThis.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
utilized until the whwasmutil.js part is plugged in via
|
||||
sqlite3-api-glue.js.
|
||||
*/
|
||||
globalThis.sqlite3ApiBootstrap.initializers = [];
|
||||
self.sqlite3ApiBootstrap.initializers = [];
|
||||
/**
|
||||
globalThis.sqlite3ApiBootstrap.initializersAsync is an internal detail
|
||||
self.sqlite3ApiBootstrap.initializersAsync is an internal detail
|
||||
used by the sqlite3 API's amalgamation process. It must not be
|
||||
modified by client code except when plugging such code into the
|
||||
amalgamation process.
|
||||
|
||||
The counterpart of globalThis.sqlite3ApiBootstrap.initializers,
|
||||
The counterpart of self.sqlite3ApiBootstrap.initializers,
|
||||
specifically for initializers which are asynchronous. All entries in
|
||||
this list must be either async functions, non-async functions which
|
||||
return a Promise, or a Promise. Each function in the list is called
|
||||
with the sqlite3 object as its only argument.
|
||||
with the sqlite3 ojbect as its only argument.
|
||||
|
||||
The resolved value of any Promise is ignored and rejection will kill
|
||||
the asyncPostInit() process (at an indeterminate point because all
|
||||
@@ -1987,10 +1999,10 @@ globalThis.sqlite3ApiBootstrap.initializers = [];
|
||||
|
||||
This list is not processed until the client calls
|
||||
sqlite3.asyncPostInit(). This means, for example, that intializers
|
||||
added to globalThis.sqlite3ApiBootstrap.initializers may push entries to
|
||||
added to self.sqlite3ApiBootstrap.initializers may push entries to
|
||||
this list.
|
||||
*/
|
||||
globalThis.sqlite3ApiBootstrap.initializersAsync = [];
|
||||
self.sqlite3ApiBootstrap.initializersAsync = [];
|
||||
/**
|
||||
Client code may assign sqlite3ApiBootstrap.defaultConfig an
|
||||
object-type value before calling sqlite3ApiBootstrap() (without
|
||||
@@ -2000,12 +2012,13 @@ globalThis.sqlite3ApiBootstrap.initializersAsync = [];
|
||||
an environment-suitable configuration without having to define a new
|
||||
global-scope symbol.
|
||||
*/
|
||||
globalThis.sqlite3ApiBootstrap.defaultConfig = Object.create(null);
|
||||
self.sqlite3ApiBootstrap.defaultConfig = Object.create(null);
|
||||
/**
|
||||
Placeholder: gets installed by the first call to
|
||||
globalThis.sqlite3ApiBootstrap(). However, it is recommended that the
|
||||
self.sqlite3ApiBootstrap(). However, it is recommended that the
|
||||
caller of sqlite3ApiBootstrap() capture its return value and delete
|
||||
globalThis.sqlite3ApiBootstrap after calling it. It returns the same
|
||||
self.sqlite3ApiBootstrap after calling it. It returns the same
|
||||
value which will be stored here.
|
||||
*/
|
||||
globalThis.sqlite3ApiBootstrap.sqlite3 = undefined;
|
||||
self.sqlite3ApiBootstrap.sqlite3 = undefined;
|
||||
|
||||
|
||||
@@ -278,19 +278,6 @@
|
||||
The arguments are in the same form accepted by oo1.DB.exec(), with
|
||||
the exceptions noted below.
|
||||
|
||||
If the `countChanges` arguments property (added in version 3.43) is
|
||||
truthy then the `result` property contained by the returned object
|
||||
will have a `changeCount` property which holds the number of changes
|
||||
made by the provided SQL. Because the SQL may contain an arbitrary
|
||||
number of statements, the `changeCount` is calculated by calling
|
||||
`sqlite3_total_changes()` before and after the SQL is evaluated. If
|
||||
the value of `countChanges` is 64 then the `changeCount` property
|
||||
will be returned as a 64-bit integer in the form of a BigInt (noting
|
||||
that that will trigger an exception if used in a BigInt-incapable
|
||||
build). In the latter case, the number of changes is calculated by
|
||||
calling `sqlite3_total_changes64()` before and after the SQL is
|
||||
evaluated.
|
||||
|
||||
A function-type args.callback property cannot cross
|
||||
the window/Worker boundary, so is not useful here. If
|
||||
args.callback is a string then it is assumed to be a
|
||||
@@ -326,11 +313,11 @@
|
||||
options.columnNames may be populated by the call to db.exec().
|
||||
|
||||
*/
|
||||
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
sqlite3.initWorker1API = function(){
|
||||
'use strict';
|
||||
const toss = (...args)=>{throw new Error(args.join(' '))};
|
||||
if(!(globalThis.WorkerGlobalScope instanceof Function)){
|
||||
if('function' !== typeof importScripts){
|
||||
toss("initWorker1API() must be run from a Worker thread.");
|
||||
}
|
||||
const self = this.self;
|
||||
@@ -395,10 +382,10 @@ sqlite3.initWorker1API = function(){
|
||||
*/
|
||||
post: function(msg,xferList){
|
||||
if(xferList && xferList.length){
|
||||
globalThis.postMessage( msg, Array.from(xferList) );
|
||||
self.postMessage( msg, Array.from(xferList) );
|
||||
xferList.length = 0;
|
||||
}else{
|
||||
globalThis.postMessage(msg);
|
||||
self.postMessage(msg);
|
||||
}
|
||||
},
|
||||
/** Map of DB IDs to DBs. */
|
||||
@@ -536,13 +523,7 @@ sqlite3.initWorker1API = function(){
|
||||
}
|
||||
}
|
||||
try {
|
||||
const changeCount = !!rc.countChanges
|
||||
? db.changes(true,(64===rc.countChanges))
|
||||
: undefined;
|
||||
db.exec(rc);
|
||||
if(undefined !== changeCount){
|
||||
rc.changeCount = db.changes(true,64===rc.countChanges) - changeCount;
|
||||
}
|
||||
if(rc.callback instanceof Function){
|
||||
rc.callback = theCallback;
|
||||
/* Post a sentinel message to tell the client that the end
|
||||
@@ -608,7 +589,7 @@ sqlite3.initWorker1API = function(){
|
||||
}
|
||||
}/*wMsgHandler*/;
|
||||
|
||||
globalThis.onmessage = async function(ev){
|
||||
self.onmessage = async function(ev){
|
||||
ev = ev.data;
|
||||
let result, dbId = ev.dbId, evType = ev.type;
|
||||
const arrivalTime = performance.now();
|
||||
@@ -656,6 +637,6 @@ sqlite3.initWorker1API = function(){
|
||||
result: result
|
||||
}, wState.xfer);
|
||||
};
|
||||
globalThis.postMessage({type:'sqlite3-api',result:'worker1-ready'});
|
||||
self.postMessage({type:'sqlite3-api',result:'worker1-ready'});
|
||||
}.bind({self, sqlite3});
|
||||
});
|
||||
|
||||
@@ -35,9 +35,6 @@
|
||||
|
||||
https://developer.chrome.com/blog/sync-methods-for-accesshandles/
|
||||
|
||||
Firefox v111 and Safari 16.4, both released in March 2023, also
|
||||
include this.
|
||||
|
||||
We cannot change to the sync forms at this point without breaking
|
||||
clients who use Chrome v104-ish or higher. truncate(), getSize(),
|
||||
flush(), and close() are now (as of v108) synchronous. Calling them
|
||||
@@ -53,10 +50,10 @@
|
||||
const wPost = (type,...args)=>postMessage({type, payload:args});
|
||||
const installAsyncProxy = function(self){
|
||||
const toss = function(...args){throw new Error(args.join(' '))};
|
||||
if(globalThis.window === globalThis){
|
||||
if(self.window === self){
|
||||
toss("This code cannot run from the main thread.",
|
||||
"Load it as a Worker from a separate Worker.");
|
||||
}else if(!navigator?.storage?.getDirectory){
|
||||
}else if(!navigator.storage.getDirectory){
|
||||
toss("This API requires navigator.storage.getDirectory.");
|
||||
}
|
||||
|
||||
@@ -109,8 +106,8 @@ const installAsyncProxy = function(self){
|
||||
w += m.wait;
|
||||
m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0;
|
||||
}
|
||||
console.log(globalThis?.location?.href,
|
||||
"metrics for",globalThis?.location?.href,":\n",
|
||||
console.log(self.location.href,
|
||||
"metrics for",self.location.href,":\n",
|
||||
metrics,
|
||||
"\nTotal of",n,"op(s) for",t,"ms",
|
||||
"approx",w,"ms spent waiting on OPFS APIs.");
|
||||
@@ -821,24 +818,9 @@ const installAsyncProxy = function(self){
|
||||
}
|
||||
while(!flagAsyncShutdown){
|
||||
try {
|
||||
if('not-equal'!==Atomics.wait(
|
||||
if('timed-out'===Atomics.wait(
|
||||
state.sabOPView, state.opIds.whichOp, 0, state.asyncIdleWaitTime
|
||||
)){
|
||||
/* Maintenance note: we compare against 'not-equal' because
|
||||
|
||||
https://github.com/tomayac/sqlite-wasm/issues/12
|
||||
|
||||
is reporting that this occassionally, under high loads,
|
||||
returns 'ok', which leads to the whichOp being 0 (which
|
||||
isn't a valid operation ID and leads to an exception,
|
||||
along with a corresponding ugly console log
|
||||
message). Unfortunately, the conditions for that cannot
|
||||
be reliably reproduced. The only place in our code which
|
||||
writes a 0 to the state.opIds.whichOp SharedArrayBuffer
|
||||
index is a few lines down from here, and that instance
|
||||
is required in order for clear communication between
|
||||
the sync half of this proxy and this half.
|
||||
*/
|
||||
await releaseImplicitLocks();
|
||||
continue;
|
||||
}
|
||||
@@ -861,7 +843,7 @@ const installAsyncProxy = function(self){
|
||||
|
||||
navigator.storage.getDirectory().then(function(d){
|
||||
state.rootDir = d;
|
||||
globalThis.onmessage = function({data}){
|
||||
self.onmessage = function({data}){
|
||||
switch(data.type){
|
||||
case 'opfs-async-init':{
|
||||
/* Receive shared state from synchronous partner */
|
||||
@@ -898,17 +880,17 @@ const installAsyncProxy = function(self){
|
||||
wPost('opfs-async-loaded');
|
||||
}).catch((e)=>error("error initializing OPFS asyncer:",e));
|
||||
}/*installAsyncProxy()*/;
|
||||
if(!globalThis.SharedArrayBuffer){
|
||||
if(!self.SharedArrayBuffer){
|
||||
wPost('opfs-unavailable', "Missing SharedArrayBuffer API.",
|
||||
"The server must emit the COOP/COEP response headers to enable that.");
|
||||
}else if(!globalThis.Atomics){
|
||||
}else if(!self.Atomics){
|
||||
wPost('opfs-unavailable', "Missing Atomics API.",
|
||||
"The server must emit the COOP/COEP response headers to enable that.");
|
||||
}else if(!globalThis.FileSystemHandle ||
|
||||
!globalThis.FileSystemDirectoryHandle ||
|
||||
!globalThis.FileSystemFileHandle ||
|
||||
!globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle ||
|
||||
!navigator?.storage?.getDirectory){
|
||||
}else if(!self.FileSystemHandle ||
|
||||
!self.FileSystemDirectoryHandle ||
|
||||
!self.FileSystemFileHandle ||
|
||||
!self.FileSystemFileHandle.prototype.createSyncAccessHandle ||
|
||||
!navigator.storage.getDirectory){
|
||||
wPost('opfs-unavailable',"Missing required OPFS APIs.");
|
||||
}else{
|
||||
installAsyncProxy(self);
|
||||
|
||||
@@ -15,13 +15,10 @@
|
||||
with its virtual table counterpart, sqlite3.vtab.
|
||||
*/
|
||||
'use strict';
|
||||
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
const wasm = sqlite3.wasm, capi = sqlite3.capi, toss = sqlite3.util.toss3;
|
||||
const vfs = Object.create(null), vtab = Object.create(null);
|
||||
|
||||
const StructBinder = sqlite3.StructBinder
|
||||
/* we require a local alias b/c StructBinder is removed from the sqlite3
|
||||
object during the final steps of the API cleanup. */;
|
||||
sqlite3.vfs = vfs;
|
||||
sqlite3.vtab = vtab;
|
||||
|
||||
@@ -100,7 +97,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
|
||||
ACHTUNG: because we cannot generically know how to transform JS
|
||||
exceptions into result codes, the installed functions do no
|
||||
automatic catching of exceptions. It is critical, to avoid
|
||||
automatic catching of exceptions. It is critical, to avoid
|
||||
undefined behavior in the C layer, that methods mapped via
|
||||
this function do not throw. The exception, as it were, to that
|
||||
rule is...
|
||||
@@ -115,7 +112,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
const installMethod = function callee(
|
||||
tgt, name, func, applyArgcCheck = callee.installMethodArgcCheck
|
||||
){
|
||||
if(!(tgt instanceof StructBinder.StructType)){
|
||||
if(!(tgt instanceof sqlite3.StructBinder.StructType)){
|
||||
toss("Usage error: target object is-not-a StructType.");
|
||||
}else if(!(func instanceof Function) && !wasm.isPtr(func)){
|
||||
toss("Usage errror: expecting a Function or WASM pointer to one.");
|
||||
@@ -135,7 +132,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
}
|
||||
};
|
||||
/* An ondispose() callback for use with
|
||||
StructBinder-created types. */
|
||||
sqlite3.StructBinder-created types. */
|
||||
callee.removeFuncList = function(){
|
||||
if(this.ondispose.__removeFuncList){
|
||||
this.ondispose.__removeFuncList.forEach(
|
||||
@@ -224,7 +221,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
and the first is an object, it's instead equivalent to calling
|
||||
installMethods(this,...arguments).
|
||||
*/
|
||||
StructBinder.StructType.prototype.installMethod = function callee(
|
||||
sqlite3.StructBinder.StructType.prototype.installMethod = function callee(
|
||||
name, func, applyArgcCheck = installMethod.installMethodArgcCheck
|
||||
){
|
||||
return (arguments.length < 3 && name && 'object'===typeof name)
|
||||
@@ -236,7 +233,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
Equivalent to calling installMethods() with a first argument
|
||||
of this object.
|
||||
*/
|
||||
StructBinder.StructType.prototype.installMethods = function(
|
||||
sqlite3.StructBinder.StructType.prototype.installMethods = function(
|
||||
methods, applyArgcCheck = installMethod.installMethodArgcCheck
|
||||
){
|
||||
return installMethods(this, methods, applyArgcCheck);
|
||||
@@ -295,8 +292,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
|
||||
- If `struct.$zName` is falsy and the entry has a string-type
|
||||
`name` property, `struct.$zName` is set to the C-string form of
|
||||
that `name` value before registerVfs() is called. That string
|
||||
gets added to the on-dispose state of the struct.
|
||||
that `name` value before registerVfs() is called.
|
||||
|
||||
On success returns this object. Throws on error.
|
||||
*/
|
||||
@@ -609,7 +605,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
This is to facilitate creation of those methods inline in the
|
||||
passed-in object without requiring the client to explicitly get a
|
||||
reference to one of them in order to assign it to the other
|
||||
one.
|
||||
one.
|
||||
|
||||
The `catchExceptions`-installed handlers will account for
|
||||
identical references to the above functions and will install the
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,3 @@
|
||||
//#ifnot target=node
|
||||
/*
|
||||
2022-09-18
|
||||
|
||||
@@ -19,12 +18,12 @@
|
||||
after sqlite3-api-oo1.js and before sqlite3-api-cleanup.js.
|
||||
*/
|
||||
'use strict';
|
||||
globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
/**
|
||||
installOpfsVfs() returns a Promise which, on success, installs an
|
||||
sqlite3_vfs named "opfs", suitable for use with all sqlite3 APIs
|
||||
which accept a VFS. It is intended to be called via
|
||||
sqlite3ApiBootstrap.initializers or an equivalent mechanism.
|
||||
sqlite3ApiBootstrap.initializersAsync or an equivalent mechanism.
|
||||
|
||||
The installed VFS uses the Origin-Private FileSystem API for
|
||||
all file storage. On error it is rejected with an exception
|
||||
@@ -77,23 +76,23 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
`opfs` property, containing several OPFS-specific utilities.
|
||||
*/
|
||||
const installOpfsVfs = function callee(options){
|
||||
if(!globalThis.SharedArrayBuffer
|
||||
|| !globalThis.Atomics){
|
||||
if(!self.SharedArrayBuffer
|
||||
|| !self.Atomics){
|
||||
return Promise.reject(
|
||||
new Error("Cannot install OPFS: Missing SharedArrayBuffer and/or Atomics. "+
|
||||
"The server must emit the COOP/COEP response headers to enable those. "+
|
||||
"See https://sqlite.org/wasm/doc/trunk/persistence.md#coop-coep")
|
||||
);
|
||||
}else if('undefined'===typeof WorkerGlobalScope){
|
||||
}else if(self.window===self && self.document){
|
||||
return Promise.reject(
|
||||
new Error("The OPFS sqlite3_vfs cannot run in the main thread "+
|
||||
"because it requires Atomics.wait().")
|
||||
);
|
||||
}else if(!globalThis.FileSystemHandle ||
|
||||
!globalThis.FileSystemDirectoryHandle ||
|
||||
!globalThis.FileSystemFileHandle ||
|
||||
!globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle ||
|
||||
!navigator?.storage?.getDirectory){
|
||||
}else if(!self.FileSystemHandle ||
|
||||
!self.FileSystemDirectoryHandle ||
|
||||
!self.FileSystemFileHandle ||
|
||||
!self.FileSystemFileHandle.prototype.createSyncAccessHandle ||
|
||||
!navigator.storage.getDirectory){
|
||||
return Promise.reject(
|
||||
new Error("Missing required OPFS APIs.")
|
||||
);
|
||||
@@ -101,11 +100,7 @@ const installOpfsVfs = function callee(options){
|
||||
if(!options || 'object'!==typeof options){
|
||||
options = Object.create(null);
|
||||
}
|
||||
const urlParams = new URL(globalThis.location.href).searchParams;
|
||||
if(urlParams.has('opfs-disable')){
|
||||
//sqlite3.config.warn('Explicitly not installing "opfs" VFS due to opfs-disable flag.');
|
||||
return Promise.resolve(sqlite3);
|
||||
}
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
if(undefined===options.verbose){
|
||||
options.verbose = urlParams.has('opfs-verbose')
|
||||
? (+urlParams.get('opfs-verbose') || 2) : 1;
|
||||
@@ -117,17 +112,17 @@ const installOpfsVfs = function callee(options){
|
||||
options.proxyUri = callee.defaultProxyUri;
|
||||
}
|
||||
|
||||
//sqlite3.config.warn("OPFS options =",options,globalThis.location);
|
||||
//sqlite3.config.warn("OPFS options =",options,self.location);
|
||||
|
||||
if('function' === typeof options.proxyUri){
|
||||
options.proxyUri = options.proxyUri();
|
||||
}
|
||||
const thePromise = new Promise(function(promiseResolve_, promiseReject_){
|
||||
const loggers = [
|
||||
sqlite3.config.error,
|
||||
sqlite3.config.warn,
|
||||
sqlite3.config.log
|
||||
];
|
||||
const thePromise = new Promise(function(promiseResolve, promiseReject_){
|
||||
const loggers = {
|
||||
0:sqlite3.config.error.bind(console),
|
||||
1:sqlite3.config.warn.bind(console),
|
||||
2:sqlite3.config.log.bind(console)
|
||||
};
|
||||
const logImpl = (level,...args)=>{
|
||||
if(options.verbose>level) loggers[level]("OPFS syncer:",...args);
|
||||
};
|
||||
@@ -154,11 +149,11 @@ const installOpfsVfs = function callee(options){
|
||||
Returns true if _this_ thread has access to the OPFS APIs.
|
||||
*/
|
||||
const thisThreadHasOPFS = ()=>{
|
||||
return globalThis.FileSystemHandle &&
|
||||
globalThis.FileSystemDirectoryHandle &&
|
||||
globalThis.FileSystemFileHandle &&
|
||||
globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle &&
|
||||
navigator?.storage?.getDirectory;
|
||||
return self.FileSystemHandle &&
|
||||
self.FileSystemDirectoryHandle &&
|
||||
self.FileSystemFileHandle &&
|
||||
self.FileSystemFileHandle.prototype.createSyncAccessHandle &&
|
||||
navigator.storage.getDirectory;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -176,8 +171,8 @@ const installOpfsVfs = function callee(options){
|
||||
m.avgTime = (m.count && m.time) ? (m.time / m.count) : 0;
|
||||
m.avgWait = (m.count && m.wait) ? (m.wait / m.count) : 0;
|
||||
}
|
||||
sqlite3.config.log(globalThis.location.href,
|
||||
"metrics for",globalThis.location.href,":",metrics,
|
||||
sqlite3.config.log(self.location.href,
|
||||
"metrics for",self.location.href,":",metrics,
|
||||
"\nTotal of",n,"op(s) for",t,
|
||||
"ms (incl. "+w+" ms of waiting on the async side)");
|
||||
sqlite3.config.log("Serialization metrics:",metrics.s11n);
|
||||
@@ -196,19 +191,12 @@ const installOpfsVfs = function callee(options){
|
||||
s.count = s.time = 0;
|
||||
}
|
||||
}/*metrics*/;
|
||||
const opfsVfs = new sqlite3_vfs();
|
||||
const opfsIoMethods = new sqlite3_io_methods();
|
||||
const opfsVfs = new sqlite3_vfs()
|
||||
.addOnDispose( ()=>opfsIoMethods.dispose());
|
||||
let promiseWasRejected = undefined;
|
||||
const promiseReject = (err)=>{
|
||||
promiseWasRejected = true;
|
||||
const promiseReject = function(err){
|
||||
opfsVfs.dispose();
|
||||
return promiseReject_(err);
|
||||
};
|
||||
const promiseResolve = ()=>{
|
||||
promiseWasRejected = false;
|
||||
return promiseResolve_(sqlite3);
|
||||
};
|
||||
const W =
|
||||
//#if target=es6-bundler-friendly
|
||||
new Worker(new URL("sqlite3-opfs-async-proxy.js", import.meta.url));
|
||||
@@ -217,18 +205,6 @@ const installOpfsVfs = function callee(options){
|
||||
//#else
|
||||
new Worker(options.proxyUri);
|
||||
//#endif
|
||||
setTimeout(()=>{
|
||||
/* At attempt to work around a browser-specific quirk in which
|
||||
the Worker load is failing in such a way that we neither
|
||||
resolve nor reject it. This workaround gives that resolve/reject
|
||||
a time limit and rejects if that timer expires. Discussion:
|
||||
https://sqlite.org/forum/forumpost/a708c98dcb3ef */
|
||||
if(undefined===promiseWasRejected){
|
||||
promiseReject(
|
||||
new Error("Timeout while waiting for OPFS async proxy worker.")
|
||||
);
|
||||
}
|
||||
}, 4000);
|
||||
W._originalOnError = W.onerror /* will be restored later */;
|
||||
W.onerror = function(err){
|
||||
// The error object doesn't contain any useful info when the
|
||||
@@ -241,17 +217,17 @@ const installOpfsVfs = function callee(options){
|
||||
? new sqlite3_vfs(pDVfs)
|
||||
: null /* dVfs will be null when sqlite3 is built with
|
||||
SQLITE_OS_OTHER. */;
|
||||
opfsIoMethods.$iVersion = 1;
|
||||
opfsVfs.$iVersion = 2/*yes, two*/;
|
||||
opfsVfs.$szOsFile = capi.sqlite3_file.structInfo.sizeof;
|
||||
opfsVfs.$mxPathname = 1024/*sure, why not?*/;
|
||||
opfsVfs.$zName = wasm.allocCString("opfs");
|
||||
// All C-side memory of opfsVfs is zeroed out, but just to be explicit:
|
||||
opfsVfs.$xDlOpen = opfsVfs.$xDlError = opfsVfs.$xDlSym = opfsVfs.$xDlClose = null;
|
||||
opfsVfs.addOnDispose(
|
||||
opfsVfs.ondispose = [
|
||||
'$zName', opfsVfs.$zName,
|
||||
'cleanup default VFS wrapper', ()=>(dVfs ? dVfs.dispose() : null)
|
||||
);
|
||||
'cleanup default VFS wrapper', ()=>(dVfs ? dVfs.dispose() : null),
|
||||
'cleanup opfsIoMethods', ()=>opfsIoMethods.dispose()
|
||||
];
|
||||
/**
|
||||
Pedantic sidebar about opfsVfs.ondispose: the entries in that array
|
||||
are items to clean up when opfsVfs.dispose() is called, but in this
|
||||
@@ -304,7 +280,6 @@ const installOpfsVfs = function callee(options){
|
||||
lock contention to free up.
|
||||
*/
|
||||
state.asyncIdleWaitTime = 150;
|
||||
|
||||
/**
|
||||
Whether the async counterpart should log exceptions to
|
||||
the serialization channel. That produces a great deal of
|
||||
@@ -360,6 +335,7 @@ const installOpfsVfs = function callee(options){
|
||||
state.opIds.xClose = i++;
|
||||
state.opIds.xDelete = i++;
|
||||
state.opIds.xDeleteNoWait = i++;
|
||||
state.opIds.xFileControl = i++;
|
||||
state.opIds.xFileSize = i++;
|
||||
state.opIds.xLock = i++;
|
||||
state.opIds.xOpen = i++;
|
||||
@@ -491,8 +467,7 @@ const installOpfsVfs = function callee(options){
|
||||
This proxy de/serializes cross-thread function arguments and
|
||||
output-pointer values via the state.sabIO SharedArrayBuffer,
|
||||
using the region defined by (state.sabS11nOffset,
|
||||
state.sabS11nOffset + state.sabS11nSize]. Only one dataset is
|
||||
recorded at a time.
|
||||
state.sabS11nOffset]. Only one dataset is recorded at a time.
|
||||
|
||||
This is not a general-purpose format. It only supports the
|
||||
range of operations, and data sizes, needed by the
|
||||
@@ -725,9 +700,12 @@ const installOpfsVfs = function callee(options){
|
||||
return capi.SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN;
|
||||
},
|
||||
xFileControl: function(pFile, opId, pArg){
|
||||
/*mTimeStart('xFileControl');
|
||||
mTimeEnd();*/
|
||||
return capi.SQLITE_NOTFOUND;
|
||||
mTimeStart('xFileControl');
|
||||
const rc = (capi.SQLITE_FCNTL_SYNC===opId)
|
||||
? opRun('xSync', pFile, 0)
|
||||
: capi.SQLITE_NOTFOUND;
|
||||
mTimeEnd();
|
||||
return rc;
|
||||
},
|
||||
xFileSize: function(pFile,pSz64){
|
||||
mTimeStart('xFileSize');
|
||||
@@ -783,11 +761,8 @@ const installOpfsVfs = function callee(options){
|
||||
return rc;
|
||||
},
|
||||
xSync: function(pFile,flags){
|
||||
mTimeStart('xSync');
|
||||
++metrics.xSync.count;
|
||||
const rc = opRun('xSync', pFile, flags);
|
||||
mTimeEnd();
|
||||
return rc;
|
||||
return 0; // impl'd in xFileControl()
|
||||
},
|
||||
xTruncate: function(pFile,sz64){
|
||||
mTimeStart('xTruncate');
|
||||
@@ -839,19 +814,22 @@ const installOpfsVfs = function callee(options){
|
||||
/* If it turns out that we need to adjust for timezone, see:
|
||||
https://stackoverflow.com/a/11760121/1458521 */
|
||||
wasm.poke(pOut, 2440587.5 + (new Date().getTime()/86400000),
|
||||
'double');
|
||||
'double');
|
||||
return 0;
|
||||
},
|
||||
xCurrentTimeInt64: function(pVfs,pOut){
|
||||
// TODO: confirm that this calculation is correct
|
||||
wasm.poke(pOut, (2440587.5 * 86400000) + new Date().getTime(),
|
||||
'i64');
|
||||
'i64');
|
||||
return 0;
|
||||
},
|
||||
xDelete: function(pVfs, zName, doSyncDir){
|
||||
mTimeStart('xDelete');
|
||||
const rc = opRun('xDelete', wasm.cstrToJs(zName), doSyncDir, false);
|
||||
opRun('xDelete', wasm.cstrToJs(zName), doSyncDir, false);
|
||||
/* We're ignoring errors because we cannot yet differentiate
|
||||
between harmless and non-harmless failures. */
|
||||
mTimeEnd();
|
||||
return rc;
|
||||
return 0;
|
||||
},
|
||||
xFullPathname: function(pVfs,zName,nOut,pOut){
|
||||
/* Until/unless we have some notion of "current dir"
|
||||
@@ -1093,7 +1071,7 @@ const installOpfsVfs = function callee(options){
|
||||
propagate any exception on error, rather than returning false.
|
||||
*/
|
||||
opfsUtil.unlink = async function(fsEntryName, recursive = false,
|
||||
throwOnError = false){
|
||||
throwOnError = false){
|
||||
try {
|
||||
const [hDir, filenamePart] =
|
||||
await opfsUtil.getDirForFilename(fsEntryName, false);
|
||||
@@ -1190,23 +1168,11 @@ const installOpfsVfs = function callee(options){
|
||||
contention. */
|
||||
sqlite3.capi.sqlite3_busy_timeout(oo1Db, 10000);
|
||||
sqlite3.capi.sqlite3_exec(oo1Db, [
|
||||
/* As of July 2023, the PERSIST journal mode on OPFS is
|
||||
somewhat slower than DELETE or TRUNCATE (it was faster
|
||||
before Chrome version 108 or 109). TRUNCATE and DELETE
|
||||
have very similar performance on OPFS.
|
||||
|
||||
Roy Hashimoto notes that TRUNCATE and PERSIST modes may
|
||||
decrease OPFS concurrency because multiple connections
|
||||
can open the journal file in those modes:
|
||||
|
||||
https://github.com/rhashimoto/wa-sqlite/issues/68
|
||||
|
||||
Given that, and the fact that testing has not revealed
|
||||
any appreciable difference between performance of
|
||||
TRUNCATE and DELETE modes on OPFS, we currently (as of
|
||||
2023-07-13) default to DELETE mode.
|
||||
*/
|
||||
"pragma journal_mode=DELETE;",
|
||||
/* Truncate journal mode is faster than delete for
|
||||
this vfs, per speedtest1. That gap seems to have closed with
|
||||
Chrome version 108 or 109, but "persist" is very roughly 5-6%
|
||||
faster than truncate in initial tests. */
|
||||
"pragma journal_mode=persist;",
|
||||
/*
|
||||
This vfs benefits hugely from cache on moderate/large
|
||||
speedtest1 --size 50 and --size 100 workloads. We
|
||||
@@ -1295,18 +1261,14 @@ const installOpfsVfs = function callee(options){
|
||||
promiseReject(new Error(data.payload.join(' ')));
|
||||
break;
|
||||
case 'opfs-async-loaded':
|
||||
/* Arrives as soon as the asyc proxy finishes loading.
|
||||
Pass our config and shared state on to the async
|
||||
worker. */
|
||||
/*Arrives as soon as the asyc proxy finishes loading.
|
||||
Pass our config and shared state on to the async worker.*/
|
||||
W.postMessage({type: 'opfs-async-init',args: state});
|
||||
break;
|
||||
case 'opfs-async-inited': {
|
||||
/* Indicates that the async partner has received the 'init'
|
||||
and has finished initializing, so the real work can
|
||||
begin... */
|
||||
if(true===promiseWasRejected){
|
||||
break /* promise was already rejected via timer */;
|
||||
}
|
||||
case 'opfs-async-inited':{
|
||||
/*Indicates that the async partner has received the 'init'
|
||||
and has finished initializing, so the real work can
|
||||
begin...*/
|
||||
try {
|
||||
sqlite3.vfs.installVfs({
|
||||
io: {struct: opfsIoMethods, methods: ioSyncWrappers},
|
||||
@@ -1327,10 +1289,10 @@ const installOpfsVfs = function callee(options){
|
||||
sqlite3.opfs = opfsUtil;
|
||||
opfsUtil.rootDirectory = d;
|
||||
log("End of OPFS sqlite3_vfs setup.", opfsVfs);
|
||||
promiseResolve();
|
||||
promiseResolve(sqlite3);
|
||||
}).catch(promiseReject);
|
||||
}else{
|
||||
promiseResolve();
|
||||
promiseResolve(sqlite3);
|
||||
}
|
||||
}catch(e){
|
||||
error(e);
|
||||
@@ -1338,15 +1300,10 @@ const installOpfsVfs = function callee(options){
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
const errMsg = (
|
||||
"Unexpected message from the OPFS async worker: " +
|
||||
JSON.stringify(data)
|
||||
);
|
||||
error(errMsg);
|
||||
promiseReject(new Error(errMsg));
|
||||
default:
|
||||
promiseReject(e);
|
||||
error("Unexpected message from the async worker:",data);
|
||||
break;
|
||||
}
|
||||
}/*switch(data.type)*/
|
||||
}/*W.onmessage()*/;
|
||||
})/*thePromise*/;
|
||||
@@ -1354,7 +1311,7 @@ const installOpfsVfs = function callee(options){
|
||||
}/*installOpfsVfs()*/;
|
||||
installOpfsVfs.defaultProxyUri =
|
||||
"sqlite3-opfs-async-proxy.js";
|
||||
globalThis.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
|
||||
self.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
|
||||
try{
|
||||
let proxyJs = installOpfsVfs.defaultProxyUri;
|
||||
if(sqlite3.scriptInfo.sqlite3Dir){
|
||||
@@ -1367,10 +1324,7 @@ globalThis.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
|
||||
});
|
||||
}catch(e){
|
||||
sqlite3.config.error("installOpfsVfs() exception:",e);
|
||||
return Promise.reject(e);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}/*sqlite3ApiBootstrap.initializers.push()*/);
|
||||
//#else
|
||||
/* The OPFS VFS parts are elided from builds targeting node.js. */
|
||||
//#endif target=node
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
Dummy function stubs to get sqlite3.c compiling with
|
||||
wasi-sdk. This requires, in addition:
|
||||
|
||||
-D_WASI_EMULATED_MMAN -D_WASI_EMULATED_GETPID
|
||||
|
||||
-lwasi-emulated-getpid
|
||||
*/
|
||||
typedef unsigned mode_t;
|
||||
int fchmod(int fd, mode_t mode);
|
||||
int fchmod(int fd, mode_t mode){
|
||||
return (fd && mode) ? 0 : 0;
|
||||
}
|
||||
typedef unsigned uid_t;
|
||||
typedef uid_t gid_t;
|
||||
int fchown(int fd, uid_t owner, gid_t group);
|
||||
int fchown(int fd, uid_t owner, gid_t group){
|
||||
return (fd && owner && group) ? 0 : 0;
|
||||
}
|
||||
uid_t geteuid(void);
|
||||
uid_t geteuid(void){return 0;}
|
||||
#if !defined(F_WRLCK)
|
||||
enum {
|
||||
F_WRLCK,
|
||||
F_RDLCK,
|
||||
F_GETLK,
|
||||
F_SETLK,
|
||||
F_UNLCK
|
||||
};
|
||||
#endif
|
||||
|
||||
#undef HAVE_PREAD
|
||||
|
||||
#include <wasi/api.h>
|
||||
#define WASM__KEEP __attribute__((used))
|
||||
|
||||
#if 0
|
||||
/**
|
||||
wasi-sdk cannot build sqlite3's default VFS without at least the following
|
||||
functions. They are apparently syscalls which clients have to implement or
|
||||
otherwise obtain.
|
||||
|
||||
https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md
|
||||
*/
|
||||
environ_get
|
||||
environ_sizes_get
|
||||
clock_time_get
|
||||
fd_close
|
||||
fd_fdstat_get
|
||||
fd_fdstat_set_flags
|
||||
fd_filestat_get
|
||||
fd_filestat_set_size
|
||||
fd_pread
|
||||
fd_prestat_get
|
||||
fd_prestat_dir_name
|
||||
fd_read
|
||||
fd_seek
|
||||
fd_sync
|
||||
fd_write
|
||||
path_create_directory
|
||||
path_filestat_get
|
||||
path_filestat_set_times
|
||||
path_open
|
||||
path_readlink
|
||||
path_remove_directory
|
||||
path_unlink_file
|
||||
poll_oneoff
|
||||
proc_exit
|
||||
#endif
|
||||
+49
-79
@@ -151,7 +151,7 @@
|
||||
/**********************************************************************/
|
||||
/* SQLITE_T... */
|
||||
#ifndef SQLITE_TEMP_STORE
|
||||
# define SQLITE_TEMP_STORE 2
|
||||
# define SQLITE_TEMP_STORE 3
|
||||
#endif
|
||||
#ifndef SQLITE_THREADSAFE
|
||||
# define SQLITE_THREADSAFE 0
|
||||
@@ -163,14 +163,15 @@
|
||||
# define SQLITE_USE_URI 1
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_WASM_EXTRA_INIT
|
||||
# define SQLITE_EXTRA_INIT sqlite3_wasm_extra_init
|
||||
#include <assert.h>
|
||||
#include "sqlite3.c" /* yes, .c instead of .h. */
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
# include <emscripten/console.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
** SQLITE_WASM_EXPORT is functionally identical to EMSCRIPTEN_KEEPALIVE
|
||||
** SQLITE_WASM_KEEP is functionally identical to EMSCRIPTEN_KEEPALIVE
|
||||
** but is not Emscripten-specific. It explicitly marks functions for
|
||||
** export into the target wasm file without requiring explicit listing
|
||||
** of those functions in Emscripten's -sEXPORTED_FUNCTIONS=... list
|
||||
@@ -192,34 +193,10 @@
|
||||
** this writing we are tied to Emscripten for various reasons
|
||||
** and cannot test the library with other build environments.
|
||||
*/
|
||||
#define SQLITE_WASM_EXPORT __attribute__((used,visibility("default")))
|
||||
#define SQLITE_WASM_KEEP __attribute__((used,visibility("default")))
|
||||
// See also:
|
||||
//__attribute__((export_name("theExportedName"), used, visibility("default")))
|
||||
|
||||
/*
|
||||
** Which sqlite3.c we're using needs to be configurable to enable
|
||||
** building against a custom copy, e.g. the SEE variant. Note that we
|
||||
** #include the .c file, rather than the header, so that the WASM
|
||||
** extensions have access to private API internals.
|
||||
**
|
||||
** The caveat here is that custom variants need to account for
|
||||
** exporting any necessary symbols (e.g. sqlite3_activate_see()). We
|
||||
** cannot export them from here using SQLITE_WASM_EXPORT because that
|
||||
** attribute (apparently) has to be part of the function definition.
|
||||
*/
|
||||
#ifndef SQLITE_C
|
||||
# define SQLITE_C sqlite3.c /* yes, .c instead of .h. */
|
||||
#endif
|
||||
#define INC__STRINGIFY_(f) #f
|
||||
#define INC__STRINGIFY(f) INC__STRINGIFY_(f)
|
||||
#include INC__STRINGIFY(SQLITE_C)
|
||||
#undef INC__STRINGIFY_
|
||||
#undef INC__STRINGIFY
|
||||
#undef SQLITE_C
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
# include <emscripten/console.h>
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/*
|
||||
@@ -233,24 +210,24 @@
|
||||
** Another option is to malloc() a chunk of our own and call that our
|
||||
** "stack".
|
||||
*/
|
||||
SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_end(void){
|
||||
SQLITE_WASM_KEEP void * sqlite3_wasm_stack_end(void){
|
||||
extern void __heap_base
|
||||
/* see https://stackoverflow.com/questions/10038964 */;
|
||||
return &__heap_base;
|
||||
}
|
||||
SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_begin(void){
|
||||
SQLITE_WASM_KEEP void * sqlite3_wasm_stack_begin(void){
|
||||
extern void __data_end;
|
||||
return &__data_end;
|
||||
}
|
||||
static void * pWasmStackPtr = 0;
|
||||
SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_ptr(void){
|
||||
SQLITE_WASM_KEEP void * sqlite3_wasm_stack_ptr(void){
|
||||
if(!pWasmStackPtr) pWasmStackPtr = sqlite3_wasm_stack_end();
|
||||
return pWasmStackPtr;
|
||||
}
|
||||
SQLITE_WASM_EXPORT void sqlite3_wasm_stack_restore(void * p){
|
||||
SQLITE_WASM_KEEP void sqlite3_wasm_stack_restore(void * p){
|
||||
pWasmStackPtr = p;
|
||||
}
|
||||
SQLITE_WASM_EXPORT void * sqlite3_wasm_stack_alloc(int n){
|
||||
SQLITE_WASM_KEEP void * sqlite3_wasm_stack_alloc(int n){
|
||||
if(n<=0) return 0;
|
||||
n = (n + 7) & ~7 /* align to 8-byte boundary */;
|
||||
unsigned char * const p = (unsigned char *)sqlite3_wasm_stack_ptr();
|
||||
@@ -286,14 +263,14 @@ static struct {
|
||||
/*
|
||||
** Returns the current pstack position.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT void * sqlite3_wasm_pstack_ptr(void){
|
||||
SQLITE_WASM_KEEP void * sqlite3_wasm_pstack_ptr(void){
|
||||
return PStack.pPos;
|
||||
}
|
||||
/*
|
||||
** Sets the pstack position poitner to p. Results are undefined if the
|
||||
** given value did not come from sqlite3_wasm_pstack_ptr().
|
||||
*/
|
||||
SQLITE_WASM_EXPORT void sqlite3_wasm_pstack_restore(unsigned char * p){
|
||||
SQLITE_WASM_KEEP void sqlite3_wasm_pstack_restore(unsigned char * p){
|
||||
assert(p>=PStack.pBegin && p<=PStack.pEnd && p>=PStack.pPos);
|
||||
assert(0==(p & 0x7));
|
||||
if(p>=PStack.pBegin && p<=PStack.pEnd /*&& p>=PStack.pPos*/){
|
||||
@@ -308,7 +285,7 @@ SQLITE_WASM_EXPORT void sqlite3_wasm_pstack_restore(unsigned char * p){
|
||||
** JS code from having to do so, and most uses of the pstack will
|
||||
** call for doing so).
|
||||
*/
|
||||
SQLITE_WASM_EXPORT void * sqlite3_wasm_pstack_alloc(int n){
|
||||
SQLITE_WASM_KEEP void * sqlite3_wasm_pstack_alloc(int n){
|
||||
if( n<=0 ) return 0;
|
||||
//if( n & 0x7 ) n += 8 - (n & 0x7) /* align to 8-byte boundary */;
|
||||
n = (n + 7) & ~7 /* align to 8-byte boundary */;
|
||||
@@ -321,7 +298,7 @@ SQLITE_WASM_EXPORT void * sqlite3_wasm_pstack_alloc(int n){
|
||||
** Return the number of bytes left which can be
|
||||
** sqlite3_wasm_pstack_alloc()'d.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_remaining(void){
|
||||
SQLITE_WASM_KEEP int sqlite3_wasm_pstack_remaining(void){
|
||||
assert(PStack.pPos >= PStack.pBegin);
|
||||
assert(PStack.pPos <= PStack.pEnd);
|
||||
return (int)(PStack.pPos - PStack.pBegin);
|
||||
@@ -332,7 +309,7 @@ SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_remaining(void){
|
||||
** any space which is currently allocated. This value is a
|
||||
** compile-time constant.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_quota(void){
|
||||
SQLITE_WASM_KEEP int sqlite3_wasm_pstack_quota(void){
|
||||
return (int)(PStack.pEnd - PStack.pBegin);
|
||||
}
|
||||
|
||||
@@ -350,7 +327,7 @@ SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_quota(void){
|
||||
**
|
||||
** Returns err_code.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_db_error(sqlite3*db, int err_code, const char *zMsg){
|
||||
if( db!=0 ){
|
||||
if( 0!=zMsg ){
|
||||
@@ -372,7 +349,7 @@ struct WasmTestStruct {
|
||||
void (*xFunc)(void*);
|
||||
};
|
||||
typedef struct WasmTestStruct WasmTestStruct;
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
void sqlite3_wasm_test_struct(WasmTestStruct * s){
|
||||
if(s){
|
||||
s->v4 *= 2;
|
||||
@@ -400,7 +377,7 @@ void sqlite3_wasm_test_struct(WasmTestStruct * s){
|
||||
** buffer is not large enough for the generated JSON and needs to be
|
||||
** increased. In debug builds that will trigger an assert().
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
const char * sqlite3_wasm_enum_json(void){
|
||||
static char aBuffer[1024 * 20] = {0} /* where the JSON goes */;
|
||||
int n = 0, nChildren = 0, nStruct = 0
|
||||
@@ -495,7 +472,6 @@ const char * sqlite3_wasm_enum_json(void){
|
||||
DefInt(SQLITE_CHANGESETSTART_INVERT);
|
||||
DefInt(SQLITE_CHANGESETAPPLY_NOSAVEPOINT);
|
||||
DefInt(SQLITE_CHANGESETAPPLY_INVERT);
|
||||
DefInt(SQLITE_CHANGESETAPPLY_IGNORENOOP);
|
||||
|
||||
DefInt(SQLITE_CHANGESET_DATA);
|
||||
DefInt(SQLITE_CHANGESET_NOTFOUND);
|
||||
@@ -567,8 +543,6 @@ const char * sqlite3_wasm_enum_json(void){
|
||||
DefInt(SQLITE_DBCONFIG_ENABLE_VIEW);
|
||||
DefInt(SQLITE_DBCONFIG_LEGACY_FILE_FORMAT);
|
||||
DefInt(SQLITE_DBCONFIG_TRUSTED_SCHEMA);
|
||||
DefInt(SQLITE_DBCONFIG_STMT_SCANSTATUS);
|
||||
DefInt(SQLITE_DBCONFIG_REVERSE_SCANORDER);
|
||||
DefInt(SQLITE_DBCONFIG_MAX);
|
||||
} _DefGroup;
|
||||
|
||||
@@ -640,7 +614,6 @@ const char * sqlite3_wasm_enum_json(void){
|
||||
DefInt(SQLITE_FCNTL_CKPT_START);
|
||||
DefInt(SQLITE_FCNTL_EXTERNAL_READER);
|
||||
DefInt(SQLITE_FCNTL_CKSM_FILE);
|
||||
DefInt(SQLITE_FCNTL_RESET_CACHE);
|
||||
} _DefGroup;
|
||||
|
||||
DefGroup(flock) {
|
||||
@@ -930,7 +903,6 @@ const char * sqlite3_wasm_enum_json(void){
|
||||
DefInt(SQLITE_VTAB_CONSTRAINT_SUPPORT);
|
||||
DefInt(SQLITE_VTAB_INNOCUOUS);
|
||||
DefInt(SQLITE_VTAB_DIRECTONLY);
|
||||
DefInt(SQLITE_VTAB_USES_ALL_SCHEMAS);
|
||||
DefInt(SQLITE_ROLLBACK);
|
||||
//DefInt(SQLITE_IGNORE); // Also used by sqlite3_authorizer() callback
|
||||
DefInt(SQLITE_FAIL);
|
||||
@@ -1210,7 +1182,7 @@ const char * sqlite3_wasm_enum_json(void){
|
||||
** method, SQLITE_MISUSE is returned, else the result of the xDelete()
|
||||
** call is returned.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_vfs_unlink(sqlite3_vfs *pVfs, const char *zName){
|
||||
int rc = SQLITE_MISUSE /* ??? */;
|
||||
if( 0==pVfs && 0!=zName ) pVfs = sqlite3_vfs_find(0);
|
||||
@@ -1228,7 +1200,7 @@ int sqlite3_wasm_vfs_unlink(sqlite3_vfs *pVfs, const char *zName){
|
||||
** defaulting to "main" if zDbName is 0. Returns 0 if no db with the
|
||||
** given name is open.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
sqlite3_vfs * sqlite3_wasm_db_vfs(sqlite3 *pDb, const char *zDbName){
|
||||
sqlite3_vfs * pVfs = 0;
|
||||
sqlite3_file_control(pDb, zDbName ? zDbName : "main",
|
||||
@@ -1251,7 +1223,7 @@ sqlite3_vfs * sqlite3_wasm_db_vfs(sqlite3 *pDb, const char *zDbName){
|
||||
** Returns 0 on success, an SQLITE_xxx code on error. Returns
|
||||
** SQLITE_MISUSE if pDb is NULL.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_db_reset(sqlite3 *pDb){
|
||||
int rc = SQLITE_MISUSE;
|
||||
if( pDb ){
|
||||
@@ -1282,7 +1254,7 @@ int sqlite3_wasm_db_reset(sqlite3 *pDb){
|
||||
** sqlite3_wasm_db_serialize() is arguably the better way to achieve
|
||||
** this.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_db_export_chunked( sqlite3* pDb,
|
||||
int (*xCallback)(unsigned const char *zOut, int n) ){
|
||||
sqlite3_int64 nSize = 0;
|
||||
@@ -1333,7 +1305,7 @@ int sqlite3_wasm_db_export_chunked( sqlite3* pDb,
|
||||
** If `*pOut` is not NULL, the caller is responsible for passing it to
|
||||
** sqlite3_free() to free it.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_db_serialize( sqlite3 *pDb, const char *zSchema,
|
||||
unsigned char **pOut,
|
||||
sqlite3_int64 *nOut, unsigned int mFlags ){
|
||||
@@ -1390,7 +1362,7 @@ int sqlite3_wasm_db_serialize( sqlite3 *pDb, const char *zSchema,
|
||||
** portability, so that the API can still work in builds where BigInt
|
||||
** support is disabled or unavailable.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_vfs_create_file( sqlite3_vfs *pVfs,
|
||||
const char *zFilename,
|
||||
const unsigned char * pData,
|
||||
@@ -1474,7 +1446,7 @@ int sqlite3_wasm_vfs_create_file( sqlite3_vfs *pVfs,
|
||||
** NUL-terminated pointer to that string. It is up to the caller to
|
||||
** use sqlite3_wasm_pstack_restore() to free the returned pointer.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
char * sqlite3_wasm_kvvfsMakeKeyOnPstack(const char *zClass,
|
||||
const char *zKeyIn){
|
||||
assert(sqlite3KvvfsMethods.nKeySize>24);
|
||||
@@ -1493,7 +1465,7 @@ char * sqlite3_wasm_kvvfsMakeKeyOnPstack(const char *zClass,
|
||||
** Returns the pointer to the singleton object which holds the kvvfs
|
||||
** I/O methods and associated state.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
sqlite3_kvvfs_methods * sqlite3_wasm_kvvfs_methods(void){
|
||||
return &sqlite3KvvfsMethods;
|
||||
}
|
||||
@@ -1508,7 +1480,7 @@ sqlite3_kvvfs_methods * sqlite3_wasm_kvvfs_methods(void){
|
||||
** sqlite3_vtab_config(), or SQLITE_MISUSE if the 2nd arg is not a
|
||||
** valid value.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_vtab_config(sqlite3 *pDb, int op, int arg){
|
||||
switch(op){
|
||||
case SQLITE_VTAB_DIRECTONLY:
|
||||
@@ -1528,7 +1500,7 @@ int sqlite3_wasm_vtab_config(sqlite3 *pDb, int op, int arg){
|
||||
** Wrapper for the variants of sqlite3_db_config() which take
|
||||
** (int,int*) variadic args.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){
|
||||
switch(op){
|
||||
case SQLITE_DBCONFIG_ENABLE_FKEY:
|
||||
@@ -1547,8 +1519,6 @@ int sqlite3_wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){
|
||||
case SQLITE_DBCONFIG_ENABLE_VIEW:
|
||||
case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:
|
||||
case SQLITE_DBCONFIG_TRUSTED_SCHEMA:
|
||||
case SQLITE_DBCONFIG_STMT_SCANSTATUS:
|
||||
case SQLITE_DBCONFIG_REVERSE_SCANORDER:
|
||||
return sqlite3_db_config(pDb, op, arg1, pArg2);
|
||||
default: return SQLITE_MISUSE;
|
||||
}
|
||||
@@ -1561,7 +1531,7 @@ int sqlite3_wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){
|
||||
** Wrapper for the variants of sqlite3_db_config() which take
|
||||
** (void*,int,int) variadic args.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_db_config_pii(sqlite3 *pDb, int op, void * pArg1, int arg2, int arg3){
|
||||
switch(op){
|
||||
case SQLITE_DBCONFIG_LOOKASIDE:
|
||||
@@ -1577,7 +1547,7 @@ int sqlite3_wasm_db_config_pii(sqlite3 *pDb, int op, void * pArg1, int arg2, int
|
||||
** Wrapper for the variants of sqlite3_db_config() which take
|
||||
** (const char *) variadic args.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_db_config_s(sqlite3 *pDb, int op, const char *zArg){
|
||||
switch(op){
|
||||
case SQLITE_DBCONFIG_MAINDBNAME:
|
||||
@@ -1594,7 +1564,7 @@ int sqlite3_wasm_db_config_s(sqlite3 *pDb, int op, const char *zArg){
|
||||
** Binding for combinations of sqlite3_config() arguments which take
|
||||
** a single integer argument.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_config_i(int op, int arg){
|
||||
return sqlite3_config(op, arg);
|
||||
}
|
||||
@@ -1606,7 +1576,7 @@ int sqlite3_wasm_config_i(int op, int arg){
|
||||
** Binding for combinations of sqlite3_config() arguments which take
|
||||
** two int arguments.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_config_ii(int op, int arg1, int arg2){
|
||||
return sqlite3_config(op, arg1, arg2);
|
||||
}
|
||||
@@ -1618,7 +1588,7 @@ int sqlite3_wasm_config_ii(int op, int arg1, int arg2){
|
||||
** Binding for combinations of sqlite3_config() arguments which take
|
||||
** a single i64 argument.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_config_j(int op, sqlite3_int64 arg){
|
||||
return sqlite3_config(op, arg);
|
||||
}
|
||||
@@ -1647,7 +1617,7 @@ int sqlite3_wasm_config_j(int op, sqlite3_int64 arg){
|
||||
** Safari-specific quirk covered at
|
||||
** https://sqlite.org/forum/info/e5b20e1feb37a19a.
|
||||
**/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
void * sqlite3_wasm_ptr_to_sqlite3_free(void){
|
||||
return (void*)sqlite3_free;
|
||||
}
|
||||
@@ -1677,7 +1647,7 @@ void * sqlite3_wasm_ptr_to_sqlite3_free(void){
|
||||
** the virtual FS fails. In builds compiled without SQLITE_ENABLE_WASMFS
|
||||
** defined, SQLITE_NOTFOUND is returned without side effects.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_init_wasmfs(const char *zMountPoint){
|
||||
static backend_t pOpfs = 0;
|
||||
if( !zMountPoint || !*zMountPoint ) zMountPoint = "/opfs";
|
||||
@@ -1697,7 +1667,7 @@ int sqlite3_wasm_init_wasmfs(const char *zMountPoint){
|
||||
return pOpfs ? 0 : SQLITE_NOMEM;
|
||||
}
|
||||
#else
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_init_wasmfs(const char *zUnused){
|
||||
//emscripten_console_warn("WASMFS OPFS is not compiled in.");
|
||||
if(zUnused){/*unused*/}
|
||||
@@ -1707,51 +1677,51 @@ int sqlite3_wasm_init_wasmfs(const char *zUnused){
|
||||
|
||||
#if SQLITE_WASM_TESTS
|
||||
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_test_intptr(int * p){
|
||||
return *p = *p * 2;
|
||||
}
|
||||
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
void * sqlite3_wasm_test_voidptr(void * p){
|
||||
return p;
|
||||
}
|
||||
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int64_t sqlite3_wasm_test_int64_max(void){
|
||||
return (int64_t)0x7fffffffffffffff;
|
||||
}
|
||||
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int64_t sqlite3_wasm_test_int64_min(void){
|
||||
return ~sqlite3_wasm_test_int64_max();
|
||||
}
|
||||
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int64_t sqlite3_wasm_test_int64_times2(int64_t x){
|
||||
return x * 2;
|
||||
}
|
||||
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
void sqlite3_wasm_test_int64_minmax(int64_t * min, int64_t *max){
|
||||
*max = sqlite3_wasm_test_int64_max();
|
||||
*min = sqlite3_wasm_test_int64_min();
|
||||
/*printf("minmax: min=%lld, max=%lld\n", *min, *max);*/
|
||||
}
|
||||
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
int64_t sqlite3_wasm_test_int64ptr(int64_t * p){
|
||||
/*printf("sqlite3_wasm_test_int64ptr( @%lld = 0x%llx )\n", (int64_t)p, *p);*/
|
||||
return *p = *p * 2;
|
||||
}
|
||||
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
void sqlite3_wasm_test_stack_overflow(int recurse){
|
||||
if(recurse) sqlite3_wasm_test_stack_overflow(recurse);
|
||||
}
|
||||
|
||||
/* For testing the 'string:dealloc' whwasmutil.xWrap() conversion. */
|
||||
SQLITE_WASM_EXPORT
|
||||
SQLITE_WASM_KEEP
|
||||
char * sqlite3_wasm_test_str_hello(int fail){
|
||||
char * s = fail ? 0 : (char *)sqlite3_malloc(6);
|
||||
if(s){
|
||||
@@ -1762,4 +1732,4 @@ char * sqlite3_wasm_test_str_hello(int fail){
|
||||
}
|
||||
#endif /* SQLITE_WASM_TESTS */
|
||||
|
||||
#undef SQLITE_WASM_EXPORT
|
||||
#undef SQLITE_WASM_KEEP
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
by all client code except that which tests this API. The `row`
|
||||
property contains the row result in the form implied by the
|
||||
`rowMode` option (defaulting to `'array'`). The `rowNumber` is a
|
||||
1-based integer value incremented by 1 on each call into the
|
||||
1-based integer value incremented by 1 on each call into th
|
||||
callback.
|
||||
|
||||
At the end of the result set, the same event is fired with
|
||||
@@ -122,17 +122,8 @@
|
||||
the end of the result set has been reached. Note that the rows
|
||||
arrive via worker-posted messages, with all the implications
|
||||
of that.
|
||||
|
||||
Notable shortcomings:
|
||||
|
||||
- This API was not designed with ES6 modules in mind. Neither Firefox
|
||||
nor Safari support, as of March 2023, the {type:"module"} flag to the
|
||||
Worker constructor, so that particular usage is not something we're going
|
||||
to target for the time being:
|
||||
|
||||
https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker
|
||||
*/
|
||||
globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
|
||||
self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
|
||||
// Inspired by: https://stackoverflow.com/a/52439530
|
||||
if(1===arguments.length && 'function'===typeof arguments[0]){
|
||||
const f = config;
|
||||
@@ -169,7 +160,7 @@ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfi
|
||||
if(msgHandler && msgHandler.onrow){
|
||||
msgHandler.onrow(ev);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(config.onunhandled) config.onunhandled(arguments[0]);
|
||||
else err("sqlite3Worker1Promiser() unhandled worker message:",ev);
|
||||
return;
|
||||
@@ -196,9 +187,10 @@ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfi
|
||||
if(1===arguments.length){
|
||||
msg = arguments[0];
|
||||
}else if(2===arguments.length){
|
||||
msg = Object.create(null);
|
||||
msg.type = arguments[0];
|
||||
msg.args = arguments[1];
|
||||
msg = {
|
||||
type: arguments[0],
|
||||
args: arguments[1]
|
||||
};
|
||||
}else{
|
||||
toss("Invalid arugments for sqlite3Worker1Promiser()-created factory.");
|
||||
}
|
||||
@@ -244,13 +236,10 @@ globalThis.sqlite3Worker1Promiser = function callee(config = callee.defaultConfi
|
||||
return p;
|
||||
};
|
||||
}/*sqlite3Worker1Promiser()*/;
|
||||
globalThis.sqlite3Worker1Promiser.defaultConfig = {
|
||||
self.sqlite3Worker1Promiser.defaultConfig = {
|
||||
worker: function(){
|
||||
//#if target=es6-bundler-friendly
|
||||
return new Worker("sqlite3-worker1-bundler-friendly.mjs",{
|
||||
type: 'module' /* Noting that neither Firefox nor Safari suppor this,
|
||||
as of this writing. */
|
||||
});
|
||||
return new Worker("sqlite3-worker1.js");
|
||||
//#else
|
||||
let theJs = "sqlite3-worker1.js";
|
||||
if(this.currentScript){
|
||||
@@ -258,17 +247,17 @@ globalThis.sqlite3Worker1Promiser.defaultConfig = {
|
||||
src.pop();
|
||||
theJs = src.join('/')+'/' + theJs;
|
||||
//sqlite3.config.warn("promiser currentScript, theJs =",this.currentScript,theJs);
|
||||
}else if(globalThis.location){
|
||||
//sqlite3.config.warn("promiser globalThis.location =",globalThis.location);
|
||||
const urlParams = new URL(globalThis.location.href).searchParams;
|
||||
}else{
|
||||
//sqlite3.config.warn("promiser self.location =",self.location);
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
if(urlParams.has('sqlite3.dir')){
|
||||
theJs = urlParams.get('sqlite3.dir') + '/' + theJs;
|
||||
}
|
||||
}
|
||||
return new Worker(theJs + globalThis.location.search);
|
||||
return new Worker(theJs + self.location.search);
|
||||
//#endif
|
||||
}.bind({
|
||||
currentScript: globalThis?.document?.currentScript
|
||||
currentScript: self?.document?.currentScript
|
||||
}),
|
||||
onerror: (...args)=>console.error('worker1 promiser error',...args)
|
||||
};
|
||||
|
||||
@@ -31,20 +31,20 @@
|
||||
- `sqlite3.dir`, if set, treats the given directory name as the
|
||||
directory from which `sqlite3.js` will be loaded.
|
||||
*/
|
||||
//#if target=es6-bundler-friendly
|
||||
import {default as sqlite3InitModule} from './sqlite3-bundler-friendly.mjs';
|
||||
//#else
|
||||
"use strict";
|
||||
{
|
||||
const urlParams = globalThis.location
|
||||
? new URL(self.location.href).searchParams
|
||||
: new URLSearchParams();
|
||||
(()=>{
|
||||
//#if target=es6-bundler-friendly
|
||||
importScripts('sqlite3.js');
|
||||
//#else
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
let theJs = 'sqlite3.js';
|
||||
if(urlParams.has('sqlite3.dir')){
|
||||
theJs = urlParams.get('sqlite3.dir') + '/' + theJs;
|
||||
}
|
||||
//console.warn("worker1 theJs =",theJs);
|
||||
importScripts(theJs);
|
||||
}
|
||||
//#endif
|
||||
sqlite3InitModule().then(sqlite3 => sqlite3.initWorker1API());
|
||||
sqlite3InitModule().then((sqlite3)=>{
|
||||
sqlite3.initWorker1API();
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -156,6 +156,7 @@
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
This is a module object for use with the emscripten-installed
|
||||
sqlite3InitModule() factory function.
|
||||
|
||||
@@ -40,41 +40,8 @@ span.labeled-input {
|
||||
.tests-pass { background-color: green; color: white }
|
||||
.tests-fail { background-color: red; color: yellow }
|
||||
.faded { opacity: 0.5; }
|
||||
.group-start {
|
||||
color: blue;
|
||||
background-color: skyblue;
|
||||
font-weight: bold;
|
||||
border-top: 1px dotted blue;
|
||||
padding: 0.5em;
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
.group-end {
|
||||
padding: 0.5em;
|
||||
margin-bottom: 0.25em;
|
||||
/*border-bottom: 1px dotted blue;*/
|
||||
}
|
||||
.group-end.green {
|
||||
background: lightgreen;
|
||||
border-bottom: 1px dotted green;
|
||||
}
|
||||
.one-test-line, .skipping-group {
|
||||
margin-left: 3em;
|
||||
}
|
||||
.skipping-test, .skipping-group {
|
||||
padding: 0.25em 0.5em;
|
||||
background-color: #ffff73;
|
||||
}
|
||||
.skipping-test {
|
||||
margin-left: 6em;
|
||||
}
|
||||
.one-test-summary {
|
||||
margin-left: 6em;
|
||||
}
|
||||
.full-test-summary {
|
||||
padding-bottom: 0.5em;
|
||||
padding-top: 0.5em;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
.group-start { color: blue; }
|
||||
.group-end { color: blue; }
|
||||
.input-wrapper {
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user