aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/vtab_alter.test
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/vtab_alter.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/vtab_alter.test103
1 files changed, 103 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/vtab_alter.test b/libraries/sqlite/unix/sqlite-3.5.1/test/vtab_alter.test
new file mode 100644
index 0000000..a67660d
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/vtab_alter.test
@@ -0,0 +1,103 @@
1# 2007 June 26
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. The
12# focus of this file is testing the ALTER TABLE ... RENAME TO
13# command on virtual tables.
14#
15# $Id: vtab_alter.test,v 1.2 2007/09/01 18:24:55 danielk1977 Exp $
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20ifcapable !vtab {
21 finish_test
22 return
23}
24
25# Register the echo module.
26#
27# This test uses a special feature of the echo module. If the name
28# of the virtual table is a prefix of the name of the underlying
29# real table (for example if the v-table is "tbl" and the real table
30# is "tbl_base"), then the name of the real table is modified
31# when an "ALTER TABLE ... RENAME TO" is executed on the v-table.
32# For example:
33#
34# sqlite> CREATE TABLE t1_base(a, b, c);
35# sqlite> CREATE VIRTUAL TABLE t1 USING(t1_base);
36# sqlite> ALTER TABLE t1 RENAME TO t2;
37# sqlite> SELECT tbl_name FROM sqlite_master;
38# t2_base
39# t2
40#
41register_echo_module [sqlite3_connection_pointer db]
42
43
44# Try to rename an echo table. Make sure nothing terrible happens.
45#
46do_test vtab_alter-1.1 {
47 execsql { CREATE TABLE t1(a, b VARCHAR, c INTEGER) }
48} {}
49do_test vtab_alter-1.2 {
50 execsql { CREATE VIRTUAL TABLE t1echo USING echo(t1) }
51} {}
52do_test vtab_alter-1.3 {
53 catchsql { SELECT * FROM t1echo }
54} {0 {}}
55do_test vtab_alter-1.4 {
56 execsql { ALTER TABLE t1echo RENAME TO new }
57} {}
58do_test vtab_alter-1.5 {
59 catchsql { SELECT * FROM t1echo }
60} {1 {no such table: t1echo}}
61do_test vtab_alter-1.6 {
62 catchsql { SELECT * FROM new }
63} {0 {}}
64
65# Try to rename an echo table that renames it's base table. Make
66# sure nothing terrible happens.
67#
68do_test vtab_alter-2.1 {
69 execsql {
70 DROP TABLE new;
71 DROP TABLE t1;
72 CREATE TABLE t1_base(a, b, c);
73 CREATE VIRTUAL TABLE t1 USING echo('*_base');
74 }
75} {}
76do_test vtab_alter-2.2 {
77 execsql {
78 INSERT INTO t1_base VALUES(1, 2, 3);
79 SELECT * FROM t1;
80 }
81} {1 2 3}
82do_test vtab_alter-2.3 {
83 execsql { ALTER TABLE t1 RENAME TO x }
84} {}
85do_test vtab_alter-2.4 {
86 execsql { SELECT * FROM x; }
87} {1 2 3}
88do_test vtab_alter-2.5 {
89 execsql { SELECT * FROM x_base; }
90} {1 2 3}
91
92# Cause an error to occur when the echo module renames it's
93# backing store table.
94#
95do_test vtab_alter-3.1 {
96 execsql { CREATE TABLE y_base(a, b, c) }
97 catchsql { ALTER TABLE x RENAME TO y }
98} {1 {SQL logic error or missing database}}
99do_test vtab_alter-3.2 {
100 execsql { SELECT * FROM x }
101} {1 2 3}
102
103finish_test