/ Check-in [3de17963]
Login

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 Unified Diffs Show Whitespace Changes Patch

Changes to src/parse.y.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
575
576
577
578
579
580
581
582

583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
...
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
**
*************************************************************************
** This file contains SQLite's grammar for SQL.  Process this file
** using the lemon parser generator to generate C code that runs
** the parser.  Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.256 2008/10/10 04:34:16 shane Exp $
*/

// All token codes are small integers with #defines that begin with "TK_"
%token_prefix TK_

// The type of the data attached to each token is Token.  This is also the
// default type for non-terminals.
................................................................................
                                       {A.pLimit = X; A.pOffset = Y;}
limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). 
                                       {A.pOffset = X; A.pLimit = Y;}

/////////////////////////// The DELETE statement /////////////////////////////
//
%ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W) orderby_opt(O) limit_opt(L). {

  sqlite3SrcListIndexedBy(pParse, X, &I);
  if( O && !L.pLimit ){
    sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on DELETE");
    pParse->parseError = 1;
  } else if (L.pLimit) {
    Expr *LW = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset);
    if( LW ) {
      sqlite3DeleteFrom(pParse,X,LW);
    }
  } else {
    sqlite3DeleteFrom(pParse,X,W);
  }
}
%endif
%ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
  sqlite3SrcListIndexedBy(pParse, X, &I);
................................................................................
%ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W) orderby_opt(O) limit_opt(L).  {
  sqlite3SrcListIndexedBy(pParse, X, &I);
  sqlite3ExprListCheckLength(pParse,Y,"set list"); 
  if( O && !L.pLimit ){
    sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on UPDATE");
    pParse->parseError = 1;
  } else if (L.pLimit) {
    Expr *LW = sqlite3LimitWhere(pParse, X, W, O, L.pLimit,L.pOffset);
    if( LW ) {
      sqlite3Update(pParse,X,Y,LW,R);
    }
  } else {
    sqlite3Update(pParse,X,Y,W,R);
  }
}
%endif
%ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W).  {
  sqlite3SrcListIndexedBy(pParse, X, &I);







|







 







|
>




|
|
<
<
<
<







 







|
|
<
<
<
<







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589




590
591
592
593
594
595
596
...
609
610
611
612
613
614
615
616
617




618
619
620
621
622
623
624
**
*************************************************************************
** This file contains SQLite's grammar for SQL.  Process this file
** using the lemon parser generator to generate C code that runs
** the parser.  Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.257 2008/10/10 14:27:17 drh Exp $
*/

// All token codes are small integers with #defines that begin with "TK_"
%token_prefix TK_

// The type of the data attached to each token is Token.  This is also the
// default type for non-terminals.
................................................................................
                                       {A.pLimit = X; A.pOffset = Y;}
limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). 
                                       {A.pOffset = X; A.pLimit = Y;}

/////////////////////////// The DELETE statement /////////////////////////////
//
%ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W) 
        orderby_opt(O) limit_opt(L). {
  sqlite3SrcListIndexedBy(pParse, X, &I);
  if( O && !L.pLimit ){
    sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on DELETE");
    pParse->parseError = 1;
  }else{
    W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset);




    sqlite3DeleteFrom(pParse,X,W);
  }
}
%endif
%ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
  sqlite3SrcListIndexedBy(pParse, X, &I);
................................................................................
%ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W) orderby_opt(O) limit_opt(L).  {
  sqlite3SrcListIndexedBy(pParse, X, &I);
  sqlite3ExprListCheckLength(pParse,Y,"set list"); 
  if( O && !L.pLimit ){
    sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on UPDATE");
    pParse->parseError = 1;
  }else{
    W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit,L.pOffset);




    sqlite3Update(pParse,X,Y,W,R);
  }
}
%endif
%ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W).  {
  sqlite3SrcListIndexedBy(pParse, X, &I);