mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Wasm: expose sqlite3_exec() and use it to simplify the db-reset logic in batch-runner.js a bit.
FossilOrigin-Name: 2e2821f782511b9d2274a89a5a922582aba18c7e9dc7ce01080e713942a56d7d
This commit is contained in:
@ -611,9 +611,10 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
["sqlite3_errmsg", "string", "sqlite3*"],
|
||||
["sqlite3_error_offset", "int", "sqlite3*"],
|
||||
["sqlite3_errstr", "string", "int"],
|
||||
//["sqlite3_exec", "int", "sqlite3*", "string", "*", "*", "**"],
|
||||
// ^^^ TODO: we need a wrapper to support passing a function pointer or a function
|
||||
// for the callback.
|
||||
["sqlite3_exec", "int", "sqlite3*", "string", "*", "*", "**"],
|
||||
// TODO?: ^^^ add a wrapper around sqlite3_exec() which accepts a
|
||||
// JS callback function and handles the (un)installation of that
|
||||
// function before/after the exec call.
|
||||
["sqlite3_expanded_sql", "string", "sqlite3_stmt*"],
|
||||
["sqlite3_extended_errcode", "int", "sqlite3*"],
|
||||
["sqlite3_extended_result_codes", "int", "sqlite3*", "int"],
|
||||
|
@ -67,8 +67,9 @@
|
||||
const capi = sqlite3.capi, wasm = capi.wasm;
|
||||
const scope = wasm.scopedAllocPush();
|
||||
try {
|
||||
const toDrop = [];
|
||||
const toDrop = [/* type, name pairs */];
|
||||
const ppStmt = wasm.scopedAllocPtr();
|
||||
// Collect list of tables/etc we can drop...
|
||||
let rc = capi.sqlite3_prepare_v2(db.handle, sqlToDrop, -1, ppStmt, null);
|
||||
checkSqliteRc(db.handle,rc);
|
||||
pStmt = wasm.getPtrValue(ppStmt);
|
||||
@ -78,34 +79,31 @@
|
||||
}
|
||||
capi.sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
let doBreak = !toDrop.length;
|
||||
while(!doBreak){
|
||||
// Build SQL to delete them...
|
||||
const sqlDrop = [];
|
||||
const doDrop = 0!==toDrop.length;
|
||||
while(doDrop){
|
||||
const name = toDrop.pop();
|
||||
const type = toDrop.pop();
|
||||
let sql2;
|
||||
if(name){
|
||||
const type = toDrop.pop();
|
||||
switch(type){
|
||||
case 'table': case 'view': case 'trigger': case 'index':
|
||||
sql2 = 'DROP '+type+' '+name;
|
||||
sqlDrop.push('DROP '+type+' '+name);
|
||||
break;
|
||||
default:
|
||||
warn("Unhandled db entry type:",type,name);
|
||||
continue;
|
||||
}
|
||||
}else{
|
||||
sql2 = "VACUUM";
|
||||
doBreak = true;
|
||||
sqlDrop.push("VACUUM");
|
||||
break;
|
||||
}
|
||||
wasm.setPtrValue(ppStmt, 0);
|
||||
warn(db.id,':',sql2);
|
||||
rc = capi.sqlite3_prepare_v2(db.handle, sql2, -1, ppStmt, null);
|
||||
checkSqliteRc(db.handle,rc);
|
||||
pStmt = wasm.getPtrValue(ppStmt);
|
||||
capi.sqlite3_step(pStmt);
|
||||
capi.sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
}
|
||||
}
|
||||
if(sqlDrop.length){
|
||||
const sqlClean = sqlDrop.join(';\n');
|
||||
console.log("Cleaning up",db.id,":",sqlClean);
|
||||
capi.sqlite3_exec(db.handle, sqlClean, 0, 0, 0);
|
||||
}
|
||||
}finally{
|
||||
if(pStmt) capi.sqlite3_finalize(pStmt);
|
||||
wasm.scopedAllocPop(scope);
|
||||
|
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C More\swork\son\sbatch-runner.html/js\sto\sfacilitate\sspeed\scomparisons\sbetween\svarious\sVFSes\sand\sWebSQL.
|
||||
D 2022-09-28T17:52:52.224
|
||||
C Wasm:\sexpose\ssqlite3_exec()\sand\suse\sit\sto\ssimplify\sthe\sdb-reset\slogic\sin\sbatch-runner.js\sa\sbit.
|
||||
D 2022-09-28T18:10:50.148
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -485,12 +485,12 @@ F ext/wasm/api/sqlite3-api-cleanup.js 4bd28e61216690b12d6f77bfce71b011995c294963
|
||||
F ext/wasm/api/sqlite3-api-glue.js 3b164f0ef690a838da8613a2aaec4fc49d29ad5e8fe39c8cdc0f5281f08f9d0b
|
||||
F ext/wasm/api/sqlite3-api-oo1.js 97a786b366fcac442e1557c3eedef3afa96877411bd6239094d4db5fd5b3c353
|
||||
F ext/wasm/api/sqlite3-api-opfs.js af65e056b9f5bc6182499f7e7767e3d01abc3772a62c8abbcc04e4c7bb0affc6
|
||||
F ext/wasm/api/sqlite3-api-prologue.js 2a0dedb8127e8983d3199edea55151a45186b462646cb1f2206587ac1ef4eddf
|
||||
F ext/wasm/api/sqlite3-api-prologue.js ed850804d5cd7a976717e524d719b1f9743405226a879a5170f259dbee31d13c
|
||||
F ext/wasm/api/sqlite3-api-worker1.js d5d5b7fac4c4731c38c7e03f4f404b2a95c388a2a1d8bcf361caada572f107e0
|
||||
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
|
||||
F ext/wasm/api/sqlite3-wasm.c b756b9c1fee9d0598f715e6df6bf089b750da24aa91bb7ef9277a037d81e7612
|
||||
F ext/wasm/batch-runner.html c363032aba7a525920f61f8be112a29459f73f07e46f0ba3b7730081a617826e
|
||||
F ext/wasm/batch-runner.js 756528ff41c0a2d81607fe82d088f305c379279cc84661c9422a7993b3ac544d
|
||||
F ext/wasm/batch-runner.js 0d5517be51290098bf4a92754e25c552b7c1dc73bb3f2e2b18f16b1008df060f
|
||||
F ext/wasm/common/SqliteTestUtil.js c997c12188c97109f344701a58dd627b9c0f98f32cc6a88413f6171f2191531c
|
||||
F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
|
||||
F ext/wasm/common/testing.css 3a5143699c2b73a85b962271e1a9b3241b30d90e30d895e4f55665e648572962
|
||||
@ -2026,8 +2026,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P bbfcfba260f39a9c91e82d87e06b1c2cb297c03498b4530aa3e7e01ef9916012
|
||||
R 0e9f94b500e19b6ceb4224cc315ebb8b
|
||||
P 3bd1bc240676e56da87fc49f3c67a1edc4fafcf2a2416298d19ae4f80b676a72
|
||||
R d0708515df8e5293032059e504723b7d
|
||||
U stephan
|
||||
Z cfbdefed825643b9f5c5b839e4caa73f
|
||||
Z 774d17030f6b3ac9dea357109e6b49c9
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
3bd1bc240676e56da87fc49f3c67a1edc4fafcf2a2416298d19ae4f80b676a72
|
||||
2e2821f782511b9d2274a89a5a922582aba18c7e9dc7ce01080e713942a56d7d
|
Reference in New Issue
Block a user