/ Check-in [3de17963]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Simplify the parser reduction code for the LIMIT clause on an UPDATE or DELETE. (CVS 5792)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3de179630e812396ec29e77f7a06758472d0802f
User & Date: drh 2008-10-10 14:27:17
Context
2008-10-10
17:26
Documentation updates. No changes to code. (CVS 5793) check-in: 07b5f703 user: drh tags: trunk
14:27
Simplify the parser reduction code for the LIMIT clause on an UPDATE or DELETE. (CVS 5792) check-in: 3de17963 user: drh tags: trunk
13:35
Re-factored memory allocation failure handling in the sqlite3LimitWhere() function based on failures in the mallocJ.test script. (CVS 5791) check-in: 43507bbe user: shane tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.256 2008/10/10 04:34:16 shane Exp $
           17  +** @(#) $Id: parse.y,v 1.257 2008/10/10 14:27:17 drh Exp $
    18     18   */
    19     19   
    20     20   // All token codes are small integers with #defines that begin with "TK_"
    21     21   %token_prefix TK_
    22     22   
    23     23   // The type of the data attached to each token is Token.  This is also the
    24     24   // default type for non-terminals.
................................................................................
   575    575                                          {A.pLimit = X; A.pOffset = Y;}
   576    576   limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). 
   577    577                                          {A.pOffset = X; A.pLimit = Y;}
   578    578   
   579    579   /////////////////////////// The DELETE statement /////////////////////////////
   580    580   //
   581    581   %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   582         -cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W) orderby_opt(O) limit_opt(L). {
          582  +cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W) 
          583  +        orderby_opt(O) limit_opt(L). {
   583    584     sqlite3SrcListIndexedBy(pParse, X, &I);
   584    585     if( O && !L.pLimit ){
   585    586       sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on DELETE");
   586    587       pParse->parseError = 1;
   587         -  } else if (L.pLimit) {
   588         -    Expr *LW = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset);
   589         -    if( LW ) {
   590         -      sqlite3DeleteFrom(pParse,X,LW);
   591         -    }
   592         -  } else {
          588  +  }else{
          589  +    W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset);
   593    590       sqlite3DeleteFrom(pParse,X,W);
   594    591     }
   595    592   }
   596    593   %endif
   597    594   %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   598    595   cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
   599    596     sqlite3SrcListIndexedBy(pParse, X, &I);
................................................................................
   612    609   %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   613    610   cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W) orderby_opt(O) limit_opt(L).  {
   614    611     sqlite3SrcListIndexedBy(pParse, X, &I);
   615    612     sqlite3ExprListCheckLength(pParse,Y,"set list"); 
   616    613     if( O && !L.pLimit ){
   617    614       sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on UPDATE");
   618    615       pParse->parseError = 1;
   619         -  } else if (L.pLimit) {
   620         -    Expr *LW = sqlite3LimitWhere(pParse, X, W, O, L.pLimit,L.pOffset);
   621         -    if( LW ) {
   622         -      sqlite3Update(pParse,X,Y,LW,R);
   623         -    }
   624         -  } else {
          616  +  }else{
          617  +    W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit,L.pOffset);
   625    618       sqlite3Update(pParse,X,Y,W,R);
   626    619     }
   627    620   }
   628    621   %endif
   629    622   %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   630    623   cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W).  {
   631    624     sqlite3SrcListIndexedBy(pParse, X, &I);