/ Check-in [ac2d5a60]
Login

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

Overview
Comment:More use of sqlite3NestedParse. This version of the code does not work. (CVS 2060)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ac2d5a605c873cac68bfde4bbe3797608a47b21e
User & Date: drh 2004-11-05 05:10:29
Context
2004-11-05
05:20
Fix a bug in the previous check-in. (CVS 2061) check-in: 9d259d48 user: drh tags: trunk
05:10
More use of sqlite3NestedParse. This version of the code does not work. (CVS 2060) check-in: ac2d5a60 user: drh tags: trunk
03:56
Begin using sqlite3NestedParse() to generate sections of code. (CVS 2059) check-in: 2d302931 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **     PRAGMA
    25     25   **
    26     26   <<<<<<< build.c
    27         -** $Id: build.c,v 1.263 2004/11/05 03:56:02 drh Exp $
           27  +** $Id: build.c,v 1.264 2004/11/05 05:10:29 drh Exp $
    28     28   =======
    29         -** $Id: build.c,v 1.263 2004/11/05 03:56:02 drh Exp $
           29  +** $Id: build.c,v 1.264 2004/11/05 05:10:29 drh Exp $
    30     30   >>>>>>> 1.262
    31     31   */
    32     32   #include "sqliteInt.h"
    33     33   #include <ctype.h>
    34     34   
    35     35   /*
    36     36   ** This routine is called when a new SQL statement is beginning to
................................................................................
  1631   1631   
  1632   1632   /*
  1633   1633   ** Write code to erase the table with root-page iTable from database iDb.
  1634   1634   ** Also write code to modify the sqlite_master table and internal schema
  1635   1635   ** if a root-page of another table is moved by the btree-layer whilst
  1636   1636   ** erasing iTable (this can happen with an auto-vacuum database).
  1637   1637   */ 
  1638         -static void destroyRootPage(Vdbe *v, int iTable, int iDb){
         1638  +static void destroyRootPage(Parse *pParse, int iTable, int iDb){
         1639  +  Vdbe *v = sqlite3GetVdbe(pParse);
         1640  +  sqlite3VdbeAddOp(v, OP_Destroy, iTable, iDb);
  1639   1641   #ifndef SQLITE_OMIT_AUTOVACUUM
  1640         -  int base;
  1641         -  /* If SQLITE_OMIT_AUTOVACUUM is not defined, then OP_Destroy pushes
  1642         -  ** an integer onto the stack. If this integer is non-zero, then it is
  1643         -  ** the root page number of a table moved to location iTable. The 
  1644         -  ** following writes VDBE code to modify the sqlite_master table to
  1645         -  ** reflect this. It is assumed that cursor number 0 is a write-cursor
  1646         -  ** opened on the sqlite_master table.
  1647         -  */
  1648         -  static /*const*/ VdbeOpList updateMaster[] = {
  1649         -    /* If the Op_Destroy pushed a 0 onto the stack, then skip the following
  1650         -    ** code. sqlite_master does not need updating in this case.
  1651         -    */
  1652         -    { OP_Dup,        0, 0,        0},
  1653         -    { OP_Integer,    0, 0,        0},
  1654         -    { OP_Eq,         0, ADDR(17), 0},
  1655         -
  1656         -    /* Search for the sqlite_master row containing root-page iTable. */
  1657         -    { OP_Rewind,     0, ADDR(8), 0}, 
  1658         -    { OP_Dup,        0, 0,       0}, /* 4 */
  1659         -    { OP_Column,     0, 3,       0}, /* 5 */
  1660         -    { OP_Eq,         0, ADDR(9), 0},
  1661         -    { OP_Next,       0, ADDR(4), 0},
  1662         -    { OP_Halt,       SQLITE_CORRUPT, OE_Fail, 0}, /* 8 */
  1663         -    { OP_Recno,      0, 0,       0}, /* 9 */
  1664         -
  1665         -    /* Cursor 0 now points at the row that will be updated. The top of
  1666         -    ** the stack is the rowid of that row. The next value on the stack is 
  1667         -    ** the new value for the root-page field.
  1668         -    */
  1669         -    { OP_Column,     0, 0,       0}, /* 10 */
  1670         -    { OP_Column,     0, 1,       0},
  1671         -    { OP_Column,     0, 2,       0},
  1672         -    { OP_Integer,    4, 0,       0}, /* 13 */
  1673         -    { OP_Column,     0, 4,       0},
  1674         -    { OP_MakeRecord, 5, 0,       0},
  1675         -    { OP_PutIntKey,  0, 0,       0}  /* 16 */
  1676         -  };
  1677         -#endif
  1678         -
  1679         -  sqlite3VdbeAddOp(v, OP_Destroy, iTable, iDb);
  1680         -  /* sqlite3VdbeAddOp(v, OP_Pop, 1, 0); */
  1681         -#ifndef SQLITE_OMIT_AUTOVACUUM
  1682         -  base = sqlite3VdbeAddOpList(v, ArraySize(updateMaster), updateMaster);
  1683         -  sqlite3VdbeChangeP1(v, base+13, iTable);
         1642  +  /* OP_Destroy pushes an integer onto the stack. If this integer
         1643  +  ** is non-zero, then it is the root page number of a table moved to
         1644  +  ** location iTable. The following code modifis the sqlite_master table to
         1645  +  ** reflect this.
         1646  +  **
         1647  +  ** The "#0" in the SQL is a special constant that means whatever value
         1648  +  ** is on the top of the stack.  See sqlite3RegisterExpr().
         1649  +  */
         1650  +  sqlite3NestedParse(pParse, "UPDATE %Q.%Q SET rootpage=#0 WHERE rootpage=%d",
         1651  +     pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable);
  1684   1652   #endif
  1685   1653   }
  1686   1654   
  1687   1655   /*
  1688   1656   ** Write VDBE code to erase table pTab and all associated indices on disk.
  1689   1657   ** Code to update the sqlite_master tables and internal schema definitions
  1690   1658   ** in case a root-page belonging to another table is moved by the btree layer
  1691   1659   ** is also added (this can happen with an auto-vacuum database).
  1692   1660   */
  1693         -static void destroyTable(Vdbe *v, Table *pTab){
         1661  +static void destroyTable(Parse *pParse, Table *pTab){
         1662  +  Vdbe *v = pParse->pVdbe;
  1694   1663   #ifdef SQLITE_OMIT_AUTOVACUUM
  1695         -  destroyRootPage(v, pTab->tnum, pTab->iDb);
         1664  +  destroyRootPage(pParse, pTab->tnum, pTab->iDb);
  1696   1665     for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
  1697   1666       destroyRootPage(v, pIdx->tnum, pIdx->iDb);
  1698   1667     }
  1699   1668   #else
  1700   1669     /* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
  1701   1670     ** is not defined), then it is important to call OP_Destroy on the
  1702   1671     ** table and index root-pages in order, starting with the numerically 
................................................................................
  1727   1696         int iIdx = pIdx->tnum;
  1728   1697         assert( pIdx->iDb==pTab->iDb );
  1729   1698         if( (iDestroyed==0 || (iIdx<iDestroyed)) && iIdx>iLargest ){
  1730   1699           iLargest = iIdx;
  1731   1700         }
  1732   1701       }
  1733   1702       if( iLargest==0 ) return;
  1734         -    destroyRootPage(v, iLargest, pTab->iDb);
         1703  +    destroyRootPage(pParse, iLargest, pTab->iDb);
  1735   1704       iDestroyed = iLargest;
  1736   1705     }
  1737   1706   #endif
  1738   1707   }
  1739   1708   
  1740   1709   /*
  1741   1710   ** This routine is called to do the work of a DROP TABLE statement.
................................................................................
  1823   1792       ** created in the temp database that refers to a table in another
  1824   1793       ** database.
  1825   1794       */
  1826   1795       sqlite3NestedParse(pParse, 
  1827   1796           "DELETE FROM %Q.%Q WHERE tbl_name=%Q and type!='trigger'",
  1828   1797           db->aDb[pTab->iDb].zName, SCHEMA_TABLE(pTab->iDb), pTab->zName);
  1829   1798       if( !isView ){
  1830         -      destroyTable(v, pTab);
         1799  +      destroyTable(pParse, pTab);
  1831   1800       }
  1832   1801       sqlite3VdbeOp3(v, OP_DropTable, pTab->iDb, 0, pTab->zName, 0);
  1833   1802     }
  1834   1803     sqliteViewResetAll(db, iDb);
  1835   1804   
  1836   1805   exit_drop_table:
  1837   1806     sqlite3SrcListDelete(pName);

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.167 2004/10/31 02:22:49 drh Exp $
           15  +** $Id: expr.c,v 1.168 2004/11/05 05:10:29 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
   193    193       assert( pToken->dyn==0 );
   194    194       pNew->span = pNew->token = *pToken;
   195    195     }else if( pLeft && pRight ){
   196    196       sqlite3ExprSpan(pNew, &pLeft->span, &pRight->span);
   197    197     }
   198    198     return pNew;
   199    199   }
          200  +
          201  +/*
          202  +** When doing a nested parse, you can include terms in an expression
          203  +** that look like this:   #0 #1 #2 ...  These terms refer to elements
          204  +** on the stack.  "#0" (or just "#") means the top of the stack.
          205  +** "#1" means the next down on the stack.  And so forth.
          206  +**
          207  +** This routine is called by the parser to deal with on of those terms.
          208  +** It immediately generates code to store the value in a memory location.
          209  +** The returns an expression that will code to extract the value from
          210  +** that memory location as needed.
          211  +*/
          212  +Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){
          213  +  Vdbe *v = pParse->pVdbe;
          214  +  Expr *p;
          215  +  int depth;
          216  +  if( v==0 ) return 0;
          217  +  if( pParse->nested==0 ){
          218  +    sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken);
          219  +    return 0;
          220  +  }
          221  +  p = sqlite3Expr(TK_REGISTER, 0, 0, pToken);
          222  +  depth = atoi(&pToken->z[1]);
          223  +  p->iTable = pParse->nMem++;
          224  +  sqlite3VdbeAddOp(v, OP_Dup, depth, 0);
          225  +  sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1);
          226  +  return p;
          227  +}
   200    228   
   201    229   /*
   202    230   ** Join two expressions using an AND operator.  If either expression is
   203    231   ** NULL, then just return the other expression.
   204    232   */
   205    233   Expr *sqlite3ExprAnd(Expr *pLeft, Expr *pRight){
   206    234     if( pLeft==0 ){
................................................................................
  1234   1262       }
  1235   1263       case TK_VARIABLE: {
  1236   1264         sqlite3VdbeAddOp(v, OP_Variable, pExpr->iTable, 0);
  1237   1265         if( pExpr->token.n>1 ){
  1238   1266           sqlite3VdbeChangeP3(v, -1, pExpr->token.z, pExpr->token.n);
  1239   1267         }
  1240   1268         break;
         1269  +    }
         1270  +    case TK_REGISTER: {
         1271  +      sqlite3VdbeAddOp(v, OP_MemLoad, pExpr->iTable, 0);
         1272  +      break;
  1241   1273       }
  1242   1274       case TK_LT:
  1243   1275       case TK_LE:
  1244   1276       case TK_GT:
  1245   1277       case TK_GE:
  1246   1278       case TK_NE:
  1247   1279       case TK_EQ: {

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.148 2004/11/05 00:43:12 drh Exp $
           17  +** @(#) $Id: parse.y,v 1.149 2004/11/05 05:10:29 drh Exp $
    18     18   */
    19     19   %token_prefix TK_
    20     20   %token_type {Token}
    21     21   %default_type {Token}
    22     22   %extra_argument {Parse *pParse}
    23     23   %syntax_error {
    24     24     if( pParse->zErrMsg==0 ){
................................................................................
   584    584     Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0);
   585    585     A = sqlite3Expr(TK_DOT, temp1, temp4, 0);
   586    586   }
   587    587   expr(A) ::= INTEGER(X).      {A = sqlite3Expr(@X, 0, 0, &X);}
   588    588   expr(A) ::= FLOAT(X).        {A = sqlite3Expr(@X, 0, 0, &X);}
   589    589   expr(A) ::= STRING(X).       {A = sqlite3Expr(@X, 0, 0, &X);}
   590    590   expr(A) ::= BLOB(X).         {A = sqlite3Expr(@X, 0, 0, &X);}
          591  +expr(A) ::= REGISTER(X).     {A = sqlite3RegisterExpr(pParse, &X);}
   591    592   expr(A) ::= VARIABLE(X).     {
   592    593     Token *pToken = &X;
   593    594     Expr *pExpr = A = sqlite3Expr(TK_VARIABLE, 0, 0, pToken);
   594    595     sqlite3ExprAssignVarNumber(pParse, pExpr);
   595    596   }
   596    597   expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
   597    598     A = sqlite3ExprFunction(Y, &X);

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.332 2004/11/05 03:56:02 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.333 2004/11/05 05:10:29 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** These #defines should enable >2GB file support on Posix if the
    21     21   ** underlying operating system supports it.  If the OS lacks
................................................................................
  1250   1250   void sqlite3SetString(char **, const char *, ...);
  1251   1251   void sqlite3ErrorMsg(Parse*, const char*, ...);
  1252   1252   void sqlite3Dequote(char*);
  1253   1253   int sqlite3KeywordCode(const char*, int);
  1254   1254   int sqlite3RunParser(Parse*, const char*, char **);
  1255   1255   void sqlite3FinishCoding(Parse*);
  1256   1256   Expr *sqlite3Expr(int, Expr*, Expr*, Token*);
         1257  +Expr *sqlite3RegisterExpr(Parse*,Token*);
  1257   1258   Expr *sqlite3ExprAnd(Expr*, Expr*);
  1258   1259   void sqlite3ExprSpan(Expr*,Token*,Token*);
  1259   1260   Expr *sqlite3ExprFunction(ExprList*, Token*);
  1260   1261   void sqlite3ExprAssignVarNumber(Parse*, Expr*);
  1261   1262   void sqlite3ExprDelete(Expr*);
  1262   1263   ExprList *sqlite3ExprListAppend(ExprList*,Expr*,Token*);
  1263   1264   void sqlite3ExprListDelete(ExprList*);

Changes to src/tokenize.c.

    11     11   *************************************************************************
    12     12   ** An tokenizer for SQL
    13     13   **
    14     14   ** This file contains C code that splits an SQL input string up into
    15     15   ** individual tokens and sends those tokens one-by-one over to the
    16     16   ** parser for analysis.
    17     17   **
    18         -** $Id: tokenize.c,v 1.94 2004/11/03 03:59:58 drh Exp $
           18  +** $Id: tokenize.c,v 1.95 2004/11/05 05:10:29 drh Exp $
    19     19   */
    20     20   #include "sqliteInt.h"
    21     21   #include "os.h"
    22     22   #include <ctype.h>
    23     23   #include <stdlib.h>
    24     24   
    25     25   /*
................................................................................
   172    172       case '&': {
   173    173         *tokenType = TK_BITAND;
   174    174         return 1;
   175    175       }
   176    176       case '~': {
   177    177         *tokenType = TK_BITNOT;
   178    178         return 1;
          179  +    }
          180  +    case '#': {
          181  +      for(i=1; isdigit(z[i]); i++){}
          182  +      *tokenType = TK_REGISTER;
          183  +      return i;
   179    184       }
   180    185       case '\'': case '"': {
   181    186         int delim = z[0];
   182    187         for(i=1; (c=z[i])!=0; i++){
   183    188           if( c==delim ){
   184    189             if( z[i+1]==delim ){
   185    190               i++;

Changes to test/attach2.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ATTACH and DETACH commands
    13     13   # and related functionality.
    14     14   #
    15         -# $Id: attach2.test,v 1.28 2004/11/05 03:56:02 drh Exp $
           15  +# $Id: attach2.test,v 1.29 2004/11/05 05:10:29 drh Exp $
    16     16   #
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   
    22     22   # Ticket #354
................................................................................
   321    321       CREATE TABLE aux.tbl(a, b, c);
   322    322       COMMIT;
   323    323     }
   324    324   } {}
   325    325   do_test attach2-5.3 {
   326    326     lsort [glob test.db*]
   327    327   } {test.db test.db2}
   328         -execsql {pragma vdbe_trace=on}
   329    328   do_test attach2-5.4 {
   330    329     execsql {
   331    330       BEGIN;
   332    331       DROP TABLE aux.tbl;
   333    332       DROP TABLE tbl;
   334    333       ROLLBACK;
   335    334     }

Changes to test/attach3.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing the ATTACH and DETACH commands
    13     13   # and schema changes to attached databases.
    14     14   #
    15         -# $Id: attach3.test,v 1.10 2004/11/04 04:42:28 drh Exp $
           15  +# $Id: attach3.test,v 1.11 2004/11/05 05:10:29 drh Exp $
    16     16   #
    17     17   
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Create tables t1 and t2 in the main database
................................................................................
    23     23   execsql {
    24     24     CREATE TABLE t1(a, b);
    25     25     CREATE TABLE t2(c, d);
    26     26   }
    27     27   
    28     28   # Create tables t1 and t2 in database file test2.db
    29     29   file delete -force test2.db
           30  +file delete -force test2.db-journal
    30     31   sqlite3 db2 test2.db
    31     32   execsql {
    32     33     CREATE TABLE t1(a, b);
    33     34     CREATE TABLE t2(c, d);
    34     35   } db2
    35     36   db2 close
    36     37   
................................................................................
    64     65   
    65     66   # Create an index on the auxilary database table.
    66     67   do_test attach3-2.1 {
    67     68     execsql {
    68     69       CREATE INDEX aux.i1 on t3(e);
    69     70     }
    70     71   } {}
    71         -execsql {
    72         -  pragma vdbe_trace = off;
    73         -}
    74     72   do_test attach3-2.2 {
    75     73     execsql {
    76     74       SELECT * FROM sqlite_master WHERE name = 'i1';
    77     75     }
    78     76   } {}
    79     77   do_test attach3-2.3 {
    80     78     execsql {