aboutsummaryrefslogtreecommitdiff
path: root/ext/fiddle
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-05-24 00:35:18 +0000
committerstephan <stephan@noemail.net>2022-05-24 00:35:18 +0000
commit64f0e9376b9dcd2cb0f930a1bb4d62c3ce16f2ab (patch)
treea57d8a8dc1fcdb2bccccce8a8e81c8c2bd356595 /ext/fiddle
parenta240a24ad0b9d0e2023c5e77bcc4fc277db2e5cf (diff)
downloadsqlite-64f0e9376b9dcd2cb0f930a1bb4d62c3ce16f2ab.tar.gz
sqlite-64f0e9376b9dcd2cb0f930a1bb4d62c3ce16f2ab.zip
wasm/JS: documented DB.selectValue() and corrected the fetching of NULL columns via Stmt.get().
FossilOrigin-Name: 70f91fab825d365f505750acdb8d3ae532880c4cdb64d1e61bb21b24a115958b
Diffstat (limited to 'ext/fiddle')
-rw-r--r--ext/fiddle/sqlite3-api.js12
-rw-r--r--ext/fiddle/testing1.js4
2 files changed, 13 insertions, 3 deletions
diff --git a/ext/fiddle/sqlite3-api.js b/ext/fiddle/sqlite3-api.js
index 22773d8d7..7d30634f5 100644
--- a/ext/fiddle/sqlite3-api.js
+++ b/ext/fiddle/sqlite3-api.js
@@ -736,11 +736,18 @@
this._udfs[name] = pUdf;
return this;
}/*createFunction()*/,
+ /**
+ Prepares the given SQL, step()s it one time and returns the
+ value of the first result column. If it has no results,
+ undefined is returned. If passed a second argument, it is
+ treated like an argument to Stmt.bind(), so may be any type
+ supported by that function. Throws on error (e.g. malformed
+ SQL).
+ */
selectValue: function(sql,bind){
let stmt, rc;
try {
- stmt = this.prepare(sql);
- stmt.bind(bind);
+ stmt = this.prepare(sql).bind(bind);
if(stmt.step()) rc = stmt.get(0);
}finally{
if(stmt) stmt.finalize();
@@ -1155,6 +1162,7 @@
switch(undefined===asType
? S.sqlite3_column_type(this._pStmt, ndx)
: asType){
+ case S.SQLITE_NULL: return null;
case S.SQLITE_INTEGER:{
return 0 | S.sqlite3_column_double(this._pStmt, ndx);
/* ^^^^^^^^ strips any fractional part and handles
diff --git a/ext/fiddle/testing1.js b/ext/fiddle/testing1.js
index 5e8dd662d..1c83b90e3 100644
--- a/ext/fiddle/testing1.js
+++ b/ext/fiddle/testing1.js
@@ -115,7 +115,9 @@ INSERT INTO t(a,b) VALUES(1,2),(3,4),(?,?);`,
assert(3===db.selectValue("select bar(1,2)")).
assert(-1===db.selectValue("select bar(1,2,-4)"));
- T.assert('hi' === db.selectValue("select ?",'hi'));
+ T.assert('hi' === db.selectValue("select ?",'hi')).
+ assert(null===db.selectValue("select null"));
+
}finally{
db.close();
}