aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2006-01-06 06:33:12 +0000
committerdanielk1977 <danielk1977@noemail.net>2006-01-06 06:33:12 +0000
commitde0fe3e4c3b05a8ee4db376d84d44d949474fcb6 (patch)
tree950fc714be81d0e40f820b30bbe9b0e72c4bd41a /src
parente19d594067ca72fe924b4cb10ff4e664b383c7f5 (diff)
downloadsqlite-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')
-rw-r--r--src/btree.c3
-rw-r--r--src/build.c27
-rw-r--r--src/main.c32
-rw-r--r--src/util.c6
4 files changed, 39 insertions, 29 deletions
diff --git a/src/btree.c b/src/btree.c
index 7af9fc4b1..79de82c8d 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
-** $Id: btree.c,v 1.280 2006/01/06 01:42:58 drh Exp $
+** $Id: btree.c,v 1.281 2006/01/06 06:33:12 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -1722,6 +1722,7 @@ int sqlite3BtreeClose(Btree *p){
if( pBt->xFreeSchema && pBt->pSchema ){
pBt->xFreeSchema(pBt->pSchema);
}
+ sqliteFree(pBt->pSchema);
sqliteFree(pBt);
return SQLITE_OK;
}
diff --git a/src/build.c b/src/build.c
index 3170bcf2d..528058a59 100644
--- a/src/build.c
+++ b/src/build.c
@@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
-** $Id: build.c,v 1.367 2006/01/05 11:34:34 danielk1977 Exp $
+** $Id: build.c,v 1.368 2006/01/06 06:33:13 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -258,7 +258,6 @@ static void sqliteDeleteIndex(sqlite3 *db, Index *p){
Index *pOld;
const char *zName = p->zName;
- assert( db!=0 && zName!=0 );
pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName, strlen( zName)+1, 0);
assert( pOld==0 || pOld==p );
freeIndex(p);
@@ -304,9 +303,6 @@ void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
** single file indicated.
*/
void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
- HashElem *pElem;
- Hash temp1;
- Hash temp2;
int i, j;
assert( iDb>=0 && iDb<db->nDb );
@@ -314,23 +310,7 @@ void sqlite3ResetInternalSchema(sqlite3 *db, int iDb){
for(i=iDb; i<db->nDb; i++){
Db *pDb = &db->aDb[i];
if( pDb->pSchema ){
- temp1 = pDb->pSchema->tblHash;
- temp2 = pDb->pSchema->trigHash;
- sqlite3HashInit(&pDb->pSchema->trigHash, SQLITE_HASH_STRING, 0);
- sqlite3HashClear(&pDb->pSchema->aFKey);
- sqlite3HashClear(&pDb->pSchema->idxHash);
- for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
- sqlite3DeleteTrigger((Trigger*)sqliteHashData(pElem));
- }
- sqlite3HashClear(&temp2);
- sqlite3HashInit(&pDb->pSchema->tblHash, SQLITE_HASH_STRING, 0);
- for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
- Table *pTab = sqliteHashData(pElem);
- sqlite3DeleteTable(db, pTab);
- }
- sqlite3HashClear(&temp1);
- pDb->pSchema->pSeqTab = 0;
- DbClearProperty(db, i, DB_SchemaLoaded);
+ sqlite3SchemaFree(pDb->pSchema);
}
if( iDb>0 ) return;
}
@@ -427,6 +407,8 @@ void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
Index *pIndex, *pNext;
FKey *pFKey, *pNextFKey;
+ db = 0;
+
if( pTable==0 ) return;
/* Do not delete the table until the reference count reaches zero. */
@@ -450,7 +432,6 @@ void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
*/
for(pFKey=pTable->pFKey; pFKey; pFKey=pNextFKey){
pNextFKey = pFKey->pNextFrom;
- assert( sqlite3SchemaToIndex(db, pTable->pSchema)<db->nDb );
assert( sqlite3HashFind(&pTable->pSchema->aFKey,
pFKey->zTo, strlen(pFKey->zTo)+1)!=pFKey );
sqliteFree(pFKey);
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);
diff --git a/src/util.c b/src/util.c
index 898d3dedb..82fe9ecf0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -14,7 +14,7 @@
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
-** $Id: util.c,v 1.159 2005/12/29 01:11:37 drh Exp $
+** $Id: util.c,v 1.160 2006/01/06 06:33:13 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -289,6 +289,10 @@ static void applyGuards(u32 *p)
checkGuards(p);
}
+/*
+** The argument is a malloc()ed pointer as returned by the test-wrapper.
+** Return a pointer to the Os level allocation.
+*/
static void *getOsPointer(void *p)
{
char *z = (char *)p;