#define SQLITE_WASM
#ifdef SQLITE_WASM_ENABLE_C_TESTS
# define SQLITE_WASM_TESTS 1
#else
# define SQLITE_WASM_TESTS 0
#endif
#undef SQLITE_OMIT_DESERIALIZE
#undef SQLITE_OMIT_MEMORYDB
#ifndef SQLITE_DEFAULT_CACHE_SIZE
# define SQLITE_DEFAULT_CACHE_SIZE -16384
#endif
#if !defined(SQLITE_DEFAULT_PAGE_SIZE)
# define SQLITE_DEFAULT_PAGE_SIZE 8192
#endif
#ifndef SQLITE_DEFAULT_UNIX_VFS
# define SQLITE_DEFAULT_UNIX_VFS "unix-none"
#endif
#undef SQLITE_DQS
#define SQLITE_DQS 0
#ifndef SQLITE_ENABLE_BYTECODE_VTAB
# define SQLITE_ENABLE_BYTECODE_VTAB 1
#endif
#ifndef SQLITE_ENABLE_DBPAGE_VTAB
# define SQLITE_ENABLE_DBPAGE_VTAB 1
#endif
#ifndef SQLITE_ENABLE_DBSTAT_VTAB
# define SQLITE_ENABLE_DBSTAT_VTAB 1
#endif
#ifndef SQLITE_ENABLE_EXPLAIN_COMMENTS
# define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
#endif
#ifndef SQLITE_ENABLE_FTS4
# define SQLITE_ENABLE_FTS4 1
#endif
#ifndef SQLITE_ENABLE_MATH_FUNCTIONS
# define SQLITE_ENABLE_MATH_FUNCTIONS 1
#endif
#ifndef SQLITE_ENABLE_OFFSET_SQL_FUNC
# define SQLITE_ENABLE_OFFSET_SQL_FUNC 1
#endif
#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
# define SQLITE_ENABLE_PREUPDATE_HOOK 1
#endif
#ifndef SQLITE_ENABLE_RTREE
# define SQLITE_ENABLE_RTREE 1
#endif
#ifndef SQLITE_ENABLE_SESSION
# define SQLITE_ENABLE_SESSION 1
#endif
#ifndef SQLITE_ENABLE_STMTVTAB
# define SQLITE_ENABLE_STMTVTAB 1
#endif
#ifndef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
# define SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
#endif
#ifndef SQLITE_MAX_ALLOCATION_SIZE
# define SQLITE_MAX_ALLOCATION_SIZE 0x1fffffff
#endif
#ifndef SQLITE_OMIT_DEPRECATED
# define SQLITE_OMIT_DEPRECATED 1
#endif
#ifndef SQLITE_OMIT_LOAD_EXTENSION
# define SQLITE_OMIT_LOAD_EXTENSION 1
#endif
#ifndef SQLITE_OMIT_SHARED_CACHE
# define SQLITE_OMIT_SHARED_CACHE 1
#endif
#ifndef SQLITE_OMIT_UTF16
# define SQLITE_OMIT_UTF16 1
#endif
#ifndef SQLITE_OMIT_WAL
# define SQLITE_OMIT_WAL 1
#endif
#ifndef SQLITE_OS_KV_OPTIONAL
# define SQLITE_OS_KV_OPTIONAL 1
#endif
#ifndef SQLITE_TEMP_STORE
# define SQLITE_TEMP_STORE 3
#endif
#ifndef SQLITE_THREADSAFE
# define SQLITE_THREADSAFE 0
#endif
#ifndef SQLITE_USE_URI
# define SQLITE_USE_URI 1
#endif
#ifdef SQLITE_WASM_EXTRA_INIT
# define SQLITE_EXTRA_INIT sqlite3_wasm_extra_init
#endif
#include <assert.h>
#define SQLITE_WASM_EXPORT __attribute__((used,visibility("default")))
#ifndef SQLITE_C
# define SQLITE_C sqlite3.c
#endif
#define INC__STRINGIFY_(f) #f
#define INC__STRINGIFY(f) INC__STRINGIFY_(f)
#include INC__STRINGIFY(SQLITE_C)
#undef INC__STRINGIFY_
#undef INC__STRINGIFY
#undef SQLITE_C
#if defined(__EMSCRIPTEN__)
# include <emscripten/console.h>
#endif
#if 0#endif
static unsigned char PStack_mem[512 * 8] = {0};
static struct {
unsigned const char * const pBegin;
unsigned const char * const pEnd;
unsigned char * pPos;
} PStack = {
&PStack_mem[0],
&PStack_mem[0] + sizeof(PStack_mem),
&PStack_mem[0] + sizeof(PStack_mem)
};
SQLITE_WASM_EXPORT void * sqlite3_wasm_pstack_ptr(void){
return PStack.pPos;
}
SQLITE_WASM_EXPORT void sqlite3_wasm_pstack_restore(unsigned char * p){
assert(p>=PStack.pBegin && p<=PStack.pEnd && p>=PStack.pPos);
assert(0==(p & 0x7));
if(p>=PStack.pBegin && p<=PStack.pEnd ){
PStack.pPos = p;
}
}
SQLITE_WASM_EXPORT void * sqlite3_wasm_pstack_alloc(int n){
if( n<=0 ) return 0;
n = (n + 7) & ~7 ;
if( PStack.pBegin + n > PStack.pPos
|| PStack.pBegin + n <= PStack.pBegin ) return 0;
memset((PStack.pPos = PStack.pPos - n), 0, (unsigned int)n);
return PStack.pPos;
}
SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_remaining(void){
assert(PStack.pPos >= PStack.pBegin);
assert(PStack.pPos <= PStack.pEnd);
return (int)(PStack.pPos - PStack.pBegin);
}
SQLITE_WASM_EXPORT int sqlite3_wasm_pstack_quota(void){
return (int)(PStack.pEnd - PStack.pBegin);
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_db_error(sqlite3*db, int err_code, const char *zMsg){
if( db!=0 ){
if( 0!=zMsg ){
const int nMsg = sqlite3Strlen30(zMsg);
sqlite3ErrorWithMsg(db, err_code, "%.*s", nMsg, zMsg);
}else{
sqlite3ErrorWithMsg(db, err_code, NULL);
}
}
return err_code;
}
#if SQLITE_WASM_TESTS
struct WasmTestStruct {
int v4;
void * ppV;
const char * cstr;
int64_t v8;
void (*xFunc)(void*);
};
typedef struct WasmTestStruct WasmTestStruct;
SQLITE_WASM_EXPORT
void sqlite3_wasm_test_struct(WasmTestStruct * s){
if(s){
s->v4 *= 2;
s->v8 = s->v4 * 2;
s->ppV = s;
s->cstr = __FILE__;
if(s->xFunc) s->xFunc(s);
}
return;
}
#endif
SQLITE_WASM_EXPORT
const char * sqlite3_wasm_enum_json(void){
static char aBuffer[1024 * 20] = {0} ;
int n = 0, nChildren = 0, nStruct = 0
;
char * zPos = &aBuffer[1] ;
char const * const zEnd = &aBuffer[0] + sizeof(aBuffer) ;
if(aBuffer[0]) return aBuffer;
#define lenCheck assert(zPos < zEnd - 128 \
&& "sqlite3_wasm_enum_json() buffer is too small."); \
if( zPos >= zEnd - 128 ) return 0
#define outf(format,...) \
zPos += snprintf(zPos, ((size_t)(zEnd - zPos)), format, __VA_ARGS__); \
lenCheck
#define out(TXT) outf("%s",TXT)
#define CloseBrace(LEVEL) \
assert(LEVEL<5); memset(zPos, '}', LEVEL); zPos+=LEVEL; lenCheck
#define DefGroup(KEY) n = 0; \
outf("%s\"" #KEY "\": {",(nChildren++ ? "," : ""));
#define DefInt(KEY) \
outf("%s\"%s\": %d", (n++ ? ", " : ""), #KEY, (int)KEY)
#define DefStr(KEY) \
outf("%s\"%s\": \"%s\"", (n++ ? ", " : ""), #KEY, KEY)
#define _DefGroup CloseBrace(1)
DefGroup(access){
DefInt(SQLITE_ACCESS_EXISTS);
DefInt(SQLITE_ACCESS_READWRITE);
DefInt(SQLITE_ACCESS_READ);
} _DefGroup;
DefGroup(authorizer){
DefInt(SQLITE_DENY);
DefInt(SQLITE_IGNORE);
DefInt(SQLITE_CREATE_INDEX);
DefInt(SQLITE_CREATE_TABLE);
DefInt(SQLITE_CREATE_TEMP_INDEX);
DefInt(SQLITE_CREATE_TEMP_TABLE);
DefInt(SQLITE_CREATE_TEMP_TRIGGER);
DefInt(SQLITE_CREATE_TEMP_VIEW);
DefInt(SQLITE_CREATE_TRIGGER);
DefInt(SQLITE_CREATE_VIEW);
DefInt(SQLITE_DELETE);
DefInt(SQLITE_DROP_INDEX);
DefInt(SQLITE_DROP_TABLE);
DefInt(SQLITE_DROP_TEMP_INDEX);
DefInt(SQLITE_DROP_TEMP_TABLE);
DefInt(SQLITE_DROP_TEMP_TRIGGER);
DefInt(SQLITE_DROP_TEMP_VIEW);
DefInt(SQLITE_DROP_TRIGGER);
DefInt(SQLITE_DROP_VIEW);
DefInt(SQLITE_INSERT);
DefInt(SQLITE_PRAGMA);
DefInt(SQLITE_READ);
DefInt(SQLITE_SELECT);
DefInt(SQLITE_TRANSACTION);
DefInt(SQLITE_UPDATE);
DefInt(SQLITE_ATTACH);
DefInt(SQLITE_DETACH);
DefInt(SQLITE_ALTER_TABLE);
DefInt(SQLITE_REINDEX);
DefInt(SQLITE_ANALYZE);
DefInt(SQLITE_CREATE_VTABLE);
DefInt(SQLITE_DROP_VTABLE);
DefInt(SQLITE_FUNCTION);
DefInt(SQLITE_SAVEPOINT);
DefInt(SQLITE_RECURSIVE);
} _DefGroup;
DefGroup(blobFinalizers) {
out("\"SQLITE_STATIC\":0, \"SQLITE_TRANSIENT\":-1");
outf(",\"SQLITE_WASM_DEALLOC\": %lld",
(sqlite3_int64)(sqlite3_free));
} _DefGroup;
DefGroup(changeset){
DefInt(SQLITE_CHANGESETSTART_INVERT);
DefInt(SQLITE_CHANGESETAPPLY_NOSAVEPOINT);
DefInt(SQLITE_CHANGESETAPPLY_INVERT);
DefInt(SQLITE_CHANGESETAPPLY_IGNORENOOP);
DefInt(SQLITE_CHANGESET_DATA);
DefInt(SQLITE_CHANGESET_NOTFOUND);
DefInt(SQLITE_CHANGESET_CONFLICT);
DefInt(SQLITE_CHANGESET_CONSTRAINT);
DefInt(SQLITE_CHANGESET_FOREIGN_KEY);
DefInt(SQLITE_CHANGESET_OMIT);
DefInt(SQLITE_CHANGESET_REPLACE);
DefInt(SQLITE_CHANGESET_ABORT);
} _DefGroup;
DefGroup(config){
DefInt(SQLITE_CONFIG_SINGLETHREAD);
DefInt(SQLITE_CONFIG_MULTITHREAD);
DefInt(SQLITE_CONFIG_SERIALIZED);
DefInt(SQLITE_CONFIG_MALLOC);
DefInt(SQLITE_CONFIG_GETMALLOC);
DefInt(SQLITE_CONFIG_SCRATCH);
DefInt(SQLITE_CONFIG_PAGECACHE);
DefInt(SQLITE_CONFIG_HEAP);
DefInt(SQLITE_CONFIG_MEMSTATUS);
DefInt(SQLITE_CONFIG_MUTEX);
DefInt(SQLITE_CONFIG_GETMUTEX);
DefInt(SQLITE_CONFIG_LOOKASIDE);
DefInt(SQLITE_CONFIG_PCACHE);
DefInt(SQLITE_CONFIG_GETPCACHE);
DefInt(SQLITE_CONFIG_LOG);
DefInt(SQLITE_CONFIG_URI);
DefInt(SQLITE_CONFIG_PCACHE2);
DefInt(SQLITE_CONFIG_GETPCACHE2);
DefInt(SQLITE_CONFIG_COVERING_INDEX_SCAN);
DefInt(SQLITE_CONFIG_SQLLOG);
DefInt(SQLITE_CONFIG_MMAP_SIZE);
DefInt(SQLITE_CONFIG_WIN32_HEAPSIZE);
DefInt(SQLITE_CONFIG_PCACHE_HDRSZ);
DefInt(SQLITE_CONFIG_PMASZ);
DefInt(SQLITE_CONFIG_STMTJRNL_SPILL);
DefInt(SQLITE_CONFIG_SMALL_MALLOC);
DefInt(SQLITE_CONFIG_SORTERREF_SIZE);
DefInt(SQLITE_CONFIG_MEMDB_MAXSIZE);
} _DefGroup;
DefGroup(dataTypes) {
DefInt(SQLITE_INTEGER);
DefInt(SQLITE_FLOAT);
DefInt(SQLITE_TEXT);
DefInt(SQLITE_BLOB);
DefInt(SQLITE_NULL);
} _DefGroup;
DefGroup(dbConfig){
DefInt(SQLITE_DBCONFIG_MAINDBNAME);
DefInt(SQLITE_DBCONFIG_LOOKASIDE);
DefInt(SQLITE_DBCONFIG_ENABLE_FKEY);
DefInt(SQLITE_DBCONFIG_ENABLE_TRIGGER);
DefInt(SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER);
DefInt(SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION);
DefInt(SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE);
DefInt(SQLITE_DBCONFIG_ENABLE_QPSG);
DefInt(SQLITE_DBCONFIG_TRIGGER_EQP);
DefInt(SQLITE_DBCONFIG_RESET_DATABASE);
DefInt(SQLITE_DBCONFIG_DEFENSIVE);
DefInt(SQLITE_DBCONFIG_WRITABLE_SCHEMA);
DefInt(SQLITE_DBCONFIG_LEGACY_ALTER_TABLE);
DefInt(SQLITE_DBCONFIG_DQS_DML);
DefInt(SQLITE_DBCONFIG_DQS_DDL);
DefInt(SQLITE_DBCONFIG_ENABLE_VIEW);
DefInt(SQLITE_DBCONFIG_LEGACY_FILE_FORMAT);
DefInt(SQLITE_DBCONFIG_TRUSTED_SCHEMA);
DefInt(SQLITE_DBCONFIG_STMT_SCANSTATUS);
DefInt(SQLITE_DBCONFIG_REVERSE_SCANORDER);
DefInt(SQLITE_DBCONFIG_MAX);
} _DefGroup;
DefGroup(dbStatus){
DefInt(SQLITE_DBSTATUS_LOOKASIDE_USED);
DefInt(SQLITE_DBSTATUS_CACHE_USED);
DefInt(SQLITE_DBSTATUS_SCHEMA_USED);
DefInt(SQLITE_DBSTATUS_STMT_USED);
DefInt(SQLITE_DBSTATUS_LOOKASIDE_HIT);
DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE);
DefInt(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL);
DefInt(SQLITE_DBSTATUS_CACHE_HIT);
DefInt(SQLITE_DBSTATUS_CACHE_MISS);
DefInt(SQLITE_DBSTATUS_CACHE_WRITE);
DefInt(SQLITE_DBSTATUS_DEFERRED_FKS);
DefInt(SQLITE_DBSTATUS_CACHE_USED_SHARED);
DefInt(SQLITE_DBSTATUS_CACHE_SPILL);
DefInt(SQLITE_DBSTATUS_MAX);
} _DefGroup;
DefGroup(encodings) {
DefInt(SQLITE_UTF8);
DefInt(SQLITE_UTF16LE);
DefInt(SQLITE_UTF16BE);
DefInt(SQLITE_UTF16);
DefInt(SQLITE_UTF16_ALIGNED);
} _DefGroup;
DefGroup(fcntl) {
DefInt(SQLITE_FCNTL_LOCKSTATE);
DefInt(SQLITE_FCNTL_GET_LOCKPROXYFILE);
DefInt(SQLITE_FCNTL_SET_LOCKPROXYFILE);
DefInt(SQLITE_FCNTL_LAST_ERRNO);
DefInt(SQLITE_FCNTL_SIZE_HINT);
DefInt(SQLITE_FCNTL_CHUNK_SIZE);
DefInt(SQLITE_FCNTL_FILE_POINTER);
DefInt(SQLITE_FCNTL_SYNC_OMITTED);
DefInt(SQLITE_FCNTL_WIN32_AV_RETRY);
DefInt(SQLITE_FCNTL_PERSIST_WAL);
DefInt(SQLITE_FCNTL_OVERWRITE);
DefInt(SQLITE_FCNTL_VFSNAME);
DefInt(SQLITE_FCNTL_POWERSAFE_OVERWRITE);
DefInt(SQLITE_FCNTL_PRAGMA);
DefInt(SQLITE_FCNTL_BUSYHANDLER);
DefInt(SQLITE_FCNTL_TEMPFILENAME);
DefInt(SQLITE_FCNTL_MMAP_SIZE);
DefInt(SQLITE_FCNTL_TRACE);
DefInt(SQLITE_FCNTL_HAS_MOVED);
DefInt(SQLITE_FCNTL_SYNC);
DefInt(SQLITE_FCNTL_COMMIT_PHASETWO);
DefInt(SQLITE_FCNTL_WIN32_SET_HANDLE);
DefInt(SQLITE_FCNTL_WAL_BLOCK);
DefInt(SQLITE_FCNTL_ZIPVFS);
DefInt(SQLITE_FCNTL_RBU);
DefInt(SQLITE_FCNTL_VFS_POINTER);
DefInt(SQLITE_FCNTL_JOURNAL_POINTER);
DefInt(SQLITE_FCNTL_WIN32_GET_HANDLE);
DefInt(SQLITE_FCNTL_PDB);
DefInt(SQLITE_FCNTL_BEGIN_ATOMIC_WRITE);
DefInt(SQLITE_FCNTL_COMMIT_ATOMIC_WRITE);
DefInt(SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE);
DefInt(SQLITE_FCNTL_LOCK_TIMEOUT);
DefInt(SQLITE_FCNTL_DATA_VERSION);
DefInt(SQLITE_FCNTL_SIZE_LIMIT);
DefInt(SQLITE_FCNTL_CKPT_DONE);
DefInt(SQLITE_FCNTL_RESERVE_BYTES);
DefInt(SQLITE_FCNTL_CKPT_START);
DefInt(SQLITE_FCNTL_EXTERNAL_READER);
DefInt(SQLITE_FCNTL_CKSM_FILE);
DefInt(SQLITE_FCNTL_RESET_CACHE);
} _DefGroup;
DefGroup(flock) {
DefInt(SQLITE_LOCK_NONE);
DefInt(SQLITE_LOCK_SHARED);
DefInt(SQLITE_LOCK_RESERVED);
DefInt(SQLITE_LOCK_PENDING);
DefInt(SQLITE_LOCK_EXCLUSIVE);
} _DefGroup;
DefGroup(ioCap) {
DefInt(SQLITE_IOCAP_ATOMIC);
DefInt(SQLITE_IOCAP_ATOMIC512);
DefInt(SQLITE_IOCAP_ATOMIC1K);
DefInt(SQLITE_IOCAP_ATOMIC2K);
DefInt(SQLITE_IOCAP_ATOMIC4K);
DefInt(SQLITE_IOCAP_ATOMIC8K);
DefInt(SQLITE_IOCAP_ATOMIC16K);
DefInt(SQLITE_IOCAP_ATOMIC32K);
DefInt(SQLITE_IOCAP_ATOMIC64K);
DefInt(SQLITE_IOCAP_SAFE_APPEND);
DefInt(SQLITE_IOCAP_SEQUENTIAL);
DefInt(SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN);
DefInt(SQLITE_IOCAP_POWERSAFE_OVERWRITE);
DefInt(SQLITE_IOCAP_IMMUTABLE);
DefInt(SQLITE_IOCAP_BATCH_ATOMIC);
} _DefGroup;
DefGroup(limits) {
DefInt(SQLITE_MAX_ALLOCATION_SIZE);
DefInt(SQLITE_LIMIT_LENGTH);
DefInt(SQLITE_MAX_LENGTH);
DefInt(SQLITE_LIMIT_SQL_LENGTH);
DefInt(SQLITE_MAX_SQL_LENGTH);
DefInt(SQLITE_LIMIT_COLUMN);
DefInt(SQLITE_MAX_COLUMN);
DefInt(SQLITE_LIMIT_EXPR_DEPTH);
DefInt(SQLITE_MAX_EXPR_DEPTH);
DefInt(SQLITE_LIMIT_COMPOUND_SELECT);
DefInt(SQLITE_MAX_COMPOUND_SELECT);
DefInt(SQLITE_LIMIT_VDBE_OP);
DefInt(SQLITE_MAX_VDBE_OP);
DefInt(SQLITE_LIMIT_FUNCTION_ARG);
DefInt(SQLITE_MAX_FUNCTION_ARG);
DefInt(SQLITE_LIMIT_ATTACHED);
DefInt(SQLITE_MAX_ATTACHED);
DefInt(SQLITE_LIMIT_LIKE_PATTERN_LENGTH);
DefInt(SQLITE_MAX_LIKE_PATTERN_LENGTH);
DefInt(SQLITE_LIMIT_VARIABLE_NUMBER);
DefInt(SQLITE_MAX_VARIABLE_NUMBER);
DefInt(SQLITE_LIMIT_TRIGGER_DEPTH);
DefInt(SQLITE_MAX_TRIGGER_DEPTH);
DefInt(SQLITE_LIMIT_WORKER_THREADS);
DefInt(SQLITE_MAX_WORKER_THREADS);
} _DefGroup;
DefGroup(openFlags) {
DefInt(SQLITE_OPEN_READONLY);
DefInt(SQLITE_OPEN_READWRITE);
DefInt(SQLITE_OPEN_CREATE);
DefInt(SQLITE_OPEN_URI);
DefInt(SQLITE_OPEN_MEMORY);
DefInt(SQLITE_OPEN_NOMUTEX);
DefInt(SQLITE_OPEN_FULLMUTEX);
DefInt(SQLITE_OPEN_SHAREDCACHE);
DefInt(SQLITE_OPEN_PRIVATECACHE);
DefInt(SQLITE_OPEN_EXRESCODE);
DefInt(SQLITE_OPEN_NOFOLLOW);
DefInt(SQLITE_OPEN_MAIN_DB);
DefInt(SQLITE_OPEN_MAIN_JOURNAL);
DefInt(SQLITE_OPEN_TEMP_DB);
DefInt(SQLITE_OPEN_TEMP_JOURNAL);
DefInt(SQLITE_OPEN_TRANSIENT_DB);
DefInt(SQLITE_OPEN_SUBJOURNAL);
DefInt(SQLITE_OPEN_SUPER_JOURNAL);
DefInt(SQLITE_OPEN_WAL);
DefInt(SQLITE_OPEN_DELETEONCLOSE);
DefInt(SQLITE_OPEN_EXCLUSIVE);
} _DefGroup;
DefGroup(prepareFlags) {
DefInt(SQLITE_PREPARE_PERSISTENT);
DefInt(SQLITE_PREPARE_NORMALIZE);
DefInt(SQLITE_PREPARE_NO_VTAB);
} _DefGroup;
DefGroup(resultCodes) {
DefInt(SQLITE_OK);
DefInt(SQLITE_ERROR);
DefInt(SQLITE_INTERNAL);
DefInt(SQLITE_PERM);
DefInt(SQLITE_ABORT);
DefInt(SQLITE_BUSY);
DefInt(SQLITE_LOCKED);
DefInt(SQLITE_NOMEM);
DefInt(SQLITE_READONLY);
DefInt(SQLITE_INTERRUPT);
DefInt(SQLITE_IOERR);
DefInt(SQLITE_CORRUPT);
DefInt(SQLITE_NOTFOUND);
DefInt(SQLITE_FULL);
DefInt(SQLITE_CANTOPEN);
DefInt(SQLITE_PROTOCOL);
DefInt(SQLITE_EMPTY);
DefInt(SQLITE_SCHEMA);
DefInt(SQLITE_TOOBIG);
DefInt(SQLITE_CONSTRAINT);
DefInt(SQLITE_MISMATCH);
DefInt(SQLITE_MISUSE);
DefInt(SQLITE_NOLFS);
DefInt(SQLITE_AUTH);
DefInt(SQLITE_FORMAT);
DefInt(SQLITE_RANGE);
DefInt(SQLITE_NOTADB);
DefInt(SQLITE_NOTICE);
DefInt(SQLITE_WARNING);
DefInt(SQLITE_ROW);
DefInt(SQLITE_DONE);
DefInt(SQLITE_ERROR_MISSING_COLLSEQ);
DefInt(SQLITE_ERROR_RETRY);
DefInt(SQLITE_ERROR_SNAPSHOT);
DefInt(SQLITE_IOERR_READ);
DefInt(SQLITE_IOERR_SHORT_READ);
DefInt(SQLITE_IOERR_WRITE);
DefInt(SQLITE_IOERR_FSYNC);
DefInt(SQLITE_IOERR_DIR_FSYNC);
DefInt(SQLITE_IOERR_TRUNCATE);
DefInt(SQLITE_IOERR_FSTAT);
DefInt(SQLITE_IOERR_UNLOCK);
DefInt(SQLITE_IOERR_RDLOCK);
DefInt(SQLITE_IOERR_DELETE);
DefInt(SQLITE_IOERR_BLOCKED);
DefInt(SQLITE_IOERR_NOMEM);
DefInt(SQLITE_IOERR_ACCESS);
DefInt(SQLITE_IOERR_CHECKRESERVEDLOCK);
DefInt(SQLITE_IOERR_LOCK);
DefInt(SQLITE_IOERR_CLOSE);
DefInt(SQLITE_IOERR_DIR_CLOSE);
DefInt(SQLITE_IOERR_SHMOPEN);
DefInt(SQLITE_IOERR_SHMSIZE);
DefInt(SQLITE_IOERR_SHMLOCK);
DefInt(SQLITE_IOERR_SHMMAP);
DefInt(SQLITE_IOERR_SEEK);
DefInt(SQLITE_IOERR_DELETE_NOENT);
DefInt(SQLITE_IOERR_MMAP);
DefInt(SQLITE_IOERR_GETTEMPPATH);
DefInt(SQLITE_IOERR_CONVPATH);
DefInt(SQLITE_IOERR_VNODE);
DefInt(SQLITE_IOERR_AUTH);
DefInt(SQLITE_IOERR_BEGIN_ATOMIC);
DefInt(SQLITE_IOERR_COMMIT_ATOMIC);
DefInt(SQLITE_IOERR_ROLLBACK_ATOMIC);
DefInt(SQLITE_IOERR_DATA);
DefInt(SQLITE_IOERR_CORRUPTFS);
DefInt(SQLITE_LOCKED_SHAREDCACHE);
DefInt(SQLITE_LOCKED_VTAB);
DefInt(SQLITE_BUSY_RECOVERY);
DefInt(SQLITE_BUSY_SNAPSHOT);
DefInt(SQLITE_BUSY_TIMEOUT);
DefInt(SQLITE_CANTOPEN_NOTEMPDIR);
DefInt(SQLITE_CANTOPEN_ISDIR);
DefInt(SQLITE_CANTOPEN_FULLPATH);
DefInt(SQLITE_CANTOPEN_CONVPATH);
DefInt(SQLITE_CANTOPEN_SYMLINK);
DefInt(SQLITE_CORRUPT_VTAB);
DefInt(SQLITE_CORRUPT_SEQUENCE);
DefInt(SQLITE_CORRUPT_INDEX);
DefInt(SQLITE_READONLY_RECOVERY);
DefInt(SQLITE_READONLY_CANTLOCK);
DefInt(SQLITE_READONLY_ROLLBACK);
DefInt(SQLITE_READONLY_DBMOVED);
DefInt(SQLITE_READONLY_CANTINIT);
DefInt(SQLITE_READONLY_DIRECTORY);
DefInt(SQLITE_ABORT_ROLLBACK);
DefInt(SQLITE_CONSTRAINT_CHECK);
DefInt(SQLITE_CONSTRAINT_COMMITHOOK);
DefInt(SQLITE_CONSTRAINT_FOREIGNKEY);
DefInt(SQLITE_CONSTRAINT_FUNCTION);
DefInt(SQLITE_CONSTRAINT_NOTNULL);
DefInt(SQLITE_CONSTRAINT_PRIMARYKEY);
DefInt(SQLITE_CONSTRAINT_TRIGGER);
DefInt(SQLITE_CONSTRAINT_UNIQUE);
DefInt(SQLITE_CONSTRAINT_VTAB);
DefInt(SQLITE_CONSTRAINT_ROWID);
DefInt(SQLITE_CONSTRAINT_PINNED);
DefInt(SQLITE_CONSTRAINT_DATATYPE);
DefInt(SQLITE_NOTICE_RECOVER_WAL);
DefInt(SQLITE_NOTICE_RECOVER_ROLLBACK);
DefInt(SQLITE_WARNING_AUTOINDEX);
DefInt(SQLITE_AUTH_USER);
DefInt(SQLITE_OK_LOAD_PERMANENTLY);
} _DefGroup;
DefGroup(serialize){
DefInt(SQLITE_SERIALIZE_NOCOPY);
DefInt(SQLITE_DESERIALIZE_FREEONCLOSE);
DefInt(SQLITE_DESERIALIZE_READONLY);
DefInt(SQLITE_DESERIALIZE_RESIZEABLE);
} _DefGroup;
DefGroup(session){
DefInt(SQLITE_SESSION_CONFIG_STRMSIZE);
DefInt(SQLITE_SESSION_OBJCONFIG_SIZE);
} _DefGroup;
DefGroup(sqlite3Status){
DefInt(SQLITE_STATUS_MEMORY_USED);
DefInt(SQLITE_STATUS_PAGECACHE_USED);
DefInt(SQLITE_STATUS_PAGECACHE_OVERFLOW);
DefInt(SQLITE_STATUS_MALLOC_SIZE);
DefInt(SQLITE_STATUS_PARSER_STACK);
DefInt(SQLITE_STATUS_PAGECACHE_SIZE);
DefInt(SQLITE_STATUS_MALLOC_COUNT);
} _DefGroup;
DefGroup(stmtStatus){
DefInt(SQLITE_STMTSTATUS_FULLSCAN_STEP);
DefInt(SQLITE_STMTSTATUS_SORT);
DefInt(SQLITE_STMTSTATUS_AUTOINDEX);
DefInt(SQLITE_STMTSTATUS_VM_STEP);
DefInt(SQLITE_STMTSTATUS_REPREPARE);
DefInt(SQLITE_STMTSTATUS_RUN);
DefInt(SQLITE_STMTSTATUS_FILTER_MISS);
DefInt(SQLITE_STMTSTATUS_FILTER_HIT);
DefInt(SQLITE_STMTSTATUS_MEMUSED);
} _DefGroup;
DefGroup(syncFlags) {
DefInt(SQLITE_SYNC_NORMAL);
DefInt(SQLITE_SYNC_FULL);
DefInt(SQLITE_SYNC_DATAONLY);
} _DefGroup;
DefGroup(trace) {
DefInt(SQLITE_TRACE_STMT);
DefInt(SQLITE_TRACE_PROFILE);
DefInt(SQLITE_TRACE_ROW);
DefInt(SQLITE_TRACE_CLOSE);
} _DefGroup;
DefGroup(txnState){
DefInt(SQLITE_TXN_NONE);
DefInt(SQLITE_TXN_READ);
DefInt(SQLITE_TXN_WRITE);
} _DefGroup;
DefGroup(udfFlags) {
DefInt(SQLITE_DETERMINISTIC);
DefInt(SQLITE_DIRECTONLY);
DefInt(SQLITE_INNOCUOUS);
} _DefGroup;
DefGroup(version) {
DefInt(SQLITE_VERSION_NUMBER);
DefStr(SQLITE_VERSION);
DefStr(SQLITE_SOURCE_ID);
} _DefGroup;
DefGroup(vtab) {
DefInt(SQLITE_INDEX_SCAN_UNIQUE);
DefInt(SQLITE_INDEX_CONSTRAINT_EQ);
DefInt(SQLITE_INDEX_CONSTRAINT_GT);
DefInt(SQLITE_INDEX_CONSTRAINT_LE);
DefInt(SQLITE_INDEX_CONSTRAINT_LT);
DefInt(SQLITE_INDEX_CONSTRAINT_GE);
DefInt(SQLITE_INDEX_CONSTRAINT_MATCH);
DefInt(SQLITE_INDEX_CONSTRAINT_LIKE);
DefInt(SQLITE_INDEX_CONSTRAINT_GLOB);
DefInt(SQLITE_INDEX_CONSTRAINT_REGEXP);
DefInt(SQLITE_INDEX_CONSTRAINT_NE);
DefInt(SQLITE_INDEX_CONSTRAINT_ISNOT);
DefInt(SQLITE_INDEX_CONSTRAINT_ISNOTNULL);
DefInt(SQLITE_INDEX_CONSTRAINT_ISNULL);
DefInt(SQLITE_INDEX_CONSTRAINT_IS);
DefInt(SQLITE_INDEX_CONSTRAINT_LIMIT);
DefInt(SQLITE_INDEX_CONSTRAINT_OFFSET);
DefInt(SQLITE_INDEX_CONSTRAINT_FUNCTION);
DefInt(SQLITE_VTAB_CONSTRAINT_SUPPORT);
DefInt(SQLITE_VTAB_INNOCUOUS);
DefInt(SQLITE_VTAB_DIRECTONLY);
DefInt(SQLITE_VTAB_USES_ALL_SCHEMAS);
DefInt(SQLITE_ROLLBACK);
DefInt(SQLITE_FAIL);
DefInt(SQLITE_REPLACE);
} _DefGroup;
#undef DefGroup
#undef DefStr
#undef DefInt
#undef _DefGroup
#define StructBinder__(TYPE) \
n = 0; \
outf("%s{", (nStruct++ ? ", " : "")); \
out("\"name\": \"" # TYPE "\","); \
outf("\"sizeof\": %d", (int)sizeof(TYPE)); \
out(",\"members\": {");
#define StructBinder_(T) StructBinder__(T)
#define StructBinder StructBinder_(CurrentStruct)
#define _StructBinder CloseBrace(2)
#define M(MEMBER,SIG) \
outf("%s\"%s\": " \
"{\"offset\":%d,\"sizeof\": %d,\"signature\":\"%s\"}", \
(n++ ? ", " : ""), #MEMBER, \
(int)offsetof(CurrentStruct,MEMBER), \
(int)sizeof(((CurrentStruct*)0)->MEMBER), \
SIG)
nStruct = 0;
out(", \"structs\": ["); {
#define CurrentStruct sqlite3_vfs
StructBinder {
M(iVersion, "i");
M(szOsFile, "i");
M(mxPathname, "i");
M(pNext, "p");
M(zName, "s");
M(pAppData, "p");
M(xOpen, "i(pppip)");
M(xDelete, "i(ppi)");
M(xAccess, "i(ppip)");
M(xFullPathname, "i(ppip)");
M(xDlOpen, "p(pp)");
M(xDlError, "p(pip)");
M(xDlSym, "p()");
M(xDlClose, "v(pp)");
M(xRandomness, "i(pip)");
M(xSleep, "i(pi)");
M(xCurrentTime, "i(pp)");
M(xGetLastError, "i(pip)");
M(xCurrentTimeInt64, "i(pp)");
M(xSetSystemCall, "i(ppp)");
M(xGetSystemCall, "p(pp)");
M(xNextSystemCall, "p(pp)");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_io_methods
StructBinder {
M(iVersion, "i");
M(xClose, "i(p)");
M(xRead, "i(ppij)");
M(xWrite, "i(ppij)");
M(xTruncate, "i(pj)");
M(xSync, "i(pi)");
M(xFileSize, "i(pp)");
M(xLock, "i(pi)");
M(xUnlock, "i(pi)");
M(xCheckReservedLock, "i(pp)");
M(xFileControl, "i(pip)");
M(xSectorSize, "i(p)");
M(xDeviceCharacteristics, "i(p)");
M(xShmMap, "i(piiip)");
M(xShmLock, "i(piii)");
M(xShmBarrier, "v(p)");
M(xShmUnmap, "i(pi)");
M(xFetch, "i(pjip)");
M(xUnfetch, "i(pjp)");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_file
StructBinder {
M(pMethods, "p");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_kvvfs_methods
StructBinder {
M(xRead, "i(sspi)");
M(xWrite, "i(sss)");
M(xDelete, "i(ss)");
M(nKeySize, "i");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_vtab
StructBinder {
M(pModule, "p");
M(nRef, "i");
M(zErrMsg, "p");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_vtab_cursor
StructBinder {
M(pVtab, "p");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_module
StructBinder {
M(iVersion, "i");
M(xCreate, "i(ppippp)");
M(xConnect, "i(ppippp)");
M(xBestIndex, "i(pp)");
M(xDisconnect, "i(p)");
M(xDestroy, "i(p)");
M(xOpen, "i(pp)");
M(xClose, "i(p)");
M(xFilter, "i(pisip)");
M(xNext, "i(p)");
M(xEof, "i(p)");
M(xColumn, "i(ppi)");
M(xRowid, "i(pp)");
M(xUpdate, "i(pipp)");
M(xBegin, "i(p)");
M(xSync, "i(p)");
M(xCommit, "i(p)");
M(xRollback, "i(p)");
M(xFindFunction, "i(pispp)");
M(xRename, "i(ps)");
M(xSavepoint, "i(pi)");
M(xRelease, "i(pi)");
M(xRollbackTo, "i(pi)");
M(xShadowName, "i(s)");
} _StructBinder;
#undef CurrentStruct
typedef struct {
int iColumn;
unsigned char op;
unsigned char usable;
int iTermOffset;
} sqlite3_index_constraint;
typedef struct {
int iColumn;
unsigned char desc;
} sqlite3_index_orderby;
typedef struct {
int argvIndex;
unsigned char omit;
} sqlite3_index_constraint_usage;
{
const sqlite3_index_info siiCheck;
#define IndexSzCheck(T,M) \
(sizeof(T) == sizeof(*siiCheck.M))
if(!IndexSzCheck(sqlite3_index_constraint,aConstraint)
|| !IndexSzCheck(sqlite3_index_orderby,aOrderBy)
|| !IndexSzCheck(sqlite3_index_constraint_usage,aConstraintUsage)){
assert(!"sizeof mismatch in sqlite3_index_... struct(s)");
return 0;
}
#undef IndexSzCheck
}
#define CurrentStruct sqlite3_index_constraint
StructBinder {
M(iColumn, "i");
M(op, "C");
M(usable, "C");
M(iTermOffset, "i");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_index_orderby
StructBinder {
M(iColumn, "i");
M(desc, "C");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_index_constraint_usage
StructBinder {
M(argvIndex, "i");
M(omit, "C");
} _StructBinder;
#undef CurrentStruct
#define CurrentStruct sqlite3_index_info
StructBinder {
M(nConstraint, "i");
M(aConstraint, "p");
M(nOrderBy, "i");
M(aOrderBy, "p");
M(aConstraintUsage, "p");
M(idxNum, "i");
M(idxStr, "p");
M(needToFreeIdxStr, "i");
M(orderByConsumed, "i");
M(estimatedCost, "d");
M(estimatedRows, "j");
M(idxFlags, "i");
M(colUsed, "j");
} _StructBinder;
#undef CurrentStruct
#if SQLITE_WASM_TESTS
#define CurrentStruct WasmTestStruct
StructBinder {
M(v4, "i");
M(cstr, "s");
M(ppV, "p");
M(v8, "j");
M(xFunc, "v(p)");
} _StructBinder;
#undef CurrentStruct
#endif
} out( "]");
out("}");
*zPos = 0;
aBuffer[0] = '{';
return aBuffer;
#undef StructBinder
#undef StructBinder_
#undef StructBinder__
#undef M
#undef _StructBinder
#undef CloseBrace
#undef out
#undef outf
#undef lenCheck
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_vfs_unlink(sqlite3_vfs *pVfs, const char *zName){
int rc = SQLITE_MISUSE ;
if( 0==pVfs && 0!=zName ) pVfs = sqlite3_vfs_find(0);
if( zName && pVfs && pVfs->xDelete ){
rc = pVfs->xDelete(pVfs, zName, 1);
}
return rc;
}
SQLITE_WASM_EXPORT
sqlite3_vfs * sqlite3_wasm_db_vfs(sqlite3 *pDb, const char *zDbName){
sqlite3_vfs * pVfs = 0;
sqlite3_file_control(pDb, zDbName ? zDbName : "main",
SQLITE_FCNTL_VFS_POINTER, &pVfs);
return pVfs;
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_db_reset(sqlite3 *pDb){
int rc = SQLITE_MISUSE;
if( pDb ){
sqlite3_table_column_metadata(pDb, "main", 0, 0, 0, 0, 0, 0, 0);
rc = sqlite3_db_config(pDb, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
if( 0==rc ){
rc = sqlite3_exec(pDb, "VACUUM", 0, 0, 0);
sqlite3_db_config(pDb, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
}
}
return rc;
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_db_export_chunked( sqlite3* pDb,
int (*xCallback)(unsigned const char *zOut, int n) ){
sqlite3_int64 nSize = 0;
sqlite3_int64 nPos = 0;
sqlite3_file * pFile = 0;
unsigned char buf[1024 * 8];
int nBuf = (int)sizeof(buf);
int rc = pDb
? sqlite3_file_control(pDb, "main",
SQLITE_FCNTL_FILE_POINTER, &pFile)
: SQLITE_NOTFOUND;
if( rc ) return rc;
rc = pFile->pMethods->xFileSize(pFile, &nSize);
if( rc ) return rc;
if(nSize % nBuf){
if(0 == nSize % 4096) nBuf = 4096;
else if(0 == nSize % 2048) nBuf = 2048;
else if(0 == nSize % 1024) nBuf = 1024;
else nBuf = 512;
}
for( ; 0==rc && nPos<nSize; nPos += nBuf ){
rc = pFile->pMethods->xRead(pFile, buf, nBuf, nPos);
if( SQLITE_IOERR_SHORT_READ == rc ){
rc = (nPos + nBuf) < nSize ? rc : 0;
}
if( 0==rc ) rc = xCallback(buf, nBuf);
}
return rc;
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_db_serialize( sqlite3 *pDb, const char *zSchema,
unsigned char **pOut,
sqlite3_int64 *nOut, unsigned int mFlags ){
unsigned char * z;
if( !pDb || !pOut ) return SQLITE_MISUSE;
if( nOut ) *nOut = 0;
z = sqlite3_serialize(pDb, zSchema ? zSchema : "main", nOut, mFlags);
if( z || (SQLITE_SERIALIZE_NOCOPY & mFlags) ){
*pOut = z;
return 0;
}else{
return SQLITE_NOMEM;
}
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_vfs_create_file( sqlite3_vfs *pVfs,
const char *zFilename,
const unsigned char * pData,
int nData ){
int rc;
sqlite3_file *pFile = 0;
sqlite3_io_methods const *pIo;
const int openFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
int flagsOut = 0;
int fileExisted = 0;
int doUnlock = 0;
const unsigned char *pPos = pData;
const int blockSize = 512
;
if( !pVfs ) pVfs = sqlite3_vfs_find(0);
if( !pVfs || !zFilename || nData<0 ) return SQLITE_MISUSE;
pVfs->xAccess(pVfs, zFilename, SQLITE_ACCESS_EXISTS, &fileExisted);
rc = sqlite3OsOpenMalloc(pVfs, zFilename, &pFile, openFlags, &flagsOut);
#if 0#else
# define RC
#endif
RC;
if(rc) return rc;
pIo = pFile->pMethods;
if( pIo->xLock ) {
rc = pIo->xLock(pFile, SQLITE_LOCK_EXCLUSIVE);
RC;
doUnlock = 0==rc;
}
if( 0==rc ){
rc = pIo->xTruncate(pFile, nData);
RC;
}
if( 0==rc && 0!=pData && nData>0 ){
while( 0==rc && nData>0 ){
const int n = nData>=blockSize ? blockSize : nData;
rc = pIo->xWrite(pFile, pPos, n, (sqlite3_int64)(pPos - pData));
RC;
nData -= n;
pPos += n;
}
if( 0==rc && nData>0 ){
assert( nData<blockSize );
rc = pIo->xWrite(pFile, pPos, nData,
(sqlite3_int64)(pPos - pData));
RC;
}
}
if( pIo->xUnlock && doUnlock!=0 ){
pIo->xUnlock(pFile, SQLITE_LOCK_NONE);
}
pIo->xClose(pFile);
if( rc!=0 && 0==fileExisted ){
pVfs->xDelete(pVfs, zFilename, 1);
}
RC;
#undef RC
return rc;
}
SQLITE_WASM_EXPORT
char * sqlite3_wasm_kvvfsMakeKeyOnPstack(const char *zClass,
const char *zKeyIn){
assert(sqlite3KvvfsMethods.nKeySize>24);
char *zKeyOut =
(char *)sqlite3_wasm_pstack_alloc(sqlite3KvvfsMethods.nKeySize);
if(zKeyOut){
kvstorageMakeKey(zClass, zKeyIn, zKeyOut);
}
return zKeyOut;
}
SQLITE_WASM_EXPORT
sqlite3_kvvfs_methods * sqlite3_wasm_kvvfs_methods(void){
return &sqlite3KvvfsMethods;
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_vtab_config(sqlite3 *pDb, int op, int arg){
switch(op){
case SQLITE_VTAB_DIRECTONLY:
case SQLITE_VTAB_INNOCUOUS:
return sqlite3_vtab_config(pDb, op);
case SQLITE_VTAB_CONSTRAINT_SUPPORT:
return sqlite3_vtab_config(pDb, op, arg);
default:
return SQLITE_MISUSE;
}
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){
switch(op){
case SQLITE_DBCONFIG_ENABLE_FKEY:
case SQLITE_DBCONFIG_ENABLE_TRIGGER:
case SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:
case SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:
case SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:
case SQLITE_DBCONFIG_ENABLE_QPSG:
case SQLITE_DBCONFIG_TRIGGER_EQP:
case SQLITE_DBCONFIG_RESET_DATABASE:
case SQLITE_DBCONFIG_DEFENSIVE:
case SQLITE_DBCONFIG_WRITABLE_SCHEMA:
case SQLITE_DBCONFIG_LEGACY_ALTER_TABLE:
case SQLITE_DBCONFIG_DQS_DML:
case SQLITE_DBCONFIG_DQS_DDL:
case SQLITE_DBCONFIG_ENABLE_VIEW:
case SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:
case SQLITE_DBCONFIG_TRUSTED_SCHEMA:
case SQLITE_DBCONFIG_STMT_SCANSTATUS:
case SQLITE_DBCONFIG_REVERSE_SCANORDER:
return sqlite3_db_config(pDb, op, arg1, pArg2);
default: return SQLITE_MISUSE;
}
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_db_config_pii(sqlite3 *pDb, int op, void * pArg1, int arg2, int arg3){
switch(op){
case SQLITE_DBCONFIG_LOOKASIDE:
return sqlite3_db_config(pDb, op, pArg1, arg2, arg3);
default: return SQLITE_MISUSE;
}
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_db_config_s(sqlite3 *pDb, int op, const char *zArg){
switch(op){
case SQLITE_DBCONFIG_MAINDBNAME:
return sqlite3_db_config(pDb, op, zArg);
default: return SQLITE_MISUSE;
}
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_config_i(int op, int arg){
return sqlite3_config(op, arg);
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_config_ii(int op, int arg1, int arg2){
return sqlite3_config(op, arg1, arg2);
}
SQLITE_WASM_EXPORT
int sqlite3_wasm_config_j(int op, sqlite3_int64 arg){
return sqlite3_config(op, arg);
}
#if 0#endif
#if defined(__EMSCRIPTEN__) && defined(SQLITE_ENABLE_WASMFS)
#include <emscripten/wasmfs.h>
SQLITE_WASM_EXPORT
int sqlite3_wasm_init_wasmfs(const char *zMountPoint){
static backend_t pOpfs = 0;
if( !zMountPoint || !*zMountPoint ) zMountPoint = "/opfs";
if( !pOpfs ){
pOpfs = wasmfs_create_opfs_backend();
}
if( pOpfs && 0!=access(zMountPoint, F_OK) ){
const int rc = wasmfs_create_directory(zMountPoint, 0777, pOpfs);
if(rc) return SQLITE_IOERR;
}
return pOpfs ? 0 : SQLITE_NOMEM;
}
#else
SQLITE_WASM_EXPORT
int sqlite3_wasm_init_wasmfs(const char *zUnused){
if(zUnused){}
return SQLITE_NOTFOUND;
}
#endif
#if SQLITE_WASM_TESTS
SQLITE_WASM_EXPORT
int sqlite3_wasm_test_intptr(int * p){
return *p = *p * 2;
}
SQLITE_WASM_EXPORT
void * sqlite3_wasm_test_voidptr(void * p){
return p;
}
SQLITE_WASM_EXPORT
int64_t sqlite3_wasm_test_int64_max(void){
return (int64_t)0x7fffffffffffffff;
}
SQLITE_WASM_EXPORT
int64_t sqlite3_wasm_test_int64_min(void){
return ~sqlite3_wasm_test_int64_max();
}
SQLITE_WASM_EXPORT
int64_t sqlite3_wasm_test_int64_times2(int64_t x){
return x * 2;
}
SQLITE_WASM_EXPORT
void sqlite3_wasm_test_int64_minmax(int64_t * min, int64_t *max){
*max = sqlite3_wasm_test_int64_max();
*min = sqlite3_wasm_test_int64_min();
}
SQLITE_WASM_EXPORT
int64_t sqlite3_wasm_test_int64ptr(int64_t * p){
return *p = *p * 2;
}
SQLITE_WASM_EXPORT
void sqlite3_wasm_test_stack_overflow(int recurse){
if(recurse) sqlite3_wasm_test_stack_overflow(recurse);
}
SQLITE_WASM_EXPORT
char * sqlite3_wasm_test_str_hello(int fail){
char * s = fail ? 0 : (char *)sqlite3_malloc(6);
if(s){
memcpy(s, "hello", 5);
s[5] = 0;
}
return s;
}
#endif
#undef SQLITE_WASM_EXPORT