]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Begin testing the new ATTACH and DETACH commands. (CVS 898)
authordrh <drh@noemail.net>
Sat, 5 Apr 2003 03:42:26 +0000 (03:42 +0000)
committerdrh <drh@noemail.net>
Sat, 5 Apr 2003 03:42:26 +0000 (03:42 +0000)
FossilOrigin-Name: 7a0f8024a1323a15d0c83afe9302400736f01fe8

manifest
manifest.uuid
src/build.c
src/main.c
test/attach.test [new file with mode: 0644]
test/auth.test

index 1345da9b3ba5347227c568df7118ed5e4e29763a..b81329a777a9d1118912328a8b9d51ca856e2beb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sfor\sticket\s#276.\s(CVS\s897)
-D 2003-04-03T19:35:02
+C Begin\stesting\sthe\snew\sATTACH\sand\sDETACH\scommands.\s(CVS\s898)
+D 2003-04-05T03:42:27
 F Makefile.in 3c4ba24253e61c954d67adbbb4245e7117c5357e
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -22,7 +22,7 @@ F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
 F src/auth.c f37bfc9451b8c1fa52f34adff474560018892729
 F src/btree.c 7eae5413a7f957bb0733bcab6fab31c6943c51d2
 F src/btree.h 024d2dd21310c202d648c6244dec885e48efa9ad
-F src/build.c 81d31f2e63d51683ee653df6399acc3c3a2e3672
+F src/build.c 346e93724f32ec1aa0ed429a004a5e9d7b3372be
 F src/delete.c 58d698779a6b7f819718ecd45b310a9de8537088
 F src/encode.c faf03741efe921755ec371cf4a6984536de00042
 F src/expr.c b8daee83f837b24a22d889200bdd74973ca2d8db
@@ -30,7 +30,7 @@ F src/func.c 882c3ed5a02be18cd904715c7ec62947a34a3605
 F src/hash.c 4fc39feb7b7711f6495ee9f2159559bedb043e1f
 F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8
 F src/insert.c e2f5e7feecb507d904a7da48874595f440b715aa
-F src/main.c 60a64f792a9bcd2e270ef143d8cc75cd74bde8e9
+F src/main.c c5109638c0cd86fa450faa2bd5a60468325aef69
 F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
 F src/os.c dfed46091f69cd2d1e601f8a214d41344f2b00b6
 F src/os.h aa52f0c9da321ff6134d19f2ca959e18e33615d0
@@ -58,7 +58,8 @@ F src/vdbe.c 540c480912e11e23f5c08a31b8b3594df016f4d1
 F src/vdbe.h 985c24f312d10f9ef8f9a8b8ea62fcdf68e82f21
 F src/where.c e5733f7d5e9cc4ed3590dc3401f779e7b7bb8127
 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
-F test/auth.test 33e8b9680eb0ce521c54096fff1c9ab506c7dfb8
+F test/attach.test 93414915d0c27f4e5a384b61792591cd4757fcca
+F test/auth.test bf039c94d629f64085c268e8be477fc8ff1202a7
 F test/bigfile.test 1cd8256d4619c39bea48147d344f348823e78678
 F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
 F test/btree.test 1e3463c7838e7e71bbf37c9c6e45beee9c8975ba
@@ -156,7 +157,7 @@ F www/speed.tcl cb4c10a722614aea76d2c51f32ee43400d5951be
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 5efbf62313519d0a6e8b8f5dbb29d3ef428d73e8
-R 5a014d6f47bb6b05e15d9a08aab3096d
+P 452128c6fd9a0d82bfab21374fc2041638d264db
+R a56a50d034078b39c733a78422380132
 U drh
-Z 2ea90991c4b4f9c403624226cb57c924
+Z 584b6bf3cd679c184cb1aafc492c3c1b
index 6c239d45475b8c11f8008a77e10aba714f51e1b7..86590657f80ce6b560bb165696ca458570ba8d7a 100644 (file)
@@ -1 +1 @@
-452128c6fd9a0d82bfab21374fc2041638d264db
\ No newline at end of file
+7a0f8024a1323a15d0c83afe9302400736f01fe8
\ No newline at end of file
index 5d247850c1fe298f79876821ff50d2305d7e0421..36152686fed8c7fac2d18c497c888db25c3d36f5 100644 (file)
@@ -25,7 +25,7 @@
 **     ROLLBACK
 **     PRAGMA
 **
-** $Id: build.c,v 1.139 2003/03/31 13:36:09 drh Exp $
+** $Id: build.c,v 1.140 2003/04/05 03:42:27 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -2670,6 +2670,11 @@ void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){
 
   if( pParse->explain ) return;
   db = pParse->db;
+  if( db->file_format<4 ){
+    sqliteErrorMsg(pParse, "cannot attach auxiliary databases to an "
+       "older format master database", 0);
+    return;
+  }
   if( db->nDb>=MAX_ATTACHED ){
     sqliteErrorMsg(pParse, "too many attached databases - max %d", 
        MAX_ATTACHED);
@@ -2715,6 +2720,7 @@ void sqliteAttach(Parse *pParse, Token *pFilename, Token *pDbname){
   if( pParse->nErr ) return;
   rc = sqliteInit(pParse->db, &pParse->zErrMsg);
   if( rc ){
+    sqliteResetInternalSchema(db, 0);
     pParse->nErr++;
   }
 }
index dacf11235fbfbfe332ae750a3badb390807f2c74..408d97fa2140dac6867b66c6b010e5dd91eb8e89 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.120 2003/04/03 15:46:04 drh Exp $
+** $Id: main.c,v 1.121 2003/04/05 03:42:27 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -297,9 +297,15 @@ static int sqliteInitOne(sqlite *db, int iDb, char **pzErrMsg){
       sqliteSetString(pzErrMsg, "unsupported file format", 0);
       return SQLITE_ERROR;
     }
-  }else if( db->file_format<4 || db->file_format!=meta[2] ){
-    sqliteSetString(pzErrMsg, "incompatible file format in auxiliary "
-       "database \"", db->aDb[iDb].zName, "\"", 0);
+  }else if( db->file_format!=meta[2] || db->file_format<4 ){
+    assert( db->file_format>=4 );
+    if( meta[2]==0 ){
+      sqliteSetString(pzErrMsg, "cannot attach empty database: ",
+         db->aDb[iDb].zName, 0);
+    }else{
+      sqliteSetString(pzErrMsg, "incompatible file format in auxiliary "
+         "database: ", db->aDb[iDb].zName, 0);
+    }
     sqliteBtreeClose(db->aDb[iDb].pBt);
     db->aDb[iDb].pBt = 0;
     return SQLITE_FORMAT;
diff --git a/test/attach.test b/test/attach.test
new file mode 100644 (file)
index 0000000..fd79d91
--- /dev/null
@@ -0,0 +1,72 @@
+# 2003 April 4
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.  The
+# focus of this script is testing the ATTACH and DETACH commands
+# and related functionality.
+#
+# $Id: attach.test,v 1.1 2003/04/05 03:42:27 drh Exp $
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+file delete -force test2.db
+file delete -force test2.db-journal
+
+do_test attach-1.1 {
+  execsql {
+    CREATE TABLE t1(a,b);
+    INSERT INTO t1 VALUES(1,2);
+    INSERT INTO t1 VALUES(3,4);
+    SELECT * FROM t1;
+  }
+} {1 2 3 4}
+do_test attach-1.2 {
+  sqlite db2 test2.db
+  execsql {
+    CREATE TABLE t2(x,y);
+    INSERT INTO t2 VALUES(1,'x');
+    INSERT INTO t2 VALUES(2,'y');
+    SELECT * FROM t2;
+  }
+} {1 x 2 y}
+do_test attach-1.3 {
+  execsql {
+    ATTACH DATABASE 'test2.db' AS two;
+    SELECT * FROM two.t2;
+  }
+} {1 x 2 y}
+do_test attach-1.4 {
+  execsql {
+    SELECT * FROM t2;
+  }
+} {1 x 2 y}
+do_test attach-1.5 {
+  execsql {
+    DETACH DATABASE two;
+    SELECT * FROM t1;
+  }
+} {1 2 3 4}
+do_test attach-1.6 {
+  catchsql {
+    SELECT * FROM t2;
+  }
+} {1 {no such table: t2}}
+do_test attach-1.7 {
+  catchsql {
+    SELECT * FROM two.t2;
+  }
+} {1 {no such table: two.t2}}
+
+db2 close
+
+
+finish_test
index 63610479b254ad9d0635b25dfbb2febd7dfde46c..6f532429765253a05dd301de32a88aea0be19cd6 100644 (file)
@@ -1,4 +1,4 @@
-# 2003 January 12
+# 2003 April 4
 #
 # The author disclaims copyright to this source code.  In place of
 # a legal notice, here is a blessing:
@@ -9,9 +9,10 @@
 #
 #***********************************************************************
 # This file implements regression tests for SQLite library.  The
-# focus of this script testing the sqlite_set_authorizer() API.
+# focus of this script is testing the ATTACH and DETACH commands
+# and related functionality.
 #
-# $Id: auth.test,v 1.5 2003/01/31 17:21:50 drh Exp $
+# $Id: auth.test,v 1.6 2003/04/05 03:42:27 drh Exp $
 #
 
 set testdir [file dirname $argv0]