1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Additional testing of the ATTACH command with bug fixes for the new problems

that the tests found. (CVS 998)

FossilOrigin-Name: 3e8889d7ce5e99fc855526fc1bb62ddbe282bfc5
This commit is contained in:
drh
2003-06-03 01:47:11 +00:00
parent 1aa4965ae3
commit 4312db55d9
8 changed files with 168 additions and 28 deletions

View File

@ -12,7 +12,7 @@
# focus of this script is testing the ATTACH and DETACH commands
# and related functionality.
#
# $Id: attach.test,v 1.6 2003/05/31 16:21:13 drh Exp $
# $Id: attach.test,v 1.7 2003/06/03 01:47:12 drh Exp $
#
set testdir [file dirname $argv0]
@ -469,10 +469,112 @@ do_test attach-4.13 {
}
} {910 1112 1516}
# Tests for the sqliteFix...() routines in attach.c
#
do_test attach-5.1 {
db close
sqlite db test.db
file delete -force test2.db
sqlite db2 test2.db
catchsql {
ATTACH DATABASE 'test.db' AS orig;
CREATE TRIGGER r1 AFTER INSERT ON orig.t1 BEGIN;
SELECT 'no-op';
END;
} db2
} {1 {triggers may not be added to auxiliary database orig}}
do_test attach-5.2 {
catchsql {
CREATE TABLE t5(x,y);
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op';
END;
} db2
} {0 {}}
do_test attach-5.3 {
catchsql {
DROP TRIGGER r5;
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM orig.t1;
END;
} db2
} {1 {trigger r5 cannot reference objects in database orig}}
do_test attach-5.4 {
catchsql {
CREATE TEMP TABLE t6(p,q,r);
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM temp.t6;
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.5 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' || (SELECT * FROM temp.t6);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.6 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM t1 WHERE x<(SELECT min(x) FROM temp.t6);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.7 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT 'no-op' FROM t1 GROUP BY 1 HAVING x<(SELECT min(x) FROM temp.t6);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.7 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
SELECT max(1,x,(SELECT min(x) FROM temp.t6)) FROM t1;
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.8 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
INSERT INTO t1 VALUES((SELECT min(x) FROM temp.t6),5);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
do_test attach-5.9 {
catchsql {
CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN
DELETE FROM t1 WHERE x<(SELECT min(x) FROM temp.t6);
END;
} db2
} {1 {trigger r5 cannot reference objects in database temp}}
# Check to make sure we get a sensible error if unable to open
# the file that we are trying to attach.
#
do_test attach-6.1 {
catchsql {
ATTACH DATABASE 'no-such-file' AS nosuch;
}
} {1 {cannot attach empty database: nosuch}}
file delete -force no-such-file
do_test attach-6.2 {
sqlite dbx cannot-read
dbx eval {CREATE TABLE t1(a,b,c)}
dbx close
catch {file attributes cannot-read -permission 0000}
catch {file attributes cannot-read -readonly 1}
catchsql {
ATTACH DATABASE 'cannot-read' AS noread;
}
} {1 {unable to open database: cannot-read}}
file delete -force cannot-read
for {set i 2} {$i<=15} {incr i} {
catch {db$i close}
}
file delete -force test2.db
finish_test

View File

@ -12,7 +12,7 @@
# focus of this file is testing the the library is able to correctly
# handle file-format 3 (version 2.6.x) databases.
#
# $Id: format3.test,v 1.2 2002/12/04 21:50:16 drh Exp $
# $Id: format3.test,v 1.3 2003/06/03 01:47:12 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -718,4 +718,21 @@ do_test format3-11.7 {
}
} {0 0}
# Make sure attempts to attach a format 3 database fail.
#
do_test format3-12.1 {
file delete -force test2.db
sqlite db2 test2.db
catchsql {
CREATE TABLE t8(x,y);
ATTACH DATABASE 'test.db' AS format3;
} db2;
} {1 {incompatible file format in auxiliary database: format3}}
do_test format3-12.2 {
catchsql {
ATTACH DATABASE 'test2.db' AS test2;
}
} {1 {cannot attach auxiliary databases to an older format master database}}
db2 close
finish_test

View File

@ -13,7 +13,7 @@
# This file implements tests for miscellanous features that were
# left out of other test files.
#
# $Id: misc1.test,v 1.21 2003/02/26 13:52:52 drh Exp $
# $Id: misc1.test,v 1.22 2003/06/03 01:47:12 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -518,6 +518,23 @@ do_test misc1-16.6 {
}
} {1 1 5 5 6 6}
# Ticket #333: Temp triggers that modify persistent tables.
#
do_test misc1-17.1 {
execsql {
BEGIN;
CREATE TABLE RealTable(TestID INTEGER PRIMARY KEY, TestString TEXT);
CREATE TEMP TABLE TempTable(TestID INTEGER PRIMARY KEY, TestString TEXT);
CREATE TEMP TRIGGER trigTest_1 AFTER UPDATE ON TempTable BEGIN
INSERT INTO RealTable(TestString)
SELECT new.TestString FROM TempTable LIMIT 1;
END;
INSERT INTO TempTable(TestString) VALUES ('1');
INSERT INTO TempTable(TestString) VALUES ('2');
UPDATE TempTable SET TestString = TestString + 1 WHERE TestID IN (1, 2);
COMMIT;
SELECT TestString FROM RealTable ORDER BY 1;
}
} {2 3}
finish_test