1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/jrnlmode.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,411 @@
1.4 +# 2008 April 17
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 focus
1.15 +# of these tests is the journal mode pragma.
1.16 +#
1.17 +# $Id: jrnlmode.test,v 1.6 2008/09/26 21:08:08 drh Exp $
1.18 +
1.19 +set testdir [file dirname $argv0]
1.20 +source $testdir/tester.tcl
1.21 +
1.22 +ifcapable {!pager_pragmas} {
1.23 + finish_test
1.24 + return
1.25 +}
1.26 +
1.27 +#----------------------------------------------------------------------
1.28 +# Test cases jrnlmode-1.X test the PRAGMA logic.
1.29 +#
1.30 +do_test jrnlmode-1.0 {
1.31 + execsql {
1.32 + PRAGMA journal_mode;
1.33 + PRAGMA main.journal_mode;
1.34 + PRAGMA temp.journal_mode;
1.35 + }
1.36 +} [list delete delete delete]
1.37 +do_test jrnlmode-1.1 {
1.38 + execsql {
1.39 + PRAGMA journal_mode = persist;
1.40 + }
1.41 +} {persist}
1.42 +do_test jrnlmode-1.2 {
1.43 + execsql {
1.44 + PRAGMA journal_mode;
1.45 + PRAGMA main.journal_mode;
1.46 + PRAGMA temp.journal_mode;
1.47 + }
1.48 +} [list persist persist persist]
1.49 +do_test jrnlmode-1.4 {
1.50 + execsql {
1.51 + PRAGMA journal_mode = off;
1.52 + }
1.53 +} {off}
1.54 +do_test jrnlmode-1.5 {
1.55 + execsql {
1.56 + PRAGMA journal_mode;
1.57 + PRAGMA main.journal_mode;
1.58 + PRAGMA temp.journal_mode;
1.59 + }
1.60 +} {off off off}
1.61 +do_test jrnlmode-1.6 {
1.62 + execsql {
1.63 + PRAGMA journal_mode = delete;
1.64 + }
1.65 +} {delete}
1.66 +do_test jrnlmode-1.7 {
1.67 + execsql {
1.68 + PRAGMA journal_mode;
1.69 + PRAGMA main.journal_mode;
1.70 + PRAGMA temp.journal_mode;
1.71 + }
1.72 +} {delete delete delete}
1.73 +do_test jrnlmode-1.7.1 {
1.74 + execsql {
1.75 + PRAGMA journal_mode = truncate;
1.76 + }
1.77 +} {truncate}
1.78 +do_test jrnlmode-1.7.2 {
1.79 + execsql {
1.80 + PRAGMA journal_mode;
1.81 + PRAGMA main.journal_mode;
1.82 + PRAGMA temp.journal_mode;
1.83 + }
1.84 +} {truncate truncate truncate}
1.85 +do_test jrnlmode-1.8 {
1.86 + execsql {
1.87 + PRAGMA journal_mode = off;
1.88 + PRAGMA journal_mode = invalid;
1.89 + }
1.90 +} {off off}
1.91 +ifcapable attach {
1.92 + do_test jrnlmode-1.9 {
1.93 + execsql {
1.94 + PRAGMA journal_mode = PERSIST;
1.95 + ATTACH ':memory:' as aux1;
1.96 + }
1.97 + execsql {
1.98 + PRAGMA main.journal_mode;
1.99 + PRAGMA aux1.journal_mode;
1.100 + }
1.101 + } {persist persist}
1.102 + do_test jrnlmode-1.10 {
1.103 + execsql {
1.104 + PRAGMA main.journal_mode = OFF;
1.105 + }
1.106 + execsql {
1.107 + PRAGMA main.journal_mode;
1.108 + PRAGMA temp.journal_mode;
1.109 + PRAGMA aux1.journal_mode;
1.110 + }
1.111 + } {off persist persist}
1.112 + do_test jrnlmode-1.11 {
1.113 + execsql {
1.114 + PRAGMA journal_mode;
1.115 + }
1.116 + } {persist}
1.117 + do_test jrnlmode-1.12 {
1.118 + execsql {
1.119 + ATTACH ':memory:' as aux2;
1.120 + }
1.121 + execsql {
1.122 + PRAGMA main.journal_mode;
1.123 + PRAGMA aux1.journal_mode;
1.124 + PRAGMA aux2.journal_mode;
1.125 + }
1.126 + } {off persist persist}
1.127 + do_test jrnlmode-1.11 {
1.128 + execsql {
1.129 + PRAGMA aux1.journal_mode = DELETE;
1.130 + }
1.131 + execsql {
1.132 + PRAGMA main.journal_mode;
1.133 + PRAGMA aux1.journal_mode;
1.134 + PRAGMA aux2.journal_mode;
1.135 + }
1.136 + } {off delete persist}
1.137 + do_test jrnlmode-1.12 {
1.138 + execsql {
1.139 + PRAGMA journal_mode = delete;
1.140 + }
1.141 + execsql {
1.142 + PRAGMA main.journal_mode;
1.143 + PRAGMA temp.journal_mode;
1.144 + PRAGMA aux1.journal_mode;
1.145 + PRAGMA aux2.journal_mode;
1.146 + }
1.147 + } {delete delete delete delete}
1.148 + do_test jrnlmode-1.13 {
1.149 + execsql {
1.150 + ATTACH ':memory:' as aux3;
1.151 + }
1.152 + execsql {
1.153 + PRAGMA main.journal_mode;
1.154 + PRAGMA temp.journal_mode;
1.155 + PRAGMA aux1.journal_mode;
1.156 + PRAGMA aux2.journal_mode;
1.157 + PRAGMA aux3.journal_mode;
1.158 + }
1.159 + } {delete delete delete delete delete}
1.160 + do_test jrnlmode-1.14 {
1.161 + execsql {
1.162 + PRAGMA journal_mode = TRUNCATE;
1.163 + }
1.164 + execsql {
1.165 + PRAGMA main.journal_mode;
1.166 + PRAGMA temp.journal_mode;
1.167 + PRAGMA aux1.journal_mode;
1.168 + PRAGMA aux2.journal_mode;
1.169 + PRAGMA aux3.journal_mode;
1.170 + }
1.171 + } {truncate truncate truncate truncate truncate}
1.172 +
1.173 + do_test jrnlmode-1.99 {
1.174 + execsql {
1.175 + DETACH aux1;
1.176 + DETACH aux2;
1.177 + DETACH aux3;
1.178 + }
1.179 + } {}
1.180 +}
1.181 +
1.182 +ifcapable attach {
1.183 + file delete -force test2.db
1.184 + do_test jrnlmode-2.1 {
1.185 + execsql {
1.186 + ATTACH 'test2.db' AS aux;
1.187 + PRAGMA main.journal_mode = persist;
1.188 + PRAGMA aux.journal_mode = persist;
1.189 + CREATE TABLE abc(a, b, c);
1.190 + CREATE TABLE aux.def(d, e, f);
1.191 + }
1.192 + execsql {
1.193 + BEGIN;
1.194 + INSERT INTO abc VALUES(1, 2, 3);
1.195 + INSERT INTO def VALUES(4, 5, 6);
1.196 + COMMIT;
1.197 + }
1.198 + list [file exists test.db-journal] [file exists test2.db-journal]
1.199 + } {1 1}
1.200 +
1.201 + do_test jrnlmode-2.2 {
1.202 + file size test.db-journal
1.203 + } {0}
1.204 +
1.205 + do_test jrnlmode-2.3 {
1.206 + execsql {
1.207 + SELECT * FROM abc;
1.208 + }
1.209 + } {1 2 3}
1.210 +
1.211 + do_test jrnlmode-2.4 {
1.212 + file size test.db-journal
1.213 + } {0}
1.214 +
1.215 + do_test jrnlmode-2.5 {
1.216 + execsql {
1.217 + SELECT * FROM def;
1.218 + }
1.219 + } {4 5 6}
1.220 +
1.221 +#----------------------------------------------------------------------
1.222 +# Test caes jrnlmode-3.X verify that ticket #3127 has been fixed.
1.223 +#
1.224 + db close
1.225 + file delete -force test2.db
1.226 + file delete -force test.db
1.227 + sqlite3 db test.db
1.228 +
1.229 + do_test jrnlmode-3.1 {
1.230 + execsql {
1.231 + CREATE TABLE x(n INTEGER);
1.232 + ATTACH 'test2.db' AS a;
1.233 + create table a.x ( n integer );
1.234 + insert into a.x values(1);
1.235 + insert into a.x values (2);
1.236 + insert into a.x values (3);
1.237 + insert into a.x values (4);
1.238 + }
1.239 + } {}
1.240 +
1.241 + do_test jrnlmode-3.2 {
1.242 + execsql { PRAGMA journal_mode=off; }
1.243 + execsql {
1.244 + BEGIN IMMEDIATE;
1.245 + INSERT OR IGNORE INTO main.x SELECT * FROM a.x;
1.246 + COMMIT;
1.247 + }
1.248 + } {}
1.249 +}
1.250 +
1.251 +ifcapable autovacuum&&pragma {
1.252 + db close
1.253 + file delete -force test.db
1.254 + sqlite3 db test.db
1.255 + do_test jrnlmode-4.1 {
1.256 + execsql {
1.257 + PRAGMA cache_size = 1;
1.258 + PRAGMA auto_vacuum = 1;
1.259 + CREATE TABLE abc(a, b, c);
1.260 + }
1.261 + execsql { PRAGMA page_count }
1.262 + } {3}
1.263 +
1.264 + do_test jrnlmode-4.2 {
1.265 + execsql { PRAGMA journal_mode = off }
1.266 + } {off}
1.267 +
1.268 + do_test jrnlmode-4.3 {
1.269 + execsql { INSERT INTO abc VALUES(1, 2, randomblob(2000)) }
1.270 + } {}
1.271 +
1.272 + # This will attempt to truncate the database file. Check that this
1.273 + # is not a problem when journal_mode=off.
1.274 + do_test jrnlmode-4.4 {
1.275 + execsql { DELETE FROM abc }
1.276 + } {}
1.277 +
1.278 + integrity_check jrnlmode-4.5
1.279 +}
1.280 +
1.281 +#------------------------------------------------------------------------
1.282 +# The following test caes, jrnlmode-5.*, test the journal_size_limit
1.283 +# pragma.
1.284 +ifcapable pragma {
1.285 + db close
1.286 + file delete -force test.db test2.db test3.db
1.287 + sqlite3 db test.db
1.288 +
1.289 + do_test jrnlmode-5.1 {
1.290 + execsql {pragma page_size=1024}
1.291 + execsql {pragma journal_mode=persist}
1.292 + } {persist}
1.293 +
1.294 + do_test jrnlmode-5.2 {
1.295 + execsql { PRAGMA journal_size_limit }
1.296 + } {-1}
1.297 + do_test jrnlmode-5.3 {
1.298 + execsql {
1.299 + ATTACH 'test2.db' AS aux;
1.300 + PRAGMA aux.journal_size_limit;
1.301 + }
1.302 + } {-1}
1.303 + do_test jrnlmode-5.4 {
1.304 + execsql { PRAGMA aux.journal_size_limit = 10240 }
1.305 + } {10240}
1.306 + do_test jrnlmode-5.5 {
1.307 + execsql { PRAGMA main.journal_size_limit = 20480 }
1.308 + } {20480}
1.309 + do_test jrnlmode-5.6 {
1.310 + execsql { PRAGMA journal_size_limit }
1.311 + } {20480}
1.312 + do_test jrnlmode-5.7 {
1.313 + execsql { PRAGMA aux.journal_size_limit }
1.314 + } {10240}
1.315 +
1.316 + do_test jrnlmode-5.8 {
1.317 + execsql { ATTACH 'test3.db' AS aux2 }
1.318 + } {}
1.319 +
1.320 + do_test jrnlmode-5.9 {
1.321 + execsql {
1.322 + CREATE TABLE main.t1(a, b, c);
1.323 + CREATE TABLE aux.t2(a, b, c);
1.324 + CREATE TABLE aux2.t3(a, b, c);
1.325 + }
1.326 + } {}
1.327 + do_test jrnlmode-5.10 {
1.328 + list \
1.329 + [file exists test.db-journal] \
1.330 + [file exists test2.db-journal] \
1.331 + [file exists test3.db-journal]
1.332 + } {1 1 1}
1.333 + do_test jrnlmode-5.11 {
1.334 + execsql {
1.335 + BEGIN;
1.336 + INSERT INTO t3 VALUES(randomblob(1000),randomblob(1000),randomblob(1000));
1.337 + INSERT INTO t3
1.338 + SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
1.339 + INSERT INTO t3
1.340 + SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
1.341 + INSERT INTO t3
1.342 + SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
1.343 + INSERT INTO t3
1.344 + SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
1.345 + INSERT INTO t3
1.346 + SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
1.347 + INSERT INTO t2 SELECT * FROM t3;
1.348 + INSERT INTO t1 SELECT * FROM t2;
1.349 + COMMIT;
1.350 + }
1.351 + list \
1.352 + [file exists test.db-journal] \
1.353 + [file exists test2.db-journal] \
1.354 + [file exists test3.db-journal] \
1.355 + [file size test.db-journal] \
1.356 + [file size test2.db-journal] \
1.357 + [file size test3.db-journal]
1.358 + } {1 1 1 0 0 0}
1.359 +
1.360 + do_test jrnlmode-5.12 {
1.361 + execsql {
1.362 + BEGIN;
1.363 + UPDATE t1 SET a = randomblob(1000);
1.364 + }
1.365 + expr {[file size test.db-journal]>30000}
1.366 + } {1}
1.367 + do_test jrnlmode-5.13 {
1.368 + execsql COMMIT
1.369 + file size test.db-journal
1.370 + } {20480}
1.371 +
1.372 + do_test jrnlmode-5.14 {
1.373 + execsql {
1.374 + BEGIN;
1.375 + UPDATE t2 SET a = randomblob(1000);
1.376 + }
1.377 + expr {[file size test2.db-journal]>30000}
1.378 + } {1}
1.379 + do_test jrnlmode-5.15 {
1.380 + execsql COMMIT
1.381 + file size test2.db-journal
1.382 + } {10240}
1.383 +
1.384 + do_test jrnlmode-5.16 {
1.385 + execsql {
1.386 + BEGIN;
1.387 + UPDATE t3 SET a = randomblob(1000);
1.388 + }
1.389 + set journalsize [file size test3.db-journal]
1.390 + expr {$journalsize>30000}
1.391 + } {1}
1.392 + do_test jrnlmode-5.17 {
1.393 + execsql COMMIT
1.394 + set sz [file size test3.db-journal]
1.395 + expr {$sz>=$journalsize}
1.396 + } {1}
1.397 +
1.398 + do_test jrnlmode-5.18 {
1.399 + execsql {
1.400 + PRAGMA journal_size_limit = -4;
1.401 + BEGIN;
1.402 + UPDATE t1 SET a = randomblob(1000);
1.403 + }
1.404 + set journalsize [file size test.db-journal]
1.405 + expr {$journalsize>30000}
1.406 + } {1}
1.407 + do_test jrnlmode-5.19 {
1.408 + execsql COMMIT
1.409 + set sz [file size test.db-journal]
1.410 + expr {$sz>=$journalsize}
1.411 + } {1}
1.412 +}
1.413 +
1.414 +finish_test