/ Check-in [58e42cfd]
Login

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

Overview
Comment:Change some internal details to bring this branch closer to the code on trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | schemalint
Files: files | file ages | folders
SHA3-256: 58e42cfd7d4af2279dab8dd895dca7afbdf9035445bc81bd4a7461ea24e846fc
User & Date: dan 2017-10-11 20:10:22
Context
2017-10-11
20:26
Merge latest trunk changes with this branch. check-in: 2719cf5c user: dan tags: schemalint
20:10
Change some internal details to bring this branch closer to the code on trunk. check-in: 58e42cfd user: dan tags: schemalint
2017-05-15
17:56
Merge changes from trunk. check-in: 6e0f64ab user: drh tags: schemalint
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

   475    475         while( ALWAYS(p) && p->pNext!=pIndex ){ p = p->pNext; }
   476    476         if( ALWAYS(p && p->pNext==pIndex) ){
   477    477           p->pNext = pIndex->pNext;
   478    478         }
   479    479       }
   480    480       freeIndex(db, pIndex);
   481    481     }
   482         -  db->bInternChanges = 1;
          482  +  db->flags |= SQLITE_InternChanges;
   483    483   }
   484    484   
   485    485   /*
   486    486   ** Look through the list of open database files in db->aDb[] and if
   487    487   ** any have been closed, remove them from the list.  Reallocate the
   488    488   ** db->aDb[] structure to a smaller size, if possible.
   489    489   **
................................................................................
   547    547     sqlite3BtreeEnterAll(db);
   548    548     for(i=0; i<db->nDb; i++){
   549    549       Db *pDb = &db->aDb[i];
   550    550       if( pDb->pSchema ){
   551    551         sqlite3SchemaClear(pDb->pSchema);
   552    552       }
   553    553     }
   554         -  db->bInternChanges = 0;
          554  +  db->flags &= ~SQLITE_InternChanges;
   555    555     sqlite3VtabUnlockList(db);
   556    556     sqlite3BtreeLeaveAll(db);
   557    557     sqlite3CollapseDatabaseArray(db);
   558    558   }
   559    559   
   560    560   /*
   561    561   ** This routine is called when a commit occurs.
   562    562   */
   563    563   void sqlite3CommitInternalChanges(sqlite3 *db){
   564         -  db->bInternChanges = 0;
          564  +  db->flags &= ~SQLITE_InternChanges;
   565    565   }
   566    566   
   567    567   /*
   568    568   ** Delete memory allocated for the column names of a table or view (the
   569    569   ** Table.aCol[] array).
   570    570   */
   571    571   void sqlite3DeleteColumnNames(sqlite3 *db, Table *pTable){
................................................................................
   661    661     assert( iDb>=0 && iDb<db->nDb );
   662    662     assert( zTabName );
   663    663     assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   664    664     testcase( zTabName[0]==0 );  /* Zero-length table names are allowed */
   665    665     pDb = &db->aDb[iDb];
   666    666     p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0);
   667    667     sqlite3DeleteTable(db, p);
   668         -  db->bInternChanges = 1;
          668  +  db->flags |= SQLITE_InternChanges;
   669    669   }
   670    670   
   671    671   /*
   672    672   ** Given a token, return a string that consists of the text of that
   673    673   ** token.  Space to hold the returned string
   674    674   ** is obtained from sqliteMalloc() and must be freed by the calling
   675    675   ** function.
................................................................................
  2047   2047       pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p);
  2048   2048       if( pOld ){
  2049   2049         assert( p==pOld );  /* Malloc must have failed inside HashInsert() */
  2050   2050         sqlite3OomFault(db);
  2051   2051         return;
  2052   2052       }
  2053   2053       pParse->pNewTable = 0;
  2054         -    db->bInternChanges = 1;
         2054  +    db->flags |= SQLITE_InternChanges;
  2055   2055   
  2056   2056   #ifndef SQLITE_OMIT_ALTERTABLE
  2057   2057       if( !p->pSelect ){
  2058   2058         const char *zName = (const char *)pParse->sNameToken.z;
  2059   2059         int nName;
  2060   2060         assert( !pSelect && pCons && pEnd );
  2061   2061         if( pCons->z==0 ){
................................................................................
  3316   3316       p = sqlite3HashInsert(&pIndex->pSchema->idxHash, 
  3317   3317                             pIndex->zName, pIndex);
  3318   3318       if( p ){
  3319   3319         assert( p==pIndex );  /* Malloc must have failed */
  3320   3320         sqlite3OomFault(db);
  3321   3321         goto exit_create_index;
  3322   3322       }
  3323         -    db->bInternChanges = 1;
         3323  +    db->flags |= SQLITE_InternChanges;
  3324   3324       if( pTblName!=0 ){
  3325   3325         pIndex->tnum = db->init.newTnum;
  3326   3326       }
  3327   3327     }
  3328   3328   
  3329   3329     /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
  3330   3330     ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then

Changes to src/main.c.

   796    796       }
   797    797       case SQLITE_DBCONFIG_LOOKASIDE: {
   798    798         void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
   799    799         int sz = va_arg(ap, int);       /* IMP: R-47871-25994 */
   800    800         int cnt = va_arg(ap, int);      /* IMP: R-04460-53386 */
   801    801         rc = setupLookaside(db, pBuf, sz, cnt);
   802    802         break;
          803  +    }
          804  +    case SQLITE_DBCONFIG_FULL_EQP: {
          805  +      int onoff = va_arg(ap, int);
          806  +      int *pRes = va_arg(ap, int*);
          807  +      if( onoff>0 ){
          808  +        db->bFullEQP = 1;
          809  +      }else if( onoff==0 ){
          810  +        db->bFullEQP = 0;
          811  +      }
          812  +      sqlite3ExpirePreparedStatements(db);
          813  +      if( pRes ){
          814  +        *pRes = db->bFullEQP;
          815  +      }
          816  +      rc = SQLITE_OK;
          817  +      break;
   803    818       }
   804    819       default: {
   805    820         static const struct {
   806    821           int op;      /* The opcode */
   807    822           u32 mask;    /* Mask of the bit in sqlite3.flags to set/clear */
   808    823         } aFlagOp[] = {
   809    824           { SQLITE_DBCONFIG_ENABLE_FKEY,           SQLITE_ForeignKeys    },
   810    825           { SQLITE_DBCONFIG_ENABLE_TRIGGER,        SQLITE_EnableTrigger  },
   811    826           { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer  },
   812    827           { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension  },
   813    828           { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,      SQLITE_NoCkptOnClose  },
   814         -        { SQLITE_DBCONFIG_FULL_EQP,              SQLITE_FullEQP  },
   815    829         };
   816    830         unsigned int i;
   817    831         rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
   818    832         for(i=0; i<ArraySize(aFlagOp); i++){
   819    833           if( aFlagOp[i].op==op ){
   820    834             int onoff = va_arg(ap, int);
   821    835             int *pRes = va_arg(ap, int*);
................................................................................
  1249   1263     /* Obtain all b-tree mutexes before making any calls to BtreeRollback(). 
  1250   1264     ** This is important in case the transaction being rolled back has
  1251   1265     ** modified the database schema. If the b-tree mutexes are not taken
  1252   1266     ** here, then another shared-cache connection might sneak in between
  1253   1267     ** the database rollback and schema reset, which can cause false
  1254   1268     ** corruption reports in some cases.  */
  1255   1269     sqlite3BtreeEnterAll(db);
  1256         -  schemaChange = db->bInternChanges && db->init.busy==0;
         1270  +  schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
  1257   1271   
  1258   1272     for(i=0; i<db->nDb; i++){
  1259   1273       Btree *p = db->aDb[i].pBt;
  1260   1274       if( p ){
  1261   1275         if( sqlite3BtreeIsInTrans(p) ){
  1262   1276           inTrans = 1;
  1263   1277         }
  1264   1278         sqlite3BtreeRollback(p, tripCode, !schemaChange);
  1265   1279       }
  1266   1280     }
  1267   1281     sqlite3VtabRollback(db);
  1268   1282     sqlite3EndBenignMalloc();
  1269   1283   
  1270         -  if( db->bInternChanges && db->init.busy==0 ){
         1284  +  if( (db->flags&SQLITE_InternChanges)!=0 && db->init.busy==0 ){
  1271   1285       sqlite3ExpirePreparedStatements(db);
  1272   1286       sqlite3ResetAllSchemasOfConnection(db);
  1273   1287     }
  1274   1288     sqlite3BtreeLeaveAll(db);
  1275   1289   
  1276   1290     /* Any deferred constraint violations have now been resolved. */
  1277   1291     db->nDeferredCons = 0;

Changes to src/prepare.c.

   350    350   **
   351    351   ** After a database is initialized, the DB_SchemaLoaded bit is set
   352    352   ** bit is set in the flags field of the Db structure. If the database
   353    353   ** file was of zero-length, then the DB_Empty flag is also set.
   354    354   */
   355    355   int sqlite3Init(sqlite3 *db, char **pzErrMsg){
   356    356     int i, rc;
   357         -  int commit_internal = db->bInternChanges==0;
          357  +  int commit_internal = !(db->flags&SQLITE_InternChanges);
   358    358     
   359    359     assert( sqlite3_mutex_held(db->mutex) );
   360    360     assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
   361    361     assert( db->init.busy==0 );
   362    362     rc = SQLITE_OK;
   363    363     db->init.busy = 1;
   364    364     ENC(db) = SCHEMA_ENC(db);

Changes to src/sqliteInt.h.

  1330   1330     signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
  1331   1331     u8 suppressErr;               /* Do not issue error messages if true */
  1332   1332     u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
  1333   1333     u8 isTransactionSavepoint;    /* True if the outermost savepoint is a TS */
  1334   1334     u8 mTrace;                    /* zero or more SQLITE_TRACE flags */
  1335   1335     u8 skipBtreeMutex;            /* True if no shared-cache backends */
  1336   1336     u8 nSqlExec;                  /* Number of pending OP_SqlExec opcodes */
  1337         -  u8 bInternChanges;            /* There are uncommited schema changes */
         1337  +  u8 bFullEQP;                  /* Include triggers in EQP output */
  1338   1338     int nextPagesize;             /* Pagesize after VACUUM if >0 */
  1339   1339     u32 magic;                    /* Magic number for detect library misuse */
  1340   1340     int nChange;                  /* Value returned by sqlite3_changes() */
  1341   1341     int nTotalChange;             /* Value returned by sqlite3_total_changes() */
  1342   1342     int aLimit[SQLITE_N_LIMIT];   /* Limits */
  1343   1343     int nMaxSorterMmap;           /* Maximum size of regions mapped by sorter */
  1344   1344     struct sqlite3InitInfo {      /* Information used during initialization */
................................................................................
  1446   1446   **
  1447   1447   ** Value constraints (enforced via assert()):
  1448   1448   **      SQLITE_FullFSync     == PAGER_FULLFSYNC
  1449   1449   **      SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
  1450   1450   **      SQLITE_CacheSpill    == PAGER_CACHE_SPILL
  1451   1451   */
  1452   1452   #define SQLITE_VdbeTrace      0x00000001  /* True to trace VDBE execution */
  1453         -#define SQLITE_FullEQP        0x00000002  /* Include triggers in EQP output */
         1453  +#define SQLITE_InternChanges  0x00000002  /* Uncommitted Hash table changes */
  1454   1454   #define SQLITE_FullColNames   0x00000004  /* Show full column names on SELECT */
  1455   1455   #define SQLITE_FullFSync      0x00000008  /* Use full fsync on the backend */
  1456   1456   #define SQLITE_CkptFullFSync  0x00000010  /* Use full fsync for checkpoint */
  1457   1457   #define SQLITE_CacheSpill     0x00000020  /* OK to spill pager cache */
  1458   1458   #define SQLITE_ShortColNames  0x00000040  /* Show short columns names */
  1459   1459   #define SQLITE_CountRows      0x00000080  /* Count rows changed by INSERT, */
  1460   1460                                             /*   DELETE, or UPDATE and return */

Changes to src/trigger.c.

   580    580       if( pTrigger->pSchema==pTrigger->pTabSchema ){
   581    581         Table *pTab = tableOfTrigger(pTrigger);
   582    582         Trigger **pp;
   583    583         for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext));
   584    584         *pp = (*pp)->pNext;
   585    585       }
   586    586       sqlite3DeleteTrigger(db, pTrigger);
   587         -    db->bInternChanges = 1;
          587  +    db->flags |= SQLITE_InternChanges;
   588    588     }
   589    589   }
   590    590   
   591    591   /*
   592    592   ** pEList is the SET clause of an UPDATE statement.  Each entry
   593    593   ** in pEList is of the format <id>=<expr>.  If any of the entries
   594    594   ** in pEList have an <id> which matches an identifier in pIdList,

Changes to src/vdbe.c.

  3052   3052           }
  3053   3053           db->isTransactionSavepoint = 0;
  3054   3054           rc = p->rc;
  3055   3055         }else{
  3056   3056           int isSchemaChange;
  3057   3057           iSavepoint = db->nSavepoint - iSavepoint - 1;
  3058   3058           if( p1==SAVEPOINT_ROLLBACK ){
  3059         -          isSchemaChange = db->bInternChanges;
         3059  +          isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
  3060   3060             for(ii=0; ii<db->nDb; ii++){
  3061   3061               rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
  3062   3062                                          SQLITE_ABORT_ROLLBACK,
  3063   3063                                          isSchemaChange==0);
  3064   3064               if( rc!=SQLITE_OK ) goto abort_due_to_error;
  3065   3065             }
  3066   3066           }else{
................................................................................
  3071   3071             if( rc!=SQLITE_OK ){
  3072   3072               goto abort_due_to_error;
  3073   3073             }
  3074   3074           }
  3075   3075           if( isSchemaChange ){
  3076   3076             sqlite3ExpirePreparedStatements(db);
  3077   3077             sqlite3ResetAllSchemasOfConnection(db);
  3078         -          db->bInternChanges = 1;
         3078  +          db->flags = (db->flags | SQLITE_InternChanges);
  3079   3079           }
  3080   3080         }
  3081   3081     
  3082   3082         /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all 
  3083   3083         ** savepoints nested inside of the savepoint being operated on. */
  3084   3084         while( db->pSavepoint!=pSavepoint ){
  3085   3085           pTmp = db->pSavepoint;
................................................................................
  3351   3351     assert( pDb->pBt!=0 );
  3352   3352     assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
  3353   3353     /* See note about index shifting on OP_ReadCookie */
  3354   3354     rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
  3355   3355     if( pOp->p2==BTREE_SCHEMA_VERSION ){
  3356   3356       /* When the schema cookie changes, record the new cookie internally */
  3357   3357       pDb->pSchema->schema_cookie = pOp->p3;
  3358         -    db->bInternChanges = 1;
         3358  +    db->flags |= SQLITE_InternChanges;
  3359   3359     }else if( pOp->p2==BTREE_FILE_FORMAT ){
  3360   3360       /* Record changes in the file format */
  3361   3361       pDb->pSchema->file_format = pOp->p3;
  3362   3362     }
  3363   3363     if( pOp->p1==1 ){
  3364   3364       /* Invalidate all prepared statements whenever the TEMP database
  3365   3365       ** schema is changed.  Ticket #1644 */

Changes to src/vdbeaux.c.

  1607   1607     int nSub = 0;                        /* Number of sub-vdbes seen so far */
  1608   1608     SubProgram **apSub = 0;              /* Array of sub-vdbes */
  1609   1609     Mem *pSub = 0;                       /* Memory cell hold array of subprogs */
  1610   1610     sqlite3 *db = p->db;                 /* The database connection */
  1611   1611     int i;                               /* Loop counter */
  1612   1612     int rc = SQLITE_OK;                  /* Return code */
  1613   1613     Mem *pMem = &p->aMem[1];             /* First Mem of result set */
  1614         -  int bFull = (p->explain==1 || (db->flags & SQLITE_FullEQP));
         1614  +  int bFull = (p->explain==1 || db->bFullEQP);
  1615   1615     Op *pOp = 0;
  1616   1616   
  1617   1617     assert( p->explain );
  1618   1618     assert( p->magic==VDBE_MAGIC_RUN );
  1619   1619     assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
  1620   1620   
  1621   1621     /* Even though this opcode does not use dynamic strings for