Merge latest trunk changes with this branch.
FossilOrigin-Name: 757e3f585959f4f113fee48fe3d504f037604c53a95c8d47ce5c2bccfb2af8ff
This commit is contained in:
+1
-1
@@ -3235,7 +3235,7 @@ static int rtreeUpdate(
|
||||
rtreeReference(pRtree);
|
||||
assert(nData>=1);
|
||||
|
||||
cell.iRowid = 0; /* Used only to suppress a compiler warning */
|
||||
memset(&cell, 0, sizeof(cell));
|
||||
|
||||
/* Constraint handling. A write operation on an r-tree table may return
|
||||
** SQLITE_CONSTRAINT for two reasons:
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
FS
|
||||
addFunction
|
||||
allocateUTF8OnStack
|
||||
ccall
|
||||
cwrap
|
||||
getValue
|
||||
intArrayFromString
|
||||
lengthBytesUTF8
|
||||
removeFunction
|
||||
setValue
|
||||
stackAlloc
|
||||
stackRestore
|
||||
stackSave
|
||||
stringToUTF8Array
|
||||
wasmMemory
|
||||
+186
-78
@@ -1,11 +1,32 @@
|
||||
########################################################################
|
||||
#######################################################################
|
||||
# This GNU makefile drives the build of the sqlite3 WASM
|
||||
# components. It is not part of the canonical build process.
|
||||
#
|
||||
# This build assumes a Linux platform and is not intended for
|
||||
# general-purpose client-level use, except for creating builds with
|
||||
# custom configurations. It is primarily intended for the sqlite
|
||||
# project's own development of the JS/WASM components.
|
||||
#
|
||||
# Primary targets:
|
||||
#
|
||||
# default, all = build in dev mode
|
||||
#
|
||||
# o0, o1, o2, o3, os, oz = full clean/rebuild with the -Ox level indicated
|
||||
# by the target name. Rebuild is necessary for all components to get
|
||||
# the desired optimization level.
|
||||
#
|
||||
# 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? target names.
|
||||
#
|
||||
# clean = clean up
|
||||
########################################################################
|
||||
SHELL := $(shell which bash 2>/dev/null)
|
||||
MAKEFILE := $(lastword $(MAKEFILE_LIST))
|
||||
all:
|
||||
release: all
|
||||
CLEAN_FILES :=
|
||||
DISTCLEAN_FILES := ./--dummy--
|
||||
default: all
|
||||
release: oz
|
||||
|
||||
# Emscripten SDK home dir and related binaries...
|
||||
EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/src/emsdk $(HOME)/emsdk))
|
||||
@@ -40,15 +61,53 @@ else
|
||||
endif
|
||||
|
||||
dir.top := ../..
|
||||
# Reminder: some Emscripten flags require absolute paths
|
||||
dir.wasm := $(patsubst %/,%,$(dir $(abspath $(MAKEFILE))))
|
||||
# Reminder: some Emscripten flags require absolute paths but we want
|
||||
# relative paths for most stuff simply to reduce noise. The
|
||||
# $(abspath...) GNU make function can transform relative paths to
|
||||
# absolute.
|
||||
dir.wasm := $(patsubst %/,%,$(dir $(MAKEFILE)))
|
||||
dir.api := api
|
||||
dir.jacc := jaccwabyt
|
||||
dir.common := common
|
||||
dir.fiddle := fiddle
|
||||
CLEAN_FILES := *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~
|
||||
dir.tool := $(dir.top)/tool
|
||||
########################################################################
|
||||
# MAINTENANCE REMINDER: the output .js and .wasm files of emcc must be
|
||||
# in _this_ dir, rather than a subdir, or else parts of the generated
|
||||
# code get confused and cannot load property. Specifically, when X.js
|
||||
# loads X.wasm, whether or not X.js uses the correct path for X.wasm
|
||||
# depends on how it's loaded: an HTML script tag will resolve it
|
||||
# intuitively, whereas a Worker's call to importScripts() will not.
|
||||
# That's a fundamental incompatibility with how URL resolution in
|
||||
# JS happens between those two contexts. See:
|
||||
#
|
||||
# https://zzz.buzz/2017/03/14/relative-uris-in-web-development/
|
||||
#
|
||||
# We unfortunately have no way, from Worker-initiated code, to
|
||||
# automatically resolve the path from X.js to X.wasm.
|
||||
#
|
||||
# In case we ever find a solution to that which does not require
|
||||
# duplicating the X.js files only to swap out the path to X.wasm for
|
||||
# the loading-from-worker case...
|
||||
#
|
||||
# dir.dout = output dir for deliverables.
|
||||
dir.dout := $(dir.wasm)/jswasm
|
||||
# dir.tmp = output dir for intermediary build files, as opposed to
|
||||
# end-user deliverables.
|
||||
dir.tmp := $(dir.wasm)/bld
|
||||
#CLEAN_FILES += $(wildcard $(dir.dout)/*) $(wildcard $(dir.tmp)/*)
|
||||
ifeq (,$(wildcard $(dir.dout)))
|
||||
dir._tmp := $(shell mkdir -p $(dir.dout))
|
||||
endif
|
||||
ifeq (,$(wildcard $(dir.tmp)))
|
||||
dir._tmp := $(shell mkdir -p $(dir.tmp))
|
||||
endif
|
||||
|
||||
cflags.common := -I. -I.. -I$(dir.top)
|
||||
CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~
|
||||
emcc_enable_bigint ?= 1
|
||||
sqlite3.c := $(dir.top)/sqlite3.c
|
||||
sqlite3.h := $(dir.top)/sqlite3.h
|
||||
SQLITE_OPT = \
|
||||
-DSQLITE_ENABLE_FTS4 \
|
||||
-DSQLITE_ENABLE_RTREE \
|
||||
@@ -109,11 +168,14 @@ emcc_opt_full := $(emcc_opt) -g3
|
||||
########################################################################
|
||||
|
||||
|
||||
$(sqlite3.c):
|
||||
$(sqlite3.c) $(sqlite3.h):
|
||||
$(MAKE) -C $(dir.top) sqlite3.c
|
||||
|
||||
.PHONY: clean distclean
|
||||
clean:
|
||||
-rm -f $(CLEAN_FILES)
|
||||
distclean: clean
|
||||
-rm -f $(DISTCLEAN_FILES)
|
||||
|
||||
ifeq (release,$(filter release,$(MAKECMDGOALS)))
|
||||
ifeq (,$(wasm-strip))
|
||||
@@ -124,23 +186,54 @@ else
|
||||
$(info Development build. Use '$(MAKE) release' for a smaller release build.)
|
||||
endif
|
||||
|
||||
EXPORTED_FUNCTIONS.api.in := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api
|
||||
bin.version-info := $(dir.wasm)/bin.version-info
|
||||
# ^^^^ NOT 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.c $(sqlite3.h) $(MAKEFILE)
|
||||
$(CC) -O0 -I$(dir.top) -o $@ $<
|
||||
DISTCLEAN_FILES += $(bin.version-info)
|
||||
|
||||
EXPORTED_FUNCTIONS.api: $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE)
|
||||
bin.stripccomments := $(dir.tool)/stripccomments
|
||||
$(bin.stripccomments): $(bin.stripccomments).c $(MAKEFILE)
|
||||
$(CC) -o $@ $<
|
||||
DISTCLEAN_FILES += $(bin.stripccomments)
|
||||
|
||||
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) $(MAKEFILE)
|
||||
cat $(EXPORTED_FUNCTIONS.api.in) > $@
|
||||
CLEAN_FILES += EXPORTED_FUNCTIONS.api
|
||||
|
||||
sqlite3-api.jses := $(dir.api)/sqlite3-api-prologue.js
|
||||
sqlite3-license-version.js := $(dir.tmp)/sqlite3-license-version.js
|
||||
sqlite3-license-version-header.js := $(dir.api)/sqlite3-license-version-header.js
|
||||
sqlite3-api-build-version.js := $(dir.tmp)/sqlite3-api-build-version.js
|
||||
# sqlite3-api.jses = the list of JS files which make up $(sqlite3-api.js), in
|
||||
# the order they need to be assembled.
|
||||
sqlite3-api.jses := $(sqlite3-license-version.js)
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js
|
||||
sqlite3-api.jses += $(dir.common)/whwasmutil.js
|
||||
sqlite3-api.jses += $(dir.jacc)/jaccwabyt.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-glue.js
|
||||
sqlite3-api.jses += $(sqlite3-api-build-version.js)
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-opfs.js
|
||||
sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js
|
||||
|
||||
sqlite3-api.js := sqlite3-api.js
|
||||
CLEAN_FILES += $(sqlite3-api.js)
|
||||
# "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
|
||||
sqlite3-worker1.js := $(dir.api)/sqlite3-worker1.js
|
||||
sqlite3-worker1-promiser.js := $(dir.api)/sqlite3-worker1-promiser.js
|
||||
define CP_XAPI
|
||||
sqlite3-api.ext.jses += $$(dir.dout)/$$(notdir $(1))
|
||||
$$(dir.dout)/$$(notdir $(1)): $(1) $$(MAKEFILE)
|
||||
cp $$< $$@
|
||||
endef
|
||||
$(foreach X,$(SOAP.js) $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js),\
|
||||
$(eval $(call CP_XAPI,$(X))))
|
||||
all: $(sqlite3-api.ext.jses)
|
||||
|
||||
sqlite3-api.js := $(dir.tmp)/sqlite3-api.js
|
||||
$(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE)
|
||||
@echo "Making $@..."
|
||||
@for i in $(sqlite3-api.jses); do \
|
||||
@@ -149,12 +242,21 @@ $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE)
|
||||
echo "/* END FILE: $$i */"; \
|
||||
done > $@
|
||||
|
||||
$(sqlite3-api-build-version.js): $(bin.version-info) $(MAKEFILE)
|
||||
@echo "Making $@..."
|
||||
@{ \
|
||||
echo 'self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \
|
||||
echo -n ' sqlite3.version = '; \
|
||||
$(bin.version-info) --json; \
|
||||
echo ';'; \
|
||||
echo '});'; \
|
||||
} > $@
|
||||
|
||||
########################################################################
|
||||
# --post-js and --pre-js are emcc flags we use to append/prepend JS to
|
||||
# the generated emscripten module file.
|
||||
pre-js.js := $(dir.api)/pre-js.js
|
||||
post-js.js := post-js.js
|
||||
CLEAN_FILES += $(post-js.js)
|
||||
post-js.js := $(dir.tmp)/post-js.js
|
||||
post-jses := \
|
||||
$(dir.api)/post-js-header.js \
|
||||
$(sqlite3-api.js) \
|
||||
@@ -171,20 +273,30 @@ extern-pre-js.js := $(dir.api)/extern-pre-js.js
|
||||
pre-post-common.flags := \
|
||||
--post-js=$(post-js.js) \
|
||||
--extern-post-js=$(extern-post-js.js) \
|
||||
--extern-pre-js=$(extern-pre-js.js)
|
||||
--extern-pre-js=$(sqlite3-license-version.js)
|
||||
pre-post-jses.deps := $(post-js.js) \
|
||||
$(extern-post-js.js) $(extern-pre-js.js)
|
||||
$(extern-post-js.js) $(extern-pre-js.js) $(sqlite3-license-version.js)
|
||||
$(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) $(MAKEFILE)
|
||||
@echo "Making $@..."; { \
|
||||
cat $(sqlite3-license-version-header.js); \
|
||||
echo '/*'; \
|
||||
echo '** This code was built from sqlite3 version...'; \
|
||||
echo "** "; \
|
||||
awk -e '/define SQLITE_VERSION/{$$1=""; print "**" $$0}' \
|
||||
-e '/define SQLITE_SOURCE_ID/{$$1=""; print "**" $$0}' $(sqlite3.h); \
|
||||
echo '*/'; \
|
||||
} > $@
|
||||
|
||||
########################################################################
|
||||
# call-make-pre-js creates rules for pre-js-$(1).js. $1 = the base
|
||||
# name of the JS file on whose behalf this pre-js is for.
|
||||
define call-make-pre-js
|
||||
pre-post-$(1).flags ?=
|
||||
pre-js-$(1).js: $$(pre-js.js) $$(MAKEFILE)
|
||||
$$(dir.tmp)/pre-js-$(1).js: $$(pre-js.js) $$(MAKEFILE)
|
||||
cp $$(pre-js.js) $$@
|
||||
echo "Module[xInstantiateWasm].uri = '$(1).wasm';" >> $$@
|
||||
CLEAN_FILES += pre-js-$(1).js
|
||||
pre-post-$(1).deps := $$(pre-post-jses.deps) pre-js-$(1).js
|
||||
pre-post-$(1).flags += --pre-js=pre-js-$(1).js
|
||||
pre-post-$(1).deps := $$(pre-post-jses.deps) $$(dir.tmp)/pre-js-$(1).js
|
||||
pre-post-$(1).flags += --pre-js=$$(dir.tmp)/pre-js-$(1).js
|
||||
endef
|
||||
#$(error $(call call-make-pre-js,sqlite3-wasmfs))
|
||||
# /post-js and pre-js
|
||||
@@ -192,9 +304,9 @@ endef
|
||||
|
||||
########################################################################
|
||||
# emcc flags for .c/.o/.wasm/.js.
|
||||
emcc.flags =
|
||||
emcc.flags :=
|
||||
#emcc.flags += -v # _very_ loud but also informative about what it's doing
|
||||
# -g is needed to keep -O2 and higher from creating broken JS via
|
||||
# -g3 is needed to keep -O2 and higher from creating broken JS via
|
||||
# minification.
|
||||
|
||||
########################################################################
|
||||
@@ -213,12 +325,11 @@ emcc.jsflags += -sMODULARIZE
|
||||
emcc.jsflags += -sSTRICT_JS
|
||||
emcc.jsflags += -sDYNAMIC_EXECUTION=0
|
||||
emcc.jsflags += -sNO_POLYFILL
|
||||
emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api
|
||||
emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.api)
|
||||
emcc.exportedRuntimeMethods := \
|
||||
-sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack
|
||||
-sEXPORTED_RUNTIME_METHODS=FS,wasmMemory
|
||||
# FS ==> stdio/POSIX I/O proxies
|
||||
# wasmMemory ==> required by our code for use with -sIMPORTED_MEMORY
|
||||
# allocateUTF8OnStack => for kvvfs internals
|
||||
emcc.jsflags += $(emcc.exportedRuntimeMethods)
|
||||
emcc.jsflags += -sUSE_CLOSURE_COMPILER=0
|
||||
emcc.jsflags += -sIMPORTED_MEMORY
|
||||
@@ -234,7 +345,9 @@ emcc.jsflags += $(emcc.environment)
|
||||
#emcc.jsflags += -sTOTAL_STACK=4194304
|
||||
|
||||
sqlite3.js.init-func := sqlite3InitModule
|
||||
# ^^^^ $(sqlite3.js.init-func) symbol name is hard-coded in $(extern-post-js.js)
|
||||
# ^^^^ $(sqlite3.js.init-func) symbol name is hard-coded in
|
||||
# $(extern-post-js.js) as well as in numerous docs. If changed, it
|
||||
# needs to be globally modified in *.js and all related documentation.
|
||||
|
||||
emcc.jsflags += -sEXPORT_NAME=$(sqlite3.js.init-func)
|
||||
emcc.jsflags += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from overlapping w/ heap addr.
|
||||
@@ -243,6 +356,7 @@ emcc.jsflags += -sGLOBAL_BASE=4096 # HYPOTHETICALLY keep func table indexes from
|
||||
#emcc.jsflags += -sFILESYSTEM=0 # only for experimentation. sqlite3 needs the FS API
|
||||
#emcc.jsflags += -sABORTING_MALLOC
|
||||
emcc.jsflags += -sALLOW_TABLE_GROWTH
|
||||
# -sALLOW_TABLE_GROWTH is required for installing new SQL UDFs
|
||||
emcc.jsflags += -Wno-limited-postlink-optimizations
|
||||
# ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag.
|
||||
#emcc.jsflags += -sSTANDALONE_WASM # causes OOM errors, not sure why
|
||||
@@ -250,7 +364,7 @@ emcc.jsflags += -Wno-limited-postlink-optimizations
|
||||
emcc.jsflags += -sERROR_ON_UNDEFINED_SYMBOLS=0
|
||||
emcc.jsflags += -sLLD_REPORT_UNDEFINED
|
||||
#emcc.jsflags += --allow-undefined
|
||||
emcc.jsflags += --import-undefined
|
||||
#emcc.jsflags += --import-undefined
|
||||
#emcc.jsflags += --unresolved-symbols=import-dynamic --experimental-pic
|
||||
#emcc.jsflags += --experimental-pic --unresolved-symbols=ingore-all --import-undefined
|
||||
#emcc.jsflags += --unresolved-symbols=ignore-all
|
||||
@@ -278,40 +392,27 @@ emcc.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint)
|
||||
# debugging info, _huge_.
|
||||
########################################################################
|
||||
|
||||
########################################################################
|
||||
# Maintenance reminder: the output .js and .wasm files of emcc must be
|
||||
# in _this_ dir, rather than a subdir, or else parts of the generated
|
||||
# code get confused and cannot load property (namely, the
|
||||
# sqlite3.worker.js generated in conjunction with -sWASMFS).
|
||||
sqlite3.js := sqlite3.js
|
||||
sqlite3.wasm := sqlite3.wasm
|
||||
sqlite3-wasm.o := $(dir.api)/sqlite3-wasm.o
|
||||
$(sqlite3-wasm.o): emcc.cflags += $(SQLITE_OPT)
|
||||
$(sqlite3-wasm.o): $(dir.top)/sqlite3.c
|
||||
sqlite3.js := $(dir.dout)/sqlite3.js
|
||||
sqlite3.wasm := $(dir.dout)/sqlite3.wasm
|
||||
sqlite3-wasm.c := $(dir.api)/sqlite3-wasm.c
|
||||
########################################################################
|
||||
# call-wasm-c-compile sets up build rules
|
||||
# for $1.o. $1 must be the name of a C file (with extension).
|
||||
define call-wasm-c-compile
|
||||
$(1).o := $$(subst .c,.o,$(1))
|
||||
sqlite3.wasm.obj += $$($(1).o)
|
||||
$$($(1).o): $$(MAKEFILE) $(1)
|
||||
$$(emcc.bin) $$(emcc_opt_full) $$(emcc.flags) $$(emcc.cflags) -c $(1) -o $$@
|
||||
CLEAN_FILES += $$($(1).o)
|
||||
endef
|
||||
$(foreach c,$(sqlite3-wasm.c),$(eval $(call call-wasm-c-compile,$(c))))
|
||||
# sqlite3-wasm.o vs sqlite3-wasm.c: building against the latter
|
||||
# (predictably) results in a slightly faster binary, but we're close
|
||||
# enough to the target speed requirements that the 500ms makes a
|
||||
# difference. Thus we build all binaries against sqlite3-wasm.c
|
||||
# instead of building a shared copy of sqlite3-wasm.o.
|
||||
$(eval $(call call-make-pre-js,sqlite3))
|
||||
$(sqlite3.js):
|
||||
$(sqlite3.js): $(MAKEFILE) $(sqlite3.wasm.obj) \
|
||||
EXPORTED_FUNCTIONS.api \
|
||||
$(EXPORTED_FUNCTIONS.api) \
|
||||
$(pre-post-sqlite3.deps)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \
|
||||
$(emcc.jsflags) $(pre-post-common.flags) $(pre-post-sqlite3.flags) \
|
||||
$(sqlite3.wasm.obj)
|
||||
$(cflags.common) $(SQLITE_OPT) $(sqlite3-wasm.c)
|
||||
chmod -x $(sqlite3.wasm)
|
||||
$(maybe-wasm-strip) $(sqlite3.wasm)
|
||||
@ls -la $@ $(sqlite3.wasm)
|
||||
|
||||
$(sqlite3.wasm): $(sqlite3.js)
|
||||
CLEAN_FILES += $(sqlite3.js) $(sqlite3.wasm)
|
||||
all: $(sqlite3.js)
|
||||
wasm: $(sqlite3.js)
|
||||
@@ -355,7 +456,8 @@ speedtest1-common.eflags += -sINITIAL_MEMORY=128450560
|
||||
speedtest1-common.eflags += -sSTRICT_JS
|
||||
speedtest1-common.eflags += -sMODULARIZE
|
||||
speedtest1-common.eflags += -Wno-limited-postlink-optimizations
|
||||
speedtest1-common.eflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.speedtest1
|
||||
EXPORTED_FUNCTIONS.speedtest1 := $(abspath $(dir.tmp)/EXPORTED_FUNCTIONS.speedtest1)
|
||||
speedtest1-common.eflags += -sEXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS.speedtest1)
|
||||
speedtest1-common.eflags += $(emcc.exportedRuntimeMethods)
|
||||
speedtest1-common.eflags += -sALLOW_TABLE_GROWTH
|
||||
speedtest1-common.eflags += -sDYNAMIC_EXECUTION=0
|
||||
@@ -382,31 +484,24 @@ 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
|
||||
{ echo _wasm_main; cat EXPORTED_FUNCTIONS.api; } > $@
|
||||
CLEAN_FILES += EXPORTED_FUNCTIONS.speedtest1
|
||||
speedtest1.js := speedtest1.js
|
||||
$(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api)
|
||||
@echo "Making $@ ..."
|
||||
@{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api); } > $@
|
||||
speedtest1.js := $(dir.dout)/speedtest1.js
|
||||
speedtest1.wasm := $(subst .js,.wasm,$(speedtest1.js))
|
||||
speedtest1.cflags := \
|
||||
-I. -I.. -I$(dir.top) \
|
||||
-DSQLITE_SPEEDTEST1_WASM
|
||||
speedtest1.cs := $(speedtest1.c) $(sqlite3-wasm.c)
|
||||
$(speedtest1.js): emcc.cflags+=
|
||||
# speedtest1 notes re. sqlite3-wasm.o vs sqlite3-wasm.c: building against
|
||||
# the latter (predictably) results in a slightly faster binary, but we're
|
||||
# close enough to the target speed requirements that the 500ms makes a
|
||||
# difference.
|
||||
speedtest1.cflags := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM
|
||||
speedtest1.cses := $(speedtest1.c) $(sqlite3-wasm.c)
|
||||
$(eval $(call call-make-pre-js,speedtest1))
|
||||
$(speedtest1.js): $(MAKEFILE) $(speedtest1.cs) \
|
||||
$(speedtest1.js): $(MAKEFILE) $(speedtest1.cses) \
|
||||
$(pre-post-speedtest1.deps) \
|
||||
EXPORTED_FUNCTIONS.speedtest1
|
||||
$(EXPORTED_FUNCTIONS.speedtest1)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) \
|
||||
$(speedtest1.eflags) $(speedtest1-common.eflags) $(speedtest1.cflags) \
|
||||
$(pre-post-speedtest1.flags) \
|
||||
$(SQLITE_OPT) \
|
||||
$(speedtest1.exit-runtime0) \
|
||||
-o $@ $(speedtest1.cs) -lm
|
||||
-o $@ $(speedtest1.cses) -lm
|
||||
$(maybe-wasm-strip) $(speedtest1.wasm)
|
||||
ls -la $@ $(speedtest1.wasm)
|
||||
|
||||
@@ -446,16 +541,12 @@ push-fiddle: $(fiddle_files)
|
||||
# painful.
|
||||
|
||||
.PHONY: o0 o1 o2 o3 os oz
|
||||
o-xtra := -g3
|
||||
# ^^^ -g3 is important to keep higher -O levels from mangling (via
|
||||
# minification), or outright removing, otherwise working code.
|
||||
|
||||
o-xtra += -flto
|
||||
o-xtra := -flto
|
||||
# ^^^^ -flto can have a considerably performance boost at -O0 but
|
||||
# doubles the build time and seems to have negligible effect on
|
||||
# higher optimization levels.
|
||||
o0: clean
|
||||
$(MAKE) -e "emcc_opt=-O0 $(o-xtra)"
|
||||
$(MAKE) -e "emcc_opt=-O0"
|
||||
o1: clean
|
||||
$(MAKE) -e "emcc_opt=-O1 $(o-xtra)"
|
||||
o2: clean
|
||||
@@ -473,6 +564,13 @@ oz: clean
|
||||
|
||||
include fiddle.make
|
||||
|
||||
ifneq (,$(filter wasmfs,$(MAKECMDGOALS)))
|
||||
# wasmfs build disabled 2022-10-19 per /chat
|
||||
# discussion. OPFS-over-wasmfs was initially a stopgap measure and a
|
||||
# convenient point of comparison for the OPFS sqlite3_vfs's
|
||||
# performance, but it currently doubles our deliverables for very
|
||||
# little, if any, benefit.
|
||||
#
|
||||
########################################################################
|
||||
# Some platforms do not support the WASMFS build. Raspberry Pi OS is one
|
||||
# of them. As such platforms are discovered, add their (uname -m) name
|
||||
@@ -481,14 +579,25 @@ PLATFORMS_WITH_NO_WASMFS := aarch64 # add any others here
|
||||
THIS_ARCH := $(shell /usr/bin/uname -m)
|
||||
ifneq (,$(filter $(THIS_ARCH),$(PLATFORMS_WITH_NO_WASMFS)))
|
||||
$(info This platform does not support the WASMFS build.)
|
||||
HAVE_WASMFS := 0
|
||||
else
|
||||
HAVE_WASMFS := 1
|
||||
include wasmfs.make
|
||||
endif
|
||||
endif
|
||||
# /wasmfs
|
||||
########################################################################
|
||||
|
||||
########################################################################
|
||||
# Create deliverables:
|
||||
ifneq (,$(filter dist,$(MAKECMDGOALS)))
|
||||
include dist.make
|
||||
endif
|
||||
|
||||
########################################################################
|
||||
# Push files to public wasm-testing.sqlite.org server
|
||||
wasm-testing.include = *.wasm *.js *.html \
|
||||
batch-runner.list sql common fiddle jaccwabyt
|
||||
wasm-testing.include = $(dir.dout) *.js *.html \
|
||||
batch-runner.list $(dir.sql) $(dir.common) $(dir.fiddle) $(dir.jacc)
|
||||
wasm-testing.exclude = sql/speedtest1.sql
|
||||
wasm-testing.dir = /jail/sites/wasm-testing
|
||||
wasm-testing.dest ?= wasm-testing:$(wasm-testing.dir)
|
||||
@@ -499,4 +608,3 @@ push:
|
||||
$(wasm-testing.include) $(wasm-testing.dest)
|
||||
ssh wasm-testing 'cd $(wasm-testing.dir) && bash .gzip' || \
|
||||
echo "SSH failed: it's likely that stale content will be served via old gzip files."
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
This is the README for the sqlite3 WASM/JS distribution.
|
||||
|
||||
Main project page: https://sqlite.org
|
||||
|
||||
TODO: link to main WASM/JS docs, once they are online
|
||||
|
||||
This archive contains the sqlite3.js and sqlite3.wasm file which make
|
||||
up the sqlite3 WASM/JS build.
|
||||
|
||||
The jswasm directory contains the core sqlite3 deliverables and the
|
||||
top-level directory contains demonstration and test apps. Browsers
|
||||
will not serve WASM files from file:// URLs, so the demo/test apps
|
||||
require a web server and that server must include the following
|
||||
headers in its response when serving the files:
|
||||
|
||||
Cross-Origin-Opener-Policy: same-origin
|
||||
Cross-Origin-Embedder-Policy: require-corp
|
||||
|
||||
One simple way to get the demo apps up and running on Unix-style
|
||||
systems is to install althttpd (https://sqlite.org/althttpd) and run:
|
||||
|
||||
althttpd --enable-sab --page index.html
|
||||
|
||||
@@ -89,5 +89,6 @@ _sqlite3_value_text
|
||||
_sqlite3_value_type
|
||||
_sqlite3_vfs_find
|
||||
_sqlite3_vfs_register
|
||||
_sqlite3_vfs_unregister
|
||||
_malloc
|
||||
_free
|
||||
|
||||
@@ -48,6 +48,10 @@ browser client:
|
||||
Invokes functionality exposed by the previous two files to
|
||||
flesh out low-level parts of `sqlite3-api-prologue.js`. Most of
|
||||
these pieces related to the `sqlite3.capi.wasm` object.
|
||||
- `sqlite3-api-build-version.js`\
|
||||
Gets created by the build process and populates the
|
||||
`sqlite3.version` object. This part is not critical, but records the
|
||||
version of the library against which this module was built.
|
||||
- `sqlite3-api-oo1.js`\
|
||||
Provides a high-level object-oriented wrapper to the lower-level C
|
||||
API, colloquially known as OO API #1. Its API is similar to other
|
||||
@@ -60,12 +64,12 @@ browser client:
|
||||
thread via the Worker message-passing interface. Like OO API #1,
|
||||
this is an optional component, offering one of any number of
|
||||
potential implementations for such an API.
|
||||
- `../sqlite3-worker1.js`\
|
||||
- `sqlite3-worker1.js`\
|
||||
Is not part of the amalgamated sources and is intended to be
|
||||
loaded by a client Worker thread. It loads the sqlite3 module
|
||||
and runs the Worker #1 API which is implemented in
|
||||
`sqlite3-api-worker1.js`.
|
||||
- `../sqlite3-worker1-promiser.js`\
|
||||
- `sqlite3-worker1-promiser.js`\
|
||||
Is likewise not part of the amalgamated sources and provides
|
||||
a Promise-based interface into the Worker #1 API. This is
|
||||
a far user-friendlier way to interface with databases running
|
||||
@@ -74,7 +78,7 @@ browser client:
|
||||
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`\
|
||||
- `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
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
/* extern-post-js.js must be appended to the resulting sqlite3.js
|
||||
file. */
|
||||
file. It gets its name from being used as the value for the
|
||||
--extern-post-js=... Emscripten flag. Note that this code, unlike
|
||||
most of the associated JS code, runs outside of the
|
||||
Emscripten-generated module init scope, in the current
|
||||
global scope. */
|
||||
(function(){
|
||||
/**
|
||||
In order to hide the sqlite3InitModule()'s resulting Emscripten
|
||||
@@ -15,6 +19,32 @@
|
||||
if(!originalInit){
|
||||
throw new Error("Expecting self.sqlite3InitModule to be defined by the Emscripten build.");
|
||||
}
|
||||
/**
|
||||
We need to add some state which our custom Module.locateFile()
|
||||
can see, but an Emscripten limitation currently prevents us from
|
||||
attaching it to the sqlite3InitModule function object:
|
||||
|
||||
https://github.com/emscripten-core/emscripten/issues/18071
|
||||
|
||||
The only(?) current workaround is to temporarily stash this state
|
||||
into the global scope and delete it when sqlite3InitModule()
|
||||
is called.
|
||||
*/
|
||||
const initModuleState = self.sqlite3InitModuleState = Object.assign(Object.create(null),{
|
||||
moduleScript: self?.document?.currentScript,
|
||||
isWorker: ('undefined' !== typeof WorkerGlobalScope),
|
||||
location: self.location,
|
||||
urlParams: new URL(self.location.href).searchParams
|
||||
});
|
||||
if(initModuleState.urlParams.has('sqlite3.dir')){
|
||||
initModuleState.sqlite3Dir = initModuleState.urlParams.get('sqlite3.dir') +'/';
|
||||
}else if(initModuleState.moduleScript){
|
||||
const li = initModuleState.moduleScript.src.split('/');
|
||||
li.pop();
|
||||
initModuleState.sqlite3Dir = li.join('/') + '/';
|
||||
}
|
||||
//console.warn("initModuleState =",initModuleState);
|
||||
|
||||
self.sqlite3InitModule = (...args)=>{
|
||||
//console.warn("Using replaced sqlite3InitModule()",self.location);
|
||||
return originalInit(...args).then((EmscriptenModule)=>{
|
||||
@@ -31,6 +61,8 @@
|
||||
Emscripten details. */
|
||||
return EmscriptenModule;
|
||||
}
|
||||
EmscriptenModule.sqlite3.scriptInfo = initModuleState;
|
||||
//console.warn("sqlite3.scriptInfo =",EmscriptenModule.sqlite3.scriptInfo);
|
||||
const f = EmscriptenModule.sqlite3.asyncPostInit;
|
||||
delete EmscriptenModule.sqlite3.asyncPostInit;
|
||||
return f();
|
||||
@@ -40,5 +72,27 @@
|
||||
});
|
||||
};
|
||||
self.sqlite3InitModule.ready = originalInit.ready;
|
||||
//console.warn("Replaced sqlite3InitModule()");
|
||||
|
||||
if(self.sqlite3InitModuleState.moduleScript){
|
||||
const sim = self.sqlite3InitModuleState;
|
||||
let src = sim.moduleScript.src.split('/');
|
||||
src.pop();
|
||||
sim.scriptDir = src.join('/') + '/';
|
||||
}
|
||||
if(0){
|
||||
console.warn("Replaced sqlite3InitModule()");
|
||||
console.warn("self.location.href =",self.location.href);
|
||||
if('undefined' !== typeof document){
|
||||
console.warn("document.currentScript.src =",
|
||||
document?.currentScript?.src);
|
||||
}
|
||||
}
|
||||
/* Replace the various module exports performed by the Emscripten
|
||||
glue... */
|
||||
if (typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = sqlite3InitModule;
|
||||
else if (typeof exports === 'object')
|
||||
exports["sqlite3InitModule"] = sqlite3InitModule;
|
||||
/* AMD modules get injected in a way we cannot override,
|
||||
so we can't handle those here. */
|
||||
})();
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
/* extern-pre-js.js must be prepended to the resulting sqlite3.js
|
||||
file. This file is currently only used for holding snippets during
|
||||
test and development.
|
||||
|
||||
It gets its name from being used as the value for the
|
||||
--extern-pre-js=... Emscripten flag.
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* The current function scope was opened via post-js-header.js, which
|
||||
gets prepended to this at build-time. */
|
||||
gets prepended to this at build-time. This file closes that
|
||||
scope. */
|
||||
})/*postRun.push(...)*/;
|
||||
|
||||
+49
-2
@@ -1,6 +1,52 @@
|
||||
/**
|
||||
BEGIN FILE: api/pre-js.js
|
||||
|
||||
This file is intended to be prepended to the sqlite3.js build using
|
||||
Emscripten's --pre-js=THIS_FILE flag (or equivalent).
|
||||
*/
|
||||
|
||||
// See notes in extern-post-js.js
|
||||
const sqlite3InitModuleState = self.sqlite3InitModuleState || Object.create(null);
|
||||
delete self.sqlite3InitModuleState;
|
||||
|
||||
/**
|
||||
This custom locateFile() tries to figure out where to load `path`
|
||||
from. The intent is to provide a way for foo/bar/X.js loaded from a
|
||||
Worker constructor or importScripts() to be able to resolve
|
||||
foo/bar/X.wasm (in the latter case, with some help):
|
||||
|
||||
1) If URL param named the same as `path` is set, it is returned.
|
||||
|
||||
2) If sqlite3InitModuleState.sqlite3Dir is set, then (thatName + path)
|
||||
is returned (note that it's assumed to end with '/').
|
||||
|
||||
3) If this code is running in the main UI thread AND it was loaded
|
||||
from a SCRIPT tag, the directory part of that URL is used
|
||||
as the prefix. (This form of resolution unfortunately does not
|
||||
function for scripts loaded via importScripts().)
|
||||
|
||||
4) If none of the above apply, (prefix+path) is returned.
|
||||
*/
|
||||
Module['locateFile'] = function(path, prefix) {
|
||||
return prefix + path;
|
||||
};
|
||||
let theFile;
|
||||
const up = this.urlParams;
|
||||
if(0){
|
||||
console.warn("locateFile(",arguments[0], ',', arguments[1],")",
|
||||
'self.location =',self.location,
|
||||
'sqlite3InitModuleState.scriptDir =',this.scriptDir,
|
||||
'up.entries() =',Array.from(up.entries()));
|
||||
}
|
||||
if(up.has(path)){
|
||||
theFile = up.get(path);
|
||||
}else if(this.sqlite3Dir){
|
||||
theFile = this.sqlite3Dir + path;
|
||||
}else if(this.scriptDir){
|
||||
theFile = this.scriptDir + path;
|
||||
}else{
|
||||
theFile = prefix + path;
|
||||
}
|
||||
return theFile;
|
||||
}.bind(sqlite3InitModuleState);
|
||||
|
||||
/**
|
||||
Bug warning: this xInstantiateWasm bit must remain disabled
|
||||
@@ -39,3 +85,4 @@ Module[xInstantiateWasm] = function callee(imports,onSuccess){
|
||||
scripts.
|
||||
*/
|
||||
Module[xInstantiateWasm].uri = 'sqlite3.wasm';
|
||||
/* END FILE: api/pre-js.js */
|
||||
|
||||
@@ -20,17 +20,15 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build
|
||||
/**
|
||||
Install a suitable default configuration for sqlite3ApiBootstrap().
|
||||
*/
|
||||
const SABC = self.sqlite3ApiConfig || Object.create(null);
|
||||
if(undefined===SABC.Module){
|
||||
SABC.Module = Module /* ==> Currently needs to be exposed here for
|
||||
test code. NOT part of the public API. */;
|
||||
}
|
||||
if(undefined===SABC.exports){
|
||||
SABC.exports = Module['asm'];
|
||||
}
|
||||
if(undefined===SABC.memory){
|
||||
SABC.memory = Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */;
|
||||
}
|
||||
const SABC = Object.assign(
|
||||
Object.create(null), {
|
||||
Module: Module /* ==> Currently needs to be exposed here for
|
||||
test code. NOT part of the public API. */,
|
||||
exports: Module['asm'],
|
||||
memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */
|
||||
},
|
||||
self.sqlite3ApiConfig || Object.create(null)
|
||||
);
|
||||
|
||||
/**
|
||||
For current (2022-08-22) purposes, automatically call
|
||||
@@ -38,10 +36,11 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build
|
||||
point, as we really want client code to be able to call this to
|
||||
configure certain parts. Clients may modify
|
||||
self.sqlite3ApiBootstrap.defaultConfig to tweak the default
|
||||
configuration used by a no-args call to sqlite3ApiBootstrap().
|
||||
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("self.sqlite3ApiConfig = ",self.sqlite3ApiConfig);
|
||||
const rmApiConfig = (SABC !== self.sqlite3ApiConfig);
|
||||
self.sqlite3ApiConfig = SABC;
|
||||
let sqlite3;
|
||||
try{
|
||||
@@ -51,7 +50,7 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build
|
||||
throw e;
|
||||
}finally{
|
||||
delete self.sqlite3ApiBootstrap;
|
||||
if(rmApiConfig) delete self.sqlite3ApiConfig;
|
||||
delete self.sqlite3ApiConfig;
|
||||
}
|
||||
|
||||
if(self.location && +self.location.port > 1024){
|
||||
|
||||
@@ -72,10 +72,12 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
('sqlite3_stmt*', aPtr)
|
||||
('sqlite3_context*', aPtr)
|
||||
('sqlite3_value*', aPtr)
|
||||
('sqlite3_vfs*', aPtr)
|
||||
('void*', aPtr);
|
||||
wasm.xWrap.resultAdapter('sqlite3*', aPtr)
|
||||
('sqlite3_stmt*', aPtr)
|
||||
('sqlite3_context*', aPtr)
|
||||
('sqlite3_stmt*', aPtr)
|
||||
('sqlite3_vfs*', aPtr)
|
||||
('void*', aPtr);
|
||||
|
||||
/**
|
||||
@@ -224,6 +226,9 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
const __udfSetResult = function(pCtx, val){
|
||||
//console.warn("udfSetResult",typeof val, val);
|
||||
switch(typeof val) {
|
||||
case 'undefined':
|
||||
/* Assume that the client already called sqlite3_result_xxx(). */
|
||||
break;
|
||||
case 'boolean':
|
||||
capi.sqlite3_result_int(pCtx, val ? 1 : 0);
|
||||
break;
|
||||
@@ -318,7 +323,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
if(e instanceof sqlite3.WasmAllocError){
|
||||
capi.sqlite3_result_error_nomem(pCtx);
|
||||
}else{
|
||||
capi.sqlite3_result_error(pCtx, e.message, -1);
|
||||
const msg = ('string'===typeof e) ? e : e.message;
|
||||
capi.sqlite3_result_error(pCtx, msg, -1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -437,10 +443,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
try{
|
||||
const funcArgs = __xWrapFuncs({xStep, xFinal, xValue, xInverse, xDestroy},
|
||||
uninstall);
|
||||
rc = sqlite3CreateFunction(pDb, funcName, nArg, eTextRep,
|
||||
pApp, ...funcArgs);
|
||||
rc = sqlite3CreateWindowFunction(pDb, funcName, nArg, eTextRep,
|
||||
pApp, ...funcArgs);
|
||||
}catch(e){
|
||||
console.error("sqlite3_create_function_v2() setup threw:",e);
|
||||
console.error("sqlite3_create_window_function() setup threw:",e);
|
||||
for(let v of uninstall){
|
||||
wasm.uninstallFunction(v);
|
||||
}
|
||||
@@ -460,6 +466,11 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
- `number`: sqlite3_result_int() or sqlite3_result_double()
|
||||
- `string`: sqlite3_result_text()
|
||||
- Uint8Array or Int8Array: sqlite3_result_blob()
|
||||
- `undefined`: indicates that the UDF called one of the
|
||||
`sqlite3_result_xyz()` routines on its own, making this
|
||||
function a no-op. Results are _undefined_ if this function is
|
||||
passed the `undefined` value but did _not_ call one of the
|
||||
`sqlite3_result_xyz()` routines.
|
||||
|
||||
Anything else triggers sqlite3_result_error().
|
||||
*/
|
||||
@@ -492,10 +503,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
/**
|
||||
A helper for UDFs implemented in JS and bound to WASM by the
|
||||
client. It expects to be a passed `(sqlite3_context*, Error)`
|
||||
(i.e. an exception object). And it sets the current UDF's
|
||||
result to sqlite3_result_error_nomem() or sqlite3_result_error(),
|
||||
depending on whether the 2nd argument is a
|
||||
sqlite3.WasmAllocError object or not.
|
||||
(an exception object or message string). And it sets the
|
||||
current UDF's result to sqlite3_result_error_nomem() or
|
||||
sqlite3_result_error(), depending on whether the 2nd argument
|
||||
is a sqlite3.WasmAllocError object or not.
|
||||
*/
|
||||
capi.sqlite3_create_function_v2.udfSetError =
|
||||
capi.sqlite3_create_function.udfSetError =
|
||||
@@ -590,12 +601,16 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
For the given integer, returns the SQLITE_xxx result code as a
|
||||
string, or undefined if no such mapping is found.
|
||||
*/
|
||||
capi.sqlite3_web_rc_str = (rc)=>__rcMap[rc];
|
||||
capi.sqlite3_js_rc_str = (rc)=>__rcMap[rc];
|
||||
/* Bind all registered C-side structs... */
|
||||
const notThese = Object.assign(Object.create(null),{
|
||||
// Structs NOT to register
|
||||
WasmTestStruct: true
|
||||
});
|
||||
if(!util.isUIThread()){
|
||||
/* We remove the kvvfs VFS from Worker threads below. */
|
||||
notThese.sqlite3_kvvfs_methods = true;
|
||||
}
|
||||
for(const s of wasm.ctype.structs){
|
||||
if(!notThese[s.name]){
|
||||
capi[s.name] = sqlite3.StructBinder(s);
|
||||
@@ -603,94 +618,96 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
}
|
||||
}/*end C constant imports*/
|
||||
|
||||
if( util.isMainWindow()
|
||||
&& 0!==capi.sqlite3_vfs_find("kvvfs") ){/* kvvfs-specific glue */
|
||||
const kvvfsMethods = new capi.sqlite3_kvvfs_methods(
|
||||
wasm.exports.sqlite3_wasm_kvvfs_methods()
|
||||
);
|
||||
delete capi.sqlite3_kvvfs_methods;
|
||||
const pKvvfs = capi.sqlite3_vfs_find("kvvfs");
|
||||
if( pKvvfs ){/* kvvfs-specific glue */
|
||||
if(util.isUIThread()){
|
||||
const kvvfsMethods = new capi.sqlite3_kvvfs_methods(
|
||||
wasm.exports.sqlite3_wasm_kvvfs_methods()
|
||||
);
|
||||
delete capi.sqlite3_kvvfs_methods;
|
||||
|
||||
const kvvfsMakeKey = wasm.exports.sqlite3_wasm_kvvfsMakeKeyOnPstack,
|
||||
pstack = wasm.pstack,
|
||||
pAllocRaw = wasm.exports.sqlite3_wasm_pstack_alloc;
|
||||
const kvvfsMakeKey = wasm.exports.sqlite3_wasm_kvvfsMakeKeyOnPstack,
|
||||
pstack = wasm.pstack,
|
||||
pAllocRaw = wasm.exports.sqlite3_wasm_pstack_alloc;
|
||||
|
||||
const kvvfsStorage = (zClass)=>
|
||||
((115/*=='s'*/===wasm.getMemValue(zClass))
|
||||
? sessionStorage : localStorage);
|
||||
|
||||
const kvvfsImpls = {
|
||||
xRead: (zClass, zKey, zBuf, nBuf)=>{
|
||||
const stack = pstack.pointer,
|
||||
astack = wasm.scopedAllocPush();
|
||||
try {
|
||||
const zXKey = kvvfsMakeKey(zClass,zKey);
|
||||
if(!zXKey) return -3/*OOM*/;
|
||||
const jKey = wasm.cstringToJs(zXKey);
|
||||
const jV = kvvfsStorage(zClass).getItem(jKey);
|
||||
if(!jV) return -1;
|
||||
const nV = jV.length /* Note that we are relying 100% on v being
|
||||
ASCII so that jV.length is equal to the
|
||||
C-string's byte length. */;
|
||||
if(nBuf<=0) return nV;
|
||||
else if(1===nBuf){
|
||||
wasm.setMemValue(zBuf, 0);
|
||||
return nV;
|
||||
const kvvfsStorage = (zClass)=>
|
||||
((115/*=='s'*/===wasm.getMemValue(zClass))
|
||||
? sessionStorage : localStorage);
|
||||
|
||||
const kvvfsImpls = {
|
||||
xRead: (zClass, zKey, zBuf, nBuf)=>{
|
||||
const stack = pstack.pointer,
|
||||
astack = wasm.scopedAllocPush();
|
||||
try {
|
||||
const zXKey = kvvfsMakeKey(zClass,zKey);
|
||||
if(!zXKey) return -3/*OOM*/;
|
||||
const jKey = wasm.cstringToJs(zXKey);
|
||||
const jV = kvvfsStorage(zClass).getItem(jKey);
|
||||
if(!jV) return -1;
|
||||
const nV = jV.length /* Note that we are relying 100% on v being
|
||||
ASCII so that jV.length is equal to the
|
||||
C-string's byte length. */;
|
||||
if(nBuf<=0) return nV;
|
||||
else if(1===nBuf){
|
||||
wasm.setMemValue(zBuf, 0);
|
||||
return nV;
|
||||
}
|
||||
const zV = wasm.scopedAllocCString(jV);
|
||||
if(nBuf > nV + 1) nBuf = nV + 1;
|
||||
wasm.heap8u().copyWithin(zBuf, zV, zV + nBuf - 1);
|
||||
wasm.setMemValue(zBuf + nBuf - 1, 0);
|
||||
return nBuf - 1;
|
||||
}catch(e){
|
||||
console.error("kvstorageRead()",e);
|
||||
return -2;
|
||||
}finally{
|
||||
pstack.restore(stack);
|
||||
wasm.scopedAllocPop(astack);
|
||||
}
|
||||
},
|
||||
xWrite: (zClass, zKey, zData)=>{
|
||||
const stack = pstack.pointer;
|
||||
try {
|
||||
const zXKey = kvvfsMakeKey(zClass,zKey);
|
||||
if(!zXKey) return 1/*OOM*/;
|
||||
const jKey = wasm.cstringToJs(zXKey);
|
||||
kvvfsStorage(zClass).setItem(jKey, wasm.cstringToJs(zData));
|
||||
return 0;
|
||||
}catch(e){
|
||||
console.error("kvstorageWrite()",e);
|
||||
return capi.SQLITE_IOERR;
|
||||
}finally{
|
||||
pstack.restore(stack);
|
||||
}
|
||||
},
|
||||
xDelete: (zClass, zKey)=>{
|
||||
const stack = pstack.pointer;
|
||||
try {
|
||||
const zXKey = kvvfsMakeKey(zClass,zKey);
|
||||
if(!zXKey) return 1/*OOM*/;
|
||||
kvvfsStorage(zClass).removeItem(wasm.cstringToJs(zXKey));
|
||||
return 0;
|
||||
}catch(e){
|
||||
console.error("kvstorageDelete()",e);
|
||||
return capi.SQLITE_IOERR;
|
||||
}finally{
|
||||
pstack.restore(stack);
|
||||
}
|
||||
const zV = wasm.scopedAllocCString(jV);
|
||||
if(nBuf > nV + 1) nBuf = nV + 1;
|
||||
wasm.heap8u().copyWithin(zBuf, zV, zV + nBuf - 1);
|
||||
wasm.setMemValue(zBuf + nBuf - 1, 0);
|
||||
return nBuf - 1;
|
||||
}catch(e){
|
||||
console.error("kvstorageRead()",e);
|
||||
return -2;
|
||||
}finally{
|
||||
pstack.restore(stack);
|
||||
wasm.scopedAllocPop(astack);
|
||||
}
|
||||
},
|
||||
xWrite: (zClass, zKey, zData)=>{
|
||||
const stack = pstack.pointer;
|
||||
try {
|
||||
const zXKey = kvvfsMakeKey(zClass,zKey);
|
||||
if(!zXKey) return 1/*OOM*/;
|
||||
const jKey = wasm.cstringToJs(zXKey);
|
||||
kvvfsStorage(zClass).setItem(jKey, wasm.cstringToJs(zData));
|
||||
return 0;
|
||||
}catch(e){
|
||||
console.error("kvstorageWrite()",e);
|
||||
return capi.SQLITE_IOERR;
|
||||
}finally{
|
||||
pstack.restore(stack);
|
||||
}
|
||||
},
|
||||
xDelete: (zClass, zKey)=>{
|
||||
const stack = pstack.pointer;
|
||||
try {
|
||||
const zXKey = kvvfsMakeKey(zClass,zKey);
|
||||
if(!zXKey) return 1/*OOM*/;
|
||||
kvvfsStorage(zClass).removeItem(wasm.cstringToJs(zXKey));
|
||||
return 0;
|
||||
}catch(e){
|
||||
console.error("kvstorageDelete()",e);
|
||||
return capi.SQLITE_IOERR;
|
||||
}finally{
|
||||
pstack.restore(stack);
|
||||
}
|
||||
}/*kvvfsImpls*/;
|
||||
for(let k of Object.keys(kvvfsImpls)){
|
||||
kvvfsMethods[kvvfsMethods.memberKey(k)] =
|
||||
wasm.installFunction(
|
||||
kvvfsMethods.memberSignature(k),
|
||||
kvvfsImpls[k]
|
||||
);
|
||||
}
|
||||
}/*kvvfsImpls*/;
|
||||
for(let k of Object.keys(kvvfsImpls)){
|
||||
kvvfsMethods[kvvfsMethods.memberKey(k)] =
|
||||
wasm.installFunction(
|
||||
kvvfsMethods.memberSignature(k),
|
||||
kvvfsImpls[k]
|
||||
);
|
||||
}else{
|
||||
/* Worker thread: unregister kvvfs to avoid it being used
|
||||
for anything other than local/sessionStorage. It "can"
|
||||
be used that way but it's not really intended to be. */
|
||||
capi.sqlite3_vfs_unregister(pKvvfs);
|
||||
}
|
||||
}/*kvvfs*/
|
||||
}/*pKvvfs*/
|
||||
|
||||
sqlite3.version = Object.assign(Object.create(null),{
|
||||
library: sqlite3.capi.sqlite3_libversion(),
|
||||
sourceId: sqlite3.capi.sqlite3_sourceid()
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+145
-69
@@ -45,8 +45,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
|
||||
/** If object opts has _its own_ property named p then that
|
||||
property's value is returned, else dflt is returned. */
|
||||
const getOwnOption = (opts, p, dflt)=>
|
||||
opts.hasOwnProperty(p) ? opts[p] : dflt;
|
||||
const getOwnOption = (opts, p, dflt)=>{
|
||||
const d = Object.getOwnPropertyDescriptor(opts,p);
|
||||
return d ? d.value : dflt;
|
||||
};
|
||||
|
||||
// Documented in DB.checkRc()
|
||||
const checkSqlite3Rc = function(dbPtr, sqliteResultCode){
|
||||
@@ -85,7 +87,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
being-construct DB object as its "this". See the DB constructor
|
||||
for the argument docs. This is split into a separate function
|
||||
in order to enable simple creation of special-case DB constructors,
|
||||
e.g. JsStorageDB and OpfsDB.
|
||||
e.g. JsStorageDb and OpfsDb.
|
||||
|
||||
Expects to be passed a configuration object with the following
|
||||
properties:
|
||||
@@ -147,13 +149,10 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
if( flagsStr.indexOf('w')>=0 ) oflags |= capi.SQLITE_OPEN_READWRITE;
|
||||
if( 0===oflags ) oflags |= capi.SQLITE_OPEN_READONLY;
|
||||
oflags |= capi.SQLITE_OPEN_EXRESCODE;
|
||||
const scope = wasm.scopedAllocPush();
|
||||
const stack = wasm.pstack.pointer;
|
||||
try {
|
||||
const pPtr = wasm.allocPtr() /* output (sqlite3**) arg */;
|
||||
const pVfsName = vfsName ? (
|
||||
('number'===typeof vfsName ? vfsName : wasm.scopedAllocCString(vfsName))
|
||||
): 0;
|
||||
let rc = capi.sqlite3_open_v2(fn, pPtr, oflags, pVfsName);
|
||||
const pPtr = wasm.pstack.allocPtr() /* output (sqlite3**) arg */;
|
||||
let rc = capi.sqlite3_open_v2(fn, pPtr, oflags, vfsName || 0);
|
||||
pDb = wasm.getPtrValue(pPtr);
|
||||
checkSqlite3Rc(pDb, rc);
|
||||
if(flagsStr.indexOf('t')>=0){
|
||||
@@ -161,21 +160,19 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
__dbTraceToConsole, 0);
|
||||
}
|
||||
// Check for per-VFS post-open SQL...
|
||||
wasm.setPtrValue(pPtr, 0);
|
||||
if(0===capi.sqlite3_file_control(
|
||||
pDb, "main", capi.SQLITE_FCNTL_VFS_POINTER, pPtr
|
||||
)){
|
||||
const postInitSql = __vfsPostOpenSql[wasm.getPtrValue(pPtr)];
|
||||
if(postInitSql){
|
||||
rc = capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0);
|
||||
checkSqlite3Rc(pDb, rc);
|
||||
}
|
||||
const pVfs = capi.sqlite3_js_db_vfs(pDb);
|
||||
//console.warn("Opened db",fn,"with vfs",vfsName,pVfs);
|
||||
if(!pVfs) toss3("Internal error: cannot get VFS for new db handle.");
|
||||
const postInitSql = __vfsPostOpenSql[pVfs];
|
||||
if(postInitSql){
|
||||
rc = capi.sqlite3_exec(pDb, postInitSql, 0, 0, 0);
|
||||
checkSqlite3Rc(pDb, rc);
|
||||
}
|
||||
}catch( e ){
|
||||
if( pDb ) capi.sqlite3_close_v2(pDb);
|
||||
throw e;
|
||||
}finally{
|
||||
wasm.scopedAllocPop(scope);
|
||||
wasm.pstack.restore(stack);
|
||||
}
|
||||
this.filename = fnJs;
|
||||
__ptrMap.set(this, pDb);
|
||||
@@ -374,11 +371,11 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
case 1:
|
||||
if('string'===typeof args[0] || util.isSQLableTypedArray(args[0])){
|
||||
out.sql = args[0];
|
||||
}else if(Array.isArray(args[0])){
|
||||
out.sql = args[0];
|
||||
}else if(args[0] && 'object'===typeof args[0]){
|
||||
out.opt = args[0];
|
||||
out.sql = out.opt.sql;
|
||||
}else if(Array.isArray(args[0])){
|
||||
out.sql = args[0];
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
@@ -392,7 +389,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
}else if(Array.isArray(out.sql)){
|
||||
out.sql = out.sql.join('');
|
||||
}else if('string'!==typeof out.sql){
|
||||
toss3("Missing SQL argument.");
|
||||
toss3("Missing SQL argument or unsupported SQL value type.");
|
||||
}
|
||||
if(out.opt.callback || out.opt.resultRows){
|
||||
switch((undefined===out.opt.rowMode)
|
||||
@@ -810,12 +807,14 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
`xFunc` to align with the C API documentation). In the final
|
||||
case, the function's name must be the 'name' property.
|
||||
|
||||
This can currently only be used to create scalar functions, not
|
||||
aggregate or window functions (requires only a bit of
|
||||
refactoring to support aggregates and window functions).
|
||||
The first two call forms can only be used for creating scalar
|
||||
functions. Creating an aggregate or window function requires
|
||||
the options-object form (see below for details).
|
||||
|
||||
UDFs cannot currently be removed from a DB handle after they're
|
||||
added.
|
||||
added. More correctly, they can be removed as documented for
|
||||
sqlite3_create_function_v2(), but doing so will "leak" the
|
||||
JS-created WASM binding of those functions.
|
||||
|
||||
On success, returns this object. Throws on error.
|
||||
|
||||
@@ -825,71 +824,148 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
cannot be determined. The docs for sqlite3_create_function_v2()
|
||||
describe the conversions in more detail.
|
||||
|
||||
The optional options object may contain flags to modify how
|
||||
The values set in the options object differ for scalar and
|
||||
aggregate functions:
|
||||
|
||||
- Scalar: set the `xFunc` function-type property to the UDF
|
||||
function.
|
||||
|
||||
- Aggregate: set the `xStep` and `xFinal` function-type
|
||||
properties to the "step" and "final" callbacks for the
|
||||
aggregate. Do not set the `xFunc` property.
|
||||
|
||||
- Window: set the `xStep`, `xFinal`, `xValue`, and `xInverse`
|
||||
function-type properties. Do not set the `xFunc` property.
|
||||
|
||||
The options object may optionally have an `xDestroy`
|
||||
function-type property, as per sqlite3_create_function_v2().
|
||||
Its argument will be the WASM-pointer-type value of the `pApp`
|
||||
property, and this function will throw if `pApp` is defined but
|
||||
is not null, undefined, or a numeric (WASM pointer)
|
||||
value. i.e. `pApp`, if set, must be value suitable for use as a
|
||||
WASM pointer argument, noting that `null` or `undefined` will
|
||||
translate to 0 for that purpose.
|
||||
|
||||
The options object may contain flags to modify how
|
||||
the function is defined:
|
||||
|
||||
- .arity: the number of arguments which SQL calls to this
|
||||
function expect or require. The default value is
|
||||
`callback.length` (i.e. the number of declared parameters it
|
||||
has) **MINUS 1** (see below for why). As a special case, if
|
||||
callback.length is 0, its arity is also 0 instead of -1. A
|
||||
negative arity value means that the function is variadic and
|
||||
may accept any number of arguments, up to sqlite3's
|
||||
compile-time limits. sqlite3 will enforce the argument count if
|
||||
is zero or greater.
|
||||
|
||||
The callback always receives a pointer to an `sqlite3_context`
|
||||
object as its first argument. Any arguments after that are from
|
||||
SQL code. The leading context argument does _not_ count towards
|
||||
the function's arity. See the docs for
|
||||
- `arity`: the number of arguments which SQL calls to this
|
||||
function expect or require. The default value is `xFunc.length`
|
||||
or `xStep.length` (i.e. the number of declared parameters it
|
||||
has) **MINUS 1** (see below for why). As a special case, if the
|
||||
`length` is 0, its arity is also 0 instead of -1. A negative
|
||||
arity value means that the function is variadic and may accept
|
||||
any number of arguments, up to sqlite3's compile-time
|
||||
limits. sqlite3 will enforce the argument count if is zero or
|
||||
greater. The callback always receives a pointer to an
|
||||
`sqlite3_context` object as its first argument. Any arguments
|
||||
after that are from SQL code. The leading context argument does
|
||||
_not_ count towards the function's arity. See the docs for
|
||||
sqlite3.capi.sqlite3_create_function_v2() for why that argument
|
||||
is needed in the interface.
|
||||
|
||||
The following properties correspond to flags documented at:
|
||||
The following options-object properties correspond to flags
|
||||
documented at:
|
||||
|
||||
https://sqlite.org/c3ref/create_function.html
|
||||
|
||||
- .deterministic = SQLITE_DETERMINISTIC
|
||||
- .directOnly = SQLITE_DIRECTONLY
|
||||
- .innocuous = SQLITE_INNOCUOUS
|
||||
|
||||
TODO: for the (optionsObject) form, accept callbacks for
|
||||
aggregate and window functions.
|
||||
- `deterministic` = sqlite3.capi.SQLITE_DETERMINISTIC
|
||||
- `directOnly` = sqlite3.capi.SQLITE_DIRECTONLY
|
||||
- `innocuous` = sqlite3.capi.SQLITE_INNOCUOUS
|
||||
|
||||
Sidebar: the ability to add new WASM-accessible functions to
|
||||
the runtime requires that the WASM build is compiled with the
|
||||
equivalent functionality as that provided by Emscripten's
|
||||
`-sALLOW_TABLE_GROWTH` flag.
|
||||
*/
|
||||
createFunction: function f(name, callback, opt){
|
||||
createFunction: function f(name, xFunc, opt){
|
||||
const isFunc = (f)=>(f instanceof Function);
|
||||
switch(arguments.length){
|
||||
case 1: /* (optionsObject) */
|
||||
opt = name;
|
||||
name = opt.name;
|
||||
callback = opt.xFunc || opt.callback;
|
||||
xFunc = opt.xFunc || 0;
|
||||
break;
|
||||
case 2: /* (name, callback|optionsObject) */
|
||||
if(!(callback instanceof Function)){
|
||||
opt = callback;
|
||||
callback = opt.xFunc || opt.callback;
|
||||
if(!isFunc(xFunc)){
|
||||
opt = xFunc;
|
||||
xFunc = opt.xFunc || 0;
|
||||
}
|
||||
break;
|
||||
case 3: /* name, xFunc, opt */
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
if(!opt) opt = {};
|
||||
if(!(callback instanceof Function)){
|
||||
toss3("Invalid arguments: expecting a callback function.");
|
||||
}else if('string' !== typeof name){
|
||||
if('string' !== typeof name){
|
||||
toss3("Invalid arguments: missing function name.");
|
||||
}
|
||||
let xStep = opt.xStep || 0;
|
||||
let xFinal = opt.xFinal || 0;
|
||||
const xValue = opt.xValue || 0;
|
||||
const xInverse = opt.xInverse || 0;
|
||||
let isWindow = undefined;
|
||||
if(isFunc(xFunc)){
|
||||
isWindow = false;
|
||||
if(isFunc(xStep) || isFunc(xFinal)){
|
||||
toss3("Ambiguous arguments: scalar or aggregate?");
|
||||
}
|
||||
xStep = xFinal = null;
|
||||
}else if(isFunc(xStep)){
|
||||
if(!isFunc(xFinal)){
|
||||
toss3("Missing xFinal() callback for aggregate or window UDF.");
|
||||
}
|
||||
xFunc = null;
|
||||
}else if(isFunc(xFinal)){
|
||||
toss3("Missing xStep() callback for aggregate or window UDF.");
|
||||
}else{
|
||||
toss3("Missing function-type properties.");
|
||||
}
|
||||
if(false === isWindow){
|
||||
if(isFunc(xValue) || isFunc(xInverse)){
|
||||
toss3("xValue and xInverse are not permitted for non-window UDFs.");
|
||||
}
|
||||
}else if(isFunc(xValue)){
|
||||
if(!isFunc(xInverse)){
|
||||
toss3("xInverse must be provided if xValue is.");
|
||||
}
|
||||
isWindow = true;
|
||||
}else if(isFunc(xInverse)){
|
||||
toss3("xValue must be provided if xInverse is.");
|
||||
}
|
||||
const pApp = opt.pApp;
|
||||
if(undefined!==pApp &&
|
||||
null!==pApp &&
|
||||
(('number'!==typeof pApp) || !capi.util.isInt32(pApp))){
|
||||
toss3("Invalid value for pApp property. Must be a legal WASM pointer value.");
|
||||
}
|
||||
const xDestroy = opt.xDestroy || 0;
|
||||
if(xDestroy && !isFunc(xDestroy)){
|
||||
toss3("xDestroy property must be a function.");
|
||||
}
|
||||
let fFlags = 0 /*flags for sqlite3_create_function_v2()*/;
|
||||
if(getOwnOption(opt, 'deterministic')) fFlags |= capi.SQLITE_DETERMINISTIC;
|
||||
if(getOwnOption(opt, 'directOnly')) fFlags |= capi.SQLITE_DIRECTONLY;
|
||||
if(getOwnOption(opt, 'innocuous')) fFlags |= capi.SQLITE_INNOCUOUS;
|
||||
name = name.toLowerCase();
|
||||
DB.checkRc(this, capi.sqlite3_create_function_v2(
|
||||
this.pointer, name,
|
||||
(opt.hasOwnProperty('arity')
|
||||
? +opt.arity
|
||||
: (callback.length ? callback.length-1/*for pCtx arg*/ : 0)),
|
||||
capi.SQLITE_UTF8 | fFlags, null/*pApp*/, callback,
|
||||
null/*xStep*/, null/*xFinal*/, null/*xDestroy*/));
|
||||
const xArity = xFunc || xStep;
|
||||
const arity = getOwnOption(opt, 'arity');
|
||||
const arityArg = ('number'===typeof arity
|
||||
? arity
|
||||
: (xArity.length ? xArity.length-1/*for pCtx arg*/ : 0));
|
||||
let rc;
|
||||
if( isWindow ){
|
||||
rc = capi.sqlite3_create_window_function(
|
||||
this.pointer, name, arityArg,
|
||||
capi.SQLITE_UTF8 | fFlags, pApp || 0,
|
||||
xStep, xFinal, xValue, xInverse, xDestroy);
|
||||
}else{
|
||||
rc = capi.sqlite3_create_function_v2(
|
||||
this.pointer, name, arityArg,
|
||||
capi.SQLITE_UTF8 | fFlags, pApp || 0,
|
||||
xFunc, xStep, xFinal, xDestroy);
|
||||
}
|
||||
DB.checkRc(this, rc);
|
||||
return this;
|
||||
}/*createFunction()*/,
|
||||
/**
|
||||
@@ -1358,7 +1434,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
default:
|
||||
this._mayGet = false;
|
||||
console.warn("sqlite3_step() rc=",rc,
|
||||
capi.sqlite3_web_rc_str(rc),
|
||||
capi.sqlite3_js_rc_str(rc),
|
||||
"SQL =", capi.sqlite3_sql(this.pointer));
|
||||
DB.checkRc(this.db.pointer, rc);
|
||||
}
|
||||
@@ -1596,7 +1672,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
dbCtorHelper
|
||||
}/*oo1 object*/;
|
||||
|
||||
if(util.isMainWindow()){
|
||||
if(util.isUIThread()){
|
||||
/**
|
||||
Functionally equivalent to DB(storageName,'c','kvvfs') except
|
||||
that it throws if the given storage name is not one of 'local'
|
||||
@@ -1614,8 +1690,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
};
|
||||
const jdb = sqlite3.oo1.JsStorageDb;
|
||||
jdb.prototype = Object.create(DB.prototype);
|
||||
/** Equivalent to sqlite3_web_kvvfs_clear(). */
|
||||
jdb.clearStorage = capi.sqlite3_web_kvvfs_clear;
|
||||
/** Equivalent to sqlite3_js_kvvfs_clear(). */
|
||||
jdb.clearStorage = capi.sqlite3_js_kvvfs_clear;
|
||||
/**
|
||||
Clears this database instance's storage or throws if this
|
||||
instance has been closed. Returns the number of
|
||||
@@ -1624,8 +1700,8 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
jdb.prototype.clearStorage = function(){
|
||||
return jdb.clearStorage(affirmDbOpen(this).filename);
|
||||
};
|
||||
/** Equivalent to sqlite3_web_kvvfs_size(). */
|
||||
jdb.storageSize = capi.sqlite3_web_kvvfs_size;
|
||||
/** Equivalent to sqlite3_js_kvvfs_size(). */
|
||||
jdb.storageSize = capi.sqlite3_js_kvvfs_size;
|
||||
/**
|
||||
Returns the _approximate_ number of bytes this database takes
|
||||
up in its storage or throws if this instance has been closed.
|
||||
|
||||
@@ -15,14 +15,17 @@
|
||||
asynchronous Origin-Private FileSystem (OPFS) APIs using a second
|
||||
Worker, implemented in sqlite3-opfs-async-proxy.js. This file is
|
||||
intended to be appended to the main sqlite3 JS deliverable somewhere
|
||||
after sqlite3-api-glue.js and before sqlite3-api-cleanup.js.
|
||||
after sqlite3-api-oo1.js and before sqlite3-api-cleanup.js.
|
||||
*/
|
||||
'use strict';
|
||||
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 uses the Origin-Private FileSystem API for
|
||||
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.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
|
||||
explaining the problem. Reasons for rejection include, but are
|
||||
not limited to:
|
||||
@@ -48,31 +51,31 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
proxying OPFS's synchronous API via the synchronous interface
|
||||
required by the sqlite3_vfs API.
|
||||
|
||||
- This function may only be called a single time and it must be
|
||||
called from the client, as opposed to the library initialization,
|
||||
in case the client requires a custom path for this API's
|
||||
"counterpart": this function's argument is the relative URI to
|
||||
this module's "asynchronous half". When called, this function removes
|
||||
itself from the sqlite3 object.
|
||||
- This function may only be called a single time. When called, this
|
||||
function removes itself from the sqlite3 object.
|
||||
|
||||
The argument may optionally be a plain object with the following
|
||||
configuration options:
|
||||
All arguments to this function are for internal/development purposes
|
||||
only. They do not constitute a public API and may change at any
|
||||
time.
|
||||
|
||||
- proxyUri: as described above
|
||||
The argument may optionally be a plain object with the following
|
||||
configuration options:
|
||||
|
||||
- verbose (=2): an integer 0-3. 0 disables all logging, 1 enables
|
||||
logging of errors. 2 enables logging of warnings and errors. 3
|
||||
additionally enables debugging info.
|
||||
- proxyUri: as described above
|
||||
|
||||
- sanityChecks (=false): if true, some basic sanity tests are
|
||||
run on the OPFS VFS API after it's initialized, before the
|
||||
returned Promise resolves.
|
||||
- verbose (=2): an integer 0-3. 0 disables all logging, 1 enables
|
||||
logging of errors. 2 enables logging of warnings and errors. 3
|
||||
additionally enables debugging info.
|
||||
|
||||
On success, the Promise resolves to the top-most sqlite3 namespace
|
||||
object and that object gets a new object installed in its
|
||||
`opfs` property, containing several OPFS-specific utilities.
|
||||
- sanityChecks (=false): if true, some basic sanity tests are
|
||||
run on the OPFS VFS API after it's initialized, before the
|
||||
returned Promise resolves.
|
||||
|
||||
On success, the Promise resolves to the top-most sqlite3 namespace
|
||||
object and that object gets a new object installed in its
|
||||
`opfs` property, containing several OPFS-specific utilities.
|
||||
*/
|
||||
const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
const installOpfsVfs = function callee(options){
|
||||
if(!self.SharedArrayBuffer ||
|
||||
!self.Atomics ||
|
||||
!self.FileSystemHandle ||
|
||||
@@ -84,9 +87,9 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
new Error("This environment does not have OPFS support.")
|
||||
);
|
||||
}
|
||||
const options = (asyncProxyUri && 'object'===asyncProxyUri) ? asyncProxyUri : {
|
||||
proxyUri: asyncProxyUri
|
||||
};
|
||||
if(!options || 'object'!==typeof options){
|
||||
options = Object.create(null);
|
||||
}
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
if(undefined===options.verbose){
|
||||
options.verbose = urlParams.has('opfs-verbose') ? 3 : 2;
|
||||
@@ -98,6 +101,9 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
options.proxyUri = callee.defaultProxyUri;
|
||||
}
|
||||
|
||||
if('function' === typeof options.proxyUri){
|
||||
options.proxyUri = options.proxyUri();
|
||||
}
|
||||
const thePromise = new Promise(function(promiseResolve, promiseReject_){
|
||||
const loggers = {
|
||||
0:console.error.bind(console),
|
||||
@@ -110,7 +116,6 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
const log = (...args)=>logImpl(2, ...args);
|
||||
const warn = (...args)=>logImpl(1, ...args);
|
||||
const error = (...args)=>logImpl(0, ...args);
|
||||
//warn("The OPFS VFS feature is very much experimental and under construction.");
|
||||
const toss = function(...args){throw new Error(args.join(' '))};
|
||||
const capi = sqlite3.capi;
|
||||
const wasm = capi.wasm;
|
||||
@@ -155,9 +160,6 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
s.count = s.time = 0;
|
||||
s = metrics.s11n.deserialize = Object.create(null);
|
||||
s.count = s.time = 0;
|
||||
//[ // timed routines which are not in state.opIds
|
||||
// 'xFileControl'
|
||||
//].forEach((k)=>r(metrics[k] = Object.create(null)));
|
||||
}
|
||||
}/*metrics*/;
|
||||
const promiseReject = function(err){
|
||||
@@ -220,32 +222,36 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
cases. We should probably have one SAB here with a single slot
|
||||
for locking a per-file initialization step and then allocate a
|
||||
separate SAB like the above one for each file. That will
|
||||
require a bit of acrobatics but should be feasible.
|
||||
require a bit of acrobatics but should be feasible. The most
|
||||
problematic part is that xOpen() would have to use
|
||||
postMessage() to communicate its SharedArrayBuffer, and mixing
|
||||
that approach with Atomics.wait/notify() gets a bit messy.
|
||||
*/
|
||||
const state = Object.create(null);
|
||||
state.verbose = options.verbose;
|
||||
state.littleEndian = (()=>{
|
||||
const buffer = new ArrayBuffer(2);
|
||||
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
|
||||
new DataView(buffer).setInt16(0, 256, true /* ==>littleEndian */);
|
||||
// Int16Array uses the platform's endianness.
|
||||
return new Int16Array(buffer)[0] === 256;
|
||||
})();
|
||||
/** Whether the async counterpart should log exceptions to
|
||||
the serialization channel. That produces a great deal of
|
||||
noise for seemingly innocuous things like xAccess() checks
|
||||
for missing files, so this option may have one of 3 values:
|
||||
/**
|
||||
Whether the async counterpart should log exceptions to
|
||||
the serialization channel. That produces a great deal of
|
||||
noise for seemingly innocuous things like xAccess() checks
|
||||
for missing files, so this option may have one of 3 values:
|
||||
|
||||
0 = no exception logging
|
||||
0 = no exception logging
|
||||
|
||||
1 = only log exceptions for "significant" ops like xOpen(),
|
||||
xRead(), and xWrite().
|
||||
1 = only log exceptions for "significant" ops like xOpen(),
|
||||
xRead(), and xWrite().
|
||||
|
||||
2 = log all exceptions.
|
||||
2 = log all exceptions.
|
||||
*/
|
||||
state.asyncS11nExceptions = 1;
|
||||
/* Size of file I/O buffer block. 64k = max sqlite3 page size. */
|
||||
state.fileBufferSize =
|
||||
1024 * 64;
|
||||
/* Size of file I/O buffer block. 64k = max sqlite3 page size, and
|
||||
xRead/xWrite() will never deal in blocks larger than that. */
|
||||
state.fileBufferSize = 1024 * 64;
|
||||
state.sabS11nOffset = state.fileBufferSize;
|
||||
/**
|
||||
The size of the block in our SAB for serializing arguments and
|
||||
@@ -255,7 +261,8 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
*/
|
||||
state.sabS11nSize = opfsVfs.$mxPathname * 2;
|
||||
/**
|
||||
The SAB used for all data I/O (files and arg/result s11n).
|
||||
The SAB used for all data I/O between the synchronous and
|
||||
async halves (file i/o and arg/result s11n).
|
||||
*/
|
||||
state.sabIO = new SharedArrayBuffer(
|
||||
state.fileBufferSize/* file i/o block */
|
||||
@@ -294,7 +301,13 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
state.opIds.mkdir = i++;
|
||||
state.opIds['opfs-async-metrics'] = i++;
|
||||
state.opIds['opfs-async-shutdown'] = i++;
|
||||
state.sabOP = new SharedArrayBuffer(i * 4/*sizeof int32*/);
|
||||
/* The retry slot is used by the async part for wait-and-retry
|
||||
semantics. Though we could hypothetically use the xSleep slot
|
||||
for that, doing so might lead to undesired side effects. */
|
||||
state.opIds.retry = i++;
|
||||
state.sabOP = new SharedArrayBuffer(
|
||||
i * 4/* ==sizeof int32, noting that Atomics.wait() and friends
|
||||
can only function on Int32Array views of an SAB. */);
|
||||
opfsUtil.metrics.reset();
|
||||
}
|
||||
/**
|
||||
@@ -335,9 +348,12 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
state.s11n.serialize(...args);
|
||||
Atomics.store(state.sabOPView, state.opIds.rc, -1);
|
||||
Atomics.store(state.sabOPView, state.opIds.whichOp, opNdx);
|
||||
Atomics.notify(state.sabOPView, state.opIds.whichOp) /* async thread will take over here */;
|
||||
Atomics.notify(state.sabOPView, state.opIds.whichOp)
|
||||
/* async thread will take over here */;
|
||||
const t = performance.now();
|
||||
Atomics.wait(state.sabOPView, state.opIds.rc, -1);
|
||||
Atomics.wait(state.sabOPView, state.opIds.rc, -1)
|
||||
/* When this wait() call returns, the async half will have
|
||||
completed the operation and reported its results. */;
|
||||
const rc = Atomics.load(state.sabOPView, state.opIds.rc);
|
||||
metrics[op].wait += performance.now() - t;
|
||||
if(rc && state.asyncS11nExceptions){
|
||||
@@ -349,17 +365,22 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
|
||||
const initS11n = ()=>{
|
||||
/**
|
||||
ACHTUNG: this code is 100% duplicated in the other half of this
|
||||
proxy! The documentation is maintained in the "synchronous half".
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
ACHTUNG: this code is 100% duplicated in the other half of
|
||||
this proxy! The documentation is maintained in the
|
||||
"synchronous half".
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
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]. 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 sqlite3_vfs and
|
||||
sqlite3_io_methods operations.
|
||||
This is not a general-purpose format. It only supports the
|
||||
range of operations, and data sizes, needed by the
|
||||
sqlite3_vfs and sqlite3_io_methods operations. Serialized
|
||||
data are transient and this serialization algorithm may
|
||||
change at any time.
|
||||
|
||||
The data format can be succinctly summarized as:
|
||||
|
||||
@@ -383,7 +404,8 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
using their TextEncoder/TextDecoder representations. It would
|
||||
arguably make more sense to store them as Int16Arrays of
|
||||
their JS character values, but how best/fastest to get that
|
||||
in and out of string form us an open point.
|
||||
in and out of string form is an open point. Initial
|
||||
experimentation with that approach did not gain us any speed.
|
||||
|
||||
Historical note: this impl was initially about 1% this size by
|
||||
using using JSON.stringify/parse(), but using fit-to-purpose
|
||||
@@ -580,9 +602,11 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
toss("Member",name," is not a function pointer. Signature =",sigN);
|
||||
}
|
||||
const memKey = tgt.memberKey(name);
|
||||
//log("installMethod",tgt, name, sigN);
|
||||
const fProxy = 0
|
||||
// We can remove this proxy middle-man once the VFS is working
|
||||
/** This middle-man proxy is only for use during development, to
|
||||
confirm that we always pass the proper number of
|
||||
arguments. We know that the C-level code will always use the
|
||||
correct argument count. */
|
||||
? callee.argcProxy(func, sigN)
|
||||
: func;
|
||||
const pFunc = wasm.installFunction(fProxy, tgt.memberSignature(name, true));
|
||||
@@ -603,7 +627,6 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
const mTimeStart = (op)=>{
|
||||
opTimer.start = performance.now();
|
||||
opTimer.op = op;
|
||||
//metrics[op] || toss("Maintenance required: missing metrics for",op);
|
||||
++metrics[op].count;
|
||||
};
|
||||
const mTimeEnd = ()=>(
|
||||
@@ -616,8 +639,15 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
*/
|
||||
const ioSyncWrappers = {
|
||||
xCheckReservedLock: function(pFile,pOut){
|
||||
// Exclusive lock is automatically acquired when opened
|
||||
//warn("xCheckReservedLock(",arguments,") is a no-op");
|
||||
/**
|
||||
As of late 2022, only a single lock can be held on an OPFS
|
||||
file. We have no way of checking whether any _other_ db
|
||||
connection has a lock except by trying to obtain and (on
|
||||
success) release a sync-handle for it, but doing so would
|
||||
involve an inherent race condition. For the time being,
|
||||
pending a better solution, we simply report whether the
|
||||
given pFile instance has a lock.
|
||||
*/
|
||||
const f = __openFiles[pFile];
|
||||
wasm.setMemValue(pOut, f.lockMode ? 1 : 0, 'i32');
|
||||
return 0;
|
||||
@@ -670,14 +700,17 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
return rc;
|
||||
},
|
||||
xRead: function(pFile,pDest,n,offset64){
|
||||
/* int (*xRead)(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst) */
|
||||
mTimeStart('xRead');
|
||||
const f = __openFiles[pFile];
|
||||
let rc;
|
||||
try {
|
||||
rc = opRun('xRead',pFile, n, Number(offset64));
|
||||
if(0===rc || capi.SQLITE_IOERR_SHORT_READ===rc){
|
||||
// set() seems to be the fastest way to copy this...
|
||||
if(0===rc || capi.SQLITE_IOERR_SHORT_READ===rc){
|
||||
/**
|
||||
Results get written to the SharedArrayBuffer f.sabView.
|
||||
Because the heap is _not_ a SharedArrayBuffer, we have
|
||||
to copy the results. TypedArray.set() seems to be the
|
||||
fastest way to copy this. */
|
||||
wasm.heap8u().set(f.sabView.subarray(0, n), pDest);
|
||||
}
|
||||
}catch(e){
|
||||
@@ -710,7 +743,6 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
return rc;
|
||||
},
|
||||
xWrite: function(pFile,pSrc,n,offset64){
|
||||
/* int (*xWrite)(sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst) */
|
||||
mTimeStart('xWrite');
|
||||
const f = __openFiles[pFile];
|
||||
let rc;
|
||||
@@ -776,28 +808,6 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
//xSleep is optionally defined below
|
||||
xOpen: function f(pVfs, zName, pFile, flags, pOutFlags){
|
||||
mTimeStart('xOpen');
|
||||
if(!f._){
|
||||
f._ = {
|
||||
fileTypes: {
|
||||
SQLITE_OPEN_MAIN_DB: 'mainDb',
|
||||
SQLITE_OPEN_MAIN_JOURNAL: 'mainJournal',
|
||||
SQLITE_OPEN_TEMP_DB: 'tempDb',
|
||||
SQLITE_OPEN_TEMP_JOURNAL: 'tempJournal',
|
||||
SQLITE_OPEN_TRANSIENT_DB: 'transientDb',
|
||||
SQLITE_OPEN_SUBJOURNAL: 'subjournal',
|
||||
SQLITE_OPEN_SUPER_JOURNAL: 'superJournal',
|
||||
SQLITE_OPEN_WAL: 'wal'
|
||||
},
|
||||
getFileType: function(filename,oflags){
|
||||
const ft = f._.fileTypes;
|
||||
for(let k of Object.keys(ft)){
|
||||
if(oflags & capi[k]) return ft[k];
|
||||
}
|
||||
warn("Cannot determine fileType based on xOpen() flags for file",filename);
|
||||
return '???';
|
||||
}
|
||||
};
|
||||
}
|
||||
if(0===zName){
|
||||
zName = randomFilename();
|
||||
}else if('number'===typeof zName){
|
||||
@@ -1081,20 +1091,26 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
promiseReject(e);
|
||||
error("Unexpected message from the async worker:",data);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
}/*switch(data.type)*/
|
||||
}/*W.onmessage()*/;
|
||||
})/*thePromise*/;
|
||||
return thePromise;
|
||||
}/*installOpfsVfs()*/;
|
||||
installOpfsVfs.defaultProxyUri =
|
||||
//self.location.pathname.replace(/[^/]*$/, "sqlite3-opfs-async-proxy.js");
|
||||
"sqlite3-opfs-async-proxy.js";
|
||||
//console.warn("sqlite3.installOpfsVfs.defaultProxyUri =",sqlite3.installOpfsVfs.defaultProxyUri);
|
||||
self.sqlite3ApiBootstrap.initializersAsync.push(async (sqlite3)=>{
|
||||
if(sqlite3.scriptInfo && !sqlite3.scriptInfo.isWorker){
|
||||
return;
|
||||
}
|
||||
try{
|
||||
let proxyJs = installOpfsVfs.defaultProxyUri;
|
||||
if(sqlite3.scriptInfo.sqlite3Dir){
|
||||
installOpfsVfs.defaultProxyUri =
|
||||
sqlite3.scriptInfo.sqlite3Dir + proxyJs;
|
||||
//console.warn("installOpfsVfs.defaultProxyUri =",installOpfsVfs.defaultProxyUri);
|
||||
}
|
||||
return installOpfsVfs().catch((e)=>{
|
||||
console.warn("Ignoring inability to install OPFS sqlite3_vfs:",e);
|
||||
console.warn("Ignoring inability to install OPFS sqlite3_vfs:",e.message);
|
||||
});
|
||||
}catch(e){
|
||||
console.error("installOpfsVfs() exception:",e);
|
||||
|
||||
@@ -280,8 +280,16 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
this.name = 'WasmAllocError';
|
||||
}
|
||||
};
|
||||
/**
|
||||
Functionally equivalent to the WasmAllocError constructor but may
|
||||
be used as part of an expression, e.g.:
|
||||
|
||||
```
|
||||
return someAllocatingFunction(x) || WasmAllocError.toss(...);
|
||||
```
|
||||
*/
|
||||
WasmAllocError.toss = (...args)=>{
|
||||
throw new WasmAllocError(args.join(' '));
|
||||
throw new WasmAllocError(...args);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -508,6 +516,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
"flexible-string" argument converter.
|
||||
*/
|
||||
sqlite3_exec: (pDb, sql, callback, pVoid, pErrMsg)=>{}/*installed later*/,
|
||||
|
||||
/**
|
||||
Various internal-use utilities are added here as needed. They
|
||||
are bound to an object only so that we have access to them in
|
||||
@@ -521,9 +530,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
isBindableTypedArray,
|
||||
isInt32, isSQLableTypedArray, isTypedArray,
|
||||
typedArrayToString,
|
||||
isMainWindow: ()=>{
|
||||
return self.window===self && self.document;
|
||||
}
|
||||
isUIThread: ()=>'undefined'===typeof WorkerGlobalScope
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -830,7 +837,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
["sqlite3_value_text", "string", "sqlite3_value*"],
|
||||
["sqlite3_value_type", "int", "sqlite3_value*"],
|
||||
["sqlite3_vfs_find", "*", "string"],
|
||||
["sqlite3_vfs_register", "int", "*", "int"]
|
||||
["sqlite3_vfs_register", "int", "sqlite3_vfs*", "int"],
|
||||
["sqlite3_vfs_unregister", "int", "sqlite3_vfs*"]
|
||||
]/*wasm.bindingSignatures*/;
|
||||
|
||||
if(false && wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){
|
||||
@@ -861,13 +869,12 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
/**
|
||||
Functions which are intended solely for API-internal use by the
|
||||
WASM components, not client code. These get installed into
|
||||
wasm.
|
||||
|
||||
TODO: get rid of sqlite3_wasm_vfs_unlink(). It is ill-conceived
|
||||
and only rarely actually useful.
|
||||
capi.wasm.
|
||||
*/
|
||||
wasm.bindingSignatures.wasm = [
|
||||
["sqlite3_wasm_vfs_unlink", "int", "string"]
|
||||
["sqlite3_wasm_db_reset", "int", "sqlite3*"],
|
||||
["sqlite3_wasm_db_vfs", "sqlite3_vfs*", "sqlite3*","string"],
|
||||
["sqlite3_wasm_vfs_unlink", "int", "sqlite3_vfs*","string"]
|
||||
];
|
||||
|
||||
|
||||
@@ -904,8 +911,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
*/
|
||||
wasm.pstack = Object.assign(Object.create(null),{
|
||||
/**
|
||||
Sets the current ppstack position to the given pointer.
|
||||
Results are undefined if the passed-in value did not come from
|
||||
Sets the current pstack position to the given pointer. Results
|
||||
are undefined if the passed-in value did not come from
|
||||
this.pointer.
|
||||
*/
|
||||
restore: wasm.exports.sqlite3_wasm_pstack_restore,
|
||||
@@ -919,7 +926,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
This method always adjusts the given value to be a multiple
|
||||
of 8 bytes because failing to do so can lead to incorrect
|
||||
results when reading and writing 64-bit values from/to the WASM
|
||||
heap.
|
||||
heap. Similarly, the returned address is always 8-byte aligned.
|
||||
*/
|
||||
alloc: (n)=>{
|
||||
return wasm.exports.sqlite3_wasm_pstack_alloc(n)
|
||||
@@ -927,7 +934,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
"bytes from the pstack.");
|
||||
},
|
||||
/**
|
||||
Allocates n chunks, each sz bytes, as a single memory block and
|
||||
alloc()'s n chunks, each sz bytes, as a single memory block and
|
||||
returns the addresses as an array of n element, each holding
|
||||
the address of one chunk.
|
||||
|
||||
@@ -965,7 +972,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
will corrupt or read neighboring memory.
|
||||
|
||||
However, when all pointers involved point to "small" data, it
|
||||
is safe to pass a falsy value to save to memory.
|
||||
is safe to pass a falsy value to save a tiny bit of memory.
|
||||
*/
|
||||
allocPtr: (n=1,safePtrSize=true)=>{
|
||||
return 1===n
|
||||
@@ -1018,15 +1025,31 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
class SQLite3Error extends Error {
|
||||
/**
|
||||
Constructs this object with a message equal to all arguments
|
||||
concatenated with a space between each one.
|
||||
concatenated with a space between each one. As a special case,
|
||||
if it's passed only a single integer argument, the string form
|
||||
of that argument is the result of
|
||||
sqlite3.capi.sqlite3_js_rc_str() or (if that returns falsy), a
|
||||
synthesized string which contains that integer.
|
||||
*/
|
||||
constructor(...args){
|
||||
super(args.join(' '));
|
||||
if(1===args.length && 'number'===typeof args[0] && args[0]===(args[0] | 0)){
|
||||
super(capi.sqlite3_js_rc_str(args[0]) || ("Unknown result code #"+args[0]));
|
||||
}else{
|
||||
super(args.join(' '));
|
||||
}
|
||||
this.name = 'SQLite3Error';
|
||||
}
|
||||
};
|
||||
/**
|
||||
Functionally equivalent to the SQLite3Error constructor but may
|
||||
be used as part of an expression, e.g.:
|
||||
|
||||
```
|
||||
return someFunction(x) || SQLite3Error.toss(...);
|
||||
```
|
||||
*/
|
||||
SQLite3Error.toss = (...args)=>{
|
||||
throw new SQLite3Error(args.join(' '));
|
||||
throw new SQLite3Error(...args);
|
||||
};
|
||||
|
||||
/** State for sqlite3_wasmfs_opfs_dir(). */
|
||||
@@ -1074,12 +1097,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
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.
|
||||
|
||||
Potential (but arguable) TODO: return true if the name is one of
|
||||
(":localStorage:", "local", ":sessionStorage:", "session") and
|
||||
kvvfs is available.
|
||||
*/
|
||||
capi.sqlite3_web_filename_is_persistent = function(name){
|
||||
capi.sqlite3_wasmfs_filename_is_persistent = function(name){
|
||||
const p = capi.sqlite3_wasmfs_opfs_dir();
|
||||
return (p && name) ? name.startsWith(p+'/') : false;
|
||||
};
|
||||
@@ -1101,8 +1120,10 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
pointer. The 3rd argument specifies the database name of the
|
||||
given database connection to check, defaulting to the main db.
|
||||
|
||||
The 2nd and 3rd arguments may either be a JS string or a C-string
|
||||
allocated from the wasm environment.
|
||||
The 2nd and 3rd arguments may either be a JS string or a WASM
|
||||
C-string. If the 2nd argument is a NULL WASM pointer, the default
|
||||
VFS is assumed. If the 3rd is a NULL WASM pointer, "main" is
|
||||
assumed.
|
||||
|
||||
The truthy value it returns is a pointer to the `sqlite3_vfs`
|
||||
object.
|
||||
@@ -1112,22 +1133,14 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
bad arguments cause a conversion error when passing into
|
||||
wasm-space, false is returned.
|
||||
*/
|
||||
capi.sqlite3_web_db_uses_vfs = function(pDb,vfsName,dbName="main"){
|
||||
capi.sqlite3_js_db_uses_vfs = function(pDb,vfsName,dbName="main"){
|
||||
try{
|
||||
const pK = capi.sqlite3_vfs_find(vfsName);
|
||||
if(!pK) return false;
|
||||
else if(!pDb){
|
||||
return capi.sqlite3_vfs_find(0)===pK ? pK : false;
|
||||
}
|
||||
const ppVfs = wasm.allocPtr();
|
||||
try{
|
||||
return (
|
||||
(0===capi.sqlite3_file_control(
|
||||
pDb, dbName, capi.SQLITE_FCNTL_VFS_POINTER, ppVfs
|
||||
)) && (wasm.getPtrValue(ppVfs) === pK)
|
||||
) ? pK : false;
|
||||
}finally{
|
||||
wasm.dealloc(ppVfs);
|
||||
return pK===capi.sqlite3_vfs_find(0) ? pK : false;
|
||||
}else{
|
||||
return pK===capi.sqlite3_js_db_vfs(pDb) ? pK : false;
|
||||
}
|
||||
}catch(e){
|
||||
/* Ignore - probably bad args to a wasm-bound function. */
|
||||
@@ -1139,7 +1152,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
Returns an array of the names of all currently-registered sqlite3
|
||||
VFSes.
|
||||
*/
|
||||
capi.sqlite3_web_vfs_list = function(){
|
||||
capi.sqlite3_js_vfs_list = function(){
|
||||
const rc = [];
|
||||
let pVfs = capi.sqlite3_vfs_find(0);
|
||||
while(pVfs){
|
||||
@@ -1156,9 +1169,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
sqlite3_serialize(). On success it returns a Uint8Array. On
|
||||
error it throws with a description of the problem.
|
||||
*/
|
||||
capi.sqlite3_web_db_export = function(pDb){
|
||||
capi.sqlite3_js_db_export = function(pDb){
|
||||
if(!pDb) toss('Invalid sqlite3* argument.');
|
||||
const wasm = wasm;
|
||||
if(!wasm.bigIntEnabled) toss('BigInt64 support is not enabled.');
|
||||
const stack = wasm.pstack.pointer;
|
||||
let pOut;
|
||||
@@ -1177,7 +1189,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
);
|
||||
if(rc){
|
||||
toss("Database serialization failed with code",
|
||||
sqlite3.capi.sqlite3_web_rc_str(rc));
|
||||
sqlite3.capi.sqlite3_js_rc_str(rc));
|
||||
}
|
||||
pOut = wasm.getPtrValue(ppOut);
|
||||
const nOut = wasm.getMemValue(pSize, 'i64');
|
||||
@@ -1185,20 +1197,40 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
? wasm.heap8u().slice(pOut, pOut + Number(nOut))
|
||||
: new Uint8Array();
|
||||
return rc;
|
||||
}catch(e){
|
||||
console.error('internal error?',e);
|
||||
throw w;
|
||||
}finally{
|
||||
if(pOut) wasm.exports.sqlite3_free(pOut);
|
||||
wasm.pstack.restore(stack);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
Given a `sqlite3*` and a database name (JS string or WASM
|
||||
C-string pointer, which may be 0), returns a pointer to the
|
||||
sqlite3_vfs responsible for it. If the given db name is null/0,
|
||||
or not provided, then "main" is assumed.
|
||||
*/
|
||||
capi.sqlite3_js_db_vfs =
|
||||
(dbPointer, dbName=0)=>wasm.sqlite3_wasm_db_vfs(dbPointer, dbName);
|
||||
|
||||
/**
|
||||
A thin wrapper around capi.sqlite3_aggregate_context() which
|
||||
behaves the same except that it throws a WasmAllocError if that
|
||||
function returns 0. As a special case, if n is falsy it does
|
||||
_not_ throw if that function returns 0. That special case is
|
||||
intended for use with xFinal() implementations.
|
||||
*/
|
||||
capi.sqlite3_js_aggregate_context = (pCtx, n)=>{
|
||||
return capi.sqlite3_aggregate_context(pCtx, n)
|
||||
|| (n ? WasmAllocError.toss("Cannot allocate",n,
|
||||
"bytes for sqlite3_aggregate_context()")
|
||||
: 0);
|
||||
};
|
||||
|
||||
if( capi.util.isMainWindow() ){
|
||||
if( capi.util.isUIThread() ){
|
||||
/* Features specific to the main window thread... */
|
||||
|
||||
/**
|
||||
Internal helper for sqlite3_web_kvvfs_clear() and friends.
|
||||
Internal helper for sqlite3_js_kvvfs_clear() and friends.
|
||||
Its argument should be one of ('local','session','').
|
||||
*/
|
||||
const __kvvfsInfo = function(which){
|
||||
@@ -1223,7 +1255,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
|
||||
Returns the number of entries cleared.
|
||||
*/
|
||||
capi.sqlite3_web_kvvfs_clear = function(which=''){
|
||||
capi.sqlite3_js_kvvfs_clear = function(which=''){
|
||||
let rc = 0;
|
||||
const kvinfo = __kvvfsInfo(which);
|
||||
kvinfo.stores.forEach((s)=>{
|
||||
@@ -1256,7 +1288,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
those limits are unspecified and may include per-entry
|
||||
overhead invisible to clients.
|
||||
*/
|
||||
capi.sqlite3_web_kvvfs_size = function(which=''){
|
||||
capi.sqlite3_js_kvvfs_size = function(which=''){
|
||||
let sz = 0;
|
||||
const kvinfo = __kvvfsInfo(which);
|
||||
kvinfo.stores.forEach((s)=>{
|
||||
@@ -1281,6 +1313,17 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
SQLite3Error: SQLite3Error,
|
||||
capi,
|
||||
config,
|
||||
/**
|
||||
Holds the version info of the sqlite3 source tree from which
|
||||
the generated sqlite3-api.js gets built. Note that its version
|
||||
may well differ from that reported by sqlite3_libversion(), but
|
||||
that should be considered a source file mismatch, as the JS and
|
||||
WASM files are intended to be built and distributed together.
|
||||
|
||||
This object is initially a placeholder which gets replaced by a
|
||||
build-generated object.
|
||||
*/
|
||||
version: Object.create(null),
|
||||
/**
|
||||
Performs any optional asynchronous library-level initialization
|
||||
which might be required. This function returns a Promise which
|
||||
@@ -1324,7 +1367,20 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
//while(lip.length) p = p.then(lip.shift());
|
||||
//return p.then(()=>sqlite3);
|
||||
return Promise.all(lip).then(()=>sqlite3);
|
||||
}
|
||||
},
|
||||
/**
|
||||
scriptInfo ideally gets injected into this object by the
|
||||
infrastructure which assembles the JS/WASM module. It contains
|
||||
state which must be collected before sqlite3ApiBootstrap() can
|
||||
be declared. It is not necessarily available to any
|
||||
sqlite3ApiBootstrap.initializers but "should" be in place (if
|
||||
it's added at all) by the time that
|
||||
sqlite3ApiBootstrap.initializersAsync is processed.
|
||||
|
||||
This state is not part of the public API, only intended for use
|
||||
with the sqlite3 API bootstrapping and wasm-loading process.
|
||||
*/
|
||||
scriptInfo: undefined
|
||||
};
|
||||
try{
|
||||
sqlite3ApiBootstrap.initializers.forEach((f)=>{
|
||||
@@ -1400,3 +1456,4 @@ self.sqlite3ApiBootstrap.defaultConfig = Object.create(null);
|
||||
value which will be stored here.
|
||||
*/
|
||||
self.sqlite3ApiBootstrap.sqlite3 = undefined;
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
|
||||
```
|
||||
{
|
||||
type: 'error',
|
||||
type: "error",
|
||||
|
||||
messageId: ...as above...,
|
||||
|
||||
@@ -150,7 +150,7 @@
|
||||
|
||||
```
|
||||
{
|
||||
type: 'config',
|
||||
type: "config-get",
|
||||
messageId: ...as above...,
|
||||
result: {
|
||||
|
||||
@@ -167,7 +167,7 @@
|
||||
the non-WASMFS OPFS VFS to open a database via a URI-style
|
||||
db filename.
|
||||
|
||||
vfses: result of sqlite3.capi.sqlite3_web_vfs_list()
|
||||
vfsList: result of sqlite3.capi.sqlite3_js_vfs_list()
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -196,7 +196,7 @@
|
||||
|
||||
```
|
||||
{
|
||||
type: 'open',
|
||||
type: "open",
|
||||
messageId: ...as above...,
|
||||
result: {
|
||||
filename: db filename, possibly differing from the input.
|
||||
@@ -205,7 +205,7 @@
|
||||
envelope to other calls in this API to tell them which db to
|
||||
use. If it is not provided to future calls, they will default to
|
||||
operating on the first-opened db. This property is, for API
|
||||
consistency's sake, also part of the contaning message envelope.
|
||||
consistency's sake, also part of the containing message envelope.
|
||||
Only the `open` operation includes it in the `result` property.
|
||||
|
||||
persistent: true if the given filename resides in the
|
||||
@@ -225,19 +225,21 @@
|
||||
type: "close",
|
||||
messageId: ...as above...
|
||||
dbId: ...as above...
|
||||
args: none
|
||||
args: OPTIONAL {unlink: boolean}
|
||||
}
|
||||
```
|
||||
|
||||
If the dbId does not refer to an opened ID, this is a no-op. The
|
||||
inability to close a db (because it's not opened) or delete its
|
||||
file does not trigger an error.
|
||||
If the `dbId` does not refer to an opened ID, this is a no-op. If
|
||||
the `args` object contains a truthy `unlink` value then the database
|
||||
will be unlinked (deleted) after closing it. The inability to close a
|
||||
db (because it's not opened) or delete its file does not trigger an
|
||||
error.
|
||||
|
||||
Response:
|
||||
|
||||
```
|
||||
{
|
||||
type: 'close',
|
||||
type: "close",
|
||||
messageId: ...as above...,
|
||||
result: {
|
||||
|
||||
@@ -269,7 +271,7 @@
|
||||
|
||||
```
|
||||
{
|
||||
type: 'exec',
|
||||
type: "exec",
|
||||
messageId: ...as above...,
|
||||
dbId: ...as above...
|
||||
result: {
|
||||
@@ -365,14 +367,11 @@ sqlite3.initWorker1API = function(){
|
||||
if(db){
|
||||
delete this.dbs[getDbId(db)];
|
||||
const filename = db.getFilename();
|
||||
const pVfs = sqlite3.capi.wasm.sqlite3_wasm_db_vfs(db.pointer, 0);
|
||||
db.close();
|
||||
if(db===this.defaultDb) this.defaultDb = undefined;
|
||||
if(alsoUnlink && filename){
|
||||
/* This isn't necessarily correct: the db might be using a
|
||||
VFS other than the default. How do we best resolve this
|
||||
without having to special-case the kvvfs and opfs
|
||||
VFSes? */
|
||||
sqlite3.capi.wasm.sqlite3_wasm_vfs_unlink(filename);
|
||||
if(alsoUnlink && filename && pVfs){
|
||||
sqlite3.capi.wasm.sqlite3_wasm_vfs_unlink(pVfs, filename);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -435,15 +434,13 @@ sqlite3.initWorker1API = function(){
|
||||
const pDir = sqlite3.capi.sqlite3_wasmfs_opfs_dir();
|
||||
if(!args.filename || ':memory:'===args.filename){
|
||||
oargs.filename = args.filename || '';
|
||||
}else if(pDir){
|
||||
oargs.filename = pDir + ('/'===args.filename[0] ? args.filename : ('/'+args.filename));
|
||||
}else{
|
||||
oargs.filename = args.filename;
|
||||
}
|
||||
const db = wState.open(oargs);
|
||||
rc.filename = db.filename;
|
||||
rc.persistent = (!!pDir && db.filename.startsWith(pDir))
|
||||
|| sqlite3.capi.sqlite3_web_db_uses_vfs(db.pointer, "opfs");
|
||||
rc.persistent = (!!pDir && db.filename.startsWith(pDir+'/'))
|
||||
|| sqlite3.capi.sqlite3_js_db_uses_vfs(db.pointer, "opfs");
|
||||
rc.dbId = getDbId(db);
|
||||
return rc;
|
||||
},
|
||||
@@ -524,7 +521,7 @@ sqlite3.initWorker1API = function(){
|
||||
});
|
||||
rc.wasmfsOpfsEnabled = !!sqlite3.capi.sqlite3_wasmfs_opfs_dir();
|
||||
rc.version = sqlite3.version;
|
||||
rc.vfses = sqlite3.capi.sqlite3_web_vfs_list();
|
||||
rc.vfsList = sqlite3.capi.sqlite3_js_vfs_list();
|
||||
return rc;
|
||||
},
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
** LICENSE for the sqlite3 WebAssembly/JavaScript APIs.
|
||||
**
|
||||
** This bundle (typically released as sqlite3.js or sqlite3-wasmfs.js)
|
||||
** is an amalgamation of JavaScript source code from two projects:
|
||||
**
|
||||
** 1) https://emscripten.org: the Emscripten "glue code" is covered by
|
||||
** the terms of the MIT license and University of Illinois/NCSA
|
||||
** Open Source License, as described at:
|
||||
**
|
||||
** https://emscripten.org/docs/introducing_emscripten/emscripten_license.html
|
||||
**
|
||||
** 2) https://sqlite.org: all code and documentation labeled as being
|
||||
** from this source are released under the same terms as the sqlite3
|
||||
** C library:
|
||||
**
|
||||
** 2022-10-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.
|
||||
*/
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
***********************************************************************
|
||||
|
||||
An Worker which manages asynchronous OPFS handles on behalf of a
|
||||
A Worker which manages asynchronous OPFS handles on behalf of a
|
||||
synchronous API which controls it via a combination of Worker
|
||||
messages, SharedArrayBuffer, and Atomics. It is the asynchronous
|
||||
counterpart of the API defined in sqlite3-api-opfs.js.
|
||||
@@ -25,8 +25,12 @@
|
||||
access to the sqlite3 JS/WASM bits, so any bits which it needs (most
|
||||
notably SQLITE_xxx integer codes) have to be imported into it via an
|
||||
initialization process.
|
||||
|
||||
This file represents an implementation detail of a larger piece of
|
||||
code, and not a public interface. Its details may change at any time
|
||||
and are not intended to be used by any client-level code.
|
||||
*/
|
||||
'use strict';
|
||||
"use strict";
|
||||
const toss = function(...args){throw new Error(args.join(' '))};
|
||||
if(self.window === self){
|
||||
toss("This code cannot run from the main thread.",
|
||||
@@ -133,8 +137,8 @@ const getDirForFilename = async function f(absFilename, createDirs = false){
|
||||
|
||||
/**
|
||||
Returns the sync access handle associated with the given file
|
||||
handle object (which must be a valid handle object), lazily opening
|
||||
it if needed.
|
||||
handle object (which must be a valid handle object, as created by
|
||||
xOpen()), lazily opening it if needed.
|
||||
|
||||
In order to help alleviate cross-tab contention for a dabase,
|
||||
if an exception is thrown while acquiring the handle, this routine
|
||||
@@ -150,7 +154,7 @@ const getSyncHandle = async (fh)=>{
|
||||
let i = 1, ms = 300;
|
||||
for(; true; ms *= ++i){
|
||||
try {
|
||||
//if(1===i) toss("Just testing.");
|
||||
//if(i<3) toss("Just testing.");
|
||||
//TODO? A config option which tells it to throw here
|
||||
//randomly every now and then, for testing purposes.
|
||||
fh.syncHandle = await fh.fileHandle.createSyncAccessHandle();
|
||||
@@ -163,7 +167,7 @@ const getSyncHandle = async (fh)=>{
|
||||
}
|
||||
warn("Error getting sync handle. Waiting",ms,
|
||||
"ms and trying again.",fh.filenameAbs,e);
|
||||
Atomics.wait(state.sabOPView, state.opIds.xSleep, 0, ms);
|
||||
Atomics.wait(state.sabOPView, state.opIds.retry, 0, ms);
|
||||
}
|
||||
}
|
||||
log("Got sync handle for",fh.filenameAbs,'in',performance.now() - t,'ms');
|
||||
@@ -305,7 +309,7 @@ const vfsAsyncImpls = {
|
||||
storeAndNotify('xAccess', rc);
|
||||
mTimeEnd();
|
||||
},
|
||||
xClose: async function(fid){
|
||||
xClose: async function(fid/*sqlite3_file pointer*/){
|
||||
const opName = 'xClose';
|
||||
mTimeStart(opName);
|
||||
const fh = __openFiles[fid];
|
||||
@@ -364,7 +368,7 @@ const vfsAsyncImpls = {
|
||||
wTimeEnd();
|
||||
return rc;
|
||||
},
|
||||
xFileSize: async function(fid){
|
||||
xFileSize: async function(fid/*sqlite3_file pointer*/){
|
||||
mTimeStart('xFileSize');
|
||||
const fh = __openFiles[fid];
|
||||
let sz;
|
||||
@@ -381,7 +385,8 @@ const vfsAsyncImpls = {
|
||||
storeAndNotify('xFileSize', sz);
|
||||
mTimeEnd();
|
||||
},
|
||||
xLock: async function(fid,lockType){
|
||||
xLock: async function(fid/*sqlite3_file pointer*/,
|
||||
lockType/*SQLITE_LOCK_...*/){
|
||||
mTimeStart('xLock');
|
||||
const fh = __openFiles[fid];
|
||||
let rc = 0;
|
||||
@@ -397,7 +402,8 @@ const vfsAsyncImpls = {
|
||||
storeAndNotify('xLock',rc);
|
||||
mTimeEnd();
|
||||
},
|
||||
xOpen: async function(fid/*sqlite3_file pointer*/, filename, flags){
|
||||
xOpen: async function(fid/*sqlite3_file pointer*/, filename,
|
||||
flags/*SQLITE_OPEN_...*/){
|
||||
const opName = 'xOpen';
|
||||
mTimeStart(opName);
|
||||
const deleteOnClose = (state.sq3Codes.SQLITE_OPEN_DELETEONCLOSE & flags);
|
||||
@@ -440,7 +446,7 @@ const vfsAsyncImpls = {
|
||||
}
|
||||
mTimeEnd();
|
||||
},
|
||||
xRead: async function(fid,n,offset){
|
||||
xRead: async function(fid/*sqlite3_file pointer*/,n,offset64){
|
||||
mTimeStart('xRead');
|
||||
let rc = 0, nRead;
|
||||
const fh = __openFiles[fid];
|
||||
@@ -448,7 +454,7 @@ const vfsAsyncImpls = {
|
||||
wTimeStart('xRead');
|
||||
nRead = (await getSyncHandle(fh)).read(
|
||||
fh.sabView.subarray(0, n),
|
||||
{at: Number(offset)}
|
||||
{at: Number(offset64)}
|
||||
);
|
||||
wTimeEnd();
|
||||
if(nRead < n){/* Zero-fill remaining bytes */
|
||||
@@ -464,7 +470,7 @@ const vfsAsyncImpls = {
|
||||
storeAndNotify('xRead',rc);
|
||||
mTimeEnd();
|
||||
},
|
||||
xSync: async function(fid,flags/*ignored*/){
|
||||
xSync: async function(fid/*sqlite3_file pointer*/,flags/*ignored*/){
|
||||
mTimeStart('xSync');
|
||||
const fh = __openFiles[fid];
|
||||
let rc = 0;
|
||||
@@ -480,7 +486,7 @@ const vfsAsyncImpls = {
|
||||
storeAndNotify('xSync',rc);
|
||||
mTimeEnd();
|
||||
},
|
||||
xTruncate: async function(fid,size){
|
||||
xTruncate: async function(fid/*sqlite3_file pointer*/,size){
|
||||
mTimeStart('xTruncate');
|
||||
let rc = 0;
|
||||
const fh = __openFiles[fid];
|
||||
@@ -497,7 +503,8 @@ const vfsAsyncImpls = {
|
||||
storeAndNotify('xTruncate',rc);
|
||||
mTimeEnd();
|
||||
},
|
||||
xUnlock: async function(fid,lockType){
|
||||
xUnlock: async function(fid/*sqlite3_file pointer*/,
|
||||
lockType/*SQLITE_LOCK_...*/){
|
||||
mTimeStart('xUnlock');
|
||||
let rc = 0;
|
||||
const fh = __openFiles[fid];
|
||||
@@ -514,7 +521,7 @@ const vfsAsyncImpls = {
|
||||
storeAndNotify('xUnlock',rc);
|
||||
mTimeEnd();
|
||||
},
|
||||
xWrite: async function(fid,n,offset){
|
||||
xWrite: async function(fid/*sqlite3_file pointer*/,n,offset64){
|
||||
mTimeStart('xWrite');
|
||||
let rc;
|
||||
wTimeStart('xWrite');
|
||||
@@ -524,7 +531,7 @@ const vfsAsyncImpls = {
|
||||
rc = (
|
||||
n === (await getSyncHandle(fh))
|
||||
.write(fh.sabView.subarray(0, n),
|
||||
{at: Number(offset)})
|
||||
{at: Number(offset64)})
|
||||
) ? 0 : state.sq3Codes.SQLITE_IOERR_WRITE;
|
||||
}catch(e){
|
||||
error("xWrite():",e,fh);
|
||||
+28
-15
@@ -48,6 +48,7 @@
|
||||
** want undefined. Please keep these alphabetized.
|
||||
*/
|
||||
#undef SQLITE_OMIT_DESERIALIZE
|
||||
#undef SQLITE_OMIT_MEMORYDB
|
||||
|
||||
/*
|
||||
** Define any SQLITE_... config defaults we want if they aren't
|
||||
@@ -55,7 +56,7 @@
|
||||
*/
|
||||
|
||||
/**********************************************************************/
|
||||
/* SQLITE_DEFAULT_... */
|
||||
/* SQLITE_D... */
|
||||
#ifndef SQLITE_DEFAULT_CACHE_SIZE
|
||||
/*
|
||||
** The OPFS impls benefit tremendously from an increased cache size
|
||||
@@ -74,6 +75,8 @@
|
||||
#ifndef SQLITE_DEFAULT_UNIX_VFS
|
||||
# define SQLITE_DEFAULT_UNIX_VFS "unix-none"
|
||||
#endif
|
||||
#undef SQLITE_DQS
|
||||
#define SQLITE_DQS 0
|
||||
|
||||
/**********************************************************************/
|
||||
/* SQLITE_ENABLE_... */
|
||||
@@ -809,28 +812,38 @@ const char * sqlite3_wasm_enum_json(void){
|
||||
** This function is NOT part of the sqlite3 public API. It is strictly
|
||||
** for use by the sqlite project's own JS/WASM bindings.
|
||||
**
|
||||
** Do not use this function, even for internal use: it was
|
||||
** ill-conceived and will be removed once the JS code which still
|
||||
** calls it has been weeded out.
|
||||
**
|
||||
** This function invokes the xDelete method of the default VFS,
|
||||
** passing on the given filename. If zName is NULL, no default VFS is
|
||||
** found, or it has no xDelete method, SQLITE_MISUSE is returned, else
|
||||
** the result of the xDelete() call is returned.
|
||||
** This function invokes the xDelete method of the given VFS (or the
|
||||
** default VFS if pVfs is NULL), passing on the given filename. If
|
||||
** zName is NULL, no default VFS is found, or it has no xDelete
|
||||
** method, SQLITE_MISUSE is returned, else the result of the xDelete()
|
||||
** call is returned.
|
||||
*/
|
||||
SQLITE_WASM_KEEP
|
||||
int sqlite3_wasm_vfs_unlink(const char * zName){
|
||||
int sqlite3_wasm_vfs_unlink(sqlite3_vfs *pVfs, const char * zName){
|
||||
int rc = SQLITE_MISUSE /* ??? */;
|
||||
sqlite3_vfs * const pVfs = sqlite3_vfs_find(0);
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
emscripten_console_warn("sqlite3_wasm_vfs_unlink() will be removed.");
|
||||
#endif
|
||||
if( 0==pVfs && 0!=zName ) pVfs = sqlite3_vfs_find(0);
|
||||
if( zName && pVfs && pVfs->xDelete ){
|
||||
rc = pVfs->xDelete(pVfs, zName, 1);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is NOT part of the sqlite3 public API. It is strictly
|
||||
** for use by the sqlite project's own JS/WASM bindings.
|
||||
**
|
||||
** Returns a pointer to the given DB's VFS for the given DB name,
|
||||
** defaulting to "main" if zDbName is 0. Returns 0 if no db with the
|
||||
** given name is open.
|
||||
*/
|
||||
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",
|
||||
SQLITE_FCNTL_VFS_POINTER, &pVfs);
|
||||
return pVfs;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is NOT part of the sqlite3 public API. It is strictly
|
||||
** for use by the sqlite project's own JS/WASM bindings.
|
||||
@@ -1007,7 +1020,7 @@ int sqlite3_wasm_init_wasmfs(const char *zMountPoint){
|
||||
hypothetically suffice for the transient wasm-based virtual
|
||||
filesystem we're currently running in. */
|
||||
const int rc = wasmfs_create_directory(zMountPoint, 0777, pOpfs);
|
||||
emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);
|
||||
/*emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);*/
|
||||
if(rc) return SQLITE_IOERR;
|
||||
}
|
||||
return pOpfs ? 0 : SQLITE_NOMEM;
|
||||
|
||||
@@ -70,8 +70,8 @@
|
||||
message. The second expects an object in the form {type:...,
|
||||
args:...} plus any other properties the client cares to set. This
|
||||
function will always set the `messageId` property on the object,
|
||||
even if it's already set, and will set the `dbId` property to
|
||||
`config.dbId` if it is _not_ set in the message object.
|
||||
even if it's already set, and will set the `dbId` property to the
|
||||
current database ID if it is _not_ set in the message object.
|
||||
|
||||
The function throws on error.
|
||||
|
||||
@@ -237,6 +237,23 @@ self.sqlite3Worker1Promiser = function callee(config = callee.defaultConfig){
|
||||
};
|
||||
}/*sqlite3Worker1Promiser()*/;
|
||||
self.sqlite3Worker1Promiser.defaultConfig = {
|
||||
worker: ()=>new Worker("sqlite3-worker1.js"+self.location.search),
|
||||
worker: function(){
|
||||
let theJs = "sqlite3-worker1.js";
|
||||
if(this.currentScript){
|
||||
const src = this.currentScript.src.split('/');
|
||||
src.pop();
|
||||
theJs = src.join('/')+'/' + theJs;
|
||||
//console.warn("promiser currentScript, theJs =",this.currentScript,theJs);
|
||||
}else{
|
||||
//console.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 + self.location.search);
|
||||
}.bind({
|
||||
currentScript: self?.document?.currentScript
|
||||
}),
|
||||
onerror: (...args)=>console.error('worker1 promiser error',...args)
|
||||
};
|
||||
@@ -25,13 +25,23 @@
|
||||
Worker-specific API needs to pass _this_ file (or equivalent) to the
|
||||
Worker constructor and then listen for an event in the form shown
|
||||
above in order to know when the module has completed initialization.
|
||||
|
||||
This file accepts a URL arguments to adjust how it loads sqlite3.js:
|
||||
|
||||
- `sqlite3.dir`, if set, treats the given directory name as the
|
||||
directory from which `sqlite3.js` will be loaded.
|
||||
|
||||
By default is loads 'sqlite3.js'.
|
||||
*/
|
||||
"use strict";
|
||||
(()=>{
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
importScripts(urlParams.has('wasmfs')
|
||||
? 'sqlite3-wasmfs.js'
|
||||
: 'sqlite3.js');
|
||||
let theJs = 'sqlite3.js';
|
||||
if(urlParams.has('sqlite3.dir')){
|
||||
theJs = urlParams.get('sqlite3.dir') + '/' + theJs;
|
||||
}
|
||||
//console.warn("worker1 theJs =",theJs);
|
||||
importScripts(theJs);
|
||||
sqlite3InitModule().then((sqlite3)=>{
|
||||
sqlite3.capi.sqlite3_wasmfs_opfs_dir();
|
||||
sqlite3.initWorker1API();
|
||||
@@ -69,7 +69,7 @@
|
||||
<label for='cb-reverse-log-order'>Reverse log order (newest first)</label>
|
||||
</span>
|
||||
<div id='test-output'></div>
|
||||
<script src="sqlite3-wasmfs.js"></script>
|
||||
<script src="jswasm/sqlite3.js"></script>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="batch-runner.js"></script>
|
||||
<style>
|
||||
|
||||
@@ -34,11 +34,17 @@ span.labeled-input {
|
||||
color: red;
|
||||
background-color: yellow;
|
||||
}
|
||||
.strong { font-weight: 700 }
|
||||
.warning { color: firebrick; }
|
||||
.green { color: darkgreen; }
|
||||
.faded { opacity: 0.5; }
|
||||
.group-start { color: blue; }
|
||||
.group-end { color: blue; }
|
||||
.input-wrapper { white-space: nowrap; }
|
||||
.input-wrapper {
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
#test-output {
|
||||
border: 1px inset;
|
||||
border-radius: 0.25em;
|
||||
@@ -52,3 +58,4 @@ span.labeled-input {
|
||||
#test-output.reverse {
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
label[for] { cursor: pointer }
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
ln.append(document.createTextNode(args.join(' ')));
|
||||
document.body.append(ln);
|
||||
};
|
||||
const w = new Worker("demo-123.js");
|
||||
const w = new Worker("demo-123.js?sqlite3.dir=jswasm"
|
||||
/* Note the URL argument on that name. See
|
||||
the notes in demo-123.js (search for
|
||||
"importScripts") for why we need
|
||||
that. */);
|
||||
w.onmessage = function({data}){
|
||||
switch(data.type){
|
||||
case 'log':
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>1-2-sqlite3 demo</h1>
|
||||
<script src="sqlite3.js"></script>
|
||||
<script src="jswasm/sqlite3.js"></script>
|
||||
<script src="demo-123.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+21
-2
@@ -160,7 +160,7 @@
|
||||
log("Create a scalar UDF...");
|
||||
db.createFunction({
|
||||
name: 'twice',
|
||||
callback: function(pCx, arg){ // note the call arg count
|
||||
xFunc: function(pCx, arg){ // note the call arg count
|
||||
return arg + arg;
|
||||
}
|
||||
});
|
||||
@@ -251,7 +251,26 @@
|
||||
|
||||
log("Loading and initializing sqlite3 module...");
|
||||
if(self.window!==self) /*worker thread*/{
|
||||
importScripts("sqlite3.js");
|
||||
/*
|
||||
If sqlite3.js is in a directory other than this script, in order
|
||||
to get sqlite3.js to resolve sqlite3.wasm properly, we have to
|
||||
explicitly tell it where sqlite3.js is being loaded from. We do
|
||||
that by passing the `sqlite3.dir=theDirName` URL argument to
|
||||
_this_ script. That URL argument will be seen by the JS/WASM
|
||||
loader and it will adjust the sqlite3.wasm path accordingly. If
|
||||
sqlite3.js/.wasm are in the same directory as this script then
|
||||
that's not needed.
|
||||
|
||||
URL arguments passed as part of the filename via importScripts()
|
||||
are simply lost, and such scripts see the self.location of
|
||||
_this_ script.
|
||||
*/
|
||||
let sqlite3Js = 'sqlite3.js';
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
if(urlParams.has('sqlite3.dir')){
|
||||
sqlite3Js = urlParams.get('sqlite3.dir') + '/' + sqlite3Js;
|
||||
}
|
||||
importScripts(sqlite3Js);
|
||||
}
|
||||
self.sqlite3InitModule({
|
||||
// We can redirect any stdout/stderr from the module
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
.toolbar > * { margin: 0.25em; }
|
||||
fieldset { border-radius: 0.5em; }
|
||||
</style>
|
||||
<script src="sqlite3.js"></script>
|
||||
<script src="jswasm/sqlite3.js"></script>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="demo-kvvfs1.js"></script>
|
||||
<script src="demo-jsstorage.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -28,7 +28,7 @@
|
||||
<hr>
|
||||
<div id='test-output'></div>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="sqlite3-worker1-promiser.js"></script>
|
||||
<script src="testing-worker1-promiser.js"></script>
|
||||
<script src="jswasm/sqlite3-worker1-promiser.js"></script>
|
||||
<script src="demo-worker1-promiser.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
const promiserConfig = {
|
||||
worker: ()=>{
|
||||
const w = new Worker("sqlite3-worker1.js");
|
||||
const w = new Worker("jswasm/sqlite3-worker1.js");
|
||||
w.onerror = (event)=>error("worker.onerror",event);
|
||||
return w;
|
||||
},
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
@@ -28,6 +29,6 @@
|
||||
<hr>
|
||||
<div id='test-output'></div>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="testing2.js"></script>
|
||||
<script src="demo-worker1.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -13,13 +13,13 @@
|
||||
A basic test script for sqlite3-worker1.js.
|
||||
|
||||
Note that the wrapper interface demonstrated in
|
||||
testing-worker1-promiser.js is much easier to use from client code, as it
|
||||
demo-worker1-promiser.js is much easier to use from client code, as it
|
||||
lacks the message-passing acrobatics demonstrated in this file.
|
||||
*/
|
||||
'use strict';
|
||||
(function(){
|
||||
const T = self.SqliteTestUtil;
|
||||
const SW = new Worker("sqlite3-worker1.js");
|
||||
const SW = new Worker("jswasm/sqlite3-worker1.js");
|
||||
const DbState = {
|
||||
id: undefined
|
||||
};
|
||||
@@ -0,0 +1,99 @@
|
||||
#!/do/not/make
|
||||
#^^^ help emacs select edit mode
|
||||
#
|
||||
# Intended to include'd by ./GNUmakefile.
|
||||
#
|
||||
# 'make dist' rules for creating a distribution archive of the WASM/JS
|
||||
# pieces, noting that we only build a dist of the built files, not the
|
||||
# numerous pieces required to build them.
|
||||
#######################################################################
|
||||
MAKEFILE.dist := $(lastword $(MAKEFILE_LIST))
|
||||
|
||||
########################################################################
|
||||
# Chicken/egg situation: we need $(bin.version-info) to get the version
|
||||
# info for the archive name, but that binary may not yet be built, and
|
||||
# won't be built until we expand the dependencies. We have to use a
|
||||
# temporary name for the archive.
|
||||
dist-name = sqlite-wasm-TEMP
|
||||
#ifeq (0,1)
|
||||
# $(info WARNING *******************************************************************)
|
||||
# $(info ** Be sure to create the desired build configuration before creating the)
|
||||
# $(info ** distribution archive. Use one of the following targets to do so:)
|
||||
# $(info **)
|
||||
# $(info ** o2: builds with -O2, resulting in the fastest builds)
|
||||
# $(info ** oz: builds with -Oz, resulting in the smallest builds)
|
||||
# $(info /WARNING *******************************************************************)
|
||||
#endif
|
||||
|
||||
########################################################################
|
||||
# dist.build must be the name of a target which triggers the
|
||||
# build of the files to be packed into the dist archive. The
|
||||
# intention is that it be one of (o0, o1, o2, o3, os, oz), each of
|
||||
# which uses like-named -Ox optimization level flags. The o2 target
|
||||
# provides the best overall runtime speeds. The oz target provides
|
||||
# slightly slower speeds (roughly 10%) with significantly smaller WASM
|
||||
# file sizes. Note that -O2 (the o2 target) results in faster binaries
|
||||
# than both -O3 and -Os (the o3 and os targets) in all tests run to
|
||||
# date.
|
||||
dist.build ?= oz
|
||||
|
||||
dist-dir.top := $(dist-name)
|
||||
dist-dir.jswasm := $(dist-dir.top)/$(notdir $(dir.dout))
|
||||
dist-dir.common := $(dist-dir.top)/common
|
||||
dist.top.extras := \
|
||||
demo-123.html demo-123-worker.html demo-123.js \
|
||||
tester1.html tester1-worker.html tester1.js \
|
||||
demo-jsstorage.html demo-jsstorage.js \
|
||||
demo-worker1.html demo-worker1.js \
|
||||
demo-worker1-promiser.html demo-worker1-promiser.js
|
||||
dist.jswasm.extras := $(sqlite3-api.ext.jses) $(sqlite3.wasm)
|
||||
dist.common.extras := \
|
||||
$(wildcard $(dir.common)/*.css) \
|
||||
$(dir.common)/SqliteTestUtil.js
|
||||
|
||||
.PHONY: dist
|
||||
########################################################################
|
||||
# dist: create the end-user deliverable archive.
|
||||
#
|
||||
# Maintenance reminder: because dist depends on $(dist.build), and
|
||||
# $(dist.build) will depend on clean, having any deps on
|
||||
# $(dist-archive) which themselves may be cleaned up by the clean
|
||||
# target will lead to grief in parallel builds (-j #). Thus
|
||||
# $(dist-target)'s deps must be trimmed to non-generated files or
|
||||
# files which are _not_ cleaned up by the clean target.
|
||||
#
|
||||
# Note that we require $(bin.version-info) in order to figure out the
|
||||
# dist file's name, so cannot (without a recursive make) have the
|
||||
# target name equal to the archive name.
|
||||
dist: \
|
||||
$(bin.stripccomments) $(bin.version-info) \
|
||||
$(dist.build) \
|
||||
$(MAKEFILE) $(MAKEFILE.dist)
|
||||
@echo "Making end-user deliverables..."
|
||||
@rm -fr $(dist-dir.top)
|
||||
@mkdir -p $(dist-dir.jswasm) $(dist-dir.common)
|
||||
@cp -p $(dist.top.extras) $(dist-dir.top)
|
||||
@cp -p README-dist.txt $(dist-dir.top)/README.txt
|
||||
@cp -p index-dist.html $(dist-dir.top)/index.html
|
||||
@cp -p $(dist.jswasm.extras) $(dist-dir.jswasm)
|
||||
@$(bin.stripccomments) -k -k < $(sqlite3.js) \
|
||||
> $(dist-dir.jswasm)/$(notdir $(sqlite3.js))
|
||||
@cp -p $(dist.common.extras) $(dist-dir.common)
|
||||
@vnum=$$($(bin.version-info) --version-number); \
|
||||
vdir=sqlite-wasm-$$vnum; \
|
||||
arczip=$$vdir.zip; \
|
||||
echo "Making $$arczip ..."; \
|
||||
rm -fr $$arczip $$vdir; \
|
||||
mv $(dist-dir.top) $$vdir; \
|
||||
zip -qr $$arczip $$vdir; \
|
||||
rm -fr $$vdir; \
|
||||
ls -la $$arczip; \
|
||||
unzip -lv $$arczip || echo "Missing unzip app? Not fatal."
|
||||
|
||||
# We need a separate `clean` rule to account for weirdness in
|
||||
# a sub-make, where we get a copy of the $(dist-name) dir
|
||||
# copied into the new $(dist-name) dir.
|
||||
.PHONY: dist-clean
|
||||
clean: dist-clean
|
||||
dist-clean:
|
||||
rm -fr $(dist-name) $(wildcard sqlite-wasm-*.zip)
|
||||
+13
-11
@@ -23,6 +23,7 @@ $(dir.top)/shell.c: $(SHELL_SRC) $(dir.top)/tool/mkshellc.tcl
|
||||
# /shell.c
|
||||
########################################################################
|
||||
|
||||
EXPORTED_FUNCTIONS.fiddle := $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle
|
||||
fiddle.emcc-flags = \
|
||||
$(emcc.cflags) $(emcc_opt_full) \
|
||||
--minify 0 \
|
||||
@@ -34,35 +35,36 @@ fiddle.emcc-flags = \
|
||||
-sDYNAMIC_EXECUTION=0 \
|
||||
-sWASM_BIGINT=$(emcc_enable_bigint) \
|
||||
-sEXPORT_NAME=$(sqlite3.js.init-func) \
|
||||
-Wno-limited-postlink-optimizations \
|
||||
$(sqlite3.js.flags.--post-js) \
|
||||
-sEXPORTED_RUNTIME_METHODS=@$(dir.wasm)/EXPORTED_RUNTIME_METHODS.fiddle \
|
||||
-sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.fiddle \
|
||||
$(emcc.exportedRuntimeMethods) \
|
||||
-sEXPORTED_FUNCTIONS=@$(abspath $(EXPORTED_FUNCTIONS.fiddle)) \
|
||||
$(SQLITE_OPT) $(SHELL_OPT) \
|
||||
-DSQLITE_SHELL_FIDDLE
|
||||
# -D_POSIX_C_SOURCE is needed for strdup() with emcc
|
||||
|
||||
fiddle.EXPORTED_FUNCTIONS.in := \
|
||||
EXPORTED_FUNCTIONS.fiddle.in \
|
||||
EXPORTED_FUNCTIONS.api
|
||||
$(EXPORTED_FUNCTIONS.api)
|
||||
|
||||
EXPORTED_FUNCTIONS.fiddle: $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle)
|
||||
grep -h -v jaccwabyt $(fiddle.EXPORTED_FUNCTIONS.in) | sort -u > $@
|
||||
$(EXPORTED_FUNCTIONS.fiddle): $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle)
|
||||
sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@
|
||||
|
||||
fiddle-module.js := $(dir.fiddle)/fiddle-module.js
|
||||
fiddle-module.wasm := $(subst .js,.wasm,$(fiddle-module.js))
|
||||
fiddle.cs := $(dir.top)/shell.c $(sqlite3-wasm.c)
|
||||
fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c)
|
||||
|
||||
SOAP.js := sqlite3-opfs-async-proxy.js
|
||||
$(dir.fiddle)/$(SOAP.js): $(SOAP.js)
|
||||
fiddle.SOAP.js := $(dir.fiddle)/$(notdir $(SOAP.js))
|
||||
$(fiddle.SOAP.js): $(SOAP.js)
|
||||
cp $< $@
|
||||
|
||||
$(eval $(call call-make-pre-js,fiddle-module))
|
||||
$(fiddle-module.js): $(MAKEFILE) $(MAKEFILE.fiddle) \
|
||||
EXPORTED_FUNCTIONS.fiddle EXPORTED_RUNTIME_METHODS.fiddle \
|
||||
$(fiddle.cs) $(pre-post-fiddle-module.deps) $(dir.fiddle)/$(SOAP.js)
|
||||
$(EXPORTED_FUNCTIONS.fiddle) \
|
||||
$(fiddle.cses) $(pre-post-fiddle-module.deps) $(fiddle.SOAP.js)
|
||||
$(emcc.bin) -o $@ $(fiddle.emcc-flags) \
|
||||
$(pre-post-common.flags) $(pre-post-fiddle-module.flags) \
|
||||
$(fiddle.cs)
|
||||
$(fiddle.cses)
|
||||
$(maybe-wasm-strip) $(fiddle-module.wasm)
|
||||
gzip < $@ > $@.gz
|
||||
gzip < $(fiddle-module.wasm) > $(fiddle-module.wasm).gz
|
||||
|
||||
@@ -102,7 +102,7 @@
|
||||
const toss = (...args)=>{
|
||||
throw new Error(args.join(' '));
|
||||
};
|
||||
const fixmeOPFS = "(FIXME: won't work with vanilla OPFS.)";
|
||||
const fixmeOPFS = "(FIXME: won't work with OPFS-over-sqlite3_vfs.)";
|
||||
let sqlite3 /* gets assigned when the wasm module is loaded */;
|
||||
|
||||
self.onerror = function(/*message, source, lineno, colno, error*/) {
|
||||
@@ -130,7 +130,7 @@
|
||||
return f._();
|
||||
},
|
||||
dbIsOpfs: function f(){
|
||||
return sqlite3.opfs && sqlite3.capi.sqlite3_web_db_uses_vfs(
|
||||
return sqlite3.opfs && sqlite3.capi.sqlite3_js_db_uses_vfs(
|
||||
this.dbHandle(), "opfs"
|
||||
);
|
||||
},
|
||||
@@ -251,7 +251,7 @@
|
||||
const fn2 = fn ? fn.split(/[/\\]/).pop() : null;
|
||||
try{
|
||||
if(!fn2) toss("DB appears to be closed.");
|
||||
const buffer = sqlite3.capi.sqlite3_web_db_export(
|
||||
const buffer = sqlite3.capi.sqlite3_js_db_export(
|
||||
Sqlite3Shell.dbHandle()
|
||||
);
|
||||
wMsg('db-export',{filename: fn2, buffer: buffer.buffer}, [buffer.buffer]);
|
||||
@@ -370,9 +370,9 @@
|
||||
*/
|
||||
sqlite3InitModule(fiddleModule).then((_sqlite3)=>{
|
||||
sqlite3 = _sqlite3;
|
||||
const dbVfs = sqlite3.capi.wasm.xWrap('fiddle_db_vfs', "*", ['string']);
|
||||
fiddleModule.fsUnlink = (fn)=>{
|
||||
stderr("unlink:",fixmeOPFS);
|
||||
return sqlite3.capi.wasm.sqlite3_wasm_vfs_unlink(fn);
|
||||
return sqlite3.capi.wasm.sqlite3_wasm_vfs_unlink(dbVfs(0), fn);
|
||||
};
|
||||
wMsg('fiddle-ready');
|
||||
})/*then()*/;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||
<title>sqlite3 WASM Demo Page Index</title>
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
textarea {
|
||||
font-family: monospace;
|
||||
}
|
||||
header {
|
||||
font-size: 130%;
|
||||
font-weight: bold;
|
||||
}
|
||||
.hidden, .initially-hidden {
|
||||
position: absolute !important;
|
||||
opacity: 0 !important;
|
||||
pointer-events: none !important;
|
||||
display: none !important;
|
||||
}
|
||||
.warning { color: firebrick; }
|
||||
</style>
|
||||
<header id='titlebar'><span>sqlite3 WASM demo pages</span></header>
|
||||
<hr>
|
||||
<div>Below is the list of demo pages for the sqlite3 WASM
|
||||
builds. The intent is that <em>this</em> page be run
|
||||
using the functional equivalent of:</div>
|
||||
<blockquote><pre><a href='https://sqlite.org/althttpd'>althttpd</a> -enable-sab -page index.html</pre></blockquote>
|
||||
<div>and the individual pages be started in their own tab.
|
||||
Warnings and Caveats:
|
||||
<ul class='warning'>
|
||||
<li>Some of these pages require that the web server emit the
|
||||
so-called
|
||||
<a href='https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy'>COOP</a>
|
||||
and
|
||||
<a href='https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy'>COEP</a>
|
||||
headers. <a href='https://sqlite.org/althttpd'>althttpd</a> requires the
|
||||
<code>-enable-sab</code> flag for that.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div>The tests and demos...
|
||||
<ul id='test-list'>
|
||||
<li>Core-most tests
|
||||
<ul>
|
||||
<li><a href='tester1.html'>tester1</a>: Core unit and
|
||||
regression tests for the various APIs and surrounding
|
||||
utility code.</li>
|
||||
<li><a href='tester1-worker.html'>tester1-worker</a>: same thing
|
||||
but running in a Worker.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Higher-level apps and demos...
|
||||
<ul>
|
||||
<li><a href='demo-123.html'>demo-123</a> provides a
|
||||
no-nonsense example of adding sqlite3 support to a web
|
||||
page in the UI thread.</li>
|
||||
<li><a href='demo-123-worker.html'>demo-123-worker</a> is
|
||||
the same as <code>demo-123</code> but loads and runs
|
||||
sqlite3 from a Worker thread.</li>
|
||||
<li><a href='demo-jsstorage.html'>demo-jsstorage</a>: very basic
|
||||
demo of using the key-value VFS for storing a persistent db
|
||||
in JS <code>localStorage</code> or <code>sessionStorage</code>.</li>
|
||||
<li><a href='demo-worker1.html'>demo-worker1</a>:
|
||||
Worker-based wrapper of the OO API #1. Its Promise-based
|
||||
wrapper is significantly easier to use, however.</li>
|
||||
<li><a href='demo-worker1-promiser.html'>demo-worker1-promiser</a>:
|
||||
a demo of the Promise-based wrapper of the Worker1 API.</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<style>
|
||||
#test-list { font-size: 120%; }
|
||||
</style>
|
||||
<script>//Assign a distinct target tab name for each test page...
|
||||
document.querySelectorAll('a').forEach(function(e){
|
||||
e.target = e.href;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+17
-16
@@ -34,8 +34,7 @@
|
||||
</li>
|
||||
<li>Whether or not WASMFS/OPFS support is enabled on any given
|
||||
page may depend on build-time options which are <em>off by
|
||||
default</em> because they currently (as of 2022-09-08) break
|
||||
with Worker-based pages.
|
||||
default</em>.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -46,7 +45,7 @@
|
||||
<li><a href='tester1.html'>tester1</a>: Core unit and
|
||||
regression tests for the various APIs and surrounding
|
||||
utility code.</li>
|
||||
<li><a href='tester1.html'>tester1-worker</a>: same thing
|
||||
<li><a href='tester1-worker.html'>tester1-worker</a>: same thing
|
||||
but running in a Worker.</li>
|
||||
</ul>
|
||||
</li>
|
||||
@@ -60,15 +59,21 @@
|
||||
<li><a href='demo-123-worker.html'>demo-123-worker</a> is
|
||||
the same as <code>demo-123</code> but loads and runs
|
||||
sqlite3 from a Worker thread.</li>
|
||||
<li><a href='demo-kvvfs1.html'>demo-kvvfs1</a>: very basic
|
||||
<li><a href='demo-jsstorage.html'>demo-jsstorage</a>: very basic
|
||||
demo of using the key-value VFS for storing a persistent db
|
||||
in JS <code>localStorage</code> or <code>sessionStorage</code>.</li>
|
||||
<li><a href='demo-worker1.html'>demo-worker1</a>:
|
||||
Worker-based wrapper of the OO API #1. Its Promise-based
|
||||
wrapper is significantly easier to use, however.</li>
|
||||
<li><a href='demo-worker1-promiser.html'>demo-worker1-promiser</a>:
|
||||
a demo of the Promise-based wrapper of the Worker1 API.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>speedtest1 ports (sqlite3's primary benchmarking tool)...
|
||||
<ul>
|
||||
<li><a href='speedtest1.html'>speedtest1</a>: a main-thread WASM build of speedtest1.</li>
|
||||
<li><a href='speedtest1-wasmfs.html?flags=--size,25'>speedtest1-wasmfs</a>: a variant of speedtest1 built solely for the wasmfs/opfs feature.</li>
|
||||
<!--li><a href='speedtest1-wasmfs.html?flags=--size,25'>speedtest1-wasmfs</a>: a variant of speedtest1 built solely for the wasmfs/opfs feature.
|
||||
</li-->
|
||||
<li><a href='speedtest1.html?vfs=kvvfs'>speedtest1-kvvfs</a>: speedtest1 with the kvvfs.</li>
|
||||
<li><a href='speedtest1-worker.html?size=25'>speedtest1-worker</a>: an interactive Worker-thread variant of speedtest1.</li>
|
||||
<li><a href='speedtest1-worker.html?vfs=opfs&size=25'>speedtest1-worker-opfs</a>: speedtest1-worker with the
|
||||
@@ -77,22 +82,18 @@
|
||||
</li>
|
||||
<li>The obligatory "misc." category...
|
||||
<ul>
|
||||
<li><a href='testing2.html'>testing2</a>: Worker-based test of OO API #1.</li>
|
||||
<li><a href='testing-worker1-promiser.html'>testing-worker1-promiser</a>:
|
||||
tests for the Promise-based wrapper of the Worker-based API.</li>
|
||||
<li><a href='batch-runner.html'>batch-runner</a>: runs batches of SQL exported from speedtest1.</li>
|
||||
<li><a href='scratchpad-wasmfs-main.html'>scratchpad-wasmfs-main</a>:
|
||||
<!--li><a href='scratchpad-wasmfs-main.html'>scratchpad-wasmfs-main</a>:
|
||||
experimenting with WASMFS/OPFS-based persistence. Maintenance
|
||||
reminder: we cannot currently (2022-09-15) load WASMFS in a
|
||||
worker due to an Emscripten limitation.</li>
|
||||
worker due to an Emscripten limitation.</li-->
|
||||
<li><a href='test-opfs-vfs.html'>test-opfs-vfs</a>
|
||||
(<a href='test-opfs-vfs.html?opfs-sanity-check&opfs-verbose'>same
|
||||
with verbose output and sanity-checking tests</a>) is an
|
||||
experiment in implementing a syncronous sqlite3 VFS proxy
|
||||
for a fully asynchronous backend interface (namely OPFS),
|
||||
using SharedArrayBuffer and the Atomics APIs to regulate
|
||||
communication between the synchronous interface and the
|
||||
async impl.
|
||||
with verbose output and sanity-checking tests</a>) is an
|
||||
sqlite3_vfs OPFS proxy using SharedArrayBuffer and the
|
||||
Atomics APIs to regulate communication between the
|
||||
synchronous sqlite3_vfs interface and the async OPFS
|
||||
impl.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -169,7 +169,7 @@
|
||||
return str+a.join(' ');
|
||||
};
|
||||
|
||||
const W = new Worker("speedtest1-worker.js"+self.location.search);
|
||||
const W = new Worker("speedtest1-worker.js?sqlite3.dir=jswasm");
|
||||
const mPost = function(msgType,payload){
|
||||
W.postMessage({type: msgType, data: payload});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
'use strict';
|
||||
(function(){
|
||||
importScripts('common/whwasmutil.js','speedtest1.js');
|
||||
let speedtestJs = 'speedtest1.js';
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
if(urlParams.has('sqlite3.dir')){
|
||||
speedtestJs = urlParams.get('sqlite3.dir') + '/' + speedtestJs;
|
||||
}
|
||||
importScripts('common/whwasmutil.js', speedtestJs);
|
||||
/**
|
||||
If this environment contains OPFS, this function initializes it and
|
||||
returns the name of the dir on which OPFS is mounted, else it returns
|
||||
@@ -46,7 +51,7 @@
|
||||
const runSpeedtest = function(cliFlagsArray){
|
||||
const scope = App.wasm.scopedAllocPush();
|
||||
const dbFile = App.pDir+"/speedtest1.sqlite3";
|
||||
App.unlink(dbFile);
|
||||
App.vfsUnlink(0, dbFile);
|
||||
try{
|
||||
const argv = [
|
||||
"speedtest1.wasm", ...cliFlagsArray, dbFile
|
||||
@@ -59,7 +64,7 @@
|
||||
mPost('error',e.message);
|
||||
}finally{
|
||||
App.wasm.scopedAllocPop(scope);
|
||||
App.unlink(dbFile);
|
||||
App.vfsUnlink(0, dbFile);
|
||||
mPost('run-end', App.logBuffer.join('\n'));
|
||||
App.logBuffer.length = 0;
|
||||
}
|
||||
@@ -82,16 +87,15 @@
|
||||
};
|
||||
self.sqlite3InitModule(EmscriptenModule).then((sqlite3)=>{
|
||||
const S = sqlite3;
|
||||
const vfsUnlink = S.capi.wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]);
|
||||
App.unlink = function(fname){
|
||||
vfsUnlink(fname);
|
||||
if(S.opfs) S.opfs.deleteEntry(fname);
|
||||
App.vfsUnlink = function(pDb, fname){
|
||||
const pVfs = S.capi.wasm.sqlite3_wasm_db_vfs(pDb, fname||0);
|
||||
if(pVfs) S.capi.wasm.sqlite3_wasm_vfs_unlink(pVfs, fname||0);
|
||||
};
|
||||
App.pDir = wasmfsDir(S.wasm);
|
||||
App.wasm = S.capi.wasm;
|
||||
//if(App.pDir) log("Persistent storage:",pDir);
|
||||
//else log("Using transient storage.");
|
||||
mPost('ready',true);
|
||||
log("Registered VFSes:", ...S.capi.sqlite3_web_vfs_list());
|
||||
log("Registered VFSes:", ...S.capi.sqlite3_js_vfs_list());
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
speedtest is running. Output will appear below when ready...
|
||||
<div id='test-output'></div>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="speedtest1.js"></script>
|
||||
<script src="jswasm/speedtest1.js"></script>
|
||||
<script>(function(){
|
||||
/**
|
||||
If this environment contains OPFS, this function initializes it and
|
||||
@@ -94,7 +94,6 @@
|
||||
const runTests = function(sqlite3){
|
||||
const capi = sqlite3.capi, wasm = capi.wasm;
|
||||
//console.debug('sqlite3 =',sqlite3);
|
||||
const unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["string"]);
|
||||
const pDir = wasmfsDir(wasm);
|
||||
if(pDir){
|
||||
console.warn("Persistent storage:",pDir);
|
||||
@@ -108,9 +107,11 @@
|
||||
}
|
||||
|
||||
let forceSize = 0;
|
||||
let vfs, pVfs = 0;
|
||||
if(urlParams.has('vfs')){
|
||||
const vfs = urlParams.get('vfs');
|
||||
if(!capi.sqlite3_vfs_find(vfs)){
|
||||
vfs = urlParams.get('vfs');
|
||||
pVfs = capi.sqlite3_vfs_find(vfs);
|
||||
if(!pVfs){
|
||||
log2('error',"Unknown VFS:",vfs);
|
||||
return;
|
||||
}
|
||||
@@ -121,7 +122,7 @@
|
||||
dbFile = 'session';
|
||||
log2('warning',"kvvfs VFS: forcing --size",forceSize,
|
||||
"and filename '"+dbFile+"'.");
|
||||
capi.sqlite3_web_kvvfs_clear(dbFile);
|
||||
capi.sqlite3_js_kvvfs_clear(dbFile);
|
||||
}
|
||||
}
|
||||
if(forceSize){
|
||||
@@ -146,7 +147,7 @@
|
||||
console.log("argv =",argv);
|
||||
// These log messages are not emitted to the UI until after main() returns. Fixing that
|
||||
// requires moving the main() call and related cleanup into a timeout handler.
|
||||
if(pDir) unlink(dbFile);
|
||||
if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile);
|
||||
log2('',"Starting native app:\n ",argv.join(' '));
|
||||
log2('',"This will take a while and the browser might warn about the runaway JS.",
|
||||
"Give it time...");
|
||||
@@ -155,7 +156,7 @@
|
||||
wasm.xCall('wasm_main', argv.length,
|
||||
wasm.scopedAllocMainArgv(argv));
|
||||
wasm.scopedAllocPop(scope);
|
||||
if(pDir) unlink(dbFile);
|
||||
if(pDir) wasm.sqlite3_wasm_vfs_unlink(pVfs,dbFile);
|
||||
logList.unshift("Done running native main(). Output:");
|
||||
dumpLogList();
|
||||
}, 50);
|
||||
|
||||
@@ -9,16 +9,18 @@
|
||||
<title>Async-behind-Sync experiment</title>
|
||||
</head>
|
||||
<body>
|
||||
<header id='titlebar'><span>Async-behind-Sync Experiment</span></header>
|
||||
<div>This is an experiment in wrapping the
|
||||
asynchronous OPFS APIs behind a fully synchronous proxy. It is
|
||||
very much incomplete, under construction, and experimental.
|
||||
<header id='titlebar'><span>Async-behind-Sync sqlite3_vfs</span></header>
|
||||
<div>This performs a sanity test of the "opfs" sqlite3_vfs.
|
||||
<strong>See the dev console for all output.</strong>
|
||||
</div>
|
||||
<div>
|
||||
<a href='?delete'>Use this link</a> to delete the persistent OPFS-side db (if any).
|
||||
</div>
|
||||
<div id='test-output'></div>
|
||||
<script>new Worker("test-opfs-vfs.js"+self.location.search);</script>
|
||||
<script>
|
||||
new Worker(
|
||||
"test-opfs-vfs.js?sqlite3.dir=jswasm&"+self.location.search.substr(1)
|
||||
);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -76,7 +76,7 @@ const tryOpfsVfs = async function(sqlite3){
|
||||
log("Done!");
|
||||
}/*tryOpfsVfs()*/;
|
||||
|
||||
importScripts('sqlite3.js');
|
||||
importScripts('jswasm/sqlite3.js');
|
||||
self.sqlite3InitModule()
|
||||
.then((sqlite3)=>tryOpfsVfs(sqlite3))
|
||||
.catch((e)=>{
|
||||
|
||||
@@ -15,16 +15,32 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>sqlite3 WASM/JS tester #1 (Worker thread)</h1>
|
||||
<div>See <a href='tester1.html' target='tester1.html'>tester1.html</a>
|
||||
for the UI-thread variant.</div>
|
||||
<div class='input-wrapper'>
|
||||
<input type='checkbox' id='cb-log-reverse'>
|
||||
<label for='cb-log-reverse'>Reverse log order?</label>
|
||||
</div>
|
||||
<div id='test-output'></div>
|
||||
<script>(function(){
|
||||
const logTarget = document.querySelector('#test-output');
|
||||
const logHtml = function(cssClass,...args){
|
||||
const ln = document.createElement('div');
|
||||
if(cssClass) ln.classList.add(cssClass);
|
||||
if(cssClass){
|
||||
for(const c of (Array.isArray(cssClass) ? cssClass : [cssClass])){
|
||||
ln.classList.add(c);
|
||||
}
|
||||
}
|
||||
ln.append(document.createTextNode(args.join(' ')));
|
||||
logTarget.append(ln);
|
||||
};
|
||||
const w = new Worker("tester1.js");
|
||||
const cbReverse = document.querySelector('#cb-log-reverse');
|
||||
const cbReverseIt = ()=>{
|
||||
logTarget.classList[cbReverse.checked ? 'add' : 'remove']('reverse');
|
||||
};
|
||||
cbReverse.addEventListener('change',cbReverseIt,true);
|
||||
cbReverseIt();
|
||||
const w = new Worker("tester1.js?sqlite3.dir=jswasm");
|
||||
w.onmessage = function({data}){
|
||||
switch(data.type){
|
||||
case 'log':
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||
<link rel="stylesheet" href="../common/emscripten.css"/>
|
||||
<link rel="stylesheet" href="../common/testing.css"/>
|
||||
<link rel="stylesheet" href="common/emscripten.css"/>
|
||||
<link rel="stylesheet" href="common/testing.css"/>
|
||||
<title>sqlite3 tester #1 (UI thread)</title>
|
||||
<style>
|
||||
body {
|
||||
@@ -15,8 +15,14 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>sqlite3 WASM/JS tester #1 (UI thread)</h1>
|
||||
<div>See <a href='tester1-worker.html' target='tester1-worker.html'>tester1-worker.html</a>
|
||||
for the Worker-thread variant.</div>
|
||||
<div class='input-wrapper'>
|
||||
<input type='checkbox' id='cb-log-reverse'>
|
||||
<label for='cb-log-reverse'>Reverse log order?</label>
|
||||
</div>
|
||||
<div id='test-output'></div>
|
||||
<script src="sqlite3.js"></script>
|
||||
<script src="jswasm/sqlite3.js"></script>
|
||||
<script src="tester1.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+374
-68
@@ -43,44 +43,61 @@
|
||||
const isWorker = ()=>!isUIThread();
|
||||
/* Predicate for tests/groups. */
|
||||
const testIsTodo = ()=>false;
|
||||
const haveWasmCTests = function(){
|
||||
const haveWasmCTests = ()=>{
|
||||
return !!wasm.exports.sqlite3_wasm_test_int64_max;
|
||||
};
|
||||
const mapToString = (v)=>{
|
||||
switch(typeof v){
|
||||
case 'number': case 'string': case 'boolean':
|
||||
case 'undefined':
|
||||
return ''+v;
|
||||
default: break;
|
||||
}
|
||||
if(null===v) return 'null';
|
||||
if(v instanceof Error){
|
||||
v = {
|
||||
message: v.message,
|
||||
stack: v.stack,
|
||||
errorClass: v.name
|
||||
{
|
||||
const mapToString = (v)=>{
|
||||
switch(typeof v){
|
||||
case 'number': case 'string': case 'boolean':
|
||||
case 'undefined': case 'bigint':
|
||||
return ''+v;
|
||||
default: break;
|
||||
}
|
||||
if(null===v) return 'null';
|
||||
if(v instanceof Error){
|
||||
v = {
|
||||
message: v.message,
|
||||
stack: v.stack,
|
||||
errorClass: v.name
|
||||
};
|
||||
}
|
||||
return JSON.stringify(v,undefined,2);
|
||||
};
|
||||
const normalizeArgs = (args)=>args.map(mapToString);
|
||||
if( isUIThread() ){
|
||||
console.log("Running in the UI thread.");
|
||||
const logTarget = document.querySelector('#test-output');
|
||||
logClass = function(cssClass,...args){
|
||||
const ln = document.createElement('div');
|
||||
if(cssClass){
|
||||
for(const c of (Array.isArray(cssClass) ? cssClass : [cssClass])){
|
||||
ln.classList.add(c);
|
||||
}
|
||||
}
|
||||
ln.append(document.createTextNode(normalizeArgs(args).join(' ')));
|
||||
logTarget.append(ln);
|
||||
};
|
||||
const cbReverse = document.querySelector('#cb-log-reverse');
|
||||
const cbReverseKey = 'tester1:cb-log-reverse';
|
||||
const cbReverseIt = ()=>{
|
||||
logTarget.classList[cbReverse.checked ? 'add' : 'remove']('reverse');
|
||||
//localStorage.setItem(cbReverseKey, cbReverse.checked ? 1 : 0);
|
||||
};
|
||||
cbReverse.addEventListener('change', cbReverseIt, true);
|
||||
/*if(localStorage.getItem(cbReverseKey)){
|
||||
cbReverse.checked = !!(+localStorage.getItem(cbReverseKey));
|
||||
}*/
|
||||
cbReverseIt();
|
||||
}else{ /* Worker thread */
|
||||
console.log("Running in a Worker thread.");
|
||||
logClass = function(cssClass,...args){
|
||||
postMessage({
|
||||
type:'log',
|
||||
payload:{cssClass, args: normalizeArgs(args)}
|
||||
});
|
||||
};
|
||||
}
|
||||
return JSON.stringify(v,undefined,2);
|
||||
};
|
||||
const normalizeArgs = (args)=>args.map(mapToString);
|
||||
if( isUIThread() ){
|
||||
console.log("Running in UI thread.");
|
||||
const logTarget = document.querySelector('#test-output');
|
||||
logClass = function(cssClass,...args){
|
||||
const ln = document.createElement('div');
|
||||
if(cssClass) ln.classList.add(cssClass);
|
||||
ln.append(document.createTextNode(normalizeArgs(args).join(' ')));
|
||||
logTarget.append(ln);
|
||||
};
|
||||
}else{ /* Worker thread */
|
||||
console.log("Running Worker thread.");
|
||||
logClass = function(cssClass,...args){
|
||||
postMessage({
|
||||
type:'log',
|
||||
payload:{cssClass, args: normalizeArgs(args)}
|
||||
});
|
||||
};
|
||||
}
|
||||
const log = (...args)=>{
|
||||
//console.log(...args);
|
||||
@@ -103,6 +120,8 @@
|
||||
throw new Error(args.join(' '));
|
||||
};
|
||||
|
||||
const roundMs = (ms)=>Math.round(ms*100)/100;
|
||||
|
||||
/**
|
||||
Helpers for writing sqlite3-specific tests.
|
||||
*/
|
||||
@@ -208,33 +227,41 @@
|
||||
return this;
|
||||
},
|
||||
run: async function(sqlite3){
|
||||
if(this.predicate && !this.predicate()){
|
||||
log("SKIPPING test group #"+this.number,this.name);
|
||||
return;
|
||||
}
|
||||
log(TestUtil.separator);
|
||||
logClass('group-start',"Group #"+this.number+':',this.name);
|
||||
const indent = '....';
|
||||
const indent = ' ';
|
||||
if(this.predicate && !this.predicate(sqlite3)){
|
||||
logClass('warning',indent,
|
||||
"SKIPPING group because predicate says to.");
|
||||
return;
|
||||
}
|
||||
const assertCount = TestUtil.counter;
|
||||
const groupState = Object.create(null);
|
||||
const skipped = [];
|
||||
for(let i in this.tests){
|
||||
const t = this.tests[i];
|
||||
let runtime = 0, i = 0;
|
||||
for(const t of this.tests){
|
||||
++i;
|
||||
const n = this.number+"."+i;
|
||||
if(t.predicate && !t.predicate()){
|
||||
logClass('warning',indent, n+': SKIPPING',t.name);
|
||||
log(indent, n+":", t.name);
|
||||
if(t.predicate && !t.predicate(sqlite3)){
|
||||
logClass('warning', indent, indent,
|
||||
'SKIPPING because predicate says to');
|
||||
skipped.push( n+': '+t.name );
|
||||
}else{
|
||||
const tc = TestUtil.counter
|
||||
log(indent, n+":", t.name);
|
||||
const tc = TestUtil.counter, now = performance.now();
|
||||
await t.test.call(groupState, sqlite3);
|
||||
//log(indent, indent, 'assertion count:',TestUtil.counter - tc);
|
||||
const then = performance.now();
|
||||
runtime += then - now;
|
||||
logClass('faded',indent, indent,
|
||||
TestUtil.counter - tc, 'assertion(s) in',
|
||||
roundMs(then-now),'ms');
|
||||
}
|
||||
}
|
||||
logClass('green',
|
||||
"Group #"+this.number,"assertion count:",(TestUtil.counter - assertCount));
|
||||
"Group #"+this.number+":",(TestUtil.counter - assertCount),
|
||||
"assertion(s) in",roundMs(runtime),"ms");
|
||||
if(skipped.length){
|
||||
log("SKIPPED test(s) in group",this.number+":",skipped);
|
||||
logClass('warning',"SKIPPED test(s) in group",this.number+":",skipped);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -243,7 +270,8 @@
|
||||
testGroups: [],
|
||||
currentTestGroup: undefined,
|
||||
addGroup: function(name, predicate){
|
||||
this.testGroups.push( this.currentTestGroup = new this.TestGroup(name) );
|
||||
this.testGroups.push( this.currentTestGroup =
|
||||
new this.TestGroup(name, predicate) );
|
||||
return this;
|
||||
},
|
||||
addTest: function(name, callback){
|
||||
@@ -262,11 +290,16 @@
|
||||
runTests: async function(sqlite3){
|
||||
return new Promise(async function(pok,pnok){
|
||||
try {
|
||||
let runtime = 0;
|
||||
for(let g of this.testGroups){
|
||||
const now = performance.now();
|
||||
await g.run(sqlite3);
|
||||
runtime += performance.now() - now;
|
||||
}
|
||||
log(TestUtil.separator);
|
||||
log("Done running tests. Total assertion count:",TestUtil.counter);
|
||||
logClass(['strong','green'],
|
||||
"Done running tests.",TestUtil.counter,"assertions in",
|
||||
roundMs(runtime),'ms');
|
||||
pok();
|
||||
}catch(e){
|
||||
error(e);
|
||||
@@ -310,6 +343,8 @@
|
||||
T.assert(e instanceof Error)
|
||||
.assert(e instanceof sqlite3.WasmAllocError);
|
||||
}
|
||||
try{ throw new sqlite3.SQLite3Error(capi.SQLITE_SCHEMA) }
|
||||
catch(e){ T.assert('SQLITE_SCHEMA' === e.message) }
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////
|
||||
.t('strglob/strlike', function(sqlite3){
|
||||
@@ -696,10 +731,10 @@
|
||||
if(autoResolvePtr){
|
||||
wts.$ppV = 0;
|
||||
T.assert(!wts.$ppV);
|
||||
WTStruct.debugFlags(0x03);
|
||||
//WTStruct.debugFlags(0x03);
|
||||
wts.$ppV = wts;
|
||||
T.assert(wts === wts.$ppV)
|
||||
WTStruct.debugFlags(0);
|
||||
//WTStruct.debugFlags(0);
|
||||
}
|
||||
wts.setMemberCString('cstr', "A C-string.");
|
||||
T.assert(Array.isArray(wts.ondispose)).
|
||||
@@ -1022,7 +1057,7 @@
|
||||
;/*end of C/WASM utils checks*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
T.g('sqlite3.oo1 sanity checks')
|
||||
T.g('sqlite3.oo1')
|
||||
.t('Create db', function(sqlite3){
|
||||
const db = this.db = new sqlite3.oo1.DB();
|
||||
T.assert(Number.isInteger(db.pointer)).
|
||||
@@ -1037,8 +1072,7 @@
|
||||
})
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
.t('DB.Stmt sanity checks', function(S){
|
||||
let pId;
|
||||
.t('DB.Stmt', function(S){
|
||||
let st = this.db.prepare(
|
||||
new TextEncoder('utf-8').encode("select 3 as a")
|
||||
);
|
||||
@@ -1073,7 +1107,6 @@
|
||||
.assert(false===st.step())
|
||||
.assert(!st._mayGet)
|
||||
;
|
||||
pId = st.pointer;
|
||||
T.assert(0===capi.sqlite3_strglob("*.txt", "foo.txt")).
|
||||
assert(0!==capi.sqlite3_strglob("*.txt", "foo.xtx")).
|
||||
assert(0===capi.sqlite3_strlike("%.txt", "foo.txt", 0)).
|
||||
@@ -1085,6 +1118,47 @@
|
||||
.assert(0===this.db.openStatementCount());
|
||||
})
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
.t('sqlite3_js_...()', function(){
|
||||
const db = this.db;
|
||||
if(1){
|
||||
const vfsList = capi.sqlite3_js_vfs_list();
|
||||
T.assert(vfsList.length>1);
|
||||
T.assert('string'===typeof vfsList[0]);
|
||||
//log("vfsList =",vfsList);
|
||||
for(const v of vfsList){
|
||||
T.assert('string' === typeof v)
|
||||
.assert(capi.sqlite3_vfs_find(v) > 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
Trivia: the magic db name ":memory:" does not actually use the
|
||||
"memdb" VFS unless "memdb" is _explicitly_ provided as the VFS
|
||||
name. Instead, it uses the default VFS with an in-memory btree.
|
||||
Thus this.db's VFS may not be memdb even though it's an in-memory
|
||||
db.
|
||||
*/
|
||||
const pVfsMem = capi.sqlite3_vfs_find('memdb'),
|
||||
pVfsDflt = capi.sqlite3_vfs_find(0),
|
||||
pVfsDb = capi.sqlite3_js_db_vfs(db.pointer);
|
||||
T.assert(pVfsMem > 0)
|
||||
.assert(pVfsDflt > 0)
|
||||
.assert(pVfsDb > 0)
|
||||
.assert(pVfsMem !== pVfsDflt
|
||||
/* memdb lives on top of the default vfs */)
|
||||
.assert(':memory:' === db.filename)
|
||||
.assert(pVfsDb === pVfsDflt || pVfsdb === pVfsMem)
|
||||
;
|
||||
/*const vMem = new capi.sqlite3_vfs(pVfsMem),
|
||||
vDflt = new capi.sqlite3_vfs(pVfsDflt),
|
||||
vDb = new capi.sqlite3_vfs(pVfsDb);*/
|
||||
const duv = capi.sqlite3_js_db_uses_vfs;
|
||||
T.assert(pVfsDflt === duv(db.pointer, 0)
|
||||
|| pVfsMem === duv(db.pointer,0))
|
||||
.assert(!duv(db.pointer, "foo"))
|
||||
;
|
||||
}/*sqlite3_js_...()*/)
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
.t('Table t', function(sqlite3){
|
||||
const db = this.db;
|
||||
@@ -1170,6 +1244,14 @@
|
||||
.assert(0==e.message.indexOf('Cannot prepare empty'));
|
||||
}
|
||||
})
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
.t('sqlite3_js_db_export()', function(){
|
||||
const db = this.db;
|
||||
const xp = capi.sqlite3_js_db_export(db.pointer);
|
||||
T.assert(xp instanceof Uint8Array)
|
||||
.assert(xp.byteLength>0)
|
||||
.assert(0 === xp.byteLength % 512);
|
||||
}/*sqlite3_js_db_export()*/)
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
.t('Scalar UDFs', function(sqlite3){
|
||||
@@ -1181,14 +1263,14 @@
|
||||
assert(5===db.selectValue("select foo($a,$b)",{$a:0,$b:5}));
|
||||
db.createFunction("bar", {
|
||||
arity: -1,
|
||||
callback: function(pCx){
|
||||
var rc = 0;
|
||||
for(let i = 1; i < arguments.length; ++i) rc += arguments[i];
|
||||
xFunc: (pCx,...args)=>{
|
||||
let rc = 0;
|
||||
for(const v of args) rc += v;
|
||||
return rc;
|
||||
}
|
||||
}).createFunction({
|
||||
name: "asis",
|
||||
callback: (pCx,arg)=>arg
|
||||
xFunc: (pCx,arg)=>arg
|
||||
});
|
||||
T.assert(0===db.selectValue("select bar()")).
|
||||
assert(1===db.selectValue("select bar(1)")).
|
||||
@@ -1227,15 +1309,150 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
.t({
|
||||
name: 'Aggregate UDFs (tests are TODO)',
|
||||
predicate: testIsTodo
|
||||
})
|
||||
name: 'Aggregate UDFs',
|
||||
test: function(sqlite3){
|
||||
const db = this.db;
|
||||
const sjac = capi.sqlite3_js_aggregate_context;
|
||||
db.createFunction({
|
||||
name: 'summer',
|
||||
xStep: (pCtx, n)=>{
|
||||
const ac = sjac(pCtx, 4);
|
||||
wasm.setMemValue(ac, wasm.getMemValue(ac,'i32') + Number(n), 'i32');
|
||||
},
|
||||
xFinal: (pCtx)=>{
|
||||
const ac = sjac(pCtx, 0);
|
||||
return ac ? wasm.getMemValue(ac,'i32') : 0;
|
||||
}
|
||||
});
|
||||
let v = db.selectValue([
|
||||
"with cte(v) as (",
|
||||
"select 3 union all select 5 union all select 7",
|
||||
") select summer(v), summer(v+1) from cte"
|
||||
/* ------------------^^^^^^^^^^^ ensures that we're handling
|
||||
sqlite3_aggregate_context() properly. */
|
||||
]);
|
||||
T.assert(15===v);
|
||||
T.mustThrowMatching(()=>db.selectValue("select summer(1,2)"),
|
||||
/wrong number of arguments/);
|
||||
|
||||
db.createFunction({
|
||||
name: 'summerN',
|
||||
arity: -1,
|
||||
xStep: (pCtx, ...args)=>{
|
||||
const ac = sjac(pCtx, 4);
|
||||
let sum = wasm.getMemValue(ac, 'i32');
|
||||
for(const v of args) sum += Number(v);
|
||||
wasm.setMemValue(ac, sum, 'i32');
|
||||
},
|
||||
xFinal: (pCtx)=>{
|
||||
const ac = sjac(pCtx, 0);
|
||||
capi.sqlite3_result_int( pCtx, ac ? wasm.getMemValue(ac,'i32') : 0 );
|
||||
// xFinal() may either return its value directly or call
|
||||
// sqlite3_result_xyz() and return undefined. Both are
|
||||
// functionally equivalent.
|
||||
}
|
||||
});
|
||||
T.assert(18===db.selectValue('select summerN(1,8,9), summerN(2,3,4)'));
|
||||
T.mustThrowMatching(()=>{
|
||||
db.createFunction('nope',{
|
||||
xFunc: ()=>{}, xStep: ()=>{}
|
||||
});
|
||||
}, /scalar or aggregate\?/);
|
||||
T.mustThrowMatching(()=>{
|
||||
db.createFunction('nope',{xStep: ()=>{}});
|
||||
}, /Missing xFinal/);
|
||||
T.mustThrowMatching(()=>{
|
||||
db.createFunction('nope',{xFinal: ()=>{}});
|
||||
}, /Missing xStep/);
|
||||
T.mustThrowMatching(()=>{
|
||||
db.createFunction('nope',{});
|
||||
}, /Missing function-type properties/);
|
||||
T.mustThrowMatching(()=>{
|
||||
db.createFunction('nope',{xFunc:()=>{}, xDestroy:'nope'});
|
||||
}, /xDestroy property must be a function/);
|
||||
T.mustThrowMatching(()=>{
|
||||
db.createFunction('nope',{xFunc:()=>{}, pApp:'nope'});
|
||||
}, /Invalid value for pApp/);
|
||||
}
|
||||
}/*aggregate UDFs*/)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
.t({
|
||||
name: 'Aggregate UDFs (64-bit)',
|
||||
predicate: ()=>wasm.bigIntEnabled,
|
||||
test: function(sqlite3){
|
||||
const db = this.db;
|
||||
const sjac = capi.sqlite3_js_aggregate_context;
|
||||
db.createFunction({
|
||||
name: 'summer64',
|
||||
xStep: (pCtx, n)=>{
|
||||
const ac = sjac(pCtx, 8);
|
||||
wasm.setMemValue(ac, wasm.getMemValue(ac,'i64') + BigInt(n), 'i64');
|
||||
},
|
||||
xFinal: (pCtx)=>{
|
||||
const ac = sjac(pCtx, 0);
|
||||
return ac ? wasm.getMemValue(ac,'i64') : 0n;
|
||||
}
|
||||
});
|
||||
let v = db.selectValue([
|
||||
"with cte(v) as (",
|
||||
"select 9007199254740991 union all select 1 union all select 2",
|
||||
") select summer64(v), summer64(v+1) from cte"
|
||||
]);
|
||||
T.assert(9007199254740994n===v);
|
||||
}
|
||||
}/*aggregate UDFs*/)
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
.t({
|
||||
name: 'Window UDFs (tests are TODO)',
|
||||
predicate: testIsTodo
|
||||
})
|
||||
name: 'Window UDFs',
|
||||
test: function(){
|
||||
/* Example window function, table, and results taken from:
|
||||
https://sqlite.org/windowfunctions.html#udfwinfunc */
|
||||
const db = this.db;
|
||||
const sjac = (cx,n=4)=>capi.sqlite3_js_aggregate_context(cx,n);
|
||||
const xValueFinal = (pCtx)=>{
|
||||
const ac = sjac(pCtx, 0);
|
||||
return ac ? wasm.getMemValue(ac,'i32') : 0;
|
||||
};
|
||||
const xStepInverse = (pCtx, n)=>{
|
||||
const ac = sjac(pCtx);
|
||||
wasm.setMemValue(ac, wasm.getMemValue(ac,'i32') + Number(n), 'i32');
|
||||
};
|
||||
db.createFunction({
|
||||
name: 'winsumint',
|
||||
xStep: (pCtx, n)=>xStepInverse(pCtx, n),
|
||||
xInverse: (pCtx, n)=>xStepInverse(pCtx, -n),
|
||||
xFinal: xValueFinal,
|
||||
xValue: xValueFinal
|
||||
});
|
||||
db.exec([
|
||||
"CREATE TABLE twin(x, y); INSERT INTO twin VALUES",
|
||||
"('a', 4),('b', 5),('c', 3),('d', 8),('e', 1)"
|
||||
]);
|
||||
let count = 0;
|
||||
db.exec({
|
||||
sql:[
|
||||
"SELECT x, winsumint(y) OVER (",
|
||||
"ORDER BY x ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING",
|
||||
") AS sum_y ",
|
||||
"FROM twin ORDER BY x;",
|
||||
"DROP TABLE twin;"
|
||||
],
|
||||
callback: function(row){
|
||||
switch(++count){
|
||||
case 1: T.assert('a'===row[0] && 9===row[1]); break;
|
||||
case 2: T.assert('b'===row[0] && 12===row[1]); break;
|
||||
case 3: T.assert('c'===row[0] && 16===row[1]); break;
|
||||
case 4: T.assert('d'===row[0] && 12===row[1]); break;
|
||||
case 5: T.assert('e'===row[0] && 9===row[1]); break;
|
||||
default: toss("Too many rows to window function.");
|
||||
}
|
||||
}
|
||||
});
|
||||
T.assert(5 === count);
|
||||
}
|
||||
}/*window UDFs*/)
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
.t("ATTACH", function(){
|
||||
@@ -1372,10 +1589,93 @@
|
||||
})
|
||||
;/* end of oo1 checks */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
T.g('kvvfs (Worker thread only)', isWorker)
|
||||
.t({
|
||||
name: 'kvvfs is disabled',
|
||||
test: ()=>{
|
||||
T.assert(
|
||||
!capi.sqlite3_vfs_find('kvvfs'),
|
||||
"Expecting kvvfs to be unregistered."
|
||||
);
|
||||
}
|
||||
});
|
||||
T.g('kvvfs (UI thread only)', isUIThread)
|
||||
.t({
|
||||
name: 'kvvfs sanity checks',
|
||||
test: function(sqlite3){
|
||||
const filename = 'session';
|
||||
const pVfs = capi.sqlite3_vfs_find('kvvfs');
|
||||
T.assert(pVfs);
|
||||
const JDb = sqlite3.oo1.JsStorageDb;
|
||||
const unlink = ()=>JDb.clearStorage(filename);
|
||||
unlink();
|
||||
let db = new JDb(filename);
|
||||
db.exec([
|
||||
'create table kvvfs(a);',
|
||||
'insert into kvvfs(a) values(1),(2),(3)'
|
||||
]);
|
||||
T.assert(3 === db.selectValue('select count(*) from kvvfs'));
|
||||
db.close();
|
||||
db = new JDb(filename);
|
||||
db.exec('insert into kvvfs(a) values(4),(5),(6)');
|
||||
T.assert(6 === db.selectValue('select count(*) from kvvfs'));
|
||||
db.close();
|
||||
unlink();
|
||||
}
|
||||
}/*kvvfs sanity checks*/)
|
||||
;/* end kvvfs tests */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
T.g('OPFS (Worker thread only and only in supported browsers)',
|
||||
(sqlite3)=>{return !!sqlite3.opfs})
|
||||
.t({
|
||||
name: 'OPFS sanity checks',
|
||||
test: function(sqlite3){
|
||||
const filename = 'sqlite3-tester1.db';
|
||||
const pVfs = capi.sqlite3_vfs_find('opfs');
|
||||
T.assert(pVfs);
|
||||
const unlink = (fn=filename)=>wasm.sqlite3_wasm_vfs_unlink(pVfs,fn);
|
||||
unlink();
|
||||
let db = new sqlite3.opfs.OpfsDb(filename);
|
||||
db.exec([
|
||||
'create table p(a);',
|
||||
'insert into p(a) values(1),(2),(3)'
|
||||
]);
|
||||
T.assert(3 === db.selectValue('select count(*) from p'));
|
||||
db.close();
|
||||
db = new sqlite3.opfs.OpfsDb(filename);
|
||||
db.exec('insert into p(a) values(4),(5),(6)');
|
||||
T.assert(6 === db.selectValue('select count(*) from p'));
|
||||
db.close();
|
||||
unlink();
|
||||
}
|
||||
}/*OPFS sanity checks*/)
|
||||
;/* end OPFS tests */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
log("Loading and initializing sqlite3 WASM module...");
|
||||
if(!isUIThread()){
|
||||
importScripts("sqlite3.js");
|
||||
/*
|
||||
If sqlite3.js is in a directory other than this script, in order
|
||||
to get sqlite3.js to resolve sqlite3.wasm properly, we have to
|
||||
explicitly tell it where sqlite3.js is being loaded from. We do
|
||||
that by passing the `sqlite3.dir=theDirName` URL argument to
|
||||
_this_ script. That URL argument will be seen by the JS/WASM
|
||||
loader and it will adjust the sqlite3.wasm path accordingly. If
|
||||
sqlite3.js/.wasm are in the same directory as this script then
|
||||
that's not needed.
|
||||
|
||||
URL arguments passed as part of the filename via importScripts()
|
||||
are simply lost, and such scripts see the self.location of
|
||||
_this_ script.
|
||||
*/
|
||||
let sqlite3Js = 'sqlite3.js';
|
||||
const urlParams = new URL(self.location.href).searchParams;
|
||||
if(urlParams.has('sqlite3.dir')){
|
||||
sqlite3Js = urlParams.get('sqlite3.dir') + '/' + sqlite3Js;
|
||||
}
|
||||
importScripts(sqlite3Js);
|
||||
}
|
||||
self.sqlite3InitModule({
|
||||
print: log,
|
||||
@@ -1387,9 +1687,15 @@
|
||||
wasm = capi.wasm;
|
||||
log("sqlite3 version:",capi.sqlite3_libversion(),
|
||||
capi.sqlite3_sourceid());
|
||||
log("BigInt/int64 support is",(wasm.bigIntEnabled ? "enabled" : "disabled"));
|
||||
if(wasm.bigIntEnabled){
|
||||
log("BigInt/int64 support is enabled.");
|
||||
}else{
|
||||
logClass('warning',"BigInt/int64 support is disabled.");
|
||||
}
|
||||
if(haveWasmCTests()){
|
||||
log("sqlite3_wasm_test_...() APIs are available.");
|
||||
}else{
|
||||
logClass('warning',"sqlite3_wasm_test_...() APIs unavailable.");
|
||||
}
|
||||
TestUtil.runTests(sqlite3);
|
||||
});
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||
<link rel="stylesheet" href="common/emscripten.css"/>
|
||||
<link rel="stylesheet" href="common/testing.css"/>
|
||||
<title>sqlite3-api.js tests</title>
|
||||
</head>
|
||||
<body>
|
||||
<header id='titlebar'><span>sqlite3-api.js tests</span></header>
|
||||
<!-- emscripten bits -->
|
||||
<figure id="module-spinner">
|
||||
<div class="spinner"></div>
|
||||
<div class='center'><strong>Initializing app...</strong></div>
|
||||
<div class='center'>
|
||||
On a slow internet connection this may take a moment. If this
|
||||
message displays for "a long time", intialization may have
|
||||
failed and the JavaScript console may contain clues as to why.
|
||||
</div>
|
||||
</figure>
|
||||
<div class="emscripten" id="module-status">Downloading...</div>
|
||||
<div class="emscripten">
|
||||
<progress value="0" max="100" id="module-progress" hidden='1'></progress>
|
||||
</div><!-- /emscripten bits -->
|
||||
<div>Most stuff on this page happens in the dev console.</div>
|
||||
<hr>
|
||||
<div id='test-output'></div>
|
||||
<!-- testing1.js "should" work with both sqlite3.js and sqlite3-kvvfs.js -->
|
||||
<!--script src="sqlite3-kvvfs.js"></script-->
|
||||
<script src="sqlite3.js"></script>
|
||||
<script src="common/SqliteTestUtil.js"></script>
|
||||
<script src="testing1.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
** 2022-10-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.
|
||||
**
|
||||
*************************************************************************
|
||||
** This file simply outputs sqlite3 version information in JSON form,
|
||||
** intended for embedding in the sqlite3 JS API build.
|
||||
*/
|
||||
#include "sqlite3.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void usage(const char *zAppName){
|
||||
puts("Emits version info about the sqlite3 it is built against.");
|
||||
printf("Usage: %s [--quote] --INFO-FLAG:\n\n", zAppName);
|
||||
puts(" --version Emit SQLITE_VERSION (3.X.Y)");
|
||||
puts(" --version-number Emit SQLITE_VERSION_NUMBER (30XXYYZZ)");
|
||||
puts(" --source-id Emit SQLITE_SOURCE_ID");
|
||||
puts(" --json Emit all info in JSON form");
|
||||
puts("\nThe non-JSON formats may be modified by:\n");
|
||||
puts(" --quote Add double quotes around output.");
|
||||
}
|
||||
|
||||
int main(int argc, char const * const * argv){
|
||||
int fJson = 0;
|
||||
int fVersion = 0;
|
||||
int fVersionNumber = 0;
|
||||
int fSourceInfo = 0;
|
||||
int fQuote = 0;
|
||||
int nFlags = 0;
|
||||
int i;
|
||||
|
||||
for( i = 1; i < argc; ++i ){
|
||||
const char * zArg = argv[i];
|
||||
while('-'==*zArg) ++zArg;
|
||||
if( 0==strcmp("version", zArg) ){
|
||||
fVersion = 1;
|
||||
}else if( 0==strcmp("version-number", zArg) ){
|
||||
fVersionNumber = 1;
|
||||
}else if( 0==strcmp("source-id", zArg) ){
|
||||
fSourceInfo = 1;
|
||||
}else if( 0==strcmp("json", zArg) ){
|
||||
fJson = 1;
|
||||
}else if( 0==strcmp("quote", zArg) ){
|
||||
fQuote = 1;
|
||||
--nFlags;
|
||||
}else{
|
||||
printf("Unhandled flag: %s\n", argv[i]);
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
++nFlags;
|
||||
}
|
||||
|
||||
if( 0==nFlags ) fJson = 1;
|
||||
if( fJson ){
|
||||
printf("{\"libVersion\": \"%s\", "
|
||||
"\"libVersionNumber\": %d, "
|
||||
"\"sourceId\": \"%s\"}"/*missing newline is intentional*/,
|
||||
SQLITE_VERSION,
|
||||
SQLITE_VERSION_NUMBER,
|
||||
SQLITE_SOURCE_ID);
|
||||
}else{
|
||||
if(fQuote) printf("%c", '"');
|
||||
if( fVersion ){
|
||||
printf("%s", SQLITE_VERSION);
|
||||
}else if( fVersionNumber ){
|
||||
printf("%d", SQLITE_VERSION_NUMBER);
|
||||
}else if( fSourceInfo ){
|
||||
printf("%s", SQLITE_SOURCE_ID);
|
||||
}
|
||||
if(fQuote) printf("%c", '"');
|
||||
puts("");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+18
-29
@@ -7,32 +7,26 @@
|
||||
########################################################################
|
||||
MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST))
|
||||
|
||||
sqlite3-wasmfs.js := sqlite3-wasmfs.js
|
||||
sqlite3-wasmfs.wasm := sqlite3-wasmfs.wasm
|
||||
sqlite3-wasmfs.wasm.c := $(dir.api)/sqlite3-wasm.c
|
||||
# Maintenance reminder: these particular files cannot be built into a
|
||||
# subdirectory because loading of the auxiliary
|
||||
# sqlite3-wasmfs.worker.js file it creates fails if sqlite3-wasmfs.js
|
||||
# is loaded from any directory other than the one in which the
|
||||
# containing HTML lives.
|
||||
dir.wasmfs := $(dir.wasm)
|
||||
sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js
|
||||
sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm
|
||||
|
||||
CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \
|
||||
$(subst .js,.worker.js,$(sqlite3-wasmfs.js))
|
||||
|
||||
########################################################################
|
||||
# emcc flags for .c/.o/.wasm.
|
||||
sqlite3-wasmfs.flags =
|
||||
#sqlite3-wasmfs.flags += -v # _very_ loud but also informative about what it's doing
|
||||
|
||||
########################################################################
|
||||
# emcc flags for .c/.o.
|
||||
sqlite3-wasmfs.cflags :=
|
||||
sqlite3-wasmfs.cflags += -std=c99 -fPIC
|
||||
sqlite3-wasmfs.cflags += -pthread
|
||||
sqlite3-wasmfs.cflags += -I. -I.. -I$(dir.top)
|
||||
sqlite3-wasmfs.cflags += $(cflags.common)
|
||||
sqlite3-wasmfs.cflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS
|
||||
|
||||
sqlite3-wasmfs.extra.c :=
|
||||
ifeq (1,1)
|
||||
# To get testing1.js to run with $(sqlite3-wasmfs.js) we need...
|
||||
sqlite3-wasmfs.extra.c += $(jaccwabyt_test.c)
|
||||
endif
|
||||
|
||||
########################################################################
|
||||
# emcc flags specific to building the final .js/.wasm file...
|
||||
sqlite3-wasmfs.jsflags := -fPIC
|
||||
@@ -42,12 +36,7 @@ sqlite3-wasmfs.jsflags += -sMODULARIZE
|
||||
sqlite3-wasmfs.jsflags += -sSTRICT_JS
|
||||
sqlite3-wasmfs.jsflags += -sDYNAMIC_EXECUTION=0
|
||||
sqlite3-wasmfs.jsflags += -sNO_POLYFILL
|
||||
ifeq (,$(sqlite3-wasmfs.extra.c))
|
||||
sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api
|
||||
else
|
||||
# need more exports for jaccwabyt test code...
|
||||
sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api
|
||||
endif
|
||||
sqlite3-wasmfs.jsflags += -sEXPORTED_FUNCTIONS=@$(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-api)
|
||||
sqlite3-wasmfs.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory,allocateUTF8OnStack
|
||||
# wasmMemory ==> for -sIMPORTED_MEMORY
|
||||
# allocateUTF8OnStack ==> wasmfs internals
|
||||
@@ -78,17 +67,17 @@ sqlite3-wasmfs.jsflags += $(sqlite3-wasmfs.fsflags)
|
||||
sqlite3-wasmfs.jsflags += -sWASM_BIGINT=$(emcc_enable_bigint)
|
||||
$(eval $(call call-make-pre-js,sqlite3-wasmfs))
|
||||
sqlite3-wasmfs.jsflags += $(pre-post-common.flags) $(pre-post-sqlite3-wasmfs.flags)
|
||||
$(sqlite3-wasmfs.js): $(sqlite3-wasmfs.wasm.c) $(sqlite3-wasm.c) $(sqlite3-wasmfs.extra.c) \
|
||||
EXPORTED_FUNCTIONS.api $(MAKEFILE) $(MAKEFILE.wasmfs) \
|
||||
$(sqlite3-wasmfs.js): $(sqlite3-wasm.c) \
|
||||
$(EXPORTED_FUNCTIONS.api) $(MAKEFILE) $(MAKEFILE.wasmfs) \
|
||||
$(pre-post-sqlite3-wasmfs.deps)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \
|
||||
$(sqlite3-wasmfs.cflags) $(sqlite3-wasmfs.jsflags) \
|
||||
$(sqlite3-wasmfs.wasm.c) $(sqlite3-wasmfs.extra.c)
|
||||
$(sqlite3-wasm.c)
|
||||
chmod -x $(sqlite3-wasmfs.wasm)
|
||||
$(maybe-wasm-strip) $(sqlite3-wasmfs.wasm)
|
||||
@ls -la $@ $(sqlite3-wasmfs.wasm)
|
||||
|
||||
$(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.js)
|
||||
wasmfs: $(sqlite3-wasmfs.js)
|
||||
all: wasmfs
|
||||
|
||||
@@ -96,22 +85,22 @@ all: wasmfs
|
||||
# speedtest1 for wasmfs. Re. sqlite3-wasm.o vs sqlite3-wasm.c:
|
||||
# building against the latter (predictably) results in a slightly
|
||||
# faster binary.
|
||||
speedtest1-wasmfs.js := speedtest1-wasmfs.js
|
||||
speedtest1-wasmfs.js := $(dir.wasmfs)/speedtest1-wasmfs.js
|
||||
speedtest1-wasmfs.wasm := $(subst .js,.wasm,$(speedtest1-wasmfs.js))
|
||||
speedtest1-wasmfs.eflags := $(sqlite3-wasmfs.fsflags)
|
||||
speedtest1-wasmfs.eflags += $(SQLITE_OPT) -DSQLITE_WASM_WASMFS
|
||||
$(eval $(call call-make-pre-js,speedtest1-wasmfs))
|
||||
$(speedtest1-wasmfs.js): $(speedtest1.cs) $(sqlite3-wasmfs.js) \
|
||||
$(speedtest1-wasmfs.js): $(speedtest1.cses) $(sqlite3-wasmfs.js) \
|
||||
$(MAKEFILE) $(MAKEFILE.wasmfs) \
|
||||
$(pre-post-speedtest1-wasmfs.deps) \
|
||||
EXPORTED_FUNCTIONS.speedtest1
|
||||
$(EXPORTED_FUNCTIONS.speedtest1)
|
||||
@echo "Building $@ ..."
|
||||
$(emcc.bin) \
|
||||
$(speedtest1-wasmfs.eflags) $(speedtest1-common.eflags) \
|
||||
$(pre-post-speedtest1-wasmfs.flags) \
|
||||
$(speedtest1.cflags) \
|
||||
$(sqlite3-wasmfs.cflags) \
|
||||
-o $@ $(speedtest1.cs) -lm
|
||||
-o $@ $(speedtest1.cses) -lm
|
||||
$(maybe-wasm-strip) $(speedtest1-wasmfs.wasm)
|
||||
ls -la $@ $(speedtest1-wasmfs.wasm)
|
||||
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
# PRAGMA application_id = INTEGER;
|
||||
#
|
||||
# INTEGER can be any signed 32-bit integer. That integer is written as
|
||||
# a 4-byte big-endian integer into offset 68 of the database header.
|
||||
# a 4-byte big-endian integer into offset 68 of the database header.
|
||||
#
|
||||
# The Monotone application used "PRAGMA user_version=1598903374;" to set
|
||||
# its identifier long before "PRAGMA application_id" became available.
|
||||
# The user_version is very similar to application_id except that it is
|
||||
# stored at offset 68 instead of offset 60. The application_id pragma
|
||||
# stored at offset 60 instead of offset 68. The application_id pragma
|
||||
# is preferred. The rule using offset 60 for Monotone is for historical
|
||||
# compatibility only.
|
||||
#
|
||||
0 string =SQLite\ format\ 3
|
||||
>68 belong =0x0f055112 Fossil checkout -
|
||||
>68 belong =0x0f055113 Fossil global configuration -
|
||||
>68 belong =0x0f055112 Fossil checkout -
|
||||
>68 belong =0x0f055113 Fossil global configuration -
|
||||
>68 belong =0x0f055111 Fossil repository -
|
||||
>68 belong =0x42654462 Bentley Systems BeSQLite Database -
|
||||
>68 belong =0x42654c6e Bentley Systems Localization File -
|
||||
@@ -29,4 +29,5 @@
|
||||
>68 belong =0x47503130 OGC GeoPackage version 1.0 file -
|
||||
>68 belong =0x45737269 Esri Spatially-Enabled Database -
|
||||
>68 belong =0x4d504258 MBTiles tileset -
|
||||
>68 belong =0x6a035744 TeXnicard card database
|
||||
>0 string =SQLite SQLite3 database
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
C Move\sfile\s/ext/misc/dbdata.c\sto\sthe\s/ext/recover/\sdirectory.
|
||||
D 2022-10-19T18:03:39.271
|
||||
C Merge\slatest\strunk\schanges\swith\sthis\sbranch.
|
||||
D 2022-10-25T11:05:31.760
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@@ -385,7 +385,7 @@ F ext/rbu/rbuvacuum4.test a78898e438a44803eb2bc897ba3323373c9f277418e2d6d76e90f2
|
||||
F ext/rbu/sqlite3rbu.c 8737cabdfbee84bb25a7851ecef8b1312be332761238da9be6ddb10c62ad4291
|
||||
F ext/rbu/sqlite3rbu.h 1dc88ab7bd32d0f15890ea08d23476c4198d3da3056985403991f8c9cd389812
|
||||
F ext/rbu/test_rbu.c 03f6f177096a5f822d68d8e4069ad8907fe572c62ff2d19b141f59742821828a
|
||||
F ext/recover/dbdata.c ca7b235fa2396e8fc2e950826872f820f31268ac2cb51368b0d655bb71568f07 w ext/misc/dbdata.c
|
||||
F ext/recover/dbdata.c ca7b235fa2396e8fc2e950826872f820f31268ac2cb51368b0d655bb71568f07
|
||||
F ext/recover/recover1.test 93acc42f95259f8b34050ad75873685a305da76d6cb1727d003f45157a4a6402
|
||||
F ext/recover/recover_common.tcl 6679af7dffc858e345053a91c9b0a897595b4a13007aceffafca75304ccb137c
|
||||
F ext/recover/recoverclobber.test 294dcc894124ab4ca3a7b35766630742a3d25810fceac22220beb64f70a33a60
|
||||
@@ -412,7 +412,7 @@ F ext/repair/test/checkindex01.test b530f141413b587c9eb78ff734de6bb79bc3515c3350
|
||||
F ext/repair/test/test.tcl 686d76d888dffd021f64260abf29a55c57b2cedfa7fc69150b42b1d6119aac3c
|
||||
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
|
||||
F ext/rtree/geopoly.c bb0dcd013dbb3fe0335b6bbae0d9c29fcfffda93d5ef6c31daa47e802132e435
|
||||
F ext/rtree/rtree.c d7b4b8b81d8d54376a7f81de5be85ec58b37c11604bcf42984a8418b34158d93
|
||||
F ext/rtree/rtree.c b963ebced19f249d8523396a779351481d13a67c36c3c1f034b982886cd39a42
|
||||
F ext/rtree/rtree.h 4a690463901cb5e6127cf05eb8e642f127012fd5003830dbc974eca5802d9412
|
||||
F ext/rtree/rtree1.test d47f58832145fcfed9067bc457ca8664962196c4566c17a1ebd679367db55d11
|
||||
F ext/rtree/rtree2.test 9d9deddbb16fd0c30c36e6b4fdc3ee3132d765567f0f9432ee71e1303d32603d
|
||||
@@ -487,70 +487,73 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3
|
||||
F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
|
||||
F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb
|
||||
F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
|
||||
F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle 0e88c8cfc3719e4b7e74980d9da664c709e68acf863e48386cda376edfd3bfb0
|
||||
F ext/wasm/GNUmakefile 4ec270532b921c7c4b437fbdb06f6a0ce41f3bd874395ce70dbc933c8553efa9
|
||||
F ext/wasm/GNUmakefile 72f8ca582578295315f9f198f308b927e64e8657e2b14f738123745043db7c7c
|
||||
F ext/wasm/README-dist.txt e78e44a58772d5b5d7a5a179b5bf639cd67b62249aac66138e2c319bd02dd243
|
||||
F ext/wasm/README.md 1e5b28158b74ab3ffc9d54fcbc020f0bbeb82c2ff8bbd904214c86c70e8a3066
|
||||
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 89983a8d122c35a90c65ec667844b95a78bcd04f3198a99c1e0c8368c1a0b03a
|
||||
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 36f413ab4dbb057d2dec938fb366ac0a4c5e85ba14660a8d672f0277602c0fc5
|
||||
F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287
|
||||
F ext/wasm/api/README.md 62758e8dd98741d41505f69130cc767013d2e871ebb9e4313d8f8b97d95071d8
|
||||
F ext/wasm/api/extern-post-js.js dc68cbf552d8ea085181400a6963907c32e0b088b03ffd8969b1869fea246629
|
||||
F ext/wasm/api/extern-pre-js.js 20143b16b672d0a576fbf768a786d12ee1f84e222126477072389b992542a5b2
|
||||
F ext/wasm/api/post-js-footer.js b64319261d920211b8700004d08b956a6c285f3b0bba81456260a713ed04900c
|
||||
F ext/wasm/api/README.md 1350088aee90e959ad9a94fab1bb6bcb5e99d4d27f976db389050f54f2640c78
|
||||
F ext/wasm/api/extern-post-js.js 926d192b72fa808378e5e7843721dc7ba3908c163a0260e06d8aa501c12f5469
|
||||
F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41
|
||||
F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1
|
||||
F ext/wasm/api/post-js-header.js 2e5c886398013ba2af88028ecbced1e4b22dc96a86467f1ecc5ba9e64ef90a8b
|
||||
F ext/wasm/api/pre-js.js 2db711eb637991b383fc6b5c0f3df65ec48a7201e5730e304beba8de2d3f9b0b
|
||||
F ext/wasm/api/sqlite3-api-cleanup.js 5d22d1d3818ecacb23bfa223d5970cd0617d8cdbb48c8bc4bbd463f05b021a99
|
||||
F ext/wasm/api/sqlite3-api-glue.js 842dc03783aecc951a543a209523343a6fda9af258fb0bee08e8cc2dc3c4d8ae
|
||||
F ext/wasm/api/sqlite3-api-oo1.js 00f5cfce0989d2e08d7b21765d703c69234245d03a0cce8fcb32ccfcd53ffdbb
|
||||
F ext/wasm/api/sqlite3-api-opfs.js 5a8ab3b76880c8ada8710ca9ba1ca5b160872edfd8bd5322e4f179a7f41cc616
|
||||
F ext/wasm/api/sqlite3-api-prologue.js b7c82a22d50658a48463fa646a23135273bc2cfa843aedda32627ff281c12e4d
|
||||
F ext/wasm/api/sqlite3-api-worker1.js 7f4f46cb6b512a48572d7567233896e6a9c46570c44bdc3d13419730c7c221c8
|
||||
F ext/wasm/api/pre-js.js 151e0616614a49f3db19ed544fa13b38c87c108959fbcd4029ea8399a562d94f
|
||||
F ext/wasm/api/sqlite3-api-cleanup.js 4d07a7524dc9b7b050acfde57163e839243ad2383bd7ee0de0178b1b3e988588
|
||||
F ext/wasm/api/sqlite3-api-glue.js 6e4e472eb5afc732a695cd7c5ded6dee6ef8b480e61aa0d648a3fc9033c84745
|
||||
F ext/wasm/api/sqlite3-api-oo1.js ca41ffe58bfbbefc98181081fba0b7af58afcc2770e963558f4f6a408c583fc0
|
||||
F ext/wasm/api/sqlite3-api-opfs.js 62da8b7cac30d4e7bb940762d2ac948b0aeb89704a5a290b74eb268ecbd1a64e
|
||||
F ext/wasm/api/sqlite3-api-prologue.js fa00d55f927e5a4ec51cf2c80f6f0eaed2f4f5774341ecf3d63a0ea4c738f8f5
|
||||
F ext/wasm/api/sqlite3-api-worker1.js a7f38f03275d6c27ab2aef3e83215d3c97ce09c43e6904df47c3764d9d4572b4
|
||||
F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3
|
||||
F ext/wasm/api/sqlite3-opfs-async-proxy.js f04cb1eb483c92bc61fe02749f7afcf17ec803968171aedd7d96faf428c26bcb w ext/wasm/sqlite3-opfs-async-proxy.js
|
||||
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
|
||||
F ext/wasm/api/sqlite3-wasm.c 4c131945ced4b08a694d287abcdb066b896d961ef79ee5241805ecc37e83d63a
|
||||
F ext/wasm/batch-runner.html cf1a410c92bad50fcec2ddc71390b4e9df63a6ea1bef12a5163a66a0af4d78d9
|
||||
F ext/wasm/api/sqlite3-wasm.c 940d576bda7068ba60492e206d06a3567b8a89a3770700aa88690a6e246a0c78
|
||||
F ext/wasm/api/sqlite3-worker1-promiser.js 0c7a9826dbf82a5ed4e4f7bf7816e825a52aff253afbf3350431f5773faf0e4b w ext/wasm/sqlite3-worker1-promiser.js
|
||||
F ext/wasm/api/sqlite3-worker1.js dbe54b69c1520a2d25eae148cd2750ded2dd7f219ea4ee46f83e0a851dca5974 w ext/wasm/sqlite3-worker1.js
|
||||
F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8
|
||||
F ext/wasm/batch-runner.js 5bae81684728b6be157d1f92b39824153f0fd019345b39f2ab8930f7ee2a57d8
|
||||
F ext/wasm/common/SqliteTestUtil.js 647bf014bd30bdd870a7e9001e251d12fc1c9ec9ce176a1004b838a4b33c5c05
|
||||
F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
|
||||
F ext/wasm/common/testing.css 53394885077edd3db22d2a0896192334dfc06fb3d1da0b646eb12a332d22f18e
|
||||
F ext/wasm/common/testing.css 739b58c44511f642f16f57b701c84dc9ee412d8bc47b3d8a99d947babfa69d9d
|
||||
F ext/wasm/common/whwasmutil.js 50d2ede0b0fa01c1d467e1801fab79f5e46bb02bcbd2b0232e4fdc6090a47818
|
||||
F ext/wasm/demo-123-worker.html e50b51dc7271b9d3cc830cb7c2fba294d622f56b7acb199f7257d11195a63d49
|
||||
F ext/wasm/demo-123.html 7c239c9951d1b113f9f532969ac039294cf1dcfee2b3ae0a2c1ed2b3d59f8dfa
|
||||
F ext/wasm/demo-123.js d563cf9d725692ccd940c46df1c026d87863e0544942a2ba2015f17fba3f6f74
|
||||
F ext/wasm/demo-kvvfs1.html 7d4f28873de67f51ac18c584b7d920825139866a96049a49c424d6f5a0ea5e7f
|
||||
F ext/wasm/demo-kvvfs1.js 105596bd2ccd0b1deb5fde8e99b536e8242d4bb5932fac0c8403ff3a6bc547e8
|
||||
F ext/wasm/fiddle.make 3f4efd62bc2a9c883bfcea52ae2755114a62d444d6d042df287f4aef301d6c6c
|
||||
F ext/wasm/demo-123-worker.html a0b58d9caef098a626a1a1db567076fca4245e8d60ba94557ede8684350a81ed
|
||||
F ext/wasm/demo-123.html 8c70a412ce386bd3796534257935eb1e3ea5c581e5d5aea0490b8232e570a508
|
||||
F ext/wasm/demo-123.js ebae30756585bca655b4ab2553ec9236a87c23ad24fc8652115dcedb06d28df6
|
||||
F ext/wasm/demo-jsstorage.html 409c4be4af5f207fb2877160724b91b33ea36a3cd8c204e8da1acb828ffe588e w ext/wasm/demo-kvvfs1.html
|
||||
F ext/wasm/demo-jsstorage.js 105596bd2ccd0b1deb5fde8e99b536e8242d4bb5932fac0c8403ff3a6bc547e8 w ext/wasm/demo-kvvfs1.js
|
||||
F ext/wasm/demo-worker1-promiser.html 1de7c248c7c2cfd4a5783d2aa154bce62d74c6de98ab22f5786620b3354ed15f w ext/wasm/testing-worker1-promiser.html
|
||||
F ext/wasm/demo-worker1-promiser.js f68ffbbe1c6086e18ce7961b8fc2b40dd88db174f59052e228c06b07484945ca w ext/wasm/testing-worker1-promiser.js
|
||||
F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2eb1ab2c68ef5d w ext/wasm/testing2.html
|
||||
F ext/wasm/demo-worker1.js 8ba51d94c4601fa5c313d9e59b63b238f5305b5d5739ad21f4782a0161e6682e w ext/wasm/testing2.js
|
||||
F ext/wasm/dist.make b3b156061ff6a35ce59715632c9446cb58e0fc497021a93c778fed051a04fde1
|
||||
F ext/wasm/fiddle.make acdb1a402864f9b05a4c89805c5e91d88f5080652d8861f0865655b172243847
|
||||
F ext/wasm/fiddle/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
|
||||
F ext/wasm/fiddle/fiddle-worker.js 531859a471924a0ea48afa218e6877f0c164ca324d51e15843ed6ecc1c65c7ee
|
||||
F ext/wasm/fiddle/fiddle-worker.js 7ee53ca846071de5d46bb11a2a269a7990ef9cfd8abfae2a25cc948499783d78
|
||||
F ext/wasm/fiddle/fiddle.html 5daf54e8f3d7777cbb1ca4f93affe28858dbfff25841cb4ab81d694efed28ec2
|
||||
F ext/wasm/fiddle/fiddle.js 974b995119ac443685d7d94d3b3c58c6a36540e9eb3fed7069d5653284071715
|
||||
F ext/wasm/index.html 9ae9f9629310ed3ee88901aa14e20195815583806af245da08c2ecb43ced2243
|
||||
F ext/wasm/index-dist.html cb0da16cba0f21cda2c25724c5869102d48eb0af04446acd3cd0ca031f80ed19
|
||||
F ext/wasm/index.html 751bbf248ee3106cec92cc4e6e3f703cd5c94deff3c6b7a596154fb04ab3efac
|
||||
F ext/wasm/jaccwabyt/jaccwabyt.js 0d7f32817456a0f3937fcfd934afeb32154ca33580ab264dab6c285e6dbbd215
|
||||
F ext/wasm/jaccwabyt/jaccwabyt.md 9aa6951b529a8b29f578ec8f0355713c39584c92cf1708f63ba0cf917cb5b68e
|
||||
F ext/wasm/scratchpad-wasmfs-main.html 20cf6f1a8f368e70d01e8c17200e3eaa90f1c8e1029186d836d14b83845fbe06
|
||||
F ext/wasm/scratchpad-wasmfs-main.js 1aa32c1035cf1440a226a28fefcbb5762fbbcb020ccbe5895f8736d701695c63
|
||||
F ext/wasm/speedtest1-wasmfs.html bc28eb29b69a73864b8d7aae428448f8b7e1de81d8bfb9bba99541322054dbd0
|
||||
F ext/wasm/speedtest1-worker.html 17f5b3f0ddb361ea0fdfd58703e42d65b1564c297930ec5fff2cd267e6e252d9
|
||||
F ext/wasm/speedtest1-worker.js a9e3d052dd1d8016d6e9a641e596e6d99aec04ef8995d7ee9a85a9964eed771a
|
||||
F ext/wasm/speedtest1.html e4cb5d722b494104fc1249e7c008ca018f820a784833c51004c958c71038c80f
|
||||
F ext/wasm/speedtest1-worker.html 7b0cceab6a68b2883738e19f61d21620fe1244ba36c1b2e38d0efde57ecce86d
|
||||
F ext/wasm/speedtest1-worker.js 490844a70af72d7bb16cc766d66621c1ca587d8a3f7e6b804c69327fa34881f7
|
||||
F ext/wasm/speedtest1.html 6303e620162b2058d5e212f966a7caed4a31a516b6140fbc64185cb296218e4f
|
||||
F ext/wasm/split-speedtest1-script.sh a3e271938d4d14ee49105eb05567c6a69ba4c1f1293583ad5af0cd3a3779e205 x
|
||||
F ext/wasm/sql/000-mandelbrot.sql 775337a4b80938ac8146aedf88808282f04d02d983d82675bd63d9c2d97a15f0
|
||||
F ext/wasm/sql/001-sudoku.sql 35b7cb7239ba5d5f193bc05ec379bcf66891bce6f2a5b3879f2f78d0917299b5
|
||||
F ext/wasm/sqlite3-opfs-async-proxy.js 206ce6bbc3c30ad51a37d9c25e3a2712e70b586e0f9a2cf8cb0b9619017c2671
|
||||
F ext/wasm/sqlite3-worker1-promiser.js 307d7837420ca6a9d3780dfc81194f1c0715637e6d9540e935514086b96913d8
|
||||
F ext/wasm/sqlite3-worker1.js 466e9bd39409ab03f3e00999887aaffc11e95b416e2689596e3d7f1516673fdf
|
||||
F ext/wasm/test-opfs-vfs.html eb69dda21eb414b8f5e3f7c1cc0f774103cc9c0f87b2d28a33419e778abfbab5
|
||||
F ext/wasm/test-opfs-vfs.js 56c3d725044c668fa7910451e96c1195d25ad95825f9ac79f747a7759d1973d0
|
||||
F ext/wasm/tester1-worker.html 0af7a22025ff1da72a84765d64f8f221844a57c6e6e314acf3a30f176101fd3f
|
||||
F ext/wasm/tester1.html fde0e0bdeaaa2c39877c749dc86a8c1c306f771c3d75b89a6289a5ed11243e9d
|
||||
F ext/wasm/tester1.js d6a66fc36c7571b8050314b6d0e93e69cd6def88df14fb3ef2403e7aa244ec36
|
||||
F ext/wasm/testing-worker1-promiser.html 6eaec6e04a56cf24cf4fa8ef49d78ce8905dde1354235c9125dca6885f7ce893
|
||||
F ext/wasm/testing-worker1-promiser.js bd788e33c1807e0a6dda9c9a9d784bd3350ca49c9dd8ae2cc8719b506b6e013e
|
||||
F ext/wasm/testing1.html 50575755e43232dbe4c2f97c9086b3118eb91ec2ee1fae931e6d7669fb17fcae
|
||||
F ext/wasm/testing2.html a66951c38137ff1d687df79466351f3c734fa9c6d9cce71d3cf97c291b2167e3
|
||||
F ext/wasm/testing2.js 88f40ef3cd8201bdadd120a711c36bbf0ce56cc0eab1d5e7debb71fed7822494
|
||||
F ext/wasm/wasmfs.make 3cce1820006196de140f90f2da4b4ea657083fb5bfee7d125be43f7a85748c8f
|
||||
F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555e685bce3da8c3f
|
||||
F ext/wasm/test-opfs-vfs.js 48fc59110e8775bb43c9be25b6d634fc07ebadab7da8fbd44889e8129c6e2548
|
||||
F ext/wasm/tester1-worker.html d02b9d38876b023854cf8955e77a40912f7e516956b4dbe1ec7f215faac273ee
|
||||
F ext/wasm/tester1.html c6c47e5a8071eb09cb1301104435c8e44fbb5719c92411f5b2384a461f9793c5
|
||||
F ext/wasm/tester1.js 12741d4ff6015fc14fa9a397e6f9130bbda699067bbceca23d5a228138271735
|
||||
F ext/wasm/version-info.c 5fa356d38859d71a0369b5c37e1935def7413fcc8a4e349a39d9052c1d0479f4
|
||||
F ext/wasm/wasmfs.make ee0004813e16c283ff633e08b482008d56adf9b7d42f6c5612f7ab002b924f69
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
|
||||
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
|
||||
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
|
||||
F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0
|
||||
F main.mk d5fdf519235d657a3b87d70324f8ee1f057207626e5ab4daf23a0199d20a25ad
|
||||
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
|
||||
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
|
||||
@@ -565,7 +568,7 @@ F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
|
||||
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
|
||||
F sqlite_cfg.h.in baf2e409c63d4e7a765e17769b6ff17c5a82bbd9cbf1e284fd2e4cefaff3fcf2
|
||||
F src/alter.c 0390ca1d69ec3626cfa9f153114b7ab233e6b2bada6a9eb91361ed385fe90deb
|
||||
F src/analyze.c aabdf3769c7fd9954a8ec508eb7041ae174b66f88d12c47199fabbea9a646467
|
||||
F src/analyze.c d2fce73f6a024897593012c6ca25368629fa4aeb49960d88a52fac664582e483
|
||||
F src/attach.c 4431f82f0247bf3aaf91589acafdff77d1882235c95407b36da1585c765fbbc8
|
||||
F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf
|
||||
F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7
|
||||
@@ -574,15 +577,15 @@ F src/btmutex.c 6ffb0a22c19e2f9110be0964d0731d2ef1c67b5f7fabfbaeb7b9dabc4b7740ca
|
||||
F src/btree.c 74fc5f6a0577df703d6f98d0c51ee0d8d91d22dbc0ba86e42e056517e2b45576
|
||||
F src/btree.h 74d64b8f28cfa4a894d14d4ed64fa432cd697b98b61708d4351482ae15913e22
|
||||
F src/btreeInt.h 8ce1332edd89dfd2461d561ac10a0ab5601c8e06200cb5230596c3caaf54482e
|
||||
F src/build.c 6e3ee380a4f0ff95de4b53bf510f66600cff08e4e04b92e95fae789072563f8f
|
||||
F src/build.c d3e43e950e4e377c1d451a4862556792acdef1faba14a03f899d30d09731c48b
|
||||
F src/callback.c 4cd7225b26a97f7de5fee5ae10464bed5a78f2adefe19534cc2095b3a8ca484a
|
||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||
F src/ctime.c 428b47a2548c7c2c2f885189b42fdcc178fb03c276a2d58b3008b10da29373d5
|
||||
F src/ctime.c 20507cc0b0a6c19cd882fcd0eaeda32ae6a4229fb4b024cfdf3183043d9b703d
|
||||
F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5
|
||||
F src/dbpage.c 433f13b34f1e5a84cbb5f10214c12471c6f0197f276389634a1cc393ec821c3d
|
||||
F src/dbstat.c 861e08690fcb0f2ee1165eff0060ea8d4f3e2ea10f80dab7d32ad70443a6ff2d
|
||||
F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e
|
||||
F src/expr.c d199850a925665df7f8ac29fa938909f65a2bd32354aa206aa8c25fc74ff3d3d
|
||||
F src/expr.c 847f87d9df3ede2b2b0a8db088af0b9c1923b21009f8ea1b9b7b28cb0a383170
|
||||
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
|
||||
F src/fkey.c 722f20779f5342a787922deded3628d8c74b5249cab04098cf17ee2f2aaff002
|
||||
F src/func.c fe2a795ad647ce42054873ac91c43beb7b5d204892903a67f6e7e314379b9d4a
|
||||
@@ -591,7 +594,7 @@ F src/hash.c 8d7dda241d0ebdafb6ffdeda3149a412d7df75102cecfc1021c98d6219823b19
|
||||
F src/hash.h 3340ab6e1d13e725571d7cee6d3e3135f0779a7d8e76a9ce0a85971fa3953c51
|
||||
F src/hwtime.h cb1d7e3e1ed94b7aa6fde95ae2c2daccc3df826be26fc9ed7fd90d1750ae6144
|
||||
F src/in-operator.md 10cd8f4bcd225a32518407c2fb2484089112fd71
|
||||
F src/insert.c aea5361767817f917b0f0f647a1f0b1621bd858938ae6ae545c3b6b9814b798f
|
||||
F src/insert.c b972b1642cd0f7d5ae4964d713b65158a7bfa6a6e8786a9e8e57bd9c0b4a896d
|
||||
F src/json.c 7749b98c62f691697c7ee536b570c744c0583cab4a89200fdd0fc2aa8cc8cbd6
|
||||
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
|
||||
F src/loadext.c 8086232d10e51e183a7f64199815bad1c579896354db69435347665f62f481e9
|
||||
@@ -615,7 +618,7 @@ F src/os.c 81c9c1c52eab711e27e33fd51fe5788488d3a02bc1a71439857abbee5d0d2c97
|
||||
F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63
|
||||
F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
|
||||
F src/os_kv.c c3d991bfb6207560d3416bbf241cade7113e4ce852781c53b7e40a3d6ac25fcb
|
||||
F src/os_setup.h 0711dbc4678f3ac52d7fe736951b6384a0615387c4ba5135a4764e4e31f4b6a6
|
||||
F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d872107
|
||||
F src/os_unix.c 287aa5f5691a2b356780c63e83abaa33549add84227b8313395f04088486d79c
|
||||
F src/os_win.c 8d129ae3e59e0fa900e20d0ad789e96f2e08177f0b00b53cdda65c40331e0902
|
||||
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
|
||||
@@ -632,17 +635,17 @@ F src/printf.c e99ee9741e79ae3873458146f59644276657340385ade4e76a5f5d1c25793764
|
||||
F src/random.c 546d6feb15ec69c1aafe9bb351a277cbb498fd5410e646add673acb805714960
|
||||
F src/resolve.c efea4e5fbecfd6d0a9071b0be0d952620991673391b6ffaaf4c277b0bb674633
|
||||
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
|
||||
F src/select.c b795f31a326564ffc448bb26f863c64f0796b2a5e0585a3358aff7877b72ed82
|
||||
F src/shell.c.in d24655392a5be8143b8d29226856ba6528339355702b52e5a4c165e16c01ec8f
|
||||
F src/select.c e5b6f930f068c9c5362fc76c704ae5cb5ef1e3f18759c2126f23b0cf04c0e263
|
||||
F src/shell.c.in d28a758ea56a8e9f38e27112e8b32f94be98068c17a5e3d352c6c2da5066a1d0
|
||||
F src/sqlite.h.in d9c8a6243fc0a1c270d69db33758e34b810af3462f9bc5b4af113b347e07c69d
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h 5336beea1868d99d2f62e628dbea55e97267dbff8193291ab175e960c5df9141
|
||||
F src/sqliteInt.h d15694b228fe5082587e13ac14f3e449621a5fe6d5933f5dee6e3c9491260da3
|
||||
F src/sqliteInt.h 9a40d5b075cd2e78bac6f9ae724e3fa4281373cb728f961272cb182f6ba94ce6
|
||||
F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657
|
||||
F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749
|
||||
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
|
||||
F src/tclsqlite.c 4e64ba300a5a26e0f1170e09032429faeb65e45e8f3d1a7833e8edb69fc2979e
|
||||
F src/test1.c 1356984e97bff07e4a8cc3863e892f05b3348678a74783bb6f350b76316736f1
|
||||
F src/test1.c 790c8cd24d1ac39b8cf4e2f618ce16ecc028accfcde60660f7bd983e0f4c7d28
|
||||
F src/test2.c 3efb99ab7f1fc8d154933e02ae1378bac9637da5
|
||||
F src/test3.c 61798bb0d38b915067a8c8e03f5a534b431181f802659a6616f9b4ff7d872644
|
||||
F src/test4.c 4533b76419e7feb41b40582554663ed3cd77aaa54e135cf76b3205098cd6e664
|
||||
@@ -700,29 +703,29 @@ F src/tokenize.c 1305797eab3542a0896b552c6e7669c972c1468e11e92b370533c1f37a37082
|
||||
F src/treeview.c 07787f67cd297a6d09d04b8d70c06769c60c9c1d9080378f93929c16f8fd3298
|
||||
F src/trigger.c 4163ada044af89d51caba1cb713a73165347b2ec05fe84a283737c134d61fcd5
|
||||
F src/update.c 5b0302c47cf31b533d5dff04c497ca1d8b9d89c39727e633fbe7b882fd5ac5aa
|
||||
F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937
|
||||
F src/upsert.c 5303dc6c518fa7d4b280ec65170f465c7a70b7ac2b22491598f6d0b4875b3145
|
||||
F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0
|
||||
F src/util.c 0be191521ff6d2805995f4910f0b6231b42843678b2efdc1abecaf39929a673f
|
||||
F src/vacuum.c bb346170b0b54c6683bba4a5983aea40485597fdf605c87ec8bc2e199fe88cd8
|
||||
F src/vacuum.c 84ce7f01f8a7a08748e107a441db83bcec13970190ddcb0c9ff522adbc1c23fd
|
||||
F src/vdbe.c 0c7cb1b934ad8611e14e7efaf2c3a95df7dd3f7964d63ea07fef42a23df86131
|
||||
F src/vdbe.h 58675f47dcf3105bab182c3ad3726efd60ffd003e954386904ac9107d0d2b743
|
||||
F src/vdbeInt.h 17b7461ffcf9ee760d1341731715a419f6b8c763089a7ece25c2e8098d702b3f
|
||||
F src/vdbeapi.c 1e8713d0b653acb43cd1bdf579c40e005c4844ea90f414f065946a83db3c27fb
|
||||
F src/vdbeaux.c 6946c7082a0d61566794bd35253f0ccd013a9dba3f33488a23fd5360a5744e5b
|
||||
F src/vdbeaux.c 6d0a75c1fbc7efea6924f6895ebceca664001464bc7ac56949d3c60aa5e498a0
|
||||
F src/vdbeblob.c 5e61ce31aca17db8fb60395407457a8c1c7fb471dde405e0cd675974611dcfcd
|
||||
F src/vdbemem.c 6cfed43758d57b6e3b99d9cdedfeccd86e45a07e427b22d8487cbdbebb6c522a
|
||||
F src/vdbesort.c 43756031ca7430f7aec3ef904824a7883c4ede783e51f280d99b9b65c0796e35
|
||||
F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf823
|
||||
F src/vdbevtab.c f99b275366c5fc5e2d99f734729880994ab9500bdafde7fae3b02d562b9d323c
|
||||
F src/vtab.c bb53f9e2eaeecca07158643dd3d5039cf13b525fe2d267e113b39a36f374556c
|
||||
F src/vtab.c b2f993aa954078985bc40317bb2140fe0880a08a7440f3a428b60fce74636808
|
||||
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
|
||||
F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d
|
||||
F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a
|
||||
F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b
|
||||
F src/where.c 63e712bcad47f70e94c2150976cd7da5040933699e3938d4189d064acbe40891
|
||||
F src/whereInt.h 70cd30de9ed784aa33fa6bd1245f060617de7a00d992469b6d8e419eed915743
|
||||
F src/wherecode.c bb88be457df3a6a01c844074ab79a9ba74279e73185f1362383aa697e3cae5dc
|
||||
F src/whereexpr.c 55a39f42aaf982574fbf52906371a84cceed98a994422198dfd03db4fce4cc46
|
||||
F src/where.c 1ef5aae7fac877057b9f360f06b26d4275888460d8fb6e92bbb9e70e07afe946
|
||||
F src/whereInt.h df0c79388c0b71b4a91f480d02791679fe0345d40410435c541c8893e95a4d3f
|
||||
F src/wherecode.c 133a94f82858787217d073143617df19e4a6a7d0b771a1519f957608109ad5a5
|
||||
F src/whereexpr.c 05295b44b54eea76d1ba766f0908928d0e20e990c249344c9521454d3d09c7ae
|
||||
F src/window.c 928e215840e2f2d9a2746e018c9643ef42c66c4ab6630ef0df7fa388fa145e86
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627
|
||||
@@ -1161,7 +1164,7 @@ F test/fuzzdata8.db 653423800b7671e67caa740e977d80e1360f0d69e9992851f3ea5c4a69a2
|
||||
F test/fuzzer1.test 3d4c4b7e547aba5e5511a2991e3e3d07166cfbb8
|
||||
F test/fuzzer2.test a85ef814ce071293bce1ad8dffa217cbbaad4c14
|
||||
F test/fuzzerfault.test f64c4aef4c9e9edf1d6dc0d3f1e65dcc81e67c996403c88d14f09b74807a42bc
|
||||
F test/fuzzinvariants.c a91f439e512c72045bddaf0f0ee3b876b2fe645e076aefb085658f1337066f7e
|
||||
F test/fuzzinvariants.c 760a1004ae4c4cef398310631ea6d441c5e8297af0f688a2dc7a467afd22df33
|
||||
F test/gcfault.test dd28c228a38976d6336a3fc42d7e5f1ad060cb8c
|
||||
F test/gencol1.test cc0dbb0ee116e5602e18ea7d47f2a0f76b26e09a823b7c36ef254370c2b0f3c1
|
||||
F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98
|
||||
@@ -1240,7 +1243,7 @@ F test/joinC.test 1f1a602c2127f55f136e2cbd3bf2d26546614bf8cffe5902ec1ac9c07f87f2
|
||||
F test/joinD.test 2ce62e7353a0702ca5e70008faf319c1d4686aa19fba34275c6d1da0e960be28
|
||||
F test/joinE.test d5d182f3812771e2c0d97c9dcf5dbe4c41c8e21c82560e59358731c4a3981d6b
|
||||
F test/joinF.test 53dd66158806823ea680dd7543b5406af151b5aafa5cd06a7f3231cd94938127
|
||||
F test/joinH.test e67d1d6a8c7141caf981a07386caa7fda0362baa09e03669f9a4fbee812806d0
|
||||
F test/joinH.test 15f501b33d848521964afde9865a92aeca79c8c41fa84dc4dc3f865c9ed8c868
|
||||
F test/journal1.test c7b768041b7f494471531e17abc2f4f5ebf9e5096984f43ed17c4eb80ba34497
|
||||
F test/journal2.test 9dac6b4ba0ca79c3b21446bbae993a462c2397c4
|
||||
F test/journal3.test 7c3cf23ffc77db06601c1fcfc9743de8441cb77db9d1aa931863d94f5ffa140e
|
||||
@@ -1792,7 +1795,7 @@ F test/uri.test c1abaaaa28e9422d61e5f3f9cbc8ef993ec49fe802f581520731708561d49384
|
||||
F test/uri2.test 9d3ba7a53ee167572d53a298ee4a5d38ec4a8fb7
|
||||
F test/userauth01.test e740a2697a7b40d7c5003a7d7edaee16acd349a9
|
||||
F test/utf16align.test 9fde0bb5d3a821594aa68c6829ab9c5453a084384137ebb9f6153e2d678039da
|
||||
F test/vacuum-into.test f0b8c091df5305728b6973e9cce4166c861955b650dd3c599cb045d7160d3971
|
||||
F test/vacuum-into.test e0e3406845be4cf1b44db354179e5d9437e38bc267e4ac8e8dc617f9c3c903ab
|
||||
F test/vacuum.test ce91c39f7f91a4273bf620efad21086b5aa6ef1d
|
||||
F test/vacuum2.test 9fd45ce6ce29f5614c249e03938d3567c06a9e772d4f155949f8eafe2d8af520
|
||||
F test/vacuum3.test d9d9a04ee58c485b94694fd4f68cffaba49c32234fdefe1ac1a622c5e17d4ce3
|
||||
@@ -1894,6 +1897,7 @@ F test/wherefault.test 6cf2a9c5712952d463d3f45ebee7f6caf400984df51a195d884cfb7eb
|
||||
F test/wherelfault.test 9012e4ef5259058b771606616bd007af5d154e64cc25fa9fd4170f6411db44e3
|
||||
F test/wherelimit.test afb46397c6d7e964e6e294ba3569864a0c570fe3807afc634236c2b752372f31
|
||||
F test/wherelimit2.test 657a3f24aadee62d058c5091ea682dc4af4b95ffe32f137155be49799a58e721
|
||||
F test/widetab1.test c296a98e123762de79917350e45fa33fdf88577a2571eb3a64c8bf7e44ef74d1
|
||||
F test/win32heap.test 10fd891266bd00af68671e702317726375e5407561d859be1aa04696f2aeee74
|
||||
F test/win32lock.test e0924eb8daac02bf80e9da88930747bd44dd9b230b7759fed927b1655b467c9c
|
||||
F test/win32longpath.test 4baffc3acb2e5188a5e3a895b2b543ed09e62f7c72d713c1feebf76222fe9976
|
||||
@@ -1916,6 +1920,7 @@ F test/windowA.test 6d63dc1260daa17141a55007600581778523a8b420629f1282d2acfc36af
|
||||
F test/windowB.test f2fb42b864b0cf431c956407583e9478a74c3642bdf8737fdcb6ff4a40298b07
|
||||
F test/windowC.test 6fd75f5bb2f1343d34e470e36e68f0ff638d8a42f6aa7d99471261b31a0d42f2
|
||||
F test/windowD.test 65cf5a765fb8072450e8a0de2979ce7f09a38d87724fe1280c6444073e3da49b
|
||||
F test/windowE.test 6ba0c8048e4cc02b942e56640f8fcd50fd7ca72c876656c40f6baf42e316684c
|
||||
F test/windowerr.tcl f5acd6fbc210d7b5546c0e879d157888455cd4a17a1d3f28f07c1c8a387019e0
|
||||
F test/windowerr.test a8b752402109c15aa1c5efe1b93ccb0ce1ef84fa964ae1cd6684dd0b3cc1819b
|
||||
F test/windowfault.test 15094c1529424e62f798bc679e3fe9dfab6e8ba2f7dfe8c923b6248c31660a7c
|
||||
@@ -1972,7 +1977,7 @@ F tool/max-limits.c cbb635fbb37ae4d05f240bfb5b5270bb63c54439
|
||||
F tool/merge-test.tcl de76b62f2de2a92d4c1ca4f976bce0aea6899e0229e250479b229b2a1914b176
|
||||
F tool/mkautoconfamal.sh f62353eb6c06ab264da027fd4507d09914433dbdcab9cb011cdc18016f1ab3b8
|
||||
F tool/mkccode.tcl 86463e68ce9c15d3041610fedd285ce32a5cf7a58fc88b3202b8b76837650dbe x
|
||||
F tool/mkctimec.tcl 0e309dfc8bb01cd385deeb010df4ca76dee3ab4e8ec0588233b3f152679122e8 x
|
||||
F tool/mkctimec.tcl c185cf1bdcd3d9bd3c06f77a2fd2df8a4a0d07266f992ecda75286965ba3574c x
|
||||
F tool/mkkeywordhash.c 35bfc41adacc4aa6ef6fca7fd0c63e0ec0534b78daf4d0cfdebe398216bbffc3
|
||||
F tool/mkmsvcmin.tcl 6ecab9fe22c2c8de4d82d4c46797bda3d2deac8e763885f5a38d0c44a895ab33
|
||||
F tool/mkopcodec.tcl 33d20791e191df43209b77d37f0ff0904620b28465cca6990cf8d60da61a07ef
|
||||
@@ -2017,6 +2022,7 @@ F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaa
|
||||
F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848
|
||||
F tool/srcck1.c 371de5363b70154012955544f86fdee8f6e5326f
|
||||
F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43
|
||||
F tool/stripccomments.c 20b8aabc4694d0d4af5566e42da1f1a03aff057689370326e9269a9ddcffdc37
|
||||
F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d
|
||||
F tool/symbols.sh 1612bd947750e21e7b47befad5f6b3825b06cce0705441f903bf35ced65ae9b9
|
||||
F tool/varint.c 5d94cb5003db9dbbcbcc5df08d66f16071aee003
|
||||
@@ -2046,8 +2052,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P ff9a733532fe11bb253246b45a94681a174c976aafee5c780af571893e8ce694
|
||||
R 0b6e256547f11180eef1e8e83664e1a7
|
||||
P f6d5ac807efcf6140016a8b8f0c74566c0bfc98ad92bd8fca03c5cc80ebf3dec 9c8df130b8137cb4705f805907d1ff754d7f4b07bf181e1d05f1798b7aa5f4f6
|
||||
R aefb033a9d457cee43177faf9cf7bf53
|
||||
U dan
|
||||
Z 01393ff26cde3c9365efd46ef5c6323b
|
||||
Z 7900a9dad5f38f0d2a40413478423567
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
f6d5ac807efcf6140016a8b8f0c74566c0bfc98ad92bd8fca03c5cc80ebf3dec
|
||||
757e3f585959f4f113fee48fe3d504f037604c53a95c8d47ce5c2bccfb2af8ff
|
||||
@@ -953,6 +953,7 @@ static void analyzeVdbeCommentIndexWithColumnName(
|
||||
if( NEVER(i==XN_ROWID) ){
|
||||
VdbeComment((v,"%s.rowid",pIdx->zName));
|
||||
}else if( i==XN_EXPR ){
|
||||
assert( pIdx->bHasExpr );
|
||||
VdbeComment((v,"%s.expr(%d)",pIdx->zName, k));
|
||||
}else{
|
||||
VdbeComment((v,"%s.%s", pIdx->zName, pIdx->pTable->aCol[i].zCnName));
|
||||
|
||||
+5
-2
@@ -2276,7 +2276,8 @@ static int isDupColumn(Index *pIdx, int nKey, Index *pPk, int iCol){
|
||||
/* Recompute the colNotIdxed field of the Index.
|
||||
**
|
||||
** colNotIdxed is a bitmask that has a 0 bit representing each indexed
|
||||
** columns that are within the first 63 columns of the table. The
|
||||
** columns that are within the first 63 columns of the table and a 1 for
|
||||
** all other bits (all columns that are not in the index). The
|
||||
** high-order bit of colNotIdxed is always 1. All unindexed columns
|
||||
** of the table have a 1.
|
||||
**
|
||||
@@ -2304,7 +2305,7 @@ static void recomputeColumnsNotIndexed(Index *pIdx){
|
||||
}
|
||||
}
|
||||
pIdx->colNotIdxed = ~m;
|
||||
assert( (pIdx->colNotIdxed>>63)==1 );
|
||||
assert( (pIdx->colNotIdxed>>63)==1 ); /* See note-20221022-a */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4192,6 +4193,7 @@ void sqlite3CreateIndex(
|
||||
j = XN_EXPR;
|
||||
pIndex->aiColumn[i] = XN_EXPR;
|
||||
pIndex->uniqNotNull = 0;
|
||||
pIndex->bHasExpr = 1;
|
||||
}else{
|
||||
j = pCExpr->iColumn;
|
||||
assert( j<=0x7fff );
|
||||
@@ -4203,6 +4205,7 @@ void sqlite3CreateIndex(
|
||||
}
|
||||
if( pTab->aCol[j].colFlags & COLFLAG_VIRTUAL ){
|
||||
pIndex->bHasVCol = 1;
|
||||
pIndex->bHasExpr = 1;
|
||||
}
|
||||
}
|
||||
pIndex->aiColumn[i] = (i16)j;
|
||||
|
||||
@@ -193,6 +193,9 @@ static const char * const sqlite3azCompileOpt[] = {
|
||||
#ifdef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
|
||||
"DISABLE_SKIPAHEAD_DISTINCT",
|
||||
#endif
|
||||
#ifdef SQLITE_DQS
|
||||
"DQS=" CTIMEOPT_VAL(SQLITE_DQS),
|
||||
#endif
|
||||
#ifdef SQLITE_ENABLE_8_3_NAMES
|
||||
"ENABLE_8_3_NAMES=" CTIMEOPT_VAL(SQLITE_ENABLE_8_3_NAMES),
|
||||
#endif
|
||||
|
||||
+73
-27
@@ -55,9 +55,8 @@ char sqlite3ExprAffinity(const Expr *pExpr){
|
||||
if( op==TK_REGISTER ) op = pExpr->op2;
|
||||
if( op==TK_COLUMN || op==TK_AGG_COLUMN ){
|
||||
assert( ExprUseYTab(pExpr) );
|
||||
if( pExpr->y.pTab ){
|
||||
return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
|
||||
}
|
||||
assert( pExpr->y.pTab!=0 );
|
||||
return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
|
||||
}
|
||||
if( op==TK_SELECT ){
|
||||
assert( ExprUseXSelect(pExpr) );
|
||||
@@ -175,17 +174,14 @@ CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr){
|
||||
int op = p->op;
|
||||
if( op==TK_REGISTER ) op = p->op2;
|
||||
if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){
|
||||
int j;
|
||||
assert( ExprUseYTab(p) );
|
||||
if( p->y.pTab!=0 ){
|
||||
/* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
|
||||
** a TK_COLUMN but was previously evaluated and cached in a register */
|
||||
int j = p->iColumn;
|
||||
if( j>=0 ){
|
||||
const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
|
||||
pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
|
||||
}
|
||||
break;
|
||||
assert( p->y.pTab!=0 );
|
||||
if( (j = p->iColumn)>=0 ){
|
||||
const char *zColl = sqlite3ColumnColl(&p->y.pTab->aCol[j]);
|
||||
pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if( op==TK_CAST || op==TK_UPLUS ){
|
||||
p = p->pLeft;
|
||||
@@ -3790,10 +3786,7 @@ void sqlite3ExprCodeGetColumnOfTable(
|
||||
){
|
||||
Column *pCol;
|
||||
assert( v!=0 );
|
||||
if( pTab==0 ){
|
||||
sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut);
|
||||
return;
|
||||
}
|
||||
assert( pTab!=0 );
|
||||
if( iCol<0 || iCol==pTab->iPKey ){
|
||||
sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
|
||||
VdbeComment((v, "%s.rowid", pTab->zName));
|
||||
@@ -4043,6 +4036,53 @@ static int exprCodeInlineFunction(
|
||||
return target;
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to see if pExpr is one of the indexed expressions on pParse->pIdxExpr.
|
||||
** If it is, then resolve the expression by reading from the index and
|
||||
** return the register into which the value has been read. If pExpr is
|
||||
** not an indexed expression, then return negative.
|
||||
*/
|
||||
static SQLITE_NOINLINE int sqlite3IndexedExprLookup(
|
||||
Parse *pParse, /* The parsing context */
|
||||
Expr *pExpr, /* The expression to potentially bypass */
|
||||
int target /* Where to store the result of the expression */
|
||||
){
|
||||
IndexedExpr *p;
|
||||
Vdbe *v;
|
||||
for(p=pParse->pIdxExpr; p; p=p->pIENext){
|
||||
int iDataCur = p->iDataCur;
|
||||
if( iDataCur<0 ) continue;
|
||||
if( pParse->iSelfTab ){
|
||||
if( p->iDataCur!=pParse->iSelfTab-1 ) continue;
|
||||
iDataCur = -1;
|
||||
}
|
||||
if( sqlite3ExprCompare(0, pExpr, p->pExpr, iDataCur)!=0 ) continue;
|
||||
v = pParse->pVdbe;
|
||||
assert( v!=0 );
|
||||
if( p->bMaybeNullRow ){
|
||||
/* If the index is on a NULL row due to an outer join, then we
|
||||
** cannot extract the value from the index. The value must be
|
||||
** computed using the original expression. */
|
||||
int addr = sqlite3VdbeCurrentAddr(v);
|
||||
sqlite3VdbeAddOp3(v, OP_IfNullRow, p->iIdxCur, addr+3, target);
|
||||
VdbeCoverage(v);
|
||||
sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target);
|
||||
VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol));
|
||||
sqlite3VdbeGoto(v, 0);
|
||||
p = pParse->pIdxExpr;
|
||||
pParse->pIdxExpr = 0;
|
||||
sqlite3ExprCode(pParse, pExpr, target);
|
||||
pParse->pIdxExpr = p;
|
||||
sqlite3VdbeJumpHere(v, addr+2);
|
||||
}else{
|
||||
sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target);
|
||||
VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol));
|
||||
}
|
||||
return target;
|
||||
}
|
||||
return -1; /* Not found */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Generate code into the current Vdbe to evaluate the given
|
||||
@@ -4071,6 +4111,11 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
expr_code_doover:
|
||||
if( pExpr==0 ){
|
||||
op = TK_NULL;
|
||||
}else if( pParse->pIdxExpr!=0
|
||||
&& !ExprHasProperty(pExpr, EP_Leaf)
|
||||
&& (r1 = sqlite3IndexedExprLookup(pParse, pExpr, target))>=0
|
||||
){
|
||||
return r1;
|
||||
}else{
|
||||
assert( !ExprHasVVAProperty(pExpr,EP_Immutable) );
|
||||
op = pExpr->op;
|
||||
@@ -4116,11 +4161,8 @@ expr_code_doover:
|
||||
int aff;
|
||||
iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
|
||||
assert( ExprUseYTab(pExpr) );
|
||||
if( pExpr->y.pTab ){
|
||||
aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
|
||||
}else{
|
||||
aff = pExpr->affExpr;
|
||||
}
|
||||
assert( pExpr->y.pTab!=0 );
|
||||
aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
|
||||
if( aff>SQLITE_AFF_BLOB ){
|
||||
static const char zAff[] = "B\000C\000D\000E";
|
||||
assert( SQLITE_AFF_BLOB=='A' );
|
||||
@@ -4182,12 +4224,10 @@ expr_code_doover:
|
||||
}
|
||||
}
|
||||
assert( ExprUseYTab(pExpr) );
|
||||
assert( pExpr->y.pTab!=0 );
|
||||
iReg = sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
|
||||
pExpr->iColumn, iTab, target,
|
||||
pExpr->op2);
|
||||
if( pExpr->y.pTab==0 && pExpr->affExpr==SQLITE_AFF_REAL ){
|
||||
sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg);
|
||||
}
|
||||
return iReg;
|
||||
}
|
||||
case TK_INTEGER: {
|
||||
@@ -5570,7 +5610,13 @@ int sqlite3ExprCompare(
|
||||
if( pB->op==TK_COLLATE && sqlite3ExprCompare(pParse, pA,pB->pLeft,iTab)<2 ){
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
if( pA->op==TK_AGG_COLUMN && pB->op==TK_COLUMN
|
||||
&& pB->iTable<0 && pA->iTable==iTab
|
||||
){
|
||||
/* fall through */
|
||||
}else{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
assert( !ExprHasProperty(pA, EP_IntValue) );
|
||||
assert( !ExprHasProperty(pB, EP_IntValue) );
|
||||
@@ -5872,10 +5918,10 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
|
||||
assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
|
||||
assert( pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
|
||||
if( (pLeft->op==TK_COLUMN
|
||||
&& pLeft->y.pTab!=0
|
||||
&& ALWAYS(pLeft->y.pTab!=0)
|
||||
&& IsVirtual(pLeft->y.pTab))
|
||||
|| (pRight->op==TK_COLUMN
|
||||
&& pRight->y.pTab!=0
|
||||
&& ALWAYS(pRight->y.pTab!=0)
|
||||
&& IsVirtual(pRight->y.pTab))
|
||||
){
|
||||
return WRC_Prune;
|
||||
|
||||
@@ -96,6 +96,7 @@ const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
|
||||
aff = SQLITE_AFF_INTEGER;
|
||||
}else{
|
||||
assert( x==XN_EXPR );
|
||||
assert( pIdx->bHasExpr );
|
||||
assert( pIdx->aColExpr!=0 );
|
||||
aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr);
|
||||
}
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@
|
||||
# define SQLITE_OS_WIN 0
|
||||
# define SQLITE_OMIT_LOAD_EXTENSION 1
|
||||
# define SQLITE_OMIT_WAL 1
|
||||
# define SQLITE_OMIT DEPRECATED 1
|
||||
# define SQLITE_OMIT_DEPRECATED 1
|
||||
# undef SQLITE_TEMP_STORE
|
||||
# define SQLITE_TEMP_STORE 3 /* Always use memory for temporary storage */
|
||||
# define SQLITE_DQS 0
|
||||
|
||||
+6
-6
@@ -4619,7 +4619,7 @@ static int flattenSubquery(
|
||||
pSub->pLimit = 0;
|
||||
}
|
||||
|
||||
/* Recompute the SrcList_item.colUsed masks for the flattened
|
||||
/* Recompute the SrcItem.colUsed masks for the flattened
|
||||
** tables. */
|
||||
for(i=0; i<nSubSrc; i++){
|
||||
recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]);
|
||||
@@ -5607,9 +5607,9 @@ void sqlite3SelectPopWith(Walker *pWalker, Select *p){
|
||||
#endif
|
||||
|
||||
/*
|
||||
** The SrcList_item structure passed as the second argument represents a
|
||||
** The SrcItem structure passed as the second argument represents a
|
||||
** sub-query in the FROM clause of a SELECT statement. This function
|
||||
** allocates and populates the SrcList_item.pTab object. If successful,
|
||||
** allocates and populates the SrcItem.pTab object. If successful,
|
||||
** SQLITE_OK is returned. Otherwise, if an OOM error is encountered,
|
||||
** SQLITE_NOMEM.
|
||||
*/
|
||||
@@ -6442,7 +6442,7 @@ static void havingToWhere(Parse *pParse, Select *p){
|
||||
|
||||
/*
|
||||
** Check to see if the pThis entry of pTabList is a self-join of a prior view.
|
||||
** If it is, then return the SrcList_item for the prior view. If it is not,
|
||||
** If it is, then return the SrcItem for the prior view. If it is not,
|
||||
** then return 0.
|
||||
*/
|
||||
static SrcItem *isSelfJoinView(
|
||||
@@ -7486,7 +7486,7 @@ int sqlite3Select(
|
||||
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
|
||||
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, pDistinct,
|
||||
0, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY)
|
||||
p, (sDistinct.isTnct==2 ? WHERE_DISTINCTBY : WHERE_GROUPBY)
|
||||
| (orderByGrp ? WHERE_SORTBYGROUP : 0) | distFlag, 0
|
||||
);
|
||||
if( pWInfo==0 ){
|
||||
@@ -7785,7 +7785,7 @@ int sqlite3Select(
|
||||
|
||||
SELECTTRACE(1,pParse,p,("WhereBegin\n"));
|
||||
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
|
||||
pDistinct, 0, minMaxFlag|distFlag, 0);
|
||||
pDistinct, p, minMaxFlag|distFlag, 0);
|
||||
if( pWInfo==0 ){
|
||||
goto select_end;
|
||||
}
|
||||
|
||||
+291
-272
File diff suppressed because it is too large
Load Diff
+64
-24
@@ -1189,6 +1189,7 @@ typedef struct FuncDef FuncDef;
|
||||
typedef struct FuncDefHash FuncDefHash;
|
||||
typedef struct IdList IdList;
|
||||
typedef struct Index Index;
|
||||
typedef struct IndexedExpr IndexedExpr;
|
||||
typedef struct IndexSample IndexSample;
|
||||
typedef struct KeyClass KeyClass;
|
||||
typedef struct KeyInfo KeyInfo;
|
||||
@@ -1254,6 +1255,7 @@ typedef struct With With;
|
||||
#define MASKBIT32(n) (((unsigned int)1)<<(n))
|
||||
#define SMASKBIT32(n) ((n)<=31?((unsigned int)1)<<(n):0)
|
||||
#define ALLBITS ((Bitmask)-1)
|
||||
#define TOPBIT (((Bitmask)1)<<(BMS-1))
|
||||
|
||||
/* A VList object records a mapping between parameters/variables/wildcards
|
||||
** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
|
||||
@@ -1788,6 +1790,7 @@ struct sqlite3 {
|
||||
#define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
|
||||
#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
|
||||
/* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
|
||||
#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
|
||||
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
|
||||
|
||||
/*
|
||||
@@ -2360,7 +2363,7 @@ struct Table {
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
# define IsVirtual(X) ((X)->eTabType==TABTYP_VTAB)
|
||||
# define ExprIsVtab(X) \
|
||||
((X)->op==TK_COLUMN && (X)->y.pTab!=0 && (X)->y.pTab->eTabType==TABTYP_VTAB)
|
||||
((X)->op==TK_COLUMN && (X)->y.pTab->eTabType==TABTYP_VTAB)
|
||||
#else
|
||||
# define IsVirtual(X) 0
|
||||
# define ExprIsVtab(X) 0
|
||||
@@ -2577,10 +2580,22 @@ struct UnpackedRecord {
|
||||
** The Index.onError field determines whether or not the indexed columns
|
||||
** must be unique and what to do if they are not. When Index.onError=OE_None,
|
||||
** it means this is not a unique index. Otherwise it is a unique index
|
||||
** and the value of Index.onError indicate the which conflict resolution
|
||||
** algorithm to employ whenever an attempt is made to insert a non-unique
|
||||
** and the value of Index.onError indicates which conflict resolution
|
||||
** algorithm to employ when an attempt is made to insert a non-unique
|
||||
** element.
|
||||
**
|
||||
** The colNotIdxed bitmask is used in combination with SrcItem.colUsed
|
||||
** for a fast test to see if an index can serve as a covering index.
|
||||
** colNotIdxed has a 1 bit for every column of the original table that
|
||||
** is *not* available in the index. Thus the expression
|
||||
** "colUsed & colNotIdxed" will be non-zero if the index is not a
|
||||
** covering index. The most significant bit of of colNotIdxed will always
|
||||
** be true (note-20221022-a). If a column beyond the 63rd column of the
|
||||
** table is used, the "colUsed & colNotIdxed" test will always be non-zero
|
||||
** and we have to assume either that the index is not covering, or use
|
||||
** an alternative (slower) algorithm to determine whether or not
|
||||
** the index is covering.
|
||||
**
|
||||
** While parsing a CREATE TABLE or CREATE INDEX statement in order to
|
||||
** generate VDBE code (as opposed to parsing one read from an sqlite_schema
|
||||
** table as part of parsing an existing database schema), transient instances
|
||||
@@ -2616,6 +2631,8 @@ struct Index {
|
||||
unsigned bNoQuery:1; /* Do not use this index to optimize queries */
|
||||
unsigned bAscKeyBug:1; /* True if the bba7b69f9849b5bf bug applies */
|
||||
unsigned bHasVCol:1; /* Index references one or more VIRTUAL columns */
|
||||
unsigned bHasExpr:1; /* Index contains an expression, either a literal
|
||||
** expression, or a reference to a VIRTUAL column */
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
int nSample; /* Number of elements in aSample[] */
|
||||
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
|
||||
@@ -2624,7 +2641,7 @@ struct Index {
|
||||
tRowcnt *aiRowEst; /* Non-logarithmic stat1 data for this index */
|
||||
tRowcnt nRowEst0; /* Non-logarithmic number of rows in the index */
|
||||
#endif
|
||||
Bitmask colNotIdxed; /* 0 for unindexed columns in pTab */
|
||||
Bitmask colNotIdxed; /* Unindexed columns in pTab */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -3077,6 +3094,14 @@ struct IdList {
|
||||
** The SrcItem object represents a single term in the FROM clause of a query.
|
||||
** The SrcList object is mostly an array of SrcItems.
|
||||
**
|
||||
** The jointype starts out showing the join type between the current table
|
||||
** and the next table on the list. The parser builds the list this way.
|
||||
** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
|
||||
** jointype expresses the join between the table and the previous table.
|
||||
**
|
||||
** In the colUsed field, the high-order bit (bit 63) is set if the table
|
||||
** contains more than 63 columns and the 64-th or later column is used.
|
||||
**
|
||||
** Union member validity:
|
||||
**
|
||||
** u1.zIndexedBy fg.isIndexedBy && !fg.isTabFunc
|
||||
@@ -3116,14 +3141,14 @@ struct SrcItem {
|
||||
Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */
|
||||
IdList *pUsing; /* fg.isUsing==1 => The USING clause of a join */
|
||||
} u3;
|
||||
Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
|
||||
Bitmask colUsed; /* Bit N set if column N used. Details above for N>62 */
|
||||
union {
|
||||
char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
|
||||
ExprList *pFuncArg; /* Arguments to table-valued-function */
|
||||
} u1;
|
||||
union {
|
||||
Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */
|
||||
CteUse *pCteUse; /* CTE Usage info info fg.isCte is true */
|
||||
CteUse *pCteUse; /* CTE Usage info when fg.isCte is true */
|
||||
} u2;
|
||||
};
|
||||
|
||||
@@ -3137,23 +3162,11 @@ struct OnOrUsing {
|
||||
};
|
||||
|
||||
/*
|
||||
** The following structure describes the FROM clause of a SELECT statement.
|
||||
** Each table or subquery in the FROM clause is a separate element of
|
||||
** the SrcList.a[] array.
|
||||
** This object represents one or more tables that are the source of
|
||||
** content for an SQL statement. For example, a single SrcList object
|
||||
** is used to hold the FROM clause of a SELECT statement. SrcList also
|
||||
** represents the target tables for DELETE, INSERT, and UPDATE statements.
|
||||
**
|
||||
** With the addition of multiple database support, the following structure
|
||||
** can also be used to describe a particular table such as the table that
|
||||
** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,
|
||||
** such a table must be a simple name: ID. But in SQLite, the table can
|
||||
** now be identified by a database name, a dot, then the table name: ID.ID.
|
||||
**
|
||||
** The jointype starts out showing the join type between the current table
|
||||
** and the next table on the list. The parser builds the list this way.
|
||||
** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each
|
||||
** jointype expresses the join between the table and the previous table.
|
||||
**
|
||||
** In the colUsed field, the high-order bit (bit 63) is set if the table
|
||||
** contains more than 63 columns and the 64-th or later column is used.
|
||||
*/
|
||||
struct SrcList {
|
||||
int nSrc; /* Number of tables or subqueries in the FROM clause */
|
||||
@@ -3563,6 +3576,28 @@ struct TriggerPrg {
|
||||
# define DbMaskNonZero(M) (M)!=0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** For each index X that has as one of its arguments either an expression
|
||||
** or the name of a virtual generated column, and if X is in scope such that
|
||||
** the value of the expression can simply be read from the index, then
|
||||
** there is an instance of this object on the Parse.pIdxExpr list.
|
||||
**
|
||||
** During code generation, while generating code to evaluate expressions,
|
||||
** this list is consulted and if a matching expression is found, the value
|
||||
** is read from the index rather than being recomputed.
|
||||
*/
|
||||
struct IndexedExpr {
|
||||
Expr *pExpr; /* The expression contained in the index */
|
||||
int iDataCur; /* The data cursor associated with the index */
|
||||
int iIdxCur; /* The index cursor */
|
||||
int iIdxCol; /* The index column that contains value of pExpr */
|
||||
u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */
|
||||
IndexedExpr *pIENext; /* Next in a list of all indexed expressions */
|
||||
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
const char *zIdxName; /* Name of index, used only for bytecode comments */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
** An instance of the ParseCleanup object specifies an operation that
|
||||
** should be performed after parsing to deallocation resources obtained
|
||||
@@ -3621,6 +3656,7 @@ struct Parse {
|
||||
int nLabelAlloc; /* Number of slots in aLabel */
|
||||
int *aLabel; /* Space to hold the labels */
|
||||
ExprList *pConstExpr;/* Constant expressions */
|
||||
IndexedExpr *pIdxExpr;/* List of expressions used by active indexes */
|
||||
Token constraintName;/* Name of the constraint currently being parsed */
|
||||
yDbMask writeMask; /* Start a write transaction on these databases */
|
||||
yDbMask cookieMask; /* Bitmask of schema verified databases */
|
||||
@@ -4056,15 +4092,15 @@ struct Walker {
|
||||
struct RefSrcList *pRefSrcList; /* sqlite3ReferencesSrcList() */
|
||||
int *aiCol; /* array of column indexes */
|
||||
struct IdxCover *pIdxCover; /* Check for index coverage */
|
||||
struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */
|
||||
ExprList *pGroupBy; /* GROUP BY clause */
|
||||
Select *pSelect; /* HAVING to WHERE clause ctx */
|
||||
struct WindowRewrite *pRewrite; /* Window rewrite context */
|
||||
struct WhereConst *pConst; /* WHERE clause constants */
|
||||
struct RenameCtx *pRename; /* RENAME COLUMN context */
|
||||
struct Table *pTab; /* Table of generated column */
|
||||
struct CoveringIndexCheck *pCovIdxCk; /* Check for covering index */
|
||||
SrcItem *pSrcItem; /* A single FROM clause item */
|
||||
DbFixer *pFix;
|
||||
DbFixer *pFix; /* See sqlite3FixSelect() */
|
||||
} u;
|
||||
};
|
||||
|
||||
@@ -4391,12 +4427,16 @@ int sqlite3HeapNearlyFull(void);
|
||||
*/
|
||||
#ifdef SQLITE_USE_ALLOCA
|
||||
# define sqlite3StackAllocRaw(D,N) alloca(N)
|
||||
# define sqlite3StackAllocRawNN(D,N) alloca(N)
|
||||
# define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
|
||||
# define sqlite3StackFree(D,P)
|
||||
# define sqlite3StackFreeNN(D,P)
|
||||
#else
|
||||
# define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
|
||||
# define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N)
|
||||
# define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N)
|
||||
# define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
|
||||
# define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P)
|
||||
#endif
|
||||
|
||||
/* Do not allow both MEMSYS5 and MEMSYS3 to be defined together. If they
|
||||
|
||||
+5
-1
@@ -1852,7 +1852,8 @@ static int SQLITE_TCLAPI test_create_function_v2(
|
||||
{"utf16le", SQLITE_UTF16LE },
|
||||
{"utf16be", SQLITE_UTF16BE },
|
||||
{"any", SQLITE_ANY },
|
||||
{"0", 0 }
|
||||
{"0", 0 },
|
||||
{0, 0 }
|
||||
};
|
||||
|
||||
if( objc<5 || (objc%2)==0 ){
|
||||
@@ -7273,6 +7274,7 @@ static int SQLITE_TCLAPI test_test_control(
|
||||
{ "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP },
|
||||
{ "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER },
|
||||
{ "SQLITE_TESTCTRL_INTERNAL_FUNCTIONS", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS},
|
||||
{ 0, 0 }
|
||||
};
|
||||
int iVerb;
|
||||
int iFlag;
|
||||
@@ -7658,6 +7660,8 @@ static int SQLITE_TCLAPI optimization_control(
|
||||
{ "skip-scan", SQLITE_SkipScan },
|
||||
{ "push-down", SQLITE_PushDown },
|
||||
{ "balanced-merge", SQLITE_BalancedMerge },
|
||||
{ "propagate-const", SQLITE_PropagateConst },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
if( objc!=4 ){
|
||||
|
||||
@@ -166,6 +166,7 @@ int sqlite3UpsertAnalyzeTarget(
|
||||
if( pIdx->aiColumn[ii]==XN_EXPR ){
|
||||
assert( pIdx->aColExpr!=0 );
|
||||
assert( pIdx->aColExpr->nExpr>ii );
|
||||
assert( pIdx->bHasExpr );
|
||||
pExpr = pIdx->aColExpr->a[ii].pExpr;
|
||||
if( pExpr->op!=TK_COLLATE ){
|
||||
sCol[0].pLeft = pExpr;
|
||||
|
||||
+7
-1
@@ -161,6 +161,7 @@ SQLITE_NOINLINE int sqlite3RunVacuum(
|
||||
int nDb; /* Number of attached databases */
|
||||
const char *zDbMain; /* Schema name of database to vacuum */
|
||||
const char *zOut; /* Name of output file */
|
||||
u32 pgflags = PAGER_SYNCHRONOUS_OFF; /* sync flags for output db */
|
||||
|
||||
if( !db->autoCommit ){
|
||||
sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
|
||||
@@ -232,12 +233,17 @@ SQLITE_NOINLINE int sqlite3RunVacuum(
|
||||
goto end_of_vacuum;
|
||||
}
|
||||
db->mDbFlags |= DBFLAG_VacuumInto;
|
||||
|
||||
/* For a VACUUM INTO, the pager-flags are set to the same values as
|
||||
** they are for the database being vacuumed, except that PAGER_CACHESPILL
|
||||
** is always set. */
|
||||
pgflags = db->aDb[iDb].safety_level | (db->flags & PAGER_FLAGS_MASK);
|
||||
}
|
||||
nRes = sqlite3BtreeGetRequestedReserve(pMain);
|
||||
|
||||
sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
|
||||
sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
|
||||
sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL);
|
||||
sqlite3BtreeSetPagerFlags(pTemp, pgflags|PAGER_CACHESPILL);
|
||||
|
||||
/* Begin a transaction and take an exclusive lock on the main database
|
||||
** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
|
||||
|
||||
+3
-3
@@ -4585,7 +4585,7 @@ int sqlite3VdbeRecordCompareWithSkip(
|
||||
serial_type = aKey1[idx1];
|
||||
testcase( serial_type==12 );
|
||||
if( serial_type>=10 ){
|
||||
rc = +1;
|
||||
rc = serial_type==10 ? -1 : +1;
|
||||
}else if( serial_type==0 ){
|
||||
rc = -1;
|
||||
}else if( serial_type==7 ){
|
||||
@@ -4610,7 +4610,7 @@ int sqlite3VdbeRecordCompareWithSkip(
|
||||
** numbers). Types 10 and 11 are currently "reserved for future
|
||||
** use", so it doesn't really matter what the results of comparing
|
||||
** them to numberic values are. */
|
||||
rc = +1;
|
||||
rc = serial_type==10 ? -1 : +1;
|
||||
}else if( serial_type==0 ){
|
||||
rc = -1;
|
||||
}else{
|
||||
@@ -4691,7 +4691,7 @@ int sqlite3VdbeRecordCompareWithSkip(
|
||||
/* RHS is null */
|
||||
else{
|
||||
serial_type = aKey1[idx1];
|
||||
rc = (serial_type!=0);
|
||||
rc = (serial_type!=0 && serial_type!=10);
|
||||
}
|
||||
|
||||
if( rc!=0 ){
|
||||
|
||||
+1
-1
@@ -1141,7 +1141,7 @@ FuncDef *sqlite3VtabOverloadFunction(
|
||||
if( pExpr->op!=TK_COLUMN ) return pDef;
|
||||
assert( ExprUseYTab(pExpr) );
|
||||
pTab = pExpr->y.pTab;
|
||||
if( pTab==0 ) return pDef;
|
||||
if( NEVER(pTab==0) ) return pDef;
|
||||
if( !IsVirtual(pTab) ) return pDef;
|
||||
pVtab = sqlite3GetVTable(db, pTab)->pVtab;
|
||||
assert( pVtab!=0 );
|
||||
|
||||
+185
-26
@@ -2287,7 +2287,6 @@ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
|
||||
pWInfo->pLoops = p->pNextLoop;
|
||||
whereLoopDelete(db, p);
|
||||
}
|
||||
assert( pWInfo->pExprMods==0 );
|
||||
while( pWInfo->pMemToFree ){
|
||||
WhereMemBlock *pNext = pWInfo->pMemToFree->pNext;
|
||||
sqlite3DbNNFreeNN(db, pWInfo->pMemToFree);
|
||||
@@ -2296,17 +2295,6 @@ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){
|
||||
sqlite3DbNNFreeNN(db, pWInfo);
|
||||
}
|
||||
|
||||
/* Undo all Expr node modifications
|
||||
*/
|
||||
static void whereUndoExprMods(WhereInfo *pWInfo){
|
||||
while( pWInfo->pExprMods ){
|
||||
WhereExprMod *p = pWInfo->pExprMods;
|
||||
pWInfo->pExprMods = p->pNext;
|
||||
memcpy(p->pExpr, &p->orig, sizeof(p->orig));
|
||||
sqlite3DbFree(pWInfo->pParse->db, p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if all of the following are true:
|
||||
**
|
||||
@@ -3259,6 +3247,94 @@ static int whereUsablePartialIndex(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Structure passed to the whereIsCoveringIndex Walker callback.
|
||||
*/
|
||||
struct CoveringIndexCheck {
|
||||
Index *pIdx; /* The index */
|
||||
int iTabCur; /* Cursor number for the corresponding table */
|
||||
};
|
||||
|
||||
/*
|
||||
** Information passed in is pWalk->u.pCovIdxCk. Call is pCk.
|
||||
**
|
||||
** If the Expr node references the table with cursor pCk->iTabCur, then
|
||||
** make sure that column is covered by the index pCk->pIdx. We know that
|
||||
** all columns less than 63 (really BMS-1) are covered, so we don't need
|
||||
** to check them. But we do need to check any column at 63 or greater.
|
||||
**
|
||||
** If the index does not cover the column, then set pWalk->eCode to
|
||||
** non-zero and return WRC_Abort to stop the search.
|
||||
**
|
||||
** If this node does not disprove that the index can be a covering index,
|
||||
** then just return WRC_Continue, to continue the search.
|
||||
*/
|
||||
static int whereIsCoveringIndexWalkCallback(Walker *pWalk, Expr *pExpr){
|
||||
int i; /* Loop counter */
|
||||
const Index *pIdx; /* The index of interest */
|
||||
const i16 *aiColumn; /* Columns contained in the index */
|
||||
u16 nColumn; /* Number of columns in the index */
|
||||
if( pExpr->op!=TK_COLUMN && pExpr->op!=TK_AGG_COLUMN ) return WRC_Continue;
|
||||
if( pExpr->iColumn<(BMS-1) ) return WRC_Continue;
|
||||
if( pExpr->iTable!=pWalk->u.pCovIdxCk->iTabCur ) return WRC_Continue;
|
||||
pIdx = pWalk->u.pCovIdxCk->pIdx;
|
||||
aiColumn = pIdx->aiColumn;
|
||||
nColumn = pIdx->nColumn;
|
||||
for(i=0; i<nColumn; i++){
|
||||
if( aiColumn[i]==pExpr->iColumn ) return WRC_Continue;
|
||||
}
|
||||
pWalk->eCode = 1;
|
||||
return WRC_Abort;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** pIdx is an index that covers all of the low-number columns used by
|
||||
** pWInfo->pSelect (columns from 0 through 62). But there are columns
|
||||
** in pWInfo->pSelect beyond 62. This routine tries to answer the question
|
||||
** of whether pIdx covers *all* columns in the query.
|
||||
**
|
||||
** Return 0 if pIdx is a covering index. Return non-zero if pIdx is
|
||||
** not a covering index or if we are unable to determine if pIdx is a
|
||||
** covering index.
|
||||
**
|
||||
** This routine is an optimization. It is always safe to return non-zero.
|
||||
** But returning zero when non-zero should have been returned can lead to
|
||||
** incorrect bytecode and assertion faults.
|
||||
*/
|
||||
static SQLITE_NOINLINE u32 whereIsCoveringIndex(
|
||||
WhereInfo *pWInfo, /* The WHERE clause context */
|
||||
Index *pIdx, /* Index that is being tested */
|
||||
int iTabCur /* Cursor for the table being indexed */
|
||||
){
|
||||
int i;
|
||||
struct CoveringIndexCheck ck;
|
||||
Walker w;
|
||||
if( pWInfo->pSelect==0 ){
|
||||
/* We don't have access to the full query, so we cannot check to see
|
||||
** if pIdx is covering. Assume it is not. */
|
||||
return 1;
|
||||
}
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
if( pIdx->aiColumn[i]>=BMS-1 ) break;
|
||||
}
|
||||
if( i>=pIdx->nColumn ){
|
||||
/* pIdx does not index any columns greater than 62, but we know from
|
||||
** colMask that columns greater than 62 are used, so this is not a
|
||||
** covering index */
|
||||
return 1;
|
||||
}
|
||||
ck.pIdx = pIdx;
|
||||
ck.iTabCur = iTabCur;
|
||||
memset(&w, 0, sizeof(w));
|
||||
w.xExprCallback = whereIsCoveringIndexWalkCallback;
|
||||
w.xSelectCallback = sqlite3SelectWalkNoop;
|
||||
w.u.pCovIdxCk = &ck;
|
||||
w.eCode = 0;
|
||||
sqlite3WalkSelect(&w, pWInfo->pSelect);
|
||||
return w.eCode;
|
||||
}
|
||||
|
||||
/*
|
||||
** Add all WhereLoop objects for a single table of the join where the table
|
||||
** is identified by pBuilder->pNew->iTab. That table is guaranteed to be
|
||||
@@ -3476,6 +3552,9 @@ static int whereLoopAddBtree(
|
||||
m = 0;
|
||||
}else{
|
||||
m = pSrc->colUsed & pProbe->colNotIdxed;
|
||||
if( m==TOPBIT ){
|
||||
m = whereIsCoveringIndex(pWInfo, pProbe, pSrc->iCursor);
|
||||
}
|
||||
pNew->wsFlags = (m==0) ? (WHERE_IDX_ONLY|WHERE_INDEXED) : WHERE_INDEXED;
|
||||
}
|
||||
|
||||
@@ -4701,7 +4780,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
int mxChoice; /* Maximum number of simultaneous paths tracked */
|
||||
int nLoop; /* Number of terms in the join */
|
||||
Parse *pParse; /* Parsing context */
|
||||
sqlite3 *db; /* The database connection */
|
||||
int iLoop; /* Loop counter over the terms of the join */
|
||||
int ii, jj; /* Loop counters */
|
||||
int mxI = 0; /* Index of next entry to replace */
|
||||
@@ -4720,7 +4798,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
int nSpace; /* Bytes of space allocated at pSpace */
|
||||
|
||||
pParse = pWInfo->pParse;
|
||||
db = pParse->db;
|
||||
nLoop = pWInfo->nLevel;
|
||||
/* TUNING: For simple queries, only the best path is tracked.
|
||||
** For 2-way joins, the 5 best paths are followed.
|
||||
@@ -4743,7 +4820,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
/* Allocate and initialize space for aTo, aFrom and aSortCost[] */
|
||||
nSpace = (sizeof(WherePath)+sizeof(WhereLoop*)*nLoop)*mxChoice*2;
|
||||
nSpace += sizeof(LogEst) * nOrderBy;
|
||||
pSpace = sqlite3DbMallocRawNN(db, nSpace);
|
||||
pSpace = sqlite3StackAllocRawNN(pParse->db, nSpace);
|
||||
if( pSpace==0 ) return SQLITE_NOMEM_BKPT;
|
||||
aTo = (WherePath*)pSpace;
|
||||
aFrom = aTo+mxChoice;
|
||||
@@ -5001,7 +5078,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
|
||||
if( nFrom==0 ){
|
||||
sqlite3ErrorMsg(pParse, "no query solution");
|
||||
sqlite3DbFreeNN(db, pSpace);
|
||||
sqlite3StackFreeNN(pParse->db, pSpace);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
@@ -5083,8 +5160,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
pWInfo->nRowOut = pFrom->nRow;
|
||||
|
||||
/* Free temporary memory and return success */
|
||||
assert( db!=0 );
|
||||
sqlite3DbNNFreeNN(db, pSpace);
|
||||
sqlite3StackFreeNN(pParse->db, pSpace);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -5383,6 +5459,77 @@ static SQLITE_NOINLINE void whereCheckIfBloomFilterIsUseful(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** This is an sqlite3ParserAddCleanup() callback that is invoked to
|
||||
** free the Parse->pIdxExpr list when the Parse object is destroyed.
|
||||
*/
|
||||
static void whereIndexedExprCleanup(sqlite3 *db, void *pObject){
|
||||
Parse *pParse = (Parse*)pObject;
|
||||
while( pParse->pIdxExpr!=0 ){
|
||||
IndexedExpr *p = pParse->pIdxExpr;
|
||||
pParse->pIdxExpr = p->pIENext;
|
||||
sqlite3ExprDelete(db, p->pExpr);
|
||||
sqlite3DbFreeNN(db, p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** The index pIdx is used by a query and contains one or more expressions.
|
||||
** In other words pIdx is an index on an expression. iIdxCur is the cursor
|
||||
** number for the index and iDataCur is the cursor number for the corresponding
|
||||
** table.
|
||||
**
|
||||
** This routine adds IndexedExpr entries to the Parse->pIdxExpr field for
|
||||
** each of the expressions in the index so that the expression code generator
|
||||
** will know to replace occurrences of the indexed expression with
|
||||
** references to the corresponding column of the index.
|
||||
*/
|
||||
static SQLITE_NOINLINE void whereAddIndexedExpr(
|
||||
Parse *pParse, /* Add IndexedExpr entries to pParse->pIdxExpr */
|
||||
Index *pIdx, /* The index-on-expression that contains the expressions */
|
||||
int iIdxCur, /* Cursor number for pIdx */
|
||||
SrcItem *pTabItem /* The FROM clause entry for the table */
|
||||
){
|
||||
int i;
|
||||
IndexedExpr *p;
|
||||
Table *pTab;
|
||||
assert( pIdx->bHasExpr );
|
||||
pTab = pIdx->pTable;
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
Expr *pExpr;
|
||||
int j = pIdx->aiColumn[i];
|
||||
int bMaybeNullRow;
|
||||
if( j==XN_EXPR ){
|
||||
pExpr = pIdx->aColExpr->a[i].pExpr;
|
||||
testcase( pTabItem->fg.jointype & JT_LEFT );
|
||||
testcase( pTabItem->fg.jointype & JT_RIGHT );
|
||||
testcase( pTabItem->fg.jointype & JT_LTORJ );
|
||||
bMaybeNullRow = (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0;
|
||||
}else if( j>=0 && (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)!=0 ){
|
||||
pExpr = sqlite3ColumnExpr(pTab, &pTab->aCol[j]);
|
||||
bMaybeNullRow = 0;
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
if( sqlite3ExprIsConstant(pExpr) ) continue;
|
||||
p = sqlite3DbMallocRaw(pParse->db, sizeof(IndexedExpr));
|
||||
if( p==0 ) break;
|
||||
p->pIENext = pParse->pIdxExpr;
|
||||
p->pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
|
||||
p->iDataCur = pTabItem->iCursor;
|
||||
p->iIdxCur = iIdxCur;
|
||||
p->iIdxCol = i;
|
||||
p->bMaybeNullRow = bMaybeNullRow;
|
||||
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
p->zIdxName = pIdx->zName;
|
||||
#endif
|
||||
pParse->pIdxExpr = p;
|
||||
if( p->pIENext==0 ){
|
||||
sqlite3ParserAddCleanup(pParse, whereIndexedExprCleanup, pParse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate the beginning of the loop used for WHERE clause processing.
|
||||
** The return value is a pointer to an opaque structure that contains
|
||||
@@ -5477,7 +5624,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
Expr *pWhere, /* The WHERE clause */
|
||||
ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
|
||||
ExprList *pResultSet, /* Query result set. Req'd for DISTINCT */
|
||||
Select *pLimit, /* Use this LIMIT/OFFSET clause, if any */
|
||||
Select *pSelect, /* The entire SELECT statement */
|
||||
u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
|
||||
int iAuxArg /* If WHERE_OR_SUBCLAUSE is set, index cursor number
|
||||
** If WHERE_USE_LIMIT, then the limit amount */
|
||||
@@ -5546,7 +5693,9 @@ WhereInfo *sqlite3WhereBegin(
|
||||
pWInfo->pParse = pParse;
|
||||
pWInfo->pTabList = pTabList;
|
||||
pWInfo->pOrderBy = pOrderBy;
|
||||
#if WHERETRACE_ENABLED
|
||||
pWInfo->pWhere = pWhere;
|
||||
#endif
|
||||
pWInfo->pResultSet = pResultSet;
|
||||
pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
|
||||
pWInfo->nLevel = nTabList;
|
||||
@@ -5554,9 +5703,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
pWInfo->wctrlFlags = wctrlFlags;
|
||||
pWInfo->iLimit = iAuxArg;
|
||||
pWInfo->savedNQueryLoop = pParse->nQueryLoop;
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
pWInfo->pLimit = pLimit;
|
||||
#endif
|
||||
pWInfo->pSelect = pSelect;
|
||||
memset(&pWInfo->nOBSat, 0,
|
||||
offsetof(WhereInfo,sWC) - offsetof(WhereInfo,nOBSat));
|
||||
memset(&pWInfo->a[0], 0, sizeof(WhereLoop)+nTabList*sizeof(WhereLevel));
|
||||
@@ -5625,7 +5772,9 @@ WhereInfo *sqlite3WhereBegin(
|
||||
|
||||
/* Analyze all of the subexpressions. */
|
||||
sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
|
||||
sqlite3WhereAddLimit(&pWInfo->sWC, pLimit);
|
||||
if( pSelect && pSelect->pLimit ){
|
||||
sqlite3WhereAddLimit(&pWInfo->sWC, pSelect);
|
||||
}
|
||||
if( pParse->nErr ) goto whereBeginError;
|
||||
|
||||
/* Special case: WHERE terms that do not refer to any tables in the join
|
||||
@@ -5928,6 +6077,9 @@ WhereInfo *sqlite3WhereBegin(
|
||||
op = OP_ReopenIdx;
|
||||
}else{
|
||||
iIndexCur = pParse->nTab++;
|
||||
if( pIx->bHasExpr && OptimizationEnabled(db, SQLITE_IndexedExpr) ){
|
||||
whereAddIndexedExpr(pParse, pIx, iIndexCur, pTabItem);
|
||||
}
|
||||
}
|
||||
pLevel->iIdxCur = iIndexCur;
|
||||
assert( pIx!=0 );
|
||||
@@ -6050,8 +6202,6 @@ WhereInfo *sqlite3WhereBegin(
|
||||
/* Jump here if malloc fails */
|
||||
whereBeginError:
|
||||
if( pWInfo ){
|
||||
testcase( pWInfo->pExprMods!=0 );
|
||||
whereUndoExprMods(pWInfo);
|
||||
pParse->nQueryLoop = pWInfo->savedNQueryLoop;
|
||||
whereInfoFree(db, pWInfo);
|
||||
}
|
||||
@@ -6270,7 +6420,6 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
|
||||
}
|
||||
|
||||
assert( pWInfo->nLevel<=pTabList->nSrc );
|
||||
if( pWInfo->pExprMods ) whereUndoExprMods(pWInfo);
|
||||
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
|
||||
int k, last;
|
||||
VdbeOp *pOp, *pLastOp;
|
||||
@@ -6324,6 +6473,16 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
|
||||
}else{
|
||||
last = pWInfo->iEndWhere;
|
||||
}
|
||||
if( pIdx->bHasExpr ){
|
||||
IndexedExpr *p = pParse->pIdxExpr;
|
||||
while( p ){
|
||||
if( p->iIdxCur==pLevel->iIdxCur ){
|
||||
p->iDataCur = -1;
|
||||
p->iIdxCur = -1;
|
||||
}
|
||||
p = p->pIENext;
|
||||
}
|
||||
}
|
||||
k = pLevel->addrBody + 1;
|
||||
#ifdef SQLITE_DEBUG
|
||||
if( db->flags & SQLITE_VdbeAddopTrace ){
|
||||
|
||||
+3
-18
@@ -378,7 +378,7 @@ struct WhereAndInfo {
|
||||
** between VDBE cursor numbers and bits of the bitmasks in WhereTerm.
|
||||
**
|
||||
** The VDBE cursor numbers are small integers contained in
|
||||
** SrcList_item.iCursor and Expr.iTable fields. For any given WHERE
|
||||
** SrcItem.iCursor and Expr.iTable fields. For any given WHERE
|
||||
** clause, the cursor numbers might not begin with 0 and they might
|
||||
** contain gaps in the numbering sequence. But we want to make maximum
|
||||
** use of the bits in our bitmasks. This structure provides a mapping
|
||||
@@ -449,20 +449,6 @@ struct WhereLoopBuilder {
|
||||
# define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Each instance of this object records a change to a single node
|
||||
** in an expression tree to cause that node to point to a column
|
||||
** of an index rather than an expression or a virtual column. All
|
||||
** such transformations need to be undone at the end of WHERE clause
|
||||
** processing.
|
||||
*/
|
||||
typedef struct WhereExprMod WhereExprMod;
|
||||
struct WhereExprMod {
|
||||
WhereExprMod *pNext; /* Next translation on a list of them all */
|
||||
Expr *pExpr; /* The Expr node that was transformed */
|
||||
Expr orig; /* Original value of the Expr node */
|
||||
};
|
||||
|
||||
/*
|
||||
** The WHERE clause processing routine has two halves. The
|
||||
** first part does the start of the WHERE loop and the second
|
||||
@@ -478,10 +464,10 @@ struct WhereInfo {
|
||||
SrcList *pTabList; /* List of tables in the join */
|
||||
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
|
||||
ExprList *pResultSet; /* Result set of the query */
|
||||
#if WHERETRACE_ENABLED
|
||||
Expr *pWhere; /* The complete WHERE clause */
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
Select *pLimit; /* Used to access LIMIT expr/registers for vtabs */
|
||||
#endif
|
||||
Select *pSelect; /* The entire SELECT statement containing WHERE */
|
||||
int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
|
||||
int iContinue; /* Jump here to continue with next record */
|
||||
int iBreak; /* Jump here to break out of the loop */
|
||||
@@ -500,7 +486,6 @@ struct WhereInfo {
|
||||
int iTop; /* The very beginning of the WHERE loop */
|
||||
int iEndWhere; /* End of the WHERE clause itself */
|
||||
WhereLoop *pLoops; /* List of all WhereLoop objects */
|
||||
WhereExprMod *pExprMods; /* Expression modifications */
|
||||
WhereMemBlock *pMemToFree;/* Memory to free when this object destroyed */
|
||||
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
|
||||
WhereClause sWC; /* Decomposition of the WHERE clause */
|
||||
|
||||
+5
-163
@@ -1217,143 +1217,6 @@ static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
|
||||
}
|
||||
}
|
||||
|
||||
/* An instance of the IdxExprTrans object carries information about a
|
||||
** mapping from an expression on table columns into a column in an index
|
||||
** down through the Walker.
|
||||
*/
|
||||
typedef struct IdxExprTrans {
|
||||
Expr *pIdxExpr; /* The index expression */
|
||||
int iTabCur; /* The cursor of the corresponding table */
|
||||
int iIdxCur; /* The cursor for the index */
|
||||
int iIdxCol; /* The column for the index */
|
||||
int iTabCol; /* The column for the table */
|
||||
WhereInfo *pWInfo; /* Complete WHERE clause information */
|
||||
sqlite3 *db; /* Database connection (for malloc()) */
|
||||
} IdxExprTrans;
|
||||
|
||||
/*
|
||||
** Preserve pExpr on the WhereETrans list of the WhereInfo.
|
||||
*/
|
||||
static void preserveExpr(IdxExprTrans *pTrans, Expr *pExpr){
|
||||
WhereExprMod *pNew;
|
||||
pNew = sqlite3DbMallocRaw(pTrans->db, sizeof(*pNew));
|
||||
if( pNew==0 ) return;
|
||||
pNew->pNext = pTrans->pWInfo->pExprMods;
|
||||
pTrans->pWInfo->pExprMods = pNew;
|
||||
pNew->pExpr = pExpr;
|
||||
memcpy(&pNew->orig, pExpr, sizeof(*pExpr));
|
||||
}
|
||||
|
||||
/* The walker node callback used to transform matching expressions into
|
||||
** a reference to an index column for an index on an expression.
|
||||
**
|
||||
** If pExpr matches, then transform it into a reference to the index column
|
||||
** that contains the value of pExpr.
|
||||
*/
|
||||
static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
|
||||
IdxExprTrans *pX = p->u.pIdxTrans;
|
||||
if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
|
||||
pExpr = sqlite3ExprSkipCollate(pExpr);
|
||||
preserveExpr(pX, pExpr);
|
||||
pExpr->affExpr = sqlite3ExprAffinity(pExpr);
|
||||
pExpr->op = TK_COLUMN;
|
||||
pExpr->iTable = pX->iIdxCur;
|
||||
pExpr->iColumn = pX->iIdxCol;
|
||||
testcase( ExprHasProperty(pExpr, EP_Unlikely) );
|
||||
ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
|
||||
pExpr->y.pTab = 0;
|
||||
return WRC_Prune;
|
||||
}else{
|
||||
return WRC_Continue;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
|
||||
/* A walker node callback that translates a column reference to a table
|
||||
** into a corresponding column reference of an index.
|
||||
*/
|
||||
static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){
|
||||
if( pExpr->op==TK_COLUMN ){
|
||||
IdxExprTrans *pX = p->u.pIdxTrans;
|
||||
if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){
|
||||
assert( ExprUseYTab(pExpr) && pExpr->y.pTab!=0 );
|
||||
preserveExpr(pX, pExpr);
|
||||
pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn);
|
||||
pExpr->iTable = pX->iIdxCur;
|
||||
pExpr->iColumn = pX->iIdxCol;
|
||||
pExpr->y.pTab = 0;
|
||||
}
|
||||
}
|
||||
return WRC_Continue;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
|
||||
|
||||
/*
|
||||
** For an indexes on expression X, locate every instance of expression X
|
||||
** in pExpr and change that subexpression into a reference to the appropriate
|
||||
** column of the index.
|
||||
**
|
||||
** 2019-10-24: Updated to also translate references to a VIRTUAL column in
|
||||
** the table into references to the corresponding (stored) column of the
|
||||
** index.
|
||||
*/
|
||||
static void whereIndexExprTrans(
|
||||
Index *pIdx, /* The Index */
|
||||
int iTabCur, /* Cursor of the table that is being indexed */
|
||||
int iIdxCur, /* Cursor of the index itself */
|
||||
WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
|
||||
){
|
||||
int iIdxCol; /* Column number of the index */
|
||||
ExprList *aColExpr; /* Expressions that are indexed */
|
||||
Table *pTab;
|
||||
Walker w;
|
||||
IdxExprTrans x;
|
||||
aColExpr = pIdx->aColExpr;
|
||||
if( aColExpr==0 && !pIdx->bHasVCol ){
|
||||
/* The index does not reference any expressions or virtual columns
|
||||
** so no translations are needed. */
|
||||
return;
|
||||
}
|
||||
pTab = pIdx->pTable;
|
||||
memset(&w, 0, sizeof(w));
|
||||
w.u.pIdxTrans = &x;
|
||||
x.iTabCur = iTabCur;
|
||||
x.iIdxCur = iIdxCur;
|
||||
x.pWInfo = pWInfo;
|
||||
x.db = pWInfo->pParse->db;
|
||||
for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){
|
||||
i16 iRef = pIdx->aiColumn[iIdxCol];
|
||||
if( iRef==XN_EXPR ){
|
||||
assert( aColExpr!=0 && aColExpr->a[iIdxCol].pExpr!=0 );
|
||||
x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
|
||||
if( sqlite3ExprIsConstant(x.pIdxExpr) ) continue;
|
||||
w.xExprCallback = whereIndexExprTransNode;
|
||||
#ifndef SQLITE_OMIT_GENERATED_COLUMNS
|
||||
}else if( iRef>=0
|
||||
&& (pTab->aCol[iRef].colFlags & COLFLAG_VIRTUAL)!=0
|
||||
&& ((pTab->aCol[iRef].colFlags & COLFLAG_HASCOLL)==0
|
||||
|| sqlite3StrICmp(sqlite3ColumnColl(&pTab->aCol[iRef]),
|
||||
sqlite3StrBINARY)==0)
|
||||
){
|
||||
/* Check to see if there are direct references to generated columns
|
||||
** that are contained in the index. Pulling the generated column
|
||||
** out of the index is an optimization only - the main table is always
|
||||
** available if the index cannot be used. To avoid unnecessary
|
||||
** complication, omit this optimization if the collating sequence for
|
||||
** the column is non-standard */
|
||||
x.iTabCol = iRef;
|
||||
w.xExprCallback = whereIndexExprTransColumn;
|
||||
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
x.iIdxCol = iIdxCol;
|
||||
sqlite3WalkExpr(&w, pWInfo->pWhere);
|
||||
sqlite3WalkExprList(&w, pWInfo->pOrderBy);
|
||||
sqlite3WalkExprList(&w, pWInfo->pResultSet);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** The pTruth expression is always true because it is the WHERE clause
|
||||
** a partial index that is driving a query loop. Look through all of the
|
||||
@@ -1575,9 +1438,9 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
&& pLoop->u.vtab.bOmitOffset
|
||||
){
|
||||
assert( pTerm->eOperator==WO_AUX );
|
||||
assert( pWInfo->pLimit!=0 );
|
||||
assert( pWInfo->pLimit->iOffset>0 );
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pLimit->iOffset);
|
||||
assert( pWInfo->pSelect!=0 );
|
||||
assert( pWInfo->pSelect->iOffset>0 );
|
||||
sqlite3VdbeAddOp2(v, OP_Integer, 0, pWInfo->pSelect->iOffset);
|
||||
VdbeComment((v,"Zero OFFSET counter"));
|
||||
}
|
||||
}
|
||||
@@ -2181,27 +2044,6 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
}
|
||||
|
||||
if( pLevel->iLeftJoin==0 ){
|
||||
/* If pIdx is an index on one or more expressions, then look through
|
||||
** all the expressions in pWInfo and try to transform matching expressions
|
||||
** into reference to index columns. Also attempt to translate references
|
||||
** to virtual columns in the table into references to (stored) columns
|
||||
** of the index.
|
||||
**
|
||||
** Do not do this for the RHS of a LEFT JOIN. This is because the
|
||||
** expression may be evaluated after OP_NullRow has been executed on
|
||||
** the cursor. In this case it is important to do the full evaluation,
|
||||
** as the result of the expression may not be NULL, even if all table
|
||||
** column values are. https://www.sqlite.org/src/info/7fa8049685b50b5a
|
||||
**
|
||||
** Also, do not do this when processing one index an a multi-index
|
||||
** OR clause, since the transformation will become invalid once we
|
||||
** move forward to the next index.
|
||||
** https://sqlite.org/src/info/4e8e4857d32d401f
|
||||
*/
|
||||
if( (pWInfo->wctrlFlags & (WHERE_OR_SUBCLAUSE|WHERE_RIGHT_JOIN))==0 ){
|
||||
whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
|
||||
}
|
||||
|
||||
/* If a partial index is driving the loop, try to eliminate WHERE clause
|
||||
** terms from the query that must be true due to the WHERE clause of
|
||||
** the partial index.
|
||||
@@ -2314,7 +2156,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
int nNotReady; /* The number of notReady tables */
|
||||
SrcItem *origSrc; /* Original list of tables */
|
||||
nNotReady = pWInfo->nLevel - iLevel - 1;
|
||||
pOrTab = sqlite3StackAllocRaw(db,
|
||||
pOrTab = sqlite3DbMallocRawNN(db,
|
||||
sizeof(*pOrTab)+ nNotReady*sizeof(pOrTab->a[0]));
|
||||
if( pOrTab==0 ) return notReady;
|
||||
pOrTab->nAlloc = (u8)(nNotReady + 1);
|
||||
@@ -2567,7 +2409,7 @@ Bitmask sqlite3WhereCodeOneLoopStart(
|
||||
assert( pLevel->op==OP_Return );
|
||||
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
|
||||
|
||||
if( pWInfo->nLevel>1 ){ sqlite3StackFree(db, pOrTab); }
|
||||
if( pWInfo->nLevel>1 ){ sqlite3DbFreeNN(db, pOrTab); }
|
||||
if( !untestedTerms ) disableTerm(pLevel, pTerm);
|
||||
}else
|
||||
#endif /* SQLITE_OMIT_OR_OPTIMIZATION */
|
||||
|
||||
+10
-11
@@ -266,7 +266,7 @@ static int isLikeOrGlob(
|
||||
if( pLeft->op!=TK_COLUMN
|
||||
|| sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT
|
||||
|| (ALWAYS( ExprUseYTab(pLeft) )
|
||||
&& pLeft->y.pTab
|
||||
&& ALWAYS(pLeft->y.pTab)
|
||||
&& IsVirtual(pLeft->y.pTab)) /* Might be numeric */
|
||||
){
|
||||
int isNum;
|
||||
@@ -383,8 +383,7 @@ static int isAuxiliaryVtabOperator(
|
||||
** MATCH(expression,vtab_column)
|
||||
*/
|
||||
pCol = pList->a[1].pExpr;
|
||||
assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
|
||||
testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
|
||||
assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
|
||||
if( ExprIsVtab(pCol) ){
|
||||
for(i=0; i<ArraySize(aOp); i++){
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue) );
|
||||
@@ -409,7 +408,7 @@ static int isAuxiliaryVtabOperator(
|
||||
*/
|
||||
pCol = pList->a[0].pExpr;
|
||||
assert( pCol->op!=TK_COLUMN || ExprUseYTab(pCol) );
|
||||
testcase( pCol->op==TK_COLUMN && pCol->y.pTab==0 );
|
||||
assert( pCol->op!=TK_COLUMN || (ExprUseYTab(pCol) && pCol->y.pTab!=0) );
|
||||
if( ExprIsVtab(pCol) ){
|
||||
sqlite3_vtab *pVtab;
|
||||
sqlite3_module *pMod;
|
||||
@@ -434,13 +433,12 @@ static int isAuxiliaryVtabOperator(
|
||||
int res = 0;
|
||||
Expr *pLeft = pExpr->pLeft;
|
||||
Expr *pRight = pExpr->pRight;
|
||||
assert( pLeft->op!=TK_COLUMN || ExprUseYTab(pLeft) );
|
||||
testcase( pLeft->op==TK_COLUMN && pLeft->y.pTab==0 );
|
||||
assert( pLeft->op!=TK_COLUMN || (ExprUseYTab(pLeft) && pLeft->y.pTab!=0) );
|
||||
if( ExprIsVtab(pLeft) ){
|
||||
res++;
|
||||
}
|
||||
assert( pRight==0 || pRight->op!=TK_COLUMN || ExprUseYTab(pRight) );
|
||||
testcase( pRight && pRight->op==TK_COLUMN && pRight->y.pTab==0 );
|
||||
assert( pRight==0 || pRight->op!=TK_COLUMN
|
||||
|| (ExprUseYTab(pRight) && pRight->y.pTab!=0) );
|
||||
if( pRight && ExprIsVtab(pRight) ){
|
||||
res++;
|
||||
SWAP(Expr*, pLeft, pRight);
|
||||
@@ -989,6 +987,7 @@ static SQLITE_NOINLINE int exprMightBeIndexed2(
|
||||
if( pIdx->aColExpr==0 ) continue;
|
||||
for(i=0; i<pIdx->nKeyCol; i++){
|
||||
if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
|
||||
assert( pIdx->bHasExpr );
|
||||
if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
|
||||
aiCurCol[0] = iCur;
|
||||
aiCurCol[1] = XN_EXPR;
|
||||
@@ -1602,9 +1601,9 @@ static void whereAddLimitExpr(
|
||||
** exist only so that they may be passed to the xBestIndex method of the
|
||||
** single virtual table in the FROM clause of the SELECT.
|
||||
*/
|
||||
void sqlite3WhereAddLimit(WhereClause *pWC, Select *p){
|
||||
assert( p==0 || (p->pGroupBy==0 && (p->selFlags & SF_Aggregate)==0) );
|
||||
if( (p && p->pLimit) /* 1 */
|
||||
void SQLITE_NOINLINE sqlite3WhereAddLimit(WhereClause *pWC, Select *p){
|
||||
assert( p!=0 && p->pLimit!=0 ); /* 1 -- checked by caller */
|
||||
if( p->pGroupBy==0
|
||||
&& (p->selFlags & (SF_Distinct|SF_Aggregate))==0 /* 2 */
|
||||
&& (p->pSrc->nSrc==1 && IsVirtual(p->pSrc->a[0].pTab)) /* 3 */
|
||||
){
|
||||
|
||||
+45
-3
@@ -29,7 +29,7 @@
|
||||
|
||||
/* Forward references */
|
||||
static char *fuzz_invariant_sql(sqlite3_stmt*, int);
|
||||
static int sameValue(sqlite3_stmt*,int,sqlite3_stmt*,int);
|
||||
static int sameValue(sqlite3_stmt*,int,sqlite3_stmt*,int,sqlite3_stmt*);
|
||||
static void reportInvariantFailed(sqlite3_stmt*,sqlite3_stmt*,int);
|
||||
|
||||
/*
|
||||
@@ -108,13 +108,16 @@ int fuzz_invariant(
|
||||
}
|
||||
while( (rc = sqlite3_step(pTestStmt))==SQLITE_ROW ){
|
||||
for(i=0; i<nCol; i++){
|
||||
if( !sameValue(pStmt, i, pTestStmt, i) ) break;
|
||||
if( !sameValue(pStmt, i, pTestStmt, i, 0) ) break;
|
||||
}
|
||||
if( i>=nCol ) break;
|
||||
}
|
||||
if( rc==SQLITE_DONE ){
|
||||
/* No matching output row found */
|
||||
sqlite3_stmt *pCk = 0;
|
||||
|
||||
/* This is not a fault if the database file is corrupt, because anything
|
||||
** can happen with a corrupt database file */
|
||||
rc = sqlite3_prepare_v2(db, "PRAGMA integrity_check", -1, &pCk, 0);
|
||||
if( rc ){
|
||||
sqlite3_finalize(pCk);
|
||||
@@ -132,6 +135,7 @@ int fuzz_invariant(
|
||||
return SQLITE_CORRUPT;
|
||||
}
|
||||
sqlite3_finalize(pCk);
|
||||
|
||||
if( sqlite3_strlike("%group%by%order%by%desc%",sqlite3_sql(pStmt),0)==0 ){
|
||||
/* dbsqlfuzz crash-647c162051c9b23ce091b7bbbe5125ce5f00e922
|
||||
** Original statement is:
|
||||
@@ -145,6 +149,7 @@ int fuzz_invariant(
|
||||
*/
|
||||
goto not_a_fault;
|
||||
}
|
||||
|
||||
if( sqlite3_strlike("%limit%)%order%by%", sqlite3_sql(pTestStmt),0)==0 ){
|
||||
/* crash-89bd6a6f8c6166e9a4c5f47b3e70b225f69b76c6
|
||||
** Original statement is:
|
||||
@@ -159,6 +164,31 @@ int fuzz_invariant(
|
||||
*/
|
||||
goto not_a_fault;
|
||||
}
|
||||
|
||||
/* The original sameValue() comparison assumed a collating sequence
|
||||
** of "binary". It can sometimes get an incorrect result for different
|
||||
** collating sequences. So rerun the test with no assumptions about
|
||||
** collations.
|
||||
*/
|
||||
rc = sqlite3_prepare_v2(db,
|
||||
"SELECT ?1=?2 OR ?1=?2 COLLATE nocase OR ?1=?2 COLLATE rtrim",
|
||||
-1, &pCk, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_reset(pTestStmt);
|
||||
while( (rc = sqlite3_step(pTestStmt))==SQLITE_ROW ){
|
||||
for(i=0; i<nCol; i++){
|
||||
if( !sameValue(pStmt, i, pTestStmt, i, pCk) ) break;
|
||||
}
|
||||
if( i>=nCol ){
|
||||
sqlite3_finalize(pCk);
|
||||
goto not_a_fault;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(pCk);
|
||||
|
||||
/* Invariants do not necessarily work if there are virtual tables
|
||||
** involved in the query */
|
||||
rc = sqlite3_prepare_v2(db,
|
||||
"SELECT 1 FROM bytecode(?1) WHERE opcode='VOpen'", -1, &pCk, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
@@ -272,7 +302,11 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){
|
||||
/*
|
||||
** Return true if and only if v1 and is the same as v2.
|
||||
*/
|
||||
static int sameValue(sqlite3_stmt *pS1, int i1, sqlite3_stmt *pS2, int i2){
|
||||
static int sameValue(
|
||||
sqlite3_stmt *pS1, int i1, /* Value to text on the left */
|
||||
sqlite3_stmt *pS2, int i2, /* Value to test on the right */
|
||||
sqlite3_stmt *pTestCompare /* COLLATE comparison statement or NULL */
|
||||
){
|
||||
int x = 1;
|
||||
int t1 = sqlite3_column_type(pS1,i1);
|
||||
int t2 = sqlite3_column_type(pS2,i2);
|
||||
@@ -302,6 +336,14 @@ static int sameValue(sqlite3_stmt *pS1, int i1, sqlite3_stmt *pS2, int i2){
|
||||
const char *z2 = (const char*)sqlite3_column_text(pS2,i2);
|
||||
x = ((z1==0 && z2==0) || (z1!=0 && z2!=0 && strcmp(z1,z1)==0));
|
||||
printf("Encodings differ. %d on left and %d on right\n", e1, e2);
|
||||
abort();
|
||||
}
|
||||
if( pTestCompare ){
|
||||
sqlite3_bind_value(pTestCompare, 1, sqlite3_column_value(pS1,i1));
|
||||
sqlite3_bind_value(pTestCompare, 2, sqlite3_column_value(pS2,i2));
|
||||
x = sqlite3_step(pTestCompare)==SQLITE_ROW
|
||||
&& sqlite3_column_int(pTestCompare,0)!=0;
|
||||
sqlite3_reset(pTestCompare);
|
||||
break;
|
||||
}
|
||||
if( e1!=SQLITE_UTF8 ){
|
||||
|
||||
@@ -68,5 +68,26 @@ do_catchsql_test 3.2 {
|
||||
SELECT * FROM t0 LEFT OUTER JOIN t1 ON v0.c0 INNER JOIN v0 INNER JOIN t2 ON (t2.c2 NOT NULL);
|
||||
} {1 {ON clause references tables to its right}}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
|
||||
reset_db
|
||||
do_execsql_test 4.1 {
|
||||
CREATE TABLE t1(a,b,c,d,e,f,g,h,PRIMARY KEY(a,b,c)) WITHOUT ROWID;
|
||||
CREATE TABLE t2(i, j);
|
||||
INSERT INTO t2 VALUES(10, 20);
|
||||
}
|
||||
|
||||
do_execsql_test 4.2 {
|
||||
SELECT (d IS NULL) FROM t1 RIGHT JOIN t2 ON (j=33);
|
||||
} {1}
|
||||
|
||||
do_execsql_test 4.3 {
|
||||
CREATE INDEX i1 ON t1( (d IS NULL), d );
|
||||
}
|
||||
|
||||
do_execsql_test 4.4 {
|
||||
SELECT (d IS NULL) FROM t1 RIGHT JOIN t2 ON (j=33);
|
||||
} {1}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -133,4 +133,58 @@ if {[wal_is_capable]} {
|
||||
} {1024 ok}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
testvfs tvfs -default 1
|
||||
tvfs filter xSync
|
||||
tvfs script xSyncCb
|
||||
proc xSyncCb {method file fileid flags} {
|
||||
incr ::sync($flags)
|
||||
}
|
||||
|
||||
reset_db
|
||||
|
||||
do_execsql_test vacuum-into-700 {
|
||||
CREATE TABLE t1(a, b);
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
}
|
||||
|
||||
foreach {tn pragma res} {
|
||||
710 {
|
||||
PRAGMA synchronous = normal
|
||||
} {normal 2}
|
||||
720 {
|
||||
PRAGMA synchronous = full
|
||||
} {normal 3}
|
||||
730 {
|
||||
PRAGMA synchronous = off
|
||||
} {}
|
||||
740 {
|
||||
PRAGMA synchronous = extra;
|
||||
} {normal 3}
|
||||
750 {
|
||||
PRAGMA fullfsync = 1;
|
||||
PRAGMA synchronous = full;
|
||||
} {full|dataonly 1 full 2}
|
||||
} {
|
||||
|
||||
forcedelete test.db2
|
||||
array unset ::sync
|
||||
do_execsql_test vacuum-into-$tn.1 "
|
||||
$pragma ;
|
||||
VACUUM INTO 'test.db2'
|
||||
"
|
||||
|
||||
do_test vacuum-into-$tn.2 {
|
||||
array get ::sync
|
||||
} $res
|
||||
}
|
||||
|
||||
db close
|
||||
tvfs delete
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
# 2022-10-24
|
||||
#
|
||||
# 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 test cases for wide table (tables with more than
|
||||
# 64 columns) and indexes that reference columns beyond the 63rd or 64th
|
||||
# column.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix widetab1
|
||||
|
||||
|
||||
# In order to pick the better index in the following query, SQLite needs to
|
||||
# be able to detect when an index that references later columns in a wide
|
||||
# table is a covering index.
|
||||
#
|
||||
do_execsql_test 100 {
|
||||
CREATE TABLE a(
|
||||
a00, a01, a02, a03, a04, a05, a06, a07, a08, a09,
|
||||
a10, a11, a12, a13, a14, a15, a16, a17, a18, a19,
|
||||
a20, a21, a22, a23, a24, a25, a26, a27, a28, a29,
|
||||
a30, a31, a32, a33, a34, a35, a36, a37, a38, a39,
|
||||
a40, a41, a42, a43, a44, a45, a46, a47, a48, a49,
|
||||
a50, a51, a52, a53, a54, a55, a56, a57, a58, a59,
|
||||
pd, bn, vb, bc, cn, ie, qm);
|
||||
CREATE INDEX a1 on a(pd, bn, vb, bc, cn); -- preferred index
|
||||
CREATE INDEX a2 on a(pd, bc, ie, qm); -- suboptimal index
|
||||
CREATE TABLE b(bg, bc, bn, iv, ln, mg);
|
||||
CREATE INDEX b1 on b(bn, iv, bg);
|
||||
}
|
||||
do_eqp_test 110 {
|
||||
SELECT dc, count(cn)
|
||||
FROM (SELECT coalesce(b.bg, a.bc) as dc, cn
|
||||
FROM a LEFT JOIN b
|
||||
ON a.bn = b.bn
|
||||
AND CASE WHEN a.vb IS NOT NULL THEN 1 ELSE 0 END = b.iv
|
||||
WHERE pd BETWEEN 0 AND 10)
|
||||
GROUP BY dc;
|
||||
} {
|
||||
QUERY PLAN
|
||||
|--SEARCH a USING COVERING INDEX a1 (pd>? AND pd<?)
|
||||
|--SEARCH b USING COVERING INDEX b1 (bn=? AND iv=?) LEFT-JOIN
|
||||
`--USE TEMP B-TREE FOR GROUP BY
|
||||
}
|
||||
|
||||
reset_db
|
||||
do_execsql_test 200 {
|
||||
CREATE TABLE t1(
|
||||
c00,c01,c02,c03,c04,c05,c06,c07,c08,c09,
|
||||
c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,
|
||||
c20,c21,c22,c23,c24,c25,c26,c27,c28,c29,
|
||||
c30,c31,c32,c33,c34,c35,c36,c37,c38,c39,
|
||||
c40,c41,c42,c43,c44,c45,c46,c47,c48,c49,
|
||||
c50,c51,c52,c53,c54,c55,c56,c57,c58,c59,
|
||||
c60,c61,c62,c63,c64,c65,c66,c67,c68,c69,
|
||||
c70,c71,c72,c73,c74,c75,c76,c77,c78,c79,
|
||||
c80,c81,c82,c83,c84,c85,c86,c87,c88,c89,
|
||||
c90,c91,c92,c93,c94,c95,c96,c97,c98,c99,
|
||||
a,b,c,d,e
|
||||
);
|
||||
CREATE INDEX t1x1 on t1(c00,a,b,
|
||||
c01,c02,c03,c04,c05,c06,c07,c08,c09,
|
||||
c10,c11,c12,c13,c14,c15,c16,c17,c18,c19,
|
||||
c20,c21,c22,c23,c24,c25,c26,c27,c28,c29,
|
||||
c30,c31,c32,c33,c34,c35,c36,c37,c38,c39,
|
||||
c40,c41,c42,c43,c44,c45,c46,c47,c48,c49,
|
||||
c50,c51,c52,c53,c54,c55,c56,c57,c58,c59,
|
||||
c60,c61,c62,c63,c64,c65,c66,c67,c68,c69,
|
||||
c70,c71,c72,c73,c74,c75,c76,c77,c78,c79,
|
||||
c80,c81,c82,c83,c84,c85,c86,c87,c88,c89,
|
||||
c90,c91,c92,c93,c94,c00,c96,c97,c98,c99
|
||||
);
|
||||
CREATE INDEX t1cd ON t1(c,d);
|
||||
CREATE INDEX t1x2 ON t1(c01,c02,c03,a,b);
|
||||
WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1000 FROM c WHERE x<9000)
|
||||
INSERT INTO t1 SELECT
|
||||
x+00, x+01, x+02, x+03, x+04, x+05, x+06, x+07, x+08, x+09,
|
||||
x+10, x+11, x+12, x+13, x+14, x+15, x+16, x+17, x+18, x+19,
|
||||
x+20, x+21, x+22, x+23, x+24, x+25, x+26, x+27, x+28, x+29,
|
||||
x+30, x+31, x+32, x+33, x+34, x+35, x+36, x+37, x+38, x+39,
|
||||
x+40, x+41, x+42, x+43, x+44, x+45, x+46, x+47, x+48, x+49,
|
||||
x+50, x+51, x+52, x+53, x+54, x+55, x+56, x+57, x+58, x+59,
|
||||
x+60, x+61, x+62, x+63, x+64, x+65, x+66, x+67, x+68, x+69,
|
||||
x+70, x+71, x+72, x+73, x+74, x+75, x+76, x+77, x+78, x+79,
|
||||
x+80, x+81, x+82, x+83, x+84, x+85, x+86, x+87, x+88, x+89,
|
||||
x+90, x+91, x+92, x+93, x+94, x+95, x+96, x+97, x+98, x+99,
|
||||
x+100, x+101, x+102, x+103, x+104 FROM c;
|
||||
}
|
||||
|
||||
do_execsql_test 210 {SELECT sum(c62) FROM t1;} 45620
|
||||
do_execsql_test 220 {SELECT sum(c63) FROM t1;} 45630
|
||||
do_execsql_test 230 {SELECT sum(c64) FROM t1;} 45640
|
||||
do_execsql_test 240 {SELECT sum(c65) FROM t1;} 45650
|
||||
|
||||
do_execsql_test 300 {
|
||||
BEGIN;
|
||||
SELECT sum(c62) FROM t1;
|
||||
UPDATE t1 SET c62=c62+1 WHERE c00=1000;
|
||||
SELECT sum(c62) FROM t1;
|
||||
} {45620 45621}
|
||||
do_execsql_test 310 {
|
||||
SELECT sum(c65) FROM t1;
|
||||
UPDATE t1 SET c65=c65+1 WHERE c00=1000;
|
||||
SELECT sum(c65) FROM t1;
|
||||
ROLLBACK;
|
||||
} {45650 45651}
|
||||
|
||||
do_execsql_test 320 {
|
||||
BEGIN;
|
||||
SELECT count(*) FROM t1;
|
||||
DELETE FROM t1 WHERE c=3102;
|
||||
SELECT COUNT(*) FROM t1;
|
||||
ROLLBACK;
|
||||
} {10 9}
|
||||
do_execsql_test 330 {
|
||||
BEGIN;
|
||||
SELECT count(*) FROM t1;
|
||||
DELETE FROM t1 WHERE c=3102 AND d=3103;
|
||||
SELECT COUNT(*) FROM t1;
|
||||
ROLLBACK;
|
||||
} {10 9}
|
||||
do_execsql_test 340 {
|
||||
BEGIN;
|
||||
DELETE FROM t1 WHERE (c,d) IN (VALUES(3102,3103),(4102,4103),(5102,5103),(1,2));
|
||||
SELECT count(*) FROM t1;
|
||||
ROLLBACK;
|
||||
} {7}
|
||||
|
||||
do_execsql_test 400 {
|
||||
DROP INDEX t1cd;
|
||||
DROP INDEX t1x1;
|
||||
DROP INDEX t1x2;
|
||||
CREATE INDEX t1x3 ON t1(c00,c05,c08);
|
||||
}
|
||||
do_execsql_test 410 {SELECT sum(c08) FROM t1 WHERE c00 IN (1000,5000);} 6016
|
||||
do_execsql_test 420 {SELECT sum(c63) FROM t1 WHERE c00 IN (1000,5000);} 6126
|
||||
do_execsql_test 430 {SELECT sum(c64) FROM t1 WHERE c00 IN (1000,5000);} 6128
|
||||
|
||||
do_execsql_test 500 {
|
||||
DROP INDEX t1x3;
|
||||
CREATE TABLE t2 AS SELECT * FROM t1;
|
||||
CREATE INDEX t1x4 ON t1(c00, c62, a, b);
|
||||
CREATE INDEX t2x4 ON t2(c01, c62, c63, b, c);
|
||||
SELECT t1.b, t2.b FROM t1 JOIN t2 ON t2.c01=t1.c00+1 WHERE +t1.b<7000
|
||||
ORDER BY +t1.b;
|
||||
} {101 101 1101 1101 2101 2101 3101 3101 4101 4101 5101 5101 6101 6101}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,58 @@
|
||||
# 2022 October 18
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix windowE
|
||||
|
||||
proc custom {a b} { return [string compare $a $b] }
|
||||
db collate custom custom
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT COLLATE custom);
|
||||
INSERT INTO t1 VALUES(1, 'one');
|
||||
INSERT INTO t1 VALUES(2, 'two');
|
||||
INSERT INTO t1 VALUES(3, 'three');
|
||||
INSERT INTO t1 VALUES(4, 'four');
|
||||
INSERT INTO t1 VALUES(5, 'five');
|
||||
INSERT INTO t1 VALUES(6, 'six');
|
||||
CREATE INDEX t1b ON t1(b);
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
SELECT * FROM t1
|
||||
} {
|
||||
1 one 2 two 3 three 4 four 5 five 6 six
|
||||
}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
SELECT group_concat(a,',') OVER win FROM t1
|
||||
WINDOW win AS (
|
||||
ORDER BY b RANGE BETWEEN 1 PRECEDING AND 2 PRECEDING
|
||||
)
|
||||
} {
|
||||
5 4 1 6 3 2
|
||||
}
|
||||
|
||||
proc custom {a b} { return [string compare $b $a] }
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
SELECT group_concat(a,',') OVER win FROM t1
|
||||
WINDOW win AS (
|
||||
ORDER BY b RANGE BETWEEN 1 PRECEDING AND 2 PRECEDING
|
||||
)
|
||||
} {
|
||||
5 5,4 5,4,1 5,4,1,6 5,4,1,6,3 5,4,1,6,3,2
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -304,6 +304,7 @@ set value_options {
|
||||
SQLITE_DEFAULT_WAL_AUTOCHECKPOINT
|
||||
SQLITE_DEFAULT_WAL_SYNCHRONOUS
|
||||
SQLITE_DEFAULT_WORKER_THREADS
|
||||
SQLITE_DQS
|
||||
SQLITE_ENABLE_8_3_NAMES
|
||||
SQLITE_ENABLE_CEROD
|
||||
SQLITE_ENABLE_LOCKING_STYLE
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
/**
|
||||
Strips C- and C++-style comments from stdin, sending the results to
|
||||
stdout. It assumes that its input is legal C-like code, and does
|
||||
only little error handling.
|
||||
|
||||
It treats string literals as anything starting and ending with
|
||||
matching double OR single quotes OR backticks (for use with
|
||||
scripting languages which use those). It assumes that a quote
|
||||
character within a string which uses the same quote type is escaped
|
||||
by a backslash. It should not be used on any code which might
|
||||
contain C/C++ comments inside heredocs, and similar constructs, as
|
||||
it will strip those out.
|
||||
|
||||
Usage: $0 [--keep-first|-k] < input > output
|
||||
|
||||
The --keep-first (-k) flag tells it to retain the first comment in the
|
||||
input stream (which is often a license or attribution block). It
|
||||
may be given repeatedly, each one incrementing the number of
|
||||
retained comments by one.
|
||||
|
||||
License: Public Domain
|
||||
Author: Stephan Beal (stephan@wanderinghorse.net)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#if 1
|
||||
#define MARKER(pfexp) \
|
||||
do{ printf("MARKER: %s:%d:\t",__FILE__,__LINE__); \
|
||||
printf pfexp; \
|
||||
} while(0)
|
||||
#else
|
||||
#define MARKER(exp) if(0) printf
|
||||
#endif
|
||||
|
||||
struct {
|
||||
FILE * input;
|
||||
FILE * output;
|
||||
int rc;
|
||||
int keepFirst;
|
||||
} App = {
|
||||
0/*input*/,
|
||||
0/*output*/,
|
||||
0/*rc*/,
|
||||
0/*keepFirst*/
|
||||
};
|
||||
|
||||
void do_it_all(void){
|
||||
enum states {
|
||||
S_NONE = 0 /* not in comment */,
|
||||
S_SLASH1 = 1 /* slash - possibly comment prefix */,
|
||||
S_CPP = 2 /* in C++ comment */,
|
||||
S_C = 3 /* in C comment */
|
||||
};
|
||||
int ch, prev = EOF;
|
||||
FILE * out = App.output;
|
||||
int const slash = '/';
|
||||
int const star = '*';
|
||||
int line = 1;
|
||||
int col = 0;
|
||||
enum states state = S_NONE /* current state */;
|
||||
int elide = 0 /* true if currently eliding output */;
|
||||
int state3Col = -99
|
||||
/* huge kludge for odd corner case: */
|
||||
/*/ <--- here. state3Col marks the source column in which a C-style
|
||||
comment starts, so that it can tell if star-slash inside a
|
||||
C-style comment is the end of the comment or is the weird corner
|
||||
case marked at the start of _this_ comment block. */;
|
||||
for( ; EOF != (ch = fgetc(App.input)); prev = ch,
|
||||
++col){
|
||||
switch(state){
|
||||
case S_NONE:
|
||||
if('\''==ch || '"'==ch || '`'==ch){
|
||||
/* Read string literal...
|
||||
needed to properly catch comments in strings. */
|
||||
int const quote = ch,
|
||||
startLine = line, startCol = col;
|
||||
int ch2, escaped = 0, endOfString = 0;
|
||||
fputc(ch, out);
|
||||
for( ++col; !endOfString && EOF != (ch2 = fgetc(App.input));
|
||||
++col ){
|
||||
switch(ch2){
|
||||
case '\\': escaped = !escaped;
|
||||
break;
|
||||
case '`':
|
||||
case '\'':
|
||||
case '"':
|
||||
if(!escaped && quote == ch2) endOfString = 1;
|
||||
escaped = 0;
|
||||
break;
|
||||
default:
|
||||
escaped = 0;
|
||||
break;
|
||||
}
|
||||
if('\n'==ch2){
|
||||
++line;
|
||||
col = 0;
|
||||
}
|
||||
fputc(ch2, out);
|
||||
}
|
||||
if(EOF == ch2){
|
||||
fprintf(stderr, "Unexpected EOF while reading %s literal "
|
||||
"on line %d column %d.\n",
|
||||
('\''==ch) ? "char" : "string",
|
||||
startLine, startCol);
|
||||
App.rc = 1;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if(slash == ch){
|
||||
/* MARKER(("state 0 ==> 1 @ %d:%d\n", line, col)); */
|
||||
state = S_SLASH1;
|
||||
break;
|
||||
}
|
||||
fputc(ch, out);
|
||||
break;
|
||||
case S_SLASH1: /* 1 slash */
|
||||
/* MARKER(("SLASH1 @ %d:%d App.keepFirst=%d\n",
|
||||
line, col, App.keepFirst)); */
|
||||
switch(ch){
|
||||
case '*':
|
||||
/* Enter C comment */
|
||||
if(App.keepFirst>0){
|
||||
elide = 0;
|
||||
--App.keepFirst;
|
||||
}else{
|
||||
elide = 1;
|
||||
}
|
||||
/*MARKER(("state 1 ==> 3 @ %d:%d\n", line, col));*/
|
||||
state = S_C;
|
||||
state3Col = col-1;
|
||||
if(!elide){
|
||||
fputc(prev, out);
|
||||
fputc(ch, out);
|
||||
}
|
||||
break;
|
||||
case '/':
|
||||
/* Enter C++ comment */
|
||||
if(App.keepFirst>0){
|
||||
elide = 0;
|
||||
--App.keepFirst;
|
||||
}else{
|
||||
elide = 1;
|
||||
}
|
||||
/*MARKER(("state 1 ==> 2 @ %d:%d\n", line, col));*/
|
||||
state = S_CPP;
|
||||
if(!elide){
|
||||
fputc(prev, out);
|
||||
fputc(ch, out);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* It wasn't a comment after all. */
|
||||
state = S_NONE;
|
||||
if(!elide){
|
||||
fputc(prev, out);
|
||||
fputc(ch, out);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case S_CPP: /* C++ comment */
|
||||
if('\n' == ch){
|
||||
/* MARKER(("state 2 ==> 0 @ %d:%d\n", line, col)); */
|
||||
state = S_NONE;
|
||||
elide = 0;
|
||||
}
|
||||
if(!elide){
|
||||
fputc(ch, out);
|
||||
}
|
||||
break;
|
||||
case S_C: /* C comment */
|
||||
if(!elide){
|
||||
fputc(ch, out);
|
||||
}
|
||||
if(slash == ch){
|
||||
if(star == prev){
|
||||
/* MARKER(("state 3 ==> 0 @ %d:%d\n", line, col)); */
|
||||
/* Corner case which breaks this: */
|
||||
/*/ <-- slash there */
|
||||
/* That shows up twice in a piece of 3rd-party
|
||||
code i use. */
|
||||
/* And thus state3Col was introduced :/ */
|
||||
if(col!=state3Col+2){
|
||||
state = S_NONE;
|
||||
elide = 0;
|
||||
state3Col = -99;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(!"impossible!");
|
||||
break;
|
||||
}
|
||||
if('\n' == ch){
|
||||
++line;
|
||||
col = 0;
|
||||
state3Col = -99;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void usage(char const *zAppName){
|
||||
fprintf(stderr, "Strips C- and C++-style comments from stdin and sends "
|
||||
"the results to stdout.\n");
|
||||
fprintf(stderr, "Usage: %s [--keep-first|-k] < input > output\n", zAppName);
|
||||
}
|
||||
|
||||
int main( int argc, char const * const * argv ){
|
||||
int i;
|
||||
for(i = 1; i < argc; ++i){
|
||||
char const * zArg = argv[i];
|
||||
while( '-'==*zArg ) ++zArg;
|
||||
if( 0==strcmp(zArg,"k")
|
||||
|| 0==strcmp(zArg,"keep-first") ){
|
||||
++App.keepFirst;
|
||||
}else{
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
App.input = stdin;
|
||||
App.output = stdout;
|
||||
do_it_all();
|
||||
return App.rc ? 1 : 0;
|
||||
}
|
||||
Reference in New Issue
Block a user