/ Check-in [da00efb1]
Login

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

Overview
Comment:Make sure the pagers in-memory cache states in sync with the disk file. Ticket #529. (CVS 1133)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: da00efb13fe8ccf1c27e4e1193df6b53de9463f4
User & Date: drh 2003-12-17 23:57:35
Context
2003-12-18
00:02
Bump the version number and update the change log in preparation for the next release. (CVS 1134) check-in: 9ad0bdf6 user: drh tags: trunk
2003-12-17
23:57
Make sure the pagers in-memory cache states in sync with the disk file. Ticket #529. (CVS 1133) check-in: da00efb1 user: drh tags: trunk
2003-12-16
03:44
Improvements to the way PRAGMA integrity_check works. More likely to output userful information when given a corrupt database. (CVS 1132) check-in: b92c31d6 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.90 2003/09/06 01:10:47 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.91 2003/12/17 23:57:35 drh Exp $
    22     22   */
    23     23   #include "os.h"         /* Must be first to enable large file support */
    24     24   #include "sqliteInt.h"
    25     25   #include "pager.h"
    26     26   #include <assert.h>
    27     27   #include <string.h>
    28     28   
................................................................................
   516    516     ** at the same time, if there is one.
   517    517     */
   518    518     pPg = pager_lookup(pPager, pgRec.pgno);
   519    519     TRACE2("PLAYBACK %d\n", pgRec.pgno);
   520    520     sqliteOsSeek(&pPager->fd, (pgRec.pgno-1)*(off_t)SQLITE_PAGE_SIZE);
   521    521     rc = sqliteOsWrite(&pPager->fd, pgRec.aData, SQLITE_PAGE_SIZE);
   522    522     if( pPg ){
   523         -    if( pPg->nRef==0 ||
   524         -        memcmp(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_PAGE_SIZE)==0
   525         -    ){
   526         -      /* Do not update the data on this page if the page is in use
   527         -      ** and the page has never been modified.  This avoids resetting
   528         -      ** the "extra" data.  That in turn avoids invalidating BTree cursors
   529         -      ** in trees that have never been modified.  The end result is that
   530         -      ** you can have a SELECT going on in one table and ROLLBACK changes
   531         -      ** to a different table and the SELECT is unaffected by the ROLLBACK.
   532         -      */
   533         -      memcpy(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_PAGE_SIZE);
   534         -      memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);
   535         -    }
          523  +    /* No page should ever be rolled back that is in use, except for page
          524  +    ** 1 which is held in use in order to keep the lock on the database
          525  +    ** active.
          526  +    */
          527  +    assert( pPg->nRef==0 || pPg->pgno==1 );
          528  +    memcpy(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_PAGE_SIZE);
          529  +    memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);
   536    530       pPg->dirty = 0;
   537    531       pPg->needSync = 0;
   538    532     }
   539    533     return rc;
   540    534   }
   541    535   
   542    536   /*

Changes to test/misc2.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for miscellanous features that were
    14     14   # left out of other test files.
    15     15   #
    16         -# $Id: misc2.test,v 1.10 2003/12/10 01:31:21 drh Exp $
           16  +# $Id: misc2.test,v 1.11 2003/12/17 23:57:36 drh Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # Test for ticket #360
    22     22   #
    23     23   do_test misc2-1.1 {
................................................................................
   227    227       SELECT dim1.n, dim2.n, dim3.n, dim4.n
   228    228       FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
   229    229       WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;
   230    230   
   231    231       SELECT count(*) FROM x;
   232    232     }
   233    233   } [expr 5*5*5*5]
          234  +
          235  +finish_test

Added test/misc3.test.

            1  +# 2003 December 17
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +# This file implements tests for miscellanous features that were
           14  +# left out of other test files.
           15  +#
           16  +# $Id: misc3.test,v 1.1 2003/12/17 23:57:36 drh Exp $
           17  +
           18  +set testdir [file dirname $argv0]
           19  +source $testdir/tester.tcl
           20  +
           21  +# Ticket #529.  Make sure an ABORT does not damage the in-memory cache
           22  +# that will be used by subsequent statements in the same transaction.
           23  +#
           24  +do_test misc3-1.1 {
           25  +  execsql {
           26  +    CREATE TABLE t1(a UNIQUE,b);
           27  +    INSERT INTO t1
           28  +      VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
           29  +    UPDATE t1 SET b=b||b;
           30  +    UPDATE t1 SET b=b||b;
           31  +    UPDATE t1 SET b=b||b;
           32  +    UPDATE t1 SET b=b||b;
           33  +    UPDATE t1 SET b=b||b;
           34  +    INSERT INTO t1 VALUES(2,'x');
           35  +    UPDATE t1 SET b=substr(b,1,500);
           36  +    BEGIN;
           37  +  }
           38  +  catchsql {UPDATE t1 SET a=CASE a WHEN 2 THEN 1 ELSE a END, b='y';}
           39  +  execsql {
           40  +    CREATE TABLE t2(x,y);
           41  +    COMMIT;
           42  +    PRAGMA integrity_check;
           43  +  }
           44  +} ok
           45  +do_test misc3-1.2 {
           46  +  execsql {
           47  +    DROP TABLE t1;
           48  +    DROP TABLE t2;
           49  +    VACUUM;
           50  +    CREATE TABLE t1(a UNIQUE,b);
           51  +    INSERT INTO t1
           52  +       VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
           53  +    INSERT INTO t1 SELECT a+1, b||b FROM t1;
           54  +    INSERT INTO t1 SELECT a+2, b||b FROM t1;
           55  +    INSERT INTO t1 SELECT a+4, b FROM t1;
           56  +    INSERT INTO t1 SELECT a+8, b FROM t1;
           57  +    INSERT INTO t1 SELECT a+16, b FROM t1;
           58  +    INSERT INTO t1 SELECT a+32, b FROM t1;
           59  +    INSERT INTO t1 SELECT a+64, b FROM t1;
           60  +
           61  +    BEGIN;
           62  +  }
           63  +  catchsql {UPDATE t1 SET a=CASE a WHEN 128 THEN 127 ELSE a END, b='';}
           64  +  execsql {
           65  +    INSERT INTO t1 VALUES(200,'hello out there');
           66  +    COMMIT;
           67  +    PRAGMA integrity_check;
           68  +  }
           69  +} ok
           70  +
           71  +finish_test