diff options
author | danielk1977 <danielk1977@noemail.net> | 2006-01-06 06:33:12 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2006-01-06 06:33:12 +0000 |
commit | de0fe3e4c3b05a8ee4db376d84d44d949474fcb6 (patch) | |
tree | 950fc714be81d0e40f820b30bbe9b0e72c4bd41a /src/main.c | |
parent | e19d594067ca72fe924b4cb10ff4e664b383c7f5 (diff) | |
download | sqlite-de0fe3e4c3b05a8ee4db376d84d44d949474fcb6.tar.gz sqlite-de0fe3e4c3b05a8ee4db376d84d44d949474fcb6.zip |
Fix a bug that was emptying shared-schema tables during an ATTACH. (CVS 2867)
FossilOrigin-Name: 752a2754879becc32da9f9b910f3330f8c7145e4
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c index ebf2a3480..6f4a2c07b 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.315 2006/01/05 13:48:29 danielk1977 Exp $ +** $Id: main.c,v 1.316 2006/01/06 06:33:13 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -96,10 +96,34 @@ int sqlite3_total_changes(sqlite3 *db){ } /* -** Free a schema structure. +** Free all resources held by the schema structure. The void* argument points +** at a DbSchema struct. This function does not call sqliteFree() on the +** pointer itself, it just cleans up subsiduary resources (i.e. the contents +** of the schema hash tables). */ void sqlite3SchemaFree(void *p){ - sqliteFree(p); + Hash temp1; + Hash temp2; + HashElem *pElem; + DbSchema *pSchema = (DbSchema *)p; + + temp1 = pSchema->tblHash; + temp2 = pSchema->trigHash; + sqlite3HashInit(&pSchema->trigHash, SQLITE_HASH_STRING, 0); + sqlite3HashClear(&pSchema->aFKey); + sqlite3HashClear(&pSchema->idxHash); + for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){ + sqlite3DeleteTrigger((Trigger*)sqliteHashData(pElem)); + } + sqlite3HashClear(&temp2); + sqlite3HashInit(&pSchema->tblHash, SQLITE_HASH_STRING, 0); + for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){ + Table *pTab = sqliteHashData(pElem); + sqlite3DeleteTable(0, pTab); + } + sqlite3HashClear(&temp1); + pSchema->pSeqTab = 0; + pSchema->flags &= ~DB_SchemaLoaded; } DbSchema *sqlite3SchemaGet(Btree *pBt){ @@ -109,7 +133,7 @@ DbSchema *sqlite3SchemaGet(Btree *pBt){ }else{ p = (DbSchema *)sqliteMalloc(sizeof(DbSchema)); } - if( p ){ + if( p && 0==p->file_format ){ sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0); sqlite3HashInit(&p->idxHash, SQLITE_HASH_STRING, 0); sqlite3HashInit(&p->trigHash, SQLITE_HASH_STRING, 0); |