]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Updated LIMIT support for DELETE/UPDATE. Omit option changed to SQLITE_ENABLE_UPDATE...
authorshane <shane@noemail.net>
Fri, 10 Oct 2008 04:34:16 +0000 (04:34 +0000)
committershane <shane@noemail.net>
Fri, 10 Oct 2008 04:34:16 +0000 (04:34 +0000)
FossilOrigin-Name: c10e8a3c7ab7f21c95f24d0aba590f5b18a4b028

manifest
manifest.uuid
src/delete.c
src/parse.y
src/resolve.c
src/sqliteInt.h
src/test_config.c

index 35afe6e95fcaf431142ad0f26dc268e63b30a604..b56f9b95a874bc32857dab5d4f94e84ab4c27562 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\san\sassert()\sfailure\sthat\scan\soccur\sif\sthe\suser\sattempts\sto\sset\san\sinto\san\sinteger\sprimary\skey\scolumn\sto\sa\stext\svalue\sin\sa\stable\sthat\shas\sa\sBEFORE\sUPDATE\strigger.\s(CVS\s5787)
-D 2008-10-09T18:48:31
+C Updated\sLIMIT\ssupport\sfor\sDELETE/UPDATE.\s\sOmit\soption\schanged\sto\sSQLITE_ENABLE_UPDATE_DELETE_LIMIT.\s(CVS\s5788)
+D 2008-10-10T04:34:16
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 7fc26e087207e7a4a7723583dbd7997477af3b13
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -106,7 +106,7 @@ F src/build.c 8714bd809583bbe07bf22d0e1808a3fc31abe330
 F src/callback.c 7a40fd44da3eb89e7f6eff30aa6f940c45d73a97
 F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
 F src/date.c 1b1fc801df40aae891bff8b03f65313df192d677
-F src/delete.c 7c9183a17b93b79dabbbc7cdb2159972d052b5a0
+F src/delete.c 24d4f58280bb0717c3eee8ff613d1b3200f101e3
 F src/expr.c 0ceafeff3a4e0f460d6a7695a675ae12391e313d
 F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
 F src/func.c 8431b40a7843d1024145684d303c55b4ee087bbe
@@ -140,19 +140,19 @@ F src/os_unix.c f33b69d8a85372b270fe37ee664a4c2140a5217d
 F src/os_win.c 04033a86a39f49cb8e348f515eb0116aa9d36678
 F src/pager.c d98f56128e849083f2f612196efebd982c491fea
 F src/pager.h 9c1917be28fff58118e1fe0ddbc7adfb8dd4f44d
-F src/parse.y 85d57c1dba3098da736a0c2ff8917c3d02a3a5f8
+F src/parse.y ecabcd6402a611a223824291b8b4e026c622c2b3
 F src/pcache.c f8d7beceba164a34441ac37e88abb3a404f968a7
 F src/pcache.h 28d9ce2d66909db1f01652586450b62b64793093
 F src/pragma.c 0b1c2d2a241dd79a7361bbeb8ff575a9e9d7cd71
 F src/prepare.c c7e00ed1b0bdcf699b1aad651247d4dc3d281b0b
 F src/printf.c 785f87120589c1db672e37c6eb1087c456e6f84d
 F src/random.c a87afbd598aa877e23ac676ee92fd8ee5c786a51
-F src/resolve.c 1971ff6996f1a73303339acf7f1de8497546045d
+F src/resolve.c d45e7b69f9ff653799384d7fcdd0c8d7096908b7
 F src/select.c d910d7350df0d918e22286c5bfd39d4ea68ec813
 F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967
 F src/sqlite.h.in f2640167eca2e9273ec5ea97b37155344290bd2a
 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
-F src/sqliteInt.h 3f38b600c978698014fdda68d29ca5f3792ad717
+F src/sqliteInt.h 0da9c664d89995d28587548048837e3063fa0be3
 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
 F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
 F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8
@@ -169,7 +169,7 @@ F src/test9.c 904ebe0ed1472d6bad17a81e2ecbfc20017dc237
 F src/test_async.c 45024094ed7cf780c5d5dccda645145f95cf78ef
 F src/test_autoext.c f53b0cdf7bf5f08100009572a5d65cdb540bd0ad
 F src/test_btree.c d7b8716544611c323860370ee364e897c861f1b0
-F src/test_config.c f995f649dc2dc8173079d613694b29b0b3b5f84b
+F src/test_config.c e5d6390729f0c63333ebe7e5927c07e50bc9deea
 F src/test_devsym.c 802d10e65b4217208cb47059b84adf46318bcdf4
 F src/test_func.c a55c4d5479ff2eb5c0a22d4d88e9528ab59c953b
 F src/test_hexio.c 2f1122aa3f012fa0142ee3c36ce5c902a70cd12f
@@ -643,7 +643,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 2d427746d53104ca032c404f7f65c51b41b7a20e
-R 7a5ac900e19ad3409dae5bcb06b20f5a
-U danielk1977
-Z 0940f286acf7bb42a4ff023aeb3c8678
+P c2cf9d60d6626844193b008a37e4417aa0a0f323
+R dbb64f376591fe1fef8fc7d76b6610d5
+U shane
+Z b0043e2235752f0517ee1d3e5441bcb7
index cd5d6e8e9fcfbaa4bac06701a662133ad0810656..5c1c844ba52e854e2f19df64de7bf2ff98a6a059 100644 (file)
@@ -1 +1 @@
-c2cf9d60d6626844193b008a37e4417aa0a0f323
\ No newline at end of file
+c10e8a3c7ab7f21c95f24d0aba590f5b18a4b028
\ No newline at end of file
index 9a414d2839d930ef1b4967e55235ff7f4567d1e3..0669e2dcd71d40de718adf552e5224efa2bd1416 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** in order to generate code for DELETE FROM statements.
 **
-** $Id: delete.c,v 1.178 2008/10/07 05:27:11 shane Exp $
+** $Id: delete.c,v 1.179 2008/10/10 04:34:16 shane Exp $
 */
 #include "sqliteInt.h"
 
@@ -116,7 +116,7 @@ void sqlite3MaterializeView(
 }
 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
 
-#ifndef SQLITE_OMIT_UPDATE_DELETE_LIMIT
+#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
 /*
 ** Generate an expression tree to implement the WHERE, ORDER BY,
 ** and LIMIT/OFFSET portion of DELETE and UPDATE statements.
@@ -133,17 +133,48 @@ Expr *sqlite3LimitWhere(
   Expr *pLimit,           /* The LIMIT clause.  May be null */
   Expr *pOffset           /* The OFFSET clause.  May be null */
 ){
-  Expr *pWhereRowid = sqlite3Expr(pParse->db, TK_ROW, 0, 0, 0);
-  Expr *pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
-  Expr *pSelectRowid = sqlite3Expr(pParse->db, TK_ROW, 0, 0, 0);
-  ExprList *pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid, 0);
-  SrcList *pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc);
-  Select *pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,pOrderBy,0,pLimit,pOffset);
-  if( pSelect ) {
-    pInClause->pSelect = pSelect;
-    sqlite3ExprSetHeight(pParse, pInClause);
-    return pInClause;
-  }
+  Expr *pWhereRowid = NULL;
+  Expr *pInClause = NULL;
+  Expr *pSelectRowid = NULL;
+  ExprList *pEList = NULL;
+  SrcList *pSelectSrc = NULL;
+  Select *pSelect = NULL;
+
+  /* We only need to generate a select expression if there
+  ** is a limit/offset term to enforce.
+  */
+  if (!pLimit && !pOffset) return pWhere;
+
+  /* Generate a select expression tree to enforce the limit/offset 
+  ** term for the DELETE or UPDATE statement.  For example:
+  **   DELETE FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
+  ** becomes:
+  **   DELETE FROM table_a WHERE rowid IN ( 
+  **     DELETE rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
+  **   );
+  */
+  pSelectRowid = sqlite3Expr(pParse->db, TK_ROW, 0, 0, 0);
+  if( pSelectRowid == 0 ) goto limit_where_cleanup;
+  pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid, 0);
+  if( pEList == 0 ) goto limit_where_cleanup;
+  /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
+  ** and the DELETE tree. */
+  pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc);
+  if( pSelectSrc == 0 ) goto limit_where_cleanup;
+  /* generate the DELETE expression tree. */
+  pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,pOrderBy,0,pLimit,pOffset);
+  if( pSelect == 0 ) goto limit_where_cleanup;
+  /* generate the WHERE rowid IN ( select ) expression */
+  pWhereRowid = sqlite3Expr(pParse->db, TK_ROW, 0, 0, 0);
+  if( pWhereRowid == 0 ) goto limit_where_cleanup;
+  pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
+  if( pInClause == 0 ) goto limit_where_cleanup;
+  pInClause->pSelect = pSelect;
+  sqlite3ExprSetHeight(pParse, pInClause);
+  return pInClause;
+
+limit_where_cleanup:
+  /* something went wrong. clean up anything allocated. */
   sqlite3SrcListDelete(pParse->db, pSelectSrc);
   sqlite3ExprListDelete(pParse->db, pEList);
   sqlite3ExprDelete(pParse->db, pSelectRowid);
@@ -151,7 +182,7 @@ Expr *sqlite3LimitWhere(
   sqlite3ExprDelete(pParse->db, pWhereRowid);
   return 0;
 }
-#endif /* !defined(SQLITE_OMIT_UPDATE_DELETE_LIMIT) */
+#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */
 
 /*
 ** Generate code for a DELETE FROM statement.
index 2e955294db68728cc5693b74412693cb99b99dae..b2b34103137584a5e7ec183690c311ed3322a4bf 100644 (file)
@@ -14,7 +14,7 @@
 ** the parser.  Lemon will also generate a header file containing
 ** numeric codes for all of the tokens.
 **
-** @(#) $Id: parse.y,v 1.255 2008/10/07 05:27:11 shane Exp $
+** @(#) $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_"
@@ -578,7 +578,7 @@ limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y).
 
 /////////////////////////// The DELETE statement /////////////////////////////
 //
-%ifndef SQLITE_OMIT_UPDATE_DELETE_LIMIT
+%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 ){
@@ -594,7 +594,7 @@ cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W) orderby_opt(O) limit
   }
 }
 %endif
-%ifdef SQLITE_OMIT_UPDATE_DELETE_LIMIT
+%ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
 cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
   sqlite3SrcListIndexedBy(pParse, X, &I);
   sqlite3DeleteFrom(pParse,X,W);
@@ -609,7 +609,7 @@ where_opt(A) ::= WHERE expr(X).       {A = X;}
 
 ////////////////////////// The UPDATE command ////////////////////////////////
 //
-%ifndef SQLITE_OMIT_UPDATE_DELETE_LIMIT
+%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"); 
@@ -626,7 +626,7 @@ cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W)
   }
 }
 %endif
-%ifdef SQLITE_OMIT_UPDATE_DELETE_LIMIT
+%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);
   sqlite3ExprListCheckLength(pParse,Y,"set list"); 
index 013a3ec779454635fbcbaf34f2413a30f2929d0f..10bbf481a48a70d1f18b70ffe8b19e2d72478660 100644 (file)
@@ -14,7 +14,7 @@
 ** resolve all identifiers by associating them with a particular
 ** table and column.
 **
-** $Id: resolve.c,v 1.7 2008/10/06 15:18:02 drh Exp $
+** $Id: resolve.c,v 1.8 2008/10/10 04:34:16 shane Exp $
 */
 #include "sqliteInt.h"
 #include <stdlib.h>
@@ -419,7 +419,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
 #endif
   switch( pExpr->op ){
 
-#ifndef SQLITE_OMIT_UPDATE_DELETE_LIMIT
+#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
     /* The special operator TK_ROW means use the rowid for the first
     ** column in the FROM clause.  This is used by the LIMIT and ORDER BY
     ** clause processing on UPDATE and DELETE statements.
@@ -436,7 +436,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
       pExpr->affinity = SQLITE_AFF_INTEGER;
       break;
     }
-#endif /* SQLITE_OMIT_UPDATE_DELETE_LIMIT */
+#endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) */
 
     /* A lone identifier is the name of a column.
     */
index 82c26b3fa1e42855c35b97c204eaf9e0ef40961d..f13a739db76f63a06bec69c34542044f96d18e1b 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.779 2008/10/07 23:46:38 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.780 2008/10/10 04:34:16 shane Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -2161,7 +2161,7 @@ void sqlite3SelectDelete(sqlite3*, Select*);
 Table *sqlite3SrcListLookup(Parse*, SrcList*);
 int sqlite3IsReadOnly(Parse*, Table*, int);
 void sqlite3OpenTable(Parse*, int iCur, int iDb, Table*, int);
-#ifndef SQLITE_OMIT_UPDATE_DELETE_LIMIT
+#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
 Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *);
 #endif
 void sqlite3DeleteFrom(Parse*, SrcList*, Expr*);
index 4fa74af69d100789c7c13c2203bee7025f02b83d..9639381bbfecd238a1012b802f68f18e064e41bb 100644 (file)
@@ -16,7 +16,7 @@
 ** The focus of this file is providing the TCL testing layer
 ** access to compile-time constants.
 **
-** $Id: test_config.c,v 1.38 2008/10/07 15:25:49 drh Exp $
+** $Id: test_config.c,v 1.39 2008/10/10 04:34:16 shane Exp $
 */
 
 #include "sqliteLimit.h"
@@ -450,6 +450,12 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
   Tcl_SetVar2(interp, "sqlite_options", "wsd", "1", TCL_GLOBAL_ONLY);
 #endif
 
+#if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY)
+  Tcl_SetVar2(interp, "sqlite_options", "update_delete_limit", "1", TCL_GLOBAL_ONLY);
+#else
+  Tcl_SetVar2(interp, "sqlite_options", "update_delete_limit", "0", TCL_GLOBAL_ONLY);
+#endif
+
 #ifdef SQLITE_SECURE_DELETE
   Tcl_SetVar2(interp, "sqlite_options", "secure_delete", "1", TCL_GLOBAL_ONLY);
 #else