2 ** This file requires access to sqlite3.c static state in order to
3 ** implement certain WASM-specific features, and thus directly
4 ** includes that file. Unlike the rest of sqlite3.c, this file
5 ** requires compiling with -std=c99 (or equivalent, or a later C
6 ** version) because it makes use of features not available in C89.
8 ** At its simplest, to build sqlite3.wasm either place this file
9 ** in the same directory as sqlite3.c/h before compilation or use the
10 ** -I/path flag to tell the compiler where to find both of those
11 ** files, then compile this file. For example:
13 ** emcc -o sqlite3.wasm ... -I/path/to/sqlite3-c-and-h sqlite3-wasm.c
16 #ifdef SQLITE_WASM_ENABLE_C_TESTS
18 ** Code blocked off by SQLITE_WASM_TESTS is intended solely for use in
19 ** unit/regression testing. They may be safely omitted from
20 ** client-side builds. The main unit test script, tester1.js, will
21 ** skip related tests if it doesn't find the corresponding functions
22 ** in the WASM exports.
24 # define SQLITE_WASM_TESTS 1
26 # define SQLITE_WASM_TESTS 0
30 ** Threading and file locking: JS is single-threaded. Each Worker
31 ** thread is a separate instance of the JS engine so can never access
32 ** the same db handle as another thread, thus multi-threading support
33 ** is unnecessary in the library. Because the filesystems are virtual
34 ** and local to a given wasm runtime instance, two Workers can never
35 ** access the same db file at once, with the exception of OPFS.
37 ** Summary: except for the case of OPFS, which supports locking using
38 ** its own API, threading and file locking support are unnecessary in
43 ** Undefine any SQLITE_... config flags which we specifically do not
44 ** want defined. Please keep these alphabetized.
46 #undef SQLITE_OMIT_DESERIALIZE
47 #undef SQLITE_OMIT_MEMORYDB
50 ** Define any SQLITE_... config defaults we want if they aren't
51 ** overridden by the builder. Please keep these alphabetized.
54 /**********************************************************************/
56 #ifndef SQLITE_DEFAULT_CACHE_SIZE
58 ** The OPFS impls benefit tremendously from an increased cache size
59 ** when working on large workloads, e.g. speedtest1 --size 50 or
60 ** higher. On smaller workloads, e.g. speedtest1 --size 25, they
61 ** clearly benefit from having 4mb of cache, but not as much as a
62 ** larger cache benefits the larger workloads. Speed differences
63 ** between 2x and nearly 3x have been measured with ample page cache.
65 # define SQLITE_DEFAULT_CACHE_SIZE -16384
67 #if !defined(SQLITE_DEFAULT_PAGE_SIZE)
69 ** OPFS performance is improved by approx. 12% with a page size of 8kb
70 ** instead of 4kb. Performance with 16kb is equivalent to 8kb.
72 ** Performance difference of kvvfs with a page size of 8kb compared to
73 ** 4kb, as measured by speedtest1 --size 4, is indeterminate:
74 ** measurements are all over the place either way and not
75 ** significantly different.
77 # define SQLITE_DEFAULT_PAGE_SIZE 8192
79 #ifndef SQLITE_DEFAULT_UNIX_VFS
80 # define SQLITE_DEFAULT_UNIX_VFS "unix-none"
85 /**********************************************************************/
86 /* SQLITE_ENABLE_... */
88 ** Unconditionally enable API_ARMOR in the WASM build. It ensures that
89 ** public APIs behave predictable in the face of passing illegal NULLs
90 ** or ranges which might otherwise invoke undefined behavior.
92 #undef SQLITE_ENABLE_API_ARMOR
93 #define SQLITE_ENABLE_API_ARMOR 1
95 #ifndef SQLITE_ENABLE_BYTECODE_VTAB
96 # define SQLITE_ENABLE_BYTECODE_VTAB 1
98 #ifndef SQLITE_ENABLE_DBPAGE_VTAB
99 # define SQLITE_ENABLE_DBPAGE_VTAB 1
101 #ifndef SQLITE_ENABLE_DBSTAT_VTAB
102 # define SQLITE_ENABLE_DBSTAT_VTAB 1
104 #ifndef SQLITE_ENABLE_EXPLAIN_COMMENTS
105 # define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
107 #ifndef SQLITE_ENABLE_FTS4
108 # define SQLITE_ENABLE_FTS4 1
110 #ifndef SQLITE_ENABLE_MATH_FUNCTIONS
111 # define SQLITE_ENABLE_MATH_FUNCTIONS 1
113 #ifndef SQLITE_ENABLE_OFFSET_SQL_FUNC
114 # define SQLITE_ENABLE_OFFSET_SQL_FUNC 1
116 #ifndef SQLITE_ENABLE_PREUPDATE_HOOK
117 # define SQLITE_ENABLE_PREUPDATE_HOOK 1 /*required by session extension*/
119 #ifndef SQLITE_ENABLE_RTREE
120 # define SQLITE_ENABLE_RTREE 1
122 #ifndef SQLITE_ENABLE_SESSION
123 # define SQLITE_ENABLE_SESSION 1
125 #ifndef SQLITE_ENABLE_STMTVTAB
126 # define SQLITE_ENABLE_STMTVTAB 1
128 #ifndef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
129 # define SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
132 /**********************************************************************/
134 #ifndef SQLITE_OMIT_DEPRECATED
135 # define SQLITE_OMIT_DEPRECATED 1
137 #ifndef SQLITE_OMIT_LOAD_EXTENSION
138 # define SQLITE_OMIT_LOAD_EXTENSION 1
140 #ifndef SQLITE_OMIT_SHARED_CACHE
141 # define SQLITE_OMIT_SHARED_CACHE 1
143 #ifndef SQLITE_OMIT_UTF16
144 # define SQLITE_OMIT_UTF16 1
146 #ifndef SQLITE_OS_KV_OPTIONAL
147 # define SQLITE_OS_KV_OPTIONAL 1
150 /**********************************************************************/
152 #ifndef SQLITE_STRICT_SUBTYPE
153 # define SQLITE_STRICT_SUBTYPE 1
156 /**********************************************************************/
158 #ifndef SQLITE_TEMP_STORE
159 # define SQLITE_TEMP_STORE 2
161 #ifndef SQLITE_THREADSAFE
162 # define SQLITE_THREADSAFE 0
165 /**********************************************************************/
167 #ifndef SQLITE_USE_URI
168 # define SQLITE_USE_URI 1
171 #ifdef SQLITE_WASM_EXTRA_INIT
172 # define SQLITE_EXTRA_INIT sqlite3_wasm_extra_init
178 ** SQLITE_WASM_EXPORT is functionally identical to EMSCRIPTEN_KEEPALIVE
179 ** but is not Emscripten-specific. It explicitly marks functions for
180 ** export into the target wasm file without requiring explicit listing
181 ** of those functions in Emscripten's -sEXPORTED_FUNCTIONS=... list
182 ** (or equivalent in other build platforms). Any function with neither
183 ** this attribute nor which is listed as an explicit export will not
184 ** be exported from the wasm file (but may still be used internally
185 ** within the wasm file).
187 ** The functions in this file (sqlite3-wasm.c) which require exporting
188 ** are marked with this flag. They may also be added to any explicit
189 ** build-time export list but need not be. All of these APIs are
190 ** intended for use only within the project's own JS/WASM code, and
191 ** not by client code, so an argument can be made for reducing their
192 ** visibility by not including them in any build-time export lists.
194 ** 2022-09-11: it's not yet _proven_ that this approach works in
195 ** non-Emscripten builds. If not, such builds will need to export
196 ** those using the --export=... wasm-ld flag (or equivalent). As of
197 ** this writing we are tied to Emscripten for various reasons
198 ** and cannot test the library with other build environments.
200 #define SQLITE_WASM_EXPORT __attribute__((used,visibility("default")))
202 //__attribute__((export_name("theExportedName"), used, visibility("default")))
205 ** Which sqlite3.c we're using needs to be configurable to enable
206 ** building against a custom copy, e.g. the SEE variant. Note that we
207 ** #include the .c file, rather than the header, so that the WASM
208 ** extensions have access to private API internals.
210 ** The caveat here is that custom variants need to account for
211 ** exporting any necessary symbols (e.g. sqlite3_activate_see()). We
212 ** cannot export them from here using SQLITE_WASM_EXPORT because that
213 ** attribute (apparently) has to be part of the function definition.
216 # define SQLITE_C sqlite3.c /* yes, .c instead of .h. */
218 #define INC__STRINGIFY_(f) #f
219 #define INC__STRINGIFY(f) INC__STRINGIFY_(f)
220 #include INC__STRINGIFY(SQLITE_C)
221 #undef INC__STRINGIFY_
222 #undef INC__STRINGIFY
225 #if defined(__EMSCRIPTEN__)
226 # include <emscripten/console.h>
231 ** An EXPERIMENT in implementing a stack-based allocator analog to
232 ** Emscripten's stackSave(), stackAlloc(), stackRestore().
233 ** Unfortunately, this cannot work together with Emscripten because
234 ** Emscripten defines its own native one and we'd stomp on each
235 ** other's memory. Other than that complication, basic tests show it
236 ** to work just fine.
238 ** Another option is to malloc() a chunk of our own and call that our
241 SQLITE_WASM_EXPORT
void * sqlite3__wasm_stack_end(void){
242 extern void __heap_base
243 /* see https://stackoverflow.com/questions/10038964 */;
246 SQLITE_WASM_EXPORT
void * sqlite3__wasm_stack_begin(void){
247 extern void __data_end
;
250 static void * pWasmStackPtr
= 0;
251 SQLITE_WASM_EXPORT
void * sqlite3__wasm_stack_ptr(void){
252 if(!pWasmStackPtr
) pWasmStackPtr
= sqlite3__wasm_stack_end();
253 return pWasmStackPtr
;
255 SQLITE_WASM_EXPORT
void sqlite3__wasm_stack_restore(void * p
){
258 SQLITE_WASM_EXPORT
void * sqlite3__wasm_stack_alloc(int n
){
260 n
= (n
+ 7) & ~7 /* align to 8-byte boundary */;
261 unsigned char * const p
= (unsigned char *)sqlite3__wasm_stack_ptr();
262 unsigned const char * const b
= (unsigned const char *)sqlite3__wasm_stack_begin();
263 if(b
+ n
>= p
|| b
+ n
< b
/*overflow*/) return 0;
264 return pWasmStackPtr
= p
- n
;
266 #endif /* stack allocator experiment */
269 ** State for the "pseudo-stack" allocator implemented in
270 ** sqlite3__wasm_pstack_xyz(). In order to avoid colliding with
271 ** Emscripten-controled stack space, it carves out a bit of stack
272 ** memory to use for that purpose. This memory ends up in the
273 ** WASM-managed memory, such that routines which manipulate the wasm
274 ** heap can also be used to manipulate this memory.
276 ** This particular allocator is intended for small allocations such as
277 ** storage for output pointers. We cannot reasonably size it large
278 ** enough for general-purpose string conversions because some of our
279 ** tests use input files (strings) of 16MB+.
281 static unsigned char PStack_mem
[512 * 8] = {0};
283 unsigned const char * const pBegin
;/* Start (inclusive) of memory */
284 unsigned const char * const pEnd
; /* One-after-the-end of memory */
285 unsigned char * pPos
; /* Current stack pointer */
288 &PStack_mem
[0] + sizeof(PStack_mem
),
289 &PStack_mem
[0] + sizeof(PStack_mem
)
292 ** Returns the current pstack position.
294 SQLITE_WASM_EXPORT
void * sqlite3__wasm_pstack_ptr(void){
298 ** Sets the pstack position poitner to p. Results are undefined if the
299 ** given value did not come from sqlite3__wasm_pstack_ptr().
301 SQLITE_WASM_EXPORT
void sqlite3__wasm_pstack_restore(unsigned char * p
){
302 assert(p
>=PStack
.pBegin
&& p
<=PStack
.pEnd
&& p
>=PStack
.pPos
);
303 assert(0==((unsigned long long)p
& 0x7));
304 if(p
>=PStack
.pBegin
&& p
<=PStack
.pEnd
/*&& p>=PStack.pPos*/){
309 ** Allocate and zero out n bytes from the pstack. Returns a pointer to
310 ** the memory on success, 0 on error (including a negative n value). n
311 ** is always adjusted to be a multiple of 8 and returned memory is
312 ** always zeroed out before returning (because this keeps the client
313 ** JS code from having to do so, and most uses of the pstack will
314 ** call for doing so).
316 SQLITE_WASM_EXPORT
void * sqlite3__wasm_pstack_alloc(int n
){
318 //if( n & 0x7 ) n += 8 - (n & 0x7) /* align to 8-byte boundary */;
319 n
= (n
+ 7) & ~7 /* align to 8-byte boundary */;
320 if( PStack
.pBegin
+ n
> PStack
.pPos
/*not enough space left*/
321 || PStack
.pBegin
+ n
<= PStack
.pBegin
/*overflow*/ ) return 0;
322 memset((PStack
.pPos
= PStack
.pPos
- n
), 0, (unsigned int)n
);
326 ** Return the number of bytes left which can be
327 ** sqlite3__wasm_pstack_alloc()'d.
329 SQLITE_WASM_EXPORT
int sqlite3__wasm_pstack_remaining(void){
330 assert(PStack
.pPos
>= PStack
.pBegin
);
331 assert(PStack
.pPos
<= PStack
.pEnd
);
332 return (int)(PStack
.pPos
- PStack
.pBegin
);
336 ** Return the total number of bytes available in the pstack, including
337 ** any space which is currently allocated. This value is a
338 ** compile-time constant.
340 SQLITE_WASM_EXPORT
int sqlite3__wasm_pstack_quota(void){
341 return (int)(PStack
.pEnd
- PStack
.pBegin
);
345 ** This function is NOT part of the sqlite3 public API. It is strictly
346 ** for use by the sqlite project's own JS/WASM bindings.
348 ** For purposes of certain hand-crafted C/Wasm function bindings, we
349 ** need a way of reporting errors which is consistent with the rest of
350 ** the C API, as opposed to throwing JS exceptions. To that end, this
351 ** internal-use-only function is a thin proxy around
352 ** sqlite3ErrorWithMessage(). The intent is that it only be used from
353 ** Wasm bindings such as sqlite3_prepare_v2/v3(), and definitely not
359 int sqlite3__wasm_db_error(sqlite3
*db
, int err_code
, const char *zMsg
){
362 const int nMsg
= sqlite3Strlen30(zMsg
);
363 sqlite3_mutex_enter(sqlite3_db_mutex(db
));
364 sqlite3ErrorWithMsg(db
, err_code
, "%.*s", nMsg
, zMsg
);
365 sqlite3_mutex_leave(sqlite3_db_mutex(db
));
367 sqlite3ErrorWithMsg(db
, err_code
, NULL
);
373 #if SQLITE_WASM_TESTS
374 struct WasmTestStruct
{
379 void (*xFunc
)(void*);
381 typedef struct WasmTestStruct WasmTestStruct
;
383 void sqlite3__wasm_test_struct(WasmTestStruct
* s
){
389 if(s
->xFunc
) s
->xFunc(s
);
393 #endif /* SQLITE_WASM_TESTS */
396 ** This function is NOT part of the sqlite3 public API. It is strictly
397 ** for use by the sqlite project's own JS/WASM bindings. Unlike the
398 ** rest of the sqlite3 API, this part requires C99 for snprintf() and
401 ** Returns a string containing a JSON-format "enum" of C-level
402 ** constants and struct-related metadata intended to be imported into
403 ** the JS environment. The JSON is initialized the first time this
404 ** function is called and that result is reused for all future calls.
406 ** If this function returns NULL then it means that the internal
407 ** buffer is not large enough for the generated JSON and needs to be
408 ** increased. In debug builds that will trigger an assert().
411 const char * sqlite3__wasm_enum_json(void){
412 static char aBuffer
[1024 * 20] = {0} /* where the JSON goes */;
413 int n
= 0, nChildren
= 0, nStruct
= 0
414 /* output counters for figuring out where commas go */;
415 char * zPos
= &aBuffer
[1] /* skip first byte for now to help protect
416 ** against a small race condition */;
417 char const * const zEnd
= &aBuffer
[0] + sizeof(aBuffer
) /* one-past-the-end */;
418 if(aBuffer
[0]) return aBuffer
;
419 /* Leave aBuffer[0] at 0 until the end to help guard against a tiny
420 ** race condition. If this is called twice concurrently, they might
421 ** end up both writing to aBuffer, but they'll both write the same
422 ** thing, so that's okay. If we set byte 0 up front then the 2nd
423 ** instance might return and use the string before the 1st instance
424 ** is done filling it. */
426 /* Core output macros... */
427 #define lenCheck assert(zPos < zEnd - 128 \
428 && "sqlite3__wasm_enum_json() buffer is too small."); \
429 if( zPos >= zEnd - 128 ) return 0
430 #define outf(format,...) \
431 zPos += snprintf(zPos, ((size_t)(zEnd - zPos)), format, __VA_ARGS__); \
433 #define out(TXT) outf("%s",TXT)
434 #define CloseBrace(LEVEL) \
435 assert(LEVEL<5); memset(zPos, '}', LEVEL); zPos+=LEVEL; lenCheck
437 /* Macros for emitting maps of integer- and string-type macros to
439 #define DefGroup(KEY) n = 0; \
440 outf("%s\"" #KEY "\": {",(nChildren++ ? "," : ""));
441 #define DefInt(KEY) \
442 outf("%s\"%s\": %d", (n++ ? ", " : ""), #KEY, (int)KEY)
443 #define DefStr(KEY) \
444 outf("%s\"%s\": \"%s\"", (n++ ? ", " : ""), #KEY, KEY)
445 #define _DefGroup CloseBrace(1)
447 /* The following groups are sorted alphabetic by group name. */
449 DefInt(SQLITE_ACCESS_EXISTS
);
450 DefInt(SQLITE_ACCESS_READWRITE
);
451 DefInt(SQLITE_ACCESS_READ
)/*docs say this is unused*/;
454 DefGroup(authorizer
){
456 DefInt(SQLITE_IGNORE
);
457 DefInt(SQLITE_CREATE_INDEX
);
458 DefInt(SQLITE_CREATE_TABLE
);
459 DefInt(SQLITE_CREATE_TEMP_INDEX
);
460 DefInt(SQLITE_CREATE_TEMP_TABLE
);
461 DefInt(SQLITE_CREATE_TEMP_TRIGGER
);
462 DefInt(SQLITE_CREATE_TEMP_VIEW
);
463 DefInt(SQLITE_CREATE_TRIGGER
);
464 DefInt(SQLITE_CREATE_VIEW
);
465 DefInt(SQLITE_DELETE
);
466 DefInt(SQLITE_DROP_INDEX
);
467 DefInt(SQLITE_DROP_TABLE
);
468 DefInt(SQLITE_DROP_TEMP_INDEX
);
469 DefInt(SQLITE_DROP_TEMP_TABLE
);
470 DefInt(SQLITE_DROP_TEMP_TRIGGER
);
471 DefInt(SQLITE_DROP_TEMP_VIEW
);
472 DefInt(SQLITE_DROP_TRIGGER
);
473 DefInt(SQLITE_DROP_VIEW
);
474 DefInt(SQLITE_INSERT
);
475 DefInt(SQLITE_PRAGMA
);
477 DefInt(SQLITE_SELECT
);
478 DefInt(SQLITE_TRANSACTION
);
479 DefInt(SQLITE_UPDATE
);
480 DefInt(SQLITE_ATTACH
);
481 DefInt(SQLITE_DETACH
);
482 DefInt(SQLITE_ALTER_TABLE
);
483 DefInt(SQLITE_REINDEX
);
484 DefInt(SQLITE_ANALYZE
);
485 DefInt(SQLITE_CREATE_VTABLE
);
486 DefInt(SQLITE_DROP_VTABLE
);
487 DefInt(SQLITE_FUNCTION
);
488 DefInt(SQLITE_SAVEPOINT
);
489 //DefInt(SQLITE_COPY) /* No longer used */;
490 DefInt(SQLITE_RECURSIVE
);
493 DefGroup(blobFinalizers
) {
494 /* SQLITE_STATIC/TRANSIENT need to be handled explicitly as
495 ** integers to avoid casting-related warnings. */
496 out("\"SQLITE_STATIC\":0, \"SQLITE_TRANSIENT\":-1");
497 outf(",\"SQLITE_WASM_DEALLOC\": %lld",
498 (sqlite3_int64
)(sqlite3_free
));
502 DefInt(SQLITE_CHANGESETSTART_INVERT
);
503 DefInt(SQLITE_CHANGESETAPPLY_NOSAVEPOINT
);
504 DefInt(SQLITE_CHANGESETAPPLY_INVERT
);
505 DefInt(SQLITE_CHANGESETAPPLY_IGNORENOOP
);
507 DefInt(SQLITE_CHANGESET_DATA
);
508 DefInt(SQLITE_CHANGESET_NOTFOUND
);
509 DefInt(SQLITE_CHANGESET_CONFLICT
);
510 DefInt(SQLITE_CHANGESET_CONSTRAINT
);
511 DefInt(SQLITE_CHANGESET_FOREIGN_KEY
);
513 DefInt(SQLITE_CHANGESET_OMIT
);
514 DefInt(SQLITE_CHANGESET_REPLACE
);
515 DefInt(SQLITE_CHANGESET_ABORT
);
519 DefInt(SQLITE_CONFIG_SINGLETHREAD
);
520 DefInt(SQLITE_CONFIG_MULTITHREAD
);
521 DefInt(SQLITE_CONFIG_SERIALIZED
);
522 DefInt(SQLITE_CONFIG_MALLOC
);
523 DefInt(SQLITE_CONFIG_GETMALLOC
);
524 DefInt(SQLITE_CONFIG_SCRATCH
);
525 DefInt(SQLITE_CONFIG_PAGECACHE
);
526 DefInt(SQLITE_CONFIG_HEAP
);
527 DefInt(SQLITE_CONFIG_MEMSTATUS
);
528 DefInt(SQLITE_CONFIG_MUTEX
);
529 DefInt(SQLITE_CONFIG_GETMUTEX
);
530 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
531 DefInt(SQLITE_CONFIG_LOOKASIDE
);
532 DefInt(SQLITE_CONFIG_PCACHE
);
533 DefInt(SQLITE_CONFIG_GETPCACHE
);
534 DefInt(SQLITE_CONFIG_LOG
);
535 DefInt(SQLITE_CONFIG_URI
);
536 DefInt(SQLITE_CONFIG_PCACHE2
);
537 DefInt(SQLITE_CONFIG_GETPCACHE2
);
538 DefInt(SQLITE_CONFIG_COVERING_INDEX_SCAN
);
539 DefInt(SQLITE_CONFIG_SQLLOG
);
540 DefInt(SQLITE_CONFIG_MMAP_SIZE
);
541 DefInt(SQLITE_CONFIG_WIN32_HEAPSIZE
);
542 DefInt(SQLITE_CONFIG_PCACHE_HDRSZ
);
543 DefInt(SQLITE_CONFIG_PMASZ
);
544 DefInt(SQLITE_CONFIG_STMTJRNL_SPILL
);
545 DefInt(SQLITE_CONFIG_SMALL_MALLOC
);
546 DefInt(SQLITE_CONFIG_SORTERREF_SIZE
);
547 DefInt(SQLITE_CONFIG_MEMDB_MAXSIZE
);
548 /* maintenance note: we specifically do not include
549 SQLITE_CONFIG_ROWID_IN_VIEW here, on the grounds that
550 it's only for legacy support and no apps written with
551 this API require that. */
554 DefGroup(dataTypes
) {
555 DefInt(SQLITE_INTEGER
);
556 DefInt(SQLITE_FLOAT
);
563 DefInt(SQLITE_DBCONFIG_MAINDBNAME
);
564 DefInt(SQLITE_DBCONFIG_LOOKASIDE
);
565 DefInt(SQLITE_DBCONFIG_ENABLE_FKEY
);
566 DefInt(SQLITE_DBCONFIG_ENABLE_TRIGGER
);
567 DefInt(SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
);
568 DefInt(SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
);
569 DefInt(SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
);
570 DefInt(SQLITE_DBCONFIG_ENABLE_QPSG
);
571 DefInt(SQLITE_DBCONFIG_TRIGGER_EQP
);
572 DefInt(SQLITE_DBCONFIG_RESET_DATABASE
);
573 DefInt(SQLITE_DBCONFIG_DEFENSIVE
);
574 DefInt(SQLITE_DBCONFIG_WRITABLE_SCHEMA
);
575 DefInt(SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
);
576 DefInt(SQLITE_DBCONFIG_DQS_DML
);
577 DefInt(SQLITE_DBCONFIG_DQS_DDL
);
578 DefInt(SQLITE_DBCONFIG_ENABLE_VIEW
);
579 DefInt(SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
);
580 DefInt(SQLITE_DBCONFIG_TRUSTED_SCHEMA
);
581 DefInt(SQLITE_DBCONFIG_STMT_SCANSTATUS
);
582 DefInt(SQLITE_DBCONFIG_REVERSE_SCANORDER
);
583 DefInt(SQLITE_DBCONFIG_MAX
);
587 DefInt(SQLITE_DBSTATUS_LOOKASIDE_USED
);
588 DefInt(SQLITE_DBSTATUS_CACHE_USED
);
589 DefInt(SQLITE_DBSTATUS_SCHEMA_USED
);
590 DefInt(SQLITE_DBSTATUS_STMT_USED
);
591 DefInt(SQLITE_DBSTATUS_LOOKASIDE_HIT
);
592 DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE
);
593 DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL
);
594 DefInt(SQLITE_DBSTATUS_CACHE_HIT
);
595 DefInt(SQLITE_DBSTATUS_CACHE_MISS
);
596 DefInt(SQLITE_DBSTATUS_CACHE_WRITE
);
597 DefInt(SQLITE_DBSTATUS_DEFERRED_FKS
);
598 DefInt(SQLITE_DBSTATUS_CACHE_USED_SHARED
);
599 DefInt(SQLITE_DBSTATUS_CACHE_SPILL
);
600 DefInt(SQLITE_DBSTATUS_MAX
);
603 DefGroup(encodings
) {
604 /* Noting that the wasm binding only aims to support UTF-8. */
606 DefInt(SQLITE_UTF16LE
);
607 DefInt(SQLITE_UTF16BE
);
608 DefInt(SQLITE_UTF16
);
609 /*deprecated DefInt(SQLITE_ANY); */
610 DefInt(SQLITE_UTF16_ALIGNED
);
614 DefInt(SQLITE_FCNTL_LOCKSTATE
);
615 DefInt(SQLITE_FCNTL_GET_LOCKPROXYFILE
);
616 DefInt(SQLITE_FCNTL_SET_LOCKPROXYFILE
);
617 DefInt(SQLITE_FCNTL_LAST_ERRNO
);
618 DefInt(SQLITE_FCNTL_SIZE_HINT
);
619 DefInt(SQLITE_FCNTL_CHUNK_SIZE
);
620 DefInt(SQLITE_FCNTL_FILE_POINTER
);
621 DefInt(SQLITE_FCNTL_SYNC_OMITTED
);
622 DefInt(SQLITE_FCNTL_WIN32_AV_RETRY
);
623 DefInt(SQLITE_FCNTL_PERSIST_WAL
);
624 DefInt(SQLITE_FCNTL_OVERWRITE
);
625 DefInt(SQLITE_FCNTL_VFSNAME
);
626 DefInt(SQLITE_FCNTL_POWERSAFE_OVERWRITE
);
627 DefInt(SQLITE_FCNTL_PRAGMA
);
628 DefInt(SQLITE_FCNTL_BUSYHANDLER
);
629 DefInt(SQLITE_FCNTL_TEMPFILENAME
);
630 DefInt(SQLITE_FCNTL_MMAP_SIZE
);
631 DefInt(SQLITE_FCNTL_TRACE
);
632 DefInt(SQLITE_FCNTL_HAS_MOVED
);
633 DefInt(SQLITE_FCNTL_SYNC
);
634 DefInt(SQLITE_FCNTL_COMMIT_PHASETWO
);
635 DefInt(SQLITE_FCNTL_WIN32_SET_HANDLE
);
636 DefInt(SQLITE_FCNTL_WAL_BLOCK
);
637 DefInt(SQLITE_FCNTL_ZIPVFS
);
638 DefInt(SQLITE_FCNTL_RBU
);
639 DefInt(SQLITE_FCNTL_VFS_POINTER
);
640 DefInt(SQLITE_FCNTL_JOURNAL_POINTER
);
641 DefInt(SQLITE_FCNTL_WIN32_GET_HANDLE
);
642 DefInt(SQLITE_FCNTL_PDB
);
643 DefInt(SQLITE_FCNTL_BEGIN_ATOMIC_WRITE
);
644 DefInt(SQLITE_FCNTL_COMMIT_ATOMIC_WRITE
);
645 DefInt(SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE
);
646 DefInt(SQLITE_FCNTL_LOCK_TIMEOUT
);
647 DefInt(SQLITE_FCNTL_DATA_VERSION
);
648 DefInt(SQLITE_FCNTL_SIZE_LIMIT
);
649 DefInt(SQLITE_FCNTL_CKPT_DONE
);
650 DefInt(SQLITE_FCNTL_RESERVE_BYTES
);
651 DefInt(SQLITE_FCNTL_CKPT_START
);
652 DefInt(SQLITE_FCNTL_EXTERNAL_READER
);
653 DefInt(SQLITE_FCNTL_CKSM_FILE
);
654 DefInt(SQLITE_FCNTL_RESET_CACHE
);
658 DefInt(SQLITE_LOCK_NONE
);
659 DefInt(SQLITE_LOCK_SHARED
);
660 DefInt(SQLITE_LOCK_RESERVED
);
661 DefInt(SQLITE_LOCK_PENDING
);
662 DefInt(SQLITE_LOCK_EXCLUSIVE
);
666 DefInt(SQLITE_IOCAP_ATOMIC
);
667 DefInt(SQLITE_IOCAP_ATOMIC512
);
668 DefInt(SQLITE_IOCAP_ATOMIC1K
);
669 DefInt(SQLITE_IOCAP_ATOMIC2K
);
670 DefInt(SQLITE_IOCAP_ATOMIC4K
);
671 DefInt(SQLITE_IOCAP_ATOMIC8K
);
672 DefInt(SQLITE_IOCAP_ATOMIC16K
);
673 DefInt(SQLITE_IOCAP_ATOMIC32K
);
674 DefInt(SQLITE_IOCAP_ATOMIC64K
);
675 DefInt(SQLITE_IOCAP_SAFE_APPEND
);
676 DefInt(SQLITE_IOCAP_SEQUENTIAL
);
677 DefInt(SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
);
678 DefInt(SQLITE_IOCAP_POWERSAFE_OVERWRITE
);
679 DefInt(SQLITE_IOCAP_IMMUTABLE
);
680 DefInt(SQLITE_IOCAP_BATCH_ATOMIC
);
684 DefInt(SQLITE_MAX_ALLOCATION_SIZE
);
685 DefInt(SQLITE_LIMIT_LENGTH
);
686 DefInt(SQLITE_MAX_LENGTH
);
687 DefInt(SQLITE_LIMIT_SQL_LENGTH
);
688 DefInt(SQLITE_MAX_SQL_LENGTH
);
689 DefInt(SQLITE_LIMIT_COLUMN
);
690 DefInt(SQLITE_MAX_COLUMN
);
691 DefInt(SQLITE_LIMIT_EXPR_DEPTH
);
692 DefInt(SQLITE_MAX_EXPR_DEPTH
);
693 DefInt(SQLITE_LIMIT_COMPOUND_SELECT
);
694 DefInt(SQLITE_MAX_COMPOUND_SELECT
);
695 DefInt(SQLITE_LIMIT_VDBE_OP
);
696 DefInt(SQLITE_MAX_VDBE_OP
);
697 DefInt(SQLITE_LIMIT_FUNCTION_ARG
);
698 DefInt(SQLITE_MAX_FUNCTION_ARG
);
699 DefInt(SQLITE_LIMIT_ATTACHED
);
700 DefInt(SQLITE_MAX_ATTACHED
);
701 DefInt(SQLITE_LIMIT_LIKE_PATTERN_LENGTH
);
702 DefInt(SQLITE_MAX_LIKE_PATTERN_LENGTH
);
703 DefInt(SQLITE_LIMIT_VARIABLE_NUMBER
);
704 DefInt(SQLITE_MAX_VARIABLE_NUMBER
);
705 DefInt(SQLITE_LIMIT_TRIGGER_DEPTH
);
706 DefInt(SQLITE_MAX_TRIGGER_DEPTH
);
707 DefInt(SQLITE_LIMIT_WORKER_THREADS
);
708 DefInt(SQLITE_MAX_WORKER_THREADS
);
711 DefGroup(openFlags
) {
712 /* Noting that not all of these will have any effect in
714 DefInt(SQLITE_OPEN_READONLY
);
715 DefInt(SQLITE_OPEN_READWRITE
);
716 DefInt(SQLITE_OPEN_CREATE
);
717 DefInt(SQLITE_OPEN_URI
);
718 DefInt(SQLITE_OPEN_MEMORY
);
719 DefInt(SQLITE_OPEN_NOMUTEX
);
720 DefInt(SQLITE_OPEN_FULLMUTEX
);
721 DefInt(SQLITE_OPEN_SHAREDCACHE
);
722 DefInt(SQLITE_OPEN_PRIVATECACHE
);
723 DefInt(SQLITE_OPEN_EXRESCODE
);
724 DefInt(SQLITE_OPEN_NOFOLLOW
);
725 /* OPEN flags for use with VFSes... */
726 DefInt(SQLITE_OPEN_MAIN_DB
);
727 DefInt(SQLITE_OPEN_MAIN_JOURNAL
);
728 DefInt(SQLITE_OPEN_TEMP_DB
);
729 DefInt(SQLITE_OPEN_TEMP_JOURNAL
);
730 DefInt(SQLITE_OPEN_TRANSIENT_DB
);
731 DefInt(SQLITE_OPEN_SUBJOURNAL
);
732 DefInt(SQLITE_OPEN_SUPER_JOURNAL
);
733 DefInt(SQLITE_OPEN_WAL
);
734 DefInt(SQLITE_OPEN_DELETEONCLOSE
);
735 DefInt(SQLITE_OPEN_EXCLUSIVE
);
738 DefGroup(prepareFlags
) {
739 DefInt(SQLITE_PREPARE_PERSISTENT
);
740 DefInt(SQLITE_PREPARE_NORMALIZE
);
741 DefInt(SQLITE_PREPARE_NO_VTAB
);
744 DefGroup(resultCodes
) {
746 DefInt(SQLITE_ERROR
);
747 DefInt(SQLITE_INTERNAL
);
749 DefInt(SQLITE_ABORT
);
751 DefInt(SQLITE_LOCKED
);
752 DefInt(SQLITE_NOMEM
);
753 DefInt(SQLITE_READONLY
);
754 DefInt(SQLITE_INTERRUPT
);
755 DefInt(SQLITE_IOERR
);
756 DefInt(SQLITE_CORRUPT
);
757 DefInt(SQLITE_NOTFOUND
);
759 DefInt(SQLITE_CANTOPEN
);
760 DefInt(SQLITE_PROTOCOL
);
761 DefInt(SQLITE_EMPTY
);
762 DefInt(SQLITE_SCHEMA
);
763 DefInt(SQLITE_TOOBIG
);
764 DefInt(SQLITE_CONSTRAINT
);
765 DefInt(SQLITE_MISMATCH
);
766 DefInt(SQLITE_MISUSE
);
767 DefInt(SQLITE_NOLFS
);
769 DefInt(SQLITE_FORMAT
);
770 DefInt(SQLITE_RANGE
);
771 DefInt(SQLITE_NOTADB
);
772 DefInt(SQLITE_NOTICE
);
773 DefInt(SQLITE_WARNING
);
776 // Extended Result Codes
777 DefInt(SQLITE_ERROR_MISSING_COLLSEQ
);
778 DefInt(SQLITE_ERROR_RETRY
);
779 DefInt(SQLITE_ERROR_SNAPSHOT
);
780 DefInt(SQLITE_IOERR_READ
);
781 DefInt(SQLITE_IOERR_SHORT_READ
);
782 DefInt(SQLITE_IOERR_WRITE
);
783 DefInt(SQLITE_IOERR_FSYNC
);
784 DefInt(SQLITE_IOERR_DIR_FSYNC
);
785 DefInt(SQLITE_IOERR_TRUNCATE
);
786 DefInt(SQLITE_IOERR_FSTAT
);
787 DefInt(SQLITE_IOERR_UNLOCK
);
788 DefInt(SQLITE_IOERR_RDLOCK
);
789 DefInt(SQLITE_IOERR_DELETE
);
790 DefInt(SQLITE_IOERR_BLOCKED
);
791 DefInt(SQLITE_IOERR_NOMEM
);
792 DefInt(SQLITE_IOERR_ACCESS
);
793 DefInt(SQLITE_IOERR_CHECKRESERVEDLOCK
);
794 DefInt(SQLITE_IOERR_LOCK
);
795 DefInt(SQLITE_IOERR_CLOSE
);
796 DefInt(SQLITE_IOERR_DIR_CLOSE
);
797 DefInt(SQLITE_IOERR_SHMOPEN
);
798 DefInt(SQLITE_IOERR_SHMSIZE
);
799 DefInt(SQLITE_IOERR_SHMLOCK
);
800 DefInt(SQLITE_IOERR_SHMMAP
);
801 DefInt(SQLITE_IOERR_SEEK
);
802 DefInt(SQLITE_IOERR_DELETE_NOENT
);
803 DefInt(SQLITE_IOERR_MMAP
);
804 DefInt(SQLITE_IOERR_GETTEMPPATH
);
805 DefInt(SQLITE_IOERR_CONVPATH
);
806 DefInt(SQLITE_IOERR_VNODE
);
807 DefInt(SQLITE_IOERR_AUTH
);
808 DefInt(SQLITE_IOERR_BEGIN_ATOMIC
);
809 DefInt(SQLITE_IOERR_COMMIT_ATOMIC
);
810 DefInt(SQLITE_IOERR_ROLLBACK_ATOMIC
);
811 DefInt(SQLITE_IOERR_DATA
);
812 DefInt(SQLITE_IOERR_CORRUPTFS
);
813 DefInt(SQLITE_LOCKED_SHAREDCACHE
);
814 DefInt(SQLITE_LOCKED_VTAB
);
815 DefInt(SQLITE_BUSY_RECOVERY
);
816 DefInt(SQLITE_BUSY_SNAPSHOT
);
817 DefInt(SQLITE_BUSY_TIMEOUT
);
818 DefInt(SQLITE_CANTOPEN_NOTEMPDIR
);
819 DefInt(SQLITE_CANTOPEN_ISDIR
);
820 DefInt(SQLITE_CANTOPEN_FULLPATH
);
821 DefInt(SQLITE_CANTOPEN_CONVPATH
);
822 //DefInt(SQLITE_CANTOPEN_DIRTYWAL)/*docs say not used*/;
823 DefInt(SQLITE_CANTOPEN_SYMLINK
);
824 DefInt(SQLITE_CORRUPT_VTAB
);
825 DefInt(SQLITE_CORRUPT_SEQUENCE
);
826 DefInt(SQLITE_CORRUPT_INDEX
);
827 DefInt(SQLITE_READONLY_RECOVERY
);
828 DefInt(SQLITE_READONLY_CANTLOCK
);
829 DefInt(SQLITE_READONLY_ROLLBACK
);
830 DefInt(SQLITE_READONLY_DBMOVED
);
831 DefInt(SQLITE_READONLY_CANTINIT
);
832 DefInt(SQLITE_READONLY_DIRECTORY
);
833 DefInt(SQLITE_ABORT_ROLLBACK
);
834 DefInt(SQLITE_CONSTRAINT_CHECK
);
835 DefInt(SQLITE_CONSTRAINT_COMMITHOOK
);
836 DefInt(SQLITE_CONSTRAINT_FOREIGNKEY
);
837 DefInt(SQLITE_CONSTRAINT_FUNCTION
);
838 DefInt(SQLITE_CONSTRAINT_NOTNULL
);
839 DefInt(SQLITE_CONSTRAINT_PRIMARYKEY
);
840 DefInt(SQLITE_CONSTRAINT_TRIGGER
);
841 DefInt(SQLITE_CONSTRAINT_UNIQUE
);
842 DefInt(SQLITE_CONSTRAINT_VTAB
);
843 DefInt(SQLITE_CONSTRAINT_ROWID
);
844 DefInt(SQLITE_CONSTRAINT_PINNED
);
845 DefInt(SQLITE_CONSTRAINT_DATATYPE
);
846 DefInt(SQLITE_NOTICE_RECOVER_WAL
);
847 DefInt(SQLITE_NOTICE_RECOVER_ROLLBACK
);
848 DefInt(SQLITE_WARNING_AUTOINDEX
);
849 DefInt(SQLITE_AUTH_USER
);
850 DefInt(SQLITE_OK_LOAD_PERMANENTLY
);
851 //DefInt(SQLITE_OK_SYMLINK) /* internal use only */;
855 DefInt(SQLITE_SERIALIZE_NOCOPY
);
856 DefInt(SQLITE_DESERIALIZE_FREEONCLOSE
);
857 DefInt(SQLITE_DESERIALIZE_READONLY
);
858 DefInt(SQLITE_DESERIALIZE_RESIZEABLE
);
862 DefInt(SQLITE_SESSION_CONFIG_STRMSIZE
);
863 DefInt(SQLITE_SESSION_OBJCONFIG_SIZE
);
866 DefGroup(sqlite3Status
){
867 DefInt(SQLITE_STATUS_MEMORY_USED
);
868 DefInt(SQLITE_STATUS_PAGECACHE_USED
);
869 DefInt(SQLITE_STATUS_PAGECACHE_OVERFLOW
);
870 //DefInt(SQLITE_STATUS_SCRATCH_USED) /* NOT USED */;
871 //DefInt(SQLITE_STATUS_SCRATCH_OVERFLOW) /* NOT USED */;
872 DefInt(SQLITE_STATUS_MALLOC_SIZE
);
873 DefInt(SQLITE_STATUS_PARSER_STACK
);
874 DefInt(SQLITE_STATUS_PAGECACHE_SIZE
);
875 //DefInt(SQLITE_STATUS_SCRATCH_SIZE) /* NOT USED */;
876 DefInt(SQLITE_STATUS_MALLOC_COUNT
);
879 DefGroup(stmtStatus
){
880 DefInt(SQLITE_STMTSTATUS_FULLSCAN_STEP
);
881 DefInt(SQLITE_STMTSTATUS_SORT
);
882 DefInt(SQLITE_STMTSTATUS_AUTOINDEX
);
883 DefInt(SQLITE_STMTSTATUS_VM_STEP
);
884 DefInt(SQLITE_STMTSTATUS_REPREPARE
);
885 DefInt(SQLITE_STMTSTATUS_RUN
);
886 DefInt(SQLITE_STMTSTATUS_FILTER_MISS
);
887 DefInt(SQLITE_STMTSTATUS_FILTER_HIT
);
888 DefInt(SQLITE_STMTSTATUS_MEMUSED
);
891 DefGroup(syncFlags
) {
892 DefInt(SQLITE_SYNC_NORMAL
);
893 DefInt(SQLITE_SYNC_FULL
);
894 DefInt(SQLITE_SYNC_DATAONLY
);
898 DefInt(SQLITE_TRACE_STMT
);
899 DefInt(SQLITE_TRACE_PROFILE
);
900 DefInt(SQLITE_TRACE_ROW
);
901 DefInt(SQLITE_TRACE_CLOSE
);
905 DefInt(SQLITE_TXN_NONE
);
906 DefInt(SQLITE_TXN_READ
);
907 DefInt(SQLITE_TXN_WRITE
);
911 DefInt(SQLITE_DETERMINISTIC
);
912 DefInt(SQLITE_DIRECTONLY
);
913 DefInt(SQLITE_INNOCUOUS
);
914 DefInt(SQLITE_SUBTYPE
);
915 DefInt(SQLITE_RESULT_SUBTYPE
);
919 DefInt(SQLITE_VERSION_NUMBER
);
920 DefStr(SQLITE_VERSION
);
921 DefStr(SQLITE_SOURCE_ID
);
925 DefInt(SQLITE_INDEX_SCAN_UNIQUE
);
926 DefInt(SQLITE_INDEX_CONSTRAINT_EQ
);
927 DefInt(SQLITE_INDEX_CONSTRAINT_GT
);
928 DefInt(SQLITE_INDEX_CONSTRAINT_LE
);
929 DefInt(SQLITE_INDEX_CONSTRAINT_LT
);
930 DefInt(SQLITE_INDEX_CONSTRAINT_GE
);
931 DefInt(SQLITE_INDEX_CONSTRAINT_MATCH
);
932 DefInt(SQLITE_INDEX_CONSTRAINT_LIKE
);
933 DefInt(SQLITE_INDEX_CONSTRAINT_GLOB
);
934 DefInt(SQLITE_INDEX_CONSTRAINT_REGEXP
);
935 DefInt(SQLITE_INDEX_CONSTRAINT_NE
);
936 DefInt(SQLITE_INDEX_CONSTRAINT_ISNOT
);
937 DefInt(SQLITE_INDEX_CONSTRAINT_ISNOTNULL
);
938 DefInt(SQLITE_INDEX_CONSTRAINT_ISNULL
);
939 DefInt(SQLITE_INDEX_CONSTRAINT_IS
);
940 DefInt(SQLITE_INDEX_CONSTRAINT_LIMIT
);
941 DefInt(SQLITE_INDEX_CONSTRAINT_OFFSET
);
942 DefInt(SQLITE_INDEX_CONSTRAINT_FUNCTION
);
943 DefInt(SQLITE_VTAB_CONSTRAINT_SUPPORT
);
944 DefInt(SQLITE_VTAB_INNOCUOUS
);
945 DefInt(SQLITE_VTAB_DIRECTONLY
);
946 DefInt(SQLITE_VTAB_USES_ALL_SCHEMAS
);
947 DefInt(SQLITE_ROLLBACK
);
948 //DefInt(SQLITE_IGNORE); // Also used by sqlite3_authorizer() callback
950 //DefInt(SQLITE_ABORT); // Also an error code
951 DefInt(SQLITE_REPLACE
);
960 ** Emit an array of "StructBinder" struct descripions, which look
964 ** "name": "MyStruct",
967 ** "member1": {"offset": 0,"sizeof": 4,"signature": "i"},
968 ** "member2": {"offset": 4,"sizeof": 4,"signature": "p"},
969 ** "member3": {"offset": 8,"sizeof": 8,"signature": "j"}
973 ** Detailed documentation for those bits are in the docs for the
974 ** Jaccwabyt JS-side component.
977 /** Macros for emitting StructBinder description. */
978 #define StructBinder__(TYPE) \
980 outf("%s{", (nStruct++ ? ", " : "")); \
981 out("\"name\": \"" # TYPE "\","); \
982 outf("\"sizeof\": %d", (int)sizeof(TYPE)); \
983 out(",\"members\": {");
984 #define StructBinder_(T) StructBinder__(T)
985 /** ^^^ indirection needed to expand CurrentStruct */
986 #define StructBinder StructBinder_(CurrentStruct)
987 #define _StructBinder CloseBrace(2)
988 #define M(MEMBER,SIG) \
990 "{\"offset\":%d,\"sizeof\": %d,\"signature\":\"%s\"}", \
991 (n++ ? ", " : ""), #MEMBER, \
992 (int)offsetof(CurrentStruct,MEMBER), \
993 (int)sizeof(((CurrentStruct*)0)->MEMBER), \
997 out(", \"structs\": ["); {
999 #define CurrentStruct sqlite3_vfs
1007 M(xOpen
, "i(pppip)");
1008 M(xDelete
, "i(ppi)");
1009 M(xAccess
, "i(ppip)");
1010 M(xFullPathname
, "i(ppip)");
1011 M(xDlOpen
, "p(pp)");
1012 M(xDlError
, "p(pip)");
1014 M(xDlClose
, "v(pp)");
1015 M(xRandomness
, "i(pip)");
1017 M(xCurrentTime
, "i(pp)");
1018 M(xGetLastError
, "i(pip)");
1019 M(xCurrentTimeInt64
, "i(pp)");
1020 M(xSetSystemCall
, "i(ppp)");
1021 M(xGetSystemCall
, "p(pp)");
1022 M(xNextSystemCall
, "p(pp)");
1024 #undef CurrentStruct
1026 #define CurrentStruct sqlite3_io_methods
1030 M(xRead
, "i(ppij)");
1031 M(xWrite
, "i(ppij)");
1032 M(xTruncate
, "i(pj)");
1034 M(xFileSize
, "i(pp)");
1036 M(xUnlock
, "i(pi)");
1037 M(xCheckReservedLock
, "i(pp)");
1038 M(xFileControl
, "i(pip)");
1039 M(xSectorSize
, "i(p)");
1040 M(xDeviceCharacteristics
, "i(p)");
1041 M(xShmMap
, "i(piiip)");
1042 M(xShmLock
, "i(piii)");
1043 M(xShmBarrier
, "v(p)");
1044 M(xShmUnmap
, "i(pi)");
1045 M(xFetch
, "i(pjip)");
1046 M(xUnfetch
, "i(pjp)");
1048 #undef CurrentStruct
1050 #define CurrentStruct sqlite3_file
1054 #undef CurrentStruct
1056 #define CurrentStruct sqlite3_kvvfs_methods
1058 M(xRead
, "i(sspi)");
1059 M(xWrite
, "i(sss)");
1060 M(xDelete
, "i(ss)");
1063 #undef CurrentStruct
1066 #define CurrentStruct sqlite3_vtab
1072 #undef CurrentStruct
1074 #define CurrentStruct sqlite3_vtab_cursor
1078 #undef CurrentStruct
1080 #define CurrentStruct sqlite3_module
1083 M(xCreate
, "i(ppippp)");
1084 M(xConnect
, "i(ppippp)");
1085 M(xBestIndex
, "i(pp)");
1086 M(xDisconnect
, "i(p)");
1087 M(xDestroy
, "i(p)");
1090 M(xFilter
, "i(pisip)");
1093 M(xColumn
, "i(ppi)");
1095 M(xUpdate
, "i(pipp)");
1099 M(xRollback
, "i(p)");
1100 M(xFindFunction
, "i(pispp)");
1101 M(xRename
, "i(ps)");
1102 // ^^^ v1. v2+ follows...
1103 M(xSavepoint
, "i(pi)");
1104 M(xRelease
, "i(pi)");
1105 M(xRollbackTo
, "i(pi)");
1106 // ^^^ v2. v3+ follows...
1107 M(xShadowName
, "i(s)");
1109 #undef CurrentStruct
1112 ** Workaround: in order to map the various inner structs from
1113 ** sqlite3_index_info, we have to uplift those into constructs we
1114 ** can access by type name. These structs _must_ match their
1115 ** in-sqlite3_index_info counterparts byte for byte.
1120 unsigned char usable
;
1122 } sqlite3_index_constraint
;
1126 } sqlite3_index_orderby
;
1130 } sqlite3_index_constraint_usage
;
1131 { /* Validate that the above struct sizeof()s match
1132 ** expectations. We could improve upon this by
1133 ** checking the offsetof() for each member. */
1134 const sqlite3_index_info siiCheck
;
1135 #define IndexSzCheck(T,M) \
1136 (sizeof(T) == sizeof(*siiCheck.M))
1137 if(!IndexSzCheck(sqlite3_index_constraint
,aConstraint
)
1138 || !IndexSzCheck(sqlite3_index_orderby
,aOrderBy
)
1139 || !IndexSzCheck(sqlite3_index_constraint_usage
,aConstraintUsage
)){
1140 assert(!"sizeof mismatch in sqlite3_index_... struct(s)");
1146 #define CurrentStruct sqlite3_index_constraint
1151 M(iTermOffset
, "i");
1153 #undef CurrentStruct
1155 #define CurrentStruct sqlite3_index_orderby
1160 #undef CurrentStruct
1162 #define CurrentStruct sqlite3_index_constraint_usage
1167 #undef CurrentStruct
1169 #define CurrentStruct sqlite3_index_info
1171 M(nConstraint
, "i");
1172 M(aConstraint
, "p");
1175 M(aConstraintUsage
, "p");
1178 M(needToFreeIdxStr
, "i");
1179 M(orderByConsumed
, "i");
1180 M(estimatedCost
, "d");
1181 M(estimatedRows
, "j");
1185 #undef CurrentStruct
1187 #if SQLITE_WASM_TESTS
1188 #define CurrentStruct WasmTestStruct
1196 #undef CurrentStruct
1199 } out( "]"/*structs*/);
1201 out("}"/*top-level object*/);
1203 aBuffer
[0] = '{'/*end of the race-condition workaround*/;
1206 #undef StructBinder_
1207 #undef StructBinder__
1209 #undef _StructBinder
1217 ** This function is NOT part of the sqlite3 public API. It is strictly
1218 ** for use by the sqlite project's own JS/WASM bindings.
1220 ** This function invokes the xDelete method of the given VFS (or the
1221 ** default VFS if pVfs is NULL), passing on the given filename. If
1222 ** zName is NULL, no default VFS is found, or it has no xDelete
1223 ** method, SQLITE_MISUSE is returned, else the result of the xDelete()
1224 ** call is returned.
1227 int sqlite3__wasm_vfs_unlink(sqlite3_vfs
*pVfs
, const char *zName
){
1228 int rc
= SQLITE_MISUSE
/* ??? */;
1229 if( 0==pVfs
&& 0!=zName
) pVfs
= sqlite3_vfs_find(0);
1230 if( zName
&& pVfs
&& pVfs
->xDelete
){
1231 rc
= pVfs
->xDelete(pVfs
, zName
, 1);
1237 ** This function is NOT part of the sqlite3 public API. It is strictly
1238 ** for use by the sqlite project's own JS/WASM bindings.
1240 ** Returns a pointer to the given DB's VFS for the given DB name,
1241 ** defaulting to "main" if zDbName is 0. Returns 0 if no db with the
1242 ** given name is open.
1245 sqlite3_vfs
* sqlite3__wasm_db_vfs(sqlite3
*pDb
, const char *zDbName
){
1246 sqlite3_vfs
* pVfs
= 0;
1247 sqlite3_file_control(pDb
, zDbName
? zDbName
: "main",
1248 SQLITE_FCNTL_VFS_POINTER
, &pVfs
);
1253 ** This function is NOT part of the sqlite3 public API. It is strictly
1254 ** for use by the sqlite project's own JS/WASM bindings.
1256 ** This function resets the given db pointer's database as described at
1258 ** https://sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigresetdatabase
1260 ** But beware: virtual tables destroyed that way do not have their
1261 ** xDestroy() called, so will leak if they require that function for
1264 ** Returns 0 on success, an SQLITE_xxx code on error. Returns
1265 ** SQLITE_MISUSE if pDb is NULL.
1268 int sqlite3__wasm_db_reset(sqlite3
*pDb
){
1269 int rc
= SQLITE_MISUSE
;
1271 sqlite3_table_column_metadata(pDb
, "main", 0, 0, 0, 0, 0, 0, 0);
1272 rc
= sqlite3_db_config(pDb
, SQLITE_DBCONFIG_RESET_DATABASE
, 1, 0);
1274 rc
= sqlite3_exec(pDb
, "VACUUM", 0, 0, 0);
1275 sqlite3_db_config(pDb
, SQLITE_DBCONFIG_RESET_DATABASE
, 0, 0);
1282 ** This function is NOT part of the sqlite3 public API. It is strictly
1283 ** for use by the sqlite project's own JS/WASM bindings.
1285 ** Uses the given database's VFS xRead to stream the db file's
1286 ** contents out to the given callback. The callback gets a single
1287 ** chunk of size n (its 2nd argument) on each call and must return 0
1288 ** on success, non-0 on error. This function returns 0 on success,
1289 ** SQLITE_NOTFOUND if no db is open, or propagates any other non-0
1290 ** code from the callback. Note that this is not thread-friendly: it
1291 ** expects that it will be the only thread reading the db file and
1292 ** takes no measures to ensure that is the case.
1294 ** This implementation appears to work fine, but
1295 ** sqlite3__wasm_db_serialize() is arguably the better way to achieve
1299 int sqlite3__wasm_db_export_chunked( sqlite3
* pDb
,
1300 int (*xCallback
)(unsigned const char *zOut
, int n
) ){
1301 sqlite3_int64 nSize
= 0;
1302 sqlite3_int64 nPos
= 0;
1303 sqlite3_file
* pFile
= 0;
1304 unsigned char buf
[1024 * 8];
1305 int nBuf
= (int)sizeof(buf
);
1307 ? sqlite3_file_control(pDb
, "main",
1308 SQLITE_FCNTL_FILE_POINTER
, &pFile
)
1311 rc
= pFile
->pMethods
->xFileSize(pFile
, &nSize
);
1314 /* DB size is not an even multiple of the buffer size. Reduce
1315 ** buffer size so that we do not unduly inflate the db size
1316 ** with zero-padding when exporting. */
1317 if(0 == nSize
% 4096) nBuf
= 4096;
1318 else if(0 == nSize
% 2048) nBuf
= 2048;
1319 else if(0 == nSize
% 1024) nBuf
= 1024;
1322 for( ; 0==rc
&& nPos
<nSize
; nPos
+= nBuf
){
1323 rc
= pFile
->pMethods
->xRead(pFile
, buf
, nBuf
, nPos
);
1324 if( SQLITE_IOERR_SHORT_READ
== rc
){
1325 rc
= (nPos
+ nBuf
) < nSize
? rc
: 0/*assume EOF*/;
1327 if( 0==rc
) rc
= xCallback(buf
, nBuf
);
1333 ** This function is NOT part of the sqlite3 public API. It is strictly
1334 ** for use by the sqlite project's own JS/WASM bindings.
1336 ** A proxy for sqlite3_serialize() which serializes the schema zSchema
1337 ** of pDb, placing the serialized output in pOut and nOut. nOut may be
1338 ** NULL. If zSchema is NULL then "main" is assumed. If pDb or pOut are
1339 ** NULL then SQLITE_MISUSE is returned. If allocation of the
1340 ** serialized copy fails, SQLITE_NOMEM is returned. On success, 0 is
1341 ** returned and `*pOut` will contain a pointer to the memory unless
1342 ** mFlags includes SQLITE_SERIALIZE_NOCOPY and the database has no
1343 ** contiguous memory representation, in which case `*pOut` will be
1344 ** NULL but 0 will be returned.
1346 ** If `*pOut` is not NULL, the caller is responsible for passing it to
1347 ** sqlite3_free() to free it.
1350 int sqlite3__wasm_db_serialize( sqlite3
*pDb
, const char *zSchema
,
1351 unsigned char **pOut
,
1352 sqlite3_int64
*nOut
, unsigned int mFlags
){
1354 if( !pDb
|| !pOut
) return SQLITE_MISUSE
;
1355 if( nOut
) *nOut
= 0;
1356 z
= sqlite3_serialize(pDb
, zSchema
? zSchema
: "main", nOut
, mFlags
);
1357 if( z
|| (SQLITE_SERIALIZE_NOCOPY
& mFlags
) ){
1361 return SQLITE_NOMEM
;
1366 ** This function is NOT part of the sqlite3 public API. It is strictly
1367 ** for use by the sqlite project's own JS/WASM bindings.
1369 ** ACHTUNG: it was discovered on 2023-08-11 that, with SQLITE_DEBUG,
1370 ** this function's out-of-scope use of the sqlite3_vfs/file/io_methods
1371 ** APIs leads to triggering of assertions in the core library. Its use
1372 ** is now deprecated and VFS-specific APIs for importing files need to
1373 ** be found to replace it. sqlite3__wasm_posix_create_file() is
1374 ** suitable for the "unix" family of VFSes.
1376 ** Creates a new file using the I/O API of the given VFS, containing
1377 ** the given number of bytes of the given data. If the file exists, it
1378 ** is truncated to the given length and populated with the given
1381 ** This function exists so that we can implement the equivalent of
1382 ** Emscripten's FS.createDataFile() in a VFS-agnostic way. This
1383 ** functionality is intended for use in uploading database files.
1385 ** Not all VFSes support this functionality, e.g. the "kvvfs" does
1388 ** If pVfs is NULL, sqlite3_vfs_find(0) is used.
1390 ** If zFile is NULL, pVfs is NULL (and sqlite3_vfs_find(0) returns
1391 ** NULL), or nData is negative, SQLITE_MISUSE are returned.
1393 ** On success, it creates a new file with the given name, populated
1394 ** with the fist nData bytes of pData. If pData is NULL, the file is
1395 ** created and/or truncated to nData bytes.
1397 ** Whether or not directory components of zFilename are created
1398 ** automatically or not is unspecified: that detail is left to the
1399 ** VFS. The "opfs" VFS, for example, creates them.
1401 ** If an error happens while populating or truncating the file, the
1402 ** target file will be deleted (if needed) if this function created
1403 ** it. If this function did not create it, it is not deleted but may
1404 ** be left in an undefined state.
1406 ** Returns 0 on success. On error, it returns a code described above
1407 ** or propagates a code from one of the I/O methods.
1409 ** Design note: nData is an integer, instead of int64, for WASM
1410 ** portability, so that the API can still work in builds where BigInt
1411 ** support is disabled or unavailable.
1414 int sqlite3__wasm_vfs_create_file( sqlite3_vfs
*pVfs
,
1415 const char *zFilename
,
1416 const unsigned char * pData
,
1419 sqlite3_file
*pFile
= 0;
1420 sqlite3_io_methods
const *pIo
;
1421 const int openFlags
= SQLITE_OPEN_READWRITE
| SQLITE_OPEN_CREATE
1422 #if 0 && defined(SQLITE_DEBUG)
1423 | SQLITE_OPEN_MAIN_JOURNAL
1424 /* ^^^^ This is for testing a horrible workaround to avoid
1425 triggering a specific assert() in os_unix.c:unixOpen(). Please
1426 do not enable this in real builds. */
1430 int fileExisted
= 0;
1432 const unsigned char *pPos
= pData
;
1433 const int blockSize
= 512
1434 /* Because we are using pFile->pMethods->xWrite() for writing, and
1435 ** it may have a buffer limit related to sqlite3's pager size, we
1436 ** conservatively write in 512-byte blocks (smallest page
1438 //fprintf(stderr, "pVfs=%p, zFilename=%s, nData=%d\n", pVfs, zFilename, nData);
1439 if( !pVfs
) pVfs
= sqlite3_vfs_find(0);
1440 if( !pVfs
|| !zFilename
|| nData
<0 ) return SQLITE_MISUSE
;
1441 pVfs
->xAccess(pVfs
, zFilename
, SQLITE_ACCESS_EXISTS
, &fileExisted
);
1442 rc
= sqlite3OsOpenMalloc(pVfs
, zFilename
, &pFile
, openFlags
, &flagsOut
);
1444 # define RC fprintf(stderr,"create_file(%s,%s) @%d rc=%d\n", \
1445 pVfs->zName, zFilename, __LINE__, rc);
1451 pIo
= pFile
->pMethods
;
1453 /* We need xLock() in order to accommodate the OPFS VFS, as it
1454 ** obtains a writeable handle via the lock operation and releases
1455 ** it in xUnlock(). If we don't do those here, we have to add code
1456 ** to the VFS to account check whether it was locked before
1457 ** xFileSize(), xTruncate(), and the like, and release the lock
1458 ** only if it was unlocked when the op was started. */
1459 rc
= pIo
->xLock(pFile
, SQLITE_LOCK_EXCLUSIVE
);
1464 rc
= pIo
->xTruncate(pFile
, nData
);
1467 if( 0==rc
&& 0!=pData
&& nData
>0 ){
1468 while( 0==rc
&& nData
>0 ){
1469 const int n
= nData
>=blockSize
? blockSize
: nData
;
1470 rc
= pIo
->xWrite(pFile
, pPos
, n
, (sqlite3_int64
)(pPos
- pData
));
1475 if( 0==rc
&& nData
>0 ){
1476 assert( nData
<blockSize
);
1477 rc
= pIo
->xWrite(pFile
, pPos
, nData
,
1478 (sqlite3_int64
)(pPos
- pData
));
1482 if( pIo
->xUnlock
&& doUnlock
!=0 ){
1483 pIo
->xUnlock(pFile
, SQLITE_LOCK_NONE
);
1486 if( rc
!=0 && 0==fileExisted
){
1487 pVfs
->xDelete(pVfs
, zFilename
, 1);
1495 ** This function is NOT part of the sqlite3 public API. It is strictly
1496 ** for use by the sqlite project's own JS/WASM bindings.
1498 ** Creates or overwrites a file using the POSIX file API,
1499 ** i.e. Emscripten's virtual filesystem. Creates or truncates
1500 ** zFilename, appends pData bytes to it, and returns 0 on success or
1501 ** SQLITE_IOERR on error.
1504 int sqlite3__wasm_posix_create_file( const char *zFilename
,
1505 const unsigned char * pData
,
1509 int fileExisted
= 0;
1512 if( !zFilename
|| nData
<0 || (pData
==0 && nData
>0) ) return SQLITE_MISUSE
;
1513 pFile
= fopen(zFilename
, "w");
1514 if( 0==pFile
) return SQLITE_IOERR
;
1516 nWrote
= fwrite(pData
, (size_t)nData
, 1, pFile
);
1519 return 1==nWrote
? 0 : SQLITE_IOERR
;
1523 ** This function is NOT part of the sqlite3 public API. It is strictly
1524 ** for use by the sqlite project's own JS/WASM bindings.
1526 ** Allocates sqlite3KvvfsMethods.nKeySize bytes from
1527 ** sqlite3__wasm_pstack_alloc() and returns 0 if that allocation fails,
1528 ** else it passes that string to kvstorageMakeKey() and returns a
1529 ** NUL-terminated pointer to that string. It is up to the caller to
1530 ** use sqlite3__wasm_pstack_restore() to free the returned pointer.
1533 char * sqlite3__wasm_kvvfsMakeKeyOnPstack(const char *zClass
,
1534 const char *zKeyIn
){
1535 assert(sqlite3KvvfsMethods
.nKeySize
>24);
1537 (char *)sqlite3__wasm_pstack_alloc(sqlite3KvvfsMethods
.nKeySize
);
1539 kvstorageMakeKey(zClass
, zKeyIn
, zKeyOut
);
1545 ** This function is NOT part of the sqlite3 public API. It is strictly
1546 ** for use by the sqlite project's own JS/WASM bindings.
1548 ** Returns the pointer to the singleton object which holds the kvvfs
1549 ** I/O methods and associated state.
1552 sqlite3_kvvfs_methods
* sqlite3__wasm_kvvfs_methods(void){
1553 return &sqlite3KvvfsMethods
;
1557 ** This function is NOT part of the sqlite3 public API. It is strictly
1558 ** for use by the sqlite project's own JS/WASM bindings.
1560 ** This is a proxy for the variadic sqlite3_vtab_config() which passes
1561 ** its argument on, or not, to sqlite3_vtab_config(), depending on the
1562 ** value of its 2nd argument. Returns the result of
1563 ** sqlite3_vtab_config(), or SQLITE_MISUSE if the 2nd arg is not a
1567 int sqlite3__wasm_vtab_config(sqlite3
*pDb
, int op
, int arg
){
1569 case SQLITE_VTAB_DIRECTONLY
:
1570 case SQLITE_VTAB_INNOCUOUS
:
1571 return sqlite3_vtab_config(pDb
, op
);
1572 case SQLITE_VTAB_CONSTRAINT_SUPPORT
:
1573 return sqlite3_vtab_config(pDb
, op
, arg
);
1575 return SQLITE_MISUSE
;
1580 ** This function is NOT part of the sqlite3 public API. It is strictly
1581 ** for use by the sqlite project's own JS/WASM bindings.
1583 ** Wrapper for the variants of sqlite3_db_config() which take
1584 ** (int,int*) variadic args.
1587 int sqlite3__wasm_db_config_ip(sqlite3
*pDb
, int op
, int arg1
, int* pArg2
){
1589 case SQLITE_DBCONFIG_ENABLE_FKEY
:
1590 case SQLITE_DBCONFIG_ENABLE_TRIGGER
:
1591 case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
:
1592 case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
:
1593 case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
:
1594 case SQLITE_DBCONFIG_ENABLE_QPSG
:
1595 case SQLITE_DBCONFIG_TRIGGER_EQP
:
1596 case SQLITE_DBCONFIG_RESET_DATABASE
:
1597 case SQLITE_DBCONFIG_DEFENSIVE
:
1598 case SQLITE_DBCONFIG_WRITABLE_SCHEMA
:
1599 case SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
:
1600 case SQLITE_DBCONFIG_DQS_DML
:
1601 case SQLITE_DBCONFIG_DQS_DDL
:
1602 case SQLITE_DBCONFIG_ENABLE_VIEW
:
1603 case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
:
1604 case SQLITE_DBCONFIG_TRUSTED_SCHEMA
:
1605 case SQLITE_DBCONFIG_STMT_SCANSTATUS
:
1606 case SQLITE_DBCONFIG_REVERSE_SCANORDER
:
1607 return sqlite3_db_config(pDb
, op
, arg1
, pArg2
);
1608 default: return SQLITE_MISUSE
;
1613 ** This function is NOT part of the sqlite3 public API. It is strictly
1614 ** for use by the sqlite project's own JS/WASM bindings.
1616 ** Wrapper for the variants of sqlite3_db_config() which take
1617 ** (void*,int,int) variadic args.
1620 int sqlite3__wasm_db_config_pii(sqlite3
*pDb
, int op
, void * pArg1
, int arg2
, int arg3
){
1622 case SQLITE_DBCONFIG_LOOKASIDE
:
1623 return sqlite3_db_config(pDb
, op
, pArg1
, arg2
, arg3
);
1624 default: return SQLITE_MISUSE
;
1629 ** This function is NOT part of the sqlite3 public API. It is strictly
1630 ** for use by the sqlite project's own JS/WASM bindings.
1632 ** Wrapper for the variants of sqlite3_db_config() which take
1633 ** (const char *) variadic args.
1636 int sqlite3__wasm_db_config_s(sqlite3
*pDb
, int op
, const char *zArg
){
1638 case SQLITE_DBCONFIG_MAINDBNAME
:
1639 return sqlite3_db_config(pDb
, op
, zArg
);
1640 default: return SQLITE_MISUSE
;
1646 ** This function is NOT part of the sqlite3 public API. It is strictly
1647 ** for use by the sqlite project's own JS/WASM bindings.
1649 ** Binding for combinations of sqlite3_config() arguments which take
1650 ** a single integer argument.
1653 int sqlite3__wasm_config_i(int op
, int arg
){
1654 return sqlite3_config(op
, arg
);
1658 ** This function is NOT part of the sqlite3 public API. It is strictly
1659 ** for use by the sqlite project's own JS/WASM bindings.
1661 ** Binding for combinations of sqlite3_config() arguments which take
1662 ** two int arguments.
1665 int sqlite3__wasm_config_ii(int op
, int arg1
, int arg2
){
1666 return sqlite3_config(op
, arg1
, arg2
);
1670 ** This function is NOT part of the sqlite3 public API. It is strictly
1671 ** for use by the sqlite project's own JS/WASM bindings.
1673 ** Binding for combinations of sqlite3_config() arguments which take
1674 ** a single i64 argument.
1677 int sqlite3__wasm_config_j(int op
, sqlite3_int64 arg
){
1678 return sqlite3_config(op
, arg
);
1682 ** This function is NOT part of the sqlite3 public API. It is strictly
1683 ** for use by the sqlite project's own JS/WASM bindings.
1685 ** If z is not NULL, returns the result of passing z to
1686 ** sqlite3_mprintf()'s %Q modifier (if addQuotes is true) or %q (if
1687 ** addQuotes is 0). Returns NULL if z is NULL or on OOM.
1690 char * sqlite3__wasm_qfmt_token(char *z
, int addQuotes
){
1694 ? sqlite3_mprintf("%Q", z
)
1695 : sqlite3_mprintf("%q", z
);
1700 #if defined(__EMSCRIPTEN__) && defined(SQLITE_ENABLE_WASMFS)
1701 #include <emscripten/wasmfs.h>
1704 ** This function is NOT part of the sqlite3 public API. It is strictly
1705 ** for use by the sqlite project's own JS/WASM bindings, specifically
1706 ** only when building with Emscripten's WASMFS support.
1708 ** This function should only be called if the JS side detects the
1709 ** existence of the Origin-Private FileSystem (OPFS) APIs in the
1710 ** client. The first time it is called, this function instantiates a
1711 ** WASMFS backend impl for OPFS. On success, subsequent calls are
1714 ** This function may be passed a "mount point" name, which must have a
1715 ** leading "/" and is currently restricted to a single path component,
1716 ** e.g. "/foo" is legal but "/foo/" and "/foo/bar" are not. If it is
1717 ** NULL or empty, it defaults to "/opfs".
1719 ** Returns 0 on success, SQLITE_NOMEM if instantiation of the backend
1720 ** object fails, SQLITE_IOERR if mkdir() of the zMountPoint dir in
1721 ** the virtual FS fails. In builds compiled without SQLITE_ENABLE_WASMFS
1722 ** defined, SQLITE_NOTFOUND is returned without side effects.
1725 int sqlite3__wasm_init_wasmfs(const char *zMountPoint
){
1726 static backend_t pOpfs
= 0;
1727 if( !zMountPoint
|| !*zMountPoint
) zMountPoint
= "/opfs";
1729 pOpfs
= wasmfs_create_opfs_backend();
1731 /** It's not enough to instantiate the backend. We have to create a
1732 mountpoint in the VFS and attach the backend to it. */
1733 if( pOpfs
&& 0!=access(zMountPoint
, F_OK
) ){
1734 /* Note that this check and is not robust but it will
1735 hypothetically suffice for the transient wasm-based virtual
1736 filesystem we're currently running in. */
1737 const int rc
= wasmfs_create_directory(zMountPoint
, 0777, pOpfs
);
1738 /*emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);*/
1739 if(rc
) return SQLITE_IOERR
;
1741 return pOpfs
? 0 : SQLITE_NOMEM
;
1745 int sqlite3__wasm_init_wasmfs(const char *zUnused
){
1746 //emscripten_console_warn("WASMFS OPFS is not compiled in.");
1747 if(zUnused
){/*unused*/}
1748 return SQLITE_NOTFOUND
;
1750 #endif /* __EMSCRIPTEN__ && SQLITE_ENABLE_WASMFS */
1752 #if SQLITE_WASM_TESTS
1755 int sqlite3__wasm_test_intptr(int * p
){
1760 void * sqlite3__wasm_test_voidptr(void * p
){
1765 int64_t sqlite3__wasm_test_int64_max(void){
1766 return (int64_t)0x7fffffffffffffff;
1770 int64_t sqlite3__wasm_test_int64_min(void){
1771 return ~sqlite3__wasm_test_int64_max();
1775 int64_t sqlite3__wasm_test_int64_times2(int64_t x
){
1780 void sqlite3__wasm_test_int64_minmax(int64_t * min
, int64_t *max
){
1781 *max
= sqlite3__wasm_test_int64_max();
1782 *min
= sqlite3__wasm_test_int64_min();
1783 /*printf("minmax: min=%lld, max=%lld\n", *min, *max);*/
1787 int64_t sqlite3__wasm_test_int64ptr(int64_t * p
){
1788 /*printf("sqlite3__wasm_test_int64ptr( @%lld = 0x%llx )\n", (int64_t)p, *p);*/
1793 void sqlite3__wasm_test_stack_overflow(int recurse
){
1794 if(recurse
) sqlite3__wasm_test_stack_overflow(recurse
);
1797 /* For testing the 'string:dealloc' whwasmutil.xWrap() conversion. */
1799 char * sqlite3__wasm_test_str_hello(int fail
){
1800 char * s
= fail
? 0 : (char *)sqlite3_malloc(6);
1802 memcpy(s
, "hello", 5);
1809 ** For testing using SQLTester scripts.
1811 ** Return non-zero if string z matches glob pattern zGlob and zero if the
1812 ** pattern does not match.
1817 ** non-zero == match
1821 ** '*' Matches any sequence of zero or more characters.
1823 ** '?' Matches exactly one character.
1825 ** [...] Matches one character from the enclosed list of
1828 ** [^...] Matches one character not in the enclosed list.
1830 ** '#' Matches any sequence of one or more digits with an
1831 ** optional + or - sign in front, or a hexadecimal
1832 ** literal of the form 0x...
1834 static int sqlite3__wasm_SQLTester_strnotglob(const char *zGlob
, const char *z
){
1838 typedef int (*recurse_f
)(const char *,const char *);
1839 static const recurse_f recurse
= sqlite3__wasm_SQLTester_strnotglob
;
1841 while( (c
= (*(zGlob
++)))!=0 ){
1843 while( (c
=(*(zGlob
++))) == '*' || c
=='?' ){
1844 if( c
=='?' && (*(z
++))==0 ) return 0;
1849 while( *z
&& recurse(zGlob
-1,z
)==0 ){
1854 while( (c2
= (*(z
++)))!=0 ){
1857 if( c2
==0 ) return 0;
1859 if( recurse(zGlob
,z
) ) return 1;
1863 if( (*(z
++))==0 ) return 0;
1869 if( c
==0 ) return 0;
1876 if( c
==']' ) seen
= 1;
1879 while( c2
&& c2
!=']' ){
1880 if( c2
=='-' && zGlob
[0]!=']' && zGlob
[0]!=0 && prior_c
>0 ){
1882 if( c
>=prior_c
&& c
<=c2
) seen
= 1;
1892 if( c2
==0 || (seen
^ invert
)==0 ) return 0;
1895 && (z
[1]=='x' || z
[1]=='X')
1896 && sqlite3Isxdigit(z
[2])
1899 while( sqlite3Isxdigit(z
[0]) ){ z
++; }
1901 if( (z
[0]=='-' || z
[0]=='+') && sqlite3Isdigit(z
[1]) ) z
++;
1902 if( !sqlite3Isdigit(z
[0]) ) return 0;
1904 while( sqlite3Isdigit(z
[0]) ){ z
++; }
1907 if( c
!=(*(z
++)) ) return 0;
1914 int sqlite3__wasm_SQLTester_strglob(const char *zGlob
, const char *z
){
1915 return !sqlite3__wasm_SQLTester_strnotglob(zGlob
, z
);
1918 #endif /* SQLITE_WASM_TESTS */
1920 #undef SQLITE_WASM_EXPORT