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