sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | # 2005 March 15 |
| 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. |
| 12 | # |
| 13 | # This file implements tests to make sure that leftover journals from |
| 14 | # prior databases do not try to rollback into new databases. |
| 15 | # |
| 16 | # $Id: journal1.test,v 1.2 2005/03/20 22:54:56 drh Exp $ |
| 17 | |
| 18 | |
| 19 | set testdir [file dirname $argv0] |
| 20 | source $testdir/tester.tcl |
| 21 | |
| 22 | # These tests will not work on windows because windows uses |
| 23 | # manditory file locking which breaks the copy_file command. |
| 24 | # |
| 25 | # Or with atomic_batch_write systems, as journal files are |
| 26 | # not created. |
| 27 | # |
| 28 | if {$tcl_platform(platform) eq "windows" |
| 29 | || [atomic_batch_write test.db] |
| 30 | } { |
| 31 | finish_test |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | # Create a smaple database |
| 36 | # |
| 37 | do_test journal1-1.1 { |
| 38 | execsql { |
| 39 | CREATE TABLE t1(a,b); |
| 40 | INSERT INTO t1 VALUES(1,randstr(10,400)); |
| 41 | INSERT INTO t1 VALUES(2,randstr(10,400)); |
| 42 | INSERT INTO t1 SELECT a+2, a||b FROM t1; |
| 43 | INSERT INTO t1 SELECT a+4, a||b FROM t1; |
| 44 | SELECT count(*) FROM t1; |
| 45 | } |
| 46 | } 8 |
| 47 | |
| 48 | # Make changes to the database and save the journal file. |
| 49 | # Then delete the database. Replace the journal file |
| 50 | # and try to create a new database with the same name. The |
| 51 | # old journal should not attempt to rollback into the new |
| 52 | # database. |
| 53 | # |
| 54 | do_test journal1-1.2 { |
| 55 | execsql { |
| 56 | BEGIN; |
| 57 | DELETE FROM t1; |
| 58 | } |
| 59 | forcecopy test.db-journal test.db-journal-bu |
| 60 | execsql { |
| 61 | ROLLBACK; |
| 62 | } |
| 63 | db close |
| 64 | delete_file test.db |
| 65 | copy_file test.db-journal-bu test.db-journal |
| 66 | sqlite3 db test.db |
| 67 | catchsql { |
| 68 | SELECT * FROM sqlite_master |
| 69 | } |
| 70 | } {0 {}} |
| 71 | |
| 72 | finish_test |