diff options
author | stephan <stephan@noemail.net> | 2022-09-26 11:38:58 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-09-26 11:38:58 +0000 |
commit | 1f095d482d1803deb9fcb60449e9ca1223018d73 (patch) | |
tree | ee83c502c48008460a89a0aaab2adcc728c7c69b /src | |
parent | 6a643e4bcdc81f835be75377d1c6306f5e23f541 (diff) | |
download | sqlite-1f095d482d1803deb9fcb60449e9ca1223018d73.tar.gz sqlite-1f095d482d1803deb9fcb60449e9ca1223018d73.zip |
Get fiddle db export working for OPFS VFS. Add root dir handle to the main OPFS VFS worker to enable creation of certain utility functions without delegating to the async worker. Add sqlite3.capi.sqlite3_wasm_rc_str() to map integer result codes back to their SQLITE_xxx counterparts. Minor doc touchups.
FossilOrigin-Name: 9b2244e1c8a40efe6547094a1b57acc8f2173145a8731abb0e36268ce0a8ef41
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index bafcc697f..3e5a1c216 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12632,27 +12632,13 @@ int fiddle_experiment(int a,int b){ return a + b; } -/* Only for emcc experimentation purposes. - - Define this function in JS using: - - emcc ... --js-library somefile.js - - containing: - -mergeInto(LibraryManager.library, { - my_foo: function(){ - console.debug("my_foo()",arguments); - } -}); +/* +** Returns a pointer to the current DB handle. */ -/*extern void my_foo(sqlite3 *);*/ -/* Only for emcc experimentation purposes. */ -sqlite3 * fiddle_the_db(){ - printf("fiddle_the_db(%p)\n", (const void*)globalDb); - /*my_foo(globalDb);*/ +sqlite3 * fiddle_db_handle(){ return globalDb; } + /* Only for emcc experimentation purposes. */ sqlite3 * fiddle_db_arg(sqlite3 *arg){ printf("fiddle_db_arg(%p)\n", (const void*)arg); @@ -12703,6 +12689,55 @@ void fiddle_reset_db(void){ } /* +** This is a bit of a workaround: returns true if the current db uses +** the "opfs" VFS, else false. +*/ +int fiddle_db_is_opfs(void){ + sqlite3_vfs * pVfs = 0; + if( 0!=shellState.db ){ + sqlite3_file_control( shellState.db, "main", + SQLITE_FCNTL_VFS_POINTER, &pVfs ); + } + return pVfs ? 0==strcmp("opfs", pVfs->zName) : 0; +} + +#if 0 +/* TODO: test whether this impl works properly wrt xSize() in the +** unix-none VFS. The JS impl works fine for OPFS but not unix-none +** because xSize() is returning a garbage size. +*/ +int fiddle_export_db( int (*callback)(unsigned const char *zOut, int n) ){ + sqlite3_int64 nSize = 0; + sqlite3_int64 nPos = 0; + sqlite3_vfs * pVfs = 0; + sqlite3_file * pFile = 0; + unsigned char buf[1024 * 4]; + const int nBuf = (int)sizeof(buf); + int rc = shellState.db + ? sqlite3_file_control(shellState.db, "main", + SQLITE_FCNTL_VFS_POINTER, &pVfs) + : 0; + if( rc ) return rc; + else if( 0==pVfs ) return SQLITE_NOTFOUND; + rc = sqlite3_file_control(shellState.db, "main", + SQLITE_FCNTL_FILE_POINTER, &pFile); + if( rc ) return rc; + rc = pFile->pMethods->xFileSize(pFile, &nSize); + if(rc) return rc; + 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/*assume EOF*/; + } + if(rc) return rc; + nPos += nBuf; + rc = callback(buf, nBuf); + } + return rc; +} +#endif + +/* ** Trivial exportable function for emscripten. It processes zSql as if ** it were input to the sqlite3 shell and redirects all output to the ** wasm binding. If fiddle_main() has not been called by the time this |