/ Check-in [9ac8399c]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:It runs. Simple tables can be created. INSERT and SELECT work. Much more testing is needed, however. (CVS 241)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9ac8399c99cb996a382f3d49f45b6ca857adc827
User & Date: drh 2001-09-13 16:18:54
Context
2001-09-13
21:53
Many problems fixed. Many problems yet to go. (CVS 242) check-in: 62c7bd11 user: drh tags: trunk
16:18
It runs. Simple tables can be created. INSERT and SELECT work. Much more testing is needed, however. (CVS 241) check-in: 9ac8399c user: drh tags: trunk
15:21
The new Btree code runs, but it does not yet work. (CVS 240) check-in: 991ce811 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    29     29   **     DROP TABLE
    30     30   **     CREATE INDEX
    31     31   **     DROP INDEX
    32     32   **     creating expressions and ID lists
    33     33   **     COPY
    34     34   **     VACUUM
    35     35   **
    36         -** $Id: build.c,v 1.30 2001/09/13 14:46:10 drh Exp $
           36  +** $Id: build.c,v 1.31 2001/09/13 16:18:54 drh Exp $
    37     37   */
    38     38   #include "sqliteInt.h"
    39     39   
    40     40   /*
    41     41   ** This routine is called after a single SQL statement has been
    42     42   ** parsed and we want to execute the VDBE code to implement 
    43     43   ** that statement.  Prior action routines should have already
................................................................................
   456    456       h = sqliteHashNoCase(p->zName, 0) % N_HASH;
   457    457       p->pHash = db->apTblHash[h];
   458    458       db->apTblHash[h] = p;
   459    459       pParse->pNewTable = 0;
   460    460       db->nTable++;
   461    461       db->flags |= SQLITE_InternChanges;
   462    462     }
          463  +
          464  +  /* If the initFlag is 1 it means we are reading the SQL off the
          465  +  ** "sqlite_master" table on the disk.  So do not write to the disk
          466  +  ** again.  Extract the table number from the pParse->newTnum field.
          467  +  */
          468  +  if( pParse->initFlag ){
          469  +    p->tnum = pParse->newTnum;
          470  +  }
   463    471   
   464    472     /* If not initializing, then create the table on disk.
   465    473     */
   466    474     if( !pParse->initFlag ){
   467    475       static VdbeOp addTable[] = {
   468    476         { OP_Open,        0, 2, 0},
   469    477         { OP_NewRecno,    0, 0, 0},
   470    478         { OP_String,      0, 0, "table"     },
   471    479         { OP_String,      0, 0, 0},            /* 3 */
   472    480         { OP_CreateTable, 0, 0, 0},
   473    481         { OP_String,      0, 0, 0},            /* 5 */
   474    482         { OP_String,      0, 0, 0},            /* 6 */
   475         -      { OP_MakeRecord,  4, 0, 0},
          483  +      { OP_MakeRecord,  5, 0, 0},
   476    484         { OP_Put,         0, 0, 0},
   477    485       };
   478    486       int n, base;
   479    487       Vdbe *v;
   480    488   
   481    489       v = sqliteGetVdbe(pParse);
   482    490       if( v==0 ) return;
................................................................................
   534    542     /* Generate code to remove the table from the master table
   535    543     ** on disk.
   536    544     */
   537    545     v = sqliteGetVdbe(pParse);
   538    546     if( v ){
   539    547       static VdbeOp dropTable[] = {
   540    548         { OP_Open,       0, 2,        0},
   541         -      { OP_String,     0, 0,        0}, /* 1 */
   542         -      { OP_Next,       0, ADDR(9),  0}, /* 2 */
          549  +      { OP_Rewind,     0, 0,        0},
          550  +      { OP_String,     0, 0,        0}, /* 2 */
          551  +      { OP_Next,       0, ADDR(10), 0}, /* 3 */
   543    552         { OP_Dup,        0, 0,        0},
   544    553         { OP_Column,     0, 3,        0},
   545         -      { OP_Ne,         0, ADDR(2),  0},
          554  +      { OP_Ne,         0, ADDR(3),  0},
   546    555         { OP_Recno,      0, 0,        0},
   547    556         { OP_Delete,     0, 0,        0},
   548         -      { OP_Goto,       0, ADDR(2),  0},
   549         -      { OP_Destroy,    0, 0,        0}, /* 9 */
          557  +      { OP_Goto,       0, ADDR(3),  0},
          558  +      { OP_Destroy,    0, 0,        0}, /* 10 */
   550    559         { OP_Close,      0, 0,        0},
   551    560       };
   552    561       Index *pIdx;
   553    562       if( (pParse->db->flags & SQLITE_InTrans)==0 ){
   554    563         sqliteVdbeAddOp(v, OP_Transaction, 0, 0, 0, 0);
   555    564       }
   556    565       base = sqliteVdbeAddOpList(v, ArraySize(dropTable), dropTable);
   557         -    sqliteVdbeChangeP1(v, base+9, pTable->tnum);
          566  +    sqliteVdbeChangeP1(v, base+10, pTable->tnum);
   558    567       for(pIdx=pTable->pIndex; pIdx; pIdx=pIdx->pNext){
   559    568         sqliteVdbeAddOp(v, OP_Destroy, pIdx->tnum, 0, 0, 0);
   560    569       }
   561    570       if( (pParse->db->flags & SQLITE_InTrans)==0 ){
   562    571         sqliteVdbeAddOp(v, OP_Commit, 0, 0, 0, 0);
   563    572       }
   564    573     }
................................................................................
   689    698       h = sqliteHashNoCase(pIndex->zName, 0) % N_HASH;
   690    699       pIndex->pHash = db->apIdxHash[h];
   691    700       db->apIdxHash[h] = pIndex;
   692    701       pIndex->pNext = pTab->pIndex;
   693    702       pTab->pIndex = pIndex;
   694    703       db->flags |= SQLITE_InternChanges;
   695    704     }
          705  +
          706  +  /* If the initFlag is 1 it means we are reading the SQL off the
          707  +  ** "sqlite_master" table on the disk.  So do not write to the disk
          708  +  ** again.  Extract the table number from the pParse->newTnum field.
          709  +  */
          710  +  if( pParse->initFlag ){
          711  +    pIndex->tnum = pParse->newTnum;
          712  +  }
   696    713   
   697    714     /* If the initFlag is 0 then create the index on disk.  This
   698    715     ** involves writing the index into the master table and filling in the
   699    716     ** index with the current table contents.
   700    717     **
   701    718     ** The initFlag is 0 when the user first enters a CREATE INDEX 
   702    719     ** command.  The initFlag is 1 when a database is opened and 
................................................................................
   736    753         sqliteVdbeChangeP3(v, base+3, pIndex->zName, 0);
   737    754         sqliteVdbeIndexRootAddr(v, &pIndex->tnum);
   738    755         sqliteVdbeChangeP3(v, base+5, pTab->zName, 0);
   739    756         sqliteVdbeChangeP3(v, base+6, pStart->z, n);
   740    757       }
   741    758       lbl1 = sqliteVdbeMakeLabel(v);
   742    759       lbl2 = sqliteVdbeMakeLabel(v);
          760  +    sqliteVdbeAddOp(v, OP_Rewind, 0, 0, 0, 0);
   743    761       sqliteVdbeAddOp(v, OP_Next, 0, lbl2, 0, lbl1);
   744    762       sqliteVdbeAddOp(v, OP_Recno, 0, 0, 0, 0);
   745    763       for(i=0; i<pIndex->nColumn; i++){
   746    764         sqliteVdbeAddOp(v, OP_Column, 0, pIndex->aiColumn[i], 0, 0);
   747    765       }
   748    766       sqliteVdbeAddOp(v, OP_MakeIdxKey, pIndex->nColumn, 0, 0, 0);
   749    767       sqliteVdbeAddOp(v, OP_PutIdx, 1, 0, 0, 0);
................................................................................
   791    809     }
   792    810   
   793    811     /* Generate code to remove the index and from the master table */
   794    812     v = sqliteGetVdbe(pParse);
   795    813     if( v ){
   796    814       static VdbeOp dropIndex[] = {
   797    815         { OP_Open,       0, 2,       0},
   798         -      { OP_String,     0, 0,       0}, /* 1 */
   799         -      { OP_Next,       0, ADDR(8), 0}, /* 2 */
          816  +      { OP_Rewind,     0, 0,       0}, 
          817  +      { OP_String,     0, 0,       0}, /* 2 */
          818  +      { OP_Next,       0, ADDR(9), 0}, /* 3 */
   800    819         { OP_Dup,        0, 0,       0},
   801    820         { OP_Column,     0, 1,       0},
   802         -      { OP_Ne,         0, ADDR(2), 0},
          821  +      { OP_Ne,         0, ADDR(3), 0},
   803    822         { OP_Recno,      0, 0,       0},
   804    823         { OP_Delete,     0, 0,       0},
   805         -      { OP_Destroy,    0, 0,       0}, /* 8 */
          824  +      { OP_Destroy,    0, 0,       0}, /* 9 */
   806    825         { OP_Close,      0, 0,       0},
   807    826       };
   808    827       int base;
   809    828   
   810    829       if( (db->flags & SQLITE_InTrans)==0 ){
   811    830         sqliteVdbeAddOp(v, OP_Transaction, 0, 0, 0, 0);
   812    831       }
   813    832       base = sqliteVdbeAddOpList(v, ArraySize(dropIndex), dropIndex);
   814         -    sqliteVdbeChangeP1(v, base+8, pIndex->tnum);
          833  +    sqliteVdbeChangeP1(v, base+9, pIndex->tnum);
   815    834       if( (db->flags & SQLITE_InTrans)==0 ){
   816    835         sqliteVdbeAddOp(v, OP_Commit, 0, 0, 0, 0);
   817    836       }
   818    837     }
   819    838   
   820    839     /* Mark the internal Index structure for deletion by the
   821    840     ** sqliteCommitInternalChanges routine.

Changes to src/main.c.

    22     22   **
    23     23   *************************************************************************
    24     24   ** Main file for the SQLite library.  The routines in this file
    25     25   ** implement the programmer interface to the library.  Routines in
    26     26   ** other files are for internal use by SQLite and should not be
    27     27   ** accessed by users of the library.
    28     28   **
    29         -** $Id: main.c,v 1.32 2001/09/13 15:21:32 drh Exp $
           29  +** $Id: main.c,v 1.33 2001/09/13 16:18:54 drh Exp $
    30     30   */
    31     31   #include "sqliteInt.h"
    32     32   #if defined(HAVE_USLEEP) && HAVE_USLEEP
    33     33   #include <unistd.h>
    34     34   #endif
    35     35   
    36     36   /*
    37     37   ** This is the callback routine for the code that initializes the
    38         -** database.  Each callback contains text of a CREATE TABLE or
    39         -** CREATE INDEX statement that must be parsed to yield the internal
    40         -** structures that describe the tables.
           38  +** database.  Each callback contains the following information:
    41     39   **
    42         -** This callback is also called with argc==2 when there is meta
    43         -** information in the sqlite_master file.  The meta information is
    44         -** contained in argv[1].  Typical meta information is the file format
    45         -** version.
           40  +**     argv[0] = "meta" or "table" or "index"
           41  +**     argv[1] = table or index name
           42  +**     argv[2] = root page number for table or index
           43  +**     argv[3] = SQL create statement for the table or index
           44  +**
    46     45   */
    47     46   static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
    48     47     sqlite *db = (sqlite*)pDb;
    49     48     Parse sParse;
    50         -  int nErr;
           49  +  int nErr = 0;
    51     50   
    52         -  if( argc==2 ){
    53         -    if( sscanf(argv[1],"file format %d",&db->file_format)==1 ){
    54         -      return 0;
           51  +  assert( argc==4 );
           52  +  switch( argv[0][0] ){
           53  +    case 'm': {  /* Meta information */
           54  +      sscanf(argv[1],"file format %d",&db->file_format);
           55  +      break;
           56  +    }
           57  +    case 'i':
           58  +    case 't': {  /* CREATE TABLE  and CREATE INDEX statements */
           59  +      memset(&sParse, 0, sizeof(sParse));
           60  +      sParse.db = db;
           61  +      sParse.initFlag = 1;
           62  +      sParse.newTnum = atoi(argv[2]);
           63  +      nErr = sqliteRunParser(&sParse, argv[3], 0);
           64  +      break;
           65  +    }
           66  +    default: {
           67  +      /* This can not happen! */
           68  +      nErr = 1;
           69  +      assert( nErr==0 );
    55     70       }
    56         -    /* Unknown meta information.  Ignore it. */
    57         -    return 0;
    58     71     }
    59         -  if( argc!=1 ) return 0;
    60         -  memset(&sParse, 0, sizeof(sParse));
    61         -  sParse.db = db;
    62         -  sParse.initFlag = 1;
    63         -  nErr = sqliteRunParser(&sParse, argv[0], 0);
    64     72     return nErr;
    65     73   }
    66     74   
    67     75   /*
    68     76   ** Attempt to read the database schema and initialize internal
    69     77   ** data structures.  Return one of the SQLITE_ error codes to
    70     78   ** indicate success or failure.
................................................................................
   125    133     ** table then goes back and invokes the callback on the
   126    134     ** SQL for each index.  The callback will invoke the
   127    135     ** parser to build the internal representation of the
   128    136     ** database scheme.
   129    137     */
   130    138     static VdbeOp initProg[] = {
   131    139       { OP_Open,     0, 2,  0},
   132         -    { OP_Next,     0, 9,  0},           /* 1 */
          140  +    { OP_Rewind,   0, 0,  0},
          141  +    { OP_Next,     0, 12, 0},           /* 2 */
   133    142       { OP_Column,   0, 0,  0},
   134    143       { OP_String,   0, 0,  "meta"},
   135         -    { OP_Ne,       0, 1,  0},
          144  +    { OP_Ne,       0, 2,  0},
   136    145       { OP_Column,   0, 0,  0},
          146  +    { OP_Column,   0, 1,  0},
          147  +    { OP_Column,   0, 2,  0},
   137    148       { OP_Column,   0, 4,  0},
   138         -    { OP_Callback, 2, 0,  0},
   139         -    { OP_Goto,     0, 1,  0},
   140         -    { OP_Rewind,   0, 0,  0},           /* 9 */
   141         -    { OP_Next,     0, 17, 0},           /* 10 */
          149  +    { OP_Callback, 4, 0,  0},
          150  +    { OP_Goto,     0, 2,  0},
          151  +    { OP_Rewind,   0, 0,  0},           /* 12 */
          152  +    { OP_Next,     0, 23, 0},           /* 13 */
   142    153       { OP_Column,   0, 0,  0},
   143    154       { OP_String,   0, 0,  "table"},
   144         -    { OP_Ne,       0, 10, 0},
          155  +    { OP_Ne,       0, 13, 0},
          156  +    { OP_Column,   0, 0,  0},
          157  +    { OP_Column,   0, 1,  0},
          158  +    { OP_Column,   0, 2,  0},
   145    159       { OP_Column,   0, 4,  0},
   146         -    { OP_Callback, 1, 0,  0},
   147         -    { OP_Goto,     0, 10, 0},
   148         -    { OP_Rewind,   0, 0,  0},           /* 17 */
   149         -    { OP_Next,     0, 25, 0},           /* 18 */
          160  +    { OP_Callback, 4, 0,  0},
          161  +    { OP_Goto,     0, 13, 0},
          162  +    { OP_Rewind,   0, 0,  0},           /* 23 */
          163  +    { OP_Next,     0, 34, 0},           /* 24 */
   150    164       { OP_Column,   0, 0,  0},
   151    165       { OP_String,   0, 0,  "index"},
   152         -    { OP_Ne,       0, 18, 0},
          166  +    { OP_Ne,       0, 24, 0},
          167  +    { OP_Column,   0, 0,  0},
          168  +    { OP_Column,   0, 1,  0},
          169  +    { OP_Column,   0, 2,  0},
   153    170       { OP_Column,   0, 4,  0},
   154         -    { OP_Callback, 1, 0,  0},
   155         -    { OP_Goto,     0, 18, 0},
   156         -    { OP_Close,    2, 0,  0},           /* 25 */
          171  +    { OP_Callback, 4, 0,  0},
          172  +    { OP_Goto,     0, 24, 0},
          173  +    { OP_Close,    0, 0,  0},           /* 34 */
   157    174       { OP_Halt,     0, 0,  0},
   158    175     };
   159    176   
   160    177     /* Create a virtual machine to run the initialization program.  Run
   161    178     ** the program.  The delete the virtual machine.
   162    179     */
   163    180     vdbe = sqliteVdbeCreate(db);
................................................................................
   165    182       sqliteSetString(pzErrMsg, "out of memory");
   166    183       return SQLITE_NOMEM;
   167    184     }
   168    185     sqliteVdbeAddOpList(vdbe, sizeof(initProg)/sizeof(initProg[0]), initProg);
   169    186     rc = sqliteVdbeExec(vdbe, sqliteOpenCb, db, pzErrMsg, 
   170    187                         db->pBusyArg, db->xBusyCallback);
   171    188     sqliteVdbeDelete(vdbe);
   172         -  if( rc==SQLITE_OK && db->file_format<2 && db->nTable>0 ){
   173         -    sqliteSetString(pzErrMsg, "obsolete file format", 0);
          189  +  if( rc==SQLITE_OK && db->file_format>1 && db->nTable>0 ){
          190  +    sqliteSetString(pzErrMsg, "unsupported file format", 0);
   174    191       rc = SQLITE_ERROR;
   175    192     }
   176    193     if( rc==SQLITE_OK ){
   177    194       Table *pTab;
   178         -    char *azArg[2];
   179         -    azArg[0] = master_schema;
   180         -    azArg[1] = 0;
   181         -    sqliteOpenCb(db, 1, azArg, 0);
          195  +    char *azArg[5];
          196  +    azArg[0] = "table";
          197  +    azArg[1] = MASTER_NAME;
          198  +    azArg[2] = "2";
          199  +    azArg[3] = master_schema;
          200  +    azArg[4] = 0;
          201  +    sqliteOpenCb(db, 4, azArg, 0);
   182    202       pTab = sqliteFindTable(db, MASTER_NAME);
   183    203       if( pTab ){
   184    204         pTab->readOnly = 1;
   185         -      pTab->tnum = 2;
   186    205       }
   187    206       db->flags |= SQLITE_Initialized;
   188    207       sqliteCommitInternalChanges(db);
   189    208     }
   190    209     return rc;
   191    210   }
   192    211   

Changes to src/select.c.

    20     20   **   drh@hwaci.com
    21     21   **   http://www.hwaci.com/drh/
    22     22   **
    23     23   *************************************************************************
    24     24   ** This file contains C code routines that are called by the parser
    25     25   ** to handle SELECT statements.
    26     26   **
    27         -** $Id: select.c,v 1.33 2001/09/13 14:46:10 drh Exp $
           27  +** $Id: select.c,v 1.34 2001/09/13 16:18:54 drh Exp $
    28     28   */
    29     29   #include "sqliteInt.h"
    30     30   
    31     31   /*
    32     32   ** Allocate a new Select structure and return a pointer to that
    33     33   ** structure.
    34     34   */
................................................................................
   545    545         if( eDest!=priorOp ){
   546    546           int iCont, iBreak;
   547    547           assert( p->pEList );
   548    548           generateColumnNames(pParse, 0, p->pEList);
   549    549           if( p->pOrderBy ){
   550    550             sqliteVdbeAddOp(v, OP_SortOpen, 0, 0, 0, 0);
   551    551           }
          552  +        sqliteVdbeAddOp(v, OP_Rewind, unionTab, 0, 0, 0);
   552    553           iBreak = sqliteVdbeMakeLabel(v);
   553    554           iCont = sqliteVdbeAddOp(v, OP_Next, unionTab, iBreak, 0, 0);
   554    555           rc = selectInnerLoop(pParse, 0, unionTab, p->pEList->nExpr,
   555    556                                p->pOrderBy, -1, eDest, iParm, 
   556    557                                iCont, iBreak);
   557    558           if( rc ) return 1;
   558    559           sqliteVdbeAddOp(v, OP_Goto, 0, iCont, 0, 0);
................................................................................
   597    598         ** tables.
   598    599         */
   599    600         assert( p->pEList );
   600    601         generateColumnNames(pParse, 0, p->pEList);
   601    602         if( p->pOrderBy ){
   602    603           sqliteVdbeAddOp(v, OP_SortOpen, 0, 0, 0, 0);
   603    604         }
          605  +      sqliteVdbeAddOp(v, OP_Rewind, tab1, 0, 0, 0);
   604    606         iBreak = sqliteVdbeMakeLabel(v);
   605    607         iCont = sqliteVdbeAddOp(v, OP_Next, tab1, iBreak, 0, 0);
   606    608         sqliteVdbeAddOp(v, OP_FullKey, tab1, 0, 0, 0);
   607    609         sqliteVdbeAddOp(v, OP_NotFound, tab2, iCont, 0, 0);
   608    610         rc = selectInnerLoop(pParse, 0, tab1, p->pEList->nExpr,
   609    611                                p->pOrderBy, -1, eDest, iParm, 
   610    612                                iCont, iBreak);

Changes to src/sqliteInt.h.

    19     19   ** Author contact information:
    20     20   **   drh@hwaci.com
    21     21   **   http://www.hwaci.com/drh/
    22     22   **
    23     23   *************************************************************************
    24     24   ** Internal interface definitions for SQLite.
    25     25   **
    26         -** @(#) $Id: sqliteInt.h,v 1.44 2001/09/13 14:46:10 drh Exp $
           26  +** @(#) $Id: sqliteInt.h,v 1.45 2001/09/13 16:18:54 drh Exp $
    27     27   */
    28     28   #include "sqlite.h"
    29     29   #include "vdbe.h"
    30     30   #include "parse.h"
    31     31   #include "btree.h"
    32     32   #include <stdio.h>
    33     33   #include <stdlib.h>
................................................................................
   355    355     Token sFirstToken;   /* The first token parsed */
   356    356     Token sLastToken;    /* The last token parsed */
   357    357     Table *pNewTable;    /* A table being constructed by CREATE TABLE */
   358    358     Vdbe *pVdbe;         /* An engine for executing database bytecode */
   359    359     int colNamesSet;     /* TRUE after OP_ColumnCount has been issued to pVdbe */
   360    360     int explain;         /* True if the EXPLAIN flag is found on the query */
   361    361     int initFlag;        /* True if reparsing CREATE TABLEs */
          362  +  int newTnum;         /* Table number to use when reparsing CREATE TABLEs */
   362    363     int nErr;            /* Number of errors seen */
   363    364     int nTab;            /* Number of previously allocated cursors */
   364    365     int nMem;            /* Number of memory cells used so far */
   365    366     int nSet;            /* Number of sets used so far */
   366    367     int nAgg;            /* Number of aggregate expressions */
   367    368     AggExpr *aAgg;       /* An array of aggregate expressions */
   368    369     int iAggCount;       /* Index of the count(*) aggregate in aAgg[] */

Changes to src/vdbe.c.

    37     37   ** inplicit conversion from one type to the other occurs as necessary.
    38     38   ** 
    39     39   ** Most of the code in this file is taken up by the sqliteVdbeExec()
    40     40   ** function which does the work of interpreting a VDBE program.
    41     41   ** But other routines are also provided to help in building up
    42     42   ** a program instruction by instruction.
    43     43   **
    44         -** $Id: vdbe.c,v 1.62 2001/09/13 15:21:32 drh Exp $
           44  +** $Id: vdbe.c,v 1.63 2001/09/13 16:18:54 drh Exp $
    45     45   */
    46     46   #include "sqliteInt.h"
    47     47   #include <ctype.h>
    48     48   
    49     49   /*
    50     50   ** SQL is translated into a sequence of instructions to be
    51     51   ** executed by a virtual machine.  Each instruction is an instance
................................................................................
  1794   1794     }
  1795   1795     nByte += sizeof(int)*nField;
  1796   1796     zNewRecord = sqliteMalloc( nByte );
  1797   1797     if( zNewRecord==0 ) goto no_mem;
  1798   1798     j = 0;
  1799   1799     addr = sizeof(int)*nField;
  1800   1800     for(i=p->tos-nField+1; i<=p->tos; i++){
         1801  +    memcpy(&zNewRecord[j], (char*)&addr, sizeof(int));
         1802  +    j += sizeof(int);
  1801   1803       if( (aStack[i].flags & STK_Null)==0 ){
  1802   1804         addr += aStack[i].n;
  1803   1805       }
  1804         -    memcpy(&zNewRecord[j], (char*)&addr, sizeof(int));
  1805         -    j += sizeof(int);
  1806   1806     }
  1807   1807     for(i=p->tos-nField+1; i<=p->tos; i++){
  1808   1808       if( (aStack[i].flags & STK_Null)==0 ){
  1809   1809         memcpy(&zNewRecord[j], zStack[i], aStack[i].n);
  1810   1810         j += aStack[i].n;
  1811   1811       }
  1812   1812     }
................................................................................
  2296   2296   ** If the KeyAsData opcode has previously executed on this cursor,
  2297   2297   ** then the field might be extracted from the key rather than the
  2298   2298   ** data.
  2299   2299   */
  2300   2300   case OP_Column: {
  2301   2301     int amt, offset, nCol, payloadSize;
  2302   2302     int aHdr[10];
  2303         -  const int mxHdr = sizeof(aHdr)/sizeof(aHdr[0]);
         2303  +  static const int mxHdr = sizeof(aHdr)/sizeof(aHdr[0]);
  2304   2304     int i = pOp->p1;
  2305   2305     int p2 = pOp->p2;
  2306   2306     int tos = ++p->tos;
  2307   2307     BtCursor *pCrsr;
  2308   2308     char *z;
  2309   2309   
  2310   2310     VERIFY( if( NeedStack(p, tos) ) goto no_mem; )
................................................................................
  2334   2334       if( payloadSize < sizeof(int)*(p2+1) ){
  2335   2335         rc = SQLITE_CORRUPT;
  2336   2336         goto abort_due_to_error;
  2337   2337       }
  2338   2338       if( p2+1<mxHdr ){
  2339   2339         (*xRead)(pCrsr, 0, sizeof(aHdr[0])*(p2+2), (char*)aHdr);
  2340   2340         nCol = aHdr[0];
         2341  +      nCol /= sizeof(int);
  2341   2342         offset = aHdr[p2];
  2342   2343         if( p2 == nCol-1 ){
  2343   2344           amt = payloadSize - offset;
  2344   2345         }else{
  2345   2346           amt = aHdr[p2+1] - offset;
  2346   2347         }
  2347   2348       }else{

Changes to src/where.c.

    21     21   **   http://www.hwaci.com/drh/
    22     22   **
    23     23   *************************************************************************
    24     24   ** This module contains C code that generates VDBE code used to process
    25     25   ** the WHERE clause of SQL statements.  Also found here are subroutines
    26     26   ** to generate VDBE code to evaluate expressions.
    27     27   **
    28         -** $Id: where.c,v 1.17 2001/09/13 14:46:11 drh Exp $
           28  +** $Id: where.c,v 1.18 2001/09/13 16:18:55 drh Exp $
    29     29   */
    30     30   #include "sqliteInt.h"
    31     31   
    32     32   /*
    33     33   ** The query generator uses an array of instances of this structure to
    34     34   ** help it analyze the subexpressions of the WHERE clause.  Each WHERE
    35     35   ** clause subexpression is separated from the others by an AND operator.
................................................................................
   354    354           sqliteVdbeAddOp(v, OP_MoveTo, base+idx, 0, 0, 0);
   355    355           haveKey = 0;
   356    356         }
   357    357       }else if( pIdx==0 ){
   358    358         /* Case 2:  There was no usable index.  We must do a complete
   359    359         ** scan of the table.
   360    360         */
          361  +      sqliteVdbeAddOp(v, OP_Rewind, base+idx, 0, 0, 0);
   361    362         cont = sqliteVdbeMakeLabel(v);
   362    363         sqliteVdbeAddOp(v, OP_Next, base+idx, brk, 0, cont);
   363    364         haveKey = 0;
   364    365       }else{
   365    366         /* Case 3:  We do have a usable index in pIdx.
   366    367         */
   367    368         cont = sqliteVdbeMakeLabel(v);