/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/pager.c.

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531

532

533
534
535
536
537
538
539
540
541
542
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.90 2003/09/06 01:10:47 drh Exp $
*/
#include "os.h"         /* Must be first to enable large file support */
#include "sqliteInt.h"
#include "pager.h"
#include <assert.h>
#include <string.h>

................................................................................
  ** at the same time, if there is one.
  */
  pPg = pager_lookup(pPager, pgRec.pgno);
  TRACE2("PLAYBACK %d\n", pgRec.pgno);
  sqliteOsSeek(&pPager->fd, (pgRec.pgno-1)*(off_t)SQLITE_PAGE_SIZE);
  rc = sqliteOsWrite(&pPager->fd, pgRec.aData, SQLITE_PAGE_SIZE);
  if( pPg ){
    if( pPg->nRef==0 ||
        memcmp(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_PAGE_SIZE)==0
    ){
      /* Do not update the data on this page if the page is in use
      ** and the page has never been modified.  This avoids resetting
      ** the "extra" data.  That in turn avoids invalidating BTree cursors
      ** in trees that have never been modified.  The end result is that
      ** you can have a SELECT going on in one table and ROLLBACK changes
      ** to a different table and the SELECT is unaffected by the ROLLBACK.

      */

      memcpy(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_PAGE_SIZE);
      memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);
    }
    pPg->dirty = 0;
    pPg->needSync = 0;
  }
  return rc;
}

/*







|







 







|
|
<
<
<
<
<
<
<
>
|
>
|
|
<







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
...
516
517
518
519
520
521
522
523
524







525
526
527
528
529

530
531
532
533
534
535
536
** The pager is used to access a database disk file.  It implements
** atomic commit and rollback through the use of a journal file that
** is separate from the database file.  The pager also implements file
** locking to prevent two processes from writing the same database
** file simultaneously, or one process from reading the database while
** another is writing.
**
** @(#) $Id: pager.c,v 1.91 2003/12/17 23:57:35 drh Exp $
*/
#include "os.h"         /* Must be first to enable large file support */
#include "sqliteInt.h"
#include "pager.h"
#include <assert.h>
#include <string.h>

................................................................................
  ** at the same time, if there is one.
  */
  pPg = pager_lookup(pPager, pgRec.pgno);
  TRACE2("PLAYBACK %d\n", pgRec.pgno);
  sqliteOsSeek(&pPager->fd, (pgRec.pgno-1)*(off_t)SQLITE_PAGE_SIZE);
  rc = sqliteOsWrite(&pPager->fd, pgRec.aData, SQLITE_PAGE_SIZE);
  if( pPg ){
    /* No page should ever be rolled back that is in use, except for page
    ** 1 which is held in use in order to keep the lock on the database







    ** active.
    */
    assert( pPg->nRef==0 || pPg->pgno==1 );
    memcpy(PGHDR_TO_DATA(pPg), pgRec.aData, SQLITE_PAGE_SIZE);
    memset(PGHDR_TO_EXTRA(pPg), 0, pPager->nExtra);

    pPg->dirty = 0;
    pPg->needSync = 0;
  }
  return rc;
}

/*

Changes to test/misc2.test.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
227
228
229
230
231
232
233


#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc2.test,v 1.10 2003/12/10 01:31:21 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Test for ticket #360
#
do_test misc2-1.1 {
................................................................................
    SELECT dim1.n, dim2.n, dim3.n, dim4.n
    FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
    WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;

    SELECT count(*) FROM x;
  }
} [expr 5*5*5*5]









|







 







>
>
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
227
228
229
230
231
232
233
234
235
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc2.test,v 1.11 2003/12/17 23:57:36 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Test for ticket #360
#
do_test misc2-1.1 {
................................................................................
    SELECT dim1.n, dim2.n, dim3.n, dim4.n
    FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
    WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;

    SELECT count(*) FROM x;
  }
} [expr 5*5*5*5]

finish_test

Added test/misc3.test.















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 2003 December 17
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc3.test,v 1.1 2003/12/17 23:57:36 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Ticket #529.  Make sure an ABORT does not damage the in-memory cache
# that will be used by subsequent statements in the same transaction.
#
do_test misc3-1.1 {
  execsql {
    CREATE TABLE t1(a UNIQUE,b);
    INSERT INTO t1
      VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
    UPDATE t1 SET b=b||b;
    UPDATE t1 SET b=b||b;
    UPDATE t1 SET b=b||b;
    UPDATE t1 SET b=b||b;
    UPDATE t1 SET b=b||b;
    INSERT INTO t1 VALUES(2,'x');
    UPDATE t1 SET b=substr(b,1,500);
    BEGIN;
  }
  catchsql {UPDATE t1 SET a=CASE a WHEN 2 THEN 1 ELSE a END, b='y';}
  execsql {
    CREATE TABLE t2(x,y);
    COMMIT;
    PRAGMA integrity_check;
  }
} ok
do_test misc3-1.2 {
  execsql {
    DROP TABLE t1;
    DROP TABLE t2;
    VACUUM;
    CREATE TABLE t1(a UNIQUE,b);
    INSERT INTO t1
       VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
    INSERT INTO t1 SELECT a+1, b||b FROM t1;
    INSERT INTO t1 SELECT a+2, b||b FROM t1;
    INSERT INTO t1 SELECT a+4, b FROM t1;
    INSERT INTO t1 SELECT a+8, b FROM t1;
    INSERT INTO t1 SELECT a+16, b FROM t1;
    INSERT INTO t1 SELECT a+32, b FROM t1;
    INSERT INTO t1 SELECT a+64, b FROM t1;

    BEGIN;
  }
  catchsql {UPDATE t1 SET a=CASE a WHEN 128 THEN 127 ELSE a END, b='';}
  execsql {
    INSERT INTO t1 VALUES(200,'hello out there');
    COMMIT;
    PRAGMA integrity_check;
  }
} ok

finish_test