3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
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.
15 # $Id: vtab_alter.test,v 1.3 2007/12/13 21:54:11 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 ifcapable !vtab||!altertable {
25 # Register the echo module.
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.
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;
41 register_echo_module [sqlite3_connection_pointer db]
44 # Try to rename an echo table. Make sure nothing terrible happens.
46 do_test vtab_alter-1.1 {
47 execsql { CREATE TABLE t1(a, b VARCHAR, c INTEGER) }
49 do_test vtab_alter-1.2 {
50 execsql { CREATE VIRTUAL TABLE t1echo USING echo(t1) }
52 do_test vtab_alter-1.3 {
53 catchsql { SELECT * FROM t1echo }
55 do_test vtab_alter-1.4 {
56 execsql { ALTER TABLE t1echo RENAME TO new }
58 do_test vtab_alter-1.5 {
59 catchsql { SELECT * FROM t1echo }
60 } {1 {no such table: t1echo}}
61 do_test vtab_alter-1.6 {
62 catchsql { SELECT * FROM new }
65 # Try to rename an echo table that renames its base table. Make
66 # sure nothing terrible happens.
68 do_test vtab_alter-2.1 {
72 CREATE TABLE t1_base(a, b, c);
73 CREATE VIRTUAL TABLE t1 USING echo('*_base');
76 do_test vtab_alter-2.2 {
78 INSERT INTO t1_base VALUES(1, 2, 3);
82 do_test vtab_alter-2.3 {
83 execsql { ALTER TABLE t1 RENAME TO x }
85 do_test vtab_alter-2.4 {
86 execsql { SELECT * FROM x; }
88 do_test vtab_alter-2.5 {
89 execsql { SELECT * FROM x_base; }
92 # Cause an error to occur when the echo module renames its
93 # backing store table.
95 do_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}}
99 do_test vtab_alter-3.2 {
100 execsql { SELECT * FROM x }