/ Check-in [5b0147ae]
Login

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

Overview
Comment:Refactor parts of write operations. (CVS 1268)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5b0147aece7785373e6f7439c32e5f58c6b12562
User & Date: drh 2004-02-24 01:05:32
Context
2004-02-25
02:20
Disable an assert which (as it turns out) is not always true. Ticket #615. (CVS 1269) check-in: 2773c1d3 user: drh tags: trunk
2004-02-24
01:05
Refactor parts of write operations. (CVS 1268) check-in: 5b0147ae user: drh tags: trunk
01:04
Make sure BEGIN, COMMIT, and ROLLBACK are really no-ops when preceded by EXPLAIN. Ticket #626. (CVS 1267) check-in: 2af1f065 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/copy.c.

     7      7   **    May you do good and not evil.
     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 code used to implement the COPY command.
    13     13   **
    14         -** $Id: copy.c,v 1.7 2004/02/16 03:44:02 drh Exp $
           14  +** $Id: copy.c,v 1.8 2004/02/24 01:05:32 drh Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /*
    19     19   ** The COPY command is for compatibility with PostgreSQL and specificially
    20     20   ** for the ability to read the output of pg_dump.  The format is as
    21     21   ** follows:
................................................................................
    54     54     if( sqliteAuthCheck(pParse, SQLITE_INSERT, pTab->zName, 0, zDb)
    55     55         || sqliteAuthCheck(pParse, SQLITE_COPY, pTab->zName, zFile, zDb) ){
    56     56       goto copy_cleanup;
    57     57     }
    58     58     v = sqliteGetVdbe(pParse);
    59     59     if( v ){
    60     60       sqliteBeginWriteOperation(pParse, 1, pTab->iDb);
    61         -    addr = sqliteVdbeAddOp(v, OP_FileOpen, 0, 0);
    62         -    sqliteVdbeChangeP3(v, addr, pFilename->z, pFilename->n);
           61  +    addr = sqliteVdbeOp3(v, OP_FileOpen, 0, 0, pFilename->z, pFilename->n);
    63     62       sqliteVdbeDequoteP3(v, addr);
    64         -    sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
    65         -    sqliteVdbeAddOp(v, OP_OpenWrite, 0, pTab->tnum);
    66         -    sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
    67         -    for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
    68         -      assert( pIdx->iDb==1 || pIdx->iDb==pTab->iDb );
    69         -      sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
    70         -      sqliteVdbeAddOp(v, OP_OpenWrite, i, pIdx->tnum);
    71         -      sqliteVdbeChangeP3(v, -1, pIdx->zName, P3_STATIC);
    72         -    }
           63  +    sqliteOpenTableAndIndices(pParse, pTab, 0);
    73     64       if( db->flags & SQLITE_CountRows ){
    74     65         sqliteVdbeAddOp(v, OP_Integer, 0, 0);  /* Initialize the row count */
    75     66       }
    76     67       end = sqliteVdbeMakeLabel(v);
    77     68       addr = sqliteVdbeAddOp(v, OP_FileRead, pTab->nCol, end);
    78     69       if( pDelimiter ){
    79     70         sqliteVdbeChangeP3(v, addr, pDelimiter->z, pDelimiter->n);

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.60 2004/02/20 22:53:39 rdc Exp $
           15  +** $Id: delete.c,v 1.61 2004/02/24 01:05:32 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Look up every table that is named in pSrc.  If any table is not found,
    21     21   ** add an error message to pParse->zErrMsg and return NULL.  If all tables
    22     22   ** are found, return a pointer to the last table.
................................................................................
   249    249         /* Open cursors for the table we are deleting from and all its
   250    250         ** indices.  If there are row triggers, this happens inside the
   251    251         ** OP_ListRead loop because the cursor have to all be closed
   252    252         ** before the trigger fires.  If there are no row triggers, the
   253    253         ** cursors are opened only once on the outside the loop.
   254    254         */
   255    255         pParse->nTab = iCur + 1;
   256         -      sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
   257         -      sqliteVdbeAddOp(v, OP_OpenWrite, iCur, pTab->tnum);
   258         -      for(i=1, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
   259         -        sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
   260         -        sqliteVdbeAddOp(v, OP_OpenWrite, pParse->nTab++, pIdx->tnum);
   261         -      }
          256  +      sqliteOpenTableAndIndices(pParse, pTab, iCur);
   262    257   
   263    258         /* This is the beginning of the delete loop when there are no
   264    259         ** row triggers */
   265    260         if( !row_triggers_exist ){ 
   266    261           addr = sqliteVdbeAddOp(v, OP_ListRead, 0, end);
   267    262         }
   268    263   

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.93 2004/02/22 20:05:01 drh Exp $
           15  +** $Id: insert.c,v 1.94 2004/02/24 01:05:33 drh 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)
................................................................................
   326    326       sqliteVdbeAddOp(v, OP_Integer, 0, 0);
   327    327       sqliteVdbeAddOp(v, OP_MemStore, iCntMem, 1);
   328    328     }
   329    329   
   330    330     /* Open tables and indices if there are no row triggers */
   331    331     if( !row_triggers_exist ){
   332    332       base = pParse->nTab;
   333         -    sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
   334         -    sqliteVdbeOp3(v, OP_OpenWrite, base, pTab->tnum, pTab->zName, P3_STATIC);
   335         -    for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
   336         -      sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
   337         -      sqliteVdbeOp3(v, OP_OpenWrite, idx+base, pIdx->tnum,
   338         -                       pIdx->zName, P3_STATIC);
   339         -    }
          333  +    idx = sqliteOpenTableAndIndices(pParse, pTab, base);
   340    334       pParse->nTab += idx;
   341    335     }
   342    336   
   343    337     /* If the data source is a temporary table, then we have to create
   344    338     ** a loop because there might be multiple rows of data.  If the data
   345    339     ** source is a subroutine call from the SELECT statement, then we need
   346    340     ** to launch the SELECT statement processing.
................................................................................
   410    404     }
   411    405   
   412    406     /* If any triggers exists, the opening of tables and indices is deferred
   413    407     ** until now.
   414    408     */
   415    409     if( row_triggers_exist && !isView ){
   416    410       base = pParse->nTab;
   417         -    sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
   418         -    sqliteVdbeOp3(v, OP_OpenWrite, base, pTab->tnum, pTab->zName, P3_STATIC);
   419         -    for(idx=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
   420         -      sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
   421         -      sqliteVdbeOp3(v, OP_OpenWrite, idx+base, pIdx->tnum,
   422         -                       pIdx->zName, P3_STATIC);
   423         -    }
          411  +    idx = sqliteOpenTableAndIndices(pParse, pTab, base);
   424    412       pParse->nTab += idx;
   425    413     }
   426    414   
   427    415     /* Push the record number for the new entry onto the stack.  The
   428    416     ** record number is a randomly generate integer created by NewRecno
   429    417     ** except when the table has an INTEGER PRIMARY KEY column, in which
   430    418     ** case the record number is the same as that column. 
................................................................................
   903    891     sqliteVdbeAddOp(v, OP_PutIntKey, base,
   904    892       (pParse->trigStack?0:OPFLAG_NCHANGE) |
   905    893       (isUpdate?0:OPFLAG_LASTROWID) | OPFLAG_CSCHANGE);
   906    894     if( isUpdate && recnoChng ){
   907    895       sqliteVdbeAddOp(v, OP_Pop, 1, 0);
   908    896     }
   909    897   }
          898  +
          899  +/*
          900  +** Generate code that will open write cursors for a table and for all
          901  +** indices of that table.  The "base" parameter is the cursor number used
          902  +** for the table.  Indices are opened on subsequent cursors.
          903  +**
          904  +** Return the total number of cursors opened.  This is always at least
          905  +** 1 (for the main table) plus more for each cursor.
          906  +*/
          907  +int sqliteOpenTableAndIndices(Parse *pParse, Table *pTab, int base){
          908  +  int i;
          909  +  Index *pIdx;
          910  +  Vdbe *v = sqliteGetVdbe(pParse);
          911  +  assert( v!=0 );
          912  +  sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
          913  +  sqliteVdbeOp3(v, OP_OpenWrite, base, pTab->tnum, pTab->zName, P3_STATIC);
          914  +  for(i=1, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
          915  +    sqliteVdbeAddOp(v, OP_Integer, pIdx->iDb, 0);
          916  +    sqliteVdbeOp3(v, OP_OpenWrite, i+base, pIdx->tnum, pIdx->zName, P3_STATIC);
          917  +  }
          918  +  return i;
          919  +}

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.218 2004/02/22 17:49:34 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.219 2004/02/24 01:05:33 drh Exp $
    15     15   */
    16     16   #include "config.h"
    17     17   #include "sqlite.h"
    18     18   #include "hash.h"
    19     19   #include "parse.h"
    20     20   #include "btree.h"
    21     21   #include <stdio.h>
................................................................................
  1200   1200   int sqliteExprIsConstant(Expr*);
  1201   1201   int sqliteExprIsInteger(Expr*, int*);
  1202   1202   int sqliteIsRowid(const char*);
  1203   1203   void sqliteGenerateRowDelete(sqlite*, Vdbe*, Table*, int, int);
  1204   1204   void sqliteGenerateRowIndexDelete(sqlite*, Vdbe*, Table*, int, char*);
  1205   1205   void sqliteGenerateConstraintChecks(Parse*,Table*,int,char*,int,int,int,int);
  1206   1206   void sqliteCompleteInsertion(Parse*, Table*, int, char*, int, int, int);
         1207  +int sqliteOpenTableAndIndices(Parse*, Table*, int);
  1207   1208   void sqliteBeginWriteOperation(Parse*, int, int);
  1208   1209   void sqliteEndWriteOperation(Parse*);
  1209   1210   Expr *sqliteExprDup(Expr*);
  1210   1211   void sqliteTokenCopy(Token*, Token*);
  1211   1212   ExprList *sqliteExprListDup(ExprList*);
  1212   1213   SrcList *sqliteSrcListDup(SrcList*);
  1213   1214   IdList *sqliteIdListDup(IdList*);