wasm/JS: minor doc updates, corrected bind()ing of the undefined value to behave as documented, removed some superfluous code.

FossilOrigin-Name: 526c8c728019b317624a93f6f07840ca524bca84e7c03ce5e86e38953146236f
This commit is contained in:
stephan 2022-05-24 01:15:21 +00:00
parent 64f0e9376b
commit 2f6a729d55
4 changed files with 37 additions and 33 deletions

View File

@ -605,10 +605,11 @@
- .arity: the number of arguments which SQL calls to this
function expect or require. The default value is the
callback's length property. A value of -1 means that the
function is variadic and may accept any number of
arguments, up to sqlite3's compile-time limits. sqlite3
will enforce the argument count if is zero or greater.
callback's length property (i.e. the number of declared
parameters it has). A value of -1 means that the function
is variadic and may accept any number of arguments, up to
sqlite3's compile-time limits. sqlite3 will enforce the
argument count if is zero or greater.
The following properties correspond to flags documented at:
@ -737,8 +738,8 @@
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,
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
@ -766,9 +767,10 @@
/** Returns an opaque truthy value from the BindTypes
enum if v's type is a valid bindable type, else
returns a falsy value. */
returns a falsy value. As a special case, a value of
undefined is treated as a bind type of null. */
const isSupportedBindType = function(v){
let t = BindTypes[null===v ? 'null' : typeof v];
let t = BindTypes[(null===v||undefined===v) ? 'null' : typeof v];
switch(t){
case BindTypes.boolean:
case BindTypes.null:
@ -822,14 +824,6 @@
return stmt;
};
/** If stmt._mayGet, returns stmt, else throws. */
const affirmMayGet = function(stmt){
if(!affirmStmtOpen(stmt)._mayGet){
toss("Statement.step() has not (recently) returned true.");
}
return stmt;
};
/**
If stmt._isLocked is truthy, this throws an exception
complaining that the 2nd argument (an operation name,
@ -981,8 +975,11 @@
- undefined as a standalone value is a no-op intended to
simplify certain client-side use cases: passing undefined
as a value to this function will not actually bind
anything. undefined as an array or object property when
binding an array/object is treated as null.
anything and this function will skip confirmation that
binding is even legal. (Those semantics simplify certain
client-side uses.) Conversely, a value of undefined as an
array or object property when binding an array/object
(see below) is treated the same as null.
- Numbers are bound as either doubles or integers: doubles
if they are larger than 32 bits, else double or int32,
@ -1033,7 +1030,6 @@
case 2: ndx = arguments[0]; arg = arguments[1]; break;
default: toss("Invalid bind() arguments.");
}
this._mayGet = false;
if(undefined===arg){
/* It might seem intuitive to bind undefined as NULL
but this approach simplifies certain client-side
@ -1042,7 +1038,9 @@
return this;
}else if(!this.parameterCount){
toss("This statement has no bindable parameters.");
}else if(null===arg){
}
this._mayGet = false;
if(null===arg){
/* bind NULL */
return bindOne(this, ndx, BindTypes.null, arg);
}
@ -1080,7 +1078,7 @@
If passed a single argument, a bind index of 1 is assumed.
*/
bindAsBlob: function(ndx,arg){
affirmStmtOpen(this)._mayGet = false;
affirmStmtOpen(this);
if(1===arguments.length){
ndx = 1;
arg = arguments[0];
@ -1090,6 +1088,7 @@
&& BindTypes.null !== t){
toss("Invalid value type for bindAsBlob()");
}
this._mayGet = false;
return bindOne(this, ndx, BindTypes.blob, arg);
},
/**
@ -1100,11 +1099,11 @@
step: function(){
affirmUnlocked(this, 'step()');
const rc = S.sqlite3_step(affirmStmtOpen(this)._pStmt);
this._mayGet = false;
switch(rc){
case S.SQLITE_DONE: return false;
case S.SQLITE_DONE: return this._mayGet = false;
case S.SQLITE_ROW: return this._mayGet = true;
default:
this._mayGet = false;
console.warn("sqlite3_step() rc=",rc,"SQL =",
S.sqlite3_sql(this._pStmt));
this.db.checkRc(rc);
@ -1144,7 +1143,9 @@
getJSON() can be used for that.
*/
get: function(ndx,asType){
affirmMayGet(this);
if(!affirmStmtOpen(this)._mayGet){
toss("Stmt.step() has not (recently) returned true.");
}
if(Array.isArray(ndx)){
let i = 0;
while(i<this.columnCount){

View File

@ -116,7 +116,10 @@ INSERT INTO t(a,b) VALUES(1,2),(3,4),(?,?);`,
assert(-1===db.selectValue("select bar(1,2,-4)"));
T.assert('hi' === db.selectValue("select ?",'hi')).
assert(null===db.selectValue("select null"));
assert(null===db.selectValue("select null")).
assert(null === db.selectValue("select ?",null)).
assert(null === db.selectValue("select ?",[null])).
assert(null === db.selectValue("select $a",{$a:null}));
}finally{
db.close();

View File

@ -1,5 +1,5 @@
C wasm/JS:\sdocumented\sDB.selectValue()\sand\scorrected\sthe\sfetching\sof\sNULL\scolumns\svia\sStmt.get().
D 2022-05-24T00:35:18.252
C wasm/JS:\sminor\sdoc\supdates,\scorrected\sbind()ing\sof\sthe\sundefined\svalue\sto\sbehave\sas\sdocumented,\sremoved\ssome\ssuperfluous\scode.
D 2022-05-24T01:15:21.052
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -65,10 +65,10 @@ F ext/fiddle/fiddle-worker.js e87c17070b979bd057a6849332f2a86660a4255ff7f1b6671e
F ext/fiddle/fiddle.html 657c6c3f860c322fba3c69fa4f7a1209e2d2ce44b4bc65a3e154e3a97c047a7c
F ext/fiddle/fiddle.js 68f5bb45fc1ae7f8ae3f6b85f465257db514d12bf50ec492259685178c452a88
F ext/fiddle/index.md d9c1c308d8074341bc3b11d1d39073cd77754cb3ca9aeb949f23fdd8323d81cf
F ext/fiddle/sqlite3-api.js 2a0ba8c9a0778a6ea6720c6717540732a8eb36b7605b883a716db3da9d4a2aba
F ext/fiddle/sqlite3-api.js 3f41887a66d620ae506fea4a735d909c3dc0023045265736958de6d3016fbfc9
F ext/fiddle/testing-common.js 723aada13d90a5ee3f0f8f5b5b88e46954becae5d2b04ded811d90106057f4ac
F ext/fiddle/testing1.html 026502e5d5e6a250e4101f8e8948708a1295ce831a094d741839ecaf788d8533
F ext/fiddle/testing1.js 2f9910ff46bcd31ed2779b4bd2fcf09a57805c6073da6dd56dce6cd2e95a47b9
F ext/fiddle/testing1.js b9dd06fd02fbcf947794ceb0bcca1a00e3440d80bf1d819a73bbcac25c87086e
F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e
F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b
F ext/fts1/ft_hash.h 06df7bba40dadd19597aa400a875dbc2fed705ea
@ -1968,8 +1968,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 325a9ee31ad7abae563c4da5cd8228e151b00aa9afcac7e9bca5efaa9d48e107
R ec73c1d66717375855af09a51e0d10ff
P 70f91fab825d365f505750acdb8d3ae532880c4cdb64d1e61bb21b24a115958b
R aa6cc8d5c8c48a5dcba3187d74399b46
U stephan
Z 005deadcf1ed546088d3a014fe907d3d
Z 0033b446f56e6779d5a11407c4e1444a
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
70f91fab825d365f505750acdb8d3ae532880c4cdb64d1e61bb21b24a115958b
526c8c728019b317624a93f6f07840ca524bca84e7c03ce5e86e38953146236f