/ Check-in [f000ac1e]
Login

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

Overview
Comment:Prevent an assert from failing when opening a zero-length database file with an apparently hot journal with locking_mode=exclusive set.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f000ac1e52f56f5fcbc2f8b9cd632656c6dc6002
User & Date: dan 2010-10-22 13:55:51
Context
2010-10-27
15:36
Fix a memory leak in the update_hook method of the TCL interface. check-in: 1d17e3dc user: drh tags: trunk
2010-10-22
13:55
Prevent an assert from failing when opening a zero-length database file with an apparently hot journal with locking_mode=exclusive set. check-in: f000ac1e user: dan tags: trunk
2010-10-21
22:58
Make sure the estimated row count for ephemeral tables is initialized so that automatic indices can be used on those tables. check-in: d30f7b2d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  4520   4520         */
  4521   4521         rc = pagerPagecount(pPager, &nPage);
  4522   4522         if( rc==SQLITE_OK ){
  4523   4523           if( nPage==0 ){
  4524   4524             sqlite3BeginBenignMalloc();
  4525   4525             if( pagerLockDb(pPager, RESERVED_LOCK)==SQLITE_OK ){
  4526   4526               sqlite3OsDelete(pVfs, pPager->zJournal, 0);
  4527         -            pagerUnlockDb(pPager, SHARED_LOCK);
         4527  +            if( !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
  4528   4528             }
  4529   4529             sqlite3EndBenignMalloc();
  4530   4530           }else{
  4531   4531             /* The journal file exists and no other connection has a reserved
  4532   4532             ** or greater lock on the database file. Now check that there is
  4533   4533             ** at least one non-zero bytes at the start of the journal file.
  4534   4534             ** If there is, then we consider this journal to be hot. If not, 

Changes to test/exclusive.test.

   464    464     }
   465    465   } {normal 1 2 3 2 3 4 5 6 7 11 12 13 12 13 14 15 16 17}
   466    466   do_test exclusive-5.7 {
   467    467     # Just the db open.
   468    468     set sqlite_open_file_count
   469    469     expr $sqlite_open_file_count-$extrafds
   470    470   } {1}
          471  +
          472  +#-------------------------------------------------------------------------
          473  +
          474  +do_execsql_test exclusive-6.1 {
          475  +  CREATE TABLE t4(a, b);
          476  +  INSERT INTO t4 VALUES('Eden', 1955);
          477  +  BEGIN;
          478  +    INSERT INTO t4 VALUES('Macmillan', 1957);
          479  +    INSERT INTO t4 VALUES('Douglas-Home', 1963);
          480  +    INSERT INTO t4 VALUES('Wilson', 1964);
          481  +}
          482  +do_test exclusive-6.2 {
          483  +  forcedelete test2.db test2.db-journal
          484  +  file copy test.db test2.db
          485  +  file copy test.db-journal test2.db-journal
          486  +  sqlite3 db test2.db
          487  +} {}
          488  +
          489  +do_execsql_test exclusive-6.3 {
          490  +  PRAGMA locking_mode = EXCLUSIVE;
          491  +  SELECT * FROM t4;
          492  +} {exclusive Eden 1955}
          493  +
          494  +do_test exclusive-6.4 {
          495  +  db close
          496  +  forcedelete test.db test.db-journal
          497  +  set fd [open test.db-journal w]
          498  +  puts $fd x
          499  +  close $fd
          500  +  sqlite3 db test.db
          501  +} {}
          502  +
          503  +do_execsql_test exclusive-6.5 {
          504  +  PRAGMA locking_mode = EXCLUSIVE;
          505  +  SELECT * FROM sqlite_master;
          506  +} {}
   471    507   
   472    508   finish_test
          509  +