diff options
author | stephan <stephan@noemail.net> | 2022-05-24 00:35:18 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-05-24 00:35:18 +0000 |
commit | 64f0e9376b9dcd2cb0f930a1bb4d62c3ce16f2ab (patch) | |
tree | a57d8a8dc1fcdb2bccccce8a8e81c8c2bd356595 /ext/fiddle/sqlite3-api.js | |
parent | a240a24ad0b9d0e2023c5e77bcc4fc277db2e5cf (diff) | |
download | sqlite-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/sqlite3-api.js')
-rw-r--r-- | ext/fiddle/sqlite3-api.js | 12 |
1 files changed, 10 insertions, 2 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 |