1165ffe97Sdrh# 2005 March 15 2165ffe97Sdrh# 3165ffe97Sdrh# The author disclaims copyright to this source code. In place of 4165ffe97Sdrh# a legal notice, here is a blessing: 5165ffe97Sdrh# 6165ffe97Sdrh# May you do good and not evil. 7165ffe97Sdrh# May you find forgiveness for yourself and forgive others. 8165ffe97Sdrh# May you share freely, never taking more than you give. 9165ffe97Sdrh# 10165ffe97Sdrh#*********************************************************************** 11165ffe97Sdrh# This file implements regression tests for SQLite library. 12165ffe97Sdrh# 13165ffe97Sdrh# This file implements tests to make sure that leftover journals from 14165ffe97Sdrh# prior databases do not try to rollback into new databases. 15165ffe97Sdrh# 168aa60cb7Sdrh# $Id: journal1.test,v 1.2 2005/03/20 22:54:56 drh Exp $ 17165ffe97Sdrh 18165ffe97Sdrh 19165ffe97Sdrhset testdir [file dirname $argv0] 20165ffe97Sdrhsource $testdir/tester.tcl 21165ffe97Sdrh 228aa60cb7Sdrh# These tests will not work on windows because windows uses 23fda06befSmistachkin# manditory file locking which breaks the copy_file command. 248aa60cb7Sdrh# 25*69aedc8dSdan# Or with atomic_batch_write systems, as journal files are 26*69aedc8dSdan# not created. 27*69aedc8dSdan# 28*69aedc8dSdanif {$tcl_platform(platform)=="windows" 29*69aedc8dSdan || [atomic_batch_write test.db] 30*69aedc8dSdan} { 318aa60cb7Sdrh finish_test 328aa60cb7Sdrh return 338aa60cb7Sdrh} 348aa60cb7Sdrh 35165ffe97Sdrh# Create a smaple database 36165ffe97Sdrh# 37165ffe97Sdrhdo_test journal1-1.1 { 38165ffe97Sdrh execsql { 39165ffe97Sdrh CREATE TABLE t1(a,b); 40165ffe97Sdrh INSERT INTO t1 VALUES(1,randstr(10,400)); 41165ffe97Sdrh INSERT INTO t1 VALUES(2,randstr(10,400)); 42165ffe97Sdrh INSERT INTO t1 SELECT a+2, a||b FROM t1; 43165ffe97Sdrh INSERT INTO t1 SELECT a+4, a||b FROM t1; 44165ffe97Sdrh SELECT count(*) FROM t1; 45165ffe97Sdrh } 46165ffe97Sdrh} 8 47165ffe97Sdrh 48165ffe97Sdrh# Make changes to the database and save the journal file. 49d5578433Smistachkin# Then delete the database. Replace the journal file 50165ffe97Sdrh# and try to create a new database with the same name. The 51165ffe97Sdrh# old journal should not attempt to rollback into the new 52165ffe97Sdrh# database. 53165ffe97Sdrh# 54165ffe97Sdrhdo_test journal1-1.2 { 55165ffe97Sdrh execsql { 56165ffe97Sdrh BEGIN; 57165ffe97Sdrh DELETE FROM t1; 58165ffe97Sdrh } 59fda06befSmistachkin forcecopy test.db-journal test.db-journal-bu 60165ffe97Sdrh execsql { 61165ffe97Sdrh ROLLBACK; 62165ffe97Sdrh } 63165ffe97Sdrh db close 64fda06befSmistachkin delete_file test.db 65fda06befSmistachkin copy_file test.db-journal-bu test.db-journal 66165ffe97Sdrh sqlite3 db test.db 67165ffe97Sdrh catchsql { 68165ffe97Sdrh SELECT * FROM sqlite_master 69165ffe97Sdrh } 70165ffe97Sdrh} {0 {}} 71165ffe97Sdrh 72165ffe97Sdrhfinish_test 73