xref: /sqlite-3.40.0/test/misc4.test (revision 956bc92c)
1# 2004 Jun 27
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 for miscellanous features that were
14# left out of other test files.
15#
16# $Id: misc4.test,v 1.6 2004/07/24 17:38:30 drh Exp $
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21# Prepare a statement that will create a temporary table.  Then do
22# a rollback.  Then try to execute the prepared statement.
23#
24do_test misc4-1.1 {
25  db close
26  set DB [sqlite3 db test.db]
27  execsql {
28    CREATE TABLE t1(x);
29    INSERT INTO t1 VALUES(1);
30  }
31} {}
32do_test misc4-1.2 {
33  set sql {CREATE TEMP TABLE t2 AS SELECT * FROM t1}
34  set stmt [sqlite3_prepare $DB $sql -1 TAIL]
35  execsql {
36    BEGIN;
37    CREATE TABLE t3(a,b,c);
38    INSERT INTO t1 SELECT * FROM t1;
39    ROLLBACK;
40  }
41} {}
42do_test misc4-1.3 {
43  sqlite3_step $stmt
44} SQLITE_DONE
45do_test misc4-1.4 {
46  execsql {
47    SELECT * FROM temp.t2;
48  }
49} {1}
50
51# Drop the temporary table, then rerun the prepared  statement to
52# recreate it again.  This recreates ticket #807.
53#
54do_test misc4-1.5 {
55  execsql {DROP TABLE t2}
56  sqlite3_reset $stmt
57  sqlite3_step $stmt
58} {SQLITE_ERROR}
59do_test misc4-1.6 {
60  sqlite3_finalize $stmt
61} {SQLITE_SCHEMA}
62
63# Prepare but do not execute various CREATE statements.  Then before
64# those statements are executed, try to use the tables, indices, views,
65# are triggers that were created.
66#
67do_test misc4-2.1 {
68  set stmt [sqlite3_prepare $DB {CREATE TABLE t3(x);} -1 TAIL]
69  catchsql {
70    INSERT INTO t3 VALUES(1);
71  }
72} {1 {no such table: t3}}
73do_test misc4-2.2 {
74  sqlite3_step $stmt
75} SQLITE_DONE
76do_test misc4-2.3 {
77  sqlite3_finalize $stmt
78} SQLITE_OK
79do_test misc4-2.4 {
80  catchsql {
81    INSERT INTO t3 VALUES(1);
82  }
83} {0 {}}
84
85
86finish_test
87