/ Check-in [58ea768c]
Login

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

Overview
Comment:Fix a bug in the sqlite3_changes() function reported on the mailing list. (CVS 3868)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:58ea768c3e9905bd9db137f1b31dd3dd6c6001d0
User & Date: drh 2007-04-25 11:28:17
Context
2007-04-25
11:32
Fix duplicate test IDs in the test suite. No changes to code. Ticket #2319. (CVS 3869) check-in: 0935cdf8 user: drh tags: trunk
11:28
Fix a bug in the sqlite3_changes() function reported on the mailing list. (CVS 3868) check-in: 58ea768c user: drh tags: trunk
2007-04-24
17:35
This fixes a missed case in check-in (3866). Do not apply patch (3866) without also applying this patch. (CVS 3867) check-in: 66c2fa08 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/legacy.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: legacy.c,v 1.16 2006/09/15 07:28:50 drh Exp $
           17  +** $Id: legacy.c,v 1.17 2007/04/25 11:28:17 drh Exp $
    18     18   */
    19     19   
    20     20   #include "sqliteInt.h"
    21     21   #include "os.h"
    22     22   #include <ctype.h>
    23     23   
    24     24   /*
................................................................................
    40     40   ){
    41     41     int rc = SQLITE_OK;
    42     42     const char *zLeftover;
    43     43     sqlite3_stmt *pStmt = 0;
    44     44     char **azCols = 0;
    45     45   
    46     46     int nRetry = 0;
    47         -  int nChange = 0;
    48     47     int nCallback;
    49     48   
    50     49     if( zSql==0 ) return SQLITE_OK;
    51     50     while( (rc==SQLITE_OK || (rc==SQLITE_SCHEMA && (++nRetry)<2)) && zSql[0] ){
    52     51       int nCol;
    53     52       char **azVals = 0;
    54     53   
................................................................................
    60     59       }
    61     60       if( !pStmt ){
    62     61         /* this happens for a comment or white-space */
    63     62         zSql = zLeftover;
    64     63         continue;
    65     64       }
    66     65   
    67         -    db->nChange += nChange;
    68     66       nCallback = 0;
    69     67   
    70     68       nCol = sqlite3_column_count(pStmt);
    71     69       azCols = sqliteMalloc(2*nCol*sizeof(const char *) + 1);
    72     70       if( azCols==0 ){
    73     71         goto exec_out;
    74     72       }
................................................................................
    97     95             goto exec_out;
    98     96           }
    99     97         }
   100     98   
   101     99         if( rc!=SQLITE_ROW ){
   102    100           rc = sqlite3_finalize(pStmt);
   103    101           pStmt = 0;
   104         -        if( db->pVdbe==0 ){
   105         -          nChange = db->nChange;
   106         -        }
   107    102           if( rc!=SQLITE_SCHEMA ){
   108    103             nRetry = 0;
   109    104             zSql = zLeftover;
   110    105             while( isspace((unsigned char)zSql[0]) ) zSql++;
   111    106           }
   112    107           break;
   113    108         }

Changes to test/laststmtchanges.test.

    45     45   # changes() set properly after update
    46     46   do_test laststmtchanges-1.2 {
    47     47       catchsql {
    48     48           update t0 set x=3 where x=1;
    49     49           select changes(), total_changes();
    50     50       }
    51     51   } {0 {5 13}}
           52  +
           53  +# There was some goofy change-counting logic in sqlite3_exec() that
           54  +# appears to have been left over from SQLite version 2.  This test
           55  +# makes sure it has been removed.
           56  +#
           57  +do_test laststmtchanges-1.2.1 {
           58  +    db cache flush
           59  +    sqlite3_exec_printf db {update t0 set x=4 where x=3; select 1;} {}
           60  +    execsql {select changes()}
           61  +} {5}
    52     62   
    53     63   # changes() unchanged within an update statement
    54     64   do_test laststmtchanges-1.3 {
           65  +    execsql {update t0 set x=3 where x=4}
    55     66       catchsql {
    56     67           update t0 set x=x+changes() where x=3;
    57     68           select count() from t0 where x=8;
    58     69       }
    59     70   } {0 5}
    60     71   
    61     72   # changes() set properly after update on table where no rows changed