aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/testing1.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-09-30 20:35:37 +0000
committerstephan <stephan@noemail.net>2022-09-30 20:35:37 +0000
commite67a0f40e419f4945d8157cb047ae302bf1f2852 (patch)
treea31e7863c9e6867e74ce53be5545eef1e5e02c9a /ext/wasm/testing1.js
parentd18f1bbfe06e40713de908cd894d9857f6c11606 (diff)
downloadsqlite-e67a0f40e419f4945d8157cb047ae302bf1f2852.tar.gz
sqlite-e67a0f40e419f4945d8157cb047ae302bf1f2852.zip
Add JS wrapper for sqlite3_exec() which knows how to handle a JS callback. Add some console.error() reporting of module-load failures, as they otherwise often get silently swallowed up by the loader's mechanisms. Add 'flexible-string' JS-to-WASM argument converter which performs more X-to-string conversions than the 'string' arg converter does.
FossilOrigin-Name: 96818aa83f4ccc574f558231249ecbdd39763b4351cf4cf6d33f53774a3ee5e6
Diffstat (limited to 'ext/wasm/testing1.js')
-rw-r--r--ext/wasm/testing1.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/ext/wasm/testing1.js b/ext/wasm/testing1.js
index 5b3d6189d..916f81bab 100644
--- a/ext/wasm/testing1.js
+++ b/ext/wasm/testing1.js
@@ -186,7 +186,7 @@
// Custom db error message handling via sqlite3_prepare_v2/v3()
if(capi.wasm.exports.sqlite3_wasm_db_error){
log("Testing custom error message via prepare_v3()...");
- let rc = capi.sqlite3_prepare_v3(db.pointer, [/*invalid*/], -1, 0, null, null);
+ let rc = capi.sqlite3_prepare_v3(db.pointer, {/*invalid*/}, -1, 0, null, null);
T.assert(capi.SQLITE_MISUSE === rc)
.assert(0 === capi.sqlite3_errmsg(db.pointer).indexOf("Invalid SQL"));
log("errmsg =",capi.sqlite3_errmsg(db.pointer));
@@ -253,7 +253,7 @@
const resultRows = [];
db.exec({
sql:new TextEncoder('utf-8').encode([
- // ^^^ testing string-vs-typedarray handling in execMulti()
+ // ^^^ testing string-vs-typedarray handling in exec()
"attach 'session' as foo;" /* name 'session' is magic for kvvfs! */,
"create table foo.bar(a);",
"insert into foo.bar(a) values(1),(2),(3);",
@@ -266,6 +266,26 @@
T.assert(3===resultRows.length)
.assert(2===resultRows[1]);
T.assert(2===db.selectValue('select a from foo.bar where a>1 order by a'));
+ let colCount = 0, rowCount = 0;
+ const execCallback = function(pVoid, nCols, aVals, aNames){
+ colCount = nCols;
+ ++rowCount;
+ T.assert(2===aVals.length)
+ .assert(2===aNames.length)
+ .assert(+(aVals[1]) === 2 * +(aVals[0]));
+ };
+ const capi = sqlite3.capi;
+ let rc = capi.sqlite3_exec(
+ db.pointer, "select a, a*2 from foo.bar", execCallback,
+ 0, 0
+ );
+ T.assert(0===rc).assert(3===rowCount).assert(2===colCount);
+ rc = capi.sqlite3_exec(
+ db.pointer, "select a from foo.bar", ()=>{
+ toss("Testing throwing from exec() callback.");
+ }, 0, 0
+ );
+ T.assert(capi.SQLITE_ABORT === rc);
db.exec("detach foo");
T.mustThrow(()=>db.exec("select * from foo.bar"));
};