diff options
author | stephan <stephan@noemail.net> | 2022-09-28 18:10:50 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-09-28 18:10:50 +0000 |
commit | 4b884bb4c77cb4b1e5059395212160f4ee48cc53 (patch) | |
tree | 82de05edb422ecf129db61e6968649f26df95863 /ext/wasm/batch-runner.js | |
parent | cb22bd80d28750425101ad1f591aea045f762341 (diff) | |
download | sqlite-4b884bb4c77cb4b1e5059395212160f4ee48cc53.tar.gz sqlite-4b884bb4c77cb4b1e5059395212160f4ee48cc53.zip |
Wasm: expose sqlite3_exec() and use it to simplify the db-reset logic in batch-runner.js a bit.
FossilOrigin-Name: 2e2821f782511b9d2274a89a5a922582aba18c7e9dc7ce01080e713942a56d7d
Diffstat (limited to 'ext/wasm/batch-runner.js')
-rw-r--r-- | ext/wasm/batch-runner.js | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/ext/wasm/batch-runner.js b/ext/wasm/batch-runner.js index 26a7cbbba..3762998b6 100644 --- a/ext/wasm/batch-runner.js +++ b/ext/wasm/batch-runner.js @@ -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); |