os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/ioerr4.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/ioerr4.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,100 @@
     1.4 +# 2007 December 19
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this file is testing for correct handling of I/O errors
    1.16 +# during incremental vacuum with a shared cache.
    1.17 +#
    1.18 +# $Id: ioerr4.test,v 1.2 2008/05/08 01:11:42 drh Exp $
    1.19 +
    1.20 +set testdir [file dirname $argv0]
    1.21 +source $testdir/tester.tcl
    1.22 +
    1.23 +# This test requires both shared cache and incremental vacuum.
    1.24 +#
    1.25 +ifcapable {!shared_cache || !autovacuum} {
    1.26 +  finish_test
    1.27 +  return
    1.28 +}
    1.29 +
    1.30 +# Enable shared cache mode and incremental vacuum.
    1.31 +#
    1.32 +do_test ioerr4-1.1 {
    1.33 +  db close
    1.34 +  set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
    1.35 +} {0}
    1.36 +do_test ioerr4-1.2 {
    1.37 +  file delete -force test.db test.db-journal
    1.38 +  sqlite3 db test.db
    1.39 +  sqlite3 db2 test.db
    1.40 +  db eval {
    1.41 +    PRAGMA auto_vacuum=INCREMENTAL;
    1.42 +    CREATE TABLE a(i INTEGER, b BLOB);
    1.43 +  }
    1.44 +  db2 eval {
    1.45 +    SELECT name FROM sqlite_master
    1.46 +  }
    1.47 +} {a}
    1.48 +do_test ioerr4-1.3 {
    1.49 +  db eval {
    1.50 +    PRAGMA auto_vacuum;
    1.51 +  }
    1.52 +} {2}
    1.53 +
    1.54 +# Insert and delete many records in order to put lots of pages
    1.55 +# on the freelist.
    1.56 +#
    1.57 +do_test ioerr4-1.4 {
    1.58 +  db eval {
    1.59 +    INSERT INTO a VALUES(1, zeroblob(2000));
    1.60 +    INSERT INTO a VALUES(2, zeroblob(2000));
    1.61 +    INSERT INTO a SELECT i+2, zeroblob(2000) FROM a;
    1.62 +    INSERT INTO a SELECT i+4, zeroblob(2000) FROM a;
    1.63 +    INSERT INTO a SELECT i+8, zeroblob(2000) FROM a;
    1.64 +    INSERT INTO a SELECT i+16, zeroblob(2000) FROM a;
    1.65 +    SELECT count(*) FROM a;
    1.66 +  }
    1.67 +} {32}
    1.68 +do_test ioerr4-1.5 {
    1.69 +  db eval {
    1.70 +    PRAGMA freelist_count
    1.71 +  }
    1.72 +} {0}
    1.73 +do_test ioerr4-1.6 {
    1.74 +  db eval {
    1.75 +    DELETE FROM a;
    1.76 +    PRAGMA freelist_count;
    1.77 +  }
    1.78 +} {64}
    1.79 +
    1.80 +# Set up for an I/O error on incremental vacuum
    1.81 +# with two connections on shared cache.
    1.82 +#
    1.83 +db close
    1.84 +db2 close
    1.85 +file copy -force test.db test.db-bu
    1.86 +do_ioerr_test ioerr4-2 -tclprep {
    1.87 +  catch {db2 close}
    1.88 +  db close
    1.89 +  file delete -force test.db test.db-journal
    1.90 +  file copy -force test.db-bu test.db
    1.91 +  sqlite3_enable_shared_cache 1
    1.92 +  set ::DB [sqlite3 db test.db; sqlite3_connection_pointer db]
    1.93 +  db eval {PRAGMA auto_vacuum=INCREMENTAL}
    1.94 +  sqlite3 db2 test.db
    1.95 +} -tclbody {
    1.96 +  db eval {PRAGMA incremental_vacuum(5)}
    1.97 +}
    1.98 +
    1.99 +db2 close
   1.100 +file delete -force test.db-bu
   1.101 +sqlite3_enable_shared_cache $::enable_shared_cache
   1.102 +
   1.103 +finish_test