sl@0: # 2007 June 26 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is testing the ALTER TABLE ... RENAME TO sl@0: # command on virtual tables. sl@0: # sl@0: # $Id: vtab_alter.test,v 1.3 2007/12/13 21:54:11 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !vtab { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Register the echo module. sl@0: # sl@0: # This test uses a special feature of the echo module. If the name sl@0: # of the virtual table is a prefix of the name of the underlying sl@0: # real table (for example if the v-table is "tbl" and the real table sl@0: # is "tbl_base"), then the name of the real table is modified sl@0: # when an "ALTER TABLE ... RENAME TO" is executed on the v-table. sl@0: # For example: sl@0: # sl@0: # sqlite> CREATE TABLE t1_base(a, b, c); sl@0: # sqlite> CREATE VIRTUAL TABLE t1 USING(t1_base); sl@0: # sqlite> ALTER TABLE t1 RENAME TO t2; sl@0: # sqlite> SELECT tbl_name FROM sqlite_master; sl@0: # t2_base sl@0: # t2 sl@0: # sl@0: register_echo_module [sqlite3_connection_pointer db] sl@0: sl@0: sl@0: # Try to rename an echo table. Make sure nothing terrible happens. sl@0: # sl@0: do_test vtab_alter-1.1 { sl@0: execsql { CREATE TABLE t1(a, b VARCHAR, c INTEGER) } sl@0: } {} sl@0: do_test vtab_alter-1.2 { sl@0: execsql { CREATE VIRTUAL TABLE t1echo USING echo(t1) } sl@0: } {} sl@0: do_test vtab_alter-1.3 { sl@0: catchsql { SELECT * FROM t1echo } sl@0: } {0 {}} sl@0: do_test vtab_alter-1.4 { sl@0: execsql { ALTER TABLE t1echo RENAME TO new } sl@0: } {} sl@0: do_test vtab_alter-1.5 { sl@0: catchsql { SELECT * FROM t1echo } sl@0: } {1 {no such table: t1echo}} sl@0: do_test vtab_alter-1.6 { sl@0: catchsql { SELECT * FROM new } sl@0: } {0 {}} sl@0: sl@0: # Try to rename an echo table that renames its base table. Make sl@0: # sure nothing terrible happens. sl@0: # sl@0: do_test vtab_alter-2.1 { sl@0: execsql { sl@0: DROP TABLE new; sl@0: DROP TABLE t1; sl@0: CREATE TABLE t1_base(a, b, c); sl@0: CREATE VIRTUAL TABLE t1 USING echo('*_base'); sl@0: } sl@0: } {} sl@0: do_test vtab_alter-2.2 { sl@0: execsql { sl@0: INSERT INTO t1_base VALUES(1, 2, 3); sl@0: SELECT * FROM t1; sl@0: } sl@0: } {1 2 3} sl@0: do_test vtab_alter-2.3 { sl@0: execsql { ALTER TABLE t1 RENAME TO x } sl@0: } {} sl@0: do_test vtab_alter-2.4 { sl@0: execsql { SELECT * FROM x; } sl@0: } {1 2 3} sl@0: do_test vtab_alter-2.5 { sl@0: execsql { SELECT * FROM x_base; } sl@0: } {1 2 3} sl@0: sl@0: # Cause an error to occur when the echo module renames its sl@0: # backing store table. sl@0: # sl@0: do_test vtab_alter-3.1 { sl@0: execsql { CREATE TABLE y_base(a, b, c) } sl@0: catchsql { ALTER TABLE x RENAME TO y } sl@0: } {1 {SQL logic error or missing database}} sl@0: do_test vtab_alter-3.2 { sl@0: execsql { SELECT * FROM x } sl@0: } {1 2 3} sl@0: sl@0: finish_test