/ Check-in [f5d61d7d]
Login

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

Overview
Comment:Fix the VACUUM command so that it does not modify the changes counts reported by sqlite3_changes() or sqlite3_total_changes(). Update documentation on sqlite3_changes() and sqlite3_total_changes() to state that "DELETE FROM table" records a change count of zero. (CVS 5151)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f5d61d7d982b58accaf33df4362ce4a5eb79307e
User & Date: drh 2008-05-21 13:44:14
Context
2008-05-21
15:01
Update sqlite3_open*() documentation on shared cache/filename matching relationship. Ticket #3132. (CVS 5152) check-in: 235e384e user: shane tags: trunk
13:44
Fix the VACUUM command so that it does not modify the changes counts reported by sqlite3_changes() or sqlite3_total_changes(). Update documentation on sqlite3_changes() and sqlite3_total_changes() to state that "DELETE FROM table" records a change count of zero. (CVS 5151) check-in: f5d61d7d user: drh tags: trunk
2008-05-20
19:08
Fix OS/2 compilation for pre-C99 compilers. (CVS 5150) check-in: de8e6718 user: pweilbacher tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/sqlite.h.in.

    26     26   ** on how SQLite interfaces are suppose to operate.
    27     27   **
    28     28   ** The name of this file under configuration management is "sqlite.h.in".
    29     29   ** The makefile makes some minor changes to this file (such as inserting
    30     30   ** the version number) and changes its name to "sqlite3.h" as
    31     31   ** part of the build process.
    32     32   **
    33         -** @(#) $Id: sqlite.h.in,v 1.315 2008/05/20 18:43:38 drh Exp $
           33  +** @(#) $Id: sqlite.h.in,v 1.316 2008/05/21 13:44:14 drh Exp $
    34     34   */
    35     35   #ifndef _SQLITE3_H_
    36     36   #define _SQLITE3_H_
    37     37   #include <stdarg.h>     /* Needed for the definition of va_list */
    38     38   
    39     39   /*
    40     40   ** Make sure we can call this stuff from C++.
................................................................................
   965    965   ** "DELETE FROM table" are not row changes and will not be counted
   966    966   ** by the sqlite3_changes() or [sqlite3_total_changes()] functions.
   967    967   ** To get an accurate count of the number of rows deleted, use
   968    968   ** "DELETE FROM table WHERE 1" instead.
   969    969   **
   970    970   ** INVARIANTS:
   971    971   **
   972         -** {F12241} The [sqlite3_changes()] function returns the number of
          972  +** {F12241} The [sqlite3_changes()] function shall return the number of
   973    973   **          row changes caused by the most recent INSERT, UPDATE,
   974    974   **          or DELETE statement on the same database connection and
   975         -**          within the same trigger context, or zero if there have
          975  +**          within the same or higher trigger context, or zero if there have
   976    976   **          not been any qualifying row changes.
          977  +**
          978  +** {F12243} Statements of the form "DELETE FROM tablename" with no
          979  +**          WHERE clause shall cause subsequent calls to 
          980  +**          [sqlite3_changes()] to return zero, regardless of the
          981  +**          number of rows originally in the table.
   977    982   **
   978    983   ** LIMITATIONS:
   979    984   **
   980    985   ** {U12252} If a separate thread makes changes on the same database connection
   981    986   **          while [sqlite3_changes()] is running then the value returned
   982    987   **          is unpredictable and unmeaningful.
   983    988   */
................................................................................
  1011   1016   ** INVARIANTS:
  1012   1017   ** 
  1013   1018   ** {F12261} The [sqlite3_total_changes()] returns the total number
  1014   1019   **          of row changes caused by INSERT, UPDATE, and/or DELETE
  1015   1020   **          statements on the same [database connection], in any
  1016   1021   **          trigger context, since the database connection was
  1017   1022   **          created.
         1023  +**
         1024  +** {F12263} Statements of the form "DELETE FROM tablename" with no
         1025  +**          WHERE clause shall not change the value returned
         1026  +**          by [sqlite3_total_changes()]
  1018   1027   **
  1019   1028   ** LIMITATIONS:
  1020   1029   **
  1021   1030   ** {U12264} If a separate thread makes changes on the same database connection
  1022   1031   **          while [sqlite3_total_changes()] is running then the value 
  1023   1032   **          returned is unpredictable and unmeaningful.
  1024   1033   */

Changes to src/vacuum.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the VACUUM command.
    13     13   **
    14     14   ** Most of the code in this file may be omitted by defining the
    15     15   ** SQLITE_OMIT_VACUUM macro.
    16     16   **
    17         -** $Id: vacuum.c,v 1.78 2008/04/30 16:38:23 drh Exp $
           17  +** $Id: vacuum.c,v 1.79 2008/05/21 13:44:14 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "vdbeInt.h"
    21     21   
    22     22   #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH)
    23     23   /*
    24     24   ** Execute zSql on database db. Return an error code.
................................................................................
    80     80   */
    81     81   int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
    82     82     int rc = SQLITE_OK;     /* Return code from service routines */
    83     83     Btree *pMain;           /* The database being vacuumed */
    84     84     Btree *pTemp;           /* The temporary database we vacuum into */
    85     85     char *zSql = 0;         /* SQL statements */
    86     86     int saved_flags;        /* Saved value of the db->flags */
           87  +  int saved_nChange;      /* Saved value of db->nChange */
           88  +  int saved_nTotalChange; /* Saved value of db->nTotalChange */
    87     89     Db *pDb = 0;            /* Database to detach at end of vacuum */
    88     90     int nRes;
    89     91   
    90     92     /* Save the current value of the write-schema flag before setting it. */
    91     93     saved_flags = db->flags;
           94  +  saved_nChange = db->nChange;
           95  +  saved_nTotalChange = db->nTotalChange;
    92     96     db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
    93     97   
    94     98     if( !db->autoCommit ){
    95     99       sqlite3SetString(pzErrMsg, "cannot VACUUM from within a transaction", 
    96    100          (char*)0);
    97    101       rc = SQLITE_ERROR;
    98    102       goto end_of_vacuum;
................................................................................
   249    253     if( rc==SQLITE_OK ){
   250    254       rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes);
   251    255     }
   252    256   
   253    257   end_of_vacuum:
   254    258     /* Restore the original value of db->flags */
   255    259     db->flags = saved_flags;
          260  +  db->nChange = saved_nChange;
          261  +  db->nTotalChange = saved_nTotalChange;
   256    262   
   257    263     /* Currently there is an SQL level transaction open on the vacuum
   258    264     ** database. No locks are held on any other files (since the main file
   259    265     ** was committed at the btree level). So it safe to end the transaction
   260    266     ** by manually setting the autoCommit flag to true and detaching the
   261    267     ** vacuum database. The vacuum_db journal file is deleted when the pager
   262    268     ** is closed by the DETACH.