Fix more problems with deferred execution of CREATE. Still need to do DROP.

There is now a memory leak. (CVS 1865)

FossilOrigin-Name: 6db3f122aad25b5226670ce682b7263d55c0d301
This commit is contained in:
drh
2004-07-24 14:35:58 +00:00
parent 234c39dff7
commit 3f7d4e49d8
11 changed files with 81 additions and 45 deletions
+7 -10
View 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);
}
+2 -2
View 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 ){
+2 -1
View 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 */
+2 -7
View 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];
+3 -2
View 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;
}
}
+21 -3
View 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;
+1
View 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*);
+19 -2
View 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