-C Remove\ssome\sif()\sconditions\sthat\sare\salways\strue\sfrom\sdelete.c.\s(CVS\s5843)
-D 2008-10-27T08:24:38
+C Make\ssqlite3_count_changes()\sand\stotal_changes()\swork\swith\s"DELETE\sFROM\s<table-name>".\s(CVS\s5844)
+D 2008-10-27T13:59:34
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 3fe17eccd87d385b5adc9766828716cfdd154d6b
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
F src/btmutex.c 3a90096c3080b9057dc570b8e16e46511e1c788a
-F src/btree.c 3e686f899659df8d79f2587d0f34f51fdf6a6276
-F src/btree.h 903682f2a88da37435f103da00cb915d63bc8015
+F src/btree.c 5d72b67ee20afba92e95827fc9fc599d917f7f68
+F src/btree.h 179c3ea813780df78a289a8f5130db18e6d4616e
F src/btreeInt.h e38e9b2b285f40f5bc0a6664f630d4a141622f16
F src/build.c d6d55f97abcb6f17ac3e9e7a1dd8c0db67db34fd
F src/callback.c e970e5beddbdb23f89a6d05cb1a6419d9f755624
F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c
F src/date.c 6f4277fa56d8c1b8e70c0bde838c9e99609f5ec0
-F src/delete.c 8bb079e098c0d154f0469062ddbc8237d1cc0b55
+F src/delete.c b0b7c499ccf28c1857905c9cf42f4ddc49bf7331
F src/expr.c 2b1945314fdc661fb04306cb86bd8516cfd12d4a
F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff
F src/func.c 8431b40a7843d1024145684d303c55b4ee087bbe
F src/tclsqlite.c 96049bd454f1547abff0a57c45f0dfa57701e076
F src/test1.c a7310348961945e656c096e5f91d4d87dee6b61d
F src/test2.c 897528183edf2839c2a3c991d415905db56f1240
-F src/test3.c e85b7ce5c28c3ce7fbdbf7f98e1467b19786c62b
+F src/test3.c 88a246b56b824275300e6c899634fbac1dc94b14
F src/test4.c f79ab52d27ff49b784b631a42e2ccd52cfd5c84c
F src/test5.c 162a1cea2105a2c460a3f39fa6919617b562a288
F src/test6.c 0a0304a69cfa4962a429d084c6d451ff9e4fb572
F src/utf.c c63e6f69082f85c19ab88d62dedaf91d71ac1a50
F src/util.c afe659ccc05d1f8af9e8631dabfec3ee3a7144af
F src/vacuum.c fd77433d0c26d3ff1eb96eab017a1787ac5aa642
-F src/vdbe.c b78adf571b9abac4092c641bec148832e8f26f34
+F src/vdbe.c be81532805ee6fc1fe7bd2e1c82cf4a09b7b3061
F src/vdbe.h 41c99aaad9167c1b5431993db446de74b2f71fc3
F src/vdbeInt.h a20f479ec3bf41c61b0c2bd5176a9bad6b2a07ef
F src/vdbeapi.c 6798c70cf176d23594ec557db88190ca8c7fa860
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
F test/jrnlmode.test c2e8212a6f6d32f8fd8f869b93553154eaf2244c
F test/lastinsert.test 474d519c68cb79d07ecae56a763aa7f322c72f51
-F test/laststmtchanges.test 18ead86c8a87ade949a1d5658f6dc4bb111d1b02
+F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
F test/like.test fef924922828d5a2a5bff80b9bdd9ff57a1ca500
F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da
F test/limit.test 2db7b3b34fb925b8e847d583d2eb67531d0ce67e
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 3224ea59812d0f3b5685bd92751054b81e3b681e
-R ba54cbfc3be9ecc00ba76b8e1609779a
+P 297ad90dd3a69002e6e4175e9e3938b3a627574d
+R a6b93c46cddb9e42feecabc035375dbb
U danielk1977
-Z ccda3a5856c2017497ad6a21acb2893e
+Z 98ec3e2e89a662c96092f7315cee2195
-297ad90dd3a69002e6e4175e9e3938b3a627574d
\ No newline at end of file
+e68e4282adb9003aa297d033aeb5d9cadee215cd
\ No newline at end of file
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.525 2008/10/08 17:58:49 danielk1977 Exp $
+** $Id: btree.c,v 1.526 2008/10/27 13:59:34 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
BtShared *pBt, /* The BTree that contains the table */
Pgno pgno, /* Page number to clear */
MemPage *pParent, /* Parent page. NULL for the root */
- int freePageFlag /* Deallocate page if true */
+ int freePageFlag, /* Deallocate page if true */
+ int *pnChange
){
MemPage *pPage = 0;
int rc;
for(i=0; i<pPage->nCell; i++){
pCell = findCell(pPage, i);
if( !pPage->leaf ){
- rc = clearDatabasePage(pBt, get4byte(pCell), pPage, 1);
+ rc = clearDatabasePage(pBt, get4byte(pCell), pPage, 1, pnChange);
if( rc ) goto cleardatabasepage_out;
}
rc = clearCell(pPage, pCell);
if( rc ) goto cleardatabasepage_out;
}
if( !pPage->leaf ){
- rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), pPage, 1);
+ rc = clearDatabasePage(pBt, get4byte(&pPage->aData[8]), pPage, 1, pnChange);
if( rc ) goto cleardatabasepage_out;
+ }else if( pnChange ){
+ assert( pPage->intKey );
+ *pnChange += pPage->nCell;
}
if( freePageFlag ){
rc = freePage(pPage);
** This routine will fail with SQLITE_LOCKED if there are any open
** read cursors on the table. Open write cursors are moved to the
** root of the table.
+**
+** If pnChange is not NULL, then table iTable must be an intkey table. The
+** integer value pointed to by pnChange is incremented by the number of
+** entries in the table.
*/
-int sqlite3BtreeClearTable(Btree *p, int iTable){
+int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
int rc;
BtShared *pBt = p->pBt;
sqlite3BtreeEnter(p);
}else if( SQLITE_OK!=(rc = saveAllCursors(pBt, iTable, 0)) ){
/* nothing to do */
}else{
- rc = clearDatabasePage(pBt, (Pgno)iTable, 0, 0);
+ rc = clearDatabasePage(pBt, (Pgno)iTable, 0, 0, pnChange);
}
sqlite3BtreeLeave(p);
return rc;
rc = sqlite3BtreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
if( rc ) return rc;
- rc = sqlite3BtreeClearTable(p, iTable);
+ rc = sqlite3BtreeClearTable(p, iTable, 0);
if( rc ){
releasePage(pPage);
return rc;
** subsystem. See comments in the source code for a detailed description
** of what each interface routine does.
**
-** @(#) $Id: btree.h,v 1.104 2008/10/08 17:58:49 danielk1977 Exp $
+** @(#) $Id: btree.h,v 1.105 2008/10/27 13:59:34 danielk1977 Exp $
*/
#ifndef _BTREE_H_
#define _BTREE_H_
#define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */
int sqlite3BtreeDropTable(Btree*, int, int*);
-int sqlite3BtreeClearTable(Btree*, int);
+int sqlite3BtreeClearTable(Btree*, int, int*);
int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
void sqlite3BtreeTripAllCursors(Btree*, int);
** 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.183 2008/10/27 08:24:38 danielk1977 Exp $
+** $Id: delete.c,v 1.184 2008/10/27 13:59:34 danielk1977 Exp $
*/
#include "sqliteInt.h"
int oldIdx = -1; /* Cursor for the OLD table of AFTER triggers */
NameContext sNC; /* Name context to resolve expressions in */
int iDb; /* Database number */
- int memCnt = 0; /* Memory cell used for change counting */
+ int memCnt = -1; /* Memory cell used for change counting */
#ifndef SQLITE_OMIT_TRIGGER
int isView; /* True if attempting to delete from a view */
*/
if( pWhere==0 && !triggers_exist && !IsVirtual(pTab) ){
assert( !isView );
- if( db->flags & SQLITE_CountRows ){
- /* If counting rows deleted, just count the total number of
- ** entries in the table. */
- int addr2;
- sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
- sqlite3VdbeAddOp2(v, OP_Rewind, iCur, sqlite3VdbeCurrentAddr(v)+2);
- addr2 = sqlite3VdbeAddOp2(v, OP_AddImm, memCnt, 1);
- sqlite3VdbeAddOp2(v, OP_Next, iCur, addr2);
- sqlite3VdbeAddOp1(v, OP_Close, iCur);
- }
- sqlite3VdbeAddOp2(v, OP_Clear, pTab->tnum, iDb);
+ sqlite3VdbeAddOp3(v, OP_Clear, pTab->tnum, iDb, memCnt);
if( !pParse->nested ){
sqlite3VdbeChangeP4(v, -1, pTab->zName, P4_STATIC);
}
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test3.c,v 1.101 2008/08/13 19:11:48 drh Exp $
+** $Id: test3.c,v 1.102 2008/10/27 13:59:34 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "btreeInt.h"
pBt = sqlite3TestTextToPtr(argv[1]);
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
sqlite3BtreeEnter(pBt);
- rc = sqlite3BtreeClearTable(pBt, iTable);
+ rc = sqlite3BtreeClearTable(pBt, iTable, 0);
sqlite3BtreeLeave(pBt);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
-** $Id: vdbe.c,v 1.782 2008/10/08 17:58:49 danielk1977 Exp $
+** $Id: vdbe.c,v 1.783 2008/10/27 13:59:34 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
break;
}
-/* Opcode: Clear P1 P2 *
+/* Opcode: Clear P1 P2 P3
**
** Delete all contents of the database table or index whose root page
** in the database file is given by P1. But, unlike Destroy, do not
** P2==1 then the table to be clear is in the auxiliary database file
** that is used to store tables create using CREATE TEMPORARY TABLE.
**
+** If the P3 value is non-zero, then the table refered to must be an
+** intkey table (an SQL table, not an index). In this case the row change
+** count is incremented by the number of rows in the table being cleared.
+** If P3 is greater than zero, then the value stored in register P3 is
+** also incremented by the number of rows in the table being cleared.
+**
** See also: Destroy
*/
case OP_Clear: {
+ int nChange = 0;
assert( (p->btreeMask & (1<<pOp->p2))!=0 );
- rc = sqlite3BtreeClearTable(db->aDb[pOp->p2].pBt, pOp->p1);
+ rc = sqlite3BtreeClearTable(
+ db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
+ );
+ if( pOp->p3 ){
+ p->nChange += nChange;
+ if( pOp->p3>0 ){
+ p->aMem[pOp->p3].u.i += nChange;
+ }
+ }
break;
}
+#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# Note 3: changes() is not changed by a change to a view (since everything
# is done within instead of trigger context).
#
+# $Id: laststmtchanges.test,v 1.7 2008/10/27 13:59:34 danielk1977 Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
} ;# ifcapable view
+
+# ----------------------------------------------------------------------------
+# 6.x - Test "DELETE FROM <table>" in the absence of triggers
+#
+do_test laststmtchanges-6.1 {
+ execsql {
+ CREATE TABLE t3(a, b, c);
+ INSERT INTO t3 VALUES(1, 2, 3);
+ INSERT INTO t3 VALUES(4, 5, 6);
+ }
+} {}
+do_test laststmtchanges-6.2 {
+ execsql {
+ BEGIN;
+ DELETE FROM t3;
+ SELECT changes();
+ }
+} {2}
+do_test laststmtchanges-6.3 {
+ execsql {
+ ROLLBACK;
+ BEGIN;
+ DELETE FROM t3 WHERE a IS NOT NULL;
+ SELECT changes();
+ }
+} {2}
+do_test laststmtchanges-6.4 {
+ execsql {
+ ROLLBACK;
+ CREATE INDEX t3_i1 ON t3(a);
+ BEGIN;
+ DELETE FROM t3;
+ SELECT changes();
+ }
+} {2}
+do_test laststmtchanges-6.5 {
+ execsql { ROLLBACK }
+ set nTotalChange [execsql {SELECT total_changes()}]
+ expr 0
+} {0}
+do_test laststmtchanges-6.6 {
+ execsql {
+ SELECT total_changes();
+ DELETE FROM t3;
+ SELECT total_changes();
+ }
+} [list $nTotalChange [expr $nTotalChange+2]]
+
finish_test