drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 1 | # 2001 September 15 |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 2 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 5 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements regression tests for SQLite library. The |
| 12 | # focus of this file is testing the CREATE TABLE statement. |
| 13 | # |
drh | 97fc3d0 | 2002-05-22 21:27:03 +0000 | [diff] [blame^] | 14 | # $Id: table.test,v 1.16 2002/05/22 21:27:04 drh Exp $ |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
| 19 | # Create a basic table and verify it is added to sqlite_master |
| 20 | # |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 21 | do_test table-1.1 { |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 22 | execsql { |
| 23 | CREATE TABLE test1 ( |
| 24 | one varchar(10), |
| 25 | two text |
| 26 | ) |
| 27 | } |
| 28 | execsql { |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 29 | SELECT sql FROM sqlite_master WHERE type!='meta' |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 30 | } |
| 31 | } {{CREATE TABLE test1 ( |
| 32 | one varchar(10), |
| 33 | two text |
| 34 | )}} |
| 35 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 36 | |
| 37 | # Verify the other fields of the sqlite_master file. |
| 38 | # |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 39 | do_test table-1.3 { |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 40 | execsql {SELECT name, tbl_name, type FROM sqlite_master WHERE type!='meta'} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 41 | } {test1 test1 table} |
| 42 | |
| 43 | # Close and reopen the database. Verify that everything is |
| 44 | # still the same. |
| 45 | # |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 46 | do_test table-1.4 { |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 47 | db close |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 48 | sqlite db test.db |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 49 | execsql {SELECT name, tbl_name, type from sqlite_master WHERE type!='meta'} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 50 | } {test1 test1 table} |
| 51 | |
| 52 | # Drop the database and make sure it disappears. |
| 53 | # |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 54 | do_test table-1.5 { |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 55 | execsql {DROP TABLE test1} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 56 | execsql {SELECT * FROM sqlite_master WHERE type!='meta'} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 57 | } {} |
| 58 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 59 | # Close and reopen the database. Verify that the table is |
| 60 | # still gone. |
| 61 | # |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 62 | do_test table-1.6 { |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 63 | db close |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 64 | sqlite db test.db |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 65 | execsql {SELECT name FROM sqlite_master WHERE type!='meta'} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 66 | } {} |
| 67 | |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 68 | # Repeat the above steps, but this time quote the table name. |
| 69 | # |
| 70 | do_test table-1.10 { |
| 71 | execsql {CREATE TABLE "create" (f1 int)} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 72 | execsql {SELECT name FROM sqlite_master WHERE type!='meta'} |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 73 | } {create} |
| 74 | do_test table-1.11 { |
| 75 | execsql {DROP TABLE "create"} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 76 | execsql {SELECT name FROM "sqlite_master" WHERE type!='meta'} |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 77 | } {} |
| 78 | do_test table-1.12 { |
| 79 | execsql {CREATE TABLE test1("f1 ho" int)} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 80 | execsql {SELECT name as "X" FROM sqlite_master WHERE type!='meta'} |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 81 | } {test1} |
| 82 | do_test table-1.13 { |
| 83 | execsql {DROP TABLE "TEST1"} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 84 | execsql {SELECT name FROM "sqlite_master" WHERE type!='meta'} |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 85 | } {} |
| 86 | |
| 87 | |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 88 | |
| 89 | # Verify that we cannot make two tables with the same name |
| 90 | # |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 91 | do_test table-2.1 { |
drh | 4cfa793 | 2000-06-08 15:10:46 +0000 | [diff] [blame] | 92 | execsql {CREATE TABLE TEST2(one text)} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 93 | set v [catch {execsql {CREATE TABLE test2(two text)}} msg] |
| 94 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 95 | } {1 {table test2 already exists}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 96 | do_test table-2.1b { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 97 | set v [catch {execsql {CREATE TABLE sqlite_master(two text)}} msg] |
| 98 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 99 | } {1 {table sqlite_master already exists}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 100 | do_test table-2.1c { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 101 | db close |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 102 | sqlite db test.db |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 103 | set v [catch {execsql {CREATE TABLE sqlite_master(two text)}} msg] |
| 104 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 105 | } {1 {table sqlite_master already exists}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 106 | do_test table-2.1d { |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 107 | execsql {DROP TABLE test2; SELECT name FROM sqlite_master WHERE type!='meta'} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 108 | } {} |
| 109 | |
| 110 | # Verify that we cannot make a table with the same name as an index |
| 111 | # |
drh | dcc581c | 2000-05-30 13:44:19 +0000 | [diff] [blame] | 112 | do_test table-2.2a { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 113 | execsql {CREATE TABLE test2(one text); CREATE INDEX test3 ON test2(one)} |
| 114 | set v [catch {execsql {CREATE TABLE test3(two text)}} msg] |
| 115 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 116 | } {1 {there is already an index named test3}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 117 | do_test table-2.2b { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 118 | db close |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 119 | sqlite db test.db |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 120 | set v [catch {execsql {CREATE TABLE test3(two text)}} msg] |
| 121 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 122 | } {1 {there is already an index named test3}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 123 | do_test table-2.2c { |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 124 | execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} |
| 125 | } {test2 test3} |
| 126 | do_test table-2.2d { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 127 | execsql {DROP INDEX test3} |
| 128 | set v [catch {execsql {CREATE TABLE test3(two text)}} msg] |
| 129 | lappend v $msg |
| 130 | } {0 {}} |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 131 | do_test table-2.2e { |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 132 | execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 133 | } {test2 test3} |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 134 | do_test table-2.2f { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 135 | execsql {DROP TABLE test2; DROP TABLE test3} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 136 | execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 137 | } {} |
| 138 | |
| 139 | # Create a table with many field names |
| 140 | # |
| 141 | set big_table \ |
| 142 | {CREATE TABLE big( |
| 143 | f1 varchar(20), |
| 144 | f2 char(10), |
drh | dcc581c | 2000-05-30 13:44:19 +0000 | [diff] [blame] | 145 | f3 varchar(30) primary key, |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 146 | f4 text, |
| 147 | f5 text, |
| 148 | f6 text, |
| 149 | f7 text, |
| 150 | f8 text, |
| 151 | f9 text, |
| 152 | f10 text, |
| 153 | f11 text, |
| 154 | f12 text, |
| 155 | f13 text, |
| 156 | f14 text, |
| 157 | f15 text, |
| 158 | f16 text, |
| 159 | f17 text, |
| 160 | f18 text, |
| 161 | f19 text, |
| 162 | f20 text |
| 163 | )} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 164 | do_test table-3.1 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 165 | execsql $big_table |
drh | adbca9c | 2001-09-27 15:11:53 +0000 | [diff] [blame] | 166 | execsql {SELECT sql FROM sqlite_master WHERE type=='table'} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 167 | } \{$big_table\} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 168 | do_test table-3.2 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 169 | set v [catch {execsql {CREATE TABLE BIG(xyz foo)}} msg] |
| 170 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 171 | } {1 {table BIG already exists}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 172 | do_test table-3.3 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 173 | set v [catch {execsql {CREATE TABLE biG(xyz foo)}} msg] |
| 174 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 175 | } {1 {table biG already exists}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 176 | do_test table-3.4 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 177 | set v [catch {execsql {CREATE TABLE bIg(xyz foo)}} msg] |
| 178 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 179 | } {1 {table bIg already exists}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 180 | do_test table-3.5 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 181 | db close |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 182 | sqlite db test.db |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 183 | set v [catch {execsql {CREATE TABLE Big(xyz foo)}} msg] |
| 184 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 185 | } {1 {table Big already exists}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 186 | do_test table-3.6 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 187 | execsql {DROP TABLE big} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 188 | execsql {SELECT name FROM sqlite_master WHERE type!='meta'} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 189 | } {} |
| 190 | |
| 191 | # Try creating large numbers of tables |
| 192 | # |
| 193 | set r {} |
| 194 | for {set i 1} {$i<=100} {incr i} { |
| 195 | lappend r test$i |
| 196 | } |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 197 | do_test table-4.1 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 198 | for {set i 1} {$i<=100} {incr i} { |
| 199 | set sql "CREATE TABLE test$i (" |
| 200 | for {set k 1} {$k<$i} {incr k} { |
| 201 | append sql "field$k text," |
| 202 | } |
| 203 | append sql "last_field text)" |
| 204 | execsql $sql |
| 205 | } |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 206 | execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 207 | } $r |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 208 | do_test table-4.1b { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 209 | db close |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 210 | sqlite db test.db |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 211 | execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 212 | } $r |
| 213 | |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 214 | # Drop the even numbered tables |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 215 | # |
| 216 | set r {} |
| 217 | for {set i 1} {$i<=100} {incr i 2} { |
| 218 | lappend r test$i |
| 219 | } |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 220 | #execsql {--vdbe-trace-on--} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 221 | do_test table-4.2 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 222 | for {set i 2} {$i<=100} {incr i 2} { |
| 223 | set sql "DROP TABLE TEST$i" |
| 224 | execsql $sql |
| 225 | } |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 226 | execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 227 | } $r |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 228 | #exit |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 229 | |
| 230 | # Drop the odd number tables |
| 231 | # |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 232 | do_test table-4.3 { |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 233 | for {set i 1} {$i<=100} {incr i 2} { |
| 234 | set sql "DROP TABLE test$i" |
| 235 | execsql $sql |
| 236 | } |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 237 | execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} |
drh | b24fcbe | 2000-05-29 23:30:50 +0000 | [diff] [blame] | 238 | } {} |
| 239 | |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 240 | # Try to drop a table that does not exist |
| 241 | # |
| 242 | do_test table-5.1 { |
| 243 | set v [catch {execsql {DROP TABLE test9}} msg] |
| 244 | lappend v $msg |
| 245 | } {1 {no such table: test9}} |
| 246 | |
| 247 | # Try to drop sqlite_master |
| 248 | # |
| 249 | do_test table-5.2 { |
| 250 | set v [catch {execsql {DROP TABLE sqlite_master}} msg] |
| 251 | lappend v $msg |
drh | 1d37e28 | 2000-05-30 03:12:21 +0000 | [diff] [blame] | 252 | } {1 {table sqlite_master may not be dropped}} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 253 | |
| 254 | # Make sure an EXPLAIN does not really create a new table |
| 255 | # |
| 256 | do_test table-5.3 { |
| 257 | execsql {EXPLAIN CREATE TABLE test1(f1 int)} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 258 | execsql {SELECT name FROM sqlite_master WHERE type!='meta'} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 259 | } {} |
| 260 | |
| 261 | # Make sure an EXPLAIN does not really drop an existing table |
| 262 | # |
| 263 | do_test table-5.4 { |
| 264 | execsql {CREATE TABLE test1(f1 int)} |
| 265 | execsql {EXPLAIN DROP TABLE test1} |
drh | 2803757 | 2000-08-02 13:47:41 +0000 | [diff] [blame] | 266 | execsql {SELECT name FROM sqlite_master WHERE type!='meta'} |
drh | 1b6a71f | 2000-05-29 23:58:11 +0000 | [diff] [blame] | 267 | } {test1} |
| 268 | |
drh | 4cfa793 | 2000-06-08 15:10:46 +0000 | [diff] [blame] | 269 | # Create a table with a goofy name |
| 270 | # |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 271 | #do_test table-6.1 { |
| 272 | # execsql {CREATE TABLE 'Spaces In This Name!'(x int)} |
| 273 | # execsql {INSERT INTO 'spaces in this name!' VALUES(1)} |
| 274 | # set list [glob -nocomplain testdb/spaces*.tbl] |
| 275 | #} {testdb/spaces+in+this+name+.tbl} |
drh | 4cfa793 | 2000-06-08 15:10:46 +0000 | [diff] [blame] | 276 | |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 277 | # Try using keywords as table names or column names. |
| 278 | # |
| 279 | do_test table-7.1 { |
| 280 | set v [catch {execsql { |
| 281 | CREATE TABLE weird( |
| 282 | desc text, |
| 283 | asc text, |
| 284 | explain int, |
drh | 17f7193 | 2002-02-21 12:01:27 +0000 | [diff] [blame] | 285 | [14_vac] boolean, |
| 286 | fuzzy_dog_12 varchar(10), |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 287 | begin blob, |
| 288 | end clob |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 289 | ) |
| 290 | }} msg] |
| 291 | lappend v $msg |
| 292 | } {0 {}} |
| 293 | do_test table-7.2 { |
| 294 | execsql { |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 295 | INSERT INTO weird VALUES('a','b',9,0,'xyz','hi','y''all'); |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 296 | SELECT * FROM weird; |
| 297 | } |
drh | d400728 | 2001-04-12 23:21:58 +0000 | [diff] [blame] | 298 | } {a b 9 0 xyz hi y'all} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 299 | do_test table-7.3 { |
| 300 | execsql2 { |
| 301 | SELECT * FROM weird; |
| 302 | } |
drh | 17f7193 | 2002-02-21 12:01:27 +0000 | [diff] [blame] | 303 | } {desc a asc b explain 9 14_vac 0 fuzzy_dog_12 xyz begin hi end y'all} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 304 | |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 305 | # Try out the CREATE TABLE AS syntax |
| 306 | # |
| 307 | do_test table-8.1 { |
| 308 | execsql2 { |
| 309 | CREATE TABLE t2 AS SELECT * FROM weird; |
| 310 | SELECT * FROM t2; |
| 311 | } |
drh | 17f7193 | 2002-02-21 12:01:27 +0000 | [diff] [blame] | 312 | } {desc a asc b explain 9 14_vac 0 fuzzy_dog_12 xyz begin hi end y'all} |
| 313 | do_test table-8.1.1 { |
| 314 | execsql { |
| 315 | SELECT sql FROM sqlite_master WHERE name='t2'; |
| 316 | } |
| 317 | } {{CREATE TABLE t2( |
| 318 | 'desc', |
| 319 | 'asc', |
| 320 | 'explain', |
| 321 | '14_vac', |
| 322 | fuzzy_dog_12, |
| 323 | 'begin', |
| 324 | 'end' |
| 325 | )}} |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 326 | do_test table-8.2 { |
| 327 | execsql { |
| 328 | CREATE TABLE 't3''xyz'(a,b,c); |
| 329 | INSERT INTO [t3'xyz] VALUES(1,2,3); |
| 330 | SELECT * FROM [t3'xyz]; |
| 331 | } |
| 332 | } {1 2 3} |
| 333 | do_test table-8.3 { |
| 334 | execsql2 { |
drh | 17f7193 | 2002-02-21 12:01:27 +0000 | [diff] [blame] | 335 | CREATE TABLE [t4'abc] AS SELECT count(*) as cnt, max(b+c) FROM [t3'xyz]; |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 336 | SELECT * FROM [t4'abc]; |
| 337 | } |
drh | 17f7193 | 2002-02-21 12:01:27 +0000 | [diff] [blame] | 338 | } {cnt 1 max(b+c) 5} |
| 339 | do_test table-8.3.1 { |
| 340 | execsql { |
| 341 | SELECT sql FROM sqlite_master WHERE name='t4''abc' |
| 342 | } |
| 343 | } {{CREATE TABLE 't4''abc'(cnt,'max(b+c)')}} |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 344 | do_test table-8.4 { |
| 345 | execsql2 { |
| 346 | CREATE TEMPORARY TABLE t5 AS SELECT count(*) AS [y'all] FROM [t3'xyz]; |
| 347 | SELECT * FROM t5; |
| 348 | } |
| 349 | } {y'all 1} |
| 350 | do_test table-8.5 { |
| 351 | db close |
| 352 | sqlite db test.db |
| 353 | execsql2 { |
| 354 | SELECT * FROM [t4'abc]; |
| 355 | } |
drh | 17f7193 | 2002-02-21 12:01:27 +0000 | [diff] [blame] | 356 | } {cnt 1 max(b+c) 5} |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 357 | do_test table-8.6 { |
| 358 | execsql2 { |
| 359 | SELECT * FROM t2; |
| 360 | } |
drh | 17f7193 | 2002-02-21 12:01:27 +0000 | [diff] [blame] | 361 | } {desc a asc b explain 9 14_vac 0 fuzzy_dog_12 xyz begin hi end y'all} |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 362 | do_test table-8.7 { |
| 363 | catchsql { |
| 364 | SELECT * FROM t5; |
| 365 | } |
| 366 | } {1 {no such table: t5}} |
drh | 17f7193 | 2002-02-21 12:01:27 +0000 | [diff] [blame] | 367 | do_test table-8.8 { |
| 368 | catchsql { |
| 369 | CREATE TABLE t5 AS SELECT * FROM no_such_table; |
| 370 | } |
| 371 | } {1 {no such table: no_such_table}} |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 372 | |
drh | 97fc3d0 | 2002-05-22 21:27:03 +0000 | [diff] [blame^] | 373 | # Make sure we cannot have duplicate column names within a table. |
| 374 | # |
| 375 | do_test table-9.1 { |
| 376 | catchsql { |
| 377 | CREATE TABLE t6(a,b,a); |
| 378 | } |
| 379 | } {1 {duplicate column name: a}} |
| 380 | |
| 381 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 382 | finish_test |