mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add sqlite3.capi.sqlite3_js_posix_create_file() and oo1.OpfsDb.importDb() as alternatives for the newly-deprecated sqlite3_js_vfs_create_file().
FossilOrigin-Name: da6eaf8d8258f3e2c8633fd7faf4e90c3307b5c60bd8b69c626b3c82b19dbdef
This commit is contained in:
@ -141,9 +141,6 @@
|
||||
#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
|
||||
@ -1353,6 +1350,13 @@ int sqlite3_wasm_db_serialize( sqlite3 *pDb, const char *zSchema,
|
||||
** This function is NOT part of the sqlite3 public API. It is strictly
|
||||
** for use by the sqlite project's own JS/WASM bindings.
|
||||
**
|
||||
** ACHTUNG: it was discovered on 2023-08-11 that, with SQLITE_DEBUG,
|
||||
** this function's out-of-scope use of the sqlite3_vfs/file/io_methods
|
||||
** APIs leads to triggering of assertions in the core library. Its use
|
||||
** is now deprecated and VFS-specific APIs for importing files need to
|
||||
** be found to replace it. sqlite3_wasm_posix_create_file() is
|
||||
** suitable for the "unix" family of VFSes.
|
||||
**
|
||||
** Creates a new file using the I/O API of the given VFS, containing
|
||||
** the given number of bytes of the given data. If the file exists, it
|
||||
** is truncated to the given length and populated with the given
|
||||
@ -1395,16 +1399,17 @@ int sqlite3_wasm_vfs_create_file( sqlite3_vfs *pVfs,
|
||||
const char *zFilename,
|
||||
const unsigned char * pData,
|
||||
int nData ){
|
||||
#ifdef SQLITE_DEBUG
|
||||
fprintf(stderr,"%s does not work in debug builds because its out-of-scope use of "
|
||||
"the sqlite3_vfs API triggers assertions in the core library.\n", __func__);
|
||||
/* ^^^ That was unfortunately not discovered until 2023-08-11. */
|
||||
return SQLITE_ERROR;
|
||||
#else
|
||||
int rc;
|
||||
sqlite3_file *pFile = 0;
|
||||
sqlite3_io_methods const *pIo;
|
||||
const int openFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
||||
const int openFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
|
||||
#if 0 && defined(SQLITE_DEBUG)
|
||||
| SQLITE_OPEN_MAIN_JOURNAL
|
||||
/* ^^^^ This is for testing a horrible workaround to avoid
|
||||
triggering a specific assert() in os_unix.c:unixOpen(). Please
|
||||
do not enable this in real builds. */
|
||||
#endif
|
||||
;
|
||||
int flagsOut = 0;
|
||||
int fileExisted = 0;
|
||||
int doUnlock = 0;
|
||||
@ -1468,7 +1473,34 @@ int sqlite3_wasm_vfs_create_file( sqlite3_vfs *pVfs,
|
||||
RC;
|
||||
#undef RC
|
||||
return rc;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
** This function is NOT part of the sqlite3 public API. It is strictly
|
||||
** for use by the sqlite project's own JS/WASM bindings.
|
||||
**
|
||||
** Creates or overwrites a file using the POSIX file API,
|
||||
** i.e. Emscripten's virtual filesystem. Creates or truncates
|
||||
** zFilename, appends pData bytes to it, and returns 0 on success or
|
||||
** SQLITE_IOERR on error.
|
||||
*/
|
||||
SQLITE_WASM_EXPORT
|
||||
int sqlite3_wasm_posix_create_file( const char *zFilename,
|
||||
const unsigned char * pData,
|
||||
int nData ){
|
||||
int rc;
|
||||
FILE * pFile = 0;
|
||||
int fileExisted = 0;
|
||||
size_t nWrote = 1;
|
||||
|
||||
if( !zFilename || nData<0 || (pData==0 && nData>0) ) return SQLITE_MISUSE;
|
||||
pFile = fopen(zFilename, "w");
|
||||
if( 0==pFile ) return SQLITE_IOERR;
|
||||
if( nData>0 ){
|
||||
nWrote = fwrite(pData, (size_t)nData, 1, pFile);
|
||||
}
|
||||
fclose(pFile);
|
||||
return 1==nWrote ? 0 : SQLITE_IOERR;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user