SQLite

Check-in [e4eb227b14]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Various fixes so that "make test" works with OMIT_FOREIGN_KEY, OMIT_TRIGGER and OMIT_ALTER_TABLE.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e4eb227b14e4bfcb9f7f284692a391b7355f0204
User & Date: dan 2009-09-29 06:33:24.000
Context
2009-09-29
11:28
Remove an unused variable from fkey.c. (check-in: 582bd76828 user: dan tags: trunk)
06:33
Various fixes so that "make test" works with OMIT_FOREIGN_KEY, OMIT_TRIGGER and OMIT_ALTER_TABLE. (check-in: e4eb227b14 user: dan tags: trunk)
2009-09-28
18:52
Ignore foreign key mismatch errors while compiling DROP TABLE commands. (check-in: 5b4d46374a user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/alter.c.
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
  }else{
    zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
    sqlite3DbFree(db, zWhere);
  }
  return zNew;
}


/*
** Generate the text of a WHERE expression which can be used to select all
** tables that have foreign key constraints that refer to table pTab (i.e.
** constraints for which pTab is the parent table) from the sqlite_master
** table.
*/
static char *whereForeignKeys(Parse *pParse, Table *pTab){
  FKey *p;
  char *zWhere = 0;
  for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
    zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
  }
  return zWhere;
}


/*
** Generate the text of a WHERE expression which can be used to select all
** temporary triggers on table pTab from the sqlite_temp_master table. If
** table pTab has no temporary triggers, or is itself stored in the 
** temporary database, NULL is returned.
*/







>














>







262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
  }else{
    zNew = sqlite3MPrintf(db, "%s OR name=%Q", zWhere, zConstant);
    sqlite3DbFree(db, zWhere);
  }
  return zNew;
}

#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
/*
** Generate the text of a WHERE expression which can be used to select all
** tables that have foreign key constraints that refer to table pTab (i.e.
** constraints for which pTab is the parent table) from the sqlite_master
** table.
*/
static char *whereForeignKeys(Parse *pParse, Table *pTab){
  FKey *p;
  char *zWhere = 0;
  for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
    zWhere = whereOrName(pParse->db, zWhere, p->pFrom->zName);
  }
  return zWhere;
}
#endif

/*
** Generate the text of a WHERE expression which can be used to select all
** temporary triggers on table pTab from the sqlite_temp_master table. If
** table pTab has no temporary triggers, or is itself stored in the 
** temporary database, NULL is returned.
*/
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
  }
#endif

  /* figure out how many UTF-8 characters are in zName */
  zTabName = pTab->zName;
  nTabName = sqlite3Utf8CharLen(zTabName, -1);

#ifndef SQLITE_OMIT_FOREIGN_KEY
  if( db->flags&SQLITE_ForeignKeys ){
    /* If foreign-key support is enabled, rewrite the CREATE TABLE 
    ** statements corresponding to all child tables of foreign key constraints
    ** for which the renamed table is the parent table.  */
    if( (zWhere=whereForeignKeys(pParse, pTab))!=0 ){
      sqlite3NestedParse(pParse, 
          "UPDATE sqlite_master SET "







|







468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
  }
#endif

  /* figure out how many UTF-8 characters are in zName */
  zTabName = pTab->zName;
  nTabName = sqlite3Utf8CharLen(zTabName, -1);

#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
  if( db->flags&SQLITE_ForeignKeys ){
    /* If foreign-key support is enabled, rewrite the CREATE TABLE 
    ** statements corresponding to all child tables of foreign key constraints
    ** for which the renamed table is the parent table.  */
    if( (zWhere=whereForeignKeys(pParse, pTab))!=0 ){
      sqlite3NestedParse(pParse, 
          "UPDATE sqlite_master SET "
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
            "sql = sqlite_rename_trigger(sql, %Q), "
            "tbl_name = %Q "
            "WHERE %s;", zName, zName, zWhere);
    sqlite3DbFree(db, zWhere);
  }
#endif

#ifndef SQLITE_OMIT_FOREIGN_KEY
  if( db->flags&SQLITE_ForeignKeys ){
    FKey *p;
    for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
      Table *pFrom = p->pFrom;
      if( pFrom!=pTab ){
        reloadTableSchema(pParse, p->pFrom, pFrom->zName);
      }







|







534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
            "sql = sqlite_rename_trigger(sql, %Q), "
            "tbl_name = %Q "
            "WHERE %s;", zName, zName, zWhere);
    sqlite3DbFree(db, zWhere);
  }
#endif

#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
  if( db->flags&SQLITE_ForeignKeys ){
    FKey *p;
    for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
      Table *pFrom = p->pFrom;
      if( pFrom!=pTab ){
        reloadTableSchema(pParse, p->pFrom, pFrom->zName);
      }
Changes to test/boundary4.tcl.
16
17
18
19
20
21
22

23
24
25
26
27
28
29
# $Id: boundary4.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Many of the boundary tests depend on a working 64-bit implementation.
if {![working_64bit_int]} { finish_test; return }

}

expr srand(0)

# Generate interesting boundary numbers
#
foreach x {







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# $Id: boundary4.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Many of the boundary tests depend on a working 64-bit implementation.
if {![working_64bit_int]} { finish_test; return }
ifcapable !altertable     { finish_test; return }
}

expr srand(0)

# Generate interesting boundary numbers
#
foreach x {
Changes to test/boundary4.test.
16
17
18
19
20
21
22

23
24
25
26
27
28
29
# $Id: boundary4.test,v 1.2 2009/01/02 15:45:48 shane Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Many of the boundary tests depend on a working 64-bit implementation.
if {![working_64bit_int]} { finish_test; return }


do_test boundary4-1.1 {
  db eval {
    CREATE TABLE t1(a,x);
    INSERT INTO t1(oid,a,x) VALUES(549755813887,1,'0000007fffffffff');
    INSERT INTO t1(oid,a,x) VALUES(-8388608,2,'ffffffffff800000');
    INSERT INTO t1(oid,a,x) VALUES(0,3,'0000000000000000');







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# $Id: boundary4.test,v 1.2 2009/01/02 15:45:48 shane Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Many of the boundary tests depend on a working 64-bit implementation.
if {![working_64bit_int]} { finish_test; return }
ifcapable !altertable     { finish_test; return }

do_test boundary4-1.1 {
  db eval {
    CREATE TABLE t1(a,x);
    INSERT INTO t1(oid,a,x) VALUES(549755813887,1,'0000007fffffffff');
    INSERT INTO t1(oid,a,x) VALUES(-8388608,2,'ffffffffff800000');
    INSERT INTO t1(oid,a,x) VALUES(0,3,'0000000000000000');
Changes to test/fkey2.test.
776
777
778
779
780
781
782

783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865

866
867
868
869
870
871
872
# TABLE" commands work as expected wrt foreign key constraints.
#
# fkey2-14.1*: ALTER TABLE ADD COLUMN
# fkey2-14.2*: ALTER TABLE RENAME TABLE
# fkey2-14.3*: DROP TABLE
#
drop_all_tables

do_test fkey2-14.1.1 {
  # Adding a column with a REFERENCES clause is not supported.
  execsql { 
    CREATE TABLE t1(a PRIMARY KEY);
    CREATE TABLE t2(a, b);
  }
  catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 }
} {0 {}}
do_test fkey2-14.1.2 {
  catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 }
} {0 {}}
do_test fkey2-14.1.3 {
  catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL}
} {0 {}}
do_test fkey2-14.1.4 {
  catchsql { ALTER TABLE t2 ADD COLUMN f REFERENCES t1 DEFAULT 'text'}
} {1 {Cannot add a REFERENCES column with non-NULL default value}}
do_test fkey2-14.1.5 {
  catchsql { ALTER TABLE t2 ADD COLUMN g DEFAULT CURRENT_TIME REFERENCES t1 }
} {1 {Cannot add a REFERENCES column with non-NULL default value}}
do_test fkey2-14.1.6 {
  execsql { 
    PRAGMA foreign_keys = off;
    ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1;
    PRAGMA foreign_keys = on;
    SELECT sql FROM sqlite_master WHERE name='t2';
  }
} {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}}


# Test the sqlite_rename_parent() function directly.
#
proc test_rename_parent {zCreate zOld zNew} {
  db eval {SELECT sqlite_rename_parent($zCreate, $zOld, $zNew)}
}
do_test fkey2-14.2.1.1 {
  test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
} {{CREATE TABLE t1(a REFERENCES "t3")}}
do_test fkey2-14.2.1.2 {
  test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
} {{CREATE TABLE t1(a REFERENCES t2)}}
do_test fkey2-14.2.1.3 {
  test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
} {{CREATE TABLE t1(a REFERENCES "t3")}}

# Test ALTER TABLE RENAME TABLE a bit.
#
do_test fkey2-14.2.2.1 {
  drop_all_tables
  execsql {
    CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1);
    CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2);
    CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1);
  }
  execsql { SELECT sql FROM sqlite_master WHERE type = 'table'}
} [list \
  {CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1)}                     \
  {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)}    \
  {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)}  \
]
do_test fkey2-14.2.2.2 {
  execsql { ALTER TABLE t1 RENAME TO t4 }
  execsql { SELECT sql FROM sqlite_master WHERE type = 'table'}
} [list \
  {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4")}                     \
  {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)}    \
  {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")}  \
]
do_test fkey2-14.2.2.3 {
  catchsql { INSERT INTO t3 VALUES(1, 2, 3) }
} {1 {foreign key constraint failed}}
do_test fkey2-14.2.2.4 {
  execsql { INSERT INTO t4 VALUES(1, NULL) }
} {}
do_test fkey2-14.2.2.5 {
  catchsql { UPDATE t4 SET b = 5 }
} {1 {foreign key constraint failed}}
do_test fkey2-14.2.2.6 {
  catchsql { UPDATE t4 SET b = 1 }
} {0 {}}
do_test fkey2-14.2.2.7 {
  execsql { INSERT INTO t3 VALUES(1, NULL, 1) }
} {}


do_test fkey-2.14.3.1 {
  drop_all_tables
  execsql {
    CREATE TABLE t1(a, b REFERENCES nosuchtable);
    DROP TABLE t1;
  }







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
# TABLE" commands work as expected wrt foreign key constraints.
#
# fkey2-14.1*: ALTER TABLE ADD COLUMN
# fkey2-14.2*: ALTER TABLE RENAME TABLE
# fkey2-14.3*: DROP TABLE
#
drop_all_tables
ifcapable altertable {
  do_test fkey2-14.1.1 {
    # Adding a column with a REFERENCES clause is not supported.
    execsql { 
      CREATE TABLE t1(a PRIMARY KEY);
      CREATE TABLE t2(a, b);
    }
    catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 }
  } {0 {}}
  do_test fkey2-14.1.2 {
    catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 }
  } {0 {}}
  do_test fkey2-14.1.3 {
    catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL}
  } {0 {}}
  do_test fkey2-14.1.4 {
    catchsql { ALTER TABLE t2 ADD COLUMN f REFERENCES t1 DEFAULT 'text'}
  } {1 {Cannot add a REFERENCES column with non-NULL default value}}
  do_test fkey2-14.1.5 {
    catchsql { ALTER TABLE t2 ADD COLUMN g DEFAULT CURRENT_TIME REFERENCES t1 }
  } {1 {Cannot add a REFERENCES column with non-NULL default value}}
  do_test fkey2-14.1.6 {
    execsql { 
      PRAGMA foreign_keys = off;
      ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1;
      PRAGMA foreign_keys = on;
      SELECT sql FROM sqlite_master WHERE name='t2';
    }
  } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}}
  
  
  # Test the sqlite_rename_parent() function directly.
  #
  proc test_rename_parent {zCreate zOld zNew} {
    db eval {SELECT sqlite_rename_parent($zCreate, $zOld, $zNew)}
  }
  do_test fkey2-14.2.1.1 {
    test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3
  } {{CREATE TABLE t1(a REFERENCES "t3")}}
  do_test fkey2-14.2.1.2 {
    test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3
  } {{CREATE TABLE t1(a REFERENCES t2)}}
  do_test fkey2-14.2.1.3 {
    test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3
  } {{CREATE TABLE t1(a REFERENCES "t3")}}
  
  # Test ALTER TABLE RENAME TABLE a bit.
  #
  do_test fkey2-14.2.2.1 {
    drop_all_tables
    execsql {
      CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1);
      CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2);
      CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1);
    }
    execsql { SELECT sql FROM sqlite_master WHERE type = 'table'}
  } [list \
    {CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1)}                     \
    {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)}    \
    {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)}  \
  ]
  do_test fkey2-14.2.2.2 {
    execsql { ALTER TABLE t1 RENAME TO t4 }
    execsql { SELECT sql FROM sqlite_master WHERE type = 'table'}
  } [list \
    {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4")}                    \
    {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)}     \
    {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \
  ]
  do_test fkey2-14.2.2.3 {
    catchsql { INSERT INTO t3 VALUES(1, 2, 3) }
  } {1 {foreign key constraint failed}}
  do_test fkey2-14.2.2.4 {
    execsql { INSERT INTO t4 VALUES(1, NULL) }
  } {}
  do_test fkey2-14.2.2.5 {
    catchsql { UPDATE t4 SET b = 5 }
  } {1 {foreign key constraint failed}}
  do_test fkey2-14.2.2.6 {
    catchsql { UPDATE t4 SET b = 1 }
  } {0 {}}
  do_test fkey2-14.2.2.7 {
    execsql { INSERT INTO t3 VALUES(1, NULL, 1) }
  } {}
}

do_test fkey-2.14.3.1 {
  drop_all_tables
  execsql {
    CREATE TABLE t1(a, b REFERENCES nosuchtable);
    DROP TABLE t1;
  }
Changes to test/fkey3.test.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# This file implements tests for foreign keys.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable {!foreignkey} {
  finish_test
  return
}

# Create a table and some data to work with.
#
do_test fkey3-1.1 {







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# This file implements tests for foreign keys.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable {!foreignkey||!trigger} {
  finish_test
  return
}

# Create a table and some data to work with.
#
do_test fkey3-1.1 {
Changes to test/tkt3838.test.
16
17
18
19
20
21
22




23
24
25
26
27
28
29
# Verify that this has been fixed.
#
# $Id: tkt3838.test,v 1.1 2009/05/05 12:54:50 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl






do_test tkt3838-1.1 {
  db eval {
    PRAGMA encoding=UTF16;
    CREATE TABLE t1(x);
    INSERT INTO t1 VALUES(1);
    ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT '999';







>
>
>
>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Verify that this has been fixed.
#
# $Id: tkt3838.test,v 1.1 2009/05/05 12:54:50 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !altertable {
  finish_test
  return
}

do_test tkt3838-1.1 {
  db eval {
    PRAGMA encoding=UTF16;
    CREATE TABLE t1(x);
    INSERT INTO t1 VALUES(1);
    ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT '999';
Changes to test/tkt3992.test.
40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
do_test tkt3992-1.3 {
  execsql {
    UPDATE parameters2 SET mountcnt = mountcnt + 1;
    SELECT * FROM parameters2;
  }
} {2 1.0}


do_test tkt3992-2.1 {
  execsql {
    CREATE TABLE t1(a, b);
    INSERT INTO t1 VALUES(1, 2);
    ALTER TABLE t1 ADD COLUMN c DEFAULT 3;
    SELECT * FROM t1;
  }
} {1 2 3}
do_test tkt3992-2.2 {
  execsql {
    UPDATE t1 SET a = 'one';
    SELECT * FROM t1;
  }
} {one 2 3}


ifcapable trigger {
  db function tcl eval
  do_test tkt3992-2.3 {
    execsql {
      CREATE TABLE t2(a REAL, b REAL, c REAL);
      INSERT INTO t2 VALUES(1, 2, 3);







>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>







40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
do_test tkt3992-1.3 {
  execsql {
    UPDATE parameters2 SET mountcnt = mountcnt + 1;
    SELECT * FROM parameters2;
  }
} {2 1.0}

ifcapable altertable {
  do_test tkt3992-2.1 {
    execsql {
      CREATE TABLE t1(a, b);
      INSERT INTO t1 VALUES(1, 2);
      ALTER TABLE t1 ADD COLUMN c DEFAULT 3;
      SELECT * FROM t1;
    }
  } {1 2 3}
  do_test tkt3992-2.2 {
    execsql {
      UPDATE t1 SET a = 'one';
      SELECT * FROM t1;
    }
  } {one 2 3}
}

ifcapable trigger {
  db function tcl eval
  do_test tkt3992-2.3 {
    execsql {
      CREATE TABLE t2(a REAL, b REAL, c REAL);
      INSERT INTO t2 VALUES(1, 2, 3);
Changes to test/vtab1.test.
1150
1151
1152
1153
1154
1155
1156

1157
1158
1159
1160
1161
1162

1163
1164
1165
    set echo_module_fail($method,t2) "the $method method has failed"
    catchsql { INSERT INTO echo_t2 VALUES(7, 8, 9) }
  } "1 {echo-vtab-error: the $method method has failed}"
  unset echo_module_fail($method,t2)
  incr tn
}


do_test vtab1-16.$tn {
  set echo_module_fail(xRename,t2) "the xRename method has failed"
  catchsql { ALTER TABLE echo_t2 RENAME TO another_name }
} "1 {echo-vtab-error: the xRename method has failed}"
unset echo_module_fail(xRename,t2)
incr tn


unset -nocomplain echo_module_begin_fail
finish_test







>
|
|
|
|
|
|
>



1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
    set echo_module_fail($method,t2) "the $method method has failed"
    catchsql { INSERT INTO echo_t2 VALUES(7, 8, 9) }
  } "1 {echo-vtab-error: the $method method has failed}"
  unset echo_module_fail($method,t2)
  incr tn
}

ifcapable altertable {
  do_test vtab1-16.$tn {
    set echo_module_fail(xRename,t2) "the xRename method has failed"
    catchsql { ALTER TABLE echo_t2 RENAME TO another_name }
  } "1 {echo-vtab-error: the xRename method has failed}"
  unset echo_module_fail(xRename,t2)
  incr tn
}

unset -nocomplain echo_module_begin_fail
finish_test
Changes to test/vtab5.test.
130
131
132
133
134
135
136

137
138
139
140
141

142
143
144
145
146
147
148
  catchsql {
    CREATE INDEX echo_strings_i ON echo_strings(str);
  }
} {1 {virtual tables may not be indexed}}

# Test that it is impossible to add a column to a virtual table.
#

do_test vtab5.4.2 {
  catchsql {
    ALTER TABLE echo_strings ADD COLUMN col2;
  }
} {1 {virtual tables may not be altered}}


# Test that it is impossible to rename a virtual table.
# UPDATE: It is now possible.
#
# do_test vtab5.4.3 {
#   catchsql {
#     ALTER TABLE echo_strings RENAME TO echo_strings2;







>
|
|
|
|
|
>







130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  catchsql {
    CREATE INDEX echo_strings_i ON echo_strings(str);
  }
} {1 {virtual tables may not be indexed}}

# Test that it is impossible to add a column to a virtual table.
#
ifcapable altertable {
  do_test vtab5.4.2 {
    catchsql {
      ALTER TABLE echo_strings ADD COLUMN col2;
    }
  } {1 {virtual tables may not be altered}}
}

# Test that it is impossible to rename a virtual table.
# UPDATE: It is now possible.
#
# do_test vtab5.4.3 {
#   catchsql {
#     ALTER TABLE echo_strings RENAME TO echo_strings2;
Changes to test/vtab_alter.test.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# command on virtual tables.
#
# $Id: vtab_alter.test,v 1.3 2007/12/13 21:54:11 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !vtab {
  finish_test
  return
}

# Register the echo module.
#
# This test uses a special feature of the echo module. If the name







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# command on virtual tables.
#
# $Id: vtab_alter.test,v 1.3 2007/12/13 21:54:11 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !vtab||!altertable {
  finish_test
  return
}

# Register the echo module.
#
# This test uses a special feature of the echo module. If the name
Changes to test/vtab_shared.test.
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
    SELECT * FROM t2 UNION ALL
    SELECT * FROM t3 
  } db
} {1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6}

# Try a rename or two.
#

do_test vtab_shared-1.13.1 {
  execsql { ALTER TABLE t1 RENAME TO t4 }
  execsql { SELECT * FROM t4 } db
} {1 2 3 4 5 6}
do_test vtab_shared-1.13.2 {
  execsql { SELECT * FROM t4 } db2
} {1 2 3 4 5 6}
do_test vtab_shared-1.13.3 {
  execsql { ALTER TABLE t2 RENAME TO t5 }
  execsql { SELECT * FROM t4 } db2
} {1 2 3 4 5 6}


# Try an UPDATE/INSERT/DELETE on a shared vtab as the first statement after a
# schema is loaded.
do_test vtab_shared_1.14.1 {
  db2 close
  sqlite3 db2 test.db
  register_echo_module [sqlite3_connection_pointer db2]







>
|
|
|
|
|
|
|
|
|
|
|
>







140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
    SELECT * FROM t2 UNION ALL
    SELECT * FROM t3 
  } db
} {1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6}

# Try a rename or two.
#
ifcapable altertable {
  do_test vtab_shared-1.13.1 {
    execsql { ALTER TABLE t1 RENAME TO t4 }
    execsql { SELECT * FROM t4 } db
  } {1 2 3 4 5 6}
  do_test vtab_shared-1.13.2 {
    execsql { SELECT * FROM t4 } db2
  } {1 2 3 4 5 6}
  do_test vtab_shared-1.13.3 {
    execsql { ALTER TABLE t2 RENAME TO t5 }
    execsql { SELECT * FROM t4 } db2
  } {1 2 3 4 5 6}
}

# Try an UPDATE/INSERT/DELETE on a shared vtab as the first statement after a
# schema is loaded.
do_test vtab_shared_1.14.1 {
  db2 close
  sqlite3 db2 test.db
  register_echo_module [sqlite3_connection_pointer db2]