aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/tester1.c-pp.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-01 15:22:03 +0000
committerstephan <stephan@noemail.net>2022-12-01 15:22:03 +0000
commit919dbc846a097a1f044cfd2c7003c4f256ccb155 (patch)
treeea276b2c6f866a36341868c297404c678ffd9f19 /ext/wasm/tester1.c-pp.js
parent9ec1a7a7a07be84a597fb6d7a455b52275f8eab2 (diff)
downloadsqlite-919dbc846a097a1f044cfd2c7003c4f256ccb155.tar.gz
sqlite-919dbc846a097a1f044cfd2c7003c4f256ccb155.zip
sqlite3_js_create_file() now accepts an ArrayBuffer data source. Add test for OPFS-based export/re-import. The (sqlite3*) argument converter now optionally accepts sqlite3.oo1.DB instances.
FossilOrigin-Name: 14a84b67fb17e16a5691ea4bf7f374123ac73a361a5d3d0efca53788d2001e3a
Diffstat (limited to 'ext/wasm/tester1.c-pp.js')
-rw-r--r--ext/wasm/tester1.c-pp.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js
index b1d9cba2e..9a65c8b23 100644
--- a/ext/wasm/tester1.c-pp.js
+++ b/ext/wasm/tester1.c-pp.js
@@ -1160,7 +1160,8 @@ self.sqlite3InitModule = sqlite3InitModule;
.mustThrowMatching(()=>db.pointer=1, /read-only/)
.assert(0===sqlite3.capi.sqlite3_extended_result_codes(db.pointer,1))
.assert('main'===db.dbName(0))
- .assert('string' === typeof db.dbVfsName());
+ .assert('string' === typeof db.dbVfsName())
+ .assert(db.pointer === wasm.xWrap.testConvertArg('sqlite3*',db));
// Custom db error message handling via sqlite3_prepare_v2/v3()
let rc = capi.sqlite3_prepare_v3(db.pointer, {/*invalid*/}, -1, 0, null, null);
T.assert(capi.SQLITE_MISUSE === rc)
@@ -1782,6 +1783,17 @@ self.sqlite3InitModule = sqlite3InitModule;
db = new JDb(filename);
db.exec('insert into kvvfs(a) values(4),(5),(6)');
T.assert(6 === db.selectValue('select count(*) from kvvfs'));
+
+ // Check import/export of db...
+ if(0){
+ // does not yet work with kvvfs for unknown reasons...
+ const exp = capi.sqlite3_js_db_export(db);
+ db.close();
+ unlink();
+ capi.sqlite3_js_vfs_create_file("kvvfs", filename, exp);
+ db = new JDb(filename);
+ T.assert(6 === db.selectValue('select count(*) from kvvfs'));
+ }
}finally{
db.close();
unlink();
@@ -1812,6 +1824,10 @@ self.sqlite3InitModule = sqlite3InitModule;
db = new sqlite3.oo1.OpfsDb(filename);
db.exec('insert into p(a) values(4),(5),(6)');
T.assert(6 === db.selectValue('select count(*) from p'));
+ this.opfsDbExport = capi.sqlite3_js_db_export(db);
+ T.assert(this.opfsDbExport instanceof Uint8Array)
+ .assert(this.opfsDbExport.byteLength>0
+ && 0===this.opfsDbExport.byteLength % 512);
}finally{
db.close();
unlink();
@@ -1819,12 +1835,30 @@ self.sqlite3InitModule = sqlite3InitModule;
}
}/*OPFS db sanity checks*/)
.t({
+ name: 'OPFS export/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'));
+ }finally{
+ if(db) db.close();
+ }
+ }
+ }/*OPFS export/import*/)
+ .t({
name: 'OPFS utility APIs and sqlite3_js_vfs_create_file()',
test: async function(sqlite3){
const filename = this.opfsDbFile;
const pVfs = this.opfsVfs;
const unlink = this.opfsUnlink;
T.assert(filename && pVfs && !!unlink);
+ delete this.opfsDbFile;
+ delete this.opfsVfs;
+ delete this.opfsUnlink;
unlink();
// Sanity-test sqlite3_js_vfs_create_file()...
/**************************************************************