xref: /sqlite-3.40.0/test/tempdb.test (revision eb4ac06f)
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#
15# $Id: tempdb.test,v 1.2 2009/04/30 09:10:38 danielk1977 Exp $
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# Use a temporary database.
21#
22db close
23sqlite3 db {}
24
25# Force a statement journal rollback on a database file that
26# has never been opened.
27#
28do_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#
49do_test tempdb-1.2 {
50  execsql {
51    SELECT * FROM t1
52  }
53} {}
54
55do_test tempdb-2.1 {
56  set default_in_memory [expr {$TEMP_STORE == 3}]
57  db close
58  sqlite3 db test.db
59} {}
60do_test tempdb-2.2 {
61  execsql {
62    CREATE TABLE t1 (a PRIMARY KEY, b, c);
63    CREATE TABLE t2 (a, b, c);
64    BEGIN;
65      INSERT INTO t1 VALUES(1, 2, 3);
66      INSERT INTO t1 VALUES(4, 5, 6);
67      INSERT INTO t2 SELECT * FROM t1;
68  }
69  catchsql { INSERT INTO t1 SELECT * FROM t2 }
70  set sqlite_open_file_count
71} [expr 2 + (0==$default_in_memory)]
72do_test tempdb-2.3 {
73  execsql {
74    PRAGMA temp_store = 'memory';
75    ROLLBACK;
76    BEGIN;
77      INSERT INTO t1 VALUES(1, 2, 3);
78      INSERT INTO t1 VALUES(4, 5, 6);
79      INSERT INTO t2 SELECT * FROM t1;
80  }
81  catchsql { INSERT INTO t1 SELECT * FROM t2 }
82  set sqlite_open_file_count
83} {2}
84
85finish_test
86
87