/ Check-in [4fb66d65]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Clarification of code comments in expr.c. Clean up the implementations of sqlite3ExprIsVector() and sqlite3ExprVectorSize() slightly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rowvalue
Files: files | file ages | folders
SHA1: 4fb66d6592b141a4a71359250dbd1ac454569cb9
User & Date: drh 2016-08-20 21:02:38
Context
2016-08-20
21:11
Further comment enhancements. No changes to code. check-in: d4562a9e user: drh tags: rowvalue
21:02
Clarification of code comments in expr.c. Clean up the implementations of sqlite3ExprIsVector() and sqlite3ExprVectorSize() slightly. check-in: 4fb66d65 user: drh tags: rowvalue
18:06
Fixes for problems following OOM errors. check-in: 9041ee4a user: drh tags: rowvalue
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

   309    309     return addr;
   310    310   }
   311    311   
   312    312   /*
   313    313   ** Return true if expression pExpr is a vector, or false otherwise.
   314    314   */
   315    315   int sqlite3ExprIsVector(Expr *pExpr){
   316         -  return ( (pExpr->op==TK_VECTOR)
   317         -        || (pExpr->op==TK_SELECT && pExpr->x.pSelect->pEList->nExpr>1)
   318         -  );
          316  +  return sqlite3ExprVectorSize(pExpr)>1;
   319    317   }
   320    318   
   321    319   /*
   322    320   ** If the expression passed as the only argument is of type TK_VECTOR 
   323    321   ** return the number of expressions in the vector. Or, if the expression
   324    322   ** is a sub-select, return the number of columns in the sub-select. For
   325    323   ** any other type of expression, return 1.
   326    324   */
   327    325   int sqlite3ExprVectorSize(Expr *pExpr){
   328         -  if( sqlite3ExprIsVector(pExpr)==0 ) return 1;
   329         -  if( pExpr->flags & EP_xIsSelect ){
          326  +  if( pExpr->op==TK_VECTOR ){
          327  +    return pExpr->x.pList->nExpr;
          328  +  }else if( pExpr->op==TK_SELECT ){
   330    329       return pExpr->x.pSelect->pEList->nExpr;
          330  +  }else{
          331  +    return 1;
   331    332     }
   332         -  return pExpr->x.pList->nExpr;
   333    333   }
   334    334   
   335    335   #ifndef SQLITE_OMIT_SUBQUERY
   336    336   /*
   337         -** Interpret the pVector input as a vector expression.  If pVector is
   338         -** an ordinary scalar expression, treat it as a vector of size 1.
   339         -**
   340    337   ** Return a pointer to a subexpression of pVector that is the i-th
   341    338   ** column of the vector (numbered starting with 0).  The caller must
   342    339   ** ensure that i is within range.
   343    340   **
          341  +** If pVector is really a scalar (and "scalar" here includes subqueries
          342  +** that return a single column!) then return pVector unmodified.
          343  +**
   344    344   ** pVector retains ownership of the returned subexpression.
   345    345   **
   346    346   ** If the vector is a (SELECT ...) then the expression returned is
   347         -** just the expression for the i-th term of the result set, and is
   348         -** necessarily ready to be evaluated because the table cursor might
   349         -** not have been positioned yet.
          347  +** just the expression for the i-th term of the result set, and may
          348  +** not be ready for evaluation because the table cursor has not yet
          349  +** been positioned.
   350    350   */
   351    351   Expr *sqlite3VectorFieldSubexpr(Expr *pVector, int i){
   352    352     assert( i<sqlite3ExprVectorSize(pVector) );
   353    353     if( sqlite3ExprIsVector(pVector) ){
   354    354       if( pVector->op==TK_SELECT ){
   355    355         return pVector->x.pSelect->pEList->a[i].pExpr;
   356    356       }else{
................................................................................
   370    370   ** It is ok for pVector to be a scalar (as long as iField==0).  
   371    371   ** In that case, this routine works like sqlite3ExprDup().
   372    372   **
   373    373   ** The caller owns the returned Expr object and is responsible for
   374    374   ** ensuring that the returned value eventually gets freed.
   375    375   **
   376    376   ** The caller retains ownership of pVector.  If pVector is a TK_SELECT,
   377         -** then the return value will reference pVector and so pVector must remain
          377  +** then the returne object will reference pVector and so pVector must remain
   378    378   ** valid for the life of the returned object.  If pVector is a TK_VECTOR
   379    379   ** or a scalar expression, then it can be deleted as soon as this routine
   380         -** routines.
          380  +** returns.
   381    381   **
   382    382   ** A trick to cause a TK_SELECT pVector to be deleted together with
   383    383   ** the returned Expr object is to attach the pVector to the pRight field
   384    384   ** of the returned TK_SELECT_COLUMN Expr object.
   385    385   */
   386    386   Expr *sqlite3ExprForVectorField(
   387    387     Parse *pParse,       /* Parsing context */