1# 2003 April 4 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#*********************************************************************** 11# This file implements regression tests for SQLite library. The 12# focus of this script is testing the ATTACH and DETACH commands 13# and related functionality. 14# 15# $Id: attach.test,v 1.48 2008/02/06 14:11:35 drh Exp $ 16# 17 18set testdir [file dirname $argv0] 19source $testdir/tester.tcl 20 21ifcapable !attach { 22 finish_test 23 return 24} 25 26for {set i 2} {$i<=15} {incr i} { 27 file delete -force test$i.db 28 file delete -force test$i.db-journal 29} 30 31set btree_trace 0 32do_test attach-1.1 { 33 execsql { 34 CREATE TABLE t1(a,b); 35 INSERT INTO t1 VALUES(1,2); 36 INSERT INTO t1 VALUES(3,4); 37 SELECT * FROM t1; 38 } 39} {1 2 3 4} 40do_test attach-1.2 { 41 sqlite3 db2 test2.db 42 execsql { 43 CREATE TABLE t2(x,y); 44 INSERT INTO t2 VALUES(1,'x'); 45 INSERT INTO t2 VALUES(2,'y'); 46 SELECT * FROM t2; 47 } db2 48} {1 x 2 y} 49do_test attach-1.3 { 50 execsql { 51 ATTACH DATABASE 'test2.db' AS two; 52 SELECT * FROM two.t2; 53 } 54} {1 x 2 y} 55do_test attach-1.4 { 56 execsql { 57 SELECT * FROM t2; 58 } 59} {1 x 2 y} 60do_test attach-1.5 { 61btree_breakpoint 62 execsql { 63 DETACH DATABASE two; 64 SELECT * FROM t1; 65 } 66} {1 2 3 4} 67do_test attach-1.6 { 68 catchsql { 69 SELECT * FROM t2; 70 } 71} {1 {no such table: t2}} 72do_test attach-1.7 { 73 catchsql { 74 SELECT * FROM two.t2; 75 } 76} {1 {no such table: two.t2}} 77do_test attach-1.8 { 78 catchsql { 79 ATTACH DATABASE 'test3.db' AS three; 80 } 81} {0 {}} 82do_test attach-1.9 { 83 catchsql { 84 SELECT * FROM three.sqlite_master; 85 } 86} {0 {}} 87do_test attach-1.10 { 88 catchsql { 89 DETACH DATABASE [three]; 90 } 91} {0 {}} 92do_test attach-1.11 { 93 execsql { 94 ATTACH 'test.db' AS db2; 95 ATTACH 'test.db' AS db3; 96 ATTACH 'test.db' AS db4; 97 ATTACH 'test.db' AS db5; 98 ATTACH 'test.db' AS db6; 99 ATTACH 'test.db' AS db7; 100 ATTACH 'test.db' AS db8; 101 ATTACH 'test.db' AS db9; 102 } 103} {} 104proc db_list {db} { 105 set list {} 106 foreach {idx name file} [execsql {PRAGMA database_list} $db] { 107 lappend list $idx $name 108 } 109 return $list 110} 111ifcapable schema_pragmas { 112do_test attach-1.11b { 113 db_list db 114} {0 main 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9} 115} ;# ifcapable schema_pragmas 116do_test attach-1.12 { 117 catchsql { 118 ATTACH 'test.db' as db2; 119 } 120} {1 {database db2 is already in use}} 121do_test attach-1.12.2 { 122 db errorcode 123} {1} 124do_test attach-1.13 { 125 catchsql { 126 ATTACH 'test.db' as db5; 127 } 128} {1 {database db5 is already in use}} 129do_test attach-1.14 { 130 catchsql { 131 ATTACH 'test.db' as db9; 132 } 133} {1 {database db9 is already in use}} 134do_test attach-1.15 { 135 catchsql { 136 ATTACH 'test.db' as main; 137 } 138} {1 {database main is already in use}} 139ifcapable tempdb { 140 do_test attach-1.16 { 141 catchsql { 142 ATTACH 'test.db' as temp; 143 } 144 } {1 {database temp is already in use}} 145} 146do_test attach-1.17 { 147 catchsql { 148 ATTACH 'test.db' as MAIN; 149 } 150} {1 {database MAIN is already in use}} 151do_test attach-1.18 { 152 catchsql { 153 ATTACH 'test.db' as db10; 154 ATTACH 'test.db' as db11; 155 } 156} {0 {}} 157do_test attach-1.19 { 158 catchsql { 159 ATTACH 'test.db' as db12; 160 } 161} {1 {too many attached databases - max 10}} 162do_test attach-1.19.1 { 163 db errorcode 164} {1} 165do_test attach-1.20.1 { 166 execsql { 167 DETACH db5; 168 } 169} {} 170ifcapable schema_pragmas { 171do_test attach-1.20.2 { 172 db_list db 173} {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11} 174} ;# ifcapable schema_pragmas 175integrity_check attach-1.20.3 176ifcapable tempdb { 177 execsql {select * from sqlite_temp_master} 178} 179do_test attach-1.21 { 180 catchsql { 181 ATTACH 'test.db' as db12; 182 } 183} {0 {}} 184do_test attach-1.22 { 185 catchsql { 186 ATTACH 'test.db' as db13; 187 } 188} {1 {too many attached databases - max 10}} 189do_test attach-1.22.1 { 190 db errorcode 191} {1} 192do_test attach-1.23 { 193 catchsql { 194 DETACH "db14"; 195 } 196} {1 {no such database: db14}} 197do_test attach-1.24 { 198 catchsql { 199 DETACH db12; 200 } 201} {0 {}} 202do_test attach-1.25 { 203 catchsql { 204 DETACH db12; 205 } 206} {1 {no such database: db12}} 207do_test attach-1.26 { 208 catchsql { 209 DETACH main; 210 } 211} {1 {cannot detach database main}} 212 213ifcapable tempdb { 214 do_test attach-1.27 { 215 catchsql { 216 DETACH Temp; 217 } 218 } {1 {cannot detach database Temp}} 219} else { 220 do_test attach-1.27 { 221 catchsql { 222 DETACH Temp; 223 } 224 } {1 {no such database: Temp}} 225} 226 227do_test attach-1.28 { 228 catchsql { 229 DETACH db11; 230 DETACH db10; 231 DETACH db9; 232 DETACH db8; 233 DETACH db7; 234 DETACH db6; 235 DETACH db4; 236 DETACH db3; 237 DETACH db2; 238 } 239} {0 {}} 240ifcapable schema_pragmas { 241 ifcapable tempdb { 242 do_test attach-1.29 { 243 db_list db 244 } {0 main 1 temp} 245 } else { 246 do_test attach-1.29 { 247 db_list db 248 } {0 main} 249 } 250} ;# ifcapable schema_pragmas 251 252ifcapable {trigger} { # Only do the following tests if triggers are enabled 253do_test attach-2.1 { 254 execsql { 255 CREATE TABLE tx(x1,x2,y1,y2); 256 CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN 257 INSERT INTO tx(x1,x2,y1,y2) VALUES(OLD.x,NEW.x,OLD.y,NEW.y); 258 END; 259 SELECT * FROM tx; 260 } db2; 261} {} 262do_test attach-2.2 { 263 execsql { 264 UPDATE t2 SET x=x+10; 265 SELECT * FROM tx; 266 } db2; 267} {1 11 x x 2 12 y y} 268do_test attach-2.3 { 269 execsql { 270 CREATE TABLE tx(x1,x2,y1,y2); 271 SELECT * FROM tx; 272 } 273} {} 274do_test attach-2.4 { 275 execsql { 276 ATTACH 'test2.db' AS db2; 277 } 278} {} 279do_test attach-2.5 { 280 execsql { 281 UPDATE db2.t2 SET x=x+10; 282 SELECT * FROM db2.tx; 283 } 284} {1 11 x x 2 12 y y 11 21 x x 12 22 y y} 285do_test attach-2.6 { 286 execsql { 287 SELECT * FROM main.tx; 288 } 289} {} 290do_test attach-2.7 { 291 execsql { 292 SELECT type, name, tbl_name FROM db2.sqlite_master; 293 } 294} {table t2 t2 table tx tx trigger r1 t2} 295 296ifcapable schema_pragmas&&tempdb { 297 do_test attach-2.8 { 298 db_list db 299 } {0 main 1 temp 2 db2} 300} ;# ifcapable schema_pragmas&&tempdb 301ifcapable schema_pragmas&&!tempdb { 302 do_test attach-2.8 { 303 db_list db 304 } {0 main 2 db2} 305} ;# ifcapable schema_pragmas&&!tempdb 306 307do_test attach-2.9 { 308 execsql { 309 CREATE INDEX i2 ON t2(x); 310 SELECT * FROM t2 WHERE x>5; 311 } db2 312} {21 x 22 y} 313do_test attach-2.10 { 314 execsql { 315 SELECT type, name, tbl_name FROM sqlite_master; 316 } db2 317} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} 318#do_test attach-2.11 { 319# catchsql { 320# SELECT * FROM t2 WHERE x>5; 321# } 322#} {1 {database schema has changed}} 323ifcapable schema_pragmas { 324 ifcapable tempdb { 325 do_test attach-2.12 { 326 db_list db 327 } {0 main 1 temp 2 db2} 328 } else { 329 do_test attach-2.12 { 330 db_list db 331 } {0 main 2 db2} 332 } 333} ;# ifcapable schema_pragmas 334do_test attach-2.13 { 335 catchsql { 336 SELECT * FROM t2 WHERE x>5; 337 } 338} {0 {21 x 22 y}} 339do_test attach-2.14 { 340 execsql { 341 SELECT type, name, tbl_name FROM sqlite_master; 342 } 343} {table t1 t1 table tx tx} 344do_test attach-2.15 { 345 execsql { 346 SELECT type, name, tbl_name FROM db2.sqlite_master; 347 } 348} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} 349do_test attach-2.16 { 350 db close 351 sqlite3 db test.db 352 execsql { 353 ATTACH 'test2.db' AS db2; 354 SELECT type, name, tbl_name FROM db2.sqlite_master; 355 } 356} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} 357} ;# End of ifcapable {trigger} 358 359do_test attach-3.1 { 360 db close 361 db2 close 362 sqlite3 db test.db 363 sqlite3 db2 test2.db 364 execsql { 365 SELECT * FROM t1 366 } 367} {1 2 3 4} 368 369# If we are testing a version of the code that lacks trigger support, 370# adjust the database contents so that they are the same if triggers 371# had been enabled. 372ifcapable {!trigger} { 373 db2 eval { 374 DELETE FROM t2; 375 INSERT INTO t2 VALUES(21, 'x'); 376 INSERT INTO t2 VALUES(22, 'y'); 377 CREATE TABLE tx(x1,x2,y1,y2); 378 INSERT INTO tx VALUES(1, 11, 'x', 'x'); 379 INSERT INTO tx VALUES(2, 12, 'y', 'y'); 380 INSERT INTO tx VALUES(11, 21, 'x', 'x'); 381 INSERT INTO tx VALUES(12, 22, 'y', 'y'); 382 CREATE INDEX i2 ON t2(x); 383 } 384} 385 386do_test attach-3.2 { 387 catchsql { 388 SELECT * FROM t2 389 } 390} {1 {no such table: t2}} 391do_test attach-3.3 { 392 catchsql { 393 ATTACH DATABASE 'test2.db' AS db2; 394 SELECT * FROM t2 395 } 396} {0 {21 x 22 y}} 397 398# Even though 'db' has started a transaction, it should not yet have 399# a lock on test2.db so 'db2' should be readable. 400do_test attach-3.4 { 401 execsql BEGIN 402 catchsql { 403 SELECT * FROM t2; 404 } db2; 405} {0 {21 x 22 y}} 406 407# Reading from test2.db from db within a transaction should not 408# prevent test2.db from being read by db2. 409do_test attach-3.5 { 410 execsql {SELECT * FROM t2} 411btree_breakpoint 412 catchsql { 413 SELECT * FROM t2; 414 } db2; 415} {0 {21 x 22 y}} 416 417# Making a change to test2.db through db causes test2.db to get 418# a reserved lock. It should still be accessible through db2. 419do_test attach-3.6 { 420 execsql { 421 UPDATE t2 SET x=x+1 WHERE x=50; 422 } 423 catchsql { 424 SELECT * FROM t2; 425 } db2; 426} {0 {21 x 22 y}} 427 428do_test attach-3.7 { 429 execsql ROLLBACK 430 execsql {SELECT * FROM t2} db2 431} {21 x 22 y} 432 433# Start transactions on both db and db2. Once again, just because 434# we make a change to test2.db using db2, only a RESERVED lock is 435# obtained, so test2.db should still be readable using db. 436# 437do_test attach-3.8 { 438 execsql BEGIN 439 execsql BEGIN db2 440 execsql {UPDATE t2 SET x=0 WHERE 0} db2 441 catchsql {SELECT * FROM t2} 442} {0 {21 x 22 y}} 443 444# It is also still accessible from db2. 445do_test attach-3.9 { 446 catchsql {SELECT * FROM t2} db2 447} {0 {21 x 22 y}} 448 449do_test attach-3.10 { 450 execsql {SELECT * FROM t1} 451} {1 2 3 4} 452 453do_test attach-3.11 { 454 catchsql {UPDATE t1 SET a=a+1} 455} {0 {}} 456do_test attach-3.12 { 457 execsql {SELECT * FROM t1} 458} {2 2 4 4} 459 460# db2 has a RESERVED lock on test2.db, so db cannot write to any tables 461# in test2.db. 462do_test attach-3.13 { 463 catchsql {UPDATE t2 SET x=x+1 WHERE x=50} 464} {1 {database is locked}} 465 466# Change for version 3. Transaction is no longer rolled back 467# for a locked database. 468execsql {ROLLBACK} 469 470# db is able to reread its schema because db2 still only holds a 471# reserved lock. 472do_test attach-3.14 { 473 catchsql {SELECT * FROM t1} 474} {0 {1 2 3 4}} 475do_test attach-3.15 { 476 execsql COMMIT db2 477 execsql {SELECT * FROM t1} 478} {1 2 3 4} 479 480#set btree_trace 1 481 482# Ticket #323 483do_test attach-4.1 { 484 execsql {DETACH db2} 485 db2 close 486 sqlite3 db2 test2.db 487 execsql { 488 CREATE TABLE t3(x,y); 489 CREATE UNIQUE INDEX t3i1 ON t3(x); 490 INSERT INTO t3 VALUES(1,2); 491 SELECT * FROM t3; 492 } db2; 493} {1 2} 494do_test attach-4.2 { 495 execsql { 496 CREATE TABLE t3(a,b); 497 CREATE UNIQUE INDEX t3i1b ON t3(a); 498 INSERT INTO t3 VALUES(9,10); 499 SELECT * FROM t3; 500 } 501} {9 10} 502do_test attach-4.3 { 503 execsql { 504 ATTACH DATABASE 'test2.db' AS db2; 505 SELECT * FROM db2.t3; 506 } 507} {1 2} 508do_test attach-4.4 { 509 execsql { 510 SELECT * FROM main.t3; 511 } 512} {9 10} 513do_test attach-4.5 { 514 execsql { 515 INSERT INTO db2.t3 VALUES(9,10); 516 SELECT * FROM db2.t3; 517 } 518} {1 2 9 10} 519execsql { 520 DETACH db2; 521} 522ifcapable {trigger} { 523 do_test attach-4.6 { 524 execsql { 525 CREATE TABLE t4(x); 526 CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN 527 INSERT INTO t4 VALUES('db2.' || NEW.x); 528 END; 529 INSERT INTO t3 VALUES(6,7); 530 SELECT * FROM t4; 531 } db2 532 } {db2.6} 533 do_test attach-4.7 { 534 execsql { 535 CREATE TABLE t4(y); 536 CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN 537 INSERT INTO t4 VALUES('main.' || NEW.a); 538 END; 539 INSERT INTO main.t3 VALUES(11,12); 540 SELECT * FROM main.t4; 541 } 542 } {main.11} 543} 544ifcapable {!trigger} { 545 # When we do not have trigger support, set up the table like they 546 # would have been had triggers been there. The tests that follow need 547 # this setup. 548 execsql { 549 CREATE TABLE t4(x); 550 INSERT INTO t3 VALUES(6,7); 551 INSERT INTO t4 VALUES('db2.6'); 552 INSERT INTO t4 VALUES('db2.13'); 553 } db2 554 execsql { 555 CREATE TABLE t4(y); 556 INSERT INTO main.t3 VALUES(11,12); 557 INSERT INTO t4 VALUES('main.11'); 558 } 559} 560 561 562# This one is tricky. On the UNION ALL select, we have to make sure 563# the schema for both main and db2 is valid before starting to execute 564# the first query of the UNION ALL. If we wait to test the validity of 565# the schema for main until after the first query has run, that test will 566# fail and the query will abort but we will have already output some 567# results. When the query is retried, the results will be repeated. 568# 569ifcapable compound { 570do_test attach-4.8 { 571 execsql { 572 ATTACH DATABASE 'test2.db' AS db2; 573 INSERT INTO db2.t3 VALUES(13,14); 574 SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4; 575 } 576} {db2.6 db2.13 main.11} 577 578do_test attach-4.9 { 579 ifcapable {!trigger} {execsql {INSERT INTO main.t4 VALUES('main.15')}} 580 execsql { 581 INSERT INTO main.t3 VALUES(15,16); 582 SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4; 583 } 584} {db2.6 db2.13 main.11 main.15} 585} ;# ifcapable compound 586 587ifcapable !compound { 588 ifcapable {!trigger} {execsql {INSERT INTO main.t4 VALUES('main.15')}} 589 execsql { 590 ATTACH DATABASE 'test2.db' AS db2; 591 INSERT INTO db2.t3 VALUES(13,14); 592 INSERT INTO main.t3 VALUES(15,16); 593 } 594} ;# ifcapable !compound 595 596ifcapable view { 597do_test attach-4.10 { 598 execsql { 599 DETACH DATABASE db2; 600 } 601 execsql { 602 CREATE VIEW v3 AS SELECT x*100+y FROM t3; 603 SELECT * FROM v3; 604 } db2 605} {102 910 607 1314} 606do_test attach-4.11 { 607 execsql { 608 CREATE VIEW v3 AS SELECT a*100+b FROM t3; 609 SELECT * FROM v3; 610 } 611} {910 1112 1516} 612do_test attach-4.12 { 613 execsql { 614 ATTACH DATABASE 'test2.db' AS db2; 615 SELECT * FROM db2.v3; 616 } 617} {102 910 607 1314} 618do_test attach-4.13 { 619 execsql { 620 SELECT * FROM main.v3; 621 } 622} {910 1112 1516} 623} ;# ifcapable view 624 625# Tests for the sqliteFix...() routines in attach.c 626# 627ifcapable {trigger} { 628do_test attach-5.1 { 629 db close 630 sqlite3 db test.db 631 db2 close 632 file delete -force test2.db 633 sqlite3 db2 test2.db 634 catchsql { 635 ATTACH DATABASE 'test.db' AS orig; 636 CREATE TRIGGER r1 AFTER INSERT ON orig.t1 BEGIN 637 SELECT 'no-op'; 638 END; 639 } db2 640} {1 {trigger r1 cannot reference objects in database orig}} 641do_test attach-5.2 { 642 catchsql { 643 CREATE TABLE t5(x,y); 644 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 645 SELECT 'no-op'; 646 END; 647 } db2 648} {0 {}} 649do_test attach-5.3 { 650 catchsql { 651 DROP TRIGGER r5; 652 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 653 SELECT 'no-op' FROM orig.t1; 654 END; 655 } db2 656} {1 {trigger r5 cannot reference objects in database orig}} 657ifcapable tempdb { 658 do_test attach-5.4 { 659 catchsql { 660 CREATE TEMP TABLE t6(p,q,r); 661 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 662 SELECT 'no-op' FROM temp.t6; 663 END; 664 } db2 665 } {1 {trigger r5 cannot reference objects in database temp}} 666} 667ifcapable subquery { 668 do_test attach-5.5 { 669 catchsql { 670 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 671 SELECT 'no-op' || (SELECT * FROM temp.t6); 672 END; 673 } db2 674 } {1 {trigger r5 cannot reference objects in database temp}} 675 do_test attach-5.6 { 676 catchsql { 677 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 678 SELECT 'no-op' FROM t1 WHERE x<(SELECT min(x) FROM temp.t6); 679 END; 680 } db2 681 } {1 {trigger r5 cannot reference objects in database temp}} 682 do_test attach-5.7 { 683 catchsql { 684 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 685 SELECT 'no-op' FROM t1 GROUP BY 1 HAVING x<(SELECT min(x) FROM temp.t6); 686 END; 687 } db2 688 } {1 {trigger r5 cannot reference objects in database temp}} 689 do_test attach-5.7 { 690 catchsql { 691 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 692 SELECT max(1,x,(SELECT min(x) FROM temp.t6)) FROM t1; 693 END; 694 } db2 695 } {1 {trigger r5 cannot reference objects in database temp}} 696 do_test attach-5.8 { 697 catchsql { 698 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 699 INSERT INTO t1 VALUES((SELECT min(x) FROM temp.t6),5); 700 END; 701 } db2 702 } {1 {trigger r5 cannot reference objects in database temp}} 703 do_test attach-5.9 { 704 catchsql { 705 CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN 706 DELETE FROM t1 WHERE x<(SELECT min(x) FROM temp.t6); 707 END; 708 } db2 709 } {1 {trigger r5 cannot reference objects in database temp}} 710} ;# endif subquery 711} ;# endif trigger 712 713# Check to make sure we get a sensible error if unable to open 714# the file that we are trying to attach. 715# 716do_test attach-6.1 { 717 catchsql { 718 ATTACH DATABASE 'no-such-file' AS nosuch; 719 } 720} {0 {}} 721if {$tcl_platform(platform)=="unix"} { 722 do_test attach-6.2 { 723 sqlite3 dbx cannot-read 724 dbx eval {CREATE TABLE t1(a,b,c)} 725 dbx close 726 file attributes cannot-read -permission 0000 727 if {[file writable cannot-read]} { 728 puts "\n**** Tests do not work when run as root ****" 729 file delete -force cannot-read 730 exit 1 731 } 732 catchsql { 733 ATTACH DATABASE 'cannot-read' AS noread; 734 } 735 } {1 {unable to open database: cannot-read}} 736 do_test attach-6.2.2 { 737 db errorcode 738 } {14} 739 file delete -force cannot-read 740} 741 742# Check the error message if we try to access a database that has 743# not been attached. 744do_test attach-6.3 { 745 catchsql { 746 CREATE TABLE no_such_db.t1(a, b, c); 747 } 748} {1 {unknown database no_such_db}} 749for {set i 2} {$i<=15} {incr i} { 750 catch {db$i close} 751} 752db close 753file delete -force test2.db 754file delete -force no-such-file 755 756ifcapable subquery { 757 do_test attach-7.1 { 758 file delete -force test.db test.db-journal 759 sqlite3 db test.db 760 catchsql { 761 DETACH RAISE ( IGNORE ) IN ( SELECT "AAAAAA" . * ORDER BY 762 REGISTER LIMIT "AAAAAA" . "AAAAAA" OFFSET RAISE ( IGNORE ) NOT NULL ) 763 } 764 } {1 {invalid name: "RAISE ( IGNORE ) IN ( SELECT "AAAAAA" . * ORDER BY 765 REGISTER LIMIT "AAAAAA" . "AAAAAA" OFFSET RAISE ( IGNORE ) NOT NULL )"}} 766} 767 768# Create a malformed file (a file that is not a valid database) 769# and try to attach it 770# 771do_test attach-8.1 { 772 set fd [open test2.db w] 773 puts $fd "This file is not a valid SQLite database" 774 close $fd 775 catchsql { 776 ATTACH 'test2.db' AS t2; 777 } 778} {1 {file is encrypted or is not a database}} 779do_test attach-8.2 { 780 db errorcode 781} {26} 782file delete -force test2.db 783do_test attach-8.3 { 784 sqlite3 db2 test2.db 785 db2 eval {CREATE TABLE t1(x); BEGIN EXCLUSIVE} 786 catchsql { 787 ATTACH 'test2.db' AS t2; 788 } 789} {1 {database is locked}} 790do_test attach-8.4 { 791 db errorcode 792} {5} 793db2 close 794file delete -force test2.db 795 796 797finish_test 798