From: drh Date: Fri, 5 Nov 2004 05:10:28 +0000 (+0000) Subject: More use of sqlite3NestedParse. This version of the code does not work. (CVS 2060) X-Git-Tag: version-3.6.10~4090 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4e0cff6080890479afb9e418f6edebf45be35e36;p=thirdparty%2Fsqlite.git More use of sqlite3NestedParse. This version of the code does not work. (CVS 2060) FossilOrigin-Name: ac2d5a605c873cac68bfde4bbe3797608a47b21e --- diff --git a/manifest b/manifest index 65924a9014..74bc8de275 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Begin\susing\ssqlite3NestedParse()\sto\sgenerate\ssections\sof\scode.\s(CVS\s2059) -D 2004-11-05T03:56:01 +C More\suse\sof\ssqlite3NestedParse.\s\sThis\sversion\sof\sthe\scode\sdoes\snot\swork.\s(CVS\s2060) +D 2004-11-05T05:10:29 F Makefile.in c4d2416860f472a1e3393714d0372074197565df F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1 @@ -31,10 +31,10 @@ F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689 F src/auth.c 3b81f2a42f48a62c2c9c9b0eda31a157c681edea F src/btree.c f97b5a3919147fe36f776d08c80212ba3ea883aa F src/btree.h 3166388fa58c5594d8064d38b43440d79da38fb6 -F src/build.c b18a5c7cc68fe77fd6cc30f6bbeefc3ece909108 +F src/build.c 936fb262f26c5b06e7f46ee40778c8d22015bd73 F src/date.c 34bdb0082db7ec2a83ef00063f7b44e61ee19dad F src/delete.c 832adc6fe1c07b7e28e1b4c1038d2b06f7397dd4 -F src/expr.c 3a43e508a3dc213703808bbcbb17633b88b57d17 +F src/expr.c be18081d2959a2cc53846d0fbedfec40fbfa1d6e F src/func.c 600e506bccf7648df8ad03efb417560d0f7ad4c1 F src/hash.c a97721a55440b7bea31ffe471bb2f6b4123cddd5 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84 @@ -54,14 +54,14 @@ F src/os_win.c 9482dfc92f289b68205bb2c9315757c7e3946bfb F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/pager.c a43e2a392be51966129e9afb18b81551c9f222b8 F src/pager.h cbe4ba356d9dd3f30260f322b3dc77408164df14 -F src/parse.y e7f4e87a2ad14ccf5b8adcf1019fb8a355964579 +F src/parse.y 97247c0a89ca1667729db5035f1ee60140960984 F src/pragma.c 44e192eb5928157bdb015926f858a7c6e3ef6c98 F src/printf.c 7a92adc00b758cd5ce087dae80181a8bbdb70ed2 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 F src/select.c 156990c636102bb6b8de85e7ff3396a62568476b F src/shell.c 55adda3cf3c1cc2f6c1919aac17b2318f9c2a96f F src/sqlite.h.in 4f97b5907acfd2a5068cb0cec9d5178816734db7 -F src/sqliteInt.h 83d4ad5c75b50bad5c7c1573827231c148335ae6 +F src/sqliteInt.h 14b36d195ad418fc3d390e36a59ec0e3d0a1bdc7 F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9 F src/tclsqlite.c 0302e3f42f015d132d1291f3388c06e86c24a008 F src/test1.c df1d1ca2c40cafefb9a29860f072c4d0fee1a7b5 @@ -69,7 +69,7 @@ F src/test2.c b11fa244fff02190707dd0879987c37c75e61fc8 F src/test3.c de9edf178c02707cd37fd80b54e4c2ea77251cc0 F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df F src/test5.c b001fa7f1b9e2dc5c2331de62fc641b5ab2bd7a1 -F src/tokenize.c bf9de9689b3bb813d65784bf54472804bf9595e6 +F src/tokenize.c c48221284e729be067237a8cfd7848fb62ee4a92 F src/trigger.c f9a0a8d3a87238de1a934eeb7d0b6b1f13e6a55b F src/update.c 7b17b281d600bf3e220b3c5718e0883442dee722 F src/utf.c f4f83acd73389090e32d6589d307fc55d794c7ed @@ -84,8 +84,8 @@ F src/vdbemem.c ef9ac7d32acfe4bce5c5b408b1294c8d9e0cdb56 F src/where.c 6e637a6b3e61fe3104adc4e5caa4738bf6570daa F test/all.test 929bfa932b55e75c96fe2203f7650ba451c1862c F test/attach.test e305dd59a375e37c658c6d401f19f8a95880bf9a -F test/attach2.test 48a802ed9c009bcc36ad62646680a55c18403b3e -F test/attach3.test 742c932d7130e0e699a5d9f265cb831e0a824633 +F test/attach2.test 399128a7b3b209a339a8dbf53ca2ed42eb982d1a +F test/attach3.test 4a22dd620a346fe3d8189c05d8e2c55541402915 F test/auth.test 1cc252d9e7b3bdc1314199cbf3a0d3c5ed026c21 F test/autovacuum.test a5b11269daac313bea6694b04473fdd0e16e439a F test/bigfile.test d3744a8821ce9abb8697f2826a3e3d22b719e89f @@ -252,7 +252,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/whentouse.tcl fdacb0ba2d39831e8a6240d05a490026ad4c4e4c -P aed2e623ec9c4044696dc2d6f7f4c53216b45479 -R f11ae296f2dfdf96c95c6e6b63836396 +P 2d302931a69d1add1dae9f820133872b4fefe93e +R 9d8077c20528ce9bd12b7dfa2968a7b4 U drh -Z 443581b69da31601ae9d30cf00bb19d1 +Z 772277e47e3b8f9b2ce58ca939573a56 diff --git a/manifest.uuid b/manifest.uuid index 2fa8aae4e2..e7c46a0e81 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2d302931a69d1add1dae9f820133872b4fefe93e \ No newline at end of file +ac2d5a605c873cac68bfde4bbe3797608a47b21e \ No newline at end of file diff --git a/src/build.c b/src/build.c index 86b542b883..7bc36fe45a 100644 --- a/src/build.c +++ b/src/build.c @@ -24,9 +24,9 @@ ** PRAGMA ** <<<<<<< build.c -** $Id: build.c,v 1.263 2004/11/05 03:56:02 drh Exp $ +** $Id: build.c,v 1.264 2004/11/05 05:10:29 drh Exp $ ======= -** $Id: build.c,v 1.263 2004/11/05 03:56:02 drh Exp $ +** $Id: build.c,v 1.264 2004/11/05 05:10:29 drh Exp $ >>>>>>> 1.262 */ #include "sqliteInt.h" @@ -1635,52 +1635,20 @@ void sqlite3RootPageMoved(Db *pDb, int iFrom, int iTo){ ** if a root-page of another table is moved by the btree-layer whilst ** erasing iTable (this can happen with an auto-vacuum database). */ -static void destroyRootPage(Vdbe *v, int iTable, int iDb){ -#ifndef SQLITE_OMIT_AUTOVACUUM - int base; - /* If SQLITE_OMIT_AUTOVACUUM is not defined, then OP_Destroy pushes - ** an integer onto the stack. If this integer is non-zero, then it is - ** the root page number of a table moved to location iTable. The - ** following writes VDBE code to modify the sqlite_master table to - ** reflect this. It is assumed that cursor number 0 is a write-cursor - ** opened on the sqlite_master table. - */ - static /*const*/ VdbeOpList updateMaster[] = { - /* If the Op_Destroy pushed a 0 onto the stack, then skip the following - ** code. sqlite_master does not need updating in this case. - */ - { OP_Dup, 0, 0, 0}, - { OP_Integer, 0, 0, 0}, - { OP_Eq, 0, ADDR(17), 0}, - - /* Search for the sqlite_master row containing root-page iTable. */ - { OP_Rewind, 0, ADDR(8), 0}, - { OP_Dup, 0, 0, 0}, /* 4 */ - { OP_Column, 0, 3, 0}, /* 5 */ - { OP_Eq, 0, ADDR(9), 0}, - { OP_Next, 0, ADDR(4), 0}, - { OP_Halt, SQLITE_CORRUPT, OE_Fail, 0}, /* 8 */ - { OP_Recno, 0, 0, 0}, /* 9 */ - - /* Cursor 0 now points at the row that will be updated. The top of - ** the stack is the rowid of that row. The next value on the stack is - ** the new value for the root-page field. - */ - { OP_Column, 0, 0, 0}, /* 10 */ - { OP_Column, 0, 1, 0}, - { OP_Column, 0, 2, 0}, - { OP_Integer, 4, 0, 0}, /* 13 */ - { OP_Column, 0, 4, 0}, - { OP_MakeRecord, 5, 0, 0}, - { OP_PutIntKey, 0, 0, 0} /* 16 */ - }; -#endif - +static void destroyRootPage(Parse *pParse, int iTable, int iDb){ + Vdbe *v = sqlite3GetVdbe(pParse); sqlite3VdbeAddOp(v, OP_Destroy, iTable, iDb); - /* sqlite3VdbeAddOp(v, OP_Pop, 1, 0); */ #ifndef SQLITE_OMIT_AUTOVACUUM - base = sqlite3VdbeAddOpList(v, ArraySize(updateMaster), updateMaster); - sqlite3VdbeChangeP1(v, base+13, iTable); + /* OP_Destroy pushes an integer onto the stack. If this integer + ** is non-zero, then it is the root page number of a table moved to + ** location iTable. The following code modifis the sqlite_master table to + ** reflect this. + ** + ** The "#0" in the SQL is a special constant that means whatever value + ** is on the top of the stack. See sqlite3RegisterExpr(). + */ + sqlite3NestedParse(pParse, "UPDATE %Q.%Q SET rootpage=#0 WHERE rootpage=%d", + pParse->db->aDb[iDb].zName, SCHEMA_TABLE(iDb), iTable); #endif } @@ -1690,9 +1658,10 @@ static void destroyRootPage(Vdbe *v, int iTable, int iDb){ ** in case a root-page belonging to another table is moved by the btree layer ** is also added (this can happen with an auto-vacuum database). */ -static void destroyTable(Vdbe *v, Table *pTab){ +static void destroyTable(Parse *pParse, Table *pTab){ + Vdbe *v = pParse->pVdbe; #ifdef SQLITE_OMIT_AUTOVACUUM - destroyRootPage(v, pTab->tnum, pTab->iDb); + destroyRootPage(pParse, pTab->tnum, pTab->iDb); for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ destroyRootPage(v, pIdx->tnum, pIdx->iDb); } @@ -1731,7 +1700,7 @@ static void destroyTable(Vdbe *v, Table *pTab){ } } if( iLargest==0 ) return; - destroyRootPage(v, iLargest, pTab->iDb); + destroyRootPage(pParse, iLargest, pTab->iDb); iDestroyed = iLargest; } #endif @@ -1827,7 +1796,7 @@ void sqlite3DropTable(Parse *pParse, SrcList *pName, int isView){ "DELETE FROM %Q.%Q WHERE tbl_name=%Q and type!='trigger'", db->aDb[pTab->iDb].zName, SCHEMA_TABLE(pTab->iDb), pTab->zName); if( !isView ){ - destroyTable(v, pTab); + destroyTable(pParse, pTab); } sqlite3VdbeOp3(v, OP_DropTable, pTab->iDb, 0, pTab->zName, 0); } diff --git a/src/expr.c b/src/expr.c index daf7dc4929..8eec92c646 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.167 2004/10/31 02:22:49 drh Exp $ +** $Id: expr.c,v 1.168 2004/11/05 05:10:29 drh Exp $ */ #include "sqliteInt.h" #include @@ -198,6 +198,34 @@ Expr *sqlite3Expr(int op, Expr *pLeft, Expr *pRight, Token *pToken){ return pNew; } +/* +** When doing a nested parse, you can include terms in an expression +** that look like this: #0 #1 #2 ... These terms refer to elements +** on the stack. "#0" (or just "#") means the top of the stack. +** "#1" means the next down on the stack. And so forth. +** +** This routine is called by the parser to deal with on of those terms. +** It immediately generates code to store the value in a memory location. +** The returns an expression that will code to extract the value from +** that memory location as needed. +*/ +Expr *sqlite3RegisterExpr(Parse *pParse, Token *pToken){ + Vdbe *v = pParse->pVdbe; + Expr *p; + int depth; + if( v==0 ) return 0; + if( pParse->nested==0 ){ + sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken); + return 0; + } + p = sqlite3Expr(TK_REGISTER, 0, 0, pToken); + depth = atoi(&pToken->z[1]); + p->iTable = pParse->nMem++; + sqlite3VdbeAddOp(v, OP_Dup, depth, 0); + sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1); + return p; +} + /* ** Join two expressions using an AND operator. If either expression is ** NULL, then just return the other expression. @@ -1239,6 +1267,10 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){ } break; } + case TK_REGISTER: { + sqlite3VdbeAddOp(v, OP_MemLoad, pExpr->iTable, 0); + break; + } case TK_LT: case TK_LE: case TK_GT: diff --git a/src/parse.y b/src/parse.y index 90e4b1394f..f9990525dd 100644 --- a/src/parse.y +++ b/src/parse.y @@ -14,7 +14,7 @@ ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** -** @(#) $Id: parse.y,v 1.148 2004/11/05 00:43:12 drh Exp $ +** @(#) $Id: parse.y,v 1.149 2004/11/05 05:10:29 drh Exp $ */ %token_prefix TK_ %token_type {Token} @@ -588,6 +588,7 @@ expr(A) ::= INTEGER(X). {A = sqlite3Expr(@X, 0, 0, &X);} expr(A) ::= FLOAT(X). {A = sqlite3Expr(@X, 0, 0, &X);} expr(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);} expr(A) ::= BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);} +expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);} expr(A) ::= VARIABLE(X). { Token *pToken = &X; Expr *pExpr = A = sqlite3Expr(TK_VARIABLE, 0, 0, pToken); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index b65412e993..f7a51aa522 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.332 2004/11/05 03:56:02 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.333 2004/11/05 05:10:29 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -1254,6 +1254,7 @@ int sqlite3KeywordCode(const char*, int); int sqlite3RunParser(Parse*, const char*, char **); void sqlite3FinishCoding(Parse*); Expr *sqlite3Expr(int, Expr*, Expr*, Token*); +Expr *sqlite3RegisterExpr(Parse*,Token*); Expr *sqlite3ExprAnd(Expr*, Expr*); void sqlite3ExprSpan(Expr*,Token*,Token*); Expr *sqlite3ExprFunction(ExprList*, Token*); diff --git a/src/tokenize.c b/src/tokenize.c index ff2d3d2f51..46dcc76338 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -15,7 +15,7 @@ ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.94 2004/11/03 03:59:58 drh Exp $ +** $Id: tokenize.c,v 1.95 2004/11/05 05:10:29 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -177,6 +177,11 @@ static int sqliteGetToken(const unsigned char *z, int *tokenType){ *tokenType = TK_BITNOT; return 1; } + case '#': { + for(i=1; isdigit(z[i]); i++){} + *tokenType = TK_REGISTER; + return i; + } case '\'': case '"': { int delim = z[0]; for(i=1; (c=z[i])!=0; i++){ diff --git a/test/attach2.test b/test/attach2.test index 9f4b8f96f1..e62eca9195 100644 --- a/test/attach2.test +++ b/test/attach2.test @@ -12,7 +12,7 @@ # focus of this script is testing the ATTACH and DETACH commands # and related functionality. # -# $Id: attach2.test,v 1.28 2004/11/05 03:56:02 drh Exp $ +# $Id: attach2.test,v 1.29 2004/11/05 05:10:29 drh Exp $ # set testdir [file dirname $argv0] @@ -325,7 +325,6 @@ do_test attach2-5.2 { do_test attach2-5.3 { lsort [glob test.db*] } {test.db test.db2} -execsql {pragma vdbe_trace=on} do_test attach2-5.4 { execsql { BEGIN; diff --git a/test/attach3.test b/test/attach3.test index cc310164af..8075377dc5 100644 --- a/test/attach3.test +++ b/test/attach3.test @@ -12,7 +12,7 @@ # focus of this script is testing the ATTACH and DETACH commands # and schema changes to attached databases. # -# $Id: attach3.test,v 1.10 2004/11/04 04:42:28 drh Exp $ +# $Id: attach3.test,v 1.11 2004/11/05 05:10:29 drh Exp $ # @@ -27,6 +27,7 @@ execsql { # Create tables t1 and t2 in database file test2.db file delete -force test2.db +file delete -force test2.db-journal sqlite3 db2 test2.db execsql { CREATE TABLE t1(a, b); @@ -68,9 +69,6 @@ do_test attach3-2.1 { CREATE INDEX aux.i1 on t3(e); } } {} -execsql { - pragma vdbe_trace = off; -} do_test attach3-2.2 { execsql { SELECT * FROM sqlite_master WHERE name = 'i1';