1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

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
This commit is contained in:
stephan
2022-12-14 08:01:34 +00:00
parent 5d75eb3fbf
commit b943df9323
3 changed files with 25 additions and 25 deletions

View File

@ -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);