1*1da57d55SToomas Soome# 2c5c4113dSnw141292# 2001 September 15 3c5c4113dSnw141292# 4c5c4113dSnw141292# The author disclaims copyright to this source code. In place of 5c5c4113dSnw141292# a legal notice, here is a blessing: 6c5c4113dSnw141292# 7c5c4113dSnw141292# May you do good and not evil. 8c5c4113dSnw141292# May you find forgiveness for yourself and forgive others. 9c5c4113dSnw141292# May you share freely, never taking more than you give. 10c5c4113dSnw141292# 11c5c4113dSnw141292#*********************************************************************** 12c5c4113dSnw141292# This file implements regression tests for SQLite library. The 13c5c4113dSnw141292# focus of this file is testing the CREATE TABLE statement. 14c5c4113dSnw141292# 15c5c4113dSnw141292# $Id: table.test,v 1.22 2003/01/29 18:46:54 drh Exp $ 16c5c4113dSnw141292 17c5c4113dSnw141292set testdir [file dirname $argv0] 18c5c4113dSnw141292source $testdir/tester.tcl 19c5c4113dSnw141292 20c5c4113dSnw141292# Create a basic table and verify it is added to sqlite_master 21c5c4113dSnw141292# 22c5c4113dSnw141292do_test table-1.1 { 23c5c4113dSnw141292 execsql { 24c5c4113dSnw141292 CREATE TABLE test1 ( 25c5c4113dSnw141292 one varchar(10), 26c5c4113dSnw141292 two text 27c5c4113dSnw141292 ) 28c5c4113dSnw141292 } 29c5c4113dSnw141292 execsql { 30c5c4113dSnw141292 SELECT sql FROM sqlite_master WHERE type!='meta' 31c5c4113dSnw141292 } 32c5c4113dSnw141292} {{CREATE TABLE test1 ( 33c5c4113dSnw141292 one varchar(10), 34c5c4113dSnw141292 two text 35c5c4113dSnw141292 )}} 36c5c4113dSnw141292 37c5c4113dSnw141292 38c5c4113dSnw141292# Verify the other fields of the sqlite_master file. 39c5c4113dSnw141292# 40c5c4113dSnw141292do_test table-1.3 { 41c5c4113dSnw141292 execsql {SELECT name, tbl_name, type FROM sqlite_master WHERE type!='meta'} 42c5c4113dSnw141292} {test1 test1 table} 43c5c4113dSnw141292 44c5c4113dSnw141292# Close and reopen the database. Verify that everything is 45c5c4113dSnw141292# still the same. 46c5c4113dSnw141292# 47c5c4113dSnw141292do_test table-1.4 { 48c5c4113dSnw141292 db close 49c5c4113dSnw141292 sqlite db test.db 50c5c4113dSnw141292 execsql {SELECT name, tbl_name, type from sqlite_master WHERE type!='meta'} 51c5c4113dSnw141292} {test1 test1 table} 52c5c4113dSnw141292 53c5c4113dSnw141292# Drop the database and make sure it disappears. 54c5c4113dSnw141292# 55c5c4113dSnw141292do_test table-1.5 { 56c5c4113dSnw141292 execsql {DROP TABLE test1} 57c5c4113dSnw141292 execsql {SELECT * FROM sqlite_master WHERE type!='meta'} 58c5c4113dSnw141292} {} 59c5c4113dSnw141292 60c5c4113dSnw141292# Close and reopen the database. Verify that the table is 61c5c4113dSnw141292# still gone. 62c5c4113dSnw141292# 63c5c4113dSnw141292do_test table-1.6 { 64c5c4113dSnw141292 db close 65c5c4113dSnw141292 sqlite db test.db 66c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta'} 67c5c4113dSnw141292} {} 68c5c4113dSnw141292 69c5c4113dSnw141292# Repeat the above steps, but this time quote the table name. 70c5c4113dSnw141292# 71c5c4113dSnw141292do_test table-1.10 { 72c5c4113dSnw141292 execsql {CREATE TABLE "create" (f1 int)} 73c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta'} 74c5c4113dSnw141292} {create} 75c5c4113dSnw141292do_test table-1.11 { 76c5c4113dSnw141292 execsql {DROP TABLE "create"} 77c5c4113dSnw141292 execsql {SELECT name FROM "sqlite_master" WHERE type!='meta'} 78c5c4113dSnw141292} {} 79c5c4113dSnw141292do_test table-1.12 { 80c5c4113dSnw141292 execsql {CREATE TABLE test1("f1 ho" int)} 81c5c4113dSnw141292 execsql {SELECT name as "X" FROM sqlite_master WHERE type!='meta'} 82c5c4113dSnw141292} {test1} 83c5c4113dSnw141292do_test table-1.13 { 84c5c4113dSnw141292 execsql {DROP TABLE "TEST1"} 85c5c4113dSnw141292 execsql {SELECT name FROM "sqlite_master" WHERE type!='meta'} 86c5c4113dSnw141292} {} 87c5c4113dSnw141292 88c5c4113dSnw141292 89c5c4113dSnw141292 90c5c4113dSnw141292# Verify that we cannot make two tables with the same name 91c5c4113dSnw141292# 92c5c4113dSnw141292do_test table-2.1 { 93c5c4113dSnw141292 execsql {CREATE TABLE TEST2(one text)} 94c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE test2(two text)}} msg] 95c5c4113dSnw141292 lappend v $msg 96c5c4113dSnw141292} {1 {table test2 already exists}} 97c5c4113dSnw141292do_test table-2.1b { 98c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE sqlite_master(two text)}} msg] 99c5c4113dSnw141292 lappend v $msg 100c5c4113dSnw141292} {1 {table sqlite_master already exists}} 101c5c4113dSnw141292do_test table-2.1c { 102c5c4113dSnw141292 db close 103c5c4113dSnw141292 sqlite db test.db 104c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE sqlite_master(two text)}} msg] 105c5c4113dSnw141292 lappend v $msg 106c5c4113dSnw141292} {1 {table sqlite_master already exists}} 107c5c4113dSnw141292do_test table-2.1d { 108c5c4113dSnw141292 execsql {DROP TABLE test2; SELECT name FROM sqlite_master WHERE type!='meta'} 109c5c4113dSnw141292} {} 110c5c4113dSnw141292 111c5c4113dSnw141292# Verify that we cannot make a table with the same name as an index 112c5c4113dSnw141292# 113c5c4113dSnw141292do_test table-2.2a { 114c5c4113dSnw141292 execsql {CREATE TABLE test2(one text); CREATE INDEX test3 ON test2(one)} 115c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE test3(two text)}} msg] 116c5c4113dSnw141292 lappend v $msg 117c5c4113dSnw141292} {1 {there is already an index named test3}} 118c5c4113dSnw141292do_test table-2.2b { 119c5c4113dSnw141292 db close 120c5c4113dSnw141292 sqlite db test.db 121c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE test3(two text)}} msg] 122c5c4113dSnw141292 lappend v $msg 123c5c4113dSnw141292} {1 {there is already an index named test3}} 124c5c4113dSnw141292do_test table-2.2c { 125c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} 126c5c4113dSnw141292} {test2 test3} 127c5c4113dSnw141292do_test table-2.2d { 128c5c4113dSnw141292 execsql {DROP INDEX test3} 129c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE test3(two text)}} msg] 130c5c4113dSnw141292 lappend v $msg 131c5c4113dSnw141292} {0 {}} 132c5c4113dSnw141292do_test table-2.2e { 133c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} 134c5c4113dSnw141292} {test2 test3} 135c5c4113dSnw141292do_test table-2.2f { 136c5c4113dSnw141292 execsql {DROP TABLE test2; DROP TABLE test3} 137c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} 138c5c4113dSnw141292} {} 139c5c4113dSnw141292 140c5c4113dSnw141292# Create a table with many field names 141c5c4113dSnw141292# 142c5c4113dSnw141292set big_table \ 143c5c4113dSnw141292{CREATE TABLE big( 144c5c4113dSnw141292 f1 varchar(20), 145c5c4113dSnw141292 f2 char(10), 146c5c4113dSnw141292 f3 varchar(30) primary key, 147c5c4113dSnw141292 f4 text, 148c5c4113dSnw141292 f5 text, 149c5c4113dSnw141292 f6 text, 150c5c4113dSnw141292 f7 text, 151c5c4113dSnw141292 f8 text, 152c5c4113dSnw141292 f9 text, 153c5c4113dSnw141292 f10 text, 154c5c4113dSnw141292 f11 text, 155c5c4113dSnw141292 f12 text, 156c5c4113dSnw141292 f13 text, 157c5c4113dSnw141292 f14 text, 158c5c4113dSnw141292 f15 text, 159c5c4113dSnw141292 f16 text, 160c5c4113dSnw141292 f17 text, 161c5c4113dSnw141292 f18 text, 162c5c4113dSnw141292 f19 text, 163c5c4113dSnw141292 f20 text 164c5c4113dSnw141292)} 165c5c4113dSnw141292do_test table-3.1 { 166c5c4113dSnw141292 execsql $big_table 167c5c4113dSnw141292 execsql {SELECT sql FROM sqlite_master WHERE type=='table'} 168c5c4113dSnw141292} \{$big_table\} 169c5c4113dSnw141292do_test table-3.2 { 170c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE BIG(xyz foo)}} msg] 171c5c4113dSnw141292 lappend v $msg 172c5c4113dSnw141292} {1 {table BIG already exists}} 173c5c4113dSnw141292do_test table-3.3 { 174c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE biG(xyz foo)}} msg] 175c5c4113dSnw141292 lappend v $msg 176c5c4113dSnw141292} {1 {table biG already exists}} 177c5c4113dSnw141292do_test table-3.4 { 178c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE bIg(xyz foo)}} msg] 179c5c4113dSnw141292 lappend v $msg 180c5c4113dSnw141292} {1 {table bIg already exists}} 181c5c4113dSnw141292do_test table-3.5 { 182c5c4113dSnw141292 db close 183c5c4113dSnw141292 sqlite db test.db 184c5c4113dSnw141292 set v [catch {execsql {CREATE TABLE Big(xyz foo)}} msg] 185c5c4113dSnw141292 lappend v $msg 186c5c4113dSnw141292} {1 {table Big already exists}} 187c5c4113dSnw141292do_test table-3.6 { 188c5c4113dSnw141292 execsql {DROP TABLE big} 189c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta'} 190c5c4113dSnw141292} {} 191c5c4113dSnw141292 192c5c4113dSnw141292# Try creating large numbers of tables 193c5c4113dSnw141292# 194c5c4113dSnw141292set r {} 195c5c4113dSnw141292for {set i 1} {$i<=100} {incr i} { 196c5c4113dSnw141292 lappend r [format test%03d $i] 197c5c4113dSnw141292} 198c5c4113dSnw141292do_test table-4.1 { 199c5c4113dSnw141292 for {set i 1} {$i<=100} {incr i} { 200c5c4113dSnw141292 set sql "CREATE TABLE [format test%03d $i] (" 201c5c4113dSnw141292 for {set k 1} {$k<$i} {incr k} { 202c5c4113dSnw141292 append sql "field$k text," 203c5c4113dSnw141292 } 204c5c4113dSnw141292 append sql "last_field text)" 205c5c4113dSnw141292 execsql $sql 206c5c4113dSnw141292 } 207c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} 208c5c4113dSnw141292} $r 209c5c4113dSnw141292do_test table-4.1b { 210c5c4113dSnw141292 db close 211c5c4113dSnw141292 sqlite db test.db 212c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} 213c5c4113dSnw141292} $r 214c5c4113dSnw141292 215c5c4113dSnw141292# Drop the even numbered tables 216c5c4113dSnw141292# 217c5c4113dSnw141292set r {} 218c5c4113dSnw141292for {set i 1} {$i<=100} {incr i 2} { 219c5c4113dSnw141292 lappend r [format test%03d $i] 220c5c4113dSnw141292} 221c5c4113dSnw141292do_test table-4.2 { 222c5c4113dSnw141292 for {set i 2} {$i<=100} {incr i 2} { 223c5c4113dSnw141292 # if {$i==38} {execsql {pragma vdbe_trace=on}} 224c5c4113dSnw141292 set sql "DROP TABLE [format TEST%03d $i]" 225c5c4113dSnw141292 execsql $sql 226c5c4113dSnw141292 } 227c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} 228c5c4113dSnw141292} $r 229c5c4113dSnw141292#exit 230c5c4113dSnw141292 231c5c4113dSnw141292# Drop the odd number tables 232c5c4113dSnw141292# 233c5c4113dSnw141292do_test table-4.3 { 234c5c4113dSnw141292 for {set i 1} {$i<=100} {incr i 2} { 235c5c4113dSnw141292 set sql "DROP TABLE [format test%03d $i]" 236c5c4113dSnw141292 execsql $sql 237c5c4113dSnw141292 } 238c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta' ORDER BY name} 239c5c4113dSnw141292} {} 240c5c4113dSnw141292 241c5c4113dSnw141292# Try to drop a table that does not exist 242c5c4113dSnw141292# 243c5c4113dSnw141292do_test table-5.1 { 244c5c4113dSnw141292 set v [catch {execsql {DROP TABLE test009}} msg] 245c5c4113dSnw141292 lappend v $msg 246c5c4113dSnw141292} {1 {no such table: test009}} 247c5c4113dSnw141292 248c5c4113dSnw141292# Try to drop sqlite_master 249c5c4113dSnw141292# 250c5c4113dSnw141292do_test table-5.2 { 251c5c4113dSnw141292 set v [catch {execsql {DROP TABLE sqlite_master}} msg] 252c5c4113dSnw141292 lappend v $msg 253c5c4113dSnw141292} {1 {table sqlite_master may not be dropped}} 254c5c4113dSnw141292 255c5c4113dSnw141292# Make sure an EXPLAIN does not really create a new table 256c5c4113dSnw141292# 257c5c4113dSnw141292do_test table-5.3 { 258c5c4113dSnw141292 execsql {EXPLAIN CREATE TABLE test1(f1 int)} 259c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta'} 260c5c4113dSnw141292} {} 261c5c4113dSnw141292 262c5c4113dSnw141292# Make sure an EXPLAIN does not really drop an existing table 263c5c4113dSnw141292# 264c5c4113dSnw141292do_test table-5.4 { 265c5c4113dSnw141292 execsql {CREATE TABLE test1(f1 int)} 266c5c4113dSnw141292 execsql {EXPLAIN DROP TABLE test1} 267c5c4113dSnw141292 execsql {SELECT name FROM sqlite_master WHERE type!='meta'} 268c5c4113dSnw141292} {test1} 269c5c4113dSnw141292 270c5c4113dSnw141292# Create a table with a goofy name 271c5c4113dSnw141292# 272c5c4113dSnw141292#do_test table-6.1 { 273c5c4113dSnw141292# execsql {CREATE TABLE 'Spaces In This Name!'(x int)} 274c5c4113dSnw141292# execsql {INSERT INTO 'spaces in this name!' VALUES(1)} 275c5c4113dSnw141292# set list [glob -nocomplain testdb/spaces*.tbl] 276c5c4113dSnw141292#} {testdb/spaces+in+this+name+.tbl} 277c5c4113dSnw141292 278c5c4113dSnw141292# Try using keywords as table names or column names. 279c5c4113dSnw141292# 280c5c4113dSnw141292do_test table-7.1 { 281c5c4113dSnw141292 set v [catch {execsql { 282c5c4113dSnw141292 CREATE TABLE weird( 283c5c4113dSnw141292 desc text, 284c5c4113dSnw141292 asc text, 285c5c4113dSnw141292 explain int, 286c5c4113dSnw141292 [14_vac] boolean, 287c5c4113dSnw141292 fuzzy_dog_12 varchar(10), 288c5c4113dSnw141292 begin blob, 289c5c4113dSnw141292 end clob 290c5c4113dSnw141292 ) 291c5c4113dSnw141292 }} msg] 292c5c4113dSnw141292 lappend v $msg 293c5c4113dSnw141292} {0 {}} 294c5c4113dSnw141292do_test table-7.2 { 295c5c4113dSnw141292 execsql { 296c5c4113dSnw141292 INSERT INTO weird VALUES('a','b',9,0,'xyz','hi','y''all'); 297c5c4113dSnw141292 SELECT * FROM weird; 298c5c4113dSnw141292 } 299c5c4113dSnw141292} {a b 9 0 xyz hi y'all} 300c5c4113dSnw141292do_test table-7.3 { 301c5c4113dSnw141292 execsql2 { 302c5c4113dSnw141292 SELECT * FROM weird; 303c5c4113dSnw141292 } 304c5c4113dSnw141292} {desc a asc b explain 9 14_vac 0 fuzzy_dog_12 xyz begin hi end y'all} 305c5c4113dSnw141292 306c5c4113dSnw141292# Try out the CREATE TABLE AS syntax 307c5c4113dSnw141292# 308c5c4113dSnw141292do_test table-8.1 { 309c5c4113dSnw141292 execsql2 { 310c5c4113dSnw141292 CREATE TABLE t2 AS SELECT * FROM weird; 311c5c4113dSnw141292 SELECT * FROM t2; 312c5c4113dSnw141292 } 313c5c4113dSnw141292} {desc a asc b explain 9 14_vac 0 fuzzy_dog_12 xyz begin hi end y'all} 314c5c4113dSnw141292do_test table-8.1.1 { 315c5c4113dSnw141292 execsql { 316c5c4113dSnw141292 SELECT sql FROM sqlite_master WHERE name='t2'; 317c5c4113dSnw141292 } 318c5c4113dSnw141292} {{CREATE TABLE t2( 319c5c4113dSnw141292 'desc', 320c5c4113dSnw141292 'asc', 321c5c4113dSnw141292 'explain', 322c5c4113dSnw141292 '14_vac', 323c5c4113dSnw141292 fuzzy_dog_12, 324c5c4113dSnw141292 'begin', 325c5c4113dSnw141292 'end' 326c5c4113dSnw141292)}} 327c5c4113dSnw141292do_test table-8.2 { 328c5c4113dSnw141292 execsql { 329c5c4113dSnw141292 CREATE TABLE 't3''xyz'(a,b,c); 330c5c4113dSnw141292 INSERT INTO [t3'xyz] VALUES(1,2,3); 331c5c4113dSnw141292 SELECT * FROM [t3'xyz]; 332c5c4113dSnw141292 } 333c5c4113dSnw141292} {1 2 3} 334c5c4113dSnw141292do_test table-8.3 { 335c5c4113dSnw141292 execsql2 { 336c5c4113dSnw141292 CREATE TABLE [t4'abc] AS SELECT count(*) as cnt, max(b+c) FROM [t3'xyz]; 337c5c4113dSnw141292 SELECT * FROM [t4'abc]; 338c5c4113dSnw141292 } 339c5c4113dSnw141292} {cnt 1 max(b+c) 5} 340c5c4113dSnw141292do_test table-8.3.1 { 341c5c4113dSnw141292 execsql { 342c5c4113dSnw141292 SELECT sql FROM sqlite_master WHERE name='t4''abc' 343c5c4113dSnw141292 } 344c5c4113dSnw141292} {{CREATE TABLE 't4''abc'(cnt,'max(b+c)')}} 345c5c4113dSnw141292do_test table-8.4 { 346c5c4113dSnw141292 execsql2 { 347c5c4113dSnw141292 CREATE TEMPORARY TABLE t5 AS SELECT count(*) AS [y'all] FROM [t3'xyz]; 348c5c4113dSnw141292 SELECT * FROM t5; 349c5c4113dSnw141292 } 350c5c4113dSnw141292} {y'all 1} 351c5c4113dSnw141292do_test table-8.5 { 352c5c4113dSnw141292 db close 353c5c4113dSnw141292 sqlite db test.db 354c5c4113dSnw141292 execsql2 { 355c5c4113dSnw141292 SELECT * FROM [t4'abc]; 356c5c4113dSnw141292 } 357c5c4113dSnw141292} {cnt 1 max(b+c) 5} 358c5c4113dSnw141292do_test table-8.6 { 359c5c4113dSnw141292 execsql2 { 360c5c4113dSnw141292 SELECT * FROM t2; 361c5c4113dSnw141292 } 362c5c4113dSnw141292} {desc a asc b explain 9 14_vac 0 fuzzy_dog_12 xyz begin hi end y'all} 363c5c4113dSnw141292do_test table-8.7 { 364c5c4113dSnw141292 catchsql { 365c5c4113dSnw141292 SELECT * FROM t5; 366c5c4113dSnw141292 } 367c5c4113dSnw141292} {1 {no such table: t5}} 368c5c4113dSnw141292do_test table-8.8 { 369c5c4113dSnw141292 catchsql { 370c5c4113dSnw141292 CREATE TABLE t5 AS SELECT * FROM no_such_table; 371c5c4113dSnw141292 } 372c5c4113dSnw141292} {1 {no such table: no_such_table}} 373c5c4113dSnw141292 374c5c4113dSnw141292# Make sure we cannot have duplicate column names within a table. 375c5c4113dSnw141292# 376c5c4113dSnw141292do_test table-9.1 { 377c5c4113dSnw141292 catchsql { 378c5c4113dSnw141292 CREATE TABLE t6(a,b,a); 379c5c4113dSnw141292 } 380c5c4113dSnw141292} {1 {duplicate column name: a}} 381c5c4113dSnw141292 382c5c4113dSnw141292# Check the foreign key syntax. 383c5c4113dSnw141292# 384c5c4113dSnw141292do_test table-10.1 { 385c5c4113dSnw141292 catchsql { 386c5c4113dSnw141292 CREATE TABLE t6(a REFERENCES t4(a) NOT NULL); 387c5c4113dSnw141292 INSERT INTO t6 VALUES(NULL); 388c5c4113dSnw141292 } 389c5c4113dSnw141292} {1 {t6.a may not be NULL}} 390c5c4113dSnw141292do_test table-10.2 { 391c5c4113dSnw141292 catchsql { 392c5c4113dSnw141292 DROP TABLE t6; 393c5c4113dSnw141292 CREATE TABLE t6(a REFERENCES t4(a) MATCH PARTIAL); 394c5c4113dSnw141292 } 395c5c4113dSnw141292} {0 {}} 396c5c4113dSnw141292do_test table-10.3 { 397c5c4113dSnw141292 catchsql { 398c5c4113dSnw141292 DROP TABLE t6; 399c5c4113dSnw141292 CREATE TABLE t6(a REFERENCES t4 MATCH FULL ON DELETE SET NULL NOT NULL); 400c5c4113dSnw141292 } 401c5c4113dSnw141292} {0 {}} 402c5c4113dSnw141292do_test table-10.4 { 403c5c4113dSnw141292 catchsql { 404c5c4113dSnw141292 DROP TABLE t6; 405c5c4113dSnw141292 CREATE TABLE t6(a REFERENCES t4 MATCH FULL ON UPDATE SET DEFAULT DEFAULT 1); 406c5c4113dSnw141292 } 407c5c4113dSnw141292} {0 {}} 408c5c4113dSnw141292do_test table-10.5 { 409c5c4113dSnw141292 catchsql { 410c5c4113dSnw141292 DROP TABLE t6; 411c5c4113dSnw141292 CREATE TABLE t6(a NOT NULL NOT DEFERRABLE INITIALLY IMMEDIATE); 412c5c4113dSnw141292 } 413c5c4113dSnw141292} {0 {}} 414c5c4113dSnw141292do_test table-10.6 { 415c5c4113dSnw141292 catchsql { 416c5c4113dSnw141292 DROP TABLE t6; 417c5c4113dSnw141292 CREATE TABLE t6(a NOT NULL DEFERRABLE INITIALLY DEFERRED); 418c5c4113dSnw141292 } 419c5c4113dSnw141292} {0 {}} 420c5c4113dSnw141292do_test table-10.7 { 421c5c4113dSnw141292 catchsql { 422c5c4113dSnw141292 DROP TABLE t6; 423c5c4113dSnw141292 CREATE TABLE t6(a, 424c5c4113dSnw141292 FOREIGN KEY (a) REFERENCES t4(b) DEFERRABLE INITIALLY DEFERRED 425c5c4113dSnw141292 ); 426c5c4113dSnw141292 } 427c5c4113dSnw141292} {0 {}} 428c5c4113dSnw141292do_test table-10.8 { 429c5c4113dSnw141292 catchsql { 430c5c4113dSnw141292 DROP TABLE t6; 431c5c4113dSnw141292 CREATE TABLE t6(a,b,c, 432c5c4113dSnw141292 FOREIGN KEY (b,c) REFERENCES t4(x,y) MATCH PARTIAL 433c5c4113dSnw141292 ON UPDATE SET NULL ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED 434c5c4113dSnw141292 ); 435c5c4113dSnw141292 } 436c5c4113dSnw141292} {0 {}} 437c5c4113dSnw141292do_test table-10.9 { 438c5c4113dSnw141292 catchsql { 439c5c4113dSnw141292 DROP TABLE t6; 440c5c4113dSnw141292 CREATE TABLE t6(a,b,c, 441c5c4113dSnw141292 FOREIGN KEY (b,c) REFERENCES t4(x) 442c5c4113dSnw141292 ); 443c5c4113dSnw141292 } 444c5c4113dSnw141292} {1 {number of columns in foreign key does not match the number of columns in the referenced table}} 445c5c4113dSnw141292do_test table-10.10 { 446c5c4113dSnw141292 catchsql {DROP TABLE t6} 447c5c4113dSnw141292 catchsql { 448c5c4113dSnw141292 CREATE TABLE t6(a,b,c, 449c5c4113dSnw141292 FOREIGN KEY (b,c) REFERENCES t4(x,y,z) 450c5c4113dSnw141292 ); 451c5c4113dSnw141292 } 452c5c4113dSnw141292} {1 {number of columns in foreign key does not match the number of columns in the referenced table}} 453c5c4113dSnw141292do_test table-10.11 { 454c5c4113dSnw141292 catchsql {DROP TABLE t6} 455c5c4113dSnw141292 catchsql { 456c5c4113dSnw141292 CREATE TABLE t6(a,b, c REFERENCES t4(x,y)); 457c5c4113dSnw141292 } 458c5c4113dSnw141292} {1 {foreign key on c should reference only one column of table t4}} 459c5c4113dSnw141292do_test table-10.12 { 460c5c4113dSnw141292 catchsql {DROP TABLE t6} 461c5c4113dSnw141292 catchsql { 462c5c4113dSnw141292 CREATE TABLE t6(a,b,c, 463c5c4113dSnw141292 FOREIGN KEY (b,x) REFERENCES t4(x,y) 464c5c4113dSnw141292 ); 465c5c4113dSnw141292 } 466c5c4113dSnw141292} {1 {unknown column "x" in foreign key definition}} 467c5c4113dSnw141292do_test table-10.13 { 468c5c4113dSnw141292 catchsql {DROP TABLE t6} 469c5c4113dSnw141292 catchsql { 470c5c4113dSnw141292 CREATE TABLE t6(a,b,c, 471c5c4113dSnw141292 FOREIGN KEY (x,b) REFERENCES t4(x,y) 472c5c4113dSnw141292 ); 473c5c4113dSnw141292 } 474c5c4113dSnw141292} {1 {unknown column "x" in foreign key definition}} 475c5c4113dSnw141292 476c5c4113dSnw141292 477c5c4113dSnw141292# Test for the "typeof" function. 478c5c4113dSnw141292# 479c5c4113dSnw141292do_test table-11.1 { 480c5c4113dSnw141292 execsql { 481c5c4113dSnw141292 CREATE TABLE t7( 482c5c4113dSnw141292 a integer primary key, 483c5c4113dSnw141292 b number(5,10), 484c5c4113dSnw141292 c character varying (8), 485c5c4113dSnw141292 d VARCHAR(9), 486c5c4113dSnw141292 e clob, 487c5c4113dSnw141292 f BLOB, 488c5c4113dSnw141292 g Text, 489c5c4113dSnw141292 h 490c5c4113dSnw141292 ); 491c5c4113dSnw141292 INSERT INTO t7(a) VALUES(1); 492c5c4113dSnw141292 SELECT typeof(a), typeof(b), typeof(c), typeof(d), 493c5c4113dSnw141292 typeof(e), typeof(f), typeof(g), typeof(h) 494c5c4113dSnw141292 FROM t7 LIMIT 1; 495c5c4113dSnw141292 } 496c5c4113dSnw141292} {numeric numeric text text text text text numeric} 497c5c4113dSnw141292do_test table-11.2 { 498c5c4113dSnw141292 execsql { 499c5c4113dSnw141292 SELECT typeof(a+b), typeof(a||b), typeof(c+d), typeof(c||d) 500c5c4113dSnw141292 FROM t7 LIMIT 1; 501c5c4113dSnw141292 } 502c5c4113dSnw141292} {numeric text numeric text} 503c5c4113dSnw141292 504c5c4113dSnw141292finish_test 505