/ Check-in [6eddc6e6]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove the Table.dbMem variable, as it is no longer being used for its original purpose.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6eddc6e601cf8f585c6c2cf79f36fcbfe98a307e
User & Date: dan 2010-07-23 15:41:47
Context
2010-07-23
17:06
Remove additional traces (mostly in comments) of the Table.dbMem field. check-in: 5c58f44a user: drh tags: trunk
15:55
Add a test case to shared.test. No changes to production code. check-in: bfb0dd3c user: dan tags: trunk
15:41
Remove the Table.dbMem variable, as it is no longer being used for its original purpose. check-in: 6eddc6e6 user: dan tags: trunk
08:31
Remove the unused Schema.db variable. check-in: 430be657 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   765    765     ** table because user table are not allowed to have the "sqlite_"
   766    766     ** prefix on their name.
   767    767     */
   768    768     pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
   769    769     if( !pNew ) goto exit_begin_add_column;
   770    770     pParse->pNewTable = pNew;
   771    771     pNew->nRef = 1;
   772         -  pNew->dbMem = pTab->dbMem;
   773    772     pNew->nCol = pTab->nCol;
   774    773     assert( pNew->nCol>0 );
   775    774     nAlloc = (((pNew->nCol-1)/8)*8)+8;
   776    775     assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
   777    776     pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
   778    777     pNew->zName = sqlite3MPrintf(db, "sqlite_altertab_%s", pTab->zName);
   779    778     if( !pNew->aCol || !pNew->zName ){

Changes to src/analyze.c.

   490    490   ** If the Index.aSample variable is not NULL, delete the aSample[] array
   491    491   ** and its contents.
   492    492   */
   493    493   void sqlite3DeleteIndexSamples(Index *pIdx){
   494    494   #ifdef SQLITE_ENABLE_STAT2
   495    495     if( pIdx->aSample ){
   496    496       int j;
   497         -    sqlite3 *dbMem = pIdx->pTable->dbMem;
   498    497       for(j=0; j<SQLITE_INDEX_SAMPLES; j++){
   499    498         IndexSample *p = &pIdx->aSample[j];
   500    499         if( p->eType==SQLITE_TEXT || p->eType==SQLITE_BLOB ){
   501         -        sqlite3DbFree(pIdx->pTable->dbMem, p->u.z);
          500  +        sqlite3_free(p->u.z);
   502    501         }
   503    502       }
   504         -    sqlite3DbFree(dbMem, pIdx->aSample);
          503  +    sqlite3DbFree(0, pIdx->aSample);
   505    504       pIdx->aSample = 0;
   506    505     }
   507    506   #else
   508    507     UNUSED_PARAMETER(pIdx);
   509    508   #endif
   510    509   }
   511    510   
................................................................................
   583    582   
   584    583       if( rc==SQLITE_OK ){
   585    584         while( sqlite3_step(pStmt)==SQLITE_ROW ){
   586    585           char *zIndex = (char *)sqlite3_column_text(pStmt, 0);
   587    586           Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
   588    587           if( pIdx ){
   589    588             int iSample = sqlite3_column_int(pStmt, 1);
   590         -          sqlite3 *dbMem = pIdx->pTable->dbMem;
   591         -          assert( dbMem==db || dbMem==0 );
   592    589             if( iSample<SQLITE_INDEX_SAMPLES && iSample>=0 ){
   593    590               int eType = sqlite3_column_type(pStmt, 2);
   594    591   
   595    592               if( pIdx->aSample==0 ){
   596    593                 static const int sz = sizeof(IndexSample)*SQLITE_INDEX_SAMPLES;
   597         -              pIdx->aSample = (IndexSample *)sqlite3DbMallocZero(dbMem, sz);
          594  +              pIdx->aSample = (IndexSample *)sqlite3Malloc(sz);
   598    595                 if( pIdx->aSample==0 ){
   599    596                   db->mallocFailed = 1;
   600    597                   break;
   601    598                 }
          599  +	      memset(pIdx->aSample, 0, sz);
   602    600               }
   603    601   
   604    602               assert( pIdx->aSample );
   605    603               {
   606    604                 IndexSample *pSample = &pIdx->aSample[iSample];
   607    605                 pSample->eType = (u8)eType;
   608    606                 if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){
................................................................................
   617    615                   if( n>24 ){
   618    616                     n = 24;
   619    617                   }
   620    618                   pSample->nByte = (u8)n;
   621    619                   if( n < 1){
   622    620                     pSample->u.z = 0;
   623    621                   }else{
   624         -                  pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
          622  +                  pSample->u.z = sqlite3Malloc(n);
   625    623                     if( pSample->u.z ){
   626    624                       memcpy(pSample->u.z, z, n);
   627    625                     }else{
   628    626                       db->mallocFailed = 1;
   629    627                       break;
   630    628                     }
   631    629                   }

Changes to src/build.c.

   341    341     }
   342    342     return p;
   343    343   }
   344    344   
   345    345   /*
   346    346   ** Reclaim the memory used by an index
   347    347   */
   348         -static void freeIndex(Index *p){
   349         -  sqlite3 *db = p->pTable->dbMem;
          348  +static void freeIndex(sqlite3 *db, Index *p){
   350    349   #ifndef SQLITE_OMIT_ANALYZE
   351    350     sqlite3DeleteIndexSamples(p);
   352    351   #endif
   353    352     sqlite3DbFree(db, p->zColAff);
   354    353     sqlite3DbFree(db, p);
   355    354   }
   356    355   
................................................................................
   358    357   ** Remove the given index from the index hash table, and free
   359    358   ** its memory structures.
   360    359   **
   361    360   ** The index is removed from the database hash tables but
   362    361   ** it is not unlinked from the Table that it indexes.
   363    362   ** Unlinking from the Table must be done by the calling function.
   364    363   */
   365         -static void sqlite3DeleteIndex(Index *p){
          364  +static void sqlite3DeleteIndex(sqlite3 *db, Index *p){
   366    365     Index *pOld;
   367    366     const char *zName = p->zName;
   368    367   
   369    368     pOld = sqlite3HashInsert(&p->pSchema->idxHash, zName,
   370    369                              sqlite3Strlen30(zName), 0);
   371    370     assert( pOld==0 || pOld==p );
   372         -  freeIndex(p);
          371  +  freeIndex(db, p);
   373    372   }
   374    373   
   375    374   /*
   376    375   ** For the index called zIdxName which is found in the database iDb,
   377    376   ** unlike that index from its Table then remove the index from
   378    377   ** the index hash table and free all memory structures associated
   379    378   ** with the index.
................................................................................
   394    393         ** indices. */
   395    394         p = pIndex->pTable->pIndex;
   396    395         while( ALWAYS(p) && p->pNext!=pIndex ){ p = p->pNext; }
   397    396         if( ALWAYS(p && p->pNext==pIndex) ){
   398    397           p->pNext = pIndex->pNext;
   399    398         }
   400    399       }
   401         -    freeIndex(pIndex);
          400  +    freeIndex(db, pIndex);
   402    401     }
   403    402     db->flags |= SQLITE_InternChanges;
   404    403   }
   405    404   
   406    405   /*
   407    406   ** Erase all schema information from the in-memory hash tables of
   408    407   ** a single database.  This routine is called to reclaim memory
................................................................................
   467    466   void sqlite3CommitInternalChanges(sqlite3 *db){
   468    467     db->flags &= ~SQLITE_InternChanges;
   469    468   }
   470    469   
   471    470   /*
   472    471   ** Clear the column names from a table or view.
   473    472   */
   474         -static void sqliteResetColumnNames(Table *pTable){
          473  +static void sqliteResetColumnNames(sqlite3 *db, Table *pTable){
   475    474     int i;
   476    475     Column *pCol;
   477         -  sqlite3 *db = pTable->dbMem;
   478         -  testcase( db==0 );
   479    476     assert( pTable!=0 );
   480    477     if( (pCol = pTable->aCol)!=0 ){
   481    478       for(i=0; i<pTable->nCol; i++, pCol++){
   482    479         sqlite3DbFree(db, pCol->zName);
   483    480         sqlite3ExprDelete(db, pCol->pDflt);
   484    481         sqlite3DbFree(db, pCol->zDflt);
   485    482         sqlite3DbFree(db, pCol->zType);
................................................................................
   496    493   ** Table.  No changes are made to disk by this routine.
   497    494   **
   498    495   ** This routine just deletes the data structure.  It does not unlink
   499    496   ** the table data structure from the hash table.  But it does destroy
   500    497   ** memory structures of the indices and foreign keys associated with 
   501    498   ** the table.
   502    499   */
   503         -void sqlite3DeleteTable(Table *pTable){
          500  +void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
   504    501     Index *pIndex, *pNext;
   505         -  sqlite3 *db;
   506    502   
   507    503     if( pTable==0 ) return;
   508         -  db = pTable->dbMem;
   509         -  testcase( db==0 );
   510    504   
   511    505     /* Do not delete the table until the reference count reaches zero. */
   512    506     pTable->nRef--;
   513    507     if( pTable->nRef>0 ){
   514    508       return;
   515    509     }
   516    510     assert( pTable->nRef==0 );
   517    511   
   518    512     /* Delete all indices associated with this table
   519    513     */
   520    514     for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
   521    515       pNext = pIndex->pNext;
   522    516       assert( pIndex->pSchema==pTable->pSchema );
   523         -    sqlite3DeleteIndex(pIndex);
          517  +    sqlite3DeleteIndex(db, pIndex);
   524    518     }
   525    519   
   526    520     /* Delete any foreign keys attached to this table. */
   527         -  sqlite3FkDelete(pTable);
          521  +  sqlite3FkDelete(db, pTable);
   528    522   
   529    523     /* Delete the Table structure itself.
   530    524     */
   531         -  sqliteResetColumnNames(pTable);
          525  +  sqliteResetColumnNames(db, pTable);
   532    526     sqlite3DbFree(db, pTable->zName);
   533    527     sqlite3DbFree(db, pTable->zColAff);
   534    528     sqlite3SelectDelete(db, pTable->pSelect);
   535    529   #ifndef SQLITE_OMIT_CHECK
   536    530     sqlite3ExprDelete(db, pTable->pCheck);
   537    531   #endif
   538         -  sqlite3VtabClear(pTable);
          532  +  sqlite3VtabClear(db, pTable);
   539    533     sqlite3DbFree(db, pTable);
   540    534   }
   541    535   
   542    536   /*
   543    537   ** Unlink the given table from the hash tables and the delete the
   544    538   ** table structure with all its indices and foreign keys.
   545    539   */
................................................................................
   550    544     assert( db!=0 );
   551    545     assert( iDb>=0 && iDb<db->nDb );
   552    546     assert( zTabName );
   553    547     testcase( zTabName[0]==0 );  /* Zero-length table names are allowed */
   554    548     pDb = &db->aDb[iDb];
   555    549     p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
   556    550                           sqlite3Strlen30(zTabName),0);
   557         -  sqlite3DeleteTable(p);
          551  +  sqlite3DeleteTable(db, p);
   558    552     db->flags |= SQLITE_InternChanges;
   559    553   }
   560    554   
   561    555   /*
   562    556   ** Given a token, return a string that consists of the text of that
   563    557   ** token.  Space to hold the returned string
   564    558   ** is obtained from sqliteMalloc() and must be freed by the calling
................................................................................
   818    812       pParse->nErr++;
   819    813       goto begin_table_error;
   820    814     }
   821    815     pTable->zName = zName;
   822    816     pTable->iPKey = -1;
   823    817     pTable->pSchema = db->aDb[iDb].pSchema;
   824    818     pTable->nRef = 1;
   825         -  pTable->dbMem = 0;
   826    819     assert( pParse->pNewTable==0 );
   827    820     pParse->pNewTable = pTable;
   828    821   
   829    822     /* If this is the magic sqlite_sequence table used by autoincrement,
   830    823     ** then record a pointer to this table in the main database structure
   831    824     ** so that INSERT can find the table easily.
   832    825     */
................................................................................
  1551   1544           pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect);
  1552   1545           if( pSelTab==0 ) return;
  1553   1546           assert( p->aCol==0 );
  1554   1547           p->nCol = pSelTab->nCol;
  1555   1548           p->aCol = pSelTab->aCol;
  1556   1549           pSelTab->nCol = 0;
  1557   1550           pSelTab->aCol = 0;
  1558         -        sqlite3DeleteTable(pSelTab);
         1551  +        sqlite3DeleteTable(db, pSelTab);
  1559   1552         }
  1560   1553       }
  1561   1554   
  1562   1555       /* Compute the complete text of the CREATE statement */
  1563   1556       if( pSelect ){
  1564   1557         zStmt = createTableStmt(db, p);
  1565   1558       }else{
................................................................................
  1795   1788       pParse->nTab = n;
  1796   1789       if( pSelTab ){
  1797   1790         assert( pTable->aCol==0 );
  1798   1791         pTable->nCol = pSelTab->nCol;
  1799   1792         pTable->aCol = pSelTab->aCol;
  1800   1793         pSelTab->nCol = 0;
  1801   1794         pSelTab->aCol = 0;
  1802         -      sqlite3DeleteTable(pSelTab);
         1795  +      sqlite3DeleteTable(db, pSelTab);
  1803   1796         pTable->pSchema->flags |= DB_UnresetViews;
  1804   1797       }else{
  1805   1798         pTable->nCol = 0;
  1806   1799         nErr++;
  1807   1800       }
  1808   1801       sqlite3SelectDelete(db, pSel);
  1809   1802     } else {
................................................................................
  1820   1813   */
  1821   1814   static void sqliteViewResetAll(sqlite3 *db, int idx){
  1822   1815     HashElem *i;
  1823   1816     if( !DbHasProperty(db, idx, DB_UnresetViews) ) return;
  1824   1817     for(i=sqliteHashFirst(&db->aDb[idx].pSchema->tblHash); i;i=sqliteHashNext(i)){
  1825   1818       Table *pTab = sqliteHashData(i);
  1826   1819       if( pTab->pSelect ){
  1827         -      sqliteResetColumnNames(pTab);
         1820  +      sqliteResetColumnNames(db, pTab);
  1828   1821       }
  1829   1822     }
  1830   1823     DbClearProperty(db, idx, DB_UnresetViews);
  1831   1824   }
  1832   1825   #else
  1833   1826   # define sqliteViewResetAll(A,B)
  1834   1827   #endif /* SQLITE_OMIT_VIEW */
................................................................................
  3196   3189     struct SrcList_item *pItem;
  3197   3190     if( pList==0 ) return;
  3198   3191     for(pItem=pList->a, i=0; i<pList->nSrc; i++, pItem++){
  3199   3192       sqlite3DbFree(db, pItem->zDatabase);
  3200   3193       sqlite3DbFree(db, pItem->zName);
  3201   3194       sqlite3DbFree(db, pItem->zAlias);
  3202   3195       sqlite3DbFree(db, pItem->zIndex);
  3203         -    sqlite3DeleteTable(pItem->pTab);
         3196  +    sqlite3DeleteTable(db, pItem->pTab);
  3204   3197       sqlite3SelectDelete(db, pItem->pSelect);
  3205   3198       sqlite3ExprDelete(db, pItem->pOn);
  3206   3199       sqlite3IdListDelete(db, pItem->pUsing);
  3207   3200     }
  3208   3201     sqlite3DbFree(db, pList);
  3209   3202   }
  3210   3203   

Changes to src/callback.c.

   419    419       sqlite3DeleteTrigger(0, (Trigger*)sqliteHashData(pElem));
   420    420     }
   421    421     sqlite3HashClear(&temp2);
   422    422     sqlite3HashInit(&pSchema->tblHash);
   423    423     for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
   424    424       Table *pTab = sqliteHashData(pElem);
   425    425       assert( pTab->dbMem==0 );
   426         -    sqlite3DeleteTable(pTab);
          426  +    sqlite3DeleteTable(0, pTab);
   427    427     }
   428    428     sqlite3HashClear(&temp1);
   429    429     sqlite3HashClear(&pSchema->fkeyHash);
   430    430     pSchema->pSeqTab = 0;
   431    431     pSchema->flags &= ~DB_SchemaLoaded;
   432    432   }
   433    433   

Changes to src/delete.c.

    20     20   ** are found, return a pointer to the last table.
    21     21   */
    22     22   Table *sqlite3SrcListLookup(Parse *pParse, SrcList *pSrc){
    23     23     struct SrcList_item *pItem = pSrc->a;
    24     24     Table *pTab;
    25     25     assert( pItem && pSrc->nSrc==1 );
    26     26     pTab = sqlite3LocateTable(pParse, 0, pItem->zName, pItem->zDatabase);
    27         -  sqlite3DeleteTable(pItem->pTab);
           27  +  sqlite3DeleteTable(pParse->db, pItem->pTab);
    28     28     pItem->pTab = pTab;
    29     29     if( pTab ){
    30     30       pTab->nRef++;
    31     31     }
    32     32     if( sqlite3IndexedByLookup(pParse, pItem) ){
    33     33       pTab = 0;
    34     34     }

Changes to src/fkey.c.

  1151   1151   #endif /* ifndef SQLITE_OMIT_TRIGGER */
  1152   1152   
  1153   1153   /*
  1154   1154   ** Free all memory associated with foreign key definitions attached to
  1155   1155   ** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
  1156   1156   ** hash table.
  1157   1157   */
  1158         -void sqlite3FkDelete(Table *pTab){
         1158  +void sqlite3FkDelete(sqlite3 *db, Table *pTab){
  1159   1159     FKey *pFKey;                    /* Iterator variable */
  1160   1160     FKey *pNext;                    /* Copy of pFKey->pNextFrom */
  1161   1161   
  1162   1162     for(pFKey=pTab->pFKey; pFKey; pFKey=pNext){
  1163   1163   
  1164   1164       /* Remove the FK from the fkeyHash hash table. */
  1165   1165       if( pFKey->pPrevTo ){
................................................................................
  1171   1171       }
  1172   1172       if( pFKey->pNextTo ){
  1173   1173         pFKey->pNextTo->pPrevTo = pFKey->pPrevTo;
  1174   1174       }
  1175   1175   
  1176   1176       /* Delete any triggers created to implement actions for this FK. */
  1177   1177   #ifndef SQLITE_OMIT_TRIGGER
  1178         -    fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[0]);
  1179         -    fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[1]);
         1178  +    fkTriggerDelete(db, pFKey->apTrigger[0]);
         1179  +    fkTriggerDelete(db, pFKey->apTrigger[1]);
  1180   1180   #endif
  1181   1181   
  1182   1182       /* EV: R-30323-21917 Each foreign key constraint in SQLite is
  1183   1183       ** classified as either immediate or deferred.
  1184   1184       */
  1185   1185       assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
  1186   1186   
  1187   1187       pNext = pFKey->pNextFrom;
  1188         -    sqlite3DbFree(pTab->dbMem, pFKey);
         1188  +    sqlite3DbFree(db, pFKey);
  1189   1189     }
  1190   1190   }
  1191   1191   #endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */

Changes to src/select.c.

  1296   1296     pTab = sqlite3DbMallocZero(db, sizeof(Table) );
  1297   1297     if( pTab==0 ){
  1298   1298       return 0;
  1299   1299     }
  1300   1300     /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
  1301   1301     ** is disabled, so we might as well hard-code pTab->dbMem to NULL. */
  1302   1302     assert( db->lookaside.bEnabled==0 );
  1303         -  pTab->dbMem = 0;
  1304   1303     pTab->nRef = 1;
  1305   1304     pTab->zName = 0;
  1306   1305     selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
  1307   1306     selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect);
  1308   1307     pTab->iPKey = -1;
  1309   1308     if( db->mallocFailed ){
  1310         -    sqlite3DeleteTable(pTab);
         1309  +    sqlite3DeleteTable(db, pTab);
  1311   1310       return 0;
  1312   1311     }
  1313   1312     return pTab;
  1314   1313   }
  1315   1314   
  1316   1315   /*
  1317   1316   ** Get a VDBE for the given parser context.  Create a new one if necessary.
................................................................................
  3092   3091         Select *pSel = pFrom->pSelect;
  3093   3092         /* A sub-query in the FROM clause of a SELECT */
  3094   3093         assert( pSel!=0 );
  3095   3094         assert( pFrom->pTab==0 );
  3096   3095         sqlite3WalkSelect(pWalker, pSel);
  3097   3096         pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
  3098   3097         if( pTab==0 ) return WRC_Abort;
  3099         -      pTab->dbMem = db->lookaside.bEnabled ? db : 0;
  3100   3098         pTab->nRef = 1;
  3101   3099         pTab->zName = sqlite3MPrintf(db, "sqlite_subquery_%p_", (void*)pTab);
  3102   3100         while( pSel->pPrior ){ pSel = pSel->pPrior; }
  3103   3101         selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
  3104   3102         pTab->iPKey = -1;
  3105   3103         pTab->tabFlags |= TF_Ephemeral;
  3106   3104   #endif

Changes to src/sqliteInt.h.

  1213   1213   ** when the VDBE cursor to the table is closed.  In this case Table.tnum 
  1214   1214   ** refers VDBE cursor number that holds the table open, not to the root
  1215   1215   ** page number.  Transient tables are used to hold the results of a
  1216   1216   ** sub-query that appears instead of a real table name in the FROM clause 
  1217   1217   ** of a SELECT statement.
  1218   1218   */
  1219   1219   struct Table {
  1220         -  sqlite3 *dbMem;      /* DB connection used for lookaside allocations. */
  1221   1220     char *zName;         /* Name of the table or view */
  1222   1221     int iPKey;           /* If not negative, use aCol[iPKey] as the primary key */
  1223   1222     int nCol;            /* Number of columns in this table */
  1224   1223     Column *aCol;        /* Information about each column */
  1225   1224     Index *pIndex;       /* List of SQL indexes on this table. */
  1226   1225     int tnum;            /* Root BTree node for this table (see note above) */
  1227   1226     Select *pSelect;     /* NULL for tables.  Points to definition if a view. */
................................................................................
  2620   2619   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
  2621   2620     int sqlite3ViewGetColumnNames(Parse*,Table*);
  2622   2621   #else
  2623   2622   # define sqlite3ViewGetColumnNames(A,B) 0
  2624   2623   #endif
  2625   2624   
  2626   2625   void sqlite3DropTable(Parse*, SrcList*, int, int);
  2627         -void sqlite3DeleteTable(Table*);
         2626  +void sqlite3DeleteTable(sqlite3*, Table*);
  2628   2627   #ifndef SQLITE_OMIT_AUTOINCREMENT
  2629   2628     void sqlite3AutoincrementBegin(Parse *pParse);
  2630   2629     void sqlite3AutoincrementEnd(Parse *pParse);
  2631   2630   #else
  2632   2631   # define sqlite3AutoincrementBegin(X)
  2633   2632   # define sqlite3AutoincrementEnd(X)
  2634   2633   #endif
................................................................................
  2967   2966   #  define sqlite3VtabRollback(X)
  2968   2967   #  define sqlite3VtabCommit(X)
  2969   2968   #  define sqlite3VtabInSync(db) 0
  2970   2969   #  define sqlite3VtabLock(X) 
  2971   2970   #  define sqlite3VtabUnlock(X)
  2972   2971   #  define sqlite3VtabUnlockList(X)
  2973   2972   #else
  2974         -   void sqlite3VtabClear(Table*);
         2973  +   void sqlite3VtabClear(sqlite3 *db, Table*);
  2975   2974      int sqlite3VtabSync(sqlite3 *db, char **);
  2976   2975      int sqlite3VtabRollback(sqlite3 *db);
  2977   2976      int sqlite3VtabCommit(sqlite3 *db);
  2978   2977      void sqlite3VtabLock(VTable *);
  2979   2978      void sqlite3VtabUnlock(VTable *);
  2980   2979      void sqlite3VtabUnlockList(sqlite3*);
  2981   2980   #  define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
................................................................................
  3020   3019     #define sqlite3FkActions(a,b,c,d)
  3021   3020     #define sqlite3FkCheck(a,b,c,d)
  3022   3021     #define sqlite3FkDropTable(a,b,c)
  3023   3022     #define sqlite3FkOldmask(a,b)      0
  3024   3023     #define sqlite3FkRequired(a,b,c,d) 0
  3025   3024   #endif
  3026   3025   #ifndef SQLITE_OMIT_FOREIGN_KEY
  3027         -  void sqlite3FkDelete(Table*);
         3026  +  void sqlite3FkDelete(sqlite3 *, Table*);
  3028   3027   #else
  3029         -  #define sqlite3FkDelete(a)
         3028  +  #define sqlite3FkDelete(a,b)
  3030   3029   #endif
  3031   3030   
  3032   3031   
  3033   3032   /*
  3034   3033   ** Available fault injectors.  Should be numbered beginning with 0.
  3035   3034   */
  3036   3035   #define SQLITE_FAULTINJECTOR_MALLOC     0

Changes to src/tokenize.c.

   500    500   #endif
   501    501   
   502    502     if( !IN_DECLARE_VTAB ){
   503    503       /* If the pParse->declareVtab flag is set, do not delete any table 
   504    504       ** structure built up in pParse->pNewTable. The calling code (see vtab.c)
   505    505       ** will take responsibility for freeing the Table structure.
   506    506       */
   507         -    sqlite3DeleteTable(pParse->pNewTable);
          507  +    sqlite3DeleteTable(db, pParse->pNewTable);
   508    508     }
   509    509   
   510    510     sqlite3DeleteTrigger(db, pParse->pNewTrigger);
   511    511     sqlite3DbFree(db, pParse->apVarExpr);
   512    512     sqlite3DbFree(db, pParse->aAlias);
   513    513     while( pParse->pAinc ){
   514    514       AutoincInfo *p = pParse->pAinc;
   515    515       pParse->pAinc = p->pNext;
   516    516       sqlite3DbFree(db, p);
   517    517     }
   518    518     while( pParse->pZombieTab ){
   519    519       Table *p = pParse->pZombieTab;
   520    520       pParse->pZombieTab = p->pNextZombie;
   521         -    sqlite3DeleteTable(p);
          521  +    sqlite3DeleteTable(db, p);
   522    522     }
   523    523     if( nErr>0 && pParse->rc==SQLITE_OK ){
   524    524       pParse->rc = SQLITE_ERROR;
   525    525     }
   526    526     return nErr;
   527    527   }

Changes to src/vtab.c.

   217    217   ** structure is associated with a single sqlite3* user of the schema.
   218    218   ** The reference count of the VTable structure associated with database 
   219    219   ** connection db is decremented immediately (which may lead to the 
   220    220   ** structure being xDisconnected and free). Any other VTable structures
   221    221   ** in the list are moved to the sqlite3.pDisconnect list of the associated 
   222    222   ** database connection.
   223    223   */
   224         -void sqlite3VtabClear(Table *p){
          224  +void sqlite3VtabClear(sqlite3 *db, Table *p){
   225    225     vtabDisconnectAll(0, p);
   226    226     if( p->azModuleArg ){
   227    227       int i;
   228    228       for(i=0; i<p->nModuleArg; i++){
   229         -      sqlite3DbFree(p->dbMem, p->azModuleArg[i]);
          229  +      sqlite3DbFree(db, p->azModuleArg[i]);
   230    230       }
   231         -    sqlite3DbFree(p->dbMem, p->azModuleArg);
          231  +    sqlite3DbFree(db, p->azModuleArg);
   232    232     }
   233    233   }
   234    234   
   235    235   /*
   236    236   ** Add a new module argument to pTable->azModuleArg[].
   237    237   ** The string is not copied - the pointer is stored.  The
   238    238   ** string will be freed automatically when the table is
................................................................................
   677    677         rc = SQLITE_ERROR;
   678    678       }
   679    679       pParse->declareVtab = 0;
   680    680     
   681    681       if( pParse->pVdbe ){
   682    682         sqlite3VdbeFinalize(pParse->pVdbe);
   683    683       }
   684         -    sqlite3DeleteTable(pParse->pNewTable);
          684  +    sqlite3DeleteTable(db, pParse->pNewTable);
   685    685       sqlite3StackFree(db, pParse);
   686    686     }
   687    687   
   688    688     assert( (rc&0xff)==rc );
   689    689     rc = sqlite3ApiExit(db, rc);
   690    690     sqlite3_mutex_leave(db->mutex);
   691    691     return rc;