diff options
author | stephan <stephan@noemail.net> | 2022-12-14 08:01:34 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-12-14 08:01:34 +0000 |
commit | b943df9323d809ee84a595d9b18813677209c119 (patch) | |
tree | c15e460ebe904b2a3c9d8debac315df91c74ff42 /ext/wasm/api/sqlite3-api-oo1.js | |
parent | 5d75eb3fbf69ad9b95418245860638c022eda21d (diff) | |
download | sqlite-b943df9323d809ee84a595d9b18813677209c119.tar.gz sqlite-b943df9323d809ee84a595d9b18813677209c119.zip |
A micro-optimization in sqlite3.oo1.DB.exec(). Changed the rowMode option of that method to only accept $X instead of $X, @X, and :X, as the extra options are entirely superfluous and may lead to confusion.
FossilOrigin-Name: 82a6c7fdf59729c182545b15c084b136e34513f340e87a7b6e5aa199117357b0
Diffstat (limited to 'ext/wasm/api/sqlite3-api-oo1.js')
-rw-r--r-- | ext/wasm/api/sqlite3-api-oo1.js | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/ext/wasm/api/sqlite3-api-oo1.js b/ext/wasm/api/sqlite3-api-oo1.js index d4191cf3f..adfcca4d9 100644 --- a/ext/wasm/api/sqlite3-api-oo1.js +++ b/ext/wasm/api/sqlite3-api-oo1.js @@ -440,9 +440,12 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ out.cbArg = (stmt)=>stmt.get(opt.rowMode); break; }else if('string'===typeof opt.rowMode && opt.rowMode.length>1){ - /* "$X", ":X", and "@X" fetch column named "X" (case-sensitive!) */ - const prefix = opt.rowMode[0]; - if(':'===prefix || '@'===prefix || '$'===prefix){ + /* "$X": fetch column named "X" (case-sensitive!). Prior + to 2022-12-14 ":X" and "@X" were also permitted, but + that seems unnecessary and likely to cause + confusion. $ is the clear usability winner because it + doesn't require quoting in JS. */ + if('$'===opt.rowMode[0]){ out.cbArg = function(stmt){ const rc = stmt.get(this.obj)[this.colName]; return (undefined===rc) ? toss3("exec(): unknown result column:",this.colName) : rc; @@ -740,17 +743,15 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ row. Only that one single value will be passed on. C) A string with a minimum length of 2 and leading character of - ':', '$', or '@' will fetch the row as an object, extract that - one field, and pass that field's value to the callback. Note - that these keys are case-sensitive so must match the case used - in the SQL. e.g. `"select a A from t"` with a `rowMode` of - `'$A'` would work but `'$a'` would not. A reference to a column - not in the result set will trigger an exception on the first - row (as the check is not performed until rows are fetched). - Note also that `$` is a legal identifier character in JS so - need not be quoted. (Design note: those 3 characters were - chosen because they are the characters support for naming bound - parameters.) + '$' will fetch the row as an object, extract that one field, + and pass that field's value to the callback. Note that these + keys are case-sensitive so must match the case used in the + SQL. e.g. `"select a A from t"` with a `rowMode` of `'$A'` + would work but `'$a'` would not. A reference to a column not in + the result set will trigger an exception on the first row (as + the check is not performed until rows are fetched). Note also + that `$` is a legal identifier character in JS so need not be + quoted. Any other `rowMode` value triggers an exception. @@ -801,6 +802,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ let bind = opt.bind; let evalFirstResult = !!(arg.cbArg || opt.columnNames) /* true to evaluate the first result-returning query */; const stack = wasm.scopedAllocPush(); + const saveSql = Array.isArray(opt.saveSql) ? opt.saveSql : undefined; try{ const isTA = util.isSQLableTypedArray(arg.sql) /* Optimization: if the SQL is a TypedArray we can save some string @@ -834,9 +836,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ pSql = wasm.peekPtr(pzTail); sqlByteLen = pSqlEnd - pSql; if(!pStmt) continue; - if(Array.isArray(opt.saveSql)){ - opt.saveSql.push(capi.sqlite3_sql(pStmt).trim()); - } + if(saveSql) saveSql.push(capi.sqlite3_sql(pStmt).trim()); stmt = new Stmt(this, pStmt, BindTypes); if(bind && stmt.parameterCount){ stmt.bind(bind); |