]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix more problems with deferred execution of CREATE. Still need to do DROP.
authordrh <drh@noemail.net>
Sat, 24 Jul 2004 14:35:58 +0000 (14:35 +0000)
committerdrh <drh@noemail.net>
Sat, 24 Jul 2004 14:35:58 +0000 (14:35 +0000)
There is now a memory leak. (CVS 1865)

FossilOrigin-Name: 6db3f122aad25b5226670ce682b7263d55c0d301

manifest
manifest.uuid
src/build.c
src/main.c
src/sqliteInt.h
src/tokenize.c
src/vacuum.c
src/vdbe.c
src/vdbeInt.h
src/vdbeaux.c
test/misc4.test

index dc739a98264f261011083809245ae148664d5414..bda594b98f2204ba5022bc84e2947711c3609a3c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Progress\stowards\sgetting\sprepared\sstatements\sand\sCREATE\sand\sDROP\sto\splay\nnicely\stogether.\s\sWork\sis\sincomplete.\s\sSome\stests\sare\sknown\sto\sfail.\s(CVS\s1864)
-D 2004-07-24T03:30:48
+C Fix\smore\sproblems\swith\sdeferred\sexecution\sof\sCREATE.\s\sStill\sneed\sto\sdo\sDROP.\nThere\sis\snow\sa\smemory\sleak.\s(CVS\s1865)
+D 2004-07-24T14:35:58
 F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -29,7 +29,7 @@ F src/attach.c 784456629b3d7e50e4691f496700658fd1f16441
 F src/auth.c 60db23b98bb94c8b0178180faaf49dc116674217
 F src/btree.c edf4ece708350dec7f28ebd4620c6d33afe6993a
 F src/btree.h 94dfec0a1722d33359b23e7e310f2b64ffedf029
-F src/build.c d1870caf93cce22e6991116e39cf5c05c73882ee
+F src/build.c 3075ca2e66d6da3f98840d18f6e2bc4d15ced569
 F src/date.c e1bb384a7856c18dce9cadb0afbe6934ba5ddb00
 F src/delete.c e81545e546f6bc87d7508a93a09ca70695265af3
 F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
@@ -39,7 +39,7 @@ F src/hash.c f0a2f22c2a7052d67053b5f4690ea3010bb3fb9f
 F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
 F src/insert.c d99ffe87e1e1397f4233afcd06841d52d6b17b18
 F src/legacy.c ad23746f15f67e34577621b1875f639c94839e1f
-F src/main.c c4ba7d8f674d7c880e2e0deea16432d63defa5b2
+F src/main.c 49ea4a45223a002d06b5a4a5db36327acafc1779
 F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
 F src/os.h d1780e0db95cad01f213d48da22ab490eb4fd345
 F src/os_common.h fe9604754116bd2f2702d58f82d2d8b89998cb21
@@ -60,7 +60,7 @@ F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
 F src/select.c aefda626660086addca4ce85c34aeef5d0f44c25
 F src/shell.c 93c96c847228c02fb84bb381875d87ee71fbbeb4
 F src/sqlite.h.in 80de11cde2c9f78eff4dab0aad1eb5196d6e2a3f
-F src/sqliteInt.h 8cf9cf4bd02dacedbf3738ecfad49ea32e599e47
+F src/sqliteInt.h 31d5887a802b5f218f604a1fd44fe989873cf2bc
 F src/table.c 4521c278892f60e4d630788c0ea5cf4db1e75c49
 F src/tclsqlite.c 3ce001b3c301876a9c8163472077a4c10e0d49f3
 F src/test1.c ef00096c283ccfec1b2ae5fdaccb85fb06e24281
@@ -68,17 +68,17 @@ F src/test2.c f4c2f3928f1998fd8cb75a81e33a60e025ea85d4
 F src/test3.c 94d0a2a90bccd85802488cb42c69ec8afd2e4646
 F src/test4.c a921a69821fd30209589228e64f94e9f715b6fe2
 F src/test5.c b001fa7f1b9e2dc5c2331de62fc641b5ab2bd7a1
-F src/tokenize.c 368c1c6eb11355188fc4423e77c1708856b16c9b
+F src/tokenize.c bc7a80e4cf54f42ea4b030c62261c4243133af84
 F src/trigger.c 6aaf6d79cc2157c70a06031dd1531707d644cfb4
 F src/update.c b66b1896c9da54678ba3eff2bf0b4d291a95986a
 F src/utf.c f03535db72bfa09e24202ccdd245f21d2fc65f0a
 F src/util.c 2aacc79b7bf5df5859813dafd3bf3258f67a5234
-F src/vacuum.c b8546f4921719458cc537b9e736df52a8256399c
-F src/vdbe.c 5d35f08682878165bfba796b298fe3615ae9c9fc
+F src/vacuum.c 23ec8c5f3134c6315f883d648fa63b72d8c3ead3
+F src/vdbe.c cad659a06b30c03b870c4a00a828d78f7a69bbcf
 F src/vdbe.h 75b241c02431b9c0f16eaa9cdbb34146c6287f52
-F src/vdbeInt.h 7160653a006b6d2c4a00d204112a095bdf842ab6
+F src/vdbeInt.h 3d8e08c54dcb5ca2169db8bb3a37b81a12efaecd
 F src/vdbeapi.c c5c6d8f162a9581dde497b1a4034f9a0bf54c355
-F src/vdbeaux.c 4de85e30ca4a83ea0a45eceb7e88ac7a48f4c237
+F src/vdbeaux.c daf40a292ec458ed962845a8d95d5c96bc242e04
 F src/vdbemem.c bbf621377343bee046547712a144a94f387bb1eb
 F src/where.c cf8a54641eea01f1af5d09529ad69166db92f658
 F test/all.test 3b692eb43583b52c99c344b2fa8934512d179016
@@ -140,7 +140,7 @@ F test/minmax.test 6513f9a1bb85fd35ff72b34b7b6634fad6b1e69c
 F test/misc1.test 72768ec8cabc952a4cfcddca43d566f9e0bce899
 F test/misc2.test 703734f5817215ca54e364833b3bf5ff36fcc21e
 F test/misc3.test eb488314990bfc0959221a1acc465013238bf168
-F test/misc4.test e941a0918df0bf3ab42563e35970d98288ddddf7
+F test/misc4.test b31a0a08077038b03a9320fd5d9731093da708a8
 F test/misuse.test 2a64ce711419f2fd12806ed95af930fd4e7bb8f3
 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
 F test/null.test c14d0f4739f21e929b8115b72bf0c765b6bb1721
@@ -240,7 +240,7 @@ F www/tclsqlite.tcl 06a86cba4d7fc88e2bcd633b57702d3d16abebb5
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 7c7f698b2eda7b1b34f5ca7fe104145d8bbd8f56
-R b1b16f99b3da9325a0228f34d4f42233
+P 49b991492496e104f5eca620a5d465a742b7ff3a
+R 360d271fab96b9095f5b4369737eb03f
 U drh
-Z b40eb69ee75bee6f41ad47e71f93841a
+Z e2b908232fc8aa315ba06b1f36120ee8
index 8574843cd928680de4c211ac88050dec85e93e38..32b7dfe7ebe9db138bff6e206babbabfd3779108 100644 (file)
@@ -1 +1 @@
-49b991492496e104f5eca620a5d465a742b7ff3a
\ No newline at end of file
+6db3f122aad25b5226670ce682b7263d55c0d301
\ No newline at end of file
index 09427a9c3f168ec6f548344ec973eafcde8eb673..4494c43a0d25338e4579f7e6bfce68c0e75e6116 100644 (file)
@@ -23,7 +23,7 @@
 **     ROLLBACK
 **     PRAGMA
 **
-** $Id: build.c,v 1.241 2004/07/24 03:30:48 drh Exp $
+** $Id: build.c,v 1.242 2004/07/24 14:35:58 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -82,6 +82,10 @@ void sqlite3FinishCoding(Parse *pParse){
     }
   }
 
+#ifndef NDEBUG
+  sqlite3VdbeOp3(v, OP_Noop, 0, 0, pParse->zSql, pParse->zTail - pParse->zSql);
+#endif
+
   /* Get the VDBE program ready for execution
   */
   if( v && pParse->nErr==0 ){
@@ -1138,8 +1142,7 @@ char sqlite3AffinityType(const char *zType, int nType){
 }
 
 /*
-** Come up with a new random value for the schema cookie.  Make sure
-** the new value is different from the old.
+** Generate code that will increment the schema cookie.
 **
 ** The schema cookie is used to determine when the schema for the
 ** database changes.  After each schema change, the cookie value
@@ -1155,13 +1158,7 @@ char sqlite3AffinityType(const char *zType, int nType){
 ** 1 chance in 2^32.  So we're safe enough.
 */
 void sqlite3ChangeCookie(sqlite *db, Vdbe *v, int iDb){
-  unsigned char r;
-  int *pSchemaCookie = &(db->aDb[iDb].schema_cookie);
-
-  sqlite3Randomness(1, &r);
-  *pSchemaCookie = *pSchemaCookie + r + 1;
-  db->flags |= SQLITE_InternChanges;
-  sqlite3VdbeAddOp(v, OP_Integer, *pSchemaCookie, 0);
+  sqlite3VdbeAddOp(v, OP_Integer, db->aDb[iDb].schema_cookie+1, 0);
   sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 0);
 }
 
index f6cce31c69df55d03a736be3cd7517b408112677..2bb38862b63c5cadcdf26303fd4e90767ca1c82a 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.247 2004/07/24 03:30:48 drh Exp $
+** $Id: main.c,v 1.248 2004/07/24 14:35:58 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -1025,7 +1025,7 @@ int sqlite3_prepare(
     goto prepare_out;
   }
   if( sParse.rc==SQLITE_DONE ) sParse.rc = SQLITE_OK;
-  if( sParse.checkSchema && !schemaIsValid(db) ){
+  if( sParse.rc!=SQLITE_OK && sParse.checkSchema && !schemaIsValid(db) ){
     sParse.rc = SQLITE_SCHEMA;
   }
   if( sParse.rc==SQLITE_SCHEMA ){
index cdab05c9a33a565ad12e74089a0d3da5bf08c8a0..94656ab414e3fcfec52673db1b0a42578941aa6f 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.309 2004/07/24 03:30:48 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.310 2004/07/24 14:35:58 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -983,6 +983,7 @@ struct Parse {
   Token sErrToken;     /* The token at which the error occurred */
   Token sNameToken;    /* Token with unqualified schema object name */
   Token sLastToken;    /* The last token parsed */
+  const char *zSql;    /* All SQL text */
   const char *zTail;   /* All SQL text past the last semicolon parsed */
   Table *pNewTable;    /* A table being constructed by CREATE TABLE */
   Vdbe *pVdbe;         /* An engine for executing database bytecode */
index dde809146c4d88bdf8365d9a68764a12b3e31d1b..97216215d0d983b6cdebb32747f2c7e637d24c0a 100644 (file)
@@ -15,7 +15,7 @@
 ** individual tokens and sends those tokens one-by-one over to the
 ** parser for analysis.
 **
-** $Id: tokenize.c,v 1.79 2004/07/24 03:30:48 drh Exp $
+** $Id: tokenize.c,v 1.80 2004/07/24 14:35:59 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -431,13 +431,8 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
     sqlite3SetString(pzErrMsg, "out of memory", (char*)0);
     return 1;
   }
-#ifndef NDEBUG
-  if( sqlite3OsFileExists("vdbe_sqltrace") ){
-    printf("SQL To Compiler: [%s]\n", zSql);
-  }
-#endif
   pParse->sLastToken.dyn = 0;
-  pParse->zTail = zSql;
+  pParse->zTail = pParse->zSql = zSql;
   while( sqlite3_malloc_failed==0 && zSql[i]!=0 ){
     assert( i>=0 );
     pParse->sLastToken.z = &zSql[i];
index 79783d655db57c30ef9a6cf7d938f924ef210bf3..c1a35051eae8173d81c2738951db2fb329041f17 100644 (file)
@@ -14,7 +14,7 @@
 ** Most of the code in this file may be omitted by defining the
 ** SQLITE_OMIT_VACUUM macro.
 **
-** $Id: vacuum.c,v 1.26 2004/06/30 09:49:24 danielk1977 Exp $
+** $Id: vacuum.c,v 1.27 2004/07/24 14:35:59 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -247,6 +247,7 @@ end_of_vacuum:
     sqliteFree(zTemp);
   }
   if( zSql ) sqliteFree( zSql );
+  sqlite3ResetInternalSchema(db, 0);
 #endif
   return rc;
-} 
+}
index 12e0978b3cb0a8efc3150259c81500155a23b4d0..390576d63965932614f581f3b45f0d6982c65835 100644 (file)
@@ -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.404 2004/07/24 03:30:48 drh Exp $
+** $Id: vdbe.c,v 1.405 2004/07/24 14:35:59 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -508,9 +508,19 @@ int sqlite3VdbeExec(
     */
 #ifndef NDEBUG
     if( p->trace ){
+      if( pc==0 ){
+        printf("VDBE Execution Trace:\n");
+        sqlite3VdbePrintSql(p);
+      }
       sqlite3VdbePrintOp(p->trace, pc, pOp);
     }
 #endif
+#ifdef SQLITE_TEST
+    if( p->trace==0 && pc==0 && sqlite3OsFileExists("vdbe_sqltrace") ){
+      sqlite3VdbePrintSql(p);
+    }
+#endif
+      
 
     /* Check to see if we need to simulate an interrupt.  This only happens
     ** if we have a special test build.
@@ -2283,13 +2293,20 @@ case OP_ReadCookie: {
 ** A transaction must be started before executing this opcode.
 */
 case OP_SetCookie: {
+  Db *pDb;
   assert( pOp->p2<SQLITE_N_BTREE_META );
   assert( pOp->p1>=0 && pOp->p1<db->nDb );
-  assert( db->aDb[pOp->p1].pBt!=0 );
+  pDb = &db->aDb[pOp->p1];
+  assert( pDb->pBt!=0 );
   assert( pTos>=p->aStack );
   Integerify(pTos);
   /* See note about index shifting on OP_ReadCookie */
-  rc = sqlite3BtreeUpdateMeta(db->aDb[pOp->p1].pBt, 1+pOp->p2, (int)pTos->i);
+  rc = sqlite3BtreeUpdateMeta(pDb->pBt, 1+pOp->p2, (int)pTos->i);
+  if( pOp->p2==0 ){
+    /* When the schema cookie changes, record the new cookie internally */
+    pDb->schema_cookie = pTos->i;
+    db->flags |= SQLITE_InternChanges;
+  }
   assert( (pTos->flags & MEM_Dyn)==0 );
   pTos--;
   break;
@@ -3730,6 +3747,7 @@ case OP_ParseSchema: {
   InitData initData;
 
   assert( iDb>=0 && iDb<db->nDb );
+  if( !DbHasProperty(db, iDb, DB_SchemaLoaded) ) break;
   zMaster = iDb==1 ? TEMP_MASTER_NAME : MASTER_NAME;
   initData.db = db;
   initData.pzErrMsg = &p->zErrMsg;
index 5a5a5d34af667d350006fd68a9beb5734d836347..72f528a28b0b8f7afe7668c22f4ace5df7c23a6f 100644 (file)
@@ -367,6 +367,7 @@ int sqlite3VdbeCursorMoveto(Cursor*);
 #if !defined(NDEBUG) || defined(VDBE_PROFILE)
 void sqlite3VdbePrintOp(FILE*, int, Op*);
 #endif
+void sqlite3VdbePrintSql(Vdbe*);
 int sqlite3VdbeSerialTypeLen(u32);
 u32 sqlite3VdbeSerialType(Mem*);
 int sqlite3VdbeSerialPut(unsigned char*, Mem*);
index 2e37e917d4175956a0ed86ad51c21538161c887d..fc7681e3834dcf424414f8633731dbf9150dbf9d 100644 (file)
@@ -416,7 +416,7 @@ static char *displayP3(Op *pOp, char *zTemp, int nTemp){
     }
     default: {
       zP3 = pOp->p3;
-      if( zP3==0 ){
+      if( zP3==0 || pOp->opcode==OP_Noop ){
         zP3 = "";
       }
     }
@@ -521,6 +521,23 @@ int sqlite3VdbeList(
   return rc;
 }
 
+/*
+** Print the SQL that was used to generate a VDBE program.
+*/
+void sqlite3VdbePrintSql(Vdbe *p){
+#ifdef SQLITE_DEBUG
+  int nOp = p->nOp;
+  VdbeOp *pOp;
+  if( nOp<2 ) return;
+  pOp = &p->aOp[nOp-2];
+  if( pOp->opcode==OP_Noop && pOp->p3!=0 ){
+    const char *z = pOp->p3;
+    while( isspace(*z) ) z++;
+    printf("SQL: [%s]\n", z);
+  }
+#endif
+}
+
 /*
 ** Prepare a virtual machine for execution.  This involves things such
 ** as allocating stack space and initializing the program counter.
@@ -571,12 +588,12 @@ void sqlite3VdbeMakeReady(
   ){
     int i;
     printf("VDBE Program Listing:\n");
+    sqlite3VdbePrintSql(p);
     for(i=0; i<p->nOp; i++){
       sqlite3VdbePrintOp(stdout, i, &p->aOp[i]);
     }
   }
   if( sqlite3OsFileExists("vdbe_trace") ){
-    printf("VDBE Execution Trace:\n");
     p->trace = stdout;
   }
 #endif
index a8222dac40711a832233244ba1a7fa3e5e936abe..23cd465fb91205b1ead428ac85840375752f9fe7 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for miscellanous features that were
 # left out of other test files.
 #
-# $Id: misc4.test,v 1.4 2004/07/24 03:30:49 drh Exp $
+# $Id: misc4.test,v 1.5 2004/07/24 14:35:59 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -28,6 +28,8 @@ do_test misc4-1.1 {
     CREATE TABLE t1(x);
     INSERT INTO t1 VALUES(1);
   }
+} {}
+do_test misc4-1.2 {
   set sql {CREATE TEMP TABLE t2 AS SELECT * FROM t1}
   set stmt [sqlite3_prepare $DB $sql -1 TAIL]
   execsql {
@@ -36,7 +38,11 @@ do_test misc4-1.1 {
     INSERT INTO t1 SELECT * FROM t1;
     ROLLBACK;
   }
+} {}
+do_test misc4-1.3 {
   sqlite3_step $stmt
+} SQLITE_DONE
+do_test misc4-1.4 {
   execsql {
     SELECT * FROM temp.t2;
   }
@@ -45,12 +51,12 @@ do_test misc4-1.1 {
 # Drop the temporary table, then rerun the prepared  statement to
 # recreate it again.  This recreates ticket #807.
 #
-do_test misc4-1.2 {
+do_test misc4-1.5 {
   execsql {DROP TABLE t2}
   sqlite3_reset $stmt
   sqlite3_step $stmt
 } {SQLITE_ERROR}
-do_test misc4-1.3 {
+do_test misc4-1.6 {
   sqlite3_finalize $stmt
 } {SQLITE_SCHEMA}