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