diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/alter.c | 1 | ||||
-rw-r--r-- | src/analyze.c | 12 | ||||
-rw-r--r-- | src/build.c | 37 | ||||
-rw-r--r-- | src/callback.c | 2 | ||||
-rw-r--r-- | src/delete.c | 2 | ||||
-rw-r--r-- | src/fkey.c | 8 | ||||
-rw-r--r-- | src/select.c | 4 | ||||
-rw-r--r-- | src/sqliteInt.h | 9 | ||||
-rw-r--r-- | src/tokenize.c | 4 | ||||
-rw-r--r-- | src/vtab.c | 8 |
10 files changed, 37 insertions, 50 deletions
diff --git a/src/alter.c b/src/alter.c index 359c4e737..a863c4548 100644 --- a/src/alter.c +++ b/src/alter.c @@ -769,7 +769,6 @@ void sqlite3AlterBeginAddColumn(Parse *pParse, SrcList *pSrc){ if( !pNew ) goto exit_begin_add_column; pParse->pNewTable = pNew; pNew->nRef = 1; - pNew->dbMem = pTab->dbMem; pNew->nCol = pTab->nCol; assert( pNew->nCol>0 ); nAlloc = (((pNew->nCol-1)/8)*8)+8; diff --git a/src/analyze.c b/src/analyze.c index 94cf3a39d..c41fba343 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -494,14 +494,13 @@ void sqlite3DeleteIndexSamples(Index *pIdx){ #ifdef SQLITE_ENABLE_STAT2 if( pIdx->aSample ){ int j; - sqlite3 *dbMem = pIdx->pTable->dbMem; for(j=0; j<SQLITE_INDEX_SAMPLES; j++){ IndexSample *p = &pIdx->aSample[j]; if( p->eType==SQLITE_TEXT || p->eType==SQLITE_BLOB ){ - sqlite3DbFree(pIdx->pTable->dbMem, p->u.z); + sqlite3_free(p->u.z); } } - sqlite3DbFree(dbMem, pIdx->aSample); + sqlite3DbFree(0, pIdx->aSample); pIdx->aSample = 0; } #else @@ -587,18 +586,17 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){ Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase); if( pIdx ){ int iSample = sqlite3_column_int(pStmt, 1); - sqlite3 *dbMem = pIdx->pTable->dbMem; - assert( dbMem==db || dbMem==0 ); if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){ int eType = sqlite3_column_type(pStmt, 2); if( pIdx->aSample==0 ){ static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES; - pIdx->aSample = (IndexSample *)sqlite3DbMallocZero(dbMem, sz); + pIdx->aSample = (IndexSample *)sqlite3Malloc(sz); if( pIdx->aSample==0 ){ db->mallocFailed = 1; break; } + memset(pIdx->aSample, 0, sz); } assert( pIdx->aSample ); @@ -621,7 +619,7 @@ int sqlite3AnalysisLoad(sqlite3 *db, int iDb){ if( n < 1){ pSample->u.z = 0; }else{ - pSample->u.z = sqlite3DbMallocRaw(dbMem, n); + pSample->u.z = sqlite3Malloc(n); if( pSample->u.z ){ memcpy(pSample->u.z, z, n); }else{ diff --git a/src/build.c b/src/build.c index d9641774a..1ca6e2469 100644 --- a/src/build.c +++ b/src/build.c @@ -345,8 +345,7 @@ Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){ /* ** Reclaim the memory used by an index */ -static void freeIndex(Index *p){ - sqlite3 *db = p->pTable->dbMem; +static void freeIndex(sqlite3 *db, Index *p){ #ifndef SQLITE_OMIT_ANALYZE sqlite3DeleteIndexSamples(p); #endif @@ -362,14 +361,14 @@ static void freeIndex(Index *p){ ** it is not unlinked from the Table that it indexes. ** Unlinking from the Table must be done by the calling function. */ -static void sqlite3DeleteIndex(Index *p){ +static void sqlite3DeleteIndex(sqlite3 *db, Index *p){ Index *pOld; const char *zName = p->zName; pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0); assert( pOld==0 || pOld==p ); - freeIndex(p); + freeIndex(db, p); } /* @@ -398,7 +397,7 @@ void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){ p->pNext = pIndex->pNext; } } - freeIndex(pIndex); + freeIndex(db, pIndex); } db->flags |= SQLITE_InternChanges; } @@ -471,11 +470,9 @@ void sqlite3CommitInternalChanges(sqlite3 *db){ /* ** Clear the column names from a table or view. */ -static void sqliteResetColumnNames(Table *pTable){ +static void sqliteResetColumnNames(sqlite3 *db, Table *pTable){ int i; Column *pCol; - sqlite3 *db = pTable->dbMem; - testcase( db==0 ); assert( pTable!=0 ); if( (pCol = pTable->aCol)!=0 ){ for(i=0; i<pTable->nCol; i++, pCol++){ @@ -500,13 +497,10 @@ static void sqliteResetColumnNames(Table *pTable){ ** memory structures of the indices and foreign keys associated with ** the table. */ -void sqlite3DeleteTable(Table *pTable){ +void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ Index *pIndex, *pNext; - sqlite3 *db; if( pTable==0 ) return; - db = pTable->dbMem; - testcase( db==0 ); /* Do not delete the table until the reference count reaches zero. */ pTable->nRef--; @@ -520,22 +514,22 @@ void sqlite3DeleteTable(Table *pTable){ for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){ pNext = pIndex->pNext; assert( pIndex->pSchema==pTable->pSchema ); - sqlite3DeleteIndex(pIndex); + sqlite3DeleteIndex(db, pIndex); } /* Delete any foreign keys attached to this table. */ - sqlite3FkDelete(pTable); + sqlite3FkDelete(db, pTable); /* Delete the Table structure itself. */ - sqliteResetColumnNames(pTable); + sqliteResetColumnNames(db, pTable); sqlite3DbFree(db, pTable->zName); sqlite3DbFree(db, pTable->zColAff); sqlite3SelectDelete(db, pTable->pSelect); #ifndef SQLITE_OMIT_CHECK sqlite3ExprDelete(db, pTable->pCheck); #endif - sqlite3VtabClear(pTable); + sqlite3VtabClear(db, pTable); sqlite3DbFree(db, pTable); } @@ -554,7 +548,7 @@ void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){ pDb = &db->aDb[iDb]; p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, sqlite3Strlen30(zTabName),0); - sqlite3DeleteTable(p); + sqlite3DeleteTable(db, p); db->flags |= SQLITE_InternChanges; } @@ -822,7 +816,6 @@ void sqlite3StartTable( pTable->iPKey = -1; pTable->pSchema = db->aDb[iDb].pSchema; pTable->nRef = 1; - pTable->dbMem = 0; assert( pParse->pNewTable==0 ); pParse->pNewTable = pTable; @@ -1555,7 +1548,7 @@ void sqlite3EndTable( p->aCol = pSelTab->aCol; pSelTab->nCol = 0; pSelTab->aCol = 0; - sqlite3DeleteTable(pSelTab); + sqlite3DeleteTable(db, pSelTab); } } @@ -1799,7 +1792,7 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ pTable->aCol = pSelTab->aCol; pSelTab->nCol = 0; pSelTab->aCol = 0; - sqlite3DeleteTable(pSelTab); + sqlite3DeleteTable(db, pSelTab); pTable->pSchema->flags |= DB_UnresetViews; }else{ pTable->nCol = 0; @@ -1824,7 +1817,7 @@ static void sqliteViewResetAll(sqlite3 *db, int idx){ for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){ Table *pTab = sqliteHashData(i); if( pTab->pSelect ){ - sqliteResetColumnNames(pTab); + sqliteResetColumnNames(db, pTab); } } DbClearProperty(db, idx, DB_UnresetViews); @@ -3200,7 +3193,7 @@ void sqlite3SrcListDelete(sqlite3 *db, SrcList *pList){ sqlite3DbFree(db, pItem->zName); sqlite3DbFree(db, pItem->zAlias); sqlite3DbFree(db, pItem->zIndex); - sqlite3DeleteTable(pItem->pTab); + sqlite3DeleteTable(db, pItem->pTab); sqlite3SelectDelete(db, pItem->pSelect); sqlite3ExprDelete(db, pItem->pOn); sqlite3IdListDelete(db, pItem->pUsing); diff --git a/src/callback.c b/src/callback.c index c016959fd..01b292b38 100644 --- a/src/callback.c +++ b/src/callback.c @@ -423,7 +423,7 @@ void sqlite3SchemaFree(void *p){ for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){ Table *pTab = sqliteHashData(pElem); assert( pTab->dbMem==0 ); - sqlite3DeleteTable(pTab); + sqlite3DeleteTable(0, pTab); } sqlite3HashClear(&temp1); sqlite3HashClear(&pSchema->fkeyHash); diff --git a/src/delete.c b/src/delete.c index 9608dc2f5..bd7ac3d1f 100644 --- a/src/delete.c +++ b/src/delete.c @@ -24,7 +24,7 @@ Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){ Table *pTab; assert( pItem && pSrc->nSrc==1 ); pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase); - sqlite3DeleteTable(pItem->pTab); + sqlite3DeleteTable(pParse->db, pItem->pTab); pItem->pTab = pTab; if( pTab ){ pTab->nRef++; diff --git a/src/fkey.c b/src/fkey.c index e6f4bfc05..ea71f49aa 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -1155,7 +1155,7 @@ void sqlite3FkActions( ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash ** hash table. */ -void sqlite3FkDelete(Table *pTab){ +void sqlite3FkDelete(sqlite3 *db, Table *pTab){ FKey *pFKey; /* Iterator variable */ FKey *pNext; /* Copy of pFKey->pNextFrom */ @@ -1175,8 +1175,8 @@ void sqlite3FkDelete(Table *pTab){ /* Delete any triggers created to implement actions for this FK. */ #ifndef SQLITE_OMIT_TRIGGER - fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[0]); - fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[1]); + fkTriggerDelete(db, pFKey->apTrigger[0]); + fkTriggerDelete(db, pFKey->apTrigger[1]); #endif /* EV: R-30323-21917 Each foreign key constraint in SQLite is @@ -1185,7 +1185,7 @@ void sqlite3FkDelete(Table *pTab){ assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 ); pNext = pFKey->pNextFrom; - sqlite3DbFree(pTab->dbMem, pFKey); + sqlite3DbFree(db, pFKey); } } #endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */ diff --git a/src/select.c b/src/select.c index b03e50638..3008276a7 100644 --- a/src/select.c +++ b/src/select.c @@ -1300,14 +1300,13 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){ /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside ** is disabled, so we might as well hard-code pTab->dbMem to NULL. */ assert( db->lookaside.bEnabled==0 ); - pTab->dbMem = 0; pTab->nRef = 1; pTab->zName = 0; selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol); selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect); pTab->iPKey = -1; if( db->mallocFailed ){ - sqlite3DeleteTable(pTab); + sqlite3DeleteTable(db, pTab); return 0; } return pTab; @@ -3096,7 +3095,6 @@ static int selectExpander(Walker *pWalker, Select *p){ sqlite3WalkSelect(pWalker, pSel); pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table)); if( pTab==0 ) return WRC_Abort; - pTab->dbMem = db->lookaside.bEnabled ? db : 0; pTab->nRef = 1; pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab); while( pSel->pPrior ){ pSel = pSel->pPrior; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 3060f0748..a9a0885c1 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1217,7 +1217,6 @@ struct VTable { ** of a SELECT statement. */ struct Table { - sqlite3 *dbMem; /* DB connection used for lookaside allocations. */ char *zName; /* Name of the table or view */ int iPKey; /* If not negative, use aCol[iPKey] as the primary key */ int nCol; /* Number of columns in this table */ @@ -2624,7 +2623,7 @@ void sqlite3CreateView(Parse*,Token*,Token*,Token*,Select*,int,int); #endif void sqlite3DropTable(Parse*, SrcList*, int, int); -void sqlite3DeleteTable(Table*); +void sqlite3DeleteTable(sqlite3*, Table*); #ifndef SQLITE_OMIT_AUTOINCREMENT void sqlite3AutoincrementBegin(Parse *pParse); void sqlite3AutoincrementEnd(Parse *pParse); @@ -2971,7 +2970,7 @@ void sqlite3AutoLoadExtensions(sqlite3*); # define sqlite3VtabUnlock(X) # define sqlite3VtabUnlockList(X) #else - void sqlite3VtabClear(Table*); + void sqlite3VtabClear(sqlite3 *db, Table*); int sqlite3VtabSync(sqlite3 *db, char **); int sqlite3VtabRollback(sqlite3 *db); int sqlite3VtabCommit(sqlite3 *db); @@ -3024,9 +3023,9 @@ int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int); #define sqlite3FkRequired(a,b,c,d) 0 #endif #ifndef SQLITE_OMIT_FOREIGN_KEY - void sqlite3FkDelete(Table*); + void sqlite3FkDelete(sqlite3 *, Table*); #else - #define sqlite3FkDelete(a) + #define sqlite3FkDelete(a,b) #endif diff --git a/src/tokenize.c b/src/tokenize.c index 4b40770d5..e8778e69a 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -504,7 +504,7 @@ abort_parse: ** structure built up in pParse->pNewTable. The calling code (see vtab.c) ** will take responsibility for freeing the Table structure. */ - sqlite3DeleteTable(pParse->pNewTable); + sqlite3DeleteTable(db, pParse->pNewTable); } sqlite3DeleteTrigger(db, pParse->pNewTrigger); @@ -518,7 +518,7 @@ abort_parse: while( pParse->pZombieTab ){ Table *p = pParse->pZombieTab; pParse->pZombieTab = p->pNextZombie; - sqlite3DeleteTable(p); + sqlite3DeleteTable(db, p); } if( nErr>0 && pParse->rc==SQLITE_OK ){ pParse->rc = SQLITE_ERROR; diff --git a/src/vtab.c b/src/vtab.c index d23846024..5bf867604 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -221,14 +221,14 @@ void sqlite3VtabUnlockList(sqlite3 *db){ ** in the list are moved to the sqlite3.pDisconnect list of the associated ** database connection. */ -void sqlite3VtabClear(Table *p){ +void sqlite3VtabClear(sqlite3 *db, Table *p){ vtabDisconnectAll(0, p); if( p->azModuleArg ){ int i; for(i=0; i<p->nModuleArg; i++){ - sqlite3DbFree(p->dbMem, p->azModuleArg[i]); + sqlite3DbFree(db, p->azModuleArg[i]); } - sqlite3DbFree(p->dbMem, p->azModuleArg); + sqlite3DbFree(db, p->azModuleArg); } } @@ -681,7 +681,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ if( pParse->pVdbe ){ sqlite3VdbeFinalize(pParse->pVdbe); } - sqlite3DeleteTable(pParse->pNewTable); + sqlite3DeleteTable(db, pParse->pNewTable); sqlite3StackFree(db, pParse); } |