dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 1 | # 2010 February 18 |
| 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 | # |
| 12 | # The tests in this file check that SQLite uses (or does not use) a |
| 13 | # statement journal for various SQL statements. |
| 14 | # |
| 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
dan | 69aedc8 | 2018-01-13 13:07:49 +0000 | [diff] [blame] | 19 | if {[atomic_batch_write test.db]} { |
| 20 | finish_test |
| 21 | return |
| 22 | } |
| 23 | |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 24 | do_test stmt-1.1 { |
| 25 | execsql { CREATE TABLE t1(a integer primary key, b INTEGER NOT NULL) } |
| 26 | } {} |
| 27 | |
| 28 | # The following tests verify the method used for the tests in this file - |
| 29 | # that if a statement journal is required by a statement it is opened and |
| 30 | # remains open until the current transaction is committed or rolled back. |
| 31 | # |
drh | 78e0fcf | 2010-02-23 21:08:40 +0000 | [diff] [blame] | 32 | # This only work if SQLITE_TEMP_STORE!=3 |
| 33 | # |
| 34 | if {$::TEMP_STORE==3} { |
| 35 | finish_test |
| 36 | return |
| 37 | } |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 38 | do_test stmt-1.2 { |
| 39 | set sqlite_open_file_count |
| 40 | } {1} |
| 41 | do_test stmt-1.3 { |
| 42 | execsql { |
dan | d2db090 | 2010-09-20 14:55:33 +0000 | [diff] [blame] | 43 | PRAGMA temp_store = file; |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 44 | BEGIN; |
| 45 | INSERT INTO t1 VALUES(1, 1); |
| 46 | } |
| 47 | set sqlite_open_file_count |
| 48 | } {2} |
| 49 | do_test stmt-1.4 { |
| 50 | execsql { |
| 51 | INSERT INTO t1 SELECT a+1, b+1 FROM t1; |
| 52 | } |
| 53 | set sqlite_open_file_count |
drh | 3ac9a86 | 2016-03-04 14:23:10 +0000 | [diff] [blame] | 54 | # 2016-03-04: statement-journal open deferred |
| 55 | } {2} |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 56 | do_test stmt-1.5 { |
| 57 | execsql COMMIT |
| 58 | set sqlite_open_file_count |
| 59 | } {1} |
dan | 459564f | 2010-06-03 12:35:28 +0000 | [diff] [blame] | 60 | do_test stmt-1.6.1 { |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 61 | execsql { |
| 62 | BEGIN; |
| 63 | INSERT INTO t1 SELECT a+2, b+2 FROM t1; |
| 64 | } |
| 65 | set sqlite_open_file_count |
dan | 459564f | 2010-06-03 12:35:28 +0000 | [diff] [blame] | 66 | } {2} |
| 67 | do_test stmt-1.6.2 { |
| 68 | execsql { INSERT INTO t1 SELECT a+4, b+4 FROM t1 } |
| 69 | set sqlite_open_file_count |
drh | 3ac9a86 | 2016-03-04 14:23:10 +0000 | [diff] [blame] | 70 | # 2016-03-04: statement-journal open deferred |
| 71 | } {2} |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 72 | do_test stmt-1.7 { |
| 73 | execsql COMMIT |
| 74 | set sqlite_open_file_count |
| 75 | } {1} |
| 76 | |
| 77 | |
| 78 | proc filecount {testname sql expected} { |
| 79 | uplevel [list do_test $testname [subst -nocommand { |
| 80 | execsql BEGIN |
| 81 | execsql { $sql } |
| 82 | set ret [set sqlite_open_file_count] |
| 83 | execsql ROLLBACK |
| 84 | set ret |
| 85 | }] $expected] |
| 86 | } |
| 87 | |
dan | 459564f | 2010-06-03 12:35:28 +0000 | [diff] [blame] | 88 | filecount stmt-2.1 { INSERT INTO t1 VALUES(9, 9) } 2 |
| 89 | filecount stmt-2.2 { REPLACE INTO t1 VALUES(9, 9) } 2 |
| 90 | filecount stmt-2.3 { INSERT INTO t1 SELECT 9, 9 } 2 |
| 91 | filecount stmt-2.4 { |
| 92 | INSERT INTO t1 SELECT 9, 9; |
| 93 | INSERT INTO t1 SELECT 10, 10; |
drh | 3ac9a86 | 2016-03-04 14:23:10 +0000 | [diff] [blame] | 94 | } 2 |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 95 | |
dan | 459564f | 2010-06-03 12:35:28 +0000 | [diff] [blame] | 96 | do_test stmt-2.5 { |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 97 | execsql { CREATE INDEX i1 ON t1(b) } |
| 98 | } {} |
dan | 459564f | 2010-06-03 12:35:28 +0000 | [diff] [blame] | 99 | filecount stmt-2.6 { |
| 100 | REPLACE INTO t1 VALUES(5, 5); |
| 101 | REPLACE INTO t1 VALUES(5, 5); |
drh | 3ac9a86 | 2016-03-04 14:23:10 +0000 | [diff] [blame] | 102 | } 2 |
dan | da730f6 | 2010-02-18 08:19:19 +0000 | [diff] [blame] | 103 | |
| 104 | finish_test |