SQLite

Check-in [f000ac1e52]
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
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f000ac1e52f56f5fcbc2f8b9cd632656c6dc6002
User & Date: dan 2010-10-22 13:55:51.000
Context
2010-10-27
15:36
Fix a memory leak in the update_hook method of the TCL interface. (check-in: 1d17e3dc83 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: f000ac1e52 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: d30f7b2def user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pager.c.
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
      */
      rc = pagerPagecount(pPager, &nPage);
      if( rc==SQLITE_OK ){
        if( nPage==0 ){
          sqlite3BeginBenignMalloc();
          if( pagerLockDb(pPager, RESERVED_LOCK)==SQLITE_OK ){
            sqlite3OsDelete(pVfs, pPager->zJournal, 0);
            pagerUnlockDb(pPager, SHARED_LOCK);
          }
          sqlite3EndBenignMalloc();
        }else{
          /* The journal file exists and no other connection has a reserved
          ** or greater lock on the database file. Now check that there is
          ** at least one non-zero bytes at the start of the journal file.
          ** If there is, then we consider this journal to be hot. If not, 







|







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




































472

  }
} {normal 1 2 3 2 3 4 5 6 7 11 12 13 12 13 14 15 16 17}
do_test exclusive-5.7 {
  # Just the db open.
  set sqlite_open_file_count
  expr $sqlite_open_file_count-$extrafds
} {1}





































finish_test









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
  }
} {normal 1 2 3 2 3 4 5 6 7 11 12 13 12 13 14 15 16 17}
do_test exclusive-5.7 {
  # Just the db open.
  set sqlite_open_file_count
  expr $sqlite_open_file_count-$extrafds
} {1}

#-------------------------------------------------------------------------

do_execsql_test exclusive-6.1 {
  CREATE TABLE t4(a, b);
  INSERT INTO t4 VALUES('Eden', 1955);
  BEGIN;
    INSERT INTO t4 VALUES('Macmillan', 1957);
    INSERT INTO t4 VALUES('Douglas-Home', 1963);
    INSERT INTO t4 VALUES('Wilson', 1964);
}
do_test exclusive-6.2 {
  forcedelete test2.db test2.db-journal
  file copy test.db test2.db
  file copy test.db-journal test2.db-journal
  sqlite3 db test2.db
} {}

do_execsql_test exclusive-6.3 {
  PRAGMA locking_mode = EXCLUSIVE;
  SELECT * FROM t4;
} {exclusive Eden 1955}

do_test exclusive-6.4 {
  db close
  forcedelete test.db test.db-journal
  set fd [open test.db-journal w]
  puts $fd x
  close $fd
  sqlite3 db test.db
} {}

do_execsql_test exclusive-6.5 {
  PRAGMA locking_mode = EXCLUSIVE;
  SELECT * FROM sqlite_master;
} {}

finish_test