/ Check-in [634ef4fc]
Login

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

Overview
Comment:Add asserts as evidence that all FK constraints are either immediate or deferred.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 634ef4fc9f4051245b38f558bb1c733031548c2f
User & Date: drh 2009-10-12 22:30:49
Context
2009-10-13
10:39
Add further test cases to e_fkey.test. check-in: c85e5874 user: dan tags: trunk
2009-10-12
22:30
Add asserts as evidence that all FK constraints are either immediate or deferred. check-in: 634ef4fc user: drh tags: trunk
20:01
When processing FK constraints on changes to parent tables, make sure the names of child tables appear correctly in the output of EXPLAIN QUERY PLAN. check-in: a4ab5215 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  2263   2263   ** accordingly.
  2264   2264   */
  2265   2265   void sqlite3DeferForeignKey(Parse *pParse, int isDeferred){
  2266   2266   #ifndef SQLITE_OMIT_FOREIGN_KEY
  2267   2267     Table *pTab;
  2268   2268     FKey *pFKey;
  2269   2269     if( (pTab = pParse->pNewTable)==0 || (pFKey = pTab->pFKey)==0 ) return;
  2270         -  assert( isDeferred==0 || isDeferred==1 );
         2270  +  assert( isDeferred==0 || isDeferred==1 ); /* EV: R-30323-21917 */
  2271   2271     pFKey->isDeferred = (u8)isDeferred;
  2272   2272   #endif
  2273   2273   }
  2274   2274   
  2275   2275   /*
  2276   2276   ** Generate code that will erase and refill index *pIdx.  This is
  2277   2277   ** used to initialize a newly created index or to recompute the

Changes to src/fkey.c.

  1174   1174   
  1175   1175       /* Delete any triggers created to implement actions for this FK. */
  1176   1176   #ifndef SQLITE_OMIT_TRIGGER
  1177   1177       fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[0]);
  1178   1178       fkTriggerDelete(pTab->dbMem, pFKey->apTrigger[1]);
  1179   1179   #endif
  1180   1180   
  1181         -    /* Delete the memory allocated for the FK structure. */
         1181  +    /* EV: R-30323-21917 Each foreign key constraint in SQLite is
         1182  +    ** classified as either immediate or deferred.
         1183  +    */
         1184  +    assert( pFKey->isDeferred==0 || pFKey->isDeferred==1 );
         1185  +
  1182   1186       pNext = pFKey->pNextFrom;
  1183   1187       sqlite3DbFree(pTab->dbMem, pFKey);
  1184   1188     }
  1185   1189   }
  1186   1190   #endif /* ifndef SQLITE_OMIT_FOREIGN_KEY */

Changes to src/sqliteInt.h.

  1285   1285   struct FKey {
  1286   1286     Table *pFrom;     /* Table containing the REFERENCES clause (aka: Child) */
  1287   1287     FKey *pNextFrom;  /* Next foreign key in pFrom */
  1288   1288     char *zTo;        /* Name of table that the key points to (aka: Parent) */
  1289   1289     FKey *pNextTo;    /* Next foreign key on table named zTo */
  1290   1290     FKey *pPrevTo;    /* Previous foreign key on table named zTo */
  1291   1291     int nCol;         /* Number of columns in this key */
         1292  +  /* EV: R-30323-21917 */
  1292   1293     u8 isDeferred;    /* True if constraint checking is deferred till COMMIT */
  1293   1294     u8 aAction[2];          /* ON DELETE and ON UPDATE actions, respectively */
  1294   1295     Trigger *apTrigger[2];  /* Triggers for aAction[] actions */
  1295   1296     struct sColMap {  /* Mapping of columns in pFrom to columns in zTo */
  1296   1297       int iFrom;         /* Index of column in pFrom */
  1297   1298       char *zCol;        /* Name of column in zTo.  If 0 use PRIMARY KEY */
  1298   1299     } aCol[1];        /* One entry for each of nCol column s */