drh | 110af53 | 2008-04-15 00:01:59 +0000 | [diff] [blame] | 1 | # 2008 April 14 |
| 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 | # The focus of this file is in making sure that rolling back |
| 13 | # a statement journal works correctly. |
| 14 | # |
drh | dda70fe | 2009-06-05 17:09:11 +0000 | [diff] [blame] | 15 | # $Id: tempdb.test,v 1.4 2009/06/05 17:09:12 drh Exp $ |
drh | 110af53 | 2008-04-15 00:01:59 +0000 | [diff] [blame] | 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
| 19 | |
| 20 | # Use a temporary database. |
| 21 | # |
| 22 | db close |
| 23 | sqlite3 db {} |
| 24 | |
| 25 | # Force a statement journal rollback on a database file that |
| 26 | # has never been opened. |
| 27 | # |
| 28 | do_test tempdb-1.1 { |
| 29 | execsql { |
| 30 | BEGIN; |
| 31 | CREATE TABLE t1(x UNIQUE); |
| 32 | CREATE TABLE t2(y); |
| 33 | INSERT INTO t2 VALUES('hello'); |
| 34 | INSERT INTO t2 VALUES(NULL); |
| 35 | } |
| 36 | # Because of the transaction, the temporary database file |
| 37 | # has not even been opened yet. The following statement |
| 38 | # will cause a statement journal rollback on this non-existant |
| 39 | # file. |
| 40 | catchsql { |
| 41 | INSERT INTO t1 |
| 42 | SELECT CASE WHEN y IS NULL THEN test_error('oops', 11) ELSE y END |
| 43 | FROM t2; |
| 44 | } |
| 45 | } {1 oops} |
| 46 | |
| 47 | # Verify that no writes occurred in t1. |
| 48 | # |
| 49 | do_test tempdb-1.2 { |
| 50 | execsql { |
| 51 | SELECT * FROM t1 |
| 52 | } |
| 53 | } {} |
| 54 | |
danielk1977 | d829335 | 2009-04-30 09:10:37 +0000 | [diff] [blame] | 55 | do_test tempdb-2.1 { |
danielk1977 | bd2edd6 | 2009-05-01 05:23:17 +0000 | [diff] [blame] | 56 | # Set $::jrnl_in_memory if the journal file is expected to be in-memory. |
| 57 | # Similarly, set $::subj_in_memory if the sub-journal file is expected |
| 58 | # to be in memory. These variables are used to calculate the expected |
| 59 | # number of open files in the test cases below. |
| 60 | # |
dan | 430e74c | 2010-06-07 17:47:26 +0000 | [diff] [blame] | 61 | set jrnl_in_memory [expr {[permutation] eq "inmemory_journal"}] |
dan | d2db090 | 2010-09-20 14:55:33 +0000 | [diff] [blame] | 62 | set subj_in_memory [expr {$jrnl_in_memory || $TEMP_STORE>=2}] |
danielk1977 | bd2edd6 | 2009-05-01 05:23:17 +0000 | [diff] [blame] | 63 | |
danielk1977 | d829335 | 2009-04-30 09:10:37 +0000 | [diff] [blame] | 64 | db close |
| 65 | sqlite3 db test.db |
| 66 | } {} |
| 67 | do_test tempdb-2.2 { |
| 68 | execsql { |
| 69 | CREATE TABLE t1 (a PRIMARY KEY, b, c); |
| 70 | CREATE TABLE t2 (a, b, c); |
| 71 | BEGIN; |
| 72 | INSERT INTO t1 VALUES(1, 2, 3); |
| 73 | INSERT INTO t1 VALUES(4, 5, 6); |
dan | 459564f | 2010-06-03 12:35:28 +0000 | [diff] [blame] | 74 | INSERT INTO t2 VALUES(7, 8, 9); |
danielk1977 | d829335 | 2009-04-30 09:10:37 +0000 | [diff] [blame] | 75 | INSERT INTO t2 SELECT * FROM t1; |
| 76 | } |
| 77 | catchsql { INSERT INTO t1 SELECT * FROM t2 } |
| 78 | set sqlite_open_file_count |
drh | 3ac9a86 | 2016-03-04 14:23:10 +0000 | [diff] [blame] | 79 | } [expr 1 + (0==$jrnl_in_memory)] |
danielk1977 | d829335 | 2009-04-30 09:10:37 +0000 | [diff] [blame] | 80 | do_test tempdb-2.3 { |
| 81 | execsql { |
| 82 | PRAGMA temp_store = 'memory'; |
| 83 | ROLLBACK; |
| 84 | BEGIN; |
| 85 | INSERT INTO t1 VALUES(1, 2, 3); |
| 86 | INSERT INTO t1 VALUES(4, 5, 6); |
| 87 | INSERT INTO t2 SELECT * FROM t1; |
| 88 | } |
| 89 | catchsql { INSERT INTO t1 SELECT * FROM t2 } |
| 90 | set sqlite_open_file_count |
danielk1977 | bd2edd6 | 2009-05-01 05:23:17 +0000 | [diff] [blame] | 91 | } [expr 1 + (0==$jrnl_in_memory)] |
danielk1977 | d829335 | 2009-04-30 09:10:37 +0000 | [diff] [blame] | 92 | |
drh | 110af53 | 2008-04-15 00:01:59 +0000 | [diff] [blame] | 93 | finish_test |