os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vacuum2.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/vacuum2.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,162 @@
     1.4 +# 2005 February 15
     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 the VACUUM statement.
    1.16 +#
    1.17 +# $Id: vacuum2.test,v 1.8 2008/08/23 16:17:56 danielk1977 Exp $
    1.18 +
    1.19 +set testdir [file dirname $argv0]
    1.20 +source $testdir/tester.tcl
    1.21 +
    1.22 +# If the VACUUM statement is disabled in the current build, skip all
    1.23 +# the tests in this file.
    1.24 +#
    1.25 +ifcapable {!vacuum||!autoinc} {
    1.26 +  finish_test
    1.27 +  return
    1.28 +}
    1.29 +if $AUTOVACUUM {
    1.30 +  finish_test
    1.31 +  return
    1.32 +}
    1.33 +
    1.34 +# Ticket #1121 - make sure vacuum works if all autoincrement tables
    1.35 +# have been deleted.
    1.36 +#
    1.37 +do_test vacuum2-1.1 {
    1.38 +  execsql {
    1.39 +    CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
    1.40 +    DROP TABLE t1;
    1.41 +    VACUUM;
    1.42 +  }
    1.43 +} {}
    1.44 +
    1.45 +# Ticket #2518.  Make sure vacuum increments the change counter
    1.46 +# in the database header.
    1.47 +#
    1.48 +do_test vacuum2-2.1 {
    1.49 +  execsql {
    1.50 +    CREATE TABLE t1(x);
    1.51 +    CREATE TABLE t2(y);
    1.52 +    INSERT INTO t1 VALUES(1);
    1.53 +  }
    1.54 +  hexio_get_int [hexio_read test.db 24 4]
    1.55 +} [expr {[hexio_get_int [hexio_read test.db 24 4]]+3}]
    1.56 +do_test vacuum2-2.1 {
    1.57 +  execsql {
    1.58 +    VACUUM
    1.59 +  }
    1.60 +  hexio_get_int [hexio_read test.db 24 4]
    1.61 +} [expr {[hexio_get_int [hexio_read test.db 24 4]]+1}]
    1.62 +
    1.63 +############################################################################
    1.64 +# Verify that we can use the auto_vacuum pragma to request a new
    1.65 +# autovacuum setting, do a VACUUM, and the new setting takes effect.
    1.66 +# Make sure this happens correctly even if there are multiple open
    1.67 +# connections to the same database file.
    1.68 +#
    1.69 +sqlite3 db2 test.db
    1.70 +set pageSize [db eval {pragma page_size}]
    1.71 +
    1.72 +# We are currently not autovacuuming so the database should be 3 pages
    1.73 +# in size.  1 page for each of sqlite_master, t1, and t2.
    1.74 +#
    1.75 +do_test vacuum2-3.1 {
    1.76 +  execsql {
    1.77 +    INSERT INTO t1 VALUES('hello');
    1.78 +    INSERT INTO t2 VALUES('out there');
    1.79 +  }
    1.80 +  expr {[file size test.db]/$pageSize}
    1.81 +} {3}
    1.82 +set cksum [cksum]
    1.83 +do_test vacuum2-3.2 {
    1.84 +  cksum db2
    1.85 +} $cksum
    1.86 +
    1.87 +# Convert the database to an autovacuumed database.
    1.88 +do_test vacuum2-3.3 {
    1.89 +  execsql {
    1.90 +    PRAGMA auto_vacuum=FULL;
    1.91 +    VACUUM;
    1.92 +  }
    1.93 +  expr {[file size test.db]/$pageSize}
    1.94 +} {4}
    1.95 +do_test vacuum2-3.4 {
    1.96 +  cksum db2
    1.97 +} $cksum
    1.98 +do_test vacuum2-3.5 {
    1.99 +  cksum
   1.100 +} $cksum
   1.101 +do_test vacuum2-3.6 {
   1.102 +  execsql {PRAGMA integrity_check} db2
   1.103 +} {ok}
   1.104 +do_test vacuum2-3.7 {
   1.105 +  execsql {PRAGMA integrity_check} db
   1.106 +} {ok}
   1.107 +
   1.108 +# Convert the database back to a non-autovacuumed database.
   1.109 +do_test vacuum2-3.13 {
   1.110 +  execsql {
   1.111 +    PRAGMA auto_vacuum=NONE;
   1.112 +    VACUUM;
   1.113 +  }
   1.114 +  expr {[file size test.db]/$pageSize}
   1.115 +} {3}
   1.116 +do_test vacuum2-3.14 {
   1.117 +  cksum db2
   1.118 +} $cksum
   1.119 +do_test vacuum2-3.15 {
   1.120 +  cksum
   1.121 +} $cksum
   1.122 +do_test vacuum2-3.16 {
   1.123 +  execsql {PRAGMA integrity_check} db2
   1.124 +} {ok}
   1.125 +do_test vacuum2-3.17 {
   1.126 +  execsql {PRAGMA integrity_check} db
   1.127 +} {ok}
   1.128 +
   1.129 +db2 close
   1.130 +
   1.131 +ifcapable autovacuum {
   1.132 +  do_test vacuum2-4.1 {
   1.133 +    db close
   1.134 +    file delete -force test.db
   1.135 +    sqlite3 db test.db
   1.136 +    execsql {
   1.137 +      pragma auto_vacuum=1;
   1.138 +      create table t(a, b);
   1.139 +      insert into t values(1, 2);
   1.140 +      insert into t values(1, 2);
   1.141 +      pragma auto_vacuum=0;
   1.142 +      vacuum;
   1.143 +      pragma auto_vacuum;
   1.144 +    }
   1.145 +  } {0}
   1.146 +  do_test vacuum2-4.2 {
   1.147 +    execsql {
   1.148 +      pragma auto_vacuum=1;
   1.149 +      vacuum;
   1.150 +      pragma auto_vacuum;
   1.151 +    }
   1.152 +  } {1}
   1.153 +  do_test vacuum2-4.3 {
   1.154 +    execsql {
   1.155 +      pragma integrity_check
   1.156 +    }
   1.157 +  } {ok}
   1.158 +  do_test vacuum2-4.4 {
   1.159 +    execsql {
   1.160 +      pragma auto_vacuum;
   1.161 +    }
   1.162 +  } {1}
   1.163 +}
   1.164 +
   1.165 +finish_test