/ Check-in [2b3c8b9d]
Login

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

Overview
Comment:Merge in the sqlite3_db_config() enhancements for enabling and disabling FKs and triggers from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: 2b3c8b9d9aa909f64a29ed8167de24c328c50d85
User & Date: drh 2011-03-21 17:17:49
Context
2011-03-21
19:41
Remove some unreachable code in sqlite3session.c. Add test cases. check-in: 39cdfa53 user: dan tags: sessions
17:17
Merge in the sqlite3_db_config() enhancements for enabling and disabling FKs and triggers from trunk. check-in: 2b3c8b9d user: drh tags: sessions
17:15
Add the ability to enable and disable foreign key constraints and triggers using calls to sqlite3_db_config(). check-in: 09e167f9 user: drh tags: trunk
16:17
Add start of fault-injection tests for session module. Fix some bugs related to the same. check-in: 32e95164 user: dan tags: sessions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

   518    518         void *pBuf = va_arg(ap, void*); /* IMP: R-21112-12275 */
   519    519         int sz = va_arg(ap, int);       /* IMP: R-47871-25994 */
   520    520         int cnt = va_arg(ap, int);      /* IMP: R-04460-53386 */
   521    521         rc = setupLookaside(db, pBuf, sz, cnt);
   522    522         break;
   523    523       }
   524    524       default: {
          525  +      static const struct {
          526  +        int op;      /* The opcode */
          527  +        u32 mask;    /* Mask of the bit in sqlite3.flags to set/clear */
          528  +      } aFlagOp[] = {
          529  +        { SQLITE_DBCONFIG_ENABLE_FKEY,    SQLITE_ForeignKeys    },
          530  +        { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger  },
          531  +      };
          532  +      int i;
   525    533         rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
          534  +      for(i=0; i<ArraySize(aFlagOp); i++){
          535  +        if( aFlagOp[i].op==op ){
          536  +          int onoff = va_arg(ap, int);
          537  +          int *pRes = va_arg(ap, int*);
          538  +          u32 oldFlags = db->flags;
          539  +          if( onoff>0 ){
          540  +            db->flags |= aFlagOp[i].mask;
          541  +          }else if( onoff==0 ){
          542  +            db->flags &= ~aFlagOp[i].mask;
          543  +          }
          544  +          if( oldFlags!=db->flags ){
          545  +            sqlite3ExpirePreparedStatements(db);
          546  +          }
          547  +          if( pRes ){
          548  +            *pRes = (db->flags & aFlagOp[i].mask)!=0;
          549  +          }
          550  +          rc = SQLITE_OK;
          551  +          break;
          552  +        }
          553  +      }
   526    554         break;
   527    555       }
   528    556     }
   529    557     va_end(ap);
   530    558     return rc;
   531    559   }
   532    560   
................................................................................
  1870   1898     db->aDb = db->aDbStatic;
  1871   1899   
  1872   1900     assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
  1873   1901     memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
  1874   1902     db->autoCommit = 1;
  1875   1903     db->nextAutovac = -1;
  1876   1904     db->nextPagesize = 0;
  1877         -  db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex
         1905  +  db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger
  1878   1906   #if SQLITE_DEFAULT_FILE_FORMAT<4
  1879   1907                    | SQLITE_LegacyFileFmt
  1880   1908   #endif
  1881   1909   #ifdef SQLITE_ENABLE_LOAD_EXTENSION
  1882   1910                    | SQLITE_LoadExtension
  1883   1911   #endif
  1884   1912   #if SQLITE_DEFAULT_RECURSIVE_TRIGGERS

Changes to src/sqlite.h.in.

  1121   1121   
  1122   1122   /*
  1123   1123   ** CAPI3REF: Configure database connections
  1124   1124   **
  1125   1125   ** The sqlite3_db_config() interface is used to make configuration
  1126   1126   ** changes to a [database connection].  The interface is similar to
  1127   1127   ** [sqlite3_config()] except that the changes apply to a single
  1128         -** [database connection] (specified in the first argument).  The
  1129         -** sqlite3_db_config() interface should only be used immediately after
  1130         -** the database connection is created using [sqlite3_open()],
  1131         -** [sqlite3_open16()], or [sqlite3_open_v2()].  
         1128  +** [database connection] (specified in the first argument).
  1132   1129   **
  1133   1130   ** The second argument to sqlite3_db_config(D,V,...)  is the
  1134         -** configuration verb - an integer code that indicates what
  1135         -** aspect of the [database connection] is being configured.
  1136         -** The only choice for this value is [SQLITE_DBCONFIG_LOOKASIDE].
  1137         -** New verbs are likely to be added in future releases of SQLite.
  1138         -** Additional arguments depend on the verb.
         1131  +** [SQLITE_DBCONIG_LOOKASIDE | configuration verb] - an integer code 
         1132  +** that indicates what aspect of the [database connection] is being configured.
         1133  +** Subsequent arguments vary depending on the configuration verb.
  1139   1134   **
  1140   1135   ** ^Calls to sqlite3_db_config() return SQLITE_OK if and only if
  1141   1136   ** the call is considered successful.
  1142   1137   */
  1143   1138   int sqlite3_db_config(sqlite3*, int op, ...);
  1144   1139   
  1145   1140   /*
................................................................................
  1479   1474   ** connection is not currently using lookaside memory, or in other words
  1480   1475   ** when the "current value" returned by
  1481   1476   ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
  1482   1477   ** Any attempt to change the lookaside memory configuration when lookaside
  1483   1478   ** memory is in use leaves the configuration unchanged and returns 
  1484   1479   ** [SQLITE_BUSY].)^</dd>
  1485   1480   **
         1481  +** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt>
         1482  +** <dd> ^This option is used to enable or disable the enforcement of
         1483  +** [foreign key constraints].  There should be two additional arguments.
         1484  +** The first argument is an integer which is 0 to disable FK enforcement,
         1485  +** positive to enable FK enforcement or negative to leave FK enforcement
         1486  +** unchanged.  The second parameter is a pointer to an integer into which
         1487  +** is written 0 or 1 to indicate whether FK enforcement is off or on
         1488  +** following this call.  The second parameter may be a NULL pointer, in
         1489  +** which case the FK enforcement setting is not reported back. </dd>
         1490  +**
         1491  +** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt>
         1492  +** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers].
         1493  +** There should be two additional arguments.
         1494  +** The first argument is an integer which is 0 to disable triggers,
         1495  +** positive to enable trigers or negative to leave the setting unchanged.
         1496  +** The second parameter is a pointer to an integer into which
         1497  +** is written 0 or 1 to indicate whether triggers are disabled or enabled
         1498  +** following this call.  The second parameter may be a NULL pointer, in
         1499  +** which case the trigger setting is not reported back. </dd>
         1500  +**
  1486   1501   ** </dl>
  1487   1502   */
  1488         -#define SQLITE_DBCONFIG_LOOKASIDE    1001  /* void* int int */
         1503  +#define SQLITE_DBCONFIG_LOOKASIDE       1001  /* void* int int */
         1504  +#define SQLITE_DBCONFIG_ENABLE_FKEY     1002  /* int int* */
         1505  +#define SQLITE_DBCONFIG_ENABLE_TRIGGER  1003  /* int int* */
  1489   1506   
  1490   1507   
  1491   1508   /*
  1492   1509   ** CAPI3REF: Enable Or Disable Extended Result Codes
  1493   1510   **
  1494   1511   ** ^The sqlite3_extended_result_codes() routine enables or disables the
  1495   1512   ** [extended result codes] feature of SQLite. ^The extended result

Changes to src/sqliteInt.h.

   927    927   #define SQLITE_RecoveryMode   0x00800000  /* Ignore schema errors */
   928    928   #define SQLITE_ReverseOrder   0x01000000  /* Reverse unordered SELECTs */
   929    929   #define SQLITE_RecTriggers    0x02000000  /* Enable recursive triggers */
   930    930   #define SQLITE_ForeignKeys    0x04000000  /* Enforce foreign key constraints  */
   931    931   #define SQLITE_AutoIndex      0x08000000  /* Enable automatic indexes */
   932    932   #define SQLITE_PreferBuiltin  0x10000000  /* Preference to built-in funcs */
   933    933   #define SQLITE_LoadExtension  0x20000000  /* Enable load_extension */
          934  +#define SQLITE_EnableTrigger  0x40000000  /* True to enable triggers */
   934    935   
   935    936   /*
   936    937   ** Bits of the sqlite3.flags field that are used by the
   937    938   ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
   938    939   ** These must be the low-order bits of the flags field.
   939    940   */
   940    941   #define SQLITE_QueryFlattener 0x01        /* Disable query flattening */

Changes to src/trigger.c.

   619    619     Parse *pParse,          /* Parse context */
   620    620     Table *pTab,            /* The table the contains the triggers */
   621    621     int op,                 /* one of TK_DELETE, TK_INSERT, TK_UPDATE */
   622    622     ExprList *pChanges,     /* Columns that change in an UPDATE statement */
   623    623     int *pMask              /* OUT: Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
   624    624   ){
   625    625     int mask = 0;
   626         -  Trigger *pList = sqlite3TriggerList(pParse, pTab);
          626  +  Trigger *pList = 0;
   627    627     Trigger *p;
          628  +
          629  +  if( (pParse->db->flags & SQLITE_EnableTrigger)!=0 ){
          630  +    pList = sqlite3TriggerList(pParse, pTab);
          631  +  }
   628    632     assert( pList==0 || IsVirtual(pTab)==0 );
   629    633     for(p=pList; p; p=p->pNext){
   630    634       if( p->op==op && checkColumnOverlap(p->pColumns, pChanges) ){
   631    635         mask |= p->tr_tm;
   632    636       }
   633    637     }
   634    638     if( pMask ){