/ Check-in [ffd4e50a]
Login

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

Overview
Comment:Do not attempt to write a master journal name to the (non-existent) journal file in "no-journal" mode. Fix for #3127. (CVS 5145)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ffd4e50ab9b14fb7b686681c5e7a37b8355bbfca
User & Date: danielk1977 2008-05-20 07:05:09
Context
2008-05-20
13:17
Updated test case for Windows to get around problems in ticket #3129. (CVS 5146) check-in: 2faf69ca user: shane tags: trunk
07:05
Do not attempt to write a master journal name to the (non-existent) journal file in "no-journal" mode. Fix for #3127. (CVS 5145) check-in: ffd4e50a user: danielk1977 tags: trunk
2008-05-19
23:51
Improvements to API documentation. The sqlite3_exec() function now sets the result returned by sqlite3_errcode() when it receives an SQLITE_ABORT. (CVS 5144) check-in: f1df19ca 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.448 2008/05/15 11:08:08 danielk1977 Exp $
           21  +** @(#) $Id: pager.c,v 1.449 2008/05/20 07:05:09 danielk1977 Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include <assert.h>
    26     26   #include <string.h>
    27     27   
    28     28   /*
................................................................................
  4684   4684       ** written, then the process fails to upgrade from a RESERVED to an
  4685   4685       ** EXCLUSIVE lock. The next time the process tries to commit the
  4686   4686       ** transaction the m-j name will have already been written.
  4687   4687       */
  4688   4688       if( !pPager->setMaster ){
  4689   4689         rc = pager_incr_changecounter(pPager, 0);
  4690   4690         if( rc!=SQLITE_OK ) goto sync_exit;
         4691  +      if( pPager->journalMode!=PAGER_JOURNALMODE_OFF ){
  4691   4692   #ifndef SQLITE_OMIT_AUTOVACUUM
  4692         -      if( nTrunc!=0 ){
  4693         -        /* If this transaction has made the database smaller, then all pages
  4694         -        ** being discarded by the truncation must be written to the journal
  4695         -        ** file.
  4696         -        */
  4697         -        Pgno i;
  4698         -        int iSkip = PAGER_MJ_PGNO(pPager);
  4699         -        for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
  4700         -          if( !sqlite3BitvecTest(pPager->pInJournal, i) && i!=iSkip ){
  4701         -            rc = sqlite3PagerGet(pPager, i, &pPg);
  4702         -            if( rc!=SQLITE_OK ) goto sync_exit;
  4703         -            rc = sqlite3PagerWrite(pPg);
  4704         -            sqlite3PagerUnref(pPg);
  4705         -            if( rc!=SQLITE_OK ) goto sync_exit;
  4706         -          }
  4707         -        } 
  4708         -      }
         4693  +        if( nTrunc!=0 ){
         4694  +          /* If this transaction has made the database smaller, then all pages
         4695  +          ** being discarded by the truncation must be written to the journal
         4696  +          ** file.
         4697  +          */
         4698  +          Pgno i;
         4699  +          int iSkip = PAGER_MJ_PGNO(pPager);
         4700  +          for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){
         4701  +            if( !sqlite3BitvecTest(pPager->pInJournal, i) && i!=iSkip ){
         4702  +              rc = sqlite3PagerGet(pPager, i, &pPg);
         4703  +              if( rc!=SQLITE_OK ) goto sync_exit;
         4704  +              rc = sqlite3PagerWrite(pPg);
         4705  +              sqlite3PagerUnref(pPg);
         4706  +              if( rc!=SQLITE_OK ) goto sync_exit;
         4707  +            }
         4708  +          } 
         4709  +        }
  4709   4710   #endif
  4710         -      rc = writeMasterJournal(pPager, zMaster);
  4711         -      if( rc!=SQLITE_OK ) goto sync_exit;
  4712         -      rc = syncJournal(pPager);
         4711  +        rc = writeMasterJournal(pPager, zMaster);
         4712  +        if( rc!=SQLITE_OK ) goto sync_exit;
         4713  +        rc = syncJournal(pPager);
         4714  +      }
  4713   4715       }
  4714   4716       if( rc!=SQLITE_OK ) goto sync_exit;
  4715   4717   
  4716   4718   #ifndef SQLITE_OMIT_AUTOVACUUM
  4717   4719       if( nTrunc!=0 ){
  4718   4720         rc = sqlite3PagerTruncate(pPager, nTrunc);
  4719   4721         if( rc!=SQLITE_OK ) goto sync_exit;

Changes to test/jrnlmode.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library. The focus
    12     12   # of these tests is the journal mode pragma.
    13     13   #
    14         -# $Id: jrnlmode.test,v 1.2 2008/05/07 19:11:03 danielk1977 Exp $
           14  +# $Id: jrnlmode.test,v 1.3 2008/05/20 07:05:09 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   ifcapable {!pager_pragmas} {
    20     20     finish_test
    21     21     return
................................................................................
   187    187   
   188    188     do_test jrnlmode-2.5 {
   189    189       execsql {
   190    190         SELECT * FROM def;
   191    191       }
   192    192     } {4 5 6}
   193    193   
          194  +#----------------------------------------------------------------------
          195  +# Test caes jrnlmode-3.X verify that ticket #3127 has been fixed.
          196  +#
          197  +  db close
          198  +  file delete -force test2.db
          199  +  file delete -force test.db
          200  +  sqlite3 db test.db
          201  +
          202  +  do_test jrnlmode-3.1 {
          203  +    execsql { 
          204  +      CREATE TABLE x(n INTEGER); 
          205  +      ATTACH 'test2.db' AS a; 
          206  +      create table a.x ( n integer ); 
          207  +      insert into a.x values(1); 
          208  +      insert into a.x values (2); 
          209  +      insert into a.x values (3); 
          210  +      insert into a.x values (4); 
          211  +    }
          212  +  } {}
          213  +  
          214  +  do_test jrnlmode-3.2 {
          215  +    execsql { PRAGMA journal_mode=off; }
          216  +    execsql { 
          217  +      BEGIN IMMEDIATE;
          218  +      INSERT OR IGNORE INTO main.x SELECT * FROM a.x;
          219  +      COMMIT;
          220  +    }
          221  +  } {}
   194    222   }
   195    223   
          224  +ifcapable autovacuum&&pragma {
          225  +  db close
          226  +  file delete -force test.db
          227  +  sqlite3 db test.db
          228  +  do_test jrnlmode-4.1 {
          229  +    execsql {
          230  +      PRAGMA cache_size = 1;
          231  +      PRAGMA auto_vacuum = 1;
          232  +      CREATE TABLE abc(a, b, c);
          233  +    }
          234  +    execsql { PRAGMA page_count }
          235  +  } {3}
          236  +
          237  +  do_test jrnlmode-4.2 {
          238  +    execsql { PRAGMA journal_mode = off }
          239  +  } {off}
          240  +
          241  +  do_test jrnlmode-4.3 {
          242  +    execsql { INSERT INTO abc VALUES(1, 2, randomblob(2000)) }
          243  +  } {}
   196    244   
          245  +  # This will attempt to truncate the database file. Check that this
          246  +  # is not a problem when journal_mode=off.
          247  +  do_test jrnlmode-4.4 {
          248  +    execsql { DELETE FROM abc }
          249  +  } {}
   197    250   
          251  +  integrity_check jrnlmode-4.5
          252  +}
   198    253   
   199    254   finish_test