/ Check-in [ce45dea9]
Login

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

Overview
Comment:separate Select structure (CVS 51)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ce45dea902f9010a1c2c9ba3550dd789e7c15fcd
User & Date: drh 2000-06-05 16:01:39
Context
2000-06-05
18:54
:-) (CVS 52) check-in: c02268bd user: drh tags: trunk
16:01
separate Select structure (CVS 51) check-in: ce45dea9 user: drh tags: trunk
02:07
:-) (CVS 50) check-in: 1cf2873d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

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.8 2000/06/05 02:07:04 drh Exp $
           29  +** $Id: main.c,v 1.9 2000/06/05 16:01:39 drh Exp $
    30     30   */
    31     31   #include "sqliteInt.h"
    32     32   
    33     33   /*
    34     34   ** This is the callback routine for the code that initializes the
    35     35   ** database.  Each callback contains text of a CREATE TABLE or
    36     36   ** CREATE INDEX statement that must be parsed to yield the internal
    37     37   ** structures that describe the tables.
    38     38   */
    39     39   static int sqliteOpenCb(void *pDb, int argc, char **argv, char **azColName){
    40     40     sqlite *db = (sqlite*)pDb;
    41     41     Parse sParse;
    42     42     int nErr;
    43         -  char *zErrMsg = 0;
    44     43   
    45     44     if( argc!=1 ) return 0;
    46     45     memset(&sParse, 0, sizeof(sParse));
    47     46     sParse.db = db;
    48     47     sParse.initFlag = 1;
    49     48     nErr = sqliteRunParser(&sParse, argv[0], 0);
    50     49     return nErr;

Changes to src/parse.y.

    22     22   **
    23     23   *************************************************************************
    24     24   ** This file contains SQLite's grammar for SQL.  Process this file
    25     25   ** using the lemon parser generator to generate C code that runs
    26     26   ** the parser.  Lemon will also generate a header file containing
    27     27   ** numeric codes for all of the tokens.
    28     28   **
    29         -** @(#) $Id: parse.y,v 1.8 2000/06/03 19:19:41 drh Exp $
           29  +** @(#) $Id: parse.y,v 1.9 2000/06/05 16:01:39 drh Exp $
    30     30   */
    31     31   %token_prefix TK_
    32     32   %token_type {Token}
    33     33   %extra_argument {Parse *pParse}
    34     34   %syntax_error {
    35     35     sqliteSetNString(&pParse->zErrMsg,"syntax error near \"",0,TOKEN.z,TOKEN.n,
    36     36                      "\"", 1, 0);
................................................................................
   128    128   
   129    129   // The next command format is dropping tables.
   130    130   //
   131    131   cmd ::= DROP TABLE id(X).          {sqliteDropTable(pParse,&X);}
   132    132   
   133    133   // The select statement
   134    134   //
   135         -cmd ::= select.
   136         -select ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) orderby_opt(Z).
   137         -     {sqliteSelect(pParse, W, X, Y, Z, D);}
   138         -select ::= SELECT distinct(D) STAR from(X) where_opt(Y) orderby_opt(Z).
   139         -     {sqliteSelect(pParse, 0, X, Y, Z, D);}
          135  +cmd ::= select(X).  {
          136  +  sqliteSelect(pParse, X, 0, 0);
          137  +  sqliteSelectDelete(X);
          138  +}
   140    139   
          140  +%type select {Select*}
          141  +%destructor select {sqliteSelectDelete($$);}
          142  +
          143  +select(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
          144  +              orderby_opt(Z). {
          145  +  A = sqliteSelectNew(W,X,Y,0,0,Z,D);
          146  +}
          147  +
          148  +// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
          149  +// present and false (0) if it is not.
          150  +//
   141    151   %type distinct {int}
   142         -
   143    152   distinct(A) ::= DISTINCT.   {A = 1;}
   144    153   distinct(A) ::= .           {A = 0;}
   145    154   
          155  +// selcollist is a list of expressions that are to become the return
          156  +// values of the SELECT statement.  In the case of "SELECT * FROM ..."
          157  +// the selcollist value is NULL.  
          158  +//
   146    159   %type selcollist {ExprList*}
   147    160   %destructor selcollist {sqliteExprListDelete($$);}
   148    161   %type sclp {ExprList*}
   149    162   %destructor sclp {sqliteExprListDelete($$);}
   150         -
   151    163   sclp(A) ::= selcollist(X) COMMA.             {A = X;}
   152    164   sclp(A) ::= .                                {A = 0;}
          165  +selcollist(A) ::= STAR.                      {A = 0;}
   153    166   selcollist(A) ::= sclp(P) expr(X).           {A = sqliteExprListAppend(P,X,0);}
   154         -selcollist(A) ::= sclp(P) expr(X) AS ID(Y).  {A = sqliteExprListAppend(P,X,&Y);}
   155         -selcollist(A) ::= sclp(P) expr(X) AS STRING(Y).
          167  +selcollist(A) ::= sclp(P) expr(X) as ID(Y).  {A = sqliteExprListAppend(P,X,&Y);}
          168  +selcollist(A) ::= sclp(P) expr(X) as STRING(Y).
   156    169     {A = sqliteExprListAppend(P,X,&Y);}
          170  +as ::= .
          171  +as ::= AS.
          172  +
   157    173   
   158    174   %type seltablist {IdList*}
   159    175   %destructor seltablist {sqliteIdListDelete($$);}
   160    176   %type stl_prefix {IdList*}
   161    177   %destructor stl_prefix {sqliteIdListDelete($$);}
   162    178   %type from {IdList*}
   163    179   %destructor from {sqliteIdListDelete($$);}
................................................................................
   175    191   %type sortlist {ExprList*}
   176    192   %destructor sortlist {sqliteExprListDelete($$);}
   177    193   %type sortitem {Expr*}
   178    194   %destructor sortitem {sqliteExprDelete($$);}
   179    195   
   180    196   orderby_opt(A) ::= .                          {A = 0;}
   181    197   orderby_opt(A) ::= ORDER BY sortlist(X).      {A = X;}
   182         -sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z).  
   183         -  {
   184         -    A = sqliteExprListAppend(X,Y,0);
   185         -    A->a[A->nExpr-1].idx = Z;
   186         -  }
   187         -sortlist(A) ::= sortitem(Y) sortorder(Z).
   188         -  {
   189         -    A = sqliteExprListAppend(0,Y,0);
   190         -    A->a[0].idx = Z;
   191         -  }
          198  +sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
          199  +  A = sqliteExprListAppend(X,Y,0);
          200  +  A->a[A->nExpr-1].idx = Z;       /* 0 for ascending order, 1 for decending */
          201  +}
          202  +sortlist(A) ::= sortitem(Y) sortorder(Z). {
          203  +  A = sqliteExprListAppend(0,Y,0);
          204  +  A->a[0].idx = Z;
          205  +}
   192    206   sortitem(A) ::= expr(X).   {A = X;}
   193    207   
   194    208   %type sortorder {int}
   195    209   
   196    210   sortorder(A) ::= ASC.      {A = 0;}
   197    211   sortorder(A) ::= DESC.     {A = 1;}
   198    212   sortorder(A) ::= .         {A = 0;}

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.6 2000/06/04 12:58:38 drh Exp $
           27  +** $Id: select.c,v 1.7 2000/06/05 16:01:39 drh Exp $
    28     28   */
    29     29   #include "sqliteInt.h"
    30     30   
    31     31   
    32     32   /*
    33         -** Process a SELECT statement.
           33  +** Allocate a new Select structure and return a pointer to that
           34  +** structure.
           35  +*/
           36  +Select *sqliteSelectNew(
           37  +  ExprList *pEList,
           38  +  IdList *pSrc,
           39  +  Expr *pWhere,
           40  +  ExprList *pGroupBy,
           41  +  Expr *pHaving,
           42  +  ExprList *pOrderBy,
           43  +  int isDistinct
           44  +){
           45  +  Select *pNew;
           46  +  pNew = sqliteMalloc( sizeof(*pNew) );
           47  +  if( pNew==0 ) return 0;
           48  +  pNew->pEList = pEList;
           49  +  pNew->pSrc = pSrc;
           50  +  pNew->pWhere = pWhere;
           51  +  pNew->pGroupBy = pGroupBy;
           52  +  pNew->pHaving = pHaving;
           53  +  pNew->pOrderBy = pOrderBy;
           54  +  pNew->isDistinct = isDistinct;
           55  +  return pNew;
           56  +}
           57  +
           58  +/*
           59  +** Delete the given Select structure and all of its substructures.
           60  +*/
           61  +void sqliteSelectDelete(Select *p){
           62  +  sqliteExprListDelete(p->pEList);
           63  +  sqliteIdListDelete(p->pSrc);
           64  +  sqliteExprDelete(p->pWhere);
           65  +  sqliteExprListDelete(p->pGroupBy);
           66  +  sqliteExprDelete(p->pHaving);
           67  +  sqliteExprListDelete(p->pOrderBy);
           68  +  sqliteFree(p);
           69  +}
           70  +
           71  +/*
           72  +** Generate code for the given SELECT statement.
           73  +**
           74  +** If pDest==0 and iMem<0, then the results of the query are sent to
           75  +** the callback function.  If pDest!=0 then the results are written to
           76  +** the single table specified.  If pDest==0 and iMem>=0 then the result
           77  +** should be a single value which is then stored in memory location iMem
           78  +** of the virtual machine.
           79  +**
           80  +** This routine returns the number of errors.  If any errors are
           81  +** encountered, then an appropriate error message is left in
           82  +** pParse->zErrMsg.
           83  +**
           84  +** This routine does NOT free the Select structure passed in.  The
           85  +** calling function needs to do that.
    34     86   */
    35         -void sqliteSelect(
           87  +int sqliteSelect(
    36     88     Parse *pParse,         /* The parser context */
    37         -  ExprList *pEList,      /* List of fields to extract.  NULL means "*" */
    38         -  IdList *pTabList,      /* List of tables to select from */
    39         -  Expr *pWhere,          /* The WHERE clause.  May be NULL */
    40         -  ExprList *pOrderBy,    /* The ORDER BY clause.  May be NULL */
    41         -  int distinct           /* If true, only output distinct results */
           89  +  Select *p,             /* The SELECT statement being coded. */
           90  +  Table *pDest,          /* Write results here, if not NULL */
           91  +  int iMem               /* Save result in this memory location, if >=0 */
    42     92   ){
    43     93     int i, j;
    44     94     WhereInfo *pWInfo;
    45     95     Vdbe *v;
    46     96     int isAgg = 0;         /* True for select lists like "count(*)" */
           97  +  ExprList *pEList;      /* List of fields to extract.  NULL means "*" */
           98  +  IdList *pTabList;      /* List of tables to select from */
           99  +  Expr *pWhere;          /* The WHERE clause.  May be NULL */
          100  +  ExprList *pOrderBy;    /* The ORDER BY clause.  May be NULL */
          101  +  int distinct;          /* If true, only output distinct results */
    47    102   
    48         -  if( pParse->nErr>0 ) goto select_cleanup;
          103  +
          104  +  pEList = p->pEList;
          105  +  pTabList = p->pSrc;
          106  +  pWhere = p->pWhere;
          107  +  pOrderBy = p->pOrderBy;
          108  +  distinct = p->isDistinct;
          109  +
          110  +  /* 
          111  +  ** Do not even attempt to generate any code if we have already seen
          112  +  ** errors before this routine starts.
          113  +  */
          114  +  if( pParse->nErr>0 ) return 0;
    49    115   
    50    116     /* Look up every table in the table list.
    51    117     */
    52    118     for(i=0; i<pTabList->nId; i++){
    53    119       pTabList->a[i].pTab = sqliteFindTable(pParse->db, pTabList->a[i].zName);
    54    120       if( pTabList->a[i].pTab==0 ){
    55    121         sqliteSetString(&pParse->zErrMsg, "no such table: ", 
    56    122            pTabList->a[i].zName, 0);
    57    123         pParse->nErr++;
    58         -      goto select_cleanup;
          124  +      return 1;
    59    125       }
    60    126     }
    61    127   
    62    128     /* If the list of fields to retrieve is "*" then replace it with
    63    129     ** a list of all fields from all tables.
    64    130     */
    65    131     if( pEList==0 ){
................................................................................
    74    140       }
    75    141     }
    76    142   
    77    143     /* Resolve the field names and do a semantics check on all the expressions.
    78    144     */
    79    145     for(i=0; i<pEList->nExpr; i++){
    80    146       if( sqliteExprResolveIds(pParse, pTabList, pEList->a[i].pExpr) ){
    81         -      goto select_cleanup;
          147  +      return 1;
    82    148       }
    83    149       if( sqliteExprCheck(pParse, pEList->a[i].pExpr, 1, &pEList->a[i].isAgg) ){
    84         -      goto select_cleanup;
          150  +      return 1;
    85    151       }
    86    152     }
    87    153     if( pEList->nExpr>0 ){
    88    154       isAgg = pEList->a[0].isAgg;
    89    155       for(i=1; i<pEList->nExpr; i++){
    90    156         if( pEList->a[i].isAgg!=isAgg ){
    91    157           sqliteSetString(&pParse->zErrMsg, "some selected items are aggregates "
    92    158             "and others are not", 0);
    93    159           pParse->nErr++;
    94         -        goto select_cleanup;
          160  +        return 1;
    95    161         }
    96    162       }
    97    163     }
    98    164     if( pWhere ){
    99    165       if( sqliteExprResolveIds(pParse, pTabList, pWhere) ){
   100         -      goto select_cleanup;
          166  +      return 1;
   101    167       }
   102    168       if( sqliteExprCheck(pParse, pWhere, 0, 0) ){
   103         -      goto select_cleanup;
          169  +      return 1;
   104    170       }
   105    171     }
   106    172     if( pOrderBy ){
   107    173       for(i=0; i<pOrderBy->nExpr; i++){
   108    174         if( sqliteExprResolveIds(pParse, pTabList, pOrderBy->a[i].pExpr) ){
   109         -        goto select_cleanup;
          175  +        return 1;
   110    176         }
   111    177         if( sqliteExprCheck(pParse, pOrderBy->a[i].pExpr, 0, 0) ){
   112         -        goto select_cleanup;
          178  +        return 1;
   113    179         }
   114    180       }
   115    181     }
   116    182   
   117    183     /* ORDER BY is ignored if this is an aggregate query like count(*)
   118    184     ** since only one row will be returned.
   119    185     */
   120    186     if( isAgg && pOrderBy ){
   121         -    sqliteExprListDelete(pOrderBy);
   122    187       pOrderBy = 0;
   123    188     }
   124    189   
   125    190     /* Turn off distinct if this is an aggregate
   126    191     */
   127    192     if( isAgg ){
   128    193       distinct = 0;
................................................................................
   130    195   
   131    196     /* Begin generating code.
   132    197     */
   133    198     v = pParse->pVdbe;
   134    199     if( v==0 ){
   135    200       v = pParse->pVdbe = sqliteVdbeCreate(pParse->db->pBe);
   136    201     }
   137         -  if( v==0 ) goto select_cleanup;
          202  +  if( v==0 ){
          203  +    sqliteSetString(&pParse->zErrMsg, "out of memory", 0);
          204  +    pParse->nErr++;
          205  +    return 1;
          206  +  }
   138    207     if( pOrderBy ){
   139    208       sqliteVdbeAddOp(v, OP_SortOpen, 0, 0, 0, 0);
   140    209     }
   141    210   
   142    211     /* Identify column names
   143    212     */
   144    213     sqliteVdbeAddOp(v, OP_ColumnCount, pEList->nExpr, 0, 0, 0);
................................................................................
   197    266     /* Begin the database scan
   198    267     */
   199    268     if( distinct ){
   200    269       distinct = pTabList->nId*2+1;
   201    270       sqliteVdbeAddOp(v, OP_Open, distinct, 1, 0, 0);
   202    271     }
   203    272     pWInfo = sqliteWhereBegin(pParse, pTabList, pWhere, 0);
   204         -  if( pWInfo==0 ) goto select_cleanup;
          273  +  if( pWInfo==0 ) return 1;
   205    274   
   206    275     /* Pull the requested fields.
   207    276     */
   208    277     if( !isAgg ){
   209    278       for(i=0; i<pEList->nExpr; i++){
   210    279         sqliteExprCode(pParse, pEList->a[i].pExpr);
   211    280       }
................................................................................
   228    297     ** right away.  If there is an ORDER BY, then we need to put the
   229    298     ** data into an appropriate sorter record.
   230    299     */
   231    300     if( pOrderBy ){
   232    301       char *zSortOrder;
   233    302       sqliteVdbeAddOp(v, OP_SortMakeRec, pEList->nExpr, 0, 0, 0);
   234    303       zSortOrder = sqliteMalloc( pOrderBy->nExpr + 1 );
   235         -    if( zSortOrder==0 ) goto select_cleanup;
          304  +    if( zSortOrder==0 ) return 1;
   236    305       for(i=0; i<pOrderBy->nExpr; i++){
   237    306         zSortOrder[i] = pOrderBy->a[i].idx ? '-' : '+';
   238    307         sqliteExprCode(pParse, pOrderBy->a[i].pExpr);
   239    308       }
   240    309       zSortOrder[pOrderBy->nExpr] = 0;
   241    310       sqliteVdbeAddOp(v, OP_SortMakeKey, pOrderBy->nExpr, 0, zSortOrder, 0);
   242    311       sqliteVdbeAddOp(v, OP_SortPut, 0, 0, 0, 0);
................................................................................
   284    353   
   285    354     /* If this is an aggregate, then we need to invoke the callback
   286    355     ** exactly once.
   287    356     */
   288    357     if( isAgg ){
   289    358       sqliteVdbeAddOp(v, OP_Callback, pEList->nExpr, 0, 0, 0);
   290    359     }
   291         -
   292         -  /* Always execute the following code before exiting, in order to
   293         -  ** release resources.
   294         -  */
   295         -select_cleanup:
   296         -  sqliteExprListDelete(pEList);
   297         -  sqliteIdListDelete(pTabList);
   298         -  sqliteExprDelete(pWhere);
   299         -  sqliteExprListDelete(pOrderBy);
   300         -  return;
          360  +  return 0;
   301    361   }

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.13 2000/06/05 02:07:04 drh Exp $
           26  +** @(#) $Id: sqliteInt.h,v 1.14 2000/06/05 16:01:39 drh Exp $
    27     27   */
    28     28   #include "sqlite.h"
    29     29   #include "dbbe.h"
    30     30   #include "vdbe.h"
    31     31   #include "parse.h"
    32     32   #include <gdbm.h>
    33     33   #include <stdio.h>
    34     34   #include <stdlib.h>
    35     35   #include <string.h>
    36     36   #include <assert.h>
    37     37   
    38         -/* #define MEMORY_DEBUG 1 */
           38  +#define MEMORY_DEBUG 1
    39     39   #ifdef MEMORY_DEBUG
    40     40   # define sqliteMalloc(X)    sqliteMalloc_(X,__FILE__,__LINE__)
    41     41   # define sqliteFree(X)      sqliteFree_(X,__FILE__,__LINE__)
    42     42   # define sqliteRealloc(X,Y) sqliteRealloc_(X,Y,__FILE__,__LINE__)
    43     43     void sqliteStrRealloc(char**);
    44     44   #else
    45     45   # define sqliteStrRealloc(X)
................................................................................
    83     83   typedef struct Instruction Instruction;
    84     84   typedef struct Expr Expr;
    85     85   typedef struct ExprList ExprList;
    86     86   typedef struct Parse Parse;
    87     87   typedef struct Token Token;
    88     88   typedef struct IdList IdList;
    89     89   typedef struct WhereInfo WhereInfo;
           90  +typedef struct Select Select;
    90     91   
    91     92   /*
    92     93   ** Each database is an instance of the following structure
    93     94   */
    94     95   struct sqlite {
    95     96     Dbbe *pBe;                 /* The backend driver */
    96     97     int flags;                 /* Miscellanous flags */
................................................................................
   204    205   struct WhereInfo {
   205    206     Parse *pParse;
   206    207     IdList *pTabList;
   207    208     int iContinue;
   208    209     int iBreak;
   209    210   };
   210    211   
          212  +/*
          213  +** An instance of the following structure contains all information
          214  +** needed to generate code for a single SELECT statement.
          215  +*/
          216  +struct Select {
          217  +  int isDistinct;        /* True if the DISTINCT keyword is present */
          218  +  ExprList *pEList;      /* The fields of the result */
          219  +  IdList *pSrc;          /* The FROM clause */
          220  +  Expr *pWhere;          /* The WHERE clause */
          221  +  ExprList *pGroupBy;    /* The GROUP BY clause */
          222  +  Expr *pHaving;         /* The HAVING clause */
          223  +  ExprList *pOrderBy;    /* The ORDER BY clause */
          224  +};
          225  +
   211    226   /*
   212    227   ** An SQL parser context
   213    228   */
   214    229   struct Parse {
   215    230     sqlite *db;          /* The main database structure */
   216    231     sqlite_callback xCallback;  /* The callback function */
   217    232     void *pArg;          /* First argument to the callback function */
................................................................................
   262    277   void sqliteDeleteTable(sqlite*, Table*);
   263    278   void sqliteInsert(Parse*, Token*, ExprList*, IdList*);
   264    279   IdList *sqliteIdListAppend(IdList*, Token*);
   265    280   void sqliteIdListAddAlias(IdList*, Token*);
   266    281   void sqliteIdListDelete(IdList*);
   267    282   void sqliteCreateIndex(Parse*, Token*, Token*, IdList*, Token*, Token*);
   268    283   void sqliteDropIndex(Parse*, Token*);
   269         -void sqliteSelect(Parse*, ExprList*, IdList*, Expr*, ExprList*, int);
          284  +int sqliteSelect(Parse*, Select*, Table*, int);
          285  +Select *sqliteSelectNew(ExprList*,IdList*,Expr*,ExprList*,Expr*,ExprList*,int);
          286  +void sqliteSelectDelete(Select*);
   270    287   void sqliteDeleteFrom(Parse*, Token*, Expr*);
   271    288   void sqliteUpdate(Parse*, Token*, ExprList*, Expr*);
   272    289   WhereInfo *sqliteWhereBegin(Parse*, IdList*, Expr*, int);
   273    290   void sqliteWhereEnd(WhereInfo*);
   274    291   void sqliteExprCode(Parse*, Expr*);
   275    292   void sqliteExprIfTrue(Parse*, Expr*, int);
   276    293   void sqliteExprIfFalse(Parse*, Expr*, int);

Changes to src/util.c.

    22     22   **
    23     23   *************************************************************************
    24     24   ** Utility functions used throughout sqlite.
    25     25   **
    26     26   ** This file contains functions for allocating memory, comparing
    27     27   ** strings, and stuff like that.
    28     28   **
    29         -** $Id: util.c,v 1.10 2000/06/04 12:58:38 drh Exp $
           29  +** $Id: util.c,v 1.11 2000/06/05 16:01:39 drh Exp $
    30     30   */
    31     31   #include "sqliteInt.h"
    32     32   #include <stdarg.h>
    33     33   #include <ctype.h>
    34     34   
    35     35   #ifdef MEMORY_DEBUG
    36     36   
................................................................................
    98     98       sqliteFree_(oldP,zFile,line);
    99     99       return 0;
   100    100     }
   101    101     oldPi = oldP;
   102    102     oldPi -= 2;
   103    103     if( oldPi[0]!=0xdead1122 ){
   104    104       fprintf(stderr,"Low-end memory corruption in realloc at 0x%x\n", (int)p);
   105         -    return;
          105  +    return 0;
   106    106     }
   107    107     oldN = oldPi[1];
   108    108     oldK = (oldN+sizeof(int)-1)/sizeof(int);
   109    109     if( oldPi[oldK+2]!=0xdead3344 ){
   110    110       fprintf(stderr,"High-end memory corruption in realloc at 0x%x\n", (int)p);
   111         -    return;
          111  +    return 0;
   112    112     }
   113    113     k = (n + sizeof(int) - 1)/sizeof(int);
   114    114     pi = malloc( (k+3)*sizeof(int) );
   115    115     pi[0] = 0xdead1122;
   116    116     pi[1] = n;
   117    117     pi[k+2] = 0xdead3344;
   118    118     p = &pi[2];

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.14 2000/06/05 02:07:04 drh Exp $
           44  +** $Id: vdbe.c,v 1.15 2000/06/05 16:01:39 drh Exp $
    45     45   */
    46     46   #include "sqliteInt.h"
           47  +#include <unistd.h>
    47     48   
    48     49   /*
    49     50   ** SQL is translated into a sequence of instructions to be
    50     51   ** executed by a virtual machine.  Each instruction is an instance
    51     52   ** of the following structure.
    52     53   */
    53     54   typedef struct VdbeOp Op;
................................................................................
   737    738   
   738    739         /* Opcode: NULL * * *
   739    740         **
   740    741         ** Push a NULL value onto the stack.
   741    742         */
   742    743         case OP_Null: {
   743    744           int i = ++p->tos;
   744         -        char *z;
   745    745           if( NeedStack(p, p->tos) ) goto no_mem;
   746    746           p->zStack[i] = 0;
   747    747           p->aStack[i].flags = STK_Null;
   748    748           break;
   749    749         }
   750    750   
   751    751         /* Opcode: Pop P1 * *