/ Check-in [02204f8b]
Login

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

Overview
Comment:Improvements to the parser to increase coverage. Fix the parser so that at least one expresssion is required after PARTITION BY and within the list of expressions on VALUES().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 02204f8b246c868846f39bd44f2e3bc0fab0275aa09ef3a0e5a8e3d58f484ca8
User & Date: drh 2018-07-27 23:33:16
Context
2018-07-28
14:34
Improved debugging output when the ".selecttrace" option is used in the shell. check-in: fcb88dd6 user: drh tags: trunk
01:30
Add assert() statements to sqlite3ExprDelete() that prove various symmetry properties of the Expr object that might be exploited to make the Expr object smaller and faster. check-in: 81f25d5c user: drh tags: expr-simplify
2018-07-27
23:33
Improvements to the parser to increase coverage. Fix the parser so that at least one expresssion is required after PARTITION BY and within the list of expressions on VALUES(). check-in: 02204f8b user: drh tags: trunk
22:55
When doing a DROP VIEW do not try to delete entries from the sqlite_stat1 table as there are none. check-in: 7efdba2b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

   937    937     }
   938    938   }
   939    939   
   940    940   /*
   941    941   ** Construct a new expression node for a function with multiple
   942    942   ** arguments.
   943    943   */
   944         -Expr *sqlite3ExprFunction(Parse *pParse, ExprList *pList, Token *pToken){
          944  +Expr *sqlite3ExprFunction(
          945  +  Parse *pParse,        /* Parsing context */
          946  +  ExprList *pList,      /* Argument list */
          947  +  Token *pToken,        /* Name of the function */
          948  +  int eDistinct         /* SF_Distinct or SF_ALL or 0 */
          949  +){
   945    950     Expr *pNew;
   946    951     sqlite3 *db = pParse->db;
   947    952     assert( pToken );
   948    953     pNew = sqlite3ExprAlloc(db, TK_FUNCTION, pToken, 1);
   949    954     if( pNew==0 ){
   950    955       sqlite3ExprListDelete(db, pList); /* Avoid memory leak when malloc fails */
   951    956       return 0;
   952    957     }
          958  +  if( pList && pList->nExpr > pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
          959  +    sqlite3ErrorMsg(pParse, "too many arguments on function %T", pToken);
          960  +  }
   953    961     pNew->x.pList = pList;
   954    962     ExprSetProperty(pNew, EP_HasFunc);
   955    963     assert( !ExprHasProperty(pNew, EP_xIsSelect) );
   956    964     sqlite3ExprSetHeightAndFlags(pParse, pNew);
          965  +  if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct);
   957    966     return pNew;
   958    967   }
   959    968   
   960    969   /*
   961    970   ** Assign a variable number to an expression that encodes a wildcard
   962    971   ** in the original SQL statement.  
   963    972   **

Changes to src/parse.y.

   554    554   oneselect(A) ::= values(A).
   555    555   
   556    556   %type values {Select*}
   557    557   %destructor values {sqlite3SelectDelete(pParse->db, $$);}
   558    558   values(A) ::= VALUES LP nexprlist(X) RP. {
   559    559     A = sqlite3SelectNew(pParse,X,0,0,0,0,0,SF_Values,0);
   560    560   }
   561         -values(A) ::= values(A) COMMA LP exprlist(Y) RP. {
          561  +values(A) ::= values(A) COMMA LP nexprlist(Y) RP. {
   562    562     Select *pRight, *pLeft = A;
   563    563     pRight = sqlite3SelectNew(pParse,Y,0,0,0,0,0,SF_Values|SF_MultiValue,0);
   564    564     if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
   565    565     if( pRight ){
   566    566       pRight->op = TK_ALL;
   567    567       pRight->pPrior = pLeft;
   568    568       A = pRight;
................................................................................
   997    997     A = sqlite3ExprAlloc(pParse->db, TK_CAST, &T, 1);
   998    998     sqlite3ExprAttachSubtrees(pParse->db, A, E, 0);
   999    999   }
  1000   1000   %endif  SQLITE_OMIT_CAST
  1001   1001   
  1002   1002   
  1003   1003   expr(A) ::= id(X) LP distinct(D) exprlist(Y) RP. {
  1004         -  if( Y && Y->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
  1005         -    sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X);
  1006         -  }
  1007         -  A = sqlite3ExprFunction(pParse, Y, &X);
  1008         -  if( D==SF_Distinct && A ){
  1009         -    A->flags |= EP_Distinct;
  1010         -  }
         1004  +  A = sqlite3ExprFunction(pParse, Y, &X, D);
  1011   1005   }
  1012   1006   expr(A) ::= id(X) LP STAR RP. {
  1013         -  A = sqlite3ExprFunction(pParse, 0, &X);
         1007  +  A = sqlite3ExprFunction(pParse, 0, &X, 0);
  1014   1008   }
  1015   1009   
  1016   1010   %ifndef SQLITE_OMIT_WINDOWFUNC
  1017   1011   expr(A) ::= id(X) LP distinct(D) exprlist(Y) RP over_clause(Z). {
  1018         -  if( Y && Y->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
  1019         -    sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X);
  1020         -  }
  1021         -  A = sqlite3ExprFunction(pParse, Y, &X);
  1022         -  if( D==SF_Distinct && A ){
  1023         -    A->flags |= EP_Distinct;
  1024         -  }
         1012  +  A = sqlite3ExprFunction(pParse, Y, &X, D);
  1025   1013     sqlite3WindowAttach(pParse, A, Z);
  1026   1014   }
  1027   1015   expr(A) ::= id(X) LP STAR RP over_clause(Z). {
  1028         -  A = sqlite3ExprFunction(pParse, 0, &X);
         1016  +  A = sqlite3ExprFunction(pParse, 0, &X, 0);
  1029   1017     sqlite3WindowAttach(pParse, A, Z);
  1030   1018   }
  1031   1019   %endif
  1032   1020   
  1033   1021   term(A) ::= CTIME_KW(OP). {
  1034         -  A = sqlite3ExprFunction(pParse, 0, &OP);
         1022  +  A = sqlite3ExprFunction(pParse, 0, &OP, 0);
  1035   1023   }
  1036   1024   
  1037   1025   expr(A) ::= LP nexprlist(X) COMMA expr(Y) RP. {
  1038   1026     ExprList *pList = sqlite3ExprListAppend(pParse, X, Y);
  1039   1027     A = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
  1040   1028     if( A ){
  1041   1029       A->x.pList = pList;
................................................................................
  1061   1049   likeop(A) ::= NOT LIKE_KW|MATCH(X). {A=X; A.n|=0x80000000; /*A-overwrite-X*/}
  1062   1050   expr(A) ::= expr(A) likeop(OP) expr(Y).  [LIKE_KW]  {
  1063   1051     ExprList *pList;
  1064   1052     int bNot = OP.n & 0x80000000;
  1065   1053     OP.n &= 0x7fffffff;
  1066   1054     pList = sqlite3ExprListAppend(pParse,0, Y);
  1067   1055     pList = sqlite3ExprListAppend(pParse,pList, A);
  1068         -  A = sqlite3ExprFunction(pParse, pList, &OP);
         1056  +  A = sqlite3ExprFunction(pParse, pList, &OP, 0);
  1069   1057     if( bNot ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
  1070   1058     if( A ) A->flags |= EP_InfixFunc;
  1071   1059   }
  1072   1060   expr(A) ::= expr(A) likeop(OP) expr(Y) ESCAPE expr(E).  [LIKE_KW]  {
  1073   1061     ExprList *pList;
  1074   1062     int bNot = OP.n & 0x80000000;
  1075   1063     OP.n &= 0x7fffffff;
  1076   1064     pList = sqlite3ExprListAppend(pParse,0, Y);
  1077   1065     pList = sqlite3ExprListAppend(pParse,pList, A);
  1078   1066     pList = sqlite3ExprListAppend(pParse,pList, E);
  1079         -  A = sqlite3ExprFunction(pParse, pList, &OP);
         1067  +  A = sqlite3ExprFunction(pParse, pList, &OP, 0);
  1080   1068     if( bNot ) A = sqlite3PExpr(pParse, TK_NOT, A, 0);
  1081   1069     if( A ) A->flags |= EP_InfixFunc;
  1082   1070   }
  1083   1071   
  1084   1072   expr(A) ::= expr(A) ISNULL|NOTNULL(E).   {A = sqlite3PExpr(pParse,@E,A,0);}
  1085   1073   expr(A) ::= expr(A) NOT NULL.    {A = sqlite3PExpr(pParse,TK_NOTNULL,A,0);}
  1086   1074   
................................................................................
  1636   1624     A = Z;
  1637   1625     if( ALWAYS(A) ){
  1638   1626       A->pPartition = X;
  1639   1627       A->pOrderBy = Y;
  1640   1628     }
  1641   1629   }
  1642   1630   
  1643         -part_opt(A) ::= PARTITION BY exprlist(X). { A = X; }
  1644         -part_opt(A) ::= .                         { A = 0; }
         1631  +part_opt(A) ::= PARTITION BY nexprlist(X). { A = X; }
         1632  +part_opt(A) ::= .                          { A = 0; }
  1645   1633   
  1646   1634   frame_opt(A) ::= .                             { 
  1647   1635     A = sqlite3WindowAlloc(pParse, TK_RANGE, TK_UNBOUNDED, 0, TK_CURRENT, 0);
  1648   1636   }
  1649   1637   frame_opt(A) ::= range_or_rows(X) frame_bound_s(Y). { 
  1650   1638     A = sqlite3WindowAlloc(pParse, X, Y.eType, Y.pExpr, TK_CURRENT, 0);
  1651   1639   }

Changes to src/sqliteInt.h.

  3788   3788   #endif
  3789   3789   Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
  3790   3790   Expr *sqlite3Expr(sqlite3*,int,const char*);
  3791   3791   void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
  3792   3792   Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
  3793   3793   void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
  3794   3794   Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  3795         -Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
         3795  +Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
  3796   3796   void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
  3797   3797   void sqlite3ExprDelete(sqlite3*, Expr*);
  3798   3798   ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
  3799   3799   ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
  3800   3800   void sqlite3ExprListSetSortOrder(ExprList*,int);
  3801   3801   void sqlite3ExprListSetName(Parse*,ExprList*,Token*,int);
  3802   3802   void sqlite3ExprListSetSpan(Parse*,ExprList*,const char*,const char*);

Changes to src/window.c.

   955    955   }
   956    956   
   957    957   /*
   958    958   ** Attach window object pWin to expression p.
   959    959   */
   960    960   void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){
   961    961     if( p ){
   962         -    if( pWin ){
          962  +    /* This routine is only called for the parser.  If pWin was not
          963  +    ** allocated due to an OOM, then the parser would fail before ever
          964  +    ** invoking this routine */
          965  +    if( ALWAYS(pWin) ){
   963    966         p->pWin = pWin;
   964    967         pWin->pOwner = p;
   965    968         if( p->flags & EP_Distinct ){
   966    969           sqlite3ErrorMsg(pParse,
   967    970              "DISTINCT is not supported for window functions");
   968    971         }
   969    972       }