| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 index i3 T2 \ | 166 index i3 T2 \ |
| 167 index {sqlite_autoindex_T2_1} T2 \ | 167 index {sqlite_autoindex_T2_1} T2 \ |
| 168 index {sqlite_autoindex_T2_2} T2 \ | 168 index {sqlite_autoindex_T2_2} T2 \ |
| 169 ] | 169 ] |
| 170 } else { | 170 } else { |
| 171 execsql { | 171 execsql { |
| 172 DROP TABLE TempTab; | 172 DROP TABLE TempTab; |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 # Create bogus application-defined functions for functions used |
| 177 # internally by ALTER TABLE, to ensure that ALTER TABLE falls back |
| 178 # to the built-in functions. |
| 179 # |
| 180 proc failing_app_func {args} {error "bad function"} |
| 181 do_test alter-1.7-prep { |
| 182 db func substr failing_app_func |
| 183 db func like failing_app_func |
| 184 db func sqlite_rename_table failing_app_func |
| 185 db func sqlite_rename_trigger failing_app_func |
| 186 db func sqlite_rename_parent failing_app_func |
| 187 catchsql {SELECT substr(name,1,3) FROM sqlite_master} |
| 188 } {1 {bad function}} |
| 189 |
| 176 # Make sure the ALTER TABLE statements work with the | 190 # Make sure the ALTER TABLE statements work with the |
| 177 # non-callback API | 191 # non-callback API |
| 178 # | 192 # |
| 179 do_test alter-1.7 { | 193 do_test alter-1.7 { |
| 180 stepsql $DB { | 194 stepsql $DB { |
| 181 ALTER TABLE [-t1-] RENAME to [*t1*]; | 195 ALTER TABLE [-t1-] RENAME to [*t1*]; |
| 182 ALTER TABLE T2 RENAME TO [<t2>]; | 196 ALTER TABLE T2 RENAME TO [<t2>]; |
| 183 } | 197 } |
| 184 execsql { | 198 execsql { |
| 185 DELETE FROM objlist; | 199 DELETE FROM objlist; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 execsql { | 574 execsql { |
| 561 ALTER TABLE tbl1 RENAME TO tbl2; | 575 ALTER TABLE tbl1 RENAME TO tbl2; |
| 562 SELECT * FROM tbl2; | 576 SELECT * FROM tbl2; |
| 563 } db2 | 577 } db2 |
| 564 } {x y z} | 578 } {x y z} |
| 565 do_test alter-5.3 { | 579 do_test alter-5.3 { |
| 566 db2 close | 580 db2 close |
| 567 } {} | 581 } {} |
| 568 | 582 |
| 569 foreach tblname [execsql { | 583 foreach tblname [execsql { |
| 570 SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite%' | 584 SELECT name FROM sqlite_master |
| 585 WHERE type='table' AND name NOT GLOB 'sqlite*' |
| 571 }] { | 586 }] { |
| 572 execsql "DROP TABLE \"$tblname\"" | 587 execsql "DROP TABLE \"$tblname\"" |
| 573 } | 588 } |
| 574 | 589 |
| 575 set ::tbl_name "abc\uABCDdef" | 590 set ::tbl_name "abc\uABCDdef" |
| 576 do_test alter-6.1 { | 591 do_test alter-6.1 { |
| 577 string length $::tbl_name | 592 string length $::tbl_name |
| 578 } {7} | 593 } {7} |
| 579 do_test alter-6.2 { | 594 do_test alter-6.2 { |
| 580 execsql " | 595 execsql " |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 } | 696 } |
| 682 } {{} {} {}} | 697 } {{} {} {}} |
| 683 | 698 |
| 684 #------------------------------------------------------------------------ | 699 #------------------------------------------------------------------------ |
| 685 # alter-10.X - Make sure ALTER TABLE works with multi-byte UTF-8 characters | 700 # alter-10.X - Make sure ALTER TABLE works with multi-byte UTF-8 characters |
| 686 # in the names. | 701 # in the names. |
| 687 # | 702 # |
| 688 do_test alter-10.1 { | 703 do_test alter-10.1 { |
| 689 execsql "CREATE TABLE xyz(x UNIQUE)" | 704 execsql "CREATE TABLE xyz(x UNIQUE)" |
| 690 execsql "ALTER TABLE xyz RENAME TO xyz\u1234abc" | 705 execsql "ALTER TABLE xyz RENAME TO xyz\u1234abc" |
| 691 execsql {SELECT name FROM sqlite_master WHERE name LIKE 'xyz%'} | 706 execsql {SELECT name FROM sqlite_master WHERE name GLOB 'xyz*'} |
| 692 } [list xyz\u1234abc] | 707 } [list xyz\u1234abc] |
| 693 do_test alter-10.2 { | 708 do_test alter-10.2 { |
| 694 execsql {SELECT name FROM sqlite_master WHERE name LIKE 'sqlite_autoindex%'} | 709 execsql {SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_autoindex*'} |
| 695 } [list sqlite_autoindex_xyz\u1234abc_1] | 710 } [list sqlite_autoindex_xyz\u1234abc_1] |
| 696 do_test alter-10.3 { | 711 do_test alter-10.3 { |
| 697 execsql "ALTER TABLE xyz\u1234abc RENAME TO xyzabc" | 712 execsql "ALTER TABLE xyz\u1234abc RENAME TO xyzabc" |
| 698 execsql {SELECT name FROM sqlite_master WHERE name LIKE 'xyz%'} | 713 execsql {SELECT name FROM sqlite_master WHERE name GLOB 'xyz*'} |
| 699 } [list xyzabc] | 714 } [list xyzabc] |
| 700 do_test alter-10.4 { | 715 do_test alter-10.4 { |
| 701 execsql {SELECT name FROM sqlite_master WHERE name LIKE 'sqlite_autoindex%'} | 716 execsql {SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_autoindex*'} |
| 702 } [list sqlite_autoindex_xyzabc_1] | 717 } [list sqlite_autoindex_xyzabc_1] |
| 703 | 718 |
| 704 do_test alter-11.1 { | 719 do_test alter-11.1 { |
| 705 sqlite3_exec db {CREATE TABLE t11(%c6%c6)} | 720 sqlite3_exec db {CREATE TABLE t11(%c6%c6)} |
| 706 execsql { | 721 execsql { |
| 707 ALTER TABLE t11 ADD COLUMN abc; | 722 ALTER TABLE t11 ADD COLUMN abc; |
| 708 } | 723 } |
| 709 catchsql { | 724 catchsql { |
| 710 ALTER TABLE t11 ADD COLUMN abc; | 725 ALTER TABLE t11 ADD COLUMN abc; |
| 711 } | 726 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 # Ticket #3102: | 803 # Ticket #3102: |
| 789 # Verify that comments do not interfere with the table rename | 804 # Verify that comments do not interfere with the table rename |
| 790 # algorithm. | 805 # algorithm. |
| 791 # | 806 # |
| 792 do_test alter-13.1 { | 807 do_test alter-13.1 { |
| 793 execsql { | 808 execsql { |
| 794 CREATE TABLE /* hi */ t3102a(x); | 809 CREATE TABLE /* hi */ t3102a(x); |
| 795 CREATE TABLE t3102b -- comment | 810 CREATE TABLE t3102b -- comment |
| 796 (y); | 811 (y); |
| 797 CREATE INDEX t3102c ON t3102a(x); | 812 CREATE INDEX t3102c ON t3102a(x); |
| 798 SELECT name FROM sqlite_master WHERE name LIKE 't3102%' ORDER BY 1; | 813 SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; |
| 799 } | 814 } |
| 800 } {t3102a t3102b t3102c} | 815 } {t3102a t3102b t3102c} |
| 801 do_test alter-13.2 { | 816 do_test alter-13.2 { |
| 802 execsql { | 817 execsql { |
| 803 ALTER TABLE t3102a RENAME TO t3102a_rename; | 818 ALTER TABLE t3102a RENAME TO t3102a_rename; |
| 804 SELECT name FROM sqlite_master WHERE name LIKE 't3102%' ORDER BY 1; | 819 SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; |
| 805 } | 820 } |
| 806 } {t3102a_rename t3102b t3102c} | 821 } {t3102a_rename t3102b t3102c} |
| 807 do_test alter-13.3 { | 822 do_test alter-13.3 { |
| 808 execsql { | 823 execsql { |
| 809 ALTER TABLE t3102b RENAME TO t3102b_rename; | 824 ALTER TABLE t3102b RENAME TO t3102b_rename; |
| 810 SELECT name FROM sqlite_master WHERE name LIKE 't3102%' ORDER BY 1; | 825 SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; |
| 811 } | 826 } |
| 812 } {t3102a_rename t3102b_rename t3102c} | 827 } {t3102a_rename t3102b_rename t3102c} |
| 813 | 828 |
| 814 # Ticket #3651 | 829 # Ticket #3651 |
| 815 do_test alter-14.1 { | 830 do_test alter-14.1 { |
| 816 catchsql { | 831 catchsql { |
| 817 CREATE TABLE t3651(a UNIQUE); | 832 CREATE TABLE t3651(a UNIQUE); |
| 818 ALTER TABLE t3651 ADD COLUMN b UNIQUE; | 833 ALTER TABLE t3651 ADD COLUMN b UNIQUE; |
| 819 } | 834 } |
| 820 } {1 {Cannot add a UNIQUE column}} | 835 } {1 {Cannot add a UNIQUE column}} |
| 821 do_test alter-14.2 { | 836 do_test alter-14.2 { |
| 822 catchsql { | 837 catchsql { |
| 823 ALTER TABLE t3651 ADD COLUMN b PRIMARY KEY; | 838 ALTER TABLE t3651 ADD COLUMN b PRIMARY KEY; |
| 824 } | 839 } |
| 825 } {1 {Cannot add a PRIMARY KEY column}} | 840 } {1 {Cannot add a PRIMARY KEY column}} |
| 826 | 841 |
| 827 | 842 |
| 843 #------------------------------------------------------------------------- |
| 844 # Test that it is not possible to use ALTER TABLE on any system table. |
| 845 # |
| 846 set system_table_list {1 sqlite_master} |
| 847 catchsql ANALYZE |
| 848 ifcapable analyze { lappend system_table_list 2 sqlite_stat1 } |
| 849 ifcapable stat2 { lappend system_table_list 3 sqlite_stat2 } |
| 850 |
| 851 foreach {tn tbl} $system_table_list { |
| 852 do_test alter-15.$tn.1 { |
| 853 catchsql "ALTER TABLE $tbl RENAME TO xyz" |
| 854 } [list 1 "table $tbl may not be altered"] |
| 855 |
| 856 do_test alter-15.$tn.2 { |
| 857 catchsql "ALTER TABLE $tbl ADD COLUMN xyz" |
| 858 } [list 1 "table $tbl may not be altered"] |
| 859 } |
| 860 |
| 861 |
| 828 finish_test | 862 finish_test |
| OLD | NEW |