os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtab_alter.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtab_alter.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,103 @@
     1.4 +# 2007 June 26
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this file is testing the ALTER TABLE ... RENAME TO
    1.16 +# command on virtual tables.
    1.17 +#
    1.18 +# $Id: vtab_alter.test,v 1.3 2007/12/13 21:54:11 drh Exp $
    1.19 +
    1.20 +set testdir [file dirname $argv0]
    1.21 +source $testdir/tester.tcl
    1.22 +
    1.23 +ifcapable !vtab {
    1.24 +  finish_test
    1.25 +  return
    1.26 +}
    1.27 +
    1.28 +# Register the echo module.
    1.29 +#
    1.30 +# This test uses a special feature of the echo module. If the name
    1.31 +# of the virtual table is a prefix of the name of the underlying
    1.32 +# real table (for example if the v-table is "tbl" and the real table
    1.33 +# is "tbl_base"), then the name of the real table is modified
    1.34 +# when an "ALTER TABLE ... RENAME TO" is executed on the v-table.
    1.35 +# For example:
    1.36 +#
    1.37 +#   sqlite> CREATE TABLE t1_base(a, b, c); 
    1.38 +#   sqlite> CREATE VIRTUAL TABLE t1 USING(t1_base);
    1.39 +#   sqlite> ALTER TABLE t1 RENAME TO t2;
    1.40 +#   sqlite> SELECT tbl_name FROM sqlite_master;
    1.41 +#   t2_base
    1.42 +#   t2
    1.43 +#
    1.44 +register_echo_module [sqlite3_connection_pointer db]
    1.45 +
    1.46 +
    1.47 +# Try to rename an echo table. Make sure nothing terrible happens.
    1.48 +#
    1.49 +do_test vtab_alter-1.1 {
    1.50 +  execsql { CREATE TABLE t1(a, b VARCHAR, c INTEGER) }
    1.51 +} {}
    1.52 +do_test vtab_alter-1.2 {
    1.53 +  execsql { CREATE VIRTUAL TABLE t1echo USING echo(t1) }
    1.54 +} {}
    1.55 +do_test vtab_alter-1.3 {
    1.56 +  catchsql { SELECT * FROM t1echo }
    1.57 +} {0 {}}
    1.58 +do_test vtab_alter-1.4 {
    1.59 +  execsql { ALTER TABLE t1echo RENAME TO new }
    1.60 +} {}
    1.61 +do_test vtab_alter-1.5 {
    1.62 +  catchsql { SELECT * FROM t1echo }
    1.63 +} {1 {no such table: t1echo}}
    1.64 +do_test vtab_alter-1.6 {
    1.65 +  catchsql { SELECT * FROM new }
    1.66 +} {0 {}}
    1.67 +
    1.68 +# Try to rename an echo table that renames its base table. Make 
    1.69 +# sure nothing terrible happens.
    1.70 +#
    1.71 +do_test vtab_alter-2.1 {
    1.72 +  execsql { 
    1.73 +    DROP TABLE new;
    1.74 +    DROP TABLE t1;
    1.75 +    CREATE TABLE t1_base(a, b, c);
    1.76 +    CREATE VIRTUAL TABLE t1 USING echo('*_base');
    1.77 +  }
    1.78 +} {}
    1.79 +do_test vtab_alter-2.2 {
    1.80 +  execsql { 
    1.81 +    INSERT INTO t1_base VALUES(1, 2, 3);
    1.82 +    SELECT * FROM t1;
    1.83 +  }
    1.84 +} {1 2 3}
    1.85 +do_test vtab_alter-2.3 {
    1.86 +  execsql { ALTER TABLE t1 RENAME TO x }
    1.87 +} {}
    1.88 +do_test vtab_alter-2.4 {
    1.89 +  execsql { SELECT * FROM x; }
    1.90 +} {1 2 3}
    1.91 +do_test vtab_alter-2.5 {
    1.92 +  execsql { SELECT * FROM x_base; }
    1.93 +} {1 2 3}
    1.94 +
    1.95 +# Cause an error to occur when the echo module renames its
    1.96 +# backing store table.
    1.97 +#
    1.98 +do_test vtab_alter-3.1 {
    1.99 +  execsql  { CREATE TABLE y_base(a, b, c) }
   1.100 +  catchsql { ALTER TABLE x RENAME TO y }
   1.101 +} {1 {SQL logic error or missing database}}
   1.102 +do_test vtab_alter-3.2 {
   1.103 +  execsql  { SELECT * FROM x }
   1.104 +} {1 2 3}
   1.105 +
   1.106 +finish_test