OLD | NEW |
1 # 2004 November 10 | 1 # 2004 November 10 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #************************************************************************* | 10 #************************************************************************* |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 table <t2> <t2> \ | 214 table <t2> <t2> \ |
215 index i3 <t2> \ | 215 index i3 <t2> \ |
216 index {sqlite_autoindex_<t2>_1} <t2> \ | 216 index {sqlite_autoindex_<t2>_1} <t2> \ |
217 index {sqlite_autoindex_<t2>_2} <t2> \ | 217 index {sqlite_autoindex_<t2>_2} <t2> \ |
218 ] | 218 ] |
219 | 219 |
220 # Check that ALTER TABLE works on attached databases. | 220 # Check that ALTER TABLE works on attached databases. |
221 # | 221 # |
222 ifcapable attach { | 222 ifcapable attach { |
223 do_test alter-1.8.1 { | 223 do_test alter-1.8.1 { |
224 file delete -force test2.db | 224 forcedelete test2.db |
225 file delete -force test2.db-journal | 225 forcedelete test2.db-journal |
226 execsql { | 226 execsql { |
227 ATTACH 'test2.db' AS aux; | 227 ATTACH 'test2.db' AS aux; |
228 } | 228 } |
229 } {} | 229 } {} |
230 do_test alter-1.8.2 { | 230 do_test alter-1.8.2 { |
231 execsql { | 231 execsql { |
232 CREATE TABLE t4(a PRIMARY KEY, b, c); | 232 CREATE TABLE t4(a PRIMARY KEY, b, c); |
233 CREATE TABLE aux.t4(a PRIMARY KEY, b, c); | 233 CREATE TABLE aux.t4(a PRIMARY KEY, b, c); |
234 CREATE INDEX i4 ON t4(b); | 234 CREATE INDEX i4 ON t4(b); |
235 CREATE INDEX aux.i4 ON t4(b); | 235 CREATE INDEX aux.i4 ON t4(b); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 # An SQL user-function for triggers to fire, so that we know they | 342 # An SQL user-function for triggers to fire, so that we know they |
343 # are working. | 343 # are working. |
344 proc trigfunc {args} { | 344 proc trigfunc {args} { |
345 set ::TRIGGER $args | 345 set ::TRIGGER $args |
346 } | 346 } |
347 db func trigfunc trigfunc | 347 db func trigfunc trigfunc |
348 | 348 |
349 do_test alter-3.1.0 { | 349 do_test alter-3.1.0 { |
350 execsql { | 350 execsql { |
351 CREATE TABLE t6(a, b, c); | 351 CREATE TABLE t6(a, b, c); |
352 CREATE TRIGGER trig1 AFTER INSERT ON t6 BEGIN | 352 -- Different case for the table name in the trigger. |
| 353 CREATE TRIGGER trig1 AFTER INSERT ON T6 BEGIN |
353 SELECT trigfunc('trig1', new.a, new.b, new.c); | 354 SELECT trigfunc('trig1', new.a, new.b, new.c); |
354 END; | 355 END; |
355 } | 356 } |
356 } {} | 357 } {} |
357 do_test alter-3.1.1 { | 358 do_test alter-3.1.1 { |
358 execsql { | 359 execsql { |
359 INSERT INTO t6 VALUES(1, 2, 3); | 360 INSERT INTO t6 VALUES(1, 2, 3); |
360 } | 361 } |
361 set ::TRIGGER | 362 set ::TRIGGER |
362 } {trig1 1 2 3} | 363 } {trig1 1 2 3} |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 do_test alter-3.1.8 { | 406 do_test alter-3.1.8 { |
406 execsql { | 407 execsql { |
407 ALTER TABLE t8 RENAME TO t9; | 408 ALTER TABLE t8 RENAME TO t9; |
408 INSERT INTO t9 VALUES(4, 5, 6); | 409 INSERT INTO t9 VALUES(4, 5, 6); |
409 } | 410 } |
410 set ::TRIGGER | 411 set ::TRIGGER |
411 } {trig3 4 5 6} | 412 } {trig3 4 5 6} |
412 | 413 |
413 # Make sure "ON" cannot be used as a database, table or column name without | 414 # Make sure "ON" cannot be used as a database, table or column name without |
414 # quoting. Otherwise the sqlite_alter_trigger() function might not work. | 415 # quoting. Otherwise the sqlite_alter_trigger() function might not work. |
415 file delete -force test3.db | 416 forcedelete test3.db |
416 file delete -force test3.db-journal | 417 forcedelete test3.db-journal |
417 ifcapable attach { | 418 ifcapable attach { |
418 do_test alter-3.2.1 { | 419 do_test alter-3.2.1 { |
419 catchsql { | 420 catchsql { |
420 ATTACH 'test3.db' AS ON; | 421 ATTACH 'test3.db' AS ON; |
421 } | 422 } |
422 } {1 {near "ON": syntax error}} | 423 } {1 {near "ON": syntax error}} |
423 do_test alter-3.2.2 { | 424 do_test alter-3.2.2 { |
424 catchsql { | 425 catchsql { |
425 ATTACH 'test3.db' AS 'ON'; | 426 ATTACH 'test3.db' AS 'ON'; |
426 } | 427 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 do_test alter-6.7 { | 644 do_test alter-6.7 { |
644 execsql " | 645 execsql " |
645 INSERT INTO ${::tbl_name} VALUES(1, 2, 3, 4, 5); | 646 INSERT INTO ${::tbl_name} VALUES(1, 2, 3, 4, 5); |
646 SELECT $::col_name, $::col_name2 FROM $::tbl_name; | 647 SELECT $::col_name, $::col_name2 FROM $::tbl_name; |
647 " | 648 " |
648 } {4 5} | 649 } {4 5} |
649 | 650 |
650 # Ticket #1665: Make sure ALTER TABLE ADD COLUMN works on a table | 651 # Ticket #1665: Make sure ALTER TABLE ADD COLUMN works on a table |
651 # that includes a COLLATE clause. | 652 # that includes a COLLATE clause. |
652 # | 653 # |
653 do_test alter-7.1 { | 654 do_realnum_test alter-7.1 { |
654 execsql { | 655 execsql { |
655 CREATE TABLE t1(a TEXT COLLATE BINARY); | 656 CREATE TABLE t1(a TEXT COLLATE BINARY); |
656 ALTER TABLE t1 ADD COLUMN b INTEGER COLLATE NOCASE; | 657 ALTER TABLE t1 ADD COLUMN b INTEGER COLLATE NOCASE; |
657 INSERT INTO t1 VALUES(1,'-2'); | 658 INSERT INTO t1 VALUES(1,'-2'); |
658 INSERT INTO t1 VALUES(5.4e-08,'5.4e-08'); | 659 INSERT INTO t1 VALUES(5.4e-08,'5.4e-08'); |
659 SELECT typeof(a), a, typeof(b), b FROM t1; | 660 SELECT typeof(a), a, typeof(b), b FROM t1; |
660 } | 661 } |
661 } {text 1 integer -2 text 5.4e-08 real 5.4e-08} | 662 } {text 1 integer -2 text 5.4e-08 real 5.4e-08} |
662 | 663 |
663 # Make sure that when a column is added by ALTER TABLE ADD COLUMN and has | 664 # Make sure that when a column is added by ALTER TABLE ADD COLUMN and has |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 } | 840 } |
840 } {1 {Cannot add a PRIMARY KEY column}} | 841 } {1 {Cannot add a PRIMARY KEY column}} |
841 | 842 |
842 | 843 |
843 #------------------------------------------------------------------------- | 844 #------------------------------------------------------------------------- |
844 # Test that it is not possible to use ALTER TABLE on any system table. | 845 # Test that it is not possible to use ALTER TABLE on any system table. |
845 # | 846 # |
846 set system_table_list {1 sqlite_master} | 847 set system_table_list {1 sqlite_master} |
847 catchsql ANALYZE | 848 catchsql ANALYZE |
848 ifcapable analyze { lappend system_table_list 2 sqlite_stat1 } | 849 ifcapable analyze { lappend system_table_list 2 sqlite_stat1 } |
849 ifcapable stat2 { lappend system_table_list 3 sqlite_stat2 } | 850 ifcapable stat3 { lappend system_table_list 3 sqlite_stat3 } |
| 851 ifcapable stat4 { lappend system_table_list 4 sqlite_stat4 } |
850 | 852 |
851 foreach {tn tbl} $system_table_list { | 853 foreach {tn tbl} $system_table_list { |
852 do_test alter-15.$tn.1 { | 854 do_test alter-15.$tn.1 { |
853 catchsql "ALTER TABLE $tbl RENAME TO xyz" | 855 catchsql "ALTER TABLE $tbl RENAME TO xyz" |
854 } [list 1 "table $tbl may not be altered"] | 856 } [list 1 "table $tbl may not be altered"] |
855 | 857 |
856 do_test alter-15.$tn.2 { | 858 do_test alter-15.$tn.2 { |
857 catchsql "ALTER TABLE $tbl ADD COLUMN xyz" | 859 catchsql "ALTER TABLE $tbl ADD COLUMN xyz" |
858 } [list 1 "table $tbl may not be altered"] | 860 } [list 1 "table $tbl may not be altered"] |
859 } | 861 } |
860 | 862 |
| 863 #------------------------------------------------------------------------ |
| 864 # Verify that ALTER TABLE works on tables with the WITHOUT rowid option. |
| 865 # |
| 866 do_execsql_test alter-16.1 { |
| 867 CREATE TABLE t16a(a TEXT, b REAL, c INT, PRIMARY KEY(a,b)) WITHOUT rowid; |
| 868 INSERT INTO t16a VALUES('abc',1.25,99); |
| 869 ALTER TABLE t16a ADD COLUMN d TEXT DEFAULT 'xyzzy'; |
| 870 INSERT INTO t16a VALUES('cba',5.5,98,'fizzle'); |
| 871 SELECT * FROM t16a ORDER BY a; |
| 872 } {abc 1.25 99 xyzzy cba 5.5 98 fizzle} |
| 873 do_execsql_test alter-16.2 { |
| 874 ALTER TABLE t16a RENAME TO t16a_rn; |
| 875 SELECT * FROM t16a_rn ORDER BY a; |
| 876 } {abc 1.25 99 xyzzy cba 5.5 98 fizzle} |
| 877 |
| 878 #------------------------------------------------------------------------- |
| 879 # Verify that NULL values into the internal-use-only sqlite_rename_*() |
| 880 # functions do not cause problems. |
| 881 # |
| 882 do_execsql_test alter-17.1 { |
| 883 SELECT sqlite_rename_table('CREATE TABLE xyz(a,b,c)','abc'); |
| 884 } {{CREATE TABLE "abc"(a,b,c)}} |
| 885 do_execsql_test alter-17.2 { |
| 886 SELECT sqlite_rename_table('CREATE TABLE xyz(a,b,c)',NULL); |
| 887 } {{CREATE TABLE "(NULL)"(a,b,c)}} |
| 888 do_execsql_test alter-17.3 { |
| 889 SELECT sqlite_rename_table(NULL,'abc'); |
| 890 } {{}} |
| 891 do_execsql_test alter-17.4 { |
| 892 SELECT sqlite_rename_trigger('CREATE TRIGGER r1 ON xyz WHEN','abc'); |
| 893 } {{CREATE TRIGGER r1 ON "abc" WHEN}} |
| 894 do_execsql_test alter-17.5 { |
| 895 SELECT sqlite_rename_trigger('CREATE TRIGGER r1 ON xyz WHEN',NULL); |
| 896 } {{CREATE TRIGGER r1 ON "(NULL)" WHEN}} |
| 897 do_execsql_test alter-17.6 { |
| 898 SELECT sqlite_rename_trigger(NULL,'abc'); |
| 899 } {{}} |
| 900 do_execsql_test alter-17.7 { |
| 901 SELECT sqlite_rename_parent('CREATE TABLE t1(a REFERENCES "xyzzy")', |
| 902 'xyzzy','lmnop'); |
| 903 } {{CREATE TABLE t1(a REFERENCES "lmnop")}} |
| 904 do_execsql_test alter-17.8 { |
| 905 SELECT sqlite_rename_parent('CREATE TABLE t1(a REFERENCES "xyzzy")', |
| 906 'xyzzy',NULL); |
| 907 } {{CREATE TABLE t1(a REFERENCES "(NULL)")}} |
| 908 do_execsql_test alter-17.9 { |
| 909 SELECT sqlite_rename_parent('CREATE TABLE t1(a REFERENCES "xyzzy")', |
| 910 NULL, 'lmnop'); |
| 911 } {{}} |
| 912 do_execsql_test alter-17.10 { |
| 913 SELECT sqlite_rename_parent(NULL,'abc','xyz'); |
| 914 } {{}} |
861 | 915 |
862 finish_test | 916 finish_test |
OLD | NEW |