/ Check-in [8e65c0e3]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Add further test cases. Fix an assert() in pager.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8e65c0e3dac400f6a0ec3b7494fba62c14ed6182
User & Date: dan 2010-06-30 10:36:19
Context
2010-07-01
15:09
Add pager test cases. Change a condition in pager.c to NEVER(). check-in: a8f6341d user: dan tags: trunk
2010-06-30
10:36
Add further test cases. Fix an assert() in pager.c. check-in: 8e65c0e3 user: dan tags: trunk
04:36
Do not call pager_open_journal() from within PagerBegin() if the connection is in exclusive-access mode. It will be called from within PagerWrite() just as it is for non-exclusive mode anyway. check-in: cdf2c5c2 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

  5287   5287     ** to the database file. So there is no need to zero the journal 
  5288   5288     ** header. Since the pager is in exclusive mode, there is no need
  5289   5289     ** to drop any locks either.
  5290   5290     */
  5291   5291     if( pPager->dbModified==0 && pPager->exclusiveMode 
  5292   5292      && pPager->journalMode==PAGER_JOURNALMODE_PERSIST
  5293   5293     ){
  5294         -    assert( pPager->journalOff==JOURNAL_HDR_SZ(pPager) );
         5294  +    assert( pPager->journalOff==JOURNAL_HDR_SZ(pPager) || !pPager->journalOff );
  5295   5295       return SQLITE_OK;
  5296   5296     }
  5297   5297   
  5298   5298     PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
  5299   5299     assert( pPager->state==PAGER_SYNCED || MEMDB || !pPager->dbModified );
  5300   5300     rc = pager_end_transaction(pPager, pPager->setMaster);
  5301   5301     return pager_error(pPager, rc);

Added test/notify3.test.

            1  +# 2010 June 30
            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.  The
           12  +# focus of this file is testing the sqlite3_unlock_notify() API.
           13  +#
           14  +
           15  +set testdir [file dirname $argv0]
           16  +source $testdir/tester.tcl
           17  +
           18  +set esc [sqlite3_enable_shared_cache 1]
           19  +
           20  +sqlite3 db  test.db
           21  +file delete -force test.db2 test.db2-journal test.db2-wal
           22  +sqlite3 db2 test.db2
           23  +
           24  +do_test notify3-1.1 {
           25  +  execsql { 
           26  +    CREATE TABLE t1(a, b); 
           27  +    INSERT INTO t1 VALUES('t1 A', 't1 B');
           28  +  }
           29  +} {}
           30  +do_test notify3-1.2 {
           31  +  execsql { 
           32  +    CREATE TABLE t2(a, b);
           33  +    INSERT INTO t2 VALUES('t2 A', 't2 B');
           34  +  } db2
           35  +} {}
           36  +
           37  +do_test notify3-1.3 {
           38  +  execsql { 
           39  +    BEGIN EXCLUSIVE;
           40  +    INSERT INTO t2 VALUES('t2 C', 't2 D');
           41  +  } db2
           42  +} {}
           43  +do_test notify3-1.4 {
           44  +  catchsql { ATTACH 'test.db2' AS aux }
           45  +} {0 {}}
           46  +do_test notify3-1.5 {
           47  +  catchsql { SELECT * FROM t2 }
           48  +} {1 {database schema is locked: aux}}
           49  +
           50  +do_test notify3-1.6 {
           51  +  list [sqlite3_errcode db] [sqlite3_extended_errcode db]
           52  +} {SQLITE_LOCKED SQLITE_LOCKED_SHAREDCACHE}
           53  +
           54  +do_test notify3-1.7 {
           55  +  sqlite3_extended_result_codes db 1
           56  +  catch { set ::stmt [sqlite3_prepare_v2 db "SELECT * FROM t2" -1 tail] } msg
           57  +  set msg
           58  +} {(262) database schema is locked: aux}
           59  +
           60  +do_test notify3-1.8 {
           61  +  set ::when 1
           62  +  db unlock_notify { set ::res $::when }
           63  +  set ::when 2
           64  +  execsql { COMMIT } db2
           65  +  set ::res
           66  +} {2}
           67  +do_test notify3-1.9 {
           68  +  catchsql { SELECT * FROM t2 }
           69  +} {0 {{t2 A} {t2 B} {t2 C} {t2 D}}}
           70  +
           71  +sqlite3_enable_shared_cache $esc
           72  +finish_test
           73  +

Changes to test/pager1.test.

   277    277     10 { PRAGMA synchronous = NORMAL } { }
   278    278     11 { PRAGMA synchronous = OFF } { }
   279    279     12 { PRAGMA synchronous = FULL ; PRAGMA fullfsync = 1 } { }
   280    280     13 { PRAGMA synchronous = FULL } {
   281    281       testvfs tv -default 1
   282    282       tv devchar sequential
   283    283     }
          284  +  14 { PRAGMA locking_mode = EXCLUSIVE } {
          285  +  }
   284    286   } {
   285    287     do_test pager1-3.$tn.1 {
   286    288       eval $tcl
   287    289       faultsim_delete_and_reopen
   288    290       db func a_string a_string
   289    291       execsql $sql
   290    292       execsql {
................................................................................
  1673   1675                       ma, mb, mc, md, me, mf, mg, mh, mi, mj, mk, ml, mm, mn
  1674   1676       );
  1675   1677       INSERT INTO t1(aa) VALUES( a_string(100000) );
  1676   1678       INSERT INTO t2(aa) VALUES( a_string(100000) );
  1677   1679       VACUUM;
  1678   1680     }
  1679   1681   } {}
         1682  +
         1683  +#-------------------------------------------------------------------------
         1684  +# Test a couple of special cases that come up while committing 
         1685  +# transactions:
         1686  +#
         1687  +#   pager1-20.1.*: Committing an in-memory database transaction when the 
         1688  +#                  database has not been modified at all.
         1689  +#
         1690  +#   pager1-20.2.*: As above, but with a normal db in exclusive-locking mode.
         1691  +#
         1692  +#   pager1-20.3.*: Committing a transaction in WAL mode where the database has
         1693  +#                  been modified, but all dirty pages have been flushed to 
         1694  +#                  disk before the commit.
         1695  +#
         1696  +do_test pager1-20.1.1 {
         1697  +  catch {db close}
         1698  +  sqlite3 db :memory:
         1699  +  execsql {
         1700  +    CREATE TABLE one(two, three);
         1701  +    INSERT INTO one VALUES('a', 'b');
         1702  +  }
         1703  +} {}
         1704  +do_test pager1-20.1.2 {
         1705  +  execsql {
         1706  +    BEGIN EXCLUSIVE;
         1707  +    COMMIT;
         1708  +  }
         1709  +} {}
         1710  +
         1711  +do_test pager1-20.2.1 {
         1712  +  faultsim_delete_and_reopen
         1713  +  execsql {
         1714  +    PRAGMA locking_mode = exclusive;
         1715  +    PRAGMA journal_mode = persist;
         1716  +    CREATE TABLE one(two, three);
         1717  +    INSERT INTO one VALUES('a', 'b');
         1718  +  }
         1719  +} {exclusive persist}
         1720  +do_test pager1-20.2.2 {
         1721  +  execsql {
         1722  +    BEGIN EXCLUSIVE;
         1723  +    COMMIT;
         1724  +  }
         1725  +} {}
         1726  +
         1727  +do_test pager1-20.3.1 {
         1728  +  faultsim_delete_and_reopen
         1729  +  db func a_string a_string
         1730  +  execsql {
         1731  +    PRAGMA cache_size = 10;
         1732  +    PRAGMA journal_mode = wal;
         1733  +    BEGIN;
         1734  +      CREATE TABLE t1(x);
         1735  +      CREATE TABLE t2(y);
         1736  +      INSERT INTO t1 VALUES(a_string(800));
         1737  +      INSERT INTO t1 SELECT a_string(800) FROM t1;         /*   2 */
         1738  +      INSERT INTO t1 SELECT a_string(800) FROM t1;         /*   4 */
         1739  +      INSERT INTO t1 SELECT a_string(800) FROM t1;         /*   8 */
         1740  +      INSERT INTO t1 SELECT a_string(800) FROM t1;         /*  16 */
         1741  +      INSERT INTO t1 SELECT a_string(800) FROM t1;         /*  32 */
         1742  +    COMMIT;
         1743  +  }
         1744  +} {wal}
         1745  +do_test pager1-20.3.2 {
         1746  +  proc recursive_select {id} {
         1747  +    db eval {SELECT rowid, x FROM t1 WHERE rowid = ($id-1)} {
         1748  +      recursive_select $rowid
         1749  +    }
         1750  +  }
         1751  +  execsql {
         1752  +    BEGIN;
         1753  +    INSERT INTO t2 VALUES('xxxx');
         1754  +  }
         1755  +  recursive_select 32
         1756  +  execsql COMMIT
         1757  +} {}
         1758  +
         1759  +  
  1680   1760   
  1681   1761   finish_test
  1682   1762   

Changes to test/pagerfault.test.

   609    609   do_faultsim_test pagerfault-13 -prep {
   610    610     faultsim_restore_and_reopen
   611    611   } -body {
   612    612     execsql { CREATE TABLE xx(a, b) }
   613    613   } -test {
   614    614     faultsim_test_result {0 {}}
   615    615   }
          616  +
          617  +}
          618  +
   616    619   
   617    620   #---------------------------------------------------------------------------
   618    621   # Test fault injection into a small backup operation.
   619    622   #
   620    623   do_test pagerfault-14-pre1 {
   621    624     faultsim_delete_and_reopen
   622    625     db func a_string a_string;
................................................................................
   628    631         CREATE TABLE two.t2(x, y UNIQUE);
   629    632         INSERT INTO t1 VALUES(a_string(333), a_string(444));
   630    633         INSERT INTO t2 VALUES(a_string(333), a_string(444));
   631    634       COMMIT;
   632    635     }
   633    636     faultsim_save_and_close
   634    637   } {}
   635         -do_faultsim_test pagerfault-14 -prep {
          638  +
          639  +do_faultsim_test pagerfault-14a -prep {
   636    640     faultsim_restore_and_reopen
   637    641   } -body {
   638    642     if {[catch {db backup test.db2} msg]} { error [regsub {.*: } $msg {}] }
   639    643   } -test {
   640    644     faultsim_test_result {0 {}} {1 {}} {1 {SQL logic error or missing database}}
          645  +}
          646  +do_faultsim_test pagerfault-14b -prep {
          647  +  faultsim_restore_and_reopen
          648  +  sqlite3 db2 ""
          649  +  db2 eval { PRAGMA page_size = 4096; CREATE TABLE xx(a) }
          650  +} -body {
          651  +  sqlite3_backup B db2 main db main
          652  +  B step 200
          653  +  set rc [B finish]
          654  +  if {[string match SQLITE_IOERR_* $rc]} {set rc SQLITE_IOERR}
          655  +  if {$rc != "SQLITE_OK"} { error [sqlite3_test_errstr $rc] }
          656  +  set {} {}
          657  +} -test {
          658  +  faultsim_test_result {0 {}}
   641    659   }
   642    660   
   643    661   do_test pagerfault-15-pre1 {
   644    662     faultsim_delete_and_reopen
   645    663     db func a_string a_string;
   646    664     execsql {
   647    665       BEGIN;
................................................................................
   663    681       }
   664    682     }
   665    683   } -test {
   666    684     faultsim_test_result {0 {}}
   667    685     faultsim_integrity_check
   668    686   }
   669    687   
   670         -}
   671    688   
   672    689   do_test pagerfault-16-pre1 {
   673    690     faultsim_delete_and_reopen
   674    691     execsql { CREATE TABLE t1(x, y UNIQUE) }
   675    692     faultsim_save_and_close
   676    693   } {}
   677    694   do_faultsim_test pagerfault-16 -prep {