/ Check-in [8a4195c7]
Login

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

Overview
Comment:Style fixes to triggers code in various *.c files (partial fix to ticket #39) (CVS 571)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8a4195c7466962291a296e8f53034ea8cb25005f
User & Date: danielk1977 2002-05-19 23:43:13
Context
2002-05-21
11:38
Additional code cleanup resulting from a review of the new trigger code. (CVS 572) check-in: 37dbdd55 user: drh tags: trunk
2002-05-19
23:43
Style fixes to triggers code in various *.c files (partial fix to ticket #39) (CVS 571) check-in: 8a4195c7 user: danielk1977 tags: trunk
2002-05-17
00:05
Stylistic changes to src/trigger.c (partial fix to ticket #39). Also more comments. (CVS 570) check-in: b1d72cb5 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    21     21   **     COPY
    22     22   **     VACUUM
    23     23   **     BEGIN TRANSACTION
    24     24   **     COMMIT
    25     25   **     ROLLBACK
    26     26   **     PRAGMA
    27     27   **
    28         -** $Id: build.c,v 1.90 2002/05/15 12:45:43 drh Exp $
           28  +** $Id: build.c,v 1.91 2002/05/19 23:43:14 danielk1977 Exp $
    29     29   */
    30     30   #include "sqliteInt.h"
    31     31   #include <ctype.h>
    32     32   
    33     33   /*
    34     34   ** This routine is called after a single SQL statement has been
    35     35   ** parsed and we want to execute the VDBE code to implement 
................................................................................
   255    255     for(pElem=sqliteHashFirst(&db->trigHash); pElem; pElem=sqliteHashNext(pElem)){
   256    256       Trigger *pTrigger = sqliteHashData(pElem);
   257    257       pTrigger->isCommit = 1;
   258    258     }
   259    259   
   260    260     /* Delete the structures for triggers removed this transaction */
   261    261     pElem = sqliteHashFirst(&db->trigDrop);
   262         -  while (pElem) {
          262  +  while( pElem ){
   263    263       Trigger *pTrigger = sqliteHashData(pElem);
   264    264       sqliteDeleteTrigger(pTrigger);
   265    265       pElem = sqliteHashNext(pElem);
   266    266     }
   267    267     sqliteHashClear(&db->trigDrop);
   268    268   
   269    269     db->flags &= ~SQLITE_InternChanges;
................................................................................
   319    319       pOld = sqliteHashInsert(&db->idxHash, p->zName, strlen(p->zName)+1, p);
   320    320       assert( pOld==0 || pOld==p );
   321    321     }
   322    322     sqliteHashClear(&db->idxDrop);
   323    323   
   324    324     /* Remove any triggers that haven't been commited yet */
   325    325     for(pElem = sqliteHashFirst(&db->trigHash); pElem; 
   326         -      pElem = (pElem?sqliteHashNext(pElem):0)) {
          326  +      pElem = (pElem?sqliteHashNext(pElem):0)){
   327    327       Trigger *pTrigger = sqliteHashData(pElem);
   328    328       if( !pTrigger->isCommit ){
   329    329         Table *pTbl = sqliteFindTable(db, pTrigger->table);
   330    330         if( pTbl ){
   331    331           if( pTbl->pTrigger == pTrigger ){
   332    332             pTbl->pTrigger = pTrigger->pNext;
   333    333           }else{
   334    334             Trigger *cc = pTbl->pTrigger;
   335    335             while( cc ){
   336         -            if (cc->pNext == pTrigger) {
          336  +            if( cc->pNext == pTrigger ){
   337    337                 cc->pNext = cc->pNext->pNext;
   338    338                 break;
   339    339               }
   340    340               cc = cc->pNext;
   341    341             }
   342    342             assert(cc);
   343    343           }
................................................................................
   347    347         sqliteDeleteTrigger(pTrigger);
   348    348         pElem = sqliteHashFirst(&db->trigHash);
   349    349       }
   350    350     }
   351    351   
   352    352     /* Any triggers that were dropped - put 'em back in place */
   353    353     for(pElem = sqliteHashFirst(&db->trigDrop); pElem; 
   354         -      pElem = sqliteHashNext(pElem)) {
   355         -    Trigger * pTrigger = sqliteHashData(pElem);
   356         -    Table * tab = sqliteFindTable(db, pTrigger->table);
          354  +      pElem = sqliteHashNext(pElem)){
          355  +    Trigger *pTrigger = sqliteHashData(pElem);
          356  +    Table *pTbl = sqliteFindTable(db, pTrigger->table);
   357    357       sqliteHashInsert(&db->trigHash, pTrigger->name, 
   358    358           strlen(pTrigger->name) + 1, pTrigger);
   359         -    pTrigger->pNext = tab->pTrigger;
   360         -    tab->pTrigger = pTrigger;
          359  +    pTrigger->pNext = pTbl->pTrigger;
          360  +    pTbl->pTrigger = pTrigger;
   361    361     }
   362    362   
   363    363     sqliteHashClear(&db->trigDrop);
   364    364     db->flags &= ~SQLITE_InternChanges;
   365    365   }
   366    366   
   367    367   /*
................................................................................
  1751   1751   ** Generate code that concludes an operation that may have changed
  1752   1752   ** the database.  This is a companion function to BeginWriteOperation().
  1753   1753   ** If a transaction was started, then commit it.  If a checkpoint was
  1754   1754   ** started then commit that.
  1755   1755   */
  1756   1756   void sqliteEndWriteOperation(Parse *pParse){
  1757   1757     Vdbe *v;
  1758         -  if (pParse->trigStack) return; /* if this is in a trigger */
         1758  +  if( pParse->trigStack ) return; /* if this is in a trigger */
  1759   1759     v = sqliteGetVdbe(pParse);
  1760   1760     if( v==0 ) return;
  1761   1761     if( pParse->db->flags & SQLITE_InTrans ){
  1762   1762       /* Do Nothing */
  1763   1763     }else{
  1764   1764       sqliteVdbeAddOp(v, OP_Commit, 0, 0);
  1765   1765     }

Changes to src/delete.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle DELETE FROM statements.
    14     14   **
    15         -** $Id: delete.c,v 1.32 2002/05/15 11:44:14 drh Exp $
           15  +** $Id: delete.c,v 1.33 2002/05/19 23:43:14 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Given a table name, find the corresponding table and make sure the
    22     22   ** table is writeable.  Generate an error and return NULL if not.  If
................................................................................
    90     90     if( pParse->nErr || sqlite_malloc_failed ){
    91     91       pTabList = 0;
    92     92       goto delete_from_cleanup;
    93     93     }
    94     94     db = pParse->db;
    95     95   
    96     96     /* Check for the special case of a VIEW with one or more ON DELETE triggers 
    97         -   * defined 
    98         -   */
           97  +  ** defined 
           98  +  */
    99     99     {
   100         -    Table * pTab;
   101         -    char * zTab = sqliteTableNameFromToken(pTableName);
          100  +    Table *pTab;
          101  +    char *zTab = sqliteTableNameFromToken(pTableName);
   102    102   
   103         -    if(zTab != 0) {
          103  +    if( zTab != 0 ){
   104    104         pTab = sqliteFindTable(pParse->db, zTab);
   105         -      if (pTab) {
          105  +      if( pTab ){
   106    106           row_triggers_exist = 
   107    107             sqliteTriggersExist(pParse, pTab->pTrigger, 
   108    108                 TK_DELETE, TK_BEFORE, TK_ROW, 0) ||
   109    109             sqliteTriggersExist(pParse, pTab->pTrigger, 
   110    110                 TK_DELETE, TK_AFTER, TK_ROW, 0);
   111    111         }
   112    112         sqliteFree(zTab);
   113         -      if (row_triggers_exist &&  pTab->pSelect ) {
          113  +      if( row_triggers_exist &&  pTab->pSelect ){
   114    114           /* Just fire VIEW triggers */
   115    115           sqliteViewTriggers(pParse, pTab, pWhere, OE_Replace, 0);
   116    116           return;
   117    117         }
   118    118       }
   119    119     }
   120    120   
................................................................................
   125    125     */
   126    126     pTabList = sqliteTableTokenToIdList(pParse, pTableName);
   127    127     if( pTabList==0 ) goto delete_from_cleanup;
   128    128     assert( pTabList->nId==1 );
   129    129     pTab = pTabList->a[0].pTab;
   130    130     assert( pTab->pSelect==0 );  /* This table is not a view */
   131    131   
   132         -  if (row_triggers_exist) 
          132  +  if( row_triggers_exist ){ 
   133    133       oldIdx = pParse->nTab++;
          134  +  }
   134    135   
   135    136     /* Resolve the column names in all the expressions.
   136    137     */
   137    138     base = pParse->nTab++;
   138    139     if( pWhere ){
   139    140       if( sqliteExprResolveIds(pParse, base, pTabList, 0, pWhere) ){
   140    141         goto delete_from_cleanup;
................................................................................
   143    144         goto delete_from_cleanup;
   144    145       }
   145    146     }
   146    147   
   147    148     /* Begin generating code.
   148    149     */
   149    150     v = sqliteGetVdbe(pParse);
   150         -  if( v==0 ) goto delete_from_cleanup;
   151         -  if (row_triggers_exist) 
          151  +  if( v==0 ){
          152  +    goto delete_from_cleanup;
          153  +  }
          154  +  if( row_triggers_exist ){ 
   152    155       sqliteBeginMultiWriteOperation(pParse);
   153         -  else 
          156  +  } else {
   154    157       sqliteBeginWriteOperation(pParse);
          158  +  }
   155    159   
   156    160     /* Initialize the counter of the number of rows deleted, if
   157    161     ** we are counting rows.
   158    162     */
   159    163     if( db->flags & SQLITE_CountRows ){
   160    164       sqliteVdbeAddOp(v, OP_Integer, 0, 0);
   161    165     }
   162    166   
   163    167     /* Special case: A DELETE without a WHERE clause deletes everything.
   164    168     ** It is easier just to erase the whole table.
   165    169     */
   166         -  if( pWhere==0 && !row_triggers_exist){
          170  +  if( pWhere==0 && !row_triggers_exist ){
   167    171       if( db->flags & SQLITE_CountRows ){
   168    172         /* If counting rows deleted, just count the total number of
   169    173         ** entries in the table. */
   170    174         int endOfLoop = sqliteVdbeMakeLabel(v);
   171    175         int addr;
   172    176         openOp = pTab->isTemp ? OP_OpenAux : OP_Open;
   173    177         assert( base==0 );
................................................................................
   207    211       /* Delete every item whose key was written to the list during the
   208    212       ** database scan.  We have to delete items after the scan is complete
   209    213       ** because deleting an item can change the scan order.
   210    214       */
   211    215       sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
   212    216       end = sqliteVdbeMakeLabel(v);
   213    217   
   214         -    if (row_triggers_exist) {
          218  +    if( row_triggers_exist ){
   215    219         int ii;
   216    220         addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
   217    221         sqliteVdbeAddOp(v, OP_Dup, 0, 0);
   218    222   
   219    223         openOp = pTab->isTemp ? OP_OpenAux : OP_Open;
   220    224         sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
   221    225         sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
   222    226         sqliteVdbeAddOp(v, OP_OpenTemp, oldIdx, 0);
   223    227   
   224    228         sqliteVdbeAddOp(v, OP_Integer, 13, 0);
   225         -      for (ii = 0; ii < pTab->nCol; ii++) {
   226         -        if (ii == pTab->iPKey) 
          229  +      for(ii = 0; ii<pTab->nCol; ii++){
          230  +        if( ii==pTab->iPKey ){ 
   227    231             sqliteVdbeAddOp(v, OP_Recno, base, 0);
   228         -        else
          232  +	} else {
   229    233             sqliteVdbeAddOp(v, OP_Column, base, ii);
          234  +	}
   230    235         }
   231    236         sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
   232    237         sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
   233    238         sqliteVdbeAddOp(v, OP_Close, base, 0);
   234    239         sqliteVdbeAddOp(v, OP_Rewind, oldIdx, 0);
   235    240   
   236    241         sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1, 
................................................................................
   240    245       pParse->nTab = base + 1;
   241    246       openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
   242    247       sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
   243    248       for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
   244    249         sqliteVdbeAddOp(v, openOp, pParse->nTab++, pIdx->tnum);
   245    250       }
   246    251   
   247         -    if (!row_triggers_exist) 
          252  +    if( !row_triggers_exist ){ 
   248    253         addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
          254  +    }
   249    255   
   250    256       sqliteGenerateRowDelete(v, pTab, base, pParse->trigStack?0:1);
   251    257   
   252         -    if (row_triggers_exist) {
          258  +    if( row_triggers_exist ){
   253    259         for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
   254    260           sqliteVdbeAddOp(v, OP_Close, base + i, pIdx->tnum);
   255    261         }
   256    262         sqliteVdbeAddOp(v, OP_Close, base, 0);
   257    263         sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1, 
   258    264             oldIdx, (pParse->trigStack)?pParse->trigStack->orconf:OE_Default);
   259    265       }
   260    266   
   261    267       sqliteVdbeAddOp(v, OP_Goto, 0, addr);
   262    268       sqliteVdbeResolveLabel(v, end);
   263    269       sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
   264    270   
   265         -    if (!row_triggers_exist) {
          271  +    if( !row_triggers_exist ){
   266    272         for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
   267    273           sqliteVdbeAddOp(v, OP_Close, base + i, pIdx->tnum);
   268    274         }
   269    275         sqliteVdbeAddOp(v, OP_Close, base, 0);
   270    276         pParse->nTab = base;
   271    277       }
   272    278     }

Changes to src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.59 2002/05/15 08:30:13 danielk1977 Exp $
           15  +** $Id: expr.c,v 1.60 2002/05/19 23:43:14 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Construct a new expression node and return a pointer to it.  Memory
    22     22   ** for this node is obtained from sqliteMalloc().  The calling function
................................................................................
   480    480               }
   481    481             }
   482    482           }
   483    483         }
   484    484   
   485    485         /* If we have not already resolved this *.* expression, then maybe 
   486    486          * it is a new.* or old.* trigger argument reference */
   487         -      if (cnt == 0 && pParse->trigStack != 0) {
   488         -        TriggerStack * tt = pParse->trigStack;
   489         -        int j;
          487  +      if( cnt == 0 && pParse->trigStack != 0 ){
          488  +        TriggerStack *pTriggerStack = pParse->trigStack;
   490    489           int t = 0;
   491         -        if (tt->newIdx != -1 && sqliteStrICmp("new", zLeft) == 0) {
   492         -          pExpr->iTable = tt->newIdx;
          490  +        if( pTriggerStack->newIdx != -1 && sqliteStrICmp("new", zLeft) == 0 ){
          491  +          pExpr->iTable = pTriggerStack->newIdx;
   493    492             cntTab++;
   494    493             t = 1;
   495    494           }
   496         -        if (tt->oldIdx != -1 && sqliteStrICmp("old", zLeft) == 0) {
   497         -          pExpr->iTable = tt->oldIdx;
          495  +        if( pTriggerStack->oldIdx != -1 && sqliteStrICmp("old", zLeft) == 0 ){
          496  +          pExpr->iTable = pTriggerStack->oldIdx;
   498    497             cntTab++;
   499    498             t = 1;
   500    499           }
   501    500   
   502         -        if (t) 
   503         -          for(j=0; j<tt->pTab->nCol; j++) {
   504         -            if( sqliteStrICmp(tt->pTab->aCol[j].zName, zRight)==0 ){
          501  +        if( t ){ 
          502  +	  int j;
          503  +          for(j=0; j < pTriggerStack->pTab->nCol; j++) {
          504  +            if( sqliteStrICmp(pTriggerStack->pTab->aCol[j].zName, zRight)==0 ){
   505    505                 cnt++;
   506    506                 pExpr->iColumn = j;
   507    507               }
   508    508             }
          509  +	}
   509    510         }
   510    511   
   511    512         if( cnt==0 && cntTab==1 && sqliteIsRowid(zRight) ){
   512    513           cnt = 1;
   513    514           pExpr->iColumn = -1;
   514    515         }
   515    516         sqliteFree(zLeft);

Changes to src/insert.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle INSERT statements in SQLite.
    14     14   **
    15         -** $Id: insert.c,v 1.54 2002/05/15 11:44:14 drh Exp $
           15  +** $Id: insert.c,v 1.55 2002/05/19 23:43:14 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** This routine is call to handle SQL of the following forms:
    21     21   **
    22     22   **    insert into TABLE (IDLIST) values(EXPRLIST)
................................................................................
    98     98     if( pSelect || row_triggers_exist ){
    99     99       sqliteBeginMultiWriteOperation(pParse);
   100    100     }else{
   101    101       sqliteBeginWriteOperation(pParse);
   102    102     }
   103    103   
   104    104     /* if there are row triggers, allocate a temp table for new.* references. */
   105         -  if (row_triggers_exist)
          105  +  if( row_triggers_exist ){
   106    106       newIdx = pParse->nTab++;
          107  +  }
   107    108   
   108    109     /* Figure out how many columns of data are supplied.  If the data
   109    110     ** is coming from a SELECT statement, then this step has to generate
   110    111     ** all the code to implement the SELECT statement and leave the data
   111    112     ** in a temporary table.  If data is coming from an expression list,
   112    113     ** then we just have to count the number of expressions.
   113    114     */
................................................................................
   200    201     ** in the original table definition.
   201    202     */
   202    203     if( pColumn==0 ){
   203    204       keyColumn = pTab->iPKey;
   204    205     }
   205    206   
   206    207     /* Open the temp table for FOR EACH ROW triggers */
   207         -  if (row_triggers_exist)
          208  +  if( row_triggers_exist ){
   208    209       sqliteVdbeAddOp(v, OP_OpenTemp, newIdx, 0);
          210  +  }
   209    211       
   210    212     /* Initialize the count of rows to be inserted
   211    213     */
   212         -  if( db->flags & SQLITE_CountRows && !pParse->trigStack){
          214  +  if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
   213    215       sqliteVdbeAddOp(v, OP_Integer, 0, 0);  /* Initialize the row count */
   214    216     }
   215    217   
   216    218     /* Open tables and indices if there are no row triggers */
   217         -  if (!row_triggers_exist) {
          219  +  if( !row_triggers_exist ){
   218    220       base = pParse->nTab;
   219    221       openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
   220    222       sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
   221    223       sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
   222    224       for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
   223    225         sqliteVdbeAddOp(v, openOp, idx+base, pIdx->tnum);
   224    226         sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC);
................................................................................
   233    235     */
   234    236     if( srcTab>=0 ){
   235    237       iBreak = sqliteVdbeMakeLabel(v);
   236    238       sqliteVdbeAddOp(v, OP_Rewind, srcTab, iBreak);
   237    239       iCont = sqliteVdbeCurrentAddr(v);
   238    240     }
   239    241   
   240         -  if (row_triggers_exist) {
          242  +  if( row_triggers_exist ){
   241    243   
   242    244       /* build the new.* reference row */
   243    245       sqliteVdbeAddOp(v, OP_Integer, 13, 0);
   244    246       for(i=0; i<pTab->nCol; i++){
   245    247         if( pColumn==0 ){
   246    248           j = i;
   247    249         }else{
................................................................................
   259    261         }
   260    262       }
   261    263       sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
   262    264       sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
   263    265       sqliteVdbeAddOp(v, OP_Rewind, newIdx, 0);
   264    266   
   265    267       /* Fire BEFORE triggers */
   266         -    if (
   267         -    sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab, newIdx, -1, 
   268         -        onError)
   269         -       ) goto insert_cleanup;
          268  +    if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_BEFORE, pTab, newIdx, -1, 
          269  +        onError) ){
          270  +      goto insert_cleanup;
          271  +    }
   270    272   
   271    273       /* Open the tables and indices for the INSERT */
   272         -    if (!pTab->pSelect) {
          274  +    if( !pTab->pSelect ){
   273    275         base = pParse->nTab;
   274    276         openOp = pTab->isTemp ? OP_OpenWrAux : OP_OpenWrite;
   275    277         sqliteVdbeAddOp(v, openOp, base, pTab->tnum);
   276    278         sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
   277    279         for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
   278    280           sqliteVdbeAddOp(v, openOp, idx+base, pIdx->tnum);
   279    281           sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC);
................................................................................
   283    285     }
   284    286   
   285    287     /* Push the record number for the new entry onto the stack.  The
   286    288     ** record number is a randomly generate integer created by NewRecno
   287    289     ** except when the table has an INTEGER PRIMARY KEY column, in which
   288    290     ** case the record number is the same as that column. 
   289    291     */
   290         -  if (!pTab->pSelect) {
          292  +  if( !pTab->pSelect ){
   291    293       if( keyColumn>=0 ){
   292    294         if( srcTab>=0 ){
   293    295           sqliteVdbeAddOp(v, OP_Column, srcTab, keyColumn);
   294    296         }else{
   295    297           int addr;
   296    298           sqliteExprCode(pParse, pList->a[keyColumn].pExpr);
   297    299   
   298    300           /* If the PRIMARY KEY expression is NULL, then use OP_NewRecno
   299         -         ** to generate a unique primary key value.
   300         -         */
          301  +        ** to generate a unique primary key value.
          302  +        */
   301    303           addr = sqliteVdbeAddOp(v, OP_Dup, 0, 1);
   302    304           sqliteVdbeAddOp(v, OP_NotNull, 0, addr+4);
   303    305           sqliteVdbeAddOp(v, OP_Pop, 1, 0);
   304    306           sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
   305    307         }
   306    308         sqliteVdbeAddOp(v, OP_MustBeInt, 0, 0);
   307    309       }else{
   308    310         sqliteVdbeAddOp(v, OP_NewRecno, base, 0);
   309    311       }
   310    312   
   311    313       /* Push onto the stack, data for all columns of the new entry, beginning
   312         -     ** with the first column.
   313         -     */
          314  +    ** with the first column.
          315  +    */
   314    316       for(i=0; i<pTab->nCol; i++){
   315    317         if( i==pTab->iPKey ){
   316    318           /* The value of the INTEGER PRIMARY KEY column is always a NULL.
   317         -         ** Whenever this column is read, the record number will be substituted
   318         -         ** in its place.  So will fill this column with a NULL to avoid
   319         -         ** taking up data space with information that will never be used. */
          319  +        ** Whenever this column is read, the record number will be substituted
          320  +        ** in its place.  So will fill this column with a NULL to avoid
          321  +        ** taking up data space with information that will never be used. */
   320    322           sqliteVdbeAddOp(v, OP_String, 0, 0);
   321    323           continue;
   322    324         }
   323    325         if( pColumn==0 ){
   324    326           j = i;
   325    327         }else{
   326    328           for(j=0; j<pColumn->nId; j++){
................................................................................
   334    336           sqliteVdbeAddOp(v, OP_Column, srcTab, j); 
   335    337         }else{
   336    338           sqliteExprCode(pParse, pList->a[j].pExpr);
   337    339         }
   338    340       }
   339    341   
   340    342       /* Generate code to check constraints and generate index keys and
   341         -     ** do the insertion.
   342         -     */
          343  +    ** do the insertion.
          344  +    */
   343    345       endOfLoop = sqliteVdbeMakeLabel(v);
   344    346       sqliteGenerateConstraintChecks(pParse, pTab, base, 0,0,0,onError,endOfLoop);
   345    347       sqliteCompleteInsertion(pParse, pTab, base, 0,0,0);
   346    348   
   347    349       /* Update the count of rows that are inserted
   348         -     */
          350  +    */
   349    351       if( (db->flags & SQLITE_CountRows)!=0 && !pParse->trigStack){
   350    352         sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
   351    353       }
   352    354     }
   353    355   
   354         -  if (row_triggers_exist) {
          356  +  if( row_triggers_exist ){
   355    357       /* Close all tables opened */
   356         -    if (!pTab->pSelect) {
          358  +    if( !pTab->pSelect ){
   357    359         sqliteVdbeAddOp(v, OP_Close, base, 0);
   358    360         for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
   359    361           sqliteVdbeAddOp(v, OP_Close, idx+base, 0);
   360    362         }
   361    363       }
   362    364   
   363    365       /* Code AFTER triggers */
   364         -    if (
   365         -        sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_AFTER, pTab, newIdx, -1, 
   366         -          onError)
   367         -       ) goto insert_cleanup;
          366  +    if( sqliteCodeRowTrigger(pParse, TK_INSERT, 0, TK_AFTER, pTab, newIdx, -1, 
          367  +          onError) ){
          368  +      goto insert_cleanup;
          369  +    }
   368    370     }
   369    371   
   370    372     /* The bottom of the loop, if the data source is a SELECT statement
   371         -   */
          373  +  */
   372    374     sqliteVdbeResolveLabel(v, endOfLoop);
   373    375     if( srcTab>=0 ){
   374    376       sqliteVdbeAddOp(v, OP_Next, srcTab, iCont);
   375    377       sqliteVdbeResolveLabel(v, iBreak);
   376    378       sqliteVdbeAddOp(v, OP_Close, srcTab, 0);
   377    379     }
   378    380   
   379         -  if (!row_triggers_exist) {
          381  +  if( !row_triggers_exist ){
   380    382       /* Close all tables opened */
   381    383       sqliteVdbeAddOp(v, OP_Close, base, 0);
   382    384       for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
   383    385         sqliteVdbeAddOp(v, OP_Close, idx+base, 0);
   384    386       }
   385    387     }
   386    388   
   387    389     sqliteEndWriteOperation(pParse);
   388    390   
   389    391     /*
   390         -   ** Return the number of rows inserted.
          392  +  ** Return the number of rows inserted.
   391    393     */
   392    394     if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
   393    395       sqliteVdbeAddOp(v, OP_ColumnCount, 1, 0);
   394    396       sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
   395    397       sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
   396    398       sqliteVdbeAddOp(v, OP_Callback, 1, 0);
   397    399     }

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.74 2002/05/15 14:17:45 drh Exp $
           17  +** $Id: main.c,v 1.75 2002/05/19 23:43:14 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** This is the callback routine for the code that initializes the
................................................................................
   390    390     assert( sqliteHashFirst(&db->tblDrop)==0 ); /* There can not be uncommitted */
   391    391     assert( sqliteHashFirst(&db->idxDrop)==0 ); /*   DROP TABLEs or DROP INDEXs */
   392    392     temp1 = db->tblHash;
   393    393     temp2 = db->trigHash;
   394    394     sqliteHashInit(&db->trigHash, SQLITE_HASH_STRING, 0);
   395    395     sqliteHashClear(&db->idxHash);
   396    396   
   397         -  for (pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
          397  +  for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
   398    398       Trigger * pTrigger = sqliteHashData(pElem);
   399    399       Table *pTab = sqliteFindTable(db, pTrigger->table);
   400    400       assert(pTab);
   401         -    if (pTab->isTemp) { 
          401  +    if( pTab->isTemp ){ 
   402    402         sqliteHashInsert(&db->trigHash, pTrigger->name, strlen(pTrigger->name), 
   403    403             pTrigger);
   404         -    } else {
          404  +    }else{
   405    405         sqliteDeleteTrigger(pTrigger);
   406    406       }
   407    407     }
   408    408     sqliteHashClear(&temp2);
   409    409   
   410    410     sqliteHashInit(&db->tblHash, SQLITE_HASH_STRING, 0);
   411    411   
................................................................................
   430    430           }
   431    431         }
   432    432       }else{
   433    433         sqliteDeleteTable(db, pTab);
   434    434       }
   435    435     }
   436    436     sqliteHashClear(&temp1);
   437         -
   438    437     db->flags &= ~SQLITE_Initialized;
   439    438   }
   440    439   
   441    440   /*
   442    441   ** Return the ROWID of the most recent insert
   443    442   */
   444    443   int sqlite_last_insert_rowid(sqlite *db){

Changes to src/trigger.c.

    76     76   
    77     77     nt->strings = sqliteStrNDup(zData, zDataLen);
    78     78     offset = (int)(nt->strings - zData);
    79     79   
    80     80     sqliteExprMoveStrings(nt->pWhen, offset);
    81     81   
    82     82     ss = nt->step_list;
    83         -  while (ss) {
           83  +  while( ss ){
    84     84       sqliteSelectMoveStrings(ss->pSelect, offset);
    85         -    if (ss->target.z) ss->target.z += offset;
           85  +    if( ss->target.z ){
           86  +      ss->target.z += offset;
           87  +    }
    86     88       sqliteExprMoveStrings(ss->pWhere, offset);
    87     89       sqliteExprListMoveStrings(ss->pExprList, offset);
    88     90   
    89     91       ss = ss->pNext;
    90     92     }
    91     93   
    92     94     /* if we are not initializing, and this trigger is not on a TEMP table, 
................................................................................
   126    128       /* Stick it in the hash-table */
   127    129       sqliteHashInsert(&(pParse->db->trigHash), nt->name, pName->n + 1, nt);
   128    130   
   129    131       /* Attach it to the table object */
   130    132       nt->pNext = tab->pTrigger;
   131    133       tab->pTrigger = nt;
   132    134       return;
   133         -  } else {
          135  +  }else{
   134    136       sqliteFree(nt->strings);
   135    137       sqliteFree(nt->name);
   136    138       sqliteFree(nt->table);
   137    139       sqliteFree(nt);
   138    140     }
   139    141   
   140    142   trigger_cleanup:
................................................................................
   142    144     sqliteIdListDelete(pColumns);
   143    145     sqliteExprDelete(pWhen);
   144    146     {
   145    147       TriggerStep * pp;
   146    148       TriggerStep * nn;
   147    149   
   148    150       pp = pStepList;
   149         -    while (pp) {
          151  +    while( pp ){
   150    152         nn = pp->pNext;
   151    153         sqliteExprDelete(pp->pWhere);
   152    154         sqliteExprListDelete(pp->pExprList);
   153    155         sqliteSelectDelete(pp->pSelect);
   154    156         sqliteIdListDelete(pp->pIdList);
   155    157         sqliteFree(pp);
   156    158         pp = nn;
................................................................................
   224    226   ** Recursively delete a Trigger structure
   225    227   */
   226    228   void sqliteDeleteTrigger(Trigger *pTrigger)
   227    229   {
   228    230     TriggerStep *pTriggerStep;
   229    231   
   230    232     pTriggerStep = pTrigger->step_list;
   231         -  while (pTriggerStep) {
          233  +  while( pTriggerStep ){
   232    234       TriggerStep * pTmp = pTriggerStep;
   233    235       pTriggerStep = pTriggerStep->pNext;
   234    236   
   235    237       sqliteExprDelete(pTmp->pWhere);
   236    238       sqliteExprListDelete(pTmp->pExprList);
   237    239       sqliteSelectDelete(pTmp->pSelect);
   238    240       sqliteIdListDelete(pTmp->pIdList);
................................................................................
   283    285      */
   284    286     if( !pParse->explain ){
   285    287       /* 1 */
   286    288       pTable = sqliteFindTable(pParse->db, pTrigger->table);
   287    289       assert(pTable);
   288    290       if( pTable->pTrigger == pTrigger ){
   289    291         pTable->pTrigger = pTrigger->pNext;
   290         -    } else {
          292  +    }else{
   291    293         Trigger *cc = pTable->pTrigger;
   292    294         while( cc ){ 
   293    295           if( cc->pNext == pTrigger ){
   294    296             cc->pNext = cc->pNext->pNext;
   295    297             break;
   296    298           }
   297    299           cc = cc->pNext;
................................................................................
   342    344   
   343    345     sqliteFree(zName);
   344    346   }
   345    347   
   346    348   static int checkColumnOverLap(IdList * pIdList, ExprList * pEList)
   347    349   {
   348    350     int i, e;
   349         -  if (!pIdList) return 1;
   350         -  if (!pEList) return 1;
          351  +  if( !pIdList )return 1;
          352  +  if( !pEList )return 1;
   351    353   
   352         -  for (i = 0; i < pIdList->nId; i++) 
   353         -    for (e = 0; e < pEList->nExpr; e++) 
   354         -      if (!sqliteStrICmp(pIdList->a[i].zName, pEList->a[e].zName))
          354  +  for(i = 0; i < pIdList->nId; i++){ 
          355  +    for(e = 0; e < pEList->nExpr; e++){ 
          356  +      if( !sqliteStrICmp(pIdList->a[i].zName, pEList->a[e].zName) ){
   355    357           return 1;
          358  +      }
          359  +    }
          360  +  }
   356    361   
   357    362     return 0; 
   358    363   }
   359    364   
   360    365   /* A global variable that is TRUE if we should always set up temp tables for
   361    366    * for triggers, even if there are no triggers to code. This is used to test 
   362    367    * how much overhead the triggers algorithm is causing.
................................................................................
   390    395     while( pTriggerCursor ){
   391    396       if( pTriggerCursor->op == op && 
   392    397   	pTriggerCursor->tr_tm == tr_tm && 
   393    398   	pTriggerCursor->foreach == foreach &&
   394    399   	checkColumnOverLap(pTriggerCursor->pColumns, pChanges) ){
   395    400         TriggerStack * ss;
   396    401         ss = pParse->trigStack;
   397         -      while (ss && ss->pTrigger != pTrigger) ss = ss->pNext;
   398         -      if (!ss) return 1;
          402  +      while( ss && ss->pTrigger != pTrigger ){
          403  +	ss = ss->pNext;
          404  +      }
          405  +      if( !ss )return 1;
   399    406       }
   400    407       pTriggerCursor = pTriggerCursor->pNext;
   401    408     }
   402    409   
   403    410     return 0;
   404    411   }
   405    412   
................................................................................
   489    496   
   490    497     assert(op == TK_UPDATE || op == TK_INSERT || op == TK_DELETE);
   491    498     assert(tr_tm == TK_BEFORE || tr_tm == TK_AFTER);
   492    499   
   493    500     assert(newIdx != -1 || oldIdx != -1);
   494    501   
   495    502     pTrigger = pTab->pTrigger;
   496         -  while (pTrigger) {
          503  +  while( pTrigger ){
   497    504       int fire_this = 0;
   498    505   
   499    506       /* determine whether we should code this trigger */
   500         -    if (pTrigger->op == op && pTrigger->tr_tm == tr_tm && 
   501         -        pTrigger->foreach == TK_ROW) {
          507  +    if( pTrigger->op == op && pTrigger->tr_tm == tr_tm && 
          508  +        pTrigger->foreach == TK_ROW ){
   502    509         fire_this = 1;
   503    510         pTriggerStack = pParse->trigStack;
   504         -      while (pTriggerStack) {
   505         -        if (pTriggerStack->pTrigger == pTrigger) fire_this = 0;
          511  +      while( pTriggerStack ){
          512  +        if( pTriggerStack->pTrigger == pTrigger ){
          513  +	  fire_this = 0;
          514  +	}
   506    515           pTriggerStack = pTriggerStack->pNext;
   507    516         }
   508         -      if (op == TK_UPDATE && pTrigger->pColumns &&
   509         -          !checkColumnOverLap(pTrigger->pColumns, pChanges))
          517  +      if( op == TK_UPDATE && pTrigger->pColumns &&
          518  +          !checkColumnOverLap(pTrigger->pColumns, pChanges) ){
   510    519           fire_this = 0;
          520  +      }
   511    521       }
   512    522   
   513         -    if (fire_this) {
          523  +    if( fire_this ){
   514    524         int endTrigger;
   515    525         IdList dummyTablist;
   516    526         Expr * whenExpr;
   517    527   
   518    528         dummyTablist.nId = 0;
   519    529         dummyTablist.a = 0;
   520    530   
................................................................................
   526    536         pTriggerStack->pTab = pTab;
   527    537         pTriggerStack->pNext = pParse->trigStack;
   528    538         pParse->trigStack = pTriggerStack;
   529    539   
   530    540         /* code the WHEN clause */
   531    541         endTrigger = sqliteVdbeMakeLabel(pParse->pVdbe);
   532    542         whenExpr = sqliteExprDup(pTrigger->pWhen);
   533         -      if (sqliteExprResolveIds(pParse, 0, &dummyTablist, 0, whenExpr)) {
          543  +      if( sqliteExprResolveIds(pParse, 0, &dummyTablist, 0, whenExpr) ){
   534    544           pParse->trigStack = pParse->trigStack->pNext;
   535    545           sqliteFree(pTriggerStack);
   536    546           sqliteExprDelete(whenExpr);
   537    547           return 1;
   538    548         }
   539    549         sqliteExprIfFalse(pParse, whenExpr, endTrigger);
   540    550         sqliteExprDelete(whenExpr);
................................................................................
   632    642       for(ii = 0; ii < pTab->nCol; ii++){
   633    643         aXRef[ii] = -1;
   634    644       }
   635    645   
   636    646       for(ii=0; ii<pChanges->nExpr; ii++){
   637    647         int jj;
   638    648         if( sqliteExprResolveIds(pParse, oldIdx, theSelect.pSrc , 0, 
   639         -            pChanges->a[ii].pExpr) )
          649  +            pChanges->a[ii].pExpr) ){
   640    650           goto trigger_cleanup;
          651  +      }
   641    652   
   642    653         if( sqliteExprCheck(pParse, pChanges->a[ii].pExpr, 0, 0) )
   643    654           goto trigger_cleanup;
   644    655   
   645    656         for(jj=0; jj<pTab->nCol; jj++){
   646    657           if( sqliteStrICmp(pTab->aCol[jj].zName, pChanges->a[ii].zName)==0 ){
   647    658             aXRef[jj] = ii;
................................................................................
   657    668       }
   658    669   
   659    670       sqliteVdbeAddOp(v, OP_Integer, 13, 0);
   660    671   
   661    672       for(ii = 0; ii<pTab->nCol; ii++){
   662    673         if( aXRef[ii] < 0 ){ 
   663    674           sqliteVdbeAddOp(v, OP_Column, oldIdx, ii);
   664         -      } else {
          675  +      }else{
   665    676           sqliteExprCode(pParse, pChanges->a[aXRef[ii]].pExpr);
   666    677         }
   667    678       }
   668    679   
   669    680       sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
   670    681       sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
   671    682       sqliteVdbeAddOp(v, OP_Rewind, newIdx, 0);
   672    683   
   673    684       sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, 
   674    685           pTab, newIdx, oldIdx, orconf);
   675    686       sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, 
   676    687           pTab, newIdx, oldIdx, orconf);
   677         -  } else {
          688  +  }else{
   678    689       sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_BEFORE, pTab, -1, oldIdx, 
   679    690           orconf);
   680    691       sqliteCodeRowTrigger(pParse, TK_DELETE, 0, TK_AFTER, pTab, -1, oldIdx, 
   681    692           orconf);
   682    693     }
   683    694   
   684    695     sqliteVdbeAddOp(v, OP_Next, oldIdx, startOfLoop);

Changes to src/update.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle UPDATE statements.
    14     14   **
    15         -** $Id: update.c,v 1.38 2002/05/15 11:44:15 drh Exp $
           15  +** $Id: update.c,v 1.39 2002/05/19 23:43:14 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Process an UPDATE statement.
    21     21   */
    22     22   void sqliteUpdate(
................................................................................
    55     55     if( pParse->nErr || sqlite_malloc_failed ) goto update_cleanup;
    56     56     db = pParse->db;
    57     57   
    58     58     /* Check for the special case of a VIEW with one or more ON UPDATE triggers 
    59     59      * defined 
    60     60      */
    61     61     {
    62         -    char * zTab = sqliteTableNameFromToken(pTableName);
           62  +    char *zTab = sqliteTableNameFromToken(pTableName);
    63     63   
    64         -    if(zTab != 0) {
           64  +    if( zTab != 0 ){
    65     65         pTab = sqliteFindTable(pParse->db, zTab);
    66         -      if (pTab) {
           66  +      if( pTab ){
    67     67           row_triggers_exist = 
    68     68             sqliteTriggersExist(pParse, pTab->pTrigger, 
    69     69                 TK_UPDATE, TK_BEFORE, TK_ROW, pChanges) ||
    70     70             sqliteTriggersExist(pParse, pTab->pTrigger, 
    71     71                 TK_UPDATE, TK_AFTER, TK_ROW, pChanges);
    72     72         }
    73     73         sqliteFree(zTab);
    74         -      if (row_triggers_exist &&  pTab->pSelect ) {
           74  +      if( row_triggers_exist &&  pTab->pSelect ){
    75     75           /* Just fire VIEW triggers */
    76     76           sqliteViewTriggers(pParse, pTab, pWhere, onError, pChanges);
    77     77           return;
    78     78         }
    79     79       }
    80     80     }
    81     81   
................................................................................
    88     88     if( pTabList==0 ) goto update_cleanup;
    89     89     pTab = pTabList->a[0].pTab;
    90     90     assert( pTab->pSelect==0 );  /* This table is not a VIEW */
    91     91     aXRef = sqliteMalloc( sizeof(int) * pTab->nCol );
    92     92     if( aXRef==0 ) goto update_cleanup;
    93     93     for(i=0; i<pTab->nCol; i++) aXRef[i] = -1;
    94     94   
    95         -  if (row_triggers_exist) {
           95  +  /* If there are FOR EACH ROW triggers, allocate temp tables */
           96  +  if( row_triggers_exist ){
    96     97       newIdx = pParse->nTab++;
    97     98       oldIdx = pParse->nTab++;
    98     99     }
    99    100   
   100    101     /* Resolve the column names in all the expressions in both the
   101    102     ** WHERE clause and in the new values.  Also find the column index
   102    103     ** for each column to be updated in the pChanges array.
................................................................................
   193    194   
   194    195     /* Initialize the count of updated rows
   195    196     */
   196    197     if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
   197    198       sqliteVdbeAddOp(v, OP_Integer, 0, 0);
   198    199     }
   199    200   
   200         -  if (row_triggers_exist) {
          201  +  if( row_triggers_exist ){
   201    202       int ii;
   202    203   
   203    204       sqliteVdbeAddOp(v, OP_OpenTemp, oldIdx, 0);
   204    205       sqliteVdbeAddOp(v, OP_OpenTemp, newIdx, 0);
   205    206   
   206    207       sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
   207    208       addr = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
................................................................................
   208    209       sqliteVdbeAddOp(v, OP_Dup, 0, 0);
   209    210   
   210    211       sqliteVdbeAddOp(v, OP_Dup, 0, 0);
   211    212       sqliteVdbeAddOp(v, OP_Open, base, pTab->tnum);
   212    213       sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
   213    214   
   214    215       sqliteVdbeAddOp(v, OP_Integer, 13, 0);
   215         -    for (ii = 0; ii < pTab->nCol; ii++) {
   216         -        if (ii == pTab->iPKey) 
   217         -            sqliteVdbeAddOp(v, OP_Recno, base, 0);
   218         -        else
   219         -            sqliteVdbeAddOp(v, OP_Column, base, ii);
          216  +    for(ii = 0; ii < pTab->nCol; ii++){
          217  +      if( ii == pTab->iPKey ){
          218  +	sqliteVdbeAddOp(v, OP_Recno, base, 0);
          219  +      }else{
          220  +	sqliteVdbeAddOp(v, OP_Column, base, ii);
          221  +      }
   220    222       }
   221    223       sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
   222    224       sqliteVdbeAddOp(v, OP_PutIntKey, oldIdx, 0);
   223    225   
   224    226       sqliteVdbeAddOp(v, OP_Integer, 13, 0);
   225         -    for (ii = 0; ii < pTab->nCol; ii++){
          227  +    for(ii = 0; ii < pTab->nCol; ii++){
   226    228         if( aXRef[ii] < 0 ){
   227         -        if (ii == pTab->iPKey)
          229  +        if( ii == pTab->iPKey ){
   228    230             sqliteVdbeAddOp(v, OP_Recno, base, 0);
   229         -        else
          231  +	}else{
   230    232             sqliteVdbeAddOp(v, OP_Column, base, ii);
          233  +	}
   231    234         }else{
   232    235           sqliteExprCode(pParse, pChanges->a[aXRef[ii]].pExpr);
   233    236         }
   234    237       }
   235    238       sqliteVdbeAddOp(v, OP_MakeRecord, pTab->nCol, 0);
   236    239       sqliteVdbeAddOp(v, OP_PutIntKey, newIdx, 0);
   237    240       sqliteVdbeAddOp(v, OP_Close, base, 0);
   238    241   
   239    242       sqliteVdbeAddOp(v, OP_Rewind, oldIdx, 0);
   240    243       sqliteVdbeAddOp(v, OP_Rewind, newIdx, 0);
   241    244   
   242         -    if (sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab, 
   243         -          newIdx, oldIdx, onError)) goto update_cleanup;
          245  +    if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_BEFORE, pTab, 
          246  +          newIdx, oldIdx, onError) ){
          247  +      goto update_cleanup;
          248  +    }
   244    249     }
   245    250   
   246    251     /* Rewind the list of records that need to be updated and
   247    252     ** open every index that needs updating.  Note that if any
   248    253     ** index could potentially invoke a REPLACE conflict resolution 
   249    254     ** action, then we need to open all indices because we might need
   250    255     ** to be deleting some records.
................................................................................
   272    277   
   273    278     /* Loop over every record that needs updating.  We have to load
   274    279     ** the old data for each record to be updated because some columns
   275    280     ** might not change and we will need to copy the old value.
   276    281     ** Also, the old data is needed to delete the old index entires.
   277    282     ** So make the cursor point at the old record.
   278    283     */
   279         -  if (!row_triggers_exist) {
          284  +  if( !row_triggers_exist ){
   280    285       int ii;
   281    286       sqliteVdbeAddOp(v, OP_ListRewind, 0, 0);
   282    287       addr = sqliteVdbeAddOp(v, OP_ListRead, 0, 0);
   283    288       sqliteVdbeAddOp(v, OP_Dup, 0, 0);
   284    289     }
   285    290     sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
   286    291   
................................................................................
   333    338   
   334    339     /* Increment the row counter 
   335    340     */
   336    341     if( db->flags & SQLITE_CountRows && !pParse->trigStack){
   337    342       sqliteVdbeAddOp(v, OP_AddImm, 1, 0);
   338    343     }
   339    344   
   340         -  if (row_triggers_exist) {
          345  +  if( row_triggers_exist ){
   341    346       for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
   342    347         if( openAll || aIdxUsed[i] )
   343    348           sqliteVdbeAddOp(v, OP_Close, base+i+1, 0);
   344    349       }
   345    350       sqliteVdbeAddOp(v, OP_Close, base, 0);
   346    351       pParse->nTab = base;
   347    352   
   348         -    if (sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab, 
   349         -          newIdx, oldIdx, onError)) goto update_cleanup;
          353  +    if( sqliteCodeRowTrigger(pParse, TK_UPDATE, pChanges, TK_AFTER, pTab, 
          354  +          newIdx, oldIdx, onError) ){
          355  +      goto update_cleanup;
          356  +    }
   350    357     }
   351    358   
   352    359     /* Repeat the above with the next record to be updated, until
   353    360     ** all record selected by the WHERE clause have been updated.
   354    361     */
   355    362     sqliteVdbeAddOp(v, OP_Goto, 0, addr);
   356    363     sqliteVdbeChangeP2(v, addr, sqliteVdbeCurrentAddr(v));
   357    364     sqliteVdbeAddOp(v, OP_ListReset, 0, 0);
   358    365   
   359    366     /* Close all tables if there were no FOR EACH ROW triggers */
   360         -  if (!row_triggers_exist) {
          367  +  if( !row_triggers_exist ){
   361    368       for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
   362    369         if( openAll || aIdxUsed[i] ){
   363    370           sqliteVdbeAddOp(v, OP_Close, base+i+1, 0);
   364    371         }
   365    372       }
   366    373       sqliteVdbeAddOp(v, OP_Close, base, 0);
   367    374       pParse->nTab = base;
   368         -  } else {
          375  +  }else{
   369    376       sqliteVdbeAddOp(v, OP_Close, newIdx, 0);
   370    377       sqliteVdbeAddOp(v, OP_Close, oldIdx, 0);
   371    378     }
   372    379   
   373    380     sqliteEndWriteOperation(pParse);
   374    381   
   375    382     /*

Changes to src/vdbe.c.

    26     26   ** type to the other occurs as necessary.
    27     27   ** 
    28     28   ** Most of the code in this file is taken up by the sqliteVdbeExec()
    29     29   ** function which does the work of interpreting a VDBE program.
    30     30   ** But other routines are also provided to help in building up
    31     31   ** a program instruction by instruction.
    32     32   **
    33         -** $Id: vdbe.c,v 1.143 2002/05/15 11:44:15 drh Exp $
           33  +** $Id: vdbe.c,v 1.144 2002/05/19 23:43:14 danielk1977 Exp $
    34     34   */
    35     35   #include "sqliteInt.h"
    36     36   #include <ctype.h>
    37     37   
    38     38   /*
    39     39   ** The following global variable is incremented every time a cursor
    40     40   ** moves, either by the OP_MoveTo or the OP_Next opcode.  The test
................................................................................
   245    245     Mem *aMem;          /* The memory locations */
   246    246     Agg agg;            /* Aggregate information */
   247    247     int nSet;           /* Number of sets allocated */
   248    248     Set *aSet;          /* An array of sets */
   249    249     int nCallback;      /* Number of callbacks invoked so far */
   250    250     int iLimit;         /* Limit on the number of callbacks remaining */
   251    251     int iOffset;        /* Offset before beginning to do callbacks */
   252         -
   253         -  int keylistStackDepth; 
   254         -  Keylist ** keylistStack;
          252  +  int keylistStackDepth;  /* The size of the "keylist" stack */
          253  +  Keylist **keylistStack; /* The stack used by opcodes PushList & PopList */
   255    254   };
   256    255   
   257    256   /*
   258    257   ** Create a new virtual database engine.
   259    258   */
   260    259   Vdbe *sqliteVdbeCreate(sqlite *db){
   261    260     Vdbe *p;
................................................................................
   998    997     AggReset(&p->agg);
   999    998     for(i=0; i<p->nSet; i++){
  1000    999       sqliteHashClear(&p->aSet[i].hash);
  1001   1000     }
  1002   1001     sqliteFree(p->aSet);
  1003   1002     p->aSet = 0;
  1004   1003     p->nSet = 0;
  1005         -  if (p->keylistStackDepth > 0) {
         1004  +  if( p->keylistStackDepth > 0 ){
  1006   1005       int ii;
  1007         -    for (ii = 0; ii < p->keylistStackDepth; ii++) {
         1006  +    for(ii = 0; ii < p->keylistStackDepth; ii++){
  1008   1007         KeylistFree(p->keylistStack[ii]);
  1009   1008       }
  1010   1009       sqliteFree(p->keylistStack);
  1011   1010       p->keylistStackDepth = 0;
  1012   1011       p->keylistStack = 0;
  1013   1012     }
  1014   1013   }
................................................................................
  4573   4572   */
  4574   4573   case OP_PopList: {
  4575   4574     assert(p->keylistStackDepth > 0);
  4576   4575     p->keylistStackDepth--;
  4577   4576     KeylistFree(p->pList);
  4578   4577     p->pList = p->keylistStack[p->keylistStackDepth];
  4579   4578     p->keylistStack[p->keylistStackDepth] = 0;
  4580         -  if (p->keylistStackDepth == 0) {
         4579  +  if( p->keylistStackDepth == 0 ){
  4581   4580       sqliteFree(p->keylistStack);
  4582   4581       p->keylistStack = 0;
  4583   4582     }
  4584   4583     break;
  4585   4584   }
  4586   4585   
  4587   4586   /* Opcode: SetNotFound P1 P2 *

Changes to src/where.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.  Also found here are subroutines
    14     14   ** to generate VDBE code to evaluate expressions.
    15     15   **
    16         -** $Id: where.c,v 1.43 2002/05/15 11:44:15 drh Exp $
           16  +** $Id: where.c,v 1.44 2002/05/19 23:43:14 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   
    20     20   /*
    21     21   ** The query generator uses an array of instances of this structure to
    22     22   ** help it analyze the subexpressions of the WHERE clause.  Each WHERE
    23     23   ** clause subexpression is separated from the others by an AND operator.
................................................................................
   212    212     memset(aExpr, 0, sizeof(aExpr));
   213    213     nExpr = exprSplit(ARRAYSIZE(aExpr), aExpr, pWhere);
   214    214   
   215    215     /* Analyze all of the subexpressions.
   216    216     */
   217    217     for(i=0; i<nExpr; i++){
   218    218       exprAnalyze(base, &aExpr[i]);
   219         -    if (pParse->trigStack && pParse->trigStack->newIdx >= 0) {
          219  +    if( pParse->trigStack && pParse->trigStack->newIdx >= 0 ){
   220    220           aExpr[i].prereqRight = 
   221    221               aExpr[i].prereqRight & ~(1 << pParse->trigStack->newIdx - base);
   222    222           aExpr[i].prereqLeft = 
   223    223               aExpr[i].prereqLeft & ~(1 << pParse->trigStack->newIdx - base);
   224    224           aExpr[i].prereqAll = 
   225    225               aExpr[i].prereqAll & ~(1 << pParse->trigStack->newIdx - base);
   226    226       }
   227         -    if (pParse->trigStack && pParse->trigStack->oldIdx >= 0) {
          227  +    if( pParse->trigStack && pParse->trigStack->oldIdx >= 0 ){
   228    228           aExpr[i].prereqRight = 
   229    229               aExpr[i].prereqRight & ~(1 << pParse->trigStack->oldIdx - base);
   230    230           aExpr[i].prereqLeft = 
   231    231               aExpr[i].prereqLeft & ~(1 << pParse->trigStack->oldIdx - base);
   232    232           aExpr[i].prereqAll = 
   233    233               aExpr[i].prereqAll & ~(1 << pParse->trigStack->oldIdx - base);
   234    234       }