aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/tester1.c-pp.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2023-08-11 17:38:17 +0000
committerstephan <stephan@noemail.net>2023-08-11 17:38:17 +0000
commitb949244ea1c73f744b557524810c7945d3b0c5de (patch)
tree7ad6d4cb7155b2e3da6c6b317abedd0ebfd06321 /ext/wasm/tester1.c-pp.js
parent7e131529526d1f86689f1e9a3d07adac87bf21c3 (diff)
downloadsqlite-b949244ea1c73f744b557524810c7945d3b0c5de.tar.gz
sqlite-b949244ea1c73f744b557524810c7945d3b0c5de.zip
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
Diffstat (limited to 'ext/wasm/tester1.c-pp.js')
-rw-r--r--ext/wasm/tester1.c-pp.js56
1 files changed, 17 insertions, 39 deletions
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js
index c1b16d5e8..bd945dcab 100644
--- a/ext/wasm/tester1.c-pp.js
+++ b/ext/wasm/tester1.c-pp.js
@@ -1657,7 +1657,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
.assert('number'===typeof rc[0])
.assert(rc[0]|0 === rc[0] /* is small integer */);
})
- ////////////////////////////////////////////////////////////////////////
+ ////////////////////////////////////////////////////////////////////////
.t({
name: 'sqlite3_js_db_export()',
predicate: ()=>true,
@@ -1671,13 +1671,12 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
}
}/*sqlite3_js_db_export()*/)
.t({
- name: 'sqlite3_js_vfs_create_file() with db in default VFS',
+ name: 'sqlite3_js_posix_create_file()',
predicate: ()=>true,
test: function(sqlite3){
const db = this.db;
- const pVfs = capi.sqlite3_js_db_vfs(db);
- const filename = "sqlite3_js_vfs_create_file().db";
- capi.sqlite3_js_vfs_create_file(pVfs, filename, this.dbExport);
+ const filename = "sqlite3_js_posix_create_file.db";
+ capi.sqlite3_js_posix_create_file(filename, this.dbExport);
delete this.dbExport;
const db2 = new sqlite3.oo1.DB(filename,'r');
try {
@@ -1686,7 +1685,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
T.assert(n>0 && db2.selectValue(sql) === n);
}finally{
db2.close();
- wasm.sqlite3_wasm_vfs_unlink(pVfs, filename);
+ wasm.sqlite3_wasm_vfs_unlink(0, filename);
}
}
}/*sqlite3_js_vfs_create_file()*/)
@@ -2907,7 +2906,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
.t({
name: 'OPFS db sanity checks',
test: async function(sqlite3){
- const filename = this.opfsDbFile = 'sqlite3-tester1.db';
+ const filename = this.opfsDbFile = '/dir/sqlite3-tester1.db';
const pVfs = this.opfsVfs = capi.sqlite3_vfs_find('opfs');
T.assert(pVfs);
const unlink = this.opfsUnlink =
@@ -2935,22 +2934,23 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
}
}/*OPFS db sanity checks*/)
.t({
- name: 'OPFS export/import',
+ name: 'OPFS import',
test: async function(sqlite3){
let db;
try {
const exp = this.opfsDbExport;
delete this.opfsDbExport;
- capi.sqlite3_js_vfs_create_file("opfs", this.opfsDbFile, exp);
- const db = new sqlite3.oo1.OpfsDb(this.opfsDbFile);
- T.assert(6 === db.selectValue('select count(*) from p'));
+ this.opfsImportSize = await sqlite3.oo1.OpfsDb.importDb(this.opfsDbFile, exp);
+ db = new sqlite3.oo1.OpfsDb(this.opfsDbFile);
+ T.assert(6 === db.selectValue('select count(*) from p')).
+ assert( this.opfsImportSize == exp.byteLength );
}finally{
if(db) db.close();
}
}
}/*OPFS export/import*/)
.t({
- name: 'OPFS utility APIs and sqlite3_js_vfs_create_file()',
+ name: '(Internal-use) OPFS utility APIs',
test: async function(sqlite3){
const filename = this.opfsDbFile;
const pVfs = this.opfsVfs;
@@ -2959,8 +2959,6 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
delete this.opfsDbFile;
delete this.opfsVfs;
delete this.opfsUnlink;
- unlink();
- // Sanity-test sqlite3_js_vfs_create_file()...
/**************************************************************
ATTENTION CLIENT-SIDE USERS: sqlite3.opfs is NOT intended
for client-side use. It is only for this project's own
@@ -2968,39 +2966,19 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
any time.
***************************************************************/
const opfs = sqlite3.opfs;
- const fSize = 1379;
+ const fSize = this.opfsImportSize;
+ delete this.opfsImportSize;
let sh;
try{
- T.assert(!(await opfs.entryExists(filename)));
- capi.sqlite3_js_vfs_create_file(
- pVfs, filename, null, fSize
- );
T.assert(await opfs.entryExists(filename));
- let fh = await opfs.rootDirectory.getFileHandle(filename);
+ const [dirHandle, filenamePart] = await opfs.getDirForFilename(filename, false);
+ const fh = await dirHandle.getFileHandle(filenamePart);
sh = await fh.createSyncAccessHandle();
T.assert(fSize === await sh.getSize());
await sh.close();
sh = undefined;
unlink();
T.assert(!(await opfs.entryExists(filename)));
-
- const ba = new Uint8Array([1,2,3,4,5]);
- capi.sqlite3_js_vfs_create_file(
- "opfs", filename, ba
- );
- T.assert(await opfs.entryExists(filename));
- fh = await opfs.rootDirectory.getFileHandle(filename);
- sh = await fh.createSyncAccessHandle();
- T.assert(ba.byteLength === await sh.getSize());
- await sh.close();
- sh = undefined;
- unlink();
-
- T.mustThrowMatching(()=>{
- capi.sqlite3_js_vfs_create_file(
- "no-such-vfs", filename, ba
- );
- }, "SQLITE_NOTFOUND: Unknown sqlite3_vfs name: no-such-vfs");
}finally{
if(sh) await sh.close();
unlink();
@@ -3103,7 +3081,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
const conf2 = JSON.parse(JSON.stringify(sahPoolConfig));
conf2.name += '-test2';
const POther = await inst(conf2);
- log("Installed second SAH instance as",conf2.name);
+ //log("Installed second SAH instance as",conf2.name);
T.assert(0 === POther.getFileCount())
.assert(true === await POther.removeVfs());