1*4520Snw141292 2*4520Snw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*4520Snw141292 4*4520Snw141292# 2003 April 4 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 script is testing the ATTACH and DETACH commands 16*4520Snw141292# and related functionality. 17*4520Snw141292# 18*4520Snw141292# $Id: attach.test,v 1.13 2004/02/14 01:39:50 drh Exp $ 19*4520Snw141292# 20*4520Snw141292 21*4520Snw141292set testdir [file dirname $argv0] 22*4520Snw141292source $testdir/tester.tcl 23*4520Snw141292 24*4520Snw141292for {set i 2} {$i<=15} {incr i} { 25*4520Snw141292 file delete -force test$i.db 26*4520Snw141292 file delete -force test$i.db-journal 27*4520Snw141292} 28*4520Snw141292 29*4520Snw141292do_test attach-1.1 { 30*4520Snw141292 execsql { 31*4520Snw141292 CREATE TABLE t1(a,b); 32*4520Snw141292 INSERT INTO t1 VALUES(1,2); 33*4520Snw141292 INSERT INTO t1 VALUES(3,4); 34*4520Snw141292 SELECT * FROM t1; 35*4520Snw141292 } 36*4520Snw141292} {1 2 3 4} 37*4520Snw141292do_test attach-1.2 { 38*4520Snw141292 sqlite db2 test2.db 39*4520Snw141292 execsql { 40*4520Snw141292 CREATE TABLE t2(x,y); 41*4520Snw141292 INSERT INTO t2 VALUES(1,'x'); 42*4520Snw141292 INSERT INTO t2 VALUES(2,'y'); 43*4520Snw141292 SELECT * FROM t2; 44*4520Snw141292 } db2 45*4520Snw141292} {1 x 2 y} 46*4520Snw141292do_test attach-1.3 { 47*4520Snw141292 execsql { 48*4520Snw141292 ATTACH DATABASE 'test2.db' AS two; 49*4520Snw141292 SELECT * FROM two.t2; 50*4520Snw141292 } 51*4520Snw141292} {1 x 2 y} 52*4520Snw141292do_test attach-1.4 { 53*4520Snw141292 execsql { 54*4520Snw141292 SELECT * FROM t2; 55*4520Snw141292 } 56*4520Snw141292} {1 x 2 y} 57*4520Snw141292do_test attach-1.5 { 58*4520Snw141292 execsql { 59*4520Snw141292 DETACH DATABASE two; 60*4520Snw141292 SELECT * FROM t1; 61*4520Snw141292 } 62*4520Snw141292} {1 2 3 4} 63*4520Snw141292do_test attach-1.6 { 64*4520Snw141292 catchsql { 65*4520Snw141292 SELECT * FROM t2; 66*4520Snw141292 } 67*4520Snw141292} {1 {no such table: t2}} 68*4520Snw141292do_test attach-1.7 { 69*4520Snw141292 catchsql { 70*4520Snw141292 SELECT * FROM two.t2; 71*4520Snw141292 } 72*4520Snw141292} {1 {no such table: two.t2}} 73*4520Snw141292do_test attach-1.8 { 74*4520Snw141292 catchsql { 75*4520Snw141292 ATTACH DATABASE 'test3.db' AS three; 76*4520Snw141292 } 77*4520Snw141292} {1 {cannot attach empty database: three}} 78*4520Snw141292do_test attach-1.9 { 79*4520Snw141292 catchsql { 80*4520Snw141292 SELECT * FROM three.sqlite_master; 81*4520Snw141292 } 82*4520Snw141292} {1 {no such table: three.sqlite_master}} 83*4520Snw141292do_test attach-1.10 { 84*4520Snw141292 catchsql { 85*4520Snw141292 DETACH DATABASE three; 86*4520Snw141292 } 87*4520Snw141292} {1 {no such database: three}} 88*4520Snw141292do_test attach-1.11 { 89*4520Snw141292 execsql { 90*4520Snw141292 ATTACH 'test.db' AS db2; 91*4520Snw141292 ATTACH 'test.db' AS db3; 92*4520Snw141292 ATTACH 'test.db' AS db4; 93*4520Snw141292 ATTACH 'test.db' AS db5; 94*4520Snw141292 ATTACH 'test.db' AS db6; 95*4520Snw141292 ATTACH 'test.db' AS db7; 96*4520Snw141292 ATTACH 'test.db' AS db8; 97*4520Snw141292 ATTACH 'test.db' AS db9; 98*4520Snw141292 } 99*4520Snw141292} {} 100*4520Snw141292proc db_list {db} { 101*4520Snw141292 set list {} 102*4520Snw141292 foreach {idx name file} [execsql {PRAGMA database_list} $db] { 103*4520Snw141292 lappend list $idx $name 104*4520Snw141292 } 105*4520Snw141292 return $list 106*4520Snw141292} 107*4520Snw141292do_test attach-1.11b { 108*4520Snw141292 db_list db 109*4520Snw141292} {0 main 1 temp 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9} 110*4520Snw141292do_test attach-1.12 { 111*4520Snw141292 catchsql { 112*4520Snw141292 ATTACH 'test.db' as db2; 113*4520Snw141292 } 114*4520Snw141292} {1 {database db2 is already in use}} 115*4520Snw141292do_test attach-1.13 { 116*4520Snw141292 catchsql { 117*4520Snw141292 ATTACH 'test.db' as db5; 118*4520Snw141292 } 119*4520Snw141292} {1 {database db5 is already in use}} 120*4520Snw141292do_test attach-1.14 { 121*4520Snw141292 catchsql { 122*4520Snw141292 ATTACH 'test.db' as db9; 123*4520Snw141292 } 124*4520Snw141292} {1 {database db9 is already in use}} 125*4520Snw141292do_test attach-1.15 { 126*4520Snw141292 catchsql { 127*4520Snw141292 ATTACH 'test.db' as main; 128*4520Snw141292 } 129*4520Snw141292} {1 {database main is already in use}} 130*4520Snw141292do_test attach-1.16 { 131*4520Snw141292 catchsql { 132*4520Snw141292 ATTACH 'test.db' as temp; 133*4520Snw141292 } 134*4520Snw141292} {1 {database temp is already in use}} 135*4520Snw141292do_test attach-1.17 { 136*4520Snw141292 catchsql { 137*4520Snw141292 ATTACH 'test.db' as MAIN; 138*4520Snw141292 } 139*4520Snw141292} {1 {database MAIN is already in use}} 140*4520Snw141292do_test attach-1.18 { 141*4520Snw141292 catchsql { 142*4520Snw141292 ATTACH 'test.db' as db10; 143*4520Snw141292 ATTACH 'test.db' as db11; 144*4520Snw141292 } 145*4520Snw141292} {0 {}} 146*4520Snw141292do_test attach-1.19 { 147*4520Snw141292 catchsql { 148*4520Snw141292 ATTACH 'test.db' as db12; 149*4520Snw141292 } 150*4520Snw141292} {1 {too many attached databases - max 10}} 151*4520Snw141292do_test attach-1.20.1 { 152*4520Snw141292 execsql { 153*4520Snw141292 DETACH db5; 154*4520Snw141292 } 155*4520Snw141292 db_list db 156*4520Snw141292} {0 main 1 temp 2 db2 3 db3 4 db4 5 db11 6 db6 7 db7 8 db8 9 db9 10 db10} 157*4520Snw141292integrity_check attach-1.20.2 158*4520Snw141292do_test attach-1.21 { 159*4520Snw141292 catchsql { 160*4520Snw141292 ATTACH 'test.db' as db12; 161*4520Snw141292 } 162*4520Snw141292} {0 {}} 163*4520Snw141292do_test attach-1.22 { 164*4520Snw141292 catchsql { 165*4520Snw141292 ATTACH 'test.db' as db13; 166*4520Snw141292 } 167*4520Snw141292} {1 {too many attached databases - max 10}} 168*4520Snw141292do_test attach-1.23 { 169*4520Snw141292 catchsql { 170*4520Snw141292 DETACH db14; 171*4520Snw141292 } 172*4520Snw141292} {1 {no such database: db14}} 173*4520Snw141292do_test attach-1.24 { 174*4520Snw141292 catchsql { 175*4520Snw141292 DETACH db12; 176*4520Snw141292 } 177*4520Snw141292} {0 {}} 178*4520Snw141292do_test attach-1.25 { 179*4520Snw141292 catchsql { 180*4520Snw141292 DETACH db12; 181*4520Snw141292 } 182*4520Snw141292} {1 {no such database: db12}} 183*4520Snw141292do_test attach-1.26 { 184*4520Snw141292 catchsql { 185*4520Snw141292 DETACH main; 186*4520Snw141292 } 187*4520Snw141292} {1 {cannot detach database main}} 188*4520Snw141292do_test attach-1.27 { 189*4520Snw141292 catchsql { 190*4520Snw141292 DETACH Temp; 191*4520Snw141292 } 192*4520Snw141292} {1 {cannot detach database Temp}} 193*4520Snw141292do_test attach-1.28 { 194*4520Snw141292 catchsql { 195*4520Snw141292 DETACH db11; 196*4520Snw141292 DETACH db10; 197*4520Snw141292 DETACH db9; 198*4520Snw141292 DETACH db8; 199*4520Snw141292 DETACH db7; 200*4520Snw141292 DETACH db6; 201*4520Snw141292 DETACH db4; 202*4520Snw141292 DETACH db3; 203*4520Snw141292 DETACH db2; 204*4520Snw141292 } 205*4520Snw141292} {0 {}} 206*4520Snw141292do_test attach-1.29 { 207*4520Snw141292 db_list db 208*4520Snw141292} {0 main 1 temp} 209*4520Snw141292 210*4520Snw141292do_test attach-2.1 { 211*4520Snw141292 execsql { 212*4520Snw141292 CREATE TABLE tx(x1,x2,y1,y2); 213*4520Snw141292 CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN 214*4520Snw141292 INSERT INTO tx(x1,x2,y1,y2) VALUES(OLD.x,NEW.x,OLD.y,NEW.y); 215*4520Snw141292 END; 216*4520Snw141292 SELECT * FROM tx; 217*4520Snw141292 } db2; 218*4520Snw141292} {} 219*4520Snw141292do_test attach-2.2 { 220*4520Snw141292 execsql { 221*4520Snw141292 UPDATE t2 SET x=x+10; 222*4520Snw141292 SELECT * FROM tx; 223*4520Snw141292 } db2; 224*4520Snw141292} {1 11 x x 2 12 y y} 225*4520Snw141292do_test attach-2.3 { 226*4520Snw141292 execsql { 227*4520Snw141292 CREATE TABLE tx(x1,x2,y1,y2); 228*4520Snw141292 SELECT * FROM tx; 229*4520Snw141292 } 230*4520Snw141292} {} 231*4520Snw141292do_test attach-2.4 { 232*4520Snw141292 execsql { 233*4520Snw141292 ATTACH 'test2.db' AS db2; 234*4520Snw141292 } 235*4520Snw141292} {} 236*4520Snw141292do_test attach-2.5 { 237*4520Snw141292 execsql { 238*4520Snw141292 UPDATE db2.t2 SET x=x+10; 239*4520Snw141292 SELECT * FROM db2.tx; 240*4520Snw141292 } 241*4520Snw141292} {1 11 x x 2 12 y y 11 21 x x 12 22 y y} 242*4520Snw141292do_test attach-2.6 { 243*4520Snw141292 execsql { 244*4520Snw141292 SELECT * FROM main.tx; 245*4520Snw141292 } 246*4520Snw141292} {} 247*4520Snw141292do_test attach-2.7 { 248*4520Snw141292 execsql { 249*4520Snw141292 SELECT type, name, tbl_name FROM db2.sqlite_master; 250*4520Snw141292 } 251*4520Snw141292} {table t2 t2 table tx tx trigger r1 t2} 252*4520Snw141292do_test attach-2.8 { 253*4520Snw141292 db_list db 254*4520Snw141292} {0 main 1 temp 2 db2} 255*4520Snw141292do_test attach-2.9 { 256*4520Snw141292 execsql { 257*4520Snw141292 CREATE INDEX i2 ON t2(x); 258*4520Snw141292 SELECT * FROM t2 WHERE x>5; 259*4520Snw141292 } db2 260*4520Snw141292} {21 x 22 y} 261*4520Snw141292do_test attach-2.10 { 262*4520Snw141292 execsql { 263*4520Snw141292 SELECT type, name, tbl_name FROM sqlite_master; 264*4520Snw141292 } db2 265*4520Snw141292} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} 266*4520Snw141292#do_test attach-2.11 { 267*4520Snw141292# catchsql { 268*4520Snw141292# SELECT * FROM t2 WHERE x>5; 269*4520Snw141292# } 270*4520Snw141292#} {1 {database schema has changed}} 271*4520Snw141292do_test attach-2.12 { 272*4520Snw141292 db_list db 273*4520Snw141292} {0 main 1 temp 2 db2} 274*4520Snw141292do_test attach-2.13 { 275*4520Snw141292 catchsql { 276*4520Snw141292 SELECT * FROM t2 WHERE x>5; 277*4520Snw141292 } 278*4520Snw141292} {0 {21 x 22 y}} 279*4520Snw141292do_test attach-2.14 { 280*4520Snw141292 execsql { 281*4520Snw141292 SELECT type, name, tbl_name FROM sqlite_master; 282*4520Snw141292 } 283*4520Snw141292} {table t1 t1 table tx tx} 284*4520Snw141292do_test attach-2.15 { 285*4520Snw141292 execsql { 286*4520Snw141292 SELECT type, name, tbl_name FROM db2.sqlite_master; 287*4520Snw141292 } 288*4520Snw141292} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} 289*4520Snw141292do_test attach-2.16 { 290*4520Snw141292 db close 291*4520Snw141292 sqlite db test.db 292*4520Snw141292 execsql { 293*4520Snw141292 ATTACH 'test2.db' AS db2; 294*4520Snw141292 SELECT type, name, tbl_name FROM db2.sqlite_master; 295*4520Snw141292 } 296*4520Snw141292} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} 297*4520Snw141292 298*4520Snw141292do_test attach-3.1 { 299*4520Snw141292 db close 300*4520Snw141292 db2 close 301*4520Snw141292 sqlite db test.db 302*4520Snw141292 sqlite db2 test2.db 303*4520Snw141292 execsql { 304*4520Snw141292 SELECT * FROM t1 305*4520Snw141292 } 306*4520Snw141292} {1 2 3 4} 307*4520Snw141292do_test attach-3.2 { 308*4520Snw141292 catchsql { 309*4520Snw141292 SELECT * FROM t2 310*4520Snw141292 } 311*4520Snw141292} {1 {no such table: t2}} 312*4520Snw141292do_test attach-3.3 { 313*4520Snw141292 catchsql { 314*4520Snw141292 ATTACH DATABASE 'test2.db' AS db2; 315*4520Snw141292 SELECT * FROM t2 316*4520Snw141292 } 317*4520Snw141292} {0 {21 x 22 y}} 318*4520Snw141292 319*4520Snw141292# Even though main has a transaction, test2.db should not be locked. 320*4520Snw141292do_test attach-3.4 { 321*4520Snw141292 execsql BEGIN 322*4520Snw141292 catchsql { 323*4520Snw141292 SELECT * FROM t2; 324*4520Snw141292 } db2; 325*4520Snw141292} {0 {21 x 22 y}} 326*4520Snw141292 327*4520Snw141292# Reading from db2 should not lock test2.db 328*4520Snw141292do_test attach-3.5 { 329*4520Snw141292 execsql {SELECT * FROM t2} 330*4520Snw141292 catchsql { 331*4520Snw141292 SELECT * FROM t2; 332*4520Snw141292 } db2; 333*4520Snw141292} {0 {21 x 22 y}} 334*4520Snw141292 335*4520Snw141292# Making a change to db2 causes test2.ddb to become locked. 336*4520Snw141292do_test attach-3.6 { 337*4520Snw141292 execsql { 338*4520Snw141292 UPDATE t2 SET x=x+1 WHERE x=50; 339*4520Snw141292 } 340*4520Snw141292 catchsql { 341*4520Snw141292 SELECT * FROM t2; 342*4520Snw141292 } db2; 343*4520Snw141292} {1 {database is locked}} 344*4520Snw141292 345*4520Snw141292do_test attach-3.7 { 346*4520Snw141292 execsql ROLLBACK 347*4520Snw141292 execsql {SELECT * FROM t2} db2 348*4520Snw141292} {21 x 22 y} 349*4520Snw141292do_test attach-3.8 { 350*4520Snw141292 execsql BEGIN 351*4520Snw141292 execsql BEGIN db2 352*4520Snw141292 catchsql {SELECT * FROM t2} 353*4520Snw141292} {1 {database is locked}} 354*4520Snw141292do_test attach-3.9 { 355*4520Snw141292 catchsql {SELECT * FROM t2} db2 356*4520Snw141292} {0 {21 x 22 y}} 357*4520Snw141292do_test attach-3.10 { 358*4520Snw141292 execsql {SELECT * FROM t1} 359*4520Snw141292} {1 2 3 4} 360*4520Snw141292do_test attach-3.11 { 361*4520Snw141292 catchsql {UPDATE t1 SET a=a+1} 362*4520Snw141292} {0 {}} 363*4520Snw141292do_test attach-3.12 { 364*4520Snw141292 execsql {SELECT * FROM t1} 365*4520Snw141292} {2 2 4 4} 366*4520Snw141292do_test attach-3.13 { 367*4520Snw141292 catchsql {UPDATE t2 SET x=x+1 WHERE x=50} 368*4520Snw141292} {1 {database is locked}} 369*4520Snw141292do_test attach-3.14 { 370*4520Snw141292 # Unable to reinitialize the schema tables because the aux database 371*4520Snw141292 # is still locked. 372*4520Snw141292 catchsql {SELECT * FROM t1} 373*4520Snw141292} {1 {database is locked}} 374*4520Snw141292do_test attach-3.15 { 375*4520Snw141292 execsql COMMIT db2 376*4520Snw141292 execsql {SELECT * FROM t1} 377*4520Snw141292} {1 2 3 4} 378*4520Snw141292 379*4520Snw141292# Ticket #323 380*4520Snw141292do_test attach-4.1 { 381*4520Snw141292 execsql {DETACH db2} 382*4520Snw141292 db2 close 383*4520Snw141292 sqlite db2 test2.db 384*4520Snw141292 execsql { 385*4520Snw141292 CREATE TABLE t3(x,y); 386*4520Snw141292 CREATE UNIQUE INDEX t3i1 ON t3(x); 387*4520Snw141292 INSERT INTO t3 VALUES(1,2); 388*4520Snw141292 SELECT * FROM t3; 389*4520Snw141292 } db2; 390*4520Snw141292} {1 2} 391*4520Snw141292do_test attach-4.2 { 392*4520Snw141292 execsql { 393*4520Snw141292 CREATE TABLE t3(a,b); 394*4520Snw141292 CREATE UNIQUE INDEX t3i1b ON t3(a); 395*4520Snw141292 INSERT INTO t3 VALUES(9,10); 396*4520Snw141292 SELECT * FROM t3; 397*4520Snw141292 } 398*4520Snw141292} {9 10} 399*4520Snw141292do_test attach-4.3 { 400*4520Snw141292 execsql { 401*4520Snw141292 ATTACH DATABASE 'test2.db' AS db2; 402*4520Snw141292 SELECT * FROM db2.t3; 403*4520Snw141292 } 404*4520Snw141292} {1 2} 405*4520Snw141292do_test attach-4.4 { 406*4520Snw141292 execsql { 407*4520Snw141292 SELECT * FROM main.t3; 408*4520Snw141292 } 409*4520Snw141292} {9 10} 410*4520Snw141292do_test attach-4.5 { 411*4520Snw141292 execsql { 412*4520Snw141292 INSERT INTO db2.t3 VALUES(9,10); 413*4520Snw141292 SELECT * FROM db2.t3; 414*4520Snw141292 } 415*4520Snw141292} {1 2 9 10} 416*4520Snw141292do_test attach-4.6 { 417*4520Snw141292 execsql { 418*4520Snw141292 DETACH db2; 419*4520Snw141292 } 420*4520Snw141292 execsql { 421*4520Snw141292 CREATE TABLE t4(x); 422*4520Snw141292 CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN 423*4520Snw141292 INSERT INTO t4 VALUES('db2.' || NEW.x); 424*4520Snw141292 END; 425*4520Snw141292 INSERT INTO t3 VALUES(6,7); 426*4520Snw141292 SELECT * FROM t4; 427*4520Snw141292 } db2 428*4520Snw141292} {db2.6} 429*4520Snw141292do_test attach-4.7 { 430*4520Snw141292 execsql { 431*4520Snw141292 CREATE TABLE t4(y); 432*4520Snw141292 CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN 433*4520Snw141292 INSERT INTO t4 VALUES('main.' || NEW.a); 434*4520Snw141292 END; 435*4520Snw141292 INSERT INTO main.t3 VALUES(11,12); 436*4520Snw141292 SELECT * FROM main.t4; 437*4520Snw141292 } 438*4520Snw141292} {main.11} 439*4520Snw141292do_test attach-4.8 { 440*4520Snw141292 execsql { 441*4520Snw141292 ATTACH DATABASE 'test2.db' AS db2; 442*4520Snw141292 INSERT INTO db2.t3 VALUES(13,14); 443*4520Snw141292 SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4; 444*4520Snw141292 } 445*4520Snw141292} {db2.6 db2.13 main.11} 446*4520Snw141292do_test attach-4.9 { 447*4520Snw141292 execsql { 448*4520Snw141292 INSERT INTO main.t3 VALUES(15,16); 449*4520Snw141292 SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4; 450*4520Snw141292 } 451*4520Snw141292} {db2.6 db2.13 main.11 main.15} 452*4520Snw141292do_test attach-4.10 { 453*4520Snw141292 execsql { 454*4520Snw141292 DETACH DATABASE db2; 455*4520Snw141292 } 456*4520Snw141292 execsql { 457*4520Snw141292 CREATE VIEW v3 AS SELECT x*100+y FROM t3; 458*4520Snw141292 SELECT * FROM v3; 459*4520Snw141292 } db2 460*4520Snw141292} {102 910 607 1314} 461*4520Snw141292do_test attach-4.11 { 462*4520Snw141292 execsql { 463*4520Snw141292 CREATE VIEW v3 AS SELECT a*100+b FROM t3; 464*4520Snw141292 SELECT * FROM v3; 465*4520Snw141292 } 466*4520Snw141292} {910 1112 1516} 467*4520Snw141292do_test attach-4.12 { 468*4520Snw141292 execsql { 469*4520Snw141292 ATTACH DATABASE 'test2.db' AS db2; 470*4520Snw141292 SELECT * FROM db2.v3; 471*4520Snw141292 } 472*4520Snw141292} {102 910 607 1314} 473*4520Snw141292do_test attach-4.13 { 474*4520Snw141292 execsql { 475*4520Snw141292 SELECT * FROM main.v3; 476*4520Snw141292 } 477*4520Snw141292} {910 1112 1516} 478*4520Snw141292 479*4520Snw141292# Tests for the sqliteFix...() routines in attach.c 480*4520Snw141292# 481*4520Snw141292do_test attach-5.1 { 482*4520Snw141292 db close 483*4520Snw141292 sqlite db test.db 484*4520Snw141292 db2 close 485*4520Snw141292 file delete -force test2.db 486*4520Snw141292 sqlite db2 test2.db 487*4520Snw141292 catchsql { 488*4520Snw141292 ATTACH DATABASE 'test.db' AS orig; 489*4520Snw141292 CREATE TRIGGER r1 AFTER INSERT ON orig.t1 BEGIN; 490*4520Snw141292 SELECT 'no-op'; 491*4520Snw141292 END; 492*4520Snw141292 } db2 493*4520Snw141292} {1 {triggers may not be added to auxiliary database orig}} 494*4520Snw141292do_test attach-5.2 { 495*4520Snw141292 catchsql { 496*4520Snw141292 CREATE TABLE t5(x,y); 497*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 498*4520Snw141292 SELECT 'no-op'; 499*4520Snw141292 END; 500*4520Snw141292 } db2 501*4520Snw141292} {0 {}} 502*4520Snw141292do_test attach-5.3 { 503*4520Snw141292 catchsql { 504*4520Snw141292 DROP TRIGGER r5; 505*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 506*4520Snw141292 SELECT 'no-op' FROM orig.t1; 507*4520Snw141292 END; 508*4520Snw141292 } db2 509*4520Snw141292} {1 {trigger r5 cannot reference objects in database orig}} 510*4520Snw141292do_test attach-5.4 { 511*4520Snw141292 catchsql { 512*4520Snw141292 CREATE TEMP TABLE t6(p,q,r); 513*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 514*4520Snw141292 SELECT 'no-op' FROM temp.t6; 515*4520Snw141292 END; 516*4520Snw141292 } db2 517*4520Snw141292} {1 {trigger r5 cannot reference objects in database temp}} 518*4520Snw141292do_test attach-5.5 { 519*4520Snw141292 catchsql { 520*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 521*4520Snw141292 SELECT 'no-op' || (SELECT * FROM temp.t6); 522*4520Snw141292 END; 523*4520Snw141292 } db2 524*4520Snw141292} {1 {trigger r5 cannot reference objects in database temp}} 525*4520Snw141292do_test attach-5.6 { 526*4520Snw141292 catchsql { 527*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 528*4520Snw141292 SELECT 'no-op' FROM t1 WHERE x<(SELECT min(x) FROM temp.t6); 529*4520Snw141292 END; 530*4520Snw141292 } db2 531*4520Snw141292} {1 {trigger r5 cannot reference objects in database temp}} 532*4520Snw141292do_test attach-5.7 { 533*4520Snw141292 catchsql { 534*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 535*4520Snw141292 SELECT 'no-op' FROM t1 GROUP BY 1 HAVING x<(SELECT min(x) FROM temp.t6); 536*4520Snw141292 END; 537*4520Snw141292 } db2 538*4520Snw141292} {1 {trigger r5 cannot reference objects in database temp}} 539*4520Snw141292do_test attach-5.7 { 540*4520Snw141292 catchsql { 541*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 542*4520Snw141292 SELECT max(1,x,(SELECT min(x) FROM temp.t6)) FROM t1; 543*4520Snw141292 END; 544*4520Snw141292 } db2 545*4520Snw141292} {1 {trigger r5 cannot reference objects in database temp}} 546*4520Snw141292do_test attach-5.8 { 547*4520Snw141292 catchsql { 548*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 549*4520Snw141292 INSERT INTO t1 VALUES((SELECT min(x) FROM temp.t6),5); 550*4520Snw141292 END; 551*4520Snw141292 } db2 552*4520Snw141292} {1 {trigger r5 cannot reference objects in database temp}} 553*4520Snw141292do_test attach-5.9 { 554*4520Snw141292 catchsql { 555*4520Snw141292 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 556*4520Snw141292 DELETE FROM t1 WHERE x<(SELECT min(x) FROM temp.t6); 557*4520Snw141292 END; 558*4520Snw141292 } db2 559*4520Snw141292} {1 {trigger r5 cannot reference objects in database temp}} 560*4520Snw141292 561*4520Snw141292# Check to make sure we get a sensible error if unable to open 562*4520Snw141292# the file that we are trying to attach. 563*4520Snw141292# 564*4520Snw141292do_test attach-6.1 { 565*4520Snw141292 catchsql { 566*4520Snw141292 ATTACH DATABASE 'no-such-file' AS nosuch; 567*4520Snw141292 } 568*4520Snw141292} {1 {cannot attach empty database: nosuch}} 569*4520Snw141292file delete -force no-such-file 570*4520Snw141292if {$tcl_platform(platform)=="unix"} { 571*4520Snw141292 do_test attach-6.2 { 572*4520Snw141292 sqlite dbx cannot-read 573*4520Snw141292 dbx eval {CREATE TABLE t1(a,b,c)} 574*4520Snw141292 dbx close 575*4520Snw141292 file attributes cannot-read -permission 0000 576*4520Snw141292 catchsql { 577*4520Snw141292 ATTACH DATABASE 'cannot-read' AS noread; 578*4520Snw141292 } 579*4520Snw141292 } {1 {unable to open database: cannot-read}} 580*4520Snw141292 file delete -force cannot-read 581*4520Snw141292} 582*4520Snw141292 583*4520Snw141292for {set i 2} {$i<=15} {incr i} { 584*4520Snw141292 catch {db$i close} 585*4520Snw141292} 586*4520Snw141292file delete -force test2.db 587*4520Snw141292 588*4520Snw141292 589*4520Snw141292finish_test 590