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_... */
87 #ifndef SQLITE_ENABLE_BYTECODE_VTAB
88 # define SQLITE_ENABLE_BYTECODE_VTAB 1
90 #ifndef SQLITE_ENABLE_DBPAGE_VTAB
91 # define SQLITE_ENABLE_DBPAGE_VTAB 1
93 #ifndef SQLITE_ENABLE_DBSTAT_VTAB
94 # define SQLITE_ENABLE_DBSTAT_VTAB 1
96 #ifndef SQLITE_ENABLE_EXPLAIN_COMMENTS
97 # define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
99 #ifndef SQLITE_ENABLE_FTS4
100 # define SQLITE_ENABLE_FTS4 1
102 #ifndef SQLITE_ENABLE_MATH_FUNCTIONS
103 # define SQLITE_ENABLE_MATH_FUNCTIONS 1
105 #ifndef SQLITE_ENABLE_OFFSET_SQL_FUNC
106 # define SQLITE_ENABLE_OFFSET_SQL_FUNC 1
108 #ifndef SQLITE_ENABLE_PREUPDATE_HOOK
109 # define SQLITE_ENABLE_PREUPDATE_HOOK 1 /*required by session extension*/
111 #ifndef SQLITE_ENABLE_RTREE
112 # define SQLITE_ENABLE_RTREE 1
114 #ifndef SQLITE_ENABLE_SESSION
115 # define SQLITE_ENABLE_SESSION 1
117 #ifndef SQLITE_ENABLE_STMTVTAB
118 # define SQLITE_ENABLE_STMTVTAB 1
120 #ifndef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
121 # define SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
124 /**********************************************************************/
126 #ifndef SQLITE_MAX_ALLOCATION_SIZE
127 # define SQLITE_MAX_ALLOCATION_SIZE 0x1fffffff
130 /**********************************************************************/
132 #ifndef SQLITE_OMIT_DEPRECATED
133 # define SQLITE_OMIT_DEPRECATED 1
135 #ifndef SQLITE_OMIT_LOAD_EXTENSION
136 # define SQLITE_OMIT_LOAD_EXTENSION 1
138 #ifndef SQLITE_OMIT_SHARED_CACHE
139 # define SQLITE_OMIT_SHARED_CACHE 1
141 #ifndef SQLITE_OMIT_UTF16
142 # define SQLITE_OMIT_UTF16 1
144 #ifndef SQLITE_OMIT_WAL
145 # define SQLITE_OMIT_WAL 1
147 #ifndef SQLITE_OS_KV_OPTIONAL
148 # define SQLITE_OS_KV_OPTIONAL 1
151 /**********************************************************************/
153 #ifndef SQLITE_TEMP_STORE
154 # define SQLITE_TEMP_STORE 3
156 #ifndef SQLITE_THREADSAFE
157 # define SQLITE_THREADSAFE 0
160 /**********************************************************************/
162 #ifndef SQLITE_USE_URI
163 # define SQLITE_USE_URI 1
166 #ifdef SQLITE_WASM_EXTRA_INIT
167 # define SQLITE_EXTRA_INIT sqlite3_wasm_extra_init
173 ** SQLITE_WASM_EXPORT is functionally identical to EMSCRIPTEN_KEEPALIVE
174 ** but is not Emscripten-specific. It explicitly marks functions for
175 ** export into the target wasm file without requiring explicit listing
176 ** of those functions in Emscripten's -sEXPORTED_FUNCTIONS=... list
177 ** (or equivalent in other build platforms). Any function with neither
178 ** this attribute nor which is listed as an explicit export will not
179 ** be exported from the wasm file (but may still be used internally
180 ** within the wasm file).
182 ** The functions in this file (sqlite3-wasm.c) which require exporting
183 ** are marked with this flag. They may also be added to any explicit
184 ** build-time export list but need not be. All of these APIs are
185 ** intended for use only within the project's own JS/WASM code, and
186 ** not by client code, so an argument can be made for reducing their
187 ** visibility by not including them in any build-time export lists.
189 ** 2022-09-11: it's not yet _proven_ that this approach works in
190 ** non-Emscripten builds. If not, such builds will need to export
191 ** those using the --export=... wasm-ld flag (or equivalent). As of
192 ** this writing we are tied to Emscripten for various reasons
193 ** and cannot test the library with other build environments.
195 #define SQLITE_WASM_EXPORT __attribute__((used,visibility("default")))
197 //__attribute__((export_name("theExportedName"), used, visibility("default")))
200 ** Which sqlite3.c we're using needs to be configurable to enable
201 ** building against a custom copy, e.g. the SEE variant. Note that we
202 ** #include the .c file, rather than the header, so that the WASM
203 ** extensions have access to private API internals.
205 ** The caveat here is that custom variants need to account for
206 ** exporting any necessary symbols (e.g. sqlite3_activate_see()). We
207 ** cannot export them from here using SQLITE_WASM_EXPORT because that
208 ** attribute (apparently) has to be part of the function definition.
211 # define SQLITE_C sqlite3.c /* yes, .c instead of .h. */
213 #define INC__STRINGIFY_(f) #f
214 #define INC__STRINGIFY(f) INC__STRINGIFY_(f)
215 #include INC__STRINGIFY(SQLITE_C)
216 #undef INC__STRINGIFY_
217 #undef INC__STRINGIFY
220 #if defined(__EMSCRIPTEN__)
221 # include <emscripten/console.h>
226 ** An EXPERIMENT in implementing a stack-based allocator analog to
227 ** Emscripten's stackSave(), stackAlloc(), stackRestore().
228 ** Unfortunately, this cannot work together with Emscripten because
229 ** Emscripten defines its own native one and we'd stomp on each
230 ** other's memory. Other than that complication, basic tests show it
231 ** to work just fine.
233 ** Another option is to malloc() a chunk of our own and call that our
236 SQLITE_WASM_EXPORT
void * sqlite3_wasm_stack_end(void){
237 extern void __heap_base
238 /* see https://stackoverflow.com/questions/10038964 */;
241 SQLITE_WASM_EXPORT
void * sqlite3_wasm_stack_begin(void){
242 extern void __data_end
;
245 static void * pWasmStackPtr
= 0;
246 SQLITE_WASM_EXPORT
void * sqlite3_wasm_stack_ptr(void){
247 if(!pWasmStackPtr
) pWasmStackPtr
= sqlite3_wasm_stack_end();
248 return pWasmStackPtr
;
250 SQLITE_WASM_EXPORT
void sqlite3_wasm_stack_restore(void * p
){
253 SQLITE_WASM_EXPORT
void * sqlite3_wasm_stack_alloc(int n
){
255 n
= (n
+ 7) & ~7 /* align to 8-byte boundary */;
256 unsigned char * const p
= (unsigned char *)sqlite3_wasm_stack_ptr();
257 unsigned const char * const b
= (unsigned const char *)sqlite3_wasm_stack_begin();
258 if(b
+ n
>= p
|| b
+ n
< b
/*overflow*/) return 0;
259 return pWasmStackPtr
= p
- n
;
261 #endif /* stack allocator experiment */
264 ** State for the "pseudo-stack" allocator implemented in
265 ** sqlite3_wasm_pstack_xyz(). In order to avoid colliding with
266 ** Emscripten-controled stack space, it carves out a bit of stack
267 ** memory to use for that purpose. This memory ends up in the
268 ** WASM-managed memory, such that routines which manipulate the wasm
269 ** heap can also be used to manipulate this memory.
271 ** This particular allocator is intended for small allocations such as
272 ** storage for output pointers. We cannot reasonably size it large
273 ** enough for general-purpose string conversions because some of our
274 ** tests use input files (strings) of 16MB+.
276 static unsigned char PStack_mem
[512 * 8] = {0};
278 unsigned const char * const pBegin
;/* Start (inclusive) of memory */
279 unsigned const char * const pEnd
; /* One-after-the-end of memory */
280 unsigned char * pPos
; /* Current stack pointer */
283 &PStack_mem
[0] + sizeof(PStack_mem
),
284 &PStack_mem
[0] + sizeof(PStack_mem
)
287 ** Returns the current pstack position.
289 SQLITE_WASM_EXPORT
void * sqlite3_wasm_pstack_ptr(void){
293 ** Sets the pstack position poitner to p. Results are undefined if the
294 ** given value did not come from sqlite3_wasm_pstack_ptr().
296 SQLITE_WASM_EXPORT
void sqlite3_wasm_pstack_restore(unsigned char * p
){
297 assert(p
>=PStack
.pBegin
&& p
<=PStack
.pEnd
&& p
>=PStack
.pPos
);
298 assert(0==(p
& 0x7));
299 if(p
>=PStack
.pBegin
&& p
<=PStack
.pEnd
/*&& p>=PStack.pPos*/){
304 ** Allocate and zero out n bytes from the pstack. Returns a pointer to
305 ** the memory on success, 0 on error (including a negative n value). n
306 ** is always adjusted to be a multiple of 8 and returned memory is
307 ** always zeroed out before returning (because this keeps the client
308 ** JS code from having to do so, and most uses of the pstack will
309 ** call for doing so).
311 SQLITE_WASM_EXPORT
void * sqlite3_wasm_pstack_alloc(int n
){
313 //if( n & 0x7 ) n += 8 - (n & 0x7) /* align to 8-byte boundary */;
314 n
= (n
+ 7) & ~7 /* align to 8-byte boundary */;
315 if( PStack
.pBegin
+ n
> PStack
.pPos
/*not enough space left*/
316 || PStack
.pBegin
+ n
<= PStack
.pBegin
/*overflow*/ ) return 0;
317 memset((PStack
.pPos
= PStack
.pPos
- n
), 0, (unsigned int)n
);
321 ** Return the number of bytes left which can be
322 ** sqlite3_wasm_pstack_alloc()'d.
324 SQLITE_WASM_EXPORT
int sqlite3_wasm_pstack_remaining(void){
325 assert(PStack
.pPos
>= PStack
.pBegin
);
326 assert(PStack
.pPos
<= PStack
.pEnd
);
327 return (int)(PStack
.pPos
- PStack
.pBegin
);
331 ** Return the total number of bytes available in the pstack, including
332 ** any space which is currently allocated. This value is a
333 ** compile-time constant.
335 SQLITE_WASM_EXPORT
int sqlite3_wasm_pstack_quota(void){
336 return (int)(PStack
.pEnd
- PStack
.pBegin
);
340 ** This function is NOT part of the sqlite3 public API. It is strictly
341 ** for use by the sqlite project's own JS/WASM bindings.
343 ** For purposes of certain hand-crafted C/Wasm function bindings, we
344 ** need a way of reporting errors which is consistent with the rest of
345 ** the C API, as opposed to throwing JS exceptions. To that end, this
346 ** internal-use-only function is a thin proxy around
347 ** sqlite3ErrorWithMessage(). The intent is that it only be used from
348 ** Wasm bindings such as sqlite3_prepare_v2/v3(), and definitely not
354 int sqlite3_wasm_db_error(sqlite3
*db
, int err_code
, const char *zMsg
){
357 const int nMsg
= sqlite3Strlen30(zMsg
);
358 sqlite3ErrorWithMsg(db
, err_code
, "%.*s", nMsg
, zMsg
);
360 sqlite3ErrorWithMsg(db
, err_code
, NULL
);
366 #if SQLITE_WASM_TESTS
367 struct WasmTestStruct
{
372 void (*xFunc
)(void*);
374 typedef struct WasmTestStruct WasmTestStruct
;
376 void sqlite3_wasm_test_struct(WasmTestStruct
* s
){
382 if(s
->xFunc
) s
->xFunc(s
);
386 #endif /* SQLITE_WASM_TESTS */
389 ** This function is NOT part of the sqlite3 public API. It is strictly
390 ** for use by the sqlite project's own JS/WASM bindings. Unlike the
391 ** rest of the sqlite3 API, this part requires C99 for snprintf() and
394 ** Returns a string containing a JSON-format "enum" of C-level
395 ** constants and struct-related metadata intended to be imported into
396 ** the JS environment. The JSON is initialized the first time this
397 ** function is called and that result is reused for all future calls.
399 ** If this function returns NULL then it means that the internal
400 ** buffer is not large enough for the generated JSON and needs to be
401 ** increased. In debug builds that will trigger an assert().
404 const char * sqlite3_wasm_enum_json(void){
405 static char aBuffer
[1024 * 20] = {0} /* where the JSON goes */;
406 int n
= 0, nChildren
= 0, nStruct
= 0
407 /* output counters for figuring out where commas go */;
408 char * zPos
= &aBuffer
[1] /* skip first byte for now to help protect
409 ** against a small race condition */;
410 char const * const zEnd
= &aBuffer
[0] + sizeof(aBuffer
) /* one-past-the-end */;
411 if(aBuffer
[0]) return aBuffer
;
412 /* Leave aBuffer[0] at 0 until the end to help guard against a tiny
413 ** race condition. If this is called twice concurrently, they might
414 ** end up both writing to aBuffer, but they'll both write the same
415 ** thing, so that's okay. If we set byte 0 up front then the 2nd
416 ** instance might return and use the string before the 1st instance
417 ** is done filling it. */
419 /* Core output macros... */
420 #define lenCheck assert(zPos < zEnd - 128 \
421 && "sqlite3_wasm_enum_json() buffer is too small."); \
422 if( zPos >= zEnd - 128 ) return 0
423 #define outf(format,...) \
424 zPos += snprintf(zPos, ((size_t)(zEnd - zPos)), format, __VA_ARGS__); \
426 #define out(TXT) outf("%s",TXT)
427 #define CloseBrace(LEVEL) \
428 assert(LEVEL<5); memset(zPos, '}', LEVEL); zPos+=LEVEL; lenCheck
430 /* Macros for emitting maps of integer- and string-type macros to
432 #define DefGroup(KEY) n = 0; \
433 outf("%s\"" #KEY "\": {",(nChildren++ ? "," : ""));
434 #define DefInt(KEY) \
435 outf("%s\"%s\": %d", (n++ ? ", " : ""), #KEY, (int)KEY)
436 #define DefStr(KEY) \
437 outf("%s\"%s\": \"%s\"", (n++ ? ", " : ""), #KEY, KEY)
438 #define _DefGroup CloseBrace(1)
440 /* The following groups are sorted alphabetic by group name. */
442 DefInt(SQLITE_ACCESS_EXISTS
);
443 DefInt(SQLITE_ACCESS_READWRITE
);
444 DefInt(SQLITE_ACCESS_READ
)/*docs say this is unused*/;
447 DefGroup(authorizer
){
449 DefInt(SQLITE_IGNORE
);
450 DefInt(SQLITE_CREATE_INDEX
);
451 DefInt(SQLITE_CREATE_TABLE
);
452 DefInt(SQLITE_CREATE_TEMP_INDEX
);
453 DefInt(SQLITE_CREATE_TEMP_TABLE
);
454 DefInt(SQLITE_CREATE_TEMP_TRIGGER
);
455 DefInt(SQLITE_CREATE_TEMP_VIEW
);
456 DefInt(SQLITE_CREATE_TRIGGER
);
457 DefInt(SQLITE_CREATE_VIEW
);
458 DefInt(SQLITE_DELETE
);
459 DefInt(SQLITE_DROP_INDEX
);
460 DefInt(SQLITE_DROP_TABLE
);
461 DefInt(SQLITE_DROP_TEMP_INDEX
);
462 DefInt(SQLITE_DROP_TEMP_TABLE
);
463 DefInt(SQLITE_DROP_TEMP_TRIGGER
);
464 DefInt(SQLITE_DROP_TEMP_VIEW
);
465 DefInt(SQLITE_DROP_TRIGGER
);
466 DefInt(SQLITE_DROP_VIEW
);
467 DefInt(SQLITE_INSERT
);
468 DefInt(SQLITE_PRAGMA
);
470 DefInt(SQLITE_SELECT
);
471 DefInt(SQLITE_TRANSACTION
);
472 DefInt(SQLITE_UPDATE
);
473 DefInt(SQLITE_ATTACH
);
474 DefInt(SQLITE_DETACH
);
475 DefInt(SQLITE_ALTER_TABLE
);
476 DefInt(SQLITE_REINDEX
);
477 DefInt(SQLITE_ANALYZE
);
478 DefInt(SQLITE_CREATE_VTABLE
);
479 DefInt(SQLITE_DROP_VTABLE
);
480 DefInt(SQLITE_FUNCTION
);
481 DefInt(SQLITE_SAVEPOINT
);
482 //DefInt(SQLITE_COPY) /* No longer used */;
483 DefInt(SQLITE_RECURSIVE
);
486 DefGroup(blobFinalizers
) {
487 /* SQLITE_STATIC/TRANSIENT need to be handled explicitly as
488 ** integers to avoid casting-related warnings. */
489 out("\"SQLITE_STATIC\":0, \"SQLITE_TRANSIENT\":-1");
490 outf(",\"SQLITE_WASM_DEALLOC\": %lld",
491 (sqlite3_int64
)(sqlite3_free
));
495 DefInt(SQLITE_CHANGESETSTART_INVERT
);
496 DefInt(SQLITE_CHANGESETAPPLY_NOSAVEPOINT
);
497 DefInt(SQLITE_CHANGESETAPPLY_INVERT
);
498 DefInt(SQLITE_CHANGESETAPPLY_IGNORENOOP
);
500 DefInt(SQLITE_CHANGESET_DATA
);
501 DefInt(SQLITE_CHANGESET_NOTFOUND
);
502 DefInt(SQLITE_CHANGESET_CONFLICT
);
503 DefInt(SQLITE_CHANGESET_CONSTRAINT
);
504 DefInt(SQLITE_CHANGESET_FOREIGN_KEY
);
506 DefInt(SQLITE_CHANGESET_OMIT
);
507 DefInt(SQLITE_CHANGESET_REPLACE
);
508 DefInt(SQLITE_CHANGESET_ABORT
);
512 DefInt(SQLITE_CONFIG_SINGLETHREAD
);
513 DefInt(SQLITE_CONFIG_MULTITHREAD
);
514 DefInt(SQLITE_CONFIG_SERIALIZED
);
515 DefInt(SQLITE_CONFIG_MALLOC
);
516 DefInt(SQLITE_CONFIG_GETMALLOC
);
517 DefInt(SQLITE_CONFIG_SCRATCH
);
518 DefInt(SQLITE_CONFIG_PAGECACHE
);
519 DefInt(SQLITE_CONFIG_HEAP
);
520 DefInt(SQLITE_CONFIG_MEMSTATUS
);
521 DefInt(SQLITE_CONFIG_MUTEX
);
522 DefInt(SQLITE_CONFIG_GETMUTEX
);
523 /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
524 DefInt(SQLITE_CONFIG_LOOKASIDE
);
525 DefInt(SQLITE_CONFIG_PCACHE
);
526 DefInt(SQLITE_CONFIG_GETPCACHE
);
527 DefInt(SQLITE_CONFIG_LOG
);
528 DefInt(SQLITE_CONFIG_URI
);
529 DefInt(SQLITE_CONFIG_PCACHE2
);
530 DefInt(SQLITE_CONFIG_GETPCACHE2
);
531 DefInt(SQLITE_CONFIG_COVERING_INDEX_SCAN
);
532 DefInt(SQLITE_CONFIG_SQLLOG
);
533 DefInt(SQLITE_CONFIG_MMAP_SIZE
);
534 DefInt(SQLITE_CONFIG_WIN32_HEAPSIZE
);
535 DefInt(SQLITE_CONFIG_PCACHE_HDRSZ
);
536 DefInt(SQLITE_CONFIG_PMASZ
);
537 DefInt(SQLITE_CONFIG_STMTJRNL_SPILL
);
538 DefInt(SQLITE_CONFIG_SMALL_MALLOC
);
539 DefInt(SQLITE_CONFIG_SORTERREF_SIZE
);
540 DefInt(SQLITE_CONFIG_MEMDB_MAXSIZE
);
543 DefGroup(dataTypes
) {
544 DefInt(SQLITE_INTEGER
);
545 DefInt(SQLITE_FLOAT
);
552 DefInt(SQLITE_DBCONFIG_MAINDBNAME
);
553 DefInt(SQLITE_DBCONFIG_LOOKASIDE
);
554 DefInt(SQLITE_DBCONFIG_ENABLE_FKEY
);
555 DefInt(SQLITE_DBCONFIG_ENABLE_TRIGGER
);
556 DefInt(SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
);
557 DefInt(SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
);
558 DefInt(SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
);
559 DefInt(SQLITE_DBCONFIG_ENABLE_QPSG
);
560 DefInt(SQLITE_DBCONFIG_TRIGGER_EQP
);
561 DefInt(SQLITE_DBCONFIG_RESET_DATABASE
);
562 DefInt(SQLITE_DBCONFIG_DEFENSIVE
);
563 DefInt(SQLITE_DBCONFIG_WRITABLE_SCHEMA
);
564 DefInt(SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
);
565 DefInt(SQLITE_DBCONFIG_DQS_DML
);
566 DefInt(SQLITE_DBCONFIG_DQS_DDL
);
567 DefInt(SQLITE_DBCONFIG_ENABLE_VIEW
);
568 DefInt(SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
);
569 DefInt(SQLITE_DBCONFIG_TRUSTED_SCHEMA
);
570 DefInt(SQLITE_DBCONFIG_STMT_SCANSTATUS
);
571 DefInt(SQLITE_DBCONFIG_REVERSE_SCANORDER
);
572 DefInt(SQLITE_DBCONFIG_MAX
);
576 DefInt(SQLITE_DBSTATUS_LOOKASIDE_USED
);
577 DefInt(SQLITE_DBSTATUS_CACHE_USED
);
578 DefInt(SQLITE_DBSTATUS_SCHEMA_USED
);
579 DefInt(SQLITE_DBSTATUS_STMT_USED
);
580 DefInt(SQLITE_DBSTATUS_LOOKASIDE_HIT
);
581 DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE
);
582 DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL
);
583 DefInt(SQLITE_DBSTATUS_CACHE_HIT
);
584 DefInt(SQLITE_DBSTATUS_CACHE_MISS
);
585 DefInt(SQLITE_DBSTATUS_CACHE_WRITE
);
586 DefInt(SQLITE_DBSTATUS_DEFERRED_FKS
);
587 DefInt(SQLITE_DBSTATUS_CACHE_USED_SHARED
);
588 DefInt(SQLITE_DBSTATUS_CACHE_SPILL
);
589 DefInt(SQLITE_DBSTATUS_MAX
);
592 DefGroup(encodings
) {
593 /* Noting that the wasm binding only aims to support UTF-8. */
595 DefInt(SQLITE_UTF16LE
);
596 DefInt(SQLITE_UTF16BE
);
597 DefInt(SQLITE_UTF16
);
598 /*deprecated DefInt(SQLITE_ANY); */
599 DefInt(SQLITE_UTF16_ALIGNED
);
603 DefInt(SQLITE_FCNTL_LOCKSTATE
);
604 DefInt(SQLITE_FCNTL_GET_LOCKPROXYFILE
);
605 DefInt(SQLITE_FCNTL_SET_LOCKPROXYFILE
);
606 DefInt(SQLITE_FCNTL_LAST_ERRNO
);
607 DefInt(SQLITE_FCNTL_SIZE_HINT
);
608 DefInt(SQLITE_FCNTL_CHUNK_SIZE
);
609 DefInt(SQLITE_FCNTL_FILE_POINTER
);
610 DefInt(SQLITE_FCNTL_SYNC_OMITTED
);
611 DefInt(SQLITE_FCNTL_WIN32_AV_RETRY
);
612 DefInt(SQLITE_FCNTL_PERSIST_WAL
);
613 DefInt(SQLITE_FCNTL_OVERWRITE
);
614 DefInt(SQLITE_FCNTL_VFSNAME
);
615 DefInt(SQLITE_FCNTL_POWERSAFE_OVERWRITE
);
616 DefInt(SQLITE_FCNTL_PRAGMA
);
617 DefInt(SQLITE_FCNTL_BUSYHANDLER
);
618 DefInt(SQLITE_FCNTL_TEMPFILENAME
);
619 DefInt(SQLITE_FCNTL_MMAP_SIZE
);
620 DefInt(SQLITE_FCNTL_TRACE
);
621 DefInt(SQLITE_FCNTL_HAS_MOVED
);
622 DefInt(SQLITE_FCNTL_SYNC
);
623 DefInt(SQLITE_FCNTL_COMMIT_PHASETWO
);
624 DefInt(SQLITE_FCNTL_WIN32_SET_HANDLE
);
625 DefInt(SQLITE_FCNTL_WAL_BLOCK
);
626 DefInt(SQLITE_FCNTL_ZIPVFS
);
627 DefInt(SQLITE_FCNTL_RBU
);
628 DefInt(SQLITE_FCNTL_VFS_POINTER
);
629 DefInt(SQLITE_FCNTL_JOURNAL_POINTER
);
630 DefInt(SQLITE_FCNTL_WIN32_GET_HANDLE
);
631 DefInt(SQLITE_FCNTL_PDB
);
632 DefInt(SQLITE_FCNTL_BEGIN_ATOMIC_WRITE
);
633 DefInt(SQLITE_FCNTL_COMMIT_ATOMIC_WRITE
);
634 DefInt(SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE
);
635 DefInt(SQLITE_FCNTL_LOCK_TIMEOUT
);
636 DefInt(SQLITE_FCNTL_DATA_VERSION
);
637 DefInt(SQLITE_FCNTL_SIZE_LIMIT
);
638 DefInt(SQLITE_FCNTL_CKPT_DONE
);
639 DefInt(SQLITE_FCNTL_RESERVE_BYTES
);
640 DefInt(SQLITE_FCNTL_CKPT_START
);
641 DefInt(SQLITE_FCNTL_EXTERNAL_READER
);
642 DefInt(SQLITE_FCNTL_CKSM_FILE
);
643 DefInt(SQLITE_FCNTL_RESET_CACHE
);
647 DefInt(SQLITE_LOCK_NONE
);
648 DefInt(SQLITE_LOCK_SHARED
);
649 DefInt(SQLITE_LOCK_RESERVED
);
650 DefInt(SQLITE_LOCK_PENDING
);
651 DefInt(SQLITE_LOCK_EXCLUSIVE
);
655 DefInt(SQLITE_IOCAP_ATOMIC
);
656 DefInt(SQLITE_IOCAP_ATOMIC512
);
657 DefInt(SQLITE_IOCAP_ATOMIC1K
);
658 DefInt(SQLITE_IOCAP_ATOMIC2K
);
659 DefInt(SQLITE_IOCAP_ATOMIC4K
);
660 DefInt(SQLITE_IOCAP_ATOMIC8K
);
661 DefInt(SQLITE_IOCAP_ATOMIC16K
);
662 DefInt(SQLITE_IOCAP_ATOMIC32K
);
663 DefInt(SQLITE_IOCAP_ATOMIC64K
);
664 DefInt(SQLITE_IOCAP_SAFE_APPEND
);
665 DefInt(SQLITE_IOCAP_SEQUENTIAL
);
666 DefInt(SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
);
667 DefInt(SQLITE_IOCAP_POWERSAFE_OVERWRITE
);
668 DefInt(SQLITE_IOCAP_IMMUTABLE
);
669 DefInt(SQLITE_IOCAP_BATCH_ATOMIC
);
673 DefInt(SQLITE_MAX_ALLOCATION_SIZE
);
674 DefInt(SQLITE_LIMIT_LENGTH
);
675 DefInt(SQLITE_MAX_LENGTH
);
676 DefInt(SQLITE_LIMIT_SQL_LENGTH
);
677 DefInt(SQLITE_MAX_SQL_LENGTH
);
678 DefInt(SQLITE_LIMIT_COLUMN
);
679 DefInt(SQLITE_MAX_COLUMN
);
680 DefInt(SQLITE_LIMIT_EXPR_DEPTH
);
681 DefInt(SQLITE_MAX_EXPR_DEPTH
);
682 DefInt(SQLITE_LIMIT_COMPOUND_SELECT
);
683 DefInt(SQLITE_MAX_COMPOUND_SELECT
);
684 DefInt(SQLITE_LIMIT_VDBE_OP
);
685 DefInt(SQLITE_MAX_VDBE_OP
);
686 DefInt(SQLITE_LIMIT_FUNCTION_ARG
);
687 DefInt(SQLITE_MAX_FUNCTION_ARG
);
688 DefInt(SQLITE_LIMIT_ATTACHED
);
689 DefInt(SQLITE_MAX_ATTACHED
);
690 DefInt(SQLITE_LIMIT_LIKE_PATTERN_LENGTH
);
691 DefInt(SQLITE_MAX_LIKE_PATTERN_LENGTH
);
692 DefInt(SQLITE_LIMIT_VARIABLE_NUMBER
);
693 DefInt(SQLITE_MAX_VARIABLE_NUMBER
);
694 DefInt(SQLITE_LIMIT_TRIGGER_DEPTH
);
695 DefInt(SQLITE_MAX_TRIGGER_DEPTH
);
696 DefInt(SQLITE_LIMIT_WORKER_THREADS
);
697 DefInt(SQLITE_MAX_WORKER_THREADS
);
700 DefGroup(openFlags
) {
701 /* Noting that not all of these will have any effect in
703 DefInt(SQLITE_OPEN_READONLY
);
704 DefInt(SQLITE_OPEN_READWRITE
);
705 DefInt(SQLITE_OPEN_CREATE
);
706 DefInt(SQLITE_OPEN_URI
);
707 DefInt(SQLITE_OPEN_MEMORY
);
708 DefInt(SQLITE_OPEN_NOMUTEX
);
709 DefInt(SQLITE_OPEN_FULLMUTEX
);
710 DefInt(SQLITE_OPEN_SHAREDCACHE
);
711 DefInt(SQLITE_OPEN_PRIVATECACHE
);
712 DefInt(SQLITE_OPEN_EXRESCODE
);
713 DefInt(SQLITE_OPEN_NOFOLLOW
);
714 /* OPEN flags for use with VFSes... */
715 DefInt(SQLITE_OPEN_MAIN_DB
);
716 DefInt(SQLITE_OPEN_MAIN_JOURNAL
);
717 DefInt(SQLITE_OPEN_TEMP_DB
);
718 DefInt(SQLITE_OPEN_TEMP_JOURNAL
);
719 DefInt(SQLITE_OPEN_TRANSIENT_DB
);
720 DefInt(SQLITE_OPEN_SUBJOURNAL
);
721 DefInt(SQLITE_OPEN_SUPER_JOURNAL
);
722 DefInt(SQLITE_OPEN_WAL
);
723 DefInt(SQLITE_OPEN_DELETEONCLOSE
);
724 DefInt(SQLITE_OPEN_EXCLUSIVE
);
727 DefGroup(prepareFlags
) {
728 DefInt(SQLITE_PREPARE_PERSISTENT
);
729 DefInt(SQLITE_PREPARE_NORMALIZE
);
730 DefInt(SQLITE_PREPARE_NO_VTAB
);
733 DefGroup(resultCodes
) {
735 DefInt(SQLITE_ERROR
);
736 DefInt(SQLITE_INTERNAL
);
738 DefInt(SQLITE_ABORT
);
740 DefInt(SQLITE_LOCKED
);
741 DefInt(SQLITE_NOMEM
);
742 DefInt(SQLITE_READONLY
);
743 DefInt(SQLITE_INTERRUPT
);
744 DefInt(SQLITE_IOERR
);
745 DefInt(SQLITE_CORRUPT
);
746 DefInt(SQLITE_NOTFOUND
);
748 DefInt(SQLITE_CANTOPEN
);
749 DefInt(SQLITE_PROTOCOL
);
750 DefInt(SQLITE_EMPTY
);
751 DefInt(SQLITE_SCHEMA
);
752 DefInt(SQLITE_TOOBIG
);
753 DefInt(SQLITE_CONSTRAINT
);
754 DefInt(SQLITE_MISMATCH
);
755 DefInt(SQLITE_MISUSE
);
756 DefInt(SQLITE_NOLFS
);
758 DefInt(SQLITE_FORMAT
);
759 DefInt(SQLITE_RANGE
);
760 DefInt(SQLITE_NOTADB
);
761 DefInt(SQLITE_NOTICE
);
762 DefInt(SQLITE_WARNING
);
765 // Extended Result Codes
766 DefInt(SQLITE_ERROR_MISSING_COLLSEQ
);
767 DefInt(SQLITE_ERROR_RETRY
);
768 DefInt(SQLITE_ERROR_SNAPSHOT
);
769 DefInt(SQLITE_IOERR_READ
);
770 DefInt(SQLITE_IOERR_SHORT_READ
);
771 DefInt(SQLITE_IOERR_WRITE
);
772 DefInt(SQLITE_IOERR_FSYNC
);
773 DefInt(SQLITE_IOERR_DIR_FSYNC
);
774 DefInt(SQLITE_IOERR_TRUNCATE
);
775 DefInt(SQLITE_IOERR_FSTAT
);
776 DefInt(SQLITE_IOERR_UNLOCK
);
777 DefInt(SQLITE_IOERR_RDLOCK
);
778 DefInt(SQLITE_IOERR_DELETE
);
779 DefInt(SQLITE_IOERR_BLOCKED
);
780 DefInt(SQLITE_IOERR_NOMEM
);
781 DefInt(SQLITE_IOERR_ACCESS
);
782 DefInt(SQLITE_IOERR_CHECKRESERVEDLOCK
);
783 DefInt(SQLITE_IOERR_LOCK
);
784 DefInt(SQLITE_IOERR_CLOSE
);
785 DefInt(SQLITE_IOERR_DIR_CLOSE
);
786 DefInt(SQLITE_IOERR_SHMOPEN
);
787 DefInt(SQLITE_IOERR_SHMSIZE
);
788 DefInt(SQLITE_IOERR_SHMLOCK
);
789 DefInt(SQLITE_IOERR_SHMMAP
);
790 DefInt(SQLITE_IOERR_SEEK
);
791 DefInt(SQLITE_IOERR_DELETE_NOENT
);
792 DefInt(SQLITE_IOERR_MMAP
);
793 DefInt(SQLITE_IOERR_GETTEMPPATH
);
794 DefInt(SQLITE_IOERR_CONVPATH
);
795 DefInt(SQLITE_IOERR_VNODE
);
796 DefInt(SQLITE_IOERR_AUTH
);
797 DefInt(SQLITE_IOERR_BEGIN_ATOMIC
);
798 DefInt(SQLITE_IOERR_COMMIT_ATOMIC
);
799 DefInt(SQLITE_IOERR_ROLLBACK_ATOMIC
);
800 DefInt(SQLITE_IOERR_DATA
);
801 DefInt(SQLITE_IOERR_CORRUPTFS
);
802 DefInt(SQLITE_LOCKED_SHAREDCACHE
);
803 DefInt(SQLITE_LOCKED_VTAB
);
804 DefInt(SQLITE_BUSY_RECOVERY
);
805 DefInt(SQLITE_BUSY_SNAPSHOT
);
806 DefInt(SQLITE_BUSY_TIMEOUT
);
807 DefInt(SQLITE_CANTOPEN_NOTEMPDIR
);
808 DefInt(SQLITE_CANTOPEN_ISDIR
);
809 DefInt(SQLITE_CANTOPEN_FULLPATH
);
810 DefInt(SQLITE_CANTOPEN_CONVPATH
);
811 //DefInt(SQLITE_CANTOPEN_DIRTYWAL)/*docs say not used*/;
812 DefInt(SQLITE_CANTOPEN_SYMLINK
);
813 DefInt(SQLITE_CORRUPT_VTAB
);
814 DefInt(SQLITE_CORRUPT_SEQUENCE
);
815 DefInt(SQLITE_CORRUPT_INDEX
);
816 DefInt(SQLITE_READONLY_RECOVERY
);
817 DefInt(SQLITE_READONLY_CANTLOCK
);
818 DefInt(SQLITE_READONLY_ROLLBACK
);
819 DefInt(SQLITE_READONLY_DBMOVED
);
820 DefInt(SQLITE_READONLY_CANTINIT
);
821 DefInt(SQLITE_READONLY_DIRECTORY
);
822 DefInt(SQLITE_ABORT_ROLLBACK
);
823 DefInt(SQLITE_CONSTRAINT_CHECK
);
824 DefInt(SQLITE_CONSTRAINT_COMMITHOOK
);
825 DefInt(SQLITE_CONSTRAINT_FOREIGNKEY
);
826 DefInt(SQLITE_CONSTRAINT_FUNCTION
);
827 DefInt(SQLITE_CONSTRAINT_NOTNULL
);
828 DefInt(SQLITE_CONSTRAINT_PRIMARYKEY
);
829 DefInt(SQLITE_CONSTRAINT_TRIGGER
);
830 DefInt(SQLITE_CONSTRAINT_UNIQUE
);
831 DefInt(SQLITE_CONSTRAINT_VTAB
);
832 DefInt(SQLITE_CONSTRAINT_ROWID
);
833 DefInt(SQLITE_CONSTRAINT_PINNED
);
834 DefInt(SQLITE_CONSTRAINT_DATATYPE
);
835 DefInt(SQLITE_NOTICE_RECOVER_WAL
);
836 DefInt(SQLITE_NOTICE_RECOVER_ROLLBACK
);
837 DefInt(SQLITE_WARNING_AUTOINDEX
);
838 DefInt(SQLITE_AUTH_USER
);
839 DefInt(SQLITE_OK_LOAD_PERMANENTLY
);
840 //DefInt(SQLITE_OK_SYMLINK) /* internal use only */;
844 DefInt(SQLITE_SERIALIZE_NOCOPY
);
845 DefInt(SQLITE_DESERIALIZE_FREEONCLOSE
);
846 DefInt(SQLITE_DESERIALIZE_READONLY
);
847 DefInt(SQLITE_DESERIALIZE_RESIZEABLE
);
851 DefInt(SQLITE_SESSION_CONFIG_STRMSIZE
);
852 DefInt(SQLITE_SESSION_OBJCONFIG_SIZE
);
855 DefGroup(sqlite3Status
){
856 DefInt(SQLITE_STATUS_MEMORY_USED
);
857 DefInt(SQLITE_STATUS_PAGECACHE_USED
);
858 DefInt(SQLITE_STATUS_PAGECACHE_OVERFLOW
);
859 //DefInt(SQLITE_STATUS_SCRATCH_USED) /* NOT USED */;
860 //DefInt(SQLITE_STATUS_SCRATCH_OVERFLOW) /* NOT USED */;
861 DefInt(SQLITE_STATUS_MALLOC_SIZE
);
862 DefInt(SQLITE_STATUS_PARSER_STACK
);
863 DefInt(SQLITE_STATUS_PAGECACHE_SIZE
);
864 //DefInt(SQLITE_STATUS_SCRATCH_SIZE) /* NOT USED */;
865 DefInt(SQLITE_STATUS_MALLOC_COUNT
);
868 DefGroup(stmtStatus
){
869 DefInt(SQLITE_STMTSTATUS_FULLSCAN_STEP
);
870 DefInt(SQLITE_STMTSTATUS_SORT
);
871 DefInt(SQLITE_STMTSTATUS_AUTOINDEX
);
872 DefInt(SQLITE_STMTSTATUS_VM_STEP
);
873 DefInt(SQLITE_STMTSTATUS_REPREPARE
);
874 DefInt(SQLITE_STMTSTATUS_RUN
);
875 DefInt(SQLITE_STMTSTATUS_FILTER_MISS
);
876 DefInt(SQLITE_STMTSTATUS_FILTER_HIT
);
877 DefInt(SQLITE_STMTSTATUS_MEMUSED
);
880 DefGroup(syncFlags
) {
881 DefInt(SQLITE_SYNC_NORMAL
);
882 DefInt(SQLITE_SYNC_FULL
);
883 DefInt(SQLITE_SYNC_DATAONLY
);
887 DefInt(SQLITE_TRACE_STMT
);
888 DefInt(SQLITE_TRACE_PROFILE
);
889 DefInt(SQLITE_TRACE_ROW
);
890 DefInt(SQLITE_TRACE_CLOSE
);
894 DefInt(SQLITE_TXN_NONE
);
895 DefInt(SQLITE_TXN_READ
);
896 DefInt(SQLITE_TXN_WRITE
);
900 DefInt(SQLITE_DETERMINISTIC
);
901 DefInt(SQLITE_DIRECTONLY
);
902 DefInt(SQLITE_INNOCUOUS
);
906 DefInt(SQLITE_VERSION_NUMBER
);
907 DefStr(SQLITE_VERSION
);
908 DefStr(SQLITE_SOURCE_ID
);
912 DefInt(SQLITE_INDEX_SCAN_UNIQUE
);
913 DefInt(SQLITE_INDEX_CONSTRAINT_EQ
);
914 DefInt(SQLITE_INDEX_CONSTRAINT_GT
);
915 DefInt(SQLITE_INDEX_CONSTRAINT_LE
);
916 DefInt(SQLITE_INDEX_CONSTRAINT_LT
);
917 DefInt(SQLITE_INDEX_CONSTRAINT_GE
);
918 DefInt(SQLITE_INDEX_CONSTRAINT_MATCH
);
919 DefInt(SQLITE_INDEX_CONSTRAINT_LIKE
);
920 DefInt(SQLITE_INDEX_CONSTRAINT_GLOB
);
921 DefInt(SQLITE_INDEX_CONSTRAINT_REGEXP
);
922 DefInt(SQLITE_INDEX_CONSTRAINT_NE
);
923 DefInt(SQLITE_INDEX_CONSTRAINT_ISNOT
);
924 DefInt(SQLITE_INDEX_CONSTRAINT_ISNOTNULL
);
925 DefInt(SQLITE_INDEX_CONSTRAINT_ISNULL
);
926 DefInt(SQLITE_INDEX_CONSTRAINT_IS
);
927 DefInt(SQLITE_INDEX_CONSTRAINT_LIMIT
);
928 DefInt(SQLITE_INDEX_CONSTRAINT_OFFSET
);
929 DefInt(SQLITE_INDEX_CONSTRAINT_FUNCTION
);
930 DefInt(SQLITE_VTAB_CONSTRAINT_SUPPORT
);
931 DefInt(SQLITE_VTAB_INNOCUOUS
);
932 DefInt(SQLITE_VTAB_DIRECTONLY
);
933 DefInt(SQLITE_VTAB_USES_ALL_SCHEMAS
);
934 DefInt(SQLITE_ROLLBACK
);
935 //DefInt(SQLITE_IGNORE); // Also used by sqlite3_authorizer() callback
937 //DefInt(SQLITE_ABORT); // Also an error code
938 DefInt(SQLITE_REPLACE
);
947 ** Emit an array of "StructBinder" struct descripions, which look
951 ** "name": "MyStruct",
954 ** "member1": {"offset": 0,"sizeof": 4,"signature": "i"},
955 ** "member2": {"offset": 4,"sizeof": 4,"signature": "p"},
956 ** "member3": {"offset": 8,"sizeof": 8,"signature": "j"}
960 ** Detailed documentation for those bits are in the docs for the
961 ** Jaccwabyt JS-side component.
964 /** Macros for emitting StructBinder description. */
965 #define StructBinder__(TYPE) \
967 outf("%s{", (nStruct++ ? ", " : "")); \
968 out("\"name\": \"" # TYPE "\","); \
969 outf("\"sizeof\": %d", (int)sizeof(TYPE)); \
970 out(",\"members\": {");
971 #define StructBinder_(T) StructBinder__(T)
972 /** ^^^ indirection needed to expand CurrentStruct */
973 #define StructBinder StructBinder_(CurrentStruct)
974 #define _StructBinder CloseBrace(2)
975 #define M(MEMBER,SIG) \
977 "{\"offset\":%d,\"sizeof\": %d,\"signature\":\"%s\"}", \
978 (n++ ? ", " : ""), #MEMBER, \
979 (int)offsetof(CurrentStruct,MEMBER), \
980 (int)sizeof(((CurrentStruct*)0)->MEMBER), \
984 out(", \"structs\": ["); {
986 #define CurrentStruct sqlite3_vfs
994 M(xOpen
, "i(pppip)");
995 M(xDelete
, "i(ppi)");
996 M(xAccess
, "i(ppip)");
997 M(xFullPathname
, "i(ppip)");
999 M(xDlError
, "p(pip)");
1001 M(xDlClose
, "v(pp)");
1002 M(xRandomness
, "i(pip)");
1004 M(xCurrentTime
, "i(pp)");
1005 M(xGetLastError
, "i(pip)");
1006 M(xCurrentTimeInt64
, "i(pp)");
1007 M(xSetSystemCall
, "i(ppp)");
1008 M(xGetSystemCall
, "p(pp)");
1009 M(xNextSystemCall
, "p(pp)");
1011 #undef CurrentStruct
1013 #define CurrentStruct sqlite3_io_methods
1017 M(xRead
, "i(ppij)");
1018 M(xWrite
, "i(ppij)");
1019 M(xTruncate
, "i(pj)");
1021 M(xFileSize
, "i(pp)");
1023 M(xUnlock
, "i(pi)");
1024 M(xCheckReservedLock
, "i(pp)");
1025 M(xFileControl
, "i(pip)");
1026 M(xSectorSize
, "i(p)");
1027 M(xDeviceCharacteristics
, "i(p)");
1028 M(xShmMap
, "i(piiip)");
1029 M(xShmLock
, "i(piii)");
1030 M(xShmBarrier
, "v(p)");
1031 M(xShmUnmap
, "i(pi)");
1032 M(xFetch
, "i(pjip)");
1033 M(xUnfetch
, "i(pjp)");
1035 #undef CurrentStruct
1037 #define CurrentStruct sqlite3_file
1041 #undef CurrentStruct
1043 #define CurrentStruct sqlite3_kvvfs_methods
1045 M(xRead
, "i(sspi)");
1046 M(xWrite
, "i(sss)");
1047 M(xDelete
, "i(ss)");
1050 #undef CurrentStruct
1053 #define CurrentStruct sqlite3_vtab
1059 #undef CurrentStruct
1061 #define CurrentStruct sqlite3_vtab_cursor
1065 #undef CurrentStruct
1067 #define CurrentStruct sqlite3_module
1070 M(xCreate
, "i(ppippp)");
1071 M(xConnect
, "i(ppippp)");
1072 M(xBestIndex
, "i(pp)");
1073 M(xDisconnect
, "i(p)");
1074 M(xDestroy
, "i(p)");
1077 M(xFilter
, "i(pisip)");
1080 M(xColumn
, "i(ppi)");
1082 M(xUpdate
, "i(pipp)");
1086 M(xRollback
, "i(p)");
1087 M(xFindFunction
, "i(pispp)");
1088 M(xRename
, "i(ps)");
1089 // ^^^ v1. v2+ follows...
1090 M(xSavepoint
, "i(pi)");
1091 M(xRelease
, "i(pi)");
1092 M(xRollbackTo
, "i(pi)");
1093 // ^^^ v2. v3+ follows...
1094 M(xShadowName
, "i(s)");
1096 #undef CurrentStruct
1099 ** Workaround: in order to map the various inner structs from
1100 ** sqlite3_index_info, we have to uplift those into constructs we
1101 ** can access by type name. These structs _must_ match their
1102 ** in-sqlite3_index_info counterparts byte for byte.
1107 unsigned char usable
;
1109 } sqlite3_index_constraint
;
1113 } sqlite3_index_orderby
;
1117 } sqlite3_index_constraint_usage
;
1118 { /* Validate that the above struct sizeof()s match
1119 ** expectations. We could improve upon this by
1120 ** checking the offsetof() for each member. */
1121 const sqlite3_index_info siiCheck
;
1122 #define IndexSzCheck(T,M) \
1123 (sizeof(T) == sizeof(*siiCheck.M))
1124 if(!IndexSzCheck(sqlite3_index_constraint
,aConstraint
)
1125 || !IndexSzCheck(sqlite3_index_orderby
,aOrderBy
)
1126 || !IndexSzCheck(sqlite3_index_constraint_usage
,aConstraintUsage
)){
1127 assert(!"sizeof mismatch in sqlite3_index_... struct(s)");
1133 #define CurrentStruct sqlite3_index_constraint
1138 M(iTermOffset
, "i");
1140 #undef CurrentStruct
1142 #define CurrentStruct sqlite3_index_orderby
1147 #undef CurrentStruct
1149 #define CurrentStruct sqlite3_index_constraint_usage
1154 #undef CurrentStruct
1156 #define CurrentStruct sqlite3_index_info
1158 M(nConstraint
, "i");
1159 M(aConstraint
, "p");
1162 M(aConstraintUsage
, "p");
1165 M(needToFreeIdxStr
, "i");
1166 M(orderByConsumed
, "i");
1167 M(estimatedCost
, "d");
1168 M(estimatedRows
, "j");
1172 #undef CurrentStruct
1174 #if SQLITE_WASM_TESTS
1175 #define CurrentStruct WasmTestStruct
1183 #undef CurrentStruct
1186 } out( "]"/*structs*/);
1188 out("}"/*top-level object*/);
1190 aBuffer
[0] = '{'/*end of the race-condition workaround*/;
1193 #undef StructBinder_
1194 #undef StructBinder__
1196 #undef _StructBinder
1204 ** This function is NOT part of the sqlite3 public API. It is strictly
1205 ** for use by the sqlite project's own JS/WASM bindings.
1207 ** This function invokes the xDelete method of the given VFS (or the
1208 ** default VFS if pVfs is NULL), passing on the given filename. If
1209 ** zName is NULL, no default VFS is found, or it has no xDelete
1210 ** method, SQLITE_MISUSE is returned, else the result of the xDelete()
1211 ** call is returned.
1214 int sqlite3_wasm_vfs_unlink(sqlite3_vfs
*pVfs
, const char *zName
){
1215 int rc
= SQLITE_MISUSE
/* ??? */;
1216 if( 0==pVfs
&& 0!=zName
) pVfs
= sqlite3_vfs_find(0);
1217 if( zName
&& pVfs
&& pVfs
->xDelete
){
1218 rc
= pVfs
->xDelete(pVfs
, zName
, 1);
1224 ** This function is NOT part of the sqlite3 public API. It is strictly
1225 ** for use by the sqlite project's own JS/WASM bindings.
1227 ** Returns a pointer to the given DB's VFS for the given DB name,
1228 ** defaulting to "main" if zDbName is 0. Returns 0 if no db with the
1229 ** given name is open.
1232 sqlite3_vfs
* sqlite3_wasm_db_vfs(sqlite3
*pDb
, const char *zDbName
){
1233 sqlite3_vfs
* pVfs
= 0;
1234 sqlite3_file_control(pDb
, zDbName
? zDbName
: "main",
1235 SQLITE_FCNTL_VFS_POINTER
, &pVfs
);
1240 ** This function is NOT part of the sqlite3 public API. It is strictly
1241 ** for use by the sqlite project's own JS/WASM bindings.
1243 ** This function resets the given db pointer's database as described at
1245 ** https://sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigresetdatabase
1247 ** But beware: virtual tables destroyed that way do not have their
1248 ** xDestroy() called, so will leak if they require that function for
1251 ** Returns 0 on success, an SQLITE_xxx code on error. Returns
1252 ** SQLITE_MISUSE if pDb is NULL.
1255 int sqlite3_wasm_db_reset(sqlite3
*pDb
){
1256 int rc
= SQLITE_MISUSE
;
1258 sqlite3_table_column_metadata(pDb
, "main", 0, 0, 0, 0, 0, 0, 0);
1259 rc
= sqlite3_db_config(pDb
, SQLITE_DBCONFIG_RESET_DATABASE
, 1, 0);
1261 rc
= sqlite3_exec(pDb
, "VACUUM", 0, 0, 0);
1262 sqlite3_db_config(pDb
, SQLITE_DBCONFIG_RESET_DATABASE
, 0, 0);
1269 ** This function is NOT part of the sqlite3 public API. It is strictly
1270 ** for use by the sqlite project's own JS/WASM bindings.
1272 ** Uses the given database's VFS xRead to stream the db file's
1273 ** contents out to the given callback. The callback gets a single
1274 ** chunk of size n (its 2nd argument) on each call and must return 0
1275 ** on success, non-0 on error. This function returns 0 on success,
1276 ** SQLITE_NOTFOUND if no db is open, or propagates any other non-0
1277 ** code from the callback. Note that this is not thread-friendly: it
1278 ** expects that it will be the only thread reading the db file and
1279 ** takes no measures to ensure that is the case.
1281 ** This implementation appears to work fine, but
1282 ** sqlite3_wasm_db_serialize() is arguably the better way to achieve
1286 int sqlite3_wasm_db_export_chunked( sqlite3
* pDb
,
1287 int (*xCallback
)(unsigned const char *zOut
, int n
) ){
1288 sqlite3_int64 nSize
= 0;
1289 sqlite3_int64 nPos
= 0;
1290 sqlite3_file
* pFile
= 0;
1291 unsigned char buf
[1024 * 8];
1292 int nBuf
= (int)sizeof(buf
);
1294 ? sqlite3_file_control(pDb
, "main",
1295 SQLITE_FCNTL_FILE_POINTER
, &pFile
)
1298 rc
= pFile
->pMethods
->xFileSize(pFile
, &nSize
);
1301 /* DB size is not an even multiple of the buffer size. Reduce
1302 ** buffer size so that we do not unduly inflate the db size
1303 ** with zero-padding when exporting. */
1304 if(0 == nSize
% 4096) nBuf
= 4096;
1305 else if(0 == nSize
% 2048) nBuf
= 2048;
1306 else if(0 == nSize
% 1024) nBuf
= 1024;
1309 for( ; 0==rc
&& nPos
<nSize
; nPos
+= nBuf
){
1310 rc
= pFile
->pMethods
->xRead(pFile
, buf
, nBuf
, nPos
);
1311 if( SQLITE_IOERR_SHORT_READ
== rc
){
1312 rc
= (nPos
+ nBuf
) < nSize
? rc
: 0/*assume EOF*/;
1314 if( 0==rc
) rc
= xCallback(buf
, nBuf
);
1320 ** This function is NOT part of the sqlite3 public API. It is strictly
1321 ** for use by the sqlite project's own JS/WASM bindings.
1323 ** A proxy for sqlite3_serialize() which serializes the schema zSchema
1324 ** of pDb, placing the serialized output in pOut and nOut. nOut may be
1325 ** NULL. If zSchema is NULL then "main" is assumed. If pDb or pOut are
1326 ** NULL then SQLITE_MISUSE is returned. If allocation of the
1327 ** serialized copy fails, SQLITE_NOMEM is returned. On success, 0 is
1328 ** returned and `*pOut` will contain a pointer to the memory unless
1329 ** mFlags includes SQLITE_SERIALIZE_NOCOPY and the database has no
1330 ** contiguous memory representation, in which case `*pOut` will be
1331 ** NULL but 0 will be returned.
1333 ** If `*pOut` is not NULL, the caller is responsible for passing it to
1334 ** sqlite3_free() to free it.
1337 int sqlite3_wasm_db_serialize( sqlite3
*pDb
, const char *zSchema
,
1338 unsigned char **pOut
,
1339 sqlite3_int64
*nOut
, unsigned int mFlags
){
1341 if( !pDb
|| !pOut
) return SQLITE_MISUSE
;
1342 if( nOut
) *nOut
= 0;
1343 z
= sqlite3_serialize(pDb
, zSchema
? zSchema
: "main", nOut
, mFlags
);
1344 if( z
|| (SQLITE_SERIALIZE_NOCOPY
& mFlags
) ){
1348 return SQLITE_NOMEM
;
1353 ** This function is NOT part of the sqlite3 public API. It is strictly
1354 ** for use by the sqlite project's own JS/WASM bindings.
1356 ** Creates a new file using the I/O API of the given VFS, containing
1357 ** the given number of bytes of the given data. If the file exists, it
1358 ** is truncated to the given length and populated with the given
1361 ** This function exists so that we can implement the equivalent of
1362 ** Emscripten's FS.createDataFile() in a VFS-agnostic way. This
1363 ** functionality is intended for use in uploading database files.
1365 ** Not all VFSes support this functionality, e.g. the "kvvfs" does
1368 ** If pVfs is NULL, sqlite3_vfs_find(0) is used.
1370 ** If zFile is NULL, pVfs is NULL (and sqlite3_vfs_find(0) returns
1371 ** NULL), or nData is negative, SQLITE_MISUSE are returned.
1373 ** On success, it creates a new file with the given name, populated
1374 ** with the fist nData bytes of pData. If pData is NULL, the file is
1375 ** created and/or truncated to nData bytes.
1377 ** Whether or not directory components of zFilename are created
1378 ** automatically or not is unspecified: that detail is left to the
1379 ** VFS. The "opfs" VFS, for example, creates them.
1381 ** If an error happens while populating or truncating the file, the
1382 ** target file will be deleted (if needed) if this function created
1383 ** it. If this function did not create it, it is not deleted but may
1384 ** be left in an undefined state.
1386 ** Returns 0 on success. On error, it returns a code described above
1387 ** or propagates a code from one of the I/O methods.
1389 ** Design note: nData is an integer, instead of int64, for WASM
1390 ** portability, so that the API can still work in builds where BigInt
1391 ** support is disabled or unavailable.
1394 int sqlite3_wasm_vfs_create_file( sqlite3_vfs
*pVfs
,
1395 const char *zFilename
,
1396 const unsigned char * pData
,
1399 sqlite3_file
*pFile
= 0;
1400 sqlite3_io_methods
const *pIo
;
1401 const int openFlags
= SQLITE_OPEN_READWRITE
| SQLITE_OPEN_CREATE
;
1403 int fileExisted
= 0;
1405 const unsigned char *pPos
= pData
;
1406 const int blockSize
= 512
1407 /* Because we are using pFile->pMethods->xWrite() for writing, and
1408 ** it may have a buffer limit related to sqlite3's pager size, we
1409 ** conservatively write in 512-byte blocks (smallest page
1411 //fprintf(stderr, "pVfs=%p, zFilename=%s, nData=%d\n", pVfs, zFilename, nData);
1412 if( !pVfs
) pVfs
= sqlite3_vfs_find(0);
1413 if( !pVfs
|| !zFilename
|| nData
<0 ) return SQLITE_MISUSE
;
1414 pVfs
->xAccess(pVfs
, zFilename
, SQLITE_ACCESS_EXISTS
, &fileExisted
);
1415 rc
= sqlite3OsOpenMalloc(pVfs
, zFilename
, &pFile
, openFlags
, &flagsOut
);
1417 # define RC fprintf(stderr,"create_file(%s,%s) @%d rc=%d\n", \
1418 pVfs->zName, zFilename, __LINE__, rc);
1424 pIo
= pFile
->pMethods
;
1426 /* We need xLock() in order to accommodate the OPFS VFS, as it
1427 ** obtains a writeable handle via the lock operation and releases
1428 ** it in xUnlock(). If we don't do those here, we have to add code
1429 ** to the VFS to account check whether it was locked before
1430 ** xFileSize(), xTruncate(), and the like, and release the lock
1431 ** only if it was unlocked when the op was started. */
1432 rc
= pIo
->xLock(pFile
, SQLITE_LOCK_EXCLUSIVE
);
1437 rc
= pIo
->xTruncate(pFile
, nData
);
1440 if( 0==rc
&& 0!=pData
&& nData
>0 ){
1441 while( 0==rc
&& nData
>0 ){
1442 const int n
= nData
>=blockSize
? blockSize
: nData
;
1443 rc
= pIo
->xWrite(pFile
, pPos
, n
, (sqlite3_int64
)(pPos
- pData
));
1448 if( 0==rc
&& nData
>0 ){
1449 assert( nData
<blockSize
);
1450 rc
= pIo
->xWrite(pFile
, pPos
, nData
,
1451 (sqlite3_int64
)(pPos
- pData
));
1455 if( pIo
->xUnlock
&& doUnlock
!=0 ){
1456 pIo
->xUnlock(pFile
, SQLITE_LOCK_NONE
);
1459 if( rc
!=0 && 0==fileExisted
){
1460 pVfs
->xDelete(pVfs
, zFilename
, 1);
1468 ** This function is NOT part of the sqlite3 public API. It is strictly
1469 ** for use by the sqlite project's own JS/WASM bindings.
1471 ** Allocates sqlite3KvvfsMethods.nKeySize bytes from
1472 ** sqlite3_wasm_pstack_alloc() and returns 0 if that allocation fails,
1473 ** else it passes that string to kvstorageMakeKey() and returns a
1474 ** NUL-terminated pointer to that string. It is up to the caller to
1475 ** use sqlite3_wasm_pstack_restore() to free the returned pointer.
1478 char * sqlite3_wasm_kvvfsMakeKeyOnPstack(const char *zClass
,
1479 const char *zKeyIn
){
1480 assert(sqlite3KvvfsMethods
.nKeySize
>24);
1482 (char *)sqlite3_wasm_pstack_alloc(sqlite3KvvfsMethods
.nKeySize
);
1484 kvstorageMakeKey(zClass
, zKeyIn
, zKeyOut
);
1490 ** This function is NOT part of the sqlite3 public API. It is strictly
1491 ** for use by the sqlite project's own JS/WASM bindings.
1493 ** Returns the pointer to the singleton object which holds the kvvfs
1494 ** I/O methods and associated state.
1497 sqlite3_kvvfs_methods
* sqlite3_wasm_kvvfs_methods(void){
1498 return &sqlite3KvvfsMethods
;
1502 ** This function is NOT part of the sqlite3 public API. It is strictly
1503 ** for use by the sqlite project's own JS/WASM bindings.
1505 ** This is a proxy for the variadic sqlite3_vtab_config() which passes
1506 ** its argument on, or not, to sqlite3_vtab_config(), depending on the
1507 ** value of its 2nd argument. Returns the result of
1508 ** sqlite3_vtab_config(), or SQLITE_MISUSE if the 2nd arg is not a
1512 int sqlite3_wasm_vtab_config(sqlite3
*pDb
, int op
, int arg
){
1514 case SQLITE_VTAB_DIRECTONLY
:
1515 case SQLITE_VTAB_INNOCUOUS
:
1516 return sqlite3_vtab_config(pDb
, op
);
1517 case SQLITE_VTAB_CONSTRAINT_SUPPORT
:
1518 return sqlite3_vtab_config(pDb
, op
, arg
);
1520 return SQLITE_MISUSE
;
1525 ** This function is NOT part of the sqlite3 public API. It is strictly
1526 ** for use by the sqlite project's own JS/WASM bindings.
1528 ** Wrapper for the variants of sqlite3_db_config() which take
1529 ** (int,int*) variadic args.
1532 int sqlite3_wasm_db_config_ip(sqlite3
*pDb
, int op
, int arg1
, int* pArg2
){
1534 case SQLITE_DBCONFIG_ENABLE_FKEY
:
1535 case SQLITE_DBCONFIG_ENABLE_TRIGGER
:
1536 case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
:
1537 case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
:
1538 case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
:
1539 case SQLITE_DBCONFIG_ENABLE_QPSG
:
1540 case SQLITE_DBCONFIG_TRIGGER_EQP
:
1541 case SQLITE_DBCONFIG_RESET_DATABASE
:
1542 case SQLITE_DBCONFIG_DEFENSIVE
:
1543 case SQLITE_DBCONFIG_WRITABLE_SCHEMA
:
1544 case SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
:
1545 case SQLITE_DBCONFIG_DQS_DML
:
1546 case SQLITE_DBCONFIG_DQS_DDL
:
1547 case SQLITE_DBCONFIG_ENABLE_VIEW
:
1548 case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
:
1549 case SQLITE_DBCONFIG_TRUSTED_SCHEMA
:
1550 case SQLITE_DBCONFIG_STMT_SCANSTATUS
:
1551 case SQLITE_DBCONFIG_REVERSE_SCANORDER
:
1552 return sqlite3_db_config(pDb
, op
, arg1
, pArg2
);
1553 default: return SQLITE_MISUSE
;
1558 ** This function is NOT part of the sqlite3 public API. It is strictly
1559 ** for use by the sqlite project's own JS/WASM bindings.
1561 ** Wrapper for the variants of sqlite3_db_config() which take
1562 ** (void*,int,int) variadic args.
1565 int sqlite3_wasm_db_config_pii(sqlite3
*pDb
, int op
, void * pArg1
, int arg2
, int arg3
){
1567 case SQLITE_DBCONFIG_LOOKASIDE
:
1568 return sqlite3_db_config(pDb
, op
, pArg1
, arg2
, arg3
);
1569 default: return SQLITE_MISUSE
;
1574 ** This function is NOT part of the sqlite3 public API. It is strictly
1575 ** for use by the sqlite project's own JS/WASM bindings.
1577 ** Wrapper for the variants of sqlite3_db_config() which take
1578 ** (const char *) variadic args.
1581 int sqlite3_wasm_db_config_s(sqlite3
*pDb
, int op
, const char *zArg
){
1583 case SQLITE_DBCONFIG_MAINDBNAME
:
1584 return sqlite3_db_config(pDb
, op
, zArg
);
1585 default: return SQLITE_MISUSE
;
1591 ** This function is NOT part of the sqlite3 public API. It is strictly
1592 ** for use by the sqlite project's own JS/WASM bindings.
1594 ** Binding for combinations of sqlite3_config() arguments which take
1595 ** a single integer argument.
1598 int sqlite3_wasm_config_i(int op
, int arg
){
1599 return sqlite3_config(op
, arg
);
1603 ** This function is NOT part of the sqlite3 public API. It is strictly
1604 ** for use by the sqlite project's own JS/WASM bindings.
1606 ** Binding for combinations of sqlite3_config() arguments which take
1607 ** two int arguments.
1610 int sqlite3_wasm_config_ii(int op
, int arg1
, int arg2
){
1611 return sqlite3_config(op
, arg1
, arg2
);
1615 ** This function is NOT part of the sqlite3 public API. It is strictly
1616 ** for use by the sqlite project's own JS/WASM bindings.
1618 ** Binding for combinations of sqlite3_config() arguments which take
1619 ** a single i64 argument.
1622 int sqlite3_wasm_config_j(int op
, sqlite3_int64 arg
){
1623 return sqlite3_config(op
, arg
);
1627 // Pending removal after verification of a workaround discussed in the
1628 // forum post linked to below.
1630 ** This function is NOT part of the sqlite3 public API. It is strictly
1631 ** for use by the sqlite project's own JS/WASM bindings.
1633 ** Returns a pointer to sqlite3_free(). In compliant browsers the
1634 ** return value, when passed to sqlite3.wasm.exports.functionEntry(),
1635 ** must resolve to the same function as
1636 ** sqlite3.wasm.exports.sqlite3_free. i.e. from a dev console where
1637 ** sqlite3 is exported globally, the following must be true:
1640 ** sqlite3.wasm.functionEntry(
1641 ** sqlite3.wasm.exports.sqlite3_wasm_ptr_to_sqlite3_free()
1642 ** ) === sqlite3.wasm.exports.sqlite3_free
1645 ** Using a function to return this pointer, as opposed to exporting it
1646 ** via sqlite3_wasm_enum_json(), is an attempt to work around a
1647 ** Safari-specific quirk covered at
1648 ** https://sqlite.org/forum/info/e5b20e1feb37a19a.
1651 void * sqlite3_wasm_ptr_to_sqlite3_free(void){
1652 return (void*)sqlite3_free
;
1656 #if defined(__EMSCRIPTEN__) && defined(SQLITE_ENABLE_WASMFS)
1657 #include <emscripten/wasmfs.h>
1660 ** This function is NOT part of the sqlite3 public API. It is strictly
1661 ** for use by the sqlite project's own JS/WASM bindings, specifically
1662 ** only when building with Emscripten's WASMFS support.
1664 ** This function should only be called if the JS side detects the
1665 ** existence of the Origin-Private FileSystem (OPFS) APIs in the
1666 ** client. The first time it is called, this function instantiates a
1667 ** WASMFS backend impl for OPFS. On success, subsequent calls are
1670 ** This function may be passed a "mount point" name, which must have a
1671 ** leading "/" and is currently restricted to a single path component,
1672 ** e.g. "/foo" is legal but "/foo/" and "/foo/bar" are not. If it is
1673 ** NULL or empty, it defaults to "/opfs".
1675 ** Returns 0 on success, SQLITE_NOMEM if instantiation of the backend
1676 ** object fails, SQLITE_IOERR if mkdir() of the zMountPoint dir in
1677 ** the virtual FS fails. In builds compiled without SQLITE_ENABLE_WASMFS
1678 ** defined, SQLITE_NOTFOUND is returned without side effects.
1681 int sqlite3_wasm_init_wasmfs(const char *zMountPoint
){
1682 static backend_t pOpfs
= 0;
1683 if( !zMountPoint
|| !*zMountPoint
) zMountPoint
= "/opfs";
1685 pOpfs
= wasmfs_create_opfs_backend();
1687 /** It's not enough to instantiate the backend. We have to create a
1688 mountpoint in the VFS and attach the backend to it. */
1689 if( pOpfs
&& 0!=access(zMountPoint
, F_OK
) ){
1690 /* Note that this check and is not robust but it will
1691 hypothetically suffice for the transient wasm-based virtual
1692 filesystem we're currently running in. */
1693 const int rc
= wasmfs_create_directory(zMountPoint
, 0777, pOpfs
);
1694 /*emscripten_console_logf("OPFS mkdir(%s) rc=%d", zMountPoint, rc);*/
1695 if(rc
) return SQLITE_IOERR
;
1697 return pOpfs
? 0 : SQLITE_NOMEM
;
1701 int sqlite3_wasm_init_wasmfs(const char *zUnused
){
1702 //emscripten_console_warn("WASMFS OPFS is not compiled in.");
1703 if(zUnused
){/*unused*/}
1704 return SQLITE_NOTFOUND
;
1706 #endif /* __EMSCRIPTEN__ && SQLITE_ENABLE_WASMFS */
1708 #if SQLITE_WASM_TESTS
1711 int sqlite3_wasm_test_intptr(int * p
){
1716 void * sqlite3_wasm_test_voidptr(void * p
){
1721 int64_t sqlite3_wasm_test_int64_max(void){
1722 return (int64_t)0x7fffffffffffffff;
1726 int64_t sqlite3_wasm_test_int64_min(void){
1727 return ~sqlite3_wasm_test_int64_max();
1731 int64_t sqlite3_wasm_test_int64_times2(int64_t x
){
1736 void sqlite3_wasm_test_int64_minmax(int64_t * min
, int64_t *max
){
1737 *max
= sqlite3_wasm_test_int64_max();
1738 *min
= sqlite3_wasm_test_int64_min();
1739 /*printf("minmax: min=%lld, max=%lld\n", *min, *max);*/
1743 int64_t sqlite3_wasm_test_int64ptr(int64_t * p
){
1744 /*printf("sqlite3_wasm_test_int64ptr( @%lld = 0x%llx )\n", (int64_t)p, *p);*/
1749 void sqlite3_wasm_test_stack_overflow(int recurse
){
1750 if(recurse
) sqlite3_wasm_test_stack_overflow(recurse
);
1753 /* For testing the 'string:dealloc' whwasmutil.xWrap() conversion. */
1755 char * sqlite3_wasm_test_str_hello(int fail
){
1756 char * s
= fail
? 0 : (char *)sqlite3_malloc(6);
1758 memcpy(s
, "hello", 5);
1763 #endif /* SQLITE_WASM_TESTS */
1765 #undef SQLITE_WASM_EXPORT