Modifications and bugfixes so that the test suite passes with the TCL statement cache turned on. (CVS 2271)

FossilOrigin-Name: d5233e0747789dea04d35a8350b408321d23a64d
diff --git a/manifest b/manifest
index f8cf81f..e7b5cdd 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Flush\sthe\sTCL\sstatement\scache\sbefore\seach\slock_status\spragma.\s(CVS\s2270)
-D 2005-01-24T01:38:33
+C Modifications\sand\sbugfixes\sso\sthat\sthe\stest\ssuite\spasses\swith\sthe\sTCL\sstatement\scache\sturned\son.\s(CVS\s2271)
+D 2005-01-24T10:25:59
 F Makefile.in ffd81f5e926d40b457071b4de8d7c1fa18f39b5a
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@@ -27,11 +27,11 @@
 F sqlite3.1 01fdb467ce387a83248857c92f9e801df9e4611c
 F sqlite3.def dbaeb20c153e1d366e8f421b55a573f5dfc00863
 F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a
-F src/attach.c 4fcdb30304f479aa6ce57d9f583357421e7b3f65
+F src/attach.c f78f76bc6a8e5e487ca53636e21ccba2484a9a61
 F src/auth.c 4b15c85335417752cc1045eae18b8186e08c8184
 F src/btree.c e68ae12c8b12ef9d45d58d931c36c184055a3880
 F src/btree.h 74d19cf40ab49fd69abe9e4e12a6c321ad86c497
-F src/build.c b60b1f1f48521fe5b4bf98a189cadc205b2e8065
+F src/build.c 91e05a3a5031a72b94696f0ac062aa972d4254ec
 F src/cursor.c de73c00aefc4747ad59b5105cf38bbff0667922e
 F src/date.c f3d1f5cd1503dabf426a198f3ebef5afbc122a7f
 F src/delete.c b3accca9c38d9a67dbd724f67b04151a13735ebd
@@ -42,7 +42,7 @@
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
 F src/insert.c 037eb46630f027d0f93584db180d08ce163f3dbb
 F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
-F src/main.c 6a549ea86cbd7511d566a24788371ab2249d2aa9
+F src/main.c 1fe0216dc01e1929e7e009cdedfb3e6e2391d717
 F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
 F src/os.h ae44064dc118b20d39450cb331409a775e8bb1c6
 F src/os_common.h 0e7f428ba0a6c40a61bc56c4e96f493231301b73
@@ -55,7 +55,7 @@
 F src/pager.c 886a1ae43365ae3b2599d8c6eb6091d5dc91ca7c
 F src/pager.h 9eba8c53dd91eae7f3f90743b2ee242da02a9862
 F src/parse.y 5f2c197fcb63c6aed1787da436ec5a35247ab7a4
-F src/pragma.c 141a3f4985b76035d102dc7ca37be6b04cfb8376
+F src/pragma.c c893f03104e94e0921861bd2d3dbd80c47515f7b
 F src/printf.c 3d20b21cfecadacecac3fb7274e746cb81d3d357
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
 F src/select.c e204ca5292751ed889f2cbcf2d2808a4d29edd2c
@@ -63,7 +63,7 @@
 F src/sqlite.h.in 7d7c28344e2bd770491b56ed9169be20859c707d
 F src/sqliteInt.h be6fa5e31c65e2b8e10112ee47a6e63ec7de37b5
 F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
-F src/tclsqlite.c 279a3be922e6af3a2408f55dfd2c3f031acff0a2
+F src/tclsqlite.c 47ecdb00e9bc135b37ad5bed84fefe20d7c19611
 F src/test1.c 0a71a150659dd261be775c5eb60ae6c0c856c8a5
 F src/test2.c bbc2ecc58ceeab12d1e40970f831b1017524e40d
 F src/test3.c 683e1e3819152ffd35da2f201e507228921148d0
@@ -75,22 +75,22 @@
 F src/utf.c 9bece2c7b94d9002ab1bb900a7658c6f826b0f74
 F src/util.c a858b93ba06bbafab55ba41e4d58538eb51f4b6a
 F src/vacuum.c 1a9db113a027461daaf44724c71dd1ebbd064203
-F src/vdbe.c a5db9e8c1a7482a865d49ded5947ecbd97bee6f8
+F src/vdbe.c 4fb54fd01cf00b90dfd02f73785adc3f043e89e3
 F src/vdbe.h 067ca8d6750ba4f69a50284765e5883dee860181
 F src/vdbeInt.h 24d411de9efc6919a1e580069a597182be269bcf
-F src/vdbeapi.c 7b65522152c36104e1ab83057ce6f7b880755b16
-F src/vdbeaux.c acf9fe566c7985564f8c28bcbecb3ffa2e804238
+F src/vdbeapi.c 467caa6e6fb9247528b1c7ab9132ae1b4748e8ac
+F src/vdbeaux.c 30cd8af354e3a067a494196e11f6795fc4bc42f9
 F src/vdbemem.c 62fe89471b656a922e9879be005abf690509ead3
 F src/where.c f4127cc2633ee0f74790ab7f09f5af832489e44e
 F tclinstaller.tcl 36478c3bbfc5b93ceac42d94e3c736937b808432
 F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
 F test/alter.test 95c57a4f461fa81293e0dccef7f83889aadb169a
-F test/attach.test 4f83c2edc418ca2e63c6ac8678f912234732e9a7
+F test/attach.test 5147d531ca5fc5c2539fd20ce3b07a00420e1fbb
 F test/attach2.test 6f3a3a3a7f5be40388dd4d805e0e0712718dca9d
 F test/attach3.test c05c70b933afbde0901dab9da3e66ee842c09f38
-F test/auth.test 559e0816b8100740624ebb0ab7aab05f5c92831c
+F test/auth.test b24d12de3a6ba49237216429f8dc672a8a52b342
 F test/autoinc.test c6daf10ffce8a898cd375b4a71615a741a6029d0
-F test/autovacuum.test a87871f29761093dc171e97c9d0dd5ae7d43b0d1
+F test/autovacuum.test 8ba29face873300394f9446ded0e4a142d24e7e4
 F test/autovacuum_crash.test 05a63b8805b20cfba7ace82856ce4ccdda075a31
 F test/autovacuum_ioerr.test 9cf27275ca47b72e188a47c53b61b6d583a01d24
 F test/autovacuum_ioerr2.test 8feb1cfb4d8177c639cd1e0b8c41d3c88a2a1518
@@ -105,7 +105,7 @@
 F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027
 F test/btree7.test a6d3b842db22af97dd14b989e90a2fd96066b72f
 F test/capi2.test b0e12aa66684424869f899b421ff71df69411998
-F test/capi3.test 607c90dd85b357c412f064a882f197528695ab34
+F test/capi3.test f50dd4666deba96275f9927fe8ec089a3d8c0efa
 F test/capi3b.test 5b6a66f9f295f79f443b5d3f33187fa5ef6cf336
 F test/collate1.test f79736d2ebf5492167ee4d1f4ab4c09dda776b03
 F test/collate2.test 224a632ba04907c049804b08162efd234aa7871f
@@ -158,7 +158,7 @@
 F test/misc2.test fc052267d5178367f955538ae34aae1b2f696a92
 F test/misc3.test 7bd937e2c62bcc6be71939faf068d506467b1e03
 F test/misc4.test 145e301fdf10bd47059132db932523814201dc2a
-F test/misuse.test 600738a8e611989bc5f544303f5e311c5f228084
+F test/misuse.test 1c7fee3c4c0cb4008717ecccf5c72281fac0008e
 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
 F test/null.test 69c62daf1630bf54c87bbc7ef2e22012e58d6da8
 F test/pager.test 1579e8f07291ae8e24db62ffade5c101c3e76597
@@ -174,6 +174,7 @@
 F test/rollback.test 94cd981ee3a627d9f6466f69dcf1f7dbfe695d7a
 F test/rowid.test 040a3bef06f970c45f5fcd14b2355f7f4d62f0cf
 F test/safety.test 907b64fee719554a3622853812af3886fddbbb4f
+F test/schema.test ccaceafa6c0031489f7e927f0449bef360530387
 F test/select1.test ad700a2a1c325a23a7206ad4d189e33917de526f
 F test/select2.test 91a2225926039b0d1687840735c284dbbf89f0bc
 F test/select3.test 9de435aa84fc406708cd8dc1b1d60e7f27cea685
@@ -184,11 +185,11 @@
 F test/sort.test 87882e6c72a75d45e98a1c802c1ded0eac557d85
 F test/subquery.test a3ed9f11a4e576ff31b539ab5d65953dc3d27a81
 F test/subselect.test 3f3f7a940dc3195c3139f4d530385cb54665d614
-F test/table.test fe2fa0d684eee90b3bd823f23c1403818630780b
+F test/table.test a2a58cae70ef2511cbf27d40fb8f570106a2677e
 F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
 F test/tclsqlite.test 4b26cad242ef5c634fd52e0465c723d9e0c00901
 F test/temptable.test 63a16e3ad19adf073cfbcdf7624c92ac5236522c
-F test/tester.tcl d734cbbce1662179a4dd9910c891af3709f2b058
+F test/tester.tcl 227af8e343b13e2927c9ac9a6b0148fb3c7afac8
 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
 F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
 F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
@@ -271,7 +272,7 @@
 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd
-P 8db6bfef52c1f35afdb8b60cba34f6807a5917f4
-R 04f78ef84e429eb28cb91e619e88c53e
-U drh
-Z 1ed3d448d66b352d27841d237b7b8939
+P 8beae3ff8cbe23f20eb242187edbdb72133a24c3
+R e210e6d8b7fc1de8bf1fafd9d7f898f8
+U danielk1977
+Z 83dc4420463960a142888db523f30157
diff --git a/manifest.uuid b/manifest.uuid
index 400f841..dbe00e1 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-8beae3ff8cbe23f20eb242187edbdb72133a24c3
\ No newline at end of file
+d5233e0747789dea04d35a8350b408321d23a64d
\ No newline at end of file
diff --git a/src/attach.c b/src/attach.c
index f0bdc7a..095d2ab 100644
--- a/src/attach.c
+++ b/src/attach.c
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to implement the ATTACH and DETACH commands.
 **
-** $Id: attach.c,v 1.30 2005/01/23 13:14:55 drh Exp $
+** $Id: attach.c,v 1.31 2005/01/24 10:25:59 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -38,6 +38,7 @@
 
   v = sqlite3GetVdbe(pParse);
   if( !v ) return;
+  sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
   sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   if( pParse->explain ) return;
   db = pParse->db;
@@ -126,7 +127,6 @@
   }
 #endif
   sqliteFree(zFile);
-  sqlite3ExpirePreparedStatements(db);
   db->flags &= ~SQLITE_Initialized;
   if( pParse->nErr==0 && rc==SQLITE_OK ){
     rc = sqlite3ReadSchema(pParse);
@@ -161,6 +161,7 @@
 
   v = sqlite3GetVdbe(pParse);
   if( !v ) return;
+  sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
   sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
   if( pParse->explain ) return;
   db = pParse->db;
@@ -191,7 +192,6 @@
   sqlite3BtreeClose(pDb->pBt);
   pDb->pBt = 0;
   sqlite3ResetInternalSchema(db, 0);
-  sqlite3ExpirePreparedStatements(db);
 }
 
 /*
diff --git a/src/build.c b/src/build.c
index 8b238ce..5d7111d 100644
--- a/src/build.c
+++ b/src/build.c
@@ -22,7 +22,7 @@
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.297 2005/01/21 11:55:27 danielk1977 Exp $
+** $Id: build.c,v 1.298 2005/01/24 10:25:59 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -760,12 +760,21 @@
     ** The rowid value is needed by the code that sqlite3EndTable will
     ** generate.
     */
+#ifndef SQLITE_OMIT_VIEW
+    if( isView ){
+      sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
+    }else
+#endif
+    {
+      sqlite3VdbeAddOp(v, OP_CreateTable, iDb, 0);
+    }
     sqlite3OpenMasterTable(v, iDb);
     sqlite3VdbeAddOp(v, OP_NewRecno, 0, 0);
     sqlite3VdbeAddOp(v, OP_Dup, 0, 0);
     sqlite3VdbeAddOp(v, OP_String8, 0, 0);
     sqlite3VdbeAddOp(v, OP_PutIntKey, 0, 0);
     sqlite3VdbeAddOp(v, OP_Close, 0, 0);
+    sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
   }
 
   /* Normal (non-error) return. */
@@ -1404,13 +1413,13 @@
     */
     if( p->pSelect==0 ){
       /* A regular table */
-      sqlite3VdbeAddOp(v, OP_CreateTable, p->iDb, 0);
+      /* sqlite3VdbeAddOp(v, OP_CreateTable, p->iDb, 0); */
       zType = "table";
       zType2 = "TABLE";
 #ifndef SQLITE_OMIT_VIEW
     }else{
       /* A view */
-      sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
+    /*  sqlite3VdbeAddOp(v, OP_Integer, 0, 0); */
       zType = "view";
       zType2 = "VIEW";
 #endif
@@ -1884,9 +1893,11 @@
       destroyTable(pParse, pTab);
     }
 
-    /* Remove the table entry from SQLite's internal schema
+    /* Remove the table entry from SQLite's internal schema and modify
+    ** the schema cookie.
     */
     sqlite3VdbeOp3(v, OP_DropTable, iDb, 0, pTab->zName, 0);
+    sqlite3ChangeCookie(db, v, iDb);
   }
   sqliteViewResetAll(db, iDb);
 
@@ -2200,7 +2211,7 @@
         goto exit_create_index;
       }
     }
-  }else if( pName==0 ){
+  }else{
     char zBuf[30];
     int n;
     Index *pLoop;
@@ -2403,13 +2414,15 @@
     sqlite3VdbeAddOp(v, OP_Pop, 1, 0);
     sqliteFree(zStmt);
 
-    /* Fill the index with data and reparse the schema
+    /* Fill the index with data and reparse the schema. Code an OP_Expire
+    ** to invalidate all pre-compiled statements.
     */
     if( pTblName ){
       sqlite3RefillIndex(pParse, pIndex, iMem);
       sqlite3ChangeCookie(db, v, iDb);
       sqlite3VdbeOp3(v, OP_ParseSchema, iDb, 0,
          sqlite3MPrintf("name='%q'", pIndex->zName), P3_DYNAMIC);
+      sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
     }
   }
 
diff --git a/src/main.c b/src/main.c
index e2ffd31..9ab3d75 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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.273 2005/01/21 08:13:15 danielk1977 Exp $
+** $Id: main.c,v 1.274 2005/01/24 10:25:59 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -1287,6 +1287,14 @@
     );
     return SQLITE_ERROR;
   }
+
+  /* If removing a collation sequence, then set the expired flag for
+  ** all precompiled statements.
+  */
+  if( !xCompare ){
+    sqlite3ExpirePreparedStatements(db);
+  }
+
   pColl = sqlite3FindCollSeq(db, (u8)enc, zName, strlen(zName), 1);
   if( 0==pColl ){
    rc = SQLITE_NOMEM;
diff --git a/src/pragma.c b/src/pragma.c
index 890cc39..0f3a502 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to implement the PRAGMA command.
 **
-** $Id: pragma.c,v 1.85 2005/01/22 03:03:54 drh Exp $
+** $Id: pragma.c,v 1.86 2005/01/24 10:25:59 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -155,18 +155,21 @@
     if( sqlite3StrICmp(zLeft, p->zName)==0 ){
       sqlite3 *db = pParse->db;
       Vdbe *v;
-      if( zRight==0 ){
-        v = sqlite3GetVdbe(pParse);
-        if( v ){
+      v = sqlite3GetVdbe(pParse);
+      if( v ){
+        if( zRight==0 ){
           returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
-        }
-      }else{
-        if( getBoolean(zRight) ){
-          db->flags |= p->mask;
         }else{
-          db->flags &= ~p->mask;
+          if( getBoolean(zRight) ){
+            db->flags |= p->mask;
+          }else{
+            db->flags &= ~p->mask;
+          }
         }
-        sqlite3ExpirePreparedStatements(db);
+        /* If one of these pragmas is executed, any prepared statements
+        ** need to be recompiled.
+        */
+        sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
       }
       return 1;
     }
@@ -896,6 +899,14 @@
 #endif
 
   {}
+
+  if( v ){
+    /* Code an OP_Expire at the end of each PRAGMA program to cause
+    ** the VDBE implementing the pragma to expire. Most (all?) pragmas
+    ** are only valid for a single execution.
+    */
+    sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
+  }
 pragma_out:
   sqliteFree(zLeft);
   sqliteFree(zRight);
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index 177ad40..dc05eab 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -11,7 +11,7 @@
 *************************************************************************
 ** A TCL Interface to SQLite
 **
-** $Id: tclsqlite.c,v 1.116 2005/01/24 00:28:43 drh Exp $
+** $Id: tclsqlite.c,v 1.117 2005/01/24 10:25:59 danielk1977 Exp $
 */
 #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
 
@@ -22,7 +22,7 @@
 #include <string.h>
 #include <assert.h>
 
-#define NUM_PREPARED_STMTS 0
+#define NUM_PREPARED_STMTS 10
 #define MAX_PREPARED_STMTS 100
 
 /*
diff --git a/src/vdbe.c b/src/vdbe.c
index 69b5c94..e581d1c 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.445 2005/01/21 08:13:15 danielk1977 Exp $
+** $Id: vdbe.c,v 1.446 2005/01/24 10:25:59 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -4495,6 +4495,24 @@
 }
 #endif /* SQLITE_OMIT_CURSOR */
 
+/* Opcode: Expire P1 * *
+**
+** Cause precompiled statements to become expired. An expired statement
+** fails with an error code of SQLITE_SCHEMA if it is ever executed 
+** (via sqlite3_step()).
+** 
+** If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
+** then only the currently executing statement is affected. 
+*/
+case OP_Expire: {
+  if( !pOp->p1 ){
+    sqlite3ExpirePreparedStatements(db);
+  }else{
+    p->expired = 1;
+  }
+  break;
+}
+
 
 
 /* An other opcode is illegal...
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 348925a..ca16128 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -163,6 +163,12 @@
   if( p->aborted ){
     return SQLITE_ABORT;
   }
+  if( p->pc<=0 && p->expired ){
+    if( p->rc==SQLITE_OK ){
+      p->rc = SQLITE_SCHEMA;
+    }
+    return SQLITE_ERROR;
+  }
   db = p->db;
   if( sqlite3SafetyOn(db) ){
     p->rc = SQLITE_MISUSE;
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index aa45de8..aedc305 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -1302,6 +1302,12 @@
     }else{
       sqlite3Error(p->db, SQLITE_OK, 0);
     }
+  }else if( p->rc && p->expired ){
+    /* The expired flag was set on the VDBE before the first call
+    ** to sqlite3_step(). For consistency (since sqlite3_step() was
+    ** called), set the database error in this case as well.
+    */
+    sqlite3Error(p->db, p->rc, 0);
   }
 
   /* Reclaim all memory used by the VDBE
diff --git a/test/attach.test b/test/attach.test
index cac35c6..2003782 100644
--- a/test/attach.test
+++ b/test/attach.test
@@ -12,7 +12,7 @@
 # focus of this script is testing the ATTACH and DETACH commands
 # and related functionality.
 #
-# $Id: attach.test,v 1.36 2005/01/23 13:14:55 drh Exp $
+# $Id: attach.test,v 1.37 2005/01/24 10:26:00 danielk1977 Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -158,7 +158,7 @@
   db_list db
 } {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11}
 } ;# ifcapable schema_pragmas
-integrity_check attach-1.20.2
+integrity_check attach-1.20.3
 execsql {select * from sqlite_temp_master}
 do_test attach-1.21 {
   catchsql {
diff --git a/test/auth.test b/test/auth.test
index 63ed7ba..90c548c 100644
--- a/test/auth.test
+++ b/test/auth.test
@@ -12,7 +12,7 @@
 # focus of this script is testing the ATTACH and DETACH commands
 # and related functionality.
 #
-# $Id: auth.test,v 1.25 2004/11/23 15:41:17 danielk1977 Exp $
+# $Id: auth.test,v 1.26 2005/01/24 10:26:00 danielk1977 Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -25,6 +25,14 @@
   return
 }
 
+rename proc proc_real
+proc_real proc {name arguments script} {
+  proc_real $name $arguments $script
+  if {$name=="auth"} {
+    db authorizer ::auth
+  }
+}
+
 do_test auth-1.1.1 {
   db close
   set ::DB [sqlite3 db test.db]
@@ -2108,4 +2116,7 @@
 
 } ;# ifcapable view && trigger
 
+rename proc {}
+rename proc_real proc
+
 finish_test
diff --git a/test/autovacuum.test b/test/autovacuum.test
index 0b35306..ee6239f 100644
--- a/test/autovacuum.test
+++ b/test/autovacuum.test
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the SELECT statement.
 #
-# $Id: autovacuum.test,v 1.15 2005/01/21 03:12:16 danielk1977 Exp $
+# $Id: autovacuum.test,v 1.16 2005/01/24 10:26:00 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -337,9 +337,9 @@
   execsql {
     SELECT name, rootpage FROM sqlite_master;
   }
-} [list av1 4  sqlite_autoindex_av1_1 3 \
-        av2 6  sqlite_autoindex_av2_1 5 av2_i1 7 av2_i2 8 \
-        av3 10 sqlite_autoindex_av3_1 9 av3_i1 11 \
+} [list av1 3  sqlite_autoindex_av1_1 4 \
+        av2 5  sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \
+        av3 9 sqlite_autoindex_av3_1 10 av3_i1 11 \
         av4 12 av4_i1 13 av4_i2 14 av4_i3 15 av4_i4 16 \
 ]
 
@@ -378,21 +378,21 @@
     DROP TABLE av3;
     SELECT name, rootpage FROM sqlite_master;
   }
-} [list av1 4  sqlite_autoindex_av1_1 3 \
-        av2 6  sqlite_autoindex_av2_1 5 av2_i1 7 av2_i2 8 \
+} [list av1 3  sqlite_autoindex_av1_1 4 \
+        av2 5  sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \
         av4 12 av4_i1 13 av4_i2 9 av4_i3 10 av4_i4 11 \
 ]
-do_test autovacuum-2.5.2.1 {
+do_test autovacuum-2.5.3.1 {
   execsql {
     SELECT * FROM av1 WHERE a = 'av1 a';
   }
 } {{av1 a} {av1 b} {av1 c}}
-do_test autovacuum-2.5.2.2 {
+do_test autovacuum-2.5.3.2 {
   execsql {
     SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'
   }
 } {{av2 a} {av2 b} {av2 c}}
-do_test autovacuum-2.5.2.4 {
+do_test autovacuum-2.5.3.3 {
   execsql {
     SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c';
   }
@@ -406,15 +406,15 @@
     DROP TABLE av1;
     SELECT name, rootpage FROM sqlite_master;
   }
-} [list av2 6  sqlite_autoindex_av2_1 5 av2_i1 7 av2_i2 8 \
+} [list av2 5  sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \
         av4 3 av4_i1 4 av4_i2 9 av4_i3 10 av4_i4 11 \
 ]
-do_test autovacuum-2.5.2.2 {
+do_test autovacuum-2.5.4.2 {
   execsql {
     SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'
   }
 } {{av2 a} {av2 b} {av2 c}}
-do_test autovacuum-2.5.2.4 {
+do_test autovacuum-2.5.4.4 {
   execsql {
     SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c';
   }
@@ -426,13 +426,13 @@
 # Step 3: Delete av4_i2.
 # Step 4: Delete av4_i1. av2_i2 replaces it.
 # Step 5: Delete av4. av2_i1 replaces it.
-do_test autovacuum-2.5.4 {
+do_test autovacuum-2.5.5 {
   execsql {
     DROP TABLE av4;
     SELECT name, rootpage FROM sqlite_master;
   }
-} [list av2 6 sqlite_autoindex_av2_1 5 av2_i1 3 av2_i2 4]
-do_test autovacuum-2.5.2.2 {
+} [list av2 5 sqlite_autoindex_av2_1 6 av2_i1 3 av2_i2 4]
+do_test autovacuum-2.5.5.2 {
   execsql {
     SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c'
   }
diff --git a/test/capi3.test b/test/capi3.test
index 2e551d4..8c19053 100644
--- a/test/capi3.test
+++ b/test/capi3.test
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script testing the callback-free C/C++ API.
 #
-# $Id: capi3.test,v 1.28 2005/01/22 03:03:55 drh Exp $
+# $Id: capi3.test,v 1.29 2005/01/24 10:26:00 danielk1977 Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -430,13 +430,6 @@
 do_test capi3-5.2 {
   sqlite3_step $STMT
 } SQLITE_ROW
-do_test capi3-5.2.1 {
-  sqlite3_expired $STMT
-} {0}
-do_test capi3-5.2.2 {
-  db auth {}
-  sqlite3_expired $STMT
-} {1}
 
 check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}
 check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
diff --git a/test/misuse.test b/test/misuse.test
index e7cc082..8d96af6 100644
--- a/test/misuse.test
+++ b/test/misuse.test
@@ -13,7 +13,7 @@
 # This file implements tests for the SQLITE_MISUSE detection logic.
 # This test file leaks memory and file descriptors.
 #
-# $Id: misuse.test,v 1.9 2005/01/16 09:06:34 danielk1977 Exp $
+# $Id: misuse.test,v 1.10 2005/01/24 10:26:00 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -172,6 +172,9 @@
   lappend v $msg $r
 } {0 {} SQLITE_BUSY}
 do_test misuse-4.4 {
+  # Flush the TCL statement cache here, otherwise the sqlite3_close() will
+  # fail because there are still un-finalized() VDBEs.
+  db cache flush
   sqlite3_close $::DB
   catchsql2 {SELECT * FROM t1}
 } {1 {library routine called out of sequence}}
diff --git a/test/schema.test b/test/schema.test
new file mode 100644
index 0000000..67bf137
--- /dev/null
+++ b/test/schema.test
@@ -0,0 +1,133 @@
+# 2004 Jun 27
+#
+# 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.
+#
+# This file tests the various conditions under which an SQLITE_SCHEMA
+# error should be returned.
+#
+# $Id: schema.test,v 1.1 2005/01/24 10:26:00 danielk1977 Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# schema-1.1: Test that if a table is dropped by one database connection, 
+#             other database connections are aware of the schema change.
+# schema-1.2: Test that if a view is dropped by one database connection,
+#             other database connections are aware of the schema change.
+#
+do_test schema-1.1 {
+  execsql {
+    CREATE TABLE abc(a, b, c);
+  }
+  sqlite3 db2 test.db
+  execsql {
+    DROP TABLE abc;
+  } db2
+  catchsql {
+    SELECT * FROM abc;
+  }
+} {1 {no such table: abc}}
+do_test schema-1.2 {
+  execsql {
+    CREATE TABLE abc(a, b, c);
+    CREATE VIEW abcview AS SELECT * FROM abc;
+  }
+  sqlite3 db2 test.db
+  execsql {
+    DROP VIEW abcview;
+  } db2
+  db2 close
+  catchsql {
+    SELECT * FROM abcview;
+  }
+} {1 {no such table: abcview}}
+
+# Tests 2.1 to 2.4 check that prepared statements are invalidated when
+# a collation sequence is deleted (but not when one is added).
+#
+do_test schema-2.1 {
+  set sql {SELECT * FROM abc;}
+  set ::STMT [sqlite3_prepare $::DB $sql -1 TAIL]
+  add_test_collate $::DB 1 1 1
+  sqlite3_step $::STMT
+} {SQLITE_DONE}
+do_test schema-2.2 {
+  sqlite3_reset $::STMT
+} {SQLITE_OK}
+do_test schema-2.3 {
+  add_test_collate $::DB 0 0 0 
+  sqlite3_step $::STMT
+} {SQLITE_ERROR}
+do_test schema-2.4 {
+  sqlite3_finalize $::STMT
+} {SQLITE_SCHEMA}
+
+# Tests 3.1 to 3.4 check that prepared statements are invalidated when
+# a database is DETACHed (but not when one is ATTACHed).
+#
+do_test schema-3.1 {
+  set sql {SELECT * FROM abc;}
+  set ::STMT [sqlite3_prepare $::DB $sql -1 TAIL]
+  execsql {
+    ATTACH 'test2.db' AS aux;
+  }
+  sqlite3_step $::STMT
+} {SQLITE_DONE}
+do_test schema-3.2 {
+  sqlite3_reset $::STMT
+} {SQLITE_OK}
+do_test schema-3.3 {
+  execsql {
+    DETACH aux;
+  }
+  sqlite3_step $::STMT
+} {SQLITE_ERROR}
+do_test schema-3.4 {
+  sqlite3_finalize $::STMT
+} {SQLITE_SCHEMA}
+
+
+# Test that if a CREATE TABLE statement fails because there are other
+# btree cursors open on the same database file it does not corrupt
+# the sqlite_master table.
+#
+do_test schema-4.1 {
+  execsql {
+    INSERT INTO abc VALUES(1, 2, 3);
+  }
+  set sql {SELECT * FROM abc}
+  set ::STMT [sqlite3_prepare $::DB $sql -1 TAIL]
+  sqlite3_step $::STMT
+} {SQLITE_ROW}
+do_test schema-4.2 {
+  catchsql {
+    CREATE TABLE t2(a, b, c);
+  }
+} {1 {database table is locked}}
+do_test schema-4.3 {
+  sqlite3_finalize $::STMT
+} {SQLITE_OK}
+do_test schema-4.4 {
+  sqlite3 db2 test.db
+  execsql {
+    SELECT * FROM abc
+  } db2
+} {1 2 3}
+do_test schema-4.5 {
+  db2 close
+} {}
+
+finish_test
+
+
+
+
+
diff --git a/test/table.test b/test/table.test
index bc868e0..a527964 100644
--- a/test/table.test
+++ b/test/table.test
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the CREATE TABLE statement.
 #
-# $Id: table.test,v 1.37 2005/01/22 03:39:39 danielk1977 Exp $
+# $Id: table.test,v 1.38 2005/01/24 10:26:00 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -574,6 +574,9 @@
 # a table for which there is an open cursor.
 #
 
+# db eval {
+#   pragma vdbe_trace = 0;
+# }
 # Try to create a table from within a callback:
 unset -nocomplain result
 do_test table-14.1 {
@@ -654,3 +657,4 @@
 } {}
 
 finish_test
+
diff --git a/test/tester.tcl b/test/tester.tcl
index 2defff8..c99c341 100644
--- a/test/tester.tcl
+++ b/test/tester.tcl
@@ -11,7 +11,7 @@
 # This file implements some common TCL routines used for regression
 # testing the SQLite library
 #
-# $Id: tester.tcl,v 1.46 2005/01/22 03:39:39 danielk1977 Exp $
+# $Id: tester.tcl,v 1.47 2005/01/24 10:26:00 danielk1977 Exp $
 
 # Make sure tclsqlite3 was compiled correctly.  Abort now with an
 # error message if not.
@@ -60,7 +60,7 @@
 catch {db close}
 file delete -force test.db
 file delete -force test.db-journal
-sqlite3 db ./test.db
+set ::DB [sqlite3 db ./test.db]
 if {[info exists ::SETUP_SQL]} {
   db eval $::SETUP_SQL
 }