Fossil SCM

Update the built-in SQLite to the latest 3.8.3 beta that includes support for the LEVEL pseudo-column on recursive queries. Make use of a recursive query capability and the LEVEL column to replace the compute_ancestors() function with a single query.

drh 2014-01-21 00:38 trunk
Commit f2ebd7e52d16891bdbf2eb423891ad007e744f61
+16 -31
--- src/descendants.c
+++ src/descendants.c
@@ -157,42 +157,27 @@
157157
/*
158158
** Load the record ID rid and up to N-1 closest ancestors into
159159
** the "ok" table.
160160
*/
161161
void compute_ancestors(int rid, int N, int directOnly){
162
- Bag seen;
163
- PQueue queue;
164
- Stmt ins;
165
- Stmt q;
166
- bag_init(&seen);
167
- pqueuex_init(&queue);
168
- bag_insert(&seen, rid);
169
- pqueuex_insert(&queue, rid, 0.0, 0);
170
- db_prepare(&ins, "INSERT OR IGNORE INTO ok VALUES(:rid)");
171
- db_prepare(&q,
172
- "SELECT a.pid, b.mtime FROM plink a LEFT JOIN plink b ON b.cid=a.pid"
173
- " WHERE a.cid=:rid %s",
174
- directOnly ? " AND a.isprim" : ""
162
+ db_multi_exec(
163
+ "WITH RECURSIVE "
164
+ " ancestor(rid, mtime) AS ("
165
+ " SELECT %d, mtime FROM event WHERE objid=%d "
166
+ " UNION "
167
+ " SELECT plink.pid, event.mtime"
168
+ " FROM ancestor, plink, event"
169
+ " WHERE plink.cid=ancestor.rid"
170
+ " AND event.objid=plink.pid %s"
171
+ " AND level<%d"
172
+ " )"
173
+ "INSERT INTO ok"
174
+ " SELECT rid FROM ancestor "
175
+ " ORDER BY mtime DESC"
176
+ " LIMIT %d;",
177
+ rid, rid, directOnly ? "AND plink.isPrim" : "", N, N
175178
);
176
- while( (N--)>0 && (rid = pqueuex_extract(&queue, 0))!=0 ){
177
- db_bind_int(&ins, ":rid", rid);
178
- db_step(&ins);
179
- db_reset(&ins);
180
- db_bind_int(&q, ":rid", rid);
181
- while( db_step(&q)==SQLITE_ROW ){
182
- int pid = db_column_int(&q, 0);
183
- double mtime = db_column_double(&q, 1);
184
- if( bag_insert(&seen, pid) ){
185
- pqueuex_insert(&queue, pid, -mtime, 0);
186
- }
187
- }
188
- db_reset(&q);
189
- }
190
- bag_clear(&seen);
191
- pqueuex_clear(&queue);
192
- db_finalize(&ins);
193
- db_finalize(&q);
194179
}
195180
196181
/*
197182
** Compute up to N direct ancestors (merge ancestors do not count)
198183
** for the check-in rid and put them in a table named "ancestor".
199184
--- src/descendants.c
+++ src/descendants.c
@@ -157,42 +157,27 @@
157 /*
158 ** Load the record ID rid and up to N-1 closest ancestors into
159 ** the "ok" table.
160 */
161 void compute_ancestors(int rid, int N, int directOnly){
162 Bag seen;
163 PQueue queue;
164 Stmt ins;
165 Stmt q;
166 bag_init(&seen);
167 pqueuex_init(&queue);
168 bag_insert(&seen, rid);
169 pqueuex_insert(&queue, rid, 0.0, 0);
170 db_prepare(&ins, "INSERT OR IGNORE INTO ok VALUES(:rid)");
171 db_prepare(&q,
172 "SELECT a.pid, b.mtime FROM plink a LEFT JOIN plink b ON b.cid=a.pid"
173 " WHERE a.cid=:rid %s",
174 directOnly ? " AND a.isprim" : ""
 
 
 
175 );
176 while( (N--)>0 && (rid = pqueuex_extract(&queue, 0))!=0 ){
177 db_bind_int(&ins, ":rid", rid);
178 db_step(&ins);
179 db_reset(&ins);
180 db_bind_int(&q, ":rid", rid);
181 while( db_step(&q)==SQLITE_ROW ){
182 int pid = db_column_int(&q, 0);
183 double mtime = db_column_double(&q, 1);
184 if( bag_insert(&seen, pid) ){
185 pqueuex_insert(&queue, pid, -mtime, 0);
186 }
187 }
188 db_reset(&q);
189 }
190 bag_clear(&seen);
191 pqueuex_clear(&queue);
192 db_finalize(&ins);
193 db_finalize(&q);
194 }
195
196 /*
197 ** Compute up to N direct ancestors (merge ancestors do not count)
198 ** for the check-in rid and put them in a table named "ancestor".
199
--- src/descendants.c
+++ src/descendants.c
@@ -157,42 +157,27 @@
157 /*
158 ** Load the record ID rid and up to N-1 closest ancestors into
159 ** the "ok" table.
160 */
161 void compute_ancestors(int rid, int N, int directOnly){
162 db_multi_exec(
163 "WITH RECURSIVE "
164 " ancestor(rid, mtime) AS ("
165 " SELECT %d, mtime FROM event WHERE objid=%d "
166 " UNION "
167 " SELECT plink.pid, event.mtime"
168 " FROM ancestor, plink, event"
169 " WHERE plink.cid=ancestor.rid"
170 " AND event.objid=plink.pid %s"
171 " AND level<%d"
172 " )"
173 "INSERT INTO ok"
174 " SELECT rid FROM ancestor "
175 " ORDER BY mtime DESC"
176 " LIMIT %d;",
177 rid, rid, directOnly ? "AND plink.isPrim" : "", N, N
178 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179 }
180
181 /*
182 ** Compute up to N direct ancestors (merge ancestors do not count)
183 ** for the check-in rid and put them in a table named "ancestor".
184
+2 -2
--- src/main.c
+++ src/main.c
@@ -568,12 +568,12 @@
568568
#endif
569569
{
570570
const char *zCmdName = "unknown";
571571
int idx;
572572
int rc;
573
- if( sqlite3_libversion_number()<3008002 ){
574
- fossil_fatal("Unsuitable SQLite version %s, must be at least 3.8.2",
573
+ if( sqlite3_libversion_number()<3008003 ){
574
+ fossil_fatal("Unsuitable SQLite version %s, must be at least 3.8.3",
575575
sqlite3_libversion());
576576
}
577577
sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
578578
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
579579
memset(&g, 0, sizeof(g));
580580
--- src/main.c
+++ src/main.c
@@ -568,12 +568,12 @@
568 #endif
569 {
570 const char *zCmdName = "unknown";
571 int idx;
572 int rc;
573 if( sqlite3_libversion_number()<3008002 ){
574 fossil_fatal("Unsuitable SQLite version %s, must be at least 3.8.2",
575 sqlite3_libversion());
576 }
577 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
578 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
579 memset(&g, 0, sizeof(g));
580
--- src/main.c
+++ src/main.c
@@ -568,12 +568,12 @@
568 #endif
569 {
570 const char *zCmdName = "unknown";
571 int idx;
572 int rc;
573 if( sqlite3_libversion_number()<3008003 ){
574 fossil_fatal("Unsuitable SQLite version %s, must be at least 3.8.3",
575 sqlite3_libversion());
576 }
577 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
578 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
579 memset(&g, 0, sizeof(g));
580
+78 -29
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138138
#define SQLITE_VERSION "3.8.3"
139139
#define SQLITE_VERSION_NUMBER 3008003
140
-#define SQLITE_SOURCE_ID "2014-01-18 15:22:53 2ad4583c0cc7988f0dfe78fd0a2eb0fdb92d835a"
140
+#define SQLITE_SOURCE_ID "2014-01-21 00:19:43 cc1cb3217800ff666a00bf4f544a5a477589bc1b"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -8200,10 +8200,11 @@
82008200
#define TK_AGG_FUNCTION 155
82018201
#define TK_AGG_COLUMN 156
82028202
#define TK_UMINUS 157
82038203
#define TK_UPLUS 158
82048204
#define TK_REGISTER 159
8205
+#define TK_LEVEL 160
82058206
82068207
/************** End of parse.h ***********************************************/
82078208
/************** Continuing where we left off in sqliteInt.h ******************/
82088209
#include <stdio.h>
82098210
#include <stdlib.h>
@@ -10759,11 +10760,10 @@
1075910760
#define TF_Ephemeral 0x02 /* An ephemeral table */
1076010761
#define TF_HasPrimaryKey 0x04 /* Table has a primary key */
1076110762
#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
1076210763
#define TF_Virtual 0x10 /* Is a virtual table */
1076310764
#define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
10764
-#define TF_Recursive 0x40 /* Recursive reference within CTE */
1076510765
1076610766
1076710767
/*
1076810768
** Test to see whether or not a table is a virtual table. This is
1076910769
** done as a macro so that it will be optimized out when virtual
@@ -11430,10 +11430,12 @@
1143011430
#define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
1143111431
#define NC_HasAgg 0x02 /* One or more aggregate functions seen */
1143211432
#define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
1143311433
#define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
1143411434
#define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
11435
+#define NC_Recursive 0x20 /* Resolvingn a recursive CTE definition */
11436
+#define NC_UsesLevel 0x40 /* The LEVEL pseudo-column has been seen */
1143511437
1143611438
/*
1143711439
** An instance of the following structure contains all information
1143811440
** needed to generate code for a single SELECT statement.
1143911441
**
@@ -11487,10 +11489,11 @@
1148711489
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
1148811490
#define SF_Materialize 0x0100 /* Force materialization of views */
1148911491
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1149011492
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1149111493
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11494
+#define SF_UsesLevel 0x1000 /* Uses the LEVEL pseudo-column */
1149211495
1149311496
1149411497
/*
1149511498
** The results of a select can be distributed in several ways. The
1149611499
** "SRT" prefix means "SELECT Result Type".
@@ -11693,10 +11696,11 @@
1169311696
Table **apVtabLock; /* Pointer to virtual tables needing locking */
1169411697
#endif
1169511698
Table *pZombieTab; /* List of Table objects to delete after code gen */
1169611699
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
1169711700
With *pWith; /* Current WITH clause, or NULL */
11701
+ int regLevel; /* Register holding the LEVEL variable */
1169811702
u8 bFreeWith; /* True if pWith should be freed with parser */
1169911703
};
1170011704
1170111705
/*
1170211706
** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -54364,11 +54368,11 @@
5436454368
static void assertCellInfo(BtCursor *pCur){
5436554369
CellInfo info;
5436654370
int iPage = pCur->iPage;
5436754371
memset(&info, 0, sizeof(info));
5436854372
btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
54369
- assert( memcmp(&info, &pCur->info, sizeof(info))==0 );
54373
+ assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
5437054374
}
5437154375
#else
5437254376
#define assertCellInfo(x)
5437354377
#endif
5437454378
#ifdef _MSC_VER
@@ -55000,30 +55004,28 @@
5500055004
if( rc!=SQLITE_OK ){
5500155005
pCur->eState = CURSOR_INVALID;
5500255006
return rc;
5500355007
}
5500455008
pCur->iPage = 0;
55005
-
55006
- /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
55007
- ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
55008
- ** NULL, the caller expects a table b-tree. If this is not the case,
55009
- ** return an SQLITE_CORRUPT error. */
55010
- assert( pCur->apPage[0]->intKey==1 || pCur->apPage[0]->intKey==0 );
55011
- if( (pCur->pKeyInfo==0)!=pCur->apPage[0]->intKey ){
55012
- return SQLITE_CORRUPT_BKPT;
55013
- }
55014
- }
55015
-
55016
- /* Assert that the root page is of the correct type. This must be the
55017
- ** case as the call to this function that loaded the root-page (either
55018
- ** this call or a previous invocation) would have detected corruption
55019
- ** if the assumption were not true, and it is not possible for the flags
55020
- ** byte to have been modified while this cursor is holding a reference
55021
- ** to the page. */
55009
+ }
5502255010
pRoot = pCur->apPage[0];
5502355011
assert( pRoot->pgno==pCur->pgnoRoot );
55024
- assert( pRoot->isInit && (pCur->pKeyInfo==0)==pRoot->intKey );
55012
+
55013
+ /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
55014
+ ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
55015
+ ** NULL, the caller expects a table b-tree. If this is not the case,
55016
+ ** return an SQLITE_CORRUPT error.
55017
+ **
55018
+ ** Earlier versions of SQLite assumed that this test could not fail
55019
+ ** if the root page was already loaded when this function was called (i.e.
55020
+ ** if pCur->iPage>=0). But this is not so if the database is corrupted
55021
+ ** in such a way that page pRoot is linked into a second b-tree table
55022
+ ** (or the freelist). */
55023
+ assert( pRoot->intKey==1 || pRoot->intKey==0 );
55024
+ if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
55025
+ return SQLITE_CORRUPT_BKPT;
55026
+ }
5502555027
5502655028
pCur->aiIdx[0] = 0;
5502755029
pCur->info.nSize = 0;
5502855030
pCur->atLast = 0;
5502955031
pCur->validNKey = 0;
@@ -55861,10 +55863,11 @@
5586155863
releasePage(pTrunk);
5586255864
releasePage(pPrevTrunk);
5586355865
if( rc==SQLITE_OK ){
5586455866
if( sqlite3PagerPageRefcount((*ppPage)->pDbPage)>1 ){
5586555867
releasePage(*ppPage);
55868
+ *ppPage = 0;
5586655869
return SQLITE_CORRUPT_BKPT;
5586755870
}
5586855871
(*ppPage)->isInit = 0;
5586955872
}else{
5587055873
*ppPage = 0;
@@ -75127,11 +75130,11 @@
7512775130
sqlite3 *db = pParse->db; /* The database connection */
7512875131
struct SrcList_item *pItem; /* Use for looping over pSrcList items */
7512975132
struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
7513075133
NameContext *pTopNC = pNC; /* First namecontext in the list */
7513175134
Schema *pSchema = 0; /* Schema of the expression */
75132
- int isTrigger = 0; /* True if resolved to a trigger column */
75135
+ u8 newOp = TK_COLUMN; /* pExpr->op after resolving name */
7513375136
Table *pTab = 0; /* Table hold the row */
7513475137
Column *pCol; /* A column of pTab */
7513575138
7513675139
assert( pNC ); /* the name context cannot be NULL. */
7513775140
assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -75167,10 +75170,26 @@
7516775170
7516875171
/* Start at the inner-most context and move outward until a match is found */
7516975172
while( pNC && cnt==0 ){
7517075173
ExprList *pEList;
7517175174
SrcList *pSrcList = pNC->pSrcList;
75175
+
75176
+#ifndef SQLITE_OMIT_CTE
75177
+ /* The identifier "LEVEL", with a table or database qualifier and within a
75178
+ ** recursive common table expression, resolves to the special LEVEL pseudo-column.
75179
+ ** To access table names called "level", add a table qualifier.
75180
+ */
75181
+ if( (pNC->ncFlags&NC_Recursive)!=0 && zTab==0 && sqlite3_stricmp(zCol,"level")==0 ){
75182
+ assert( cnt==0 );
75183
+ cnt = 1;
75184
+ newOp = TK_LEVEL;
75185
+ pExpr->iColumn = -1;
75186
+ pExpr->affinity = SQLITE_AFF_INTEGER;
75187
+ pNC->ncFlags |= NC_UsesLevel;
75188
+ break;
75189
+ }
75190
+#endif
7517275191
7517375192
if( pSrcList ){
7517475193
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
7517575194
pTab = pItem->pTab;
7517675195
assert( pTab!=0 && pTab->zName!=0 );
@@ -75272,11 +75291,11 @@
7527275291
testcase( iCol==32 );
7527375292
pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
7527475293
}
7527575294
pExpr->iColumn = (i16)iCol;
7527675295
pExpr->pTab = pTab;
75277
- isTrigger = 1;
75296
+ newOp = TK_TRIGGER;
7527875297
}
7527975298
}
7528075299
}
7528175300
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
7528275301
@@ -75396,15 +75415,15 @@
7539675415
*/
7539775416
sqlite3ExprDelete(db, pExpr->pLeft);
7539875417
pExpr->pLeft = 0;
7539975418
sqlite3ExprDelete(db, pExpr->pRight);
7540075419
pExpr->pRight = 0;
75401
- pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
75420
+ pExpr->op = newOp;
7540275421
lookupname_end:
7540375422
if( cnt==1 ){
7540475423
assert( pNC!=0 );
75405
- if( pExpr->op!=TK_AS ){
75424
+ if( pExpr->op!=TK_AS && pExpr->op!=TK_LEVEL ){
7540675425
sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
7540775426
}
7540875427
/* Increment the nRef value on all name contexts from TopNC up to
7540975428
** the point where the name matched. */
7541075429
for(;;){
@@ -76097,10 +76116,11 @@
7609776116
7609876117
/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
7609976118
** resolve the result-set expression list.
7610076119
*/
7610176120
sNC.ncFlags = NC_AllowAgg;
76121
+ if( p->selFlags & SF_Recursive ) sNC.ncFlags |= NC_Recursive;
7610276122
sNC.pSrcList = p->pSrc;
7610376123
sNC.pNext = pOuterNC;
7610476124
7610576125
/* Resolve names in the result set. */
7610676126
pEList = p->pEList;
@@ -76175,10 +76195,14 @@
7617576195
"the GROUP BY clause");
7617676196
return WRC_Abort;
7617776197
}
7617876198
}
7617976199
}
76200
+ if( sNC.ncFlags & NC_UsesLevel ){
76201
+ p->selFlags |= SF_UsesLevel;
76202
+ }
76203
+ sNC.ncFlags &= ~(NC_Recursive|NC_UsesLevel);
7618076204
7618176205
/* Advance to the next term of the compound
7618276206
*/
7618376207
p = p->pPrior;
7618476208
nCompound++;
@@ -78811,10 +78835,16 @@
7881178835
inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
7881278836
pExpr->iColumn, iTab, target,
7881378837
pExpr->op2);
7881478838
break;
7881578839
}
78840
+#ifndef SQLITE_OMIT_CTE
78841
+ case TK_LEVEL: {
78842
+ inReg = pParse->regLevel;
78843
+ break;
78844
+ }
78845
+#endif
7881678846
case TK_INTEGER: {
7881778847
codeInteger(pParse, pExpr, 0, target);
7881878848
break;
7881978849
}
7882078850
#ifndef SQLITE_OMIT_FLOATING_POINT
@@ -79434,10 +79464,11 @@
7943479464
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
7943579465
int r2;
7943679466
pExpr = sqlite3ExprSkipCollate(pExpr);
7943779467
if( ConstFactorOk(pParse)
7943879468
&& pExpr->op!=TK_REGISTER
79469
+ && pExpr->op!=TK_LEVEL
7943979470
&& sqlite3ExprIsConstantNotJoin(pExpr)
7944079471
){
7944179472
ExprList *p = pParse->pConstExpr;
7944279473
int i;
7944379474
*pReg = 0;
@@ -101208,21 +101239,23 @@
101208101239
goto multi_select_end;
101209101240
}
101210101241
101211101242
#ifndef SQLITE_OMIT_CTE
101212101243
if( p->selFlags & SF_Recursive ){
101213
- SrcList *pSrc = p->pSrc;
101214
- int nCol = p->pEList->nExpr;
101244
+ SrcList *pSrc = p->pSrc; /* The FROM clause of the right-most SELECT */
101245
+ int nCol = p->pEList->nExpr; /* Number of columns in the result set */
101215101246
int addrNext;
101216101247
int addrSwap;
101217101248
int iCont, iBreak;
101218101249
int tmp1; /* Intermediate table */
101219101250
int tmp2; /* Next intermediate table */
101220101251
int tmp3 = 0; /* To ensure unique results if UNION */
101221101252
int eDest = SRT_Table;
101222101253
SelectDest tmp2dest;
101223101254
int i;
101255
+ int regLevel = 0; /* Register for LEVEL value */
101256
+ int savedRegLevel; /* Saved value of pParse->regLevel */
101224101257
101225101258
/* Check that there is no ORDER BY or LIMIT clause. Neither of these
101226101259
** are supported on recursive queries. */
101227101260
assert( p->pOffset==0 || p->pLimit );
101228101261
if( p->pOrderBy || p->pLimit ){
@@ -101260,10 +101293,18 @@
101260101293
}
101261101294
101262101295
/* Store the results of the initial SELECT in tmp2. */
101263101296
rc = sqlite3Select(pParse, pPrior, &tmp2dest);
101264101297
if( rc ) goto multi_select_end;
101298
+
101299
+ /* Allocate and initialize a register to hold the LEVEL pseudo-column */
101300
+ savedRegLevel = pParse->regLevel;
101301
+ if( p->selFlags & SF_UsesLevel ){
101302
+ regLevel = pParse->regLevel = ++pParse->nMem;
101303
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, regLevel);
101304
+ VdbeComment((v, "level=0"));
101305
+ }
101265101306
101266101307
/* Clear tmp1. Then switch the contents of tmp1 and tmp2. Then return
101267101308
** the contents of tmp1 to the caller. Or, if tmp1 is empty at this
101268101309
** point, the recursive query has finished - jump to address iBreak. */
101269101310
addrSwap = sqlite3VdbeAddOp2(v, OP_SwapCursors, tmp1, tmp2);
@@ -101271,10 +101312,14 @@
101271101312
addrNext = sqlite3VdbeCurrentAddr(v);
101272101313
selectInnerLoop(pParse, p, p->pEList, tmp1, p->pEList->nExpr,
101273101314
0, 0, &dest, iCont, iBreak);
101274101315
sqlite3VdbeResolveLabel(v, iCont);
101275101316
sqlite3VdbeAddOp2(v, OP_Next, tmp1, addrNext);
101317
+ if( regLevel ){
101318
+ sqlite3VdbeAddOp2(v, OP_AddImm, regLevel, 1);
101319
+ VdbeComment((v, "level++"));
101320
+ }
101276101321
101277101322
/* Execute the recursive SELECT. Store the results in tmp2. While this
101278101323
** SELECT is running, the contents of tmp1 are read by recursive
101279101324
** references to the current CTE. */
101280101325
p->pPrior = 0;
@@ -101283,10 +101328,11 @@
101283101328
p->pPrior = pPrior;
101284101329
if( rc ) goto multi_select_end;
101285101330
101286101331
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrSwap);
101287101332
sqlite3VdbeResolveLabel(v, iBreak);
101333
+ pParse->regLevel = savedRegLevel;
101288101334
}else
101289101335
#endif
101290101336
101291101337
/* Compound SELECTs that have an ORDER BY clause are handled separately.
101292101338
*/
@@ -103011,10 +103057,11 @@
103011103057
if( pCte->zErr ){
103012103058
sqlite3ErrorMsg(pParse, pCte->zErr, pCte->zName);
103013103059
return SQLITE_ERROR;
103014103060
}
103015103061
103062
+ assert( pFrom->pTab==0 );
103016103063
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
103017103064
if( pTab==0 ) return WRC_Abort;
103018103065
pTab->nRef = 1;
103019103066
pTab->zName = sqlite3DbStrDup(db, pCte->zName);
103020103067
pTab->iPKey = -1;
@@ -110432,11 +110479,12 @@
110432110479
for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
110433110480
if( pTerm->leftCursor != pSrc->iCursor ) continue;
110434110481
assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
110435110482
testcase( pTerm->eOperator & WO_IN );
110436110483
testcase( pTerm->eOperator & WO_ISNULL );
110437
- if( pTerm->eOperator & (WO_ISNULL) ) continue;
110484
+ testcase( pTerm->eOperator & WO_ALL );
110485
+ if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV))==0 ) continue;
110438110486
if( pTerm->wtFlags & TERM_VNULL ) continue;
110439110487
nTerm++;
110440110488
}
110441110489
110442110490
/* If the ORDER BY clause contains only columns in the current
@@ -110484,11 +110532,12 @@
110484110532
u8 op;
110485110533
if( pTerm->leftCursor != pSrc->iCursor ) continue;
110486110534
assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
110487110535
testcase( pTerm->eOperator & WO_IN );
110488110536
testcase( pTerm->eOperator & WO_ISNULL );
110489
- if( pTerm->eOperator & (WO_ISNULL) ) continue;
110537
+ testcase( pTerm->eOperator & WO_ALL );
110538
+ if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV))==0 ) continue;
110490110539
if( pTerm->wtFlags & TERM_VNULL ) continue;
110491110540
pIdxCons[j].iColumn = pTerm->u.leftColumn;
110492110541
pIdxCons[j].iTermOffset = i;
110493110542
op = (u8)pTerm->eOperator & WO_ALL;
110494110543
if( op==WO_IN ) op = WO_EQ;
110495110544
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2014-01-18 15:22:53 2ad4583c0cc7988f0dfe78fd0a2eb0fdb92d835a"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -8200,10 +8200,11 @@
8200 #define TK_AGG_FUNCTION 155
8201 #define TK_AGG_COLUMN 156
8202 #define TK_UMINUS 157
8203 #define TK_UPLUS 158
8204 #define TK_REGISTER 159
 
8205
8206 /************** End of parse.h ***********************************************/
8207 /************** Continuing where we left off in sqliteInt.h ******************/
8208 #include <stdio.h>
8209 #include <stdlib.h>
@@ -10759,11 +10760,10 @@
10759 #define TF_Ephemeral 0x02 /* An ephemeral table */
10760 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
10761 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
10762 #define TF_Virtual 0x10 /* Is a virtual table */
10763 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
10764 #define TF_Recursive 0x40 /* Recursive reference within CTE */
10765
10766
10767 /*
10768 ** Test to see whether or not a table is a virtual table. This is
10769 ** done as a macro so that it will be optimized out when virtual
@@ -11430,10 +11430,12 @@
11430 #define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
11431 #define NC_HasAgg 0x02 /* One or more aggregate functions seen */
11432 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11433 #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11434 #define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
 
 
11435
11436 /*
11437 ** An instance of the following structure contains all information
11438 ** needed to generate code for a single SELECT statement.
11439 **
@@ -11487,10 +11489,11 @@
11487 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11488 #define SF_Materialize 0x0100 /* Force materialization of views */
11489 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11490 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11491 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
 
11492
11493
11494 /*
11495 ** The results of a select can be distributed in several ways. The
11496 ** "SRT" prefix means "SELECT Result Type".
@@ -11693,10 +11696,11 @@
11693 Table **apVtabLock; /* Pointer to virtual tables needing locking */
11694 #endif
11695 Table *pZombieTab; /* List of Table objects to delete after code gen */
11696 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
11697 With *pWith; /* Current WITH clause, or NULL */
 
11698 u8 bFreeWith; /* True if pWith should be freed with parser */
11699 };
11700
11701 /*
11702 ** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -54364,11 +54368,11 @@
54364 static void assertCellInfo(BtCursor *pCur){
54365 CellInfo info;
54366 int iPage = pCur->iPage;
54367 memset(&info, 0, sizeof(info));
54368 btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
54369 assert( memcmp(&info, &pCur->info, sizeof(info))==0 );
54370 }
54371 #else
54372 #define assertCellInfo(x)
54373 #endif
54374 #ifdef _MSC_VER
@@ -55000,30 +55004,28 @@
55000 if( rc!=SQLITE_OK ){
55001 pCur->eState = CURSOR_INVALID;
55002 return rc;
55003 }
55004 pCur->iPage = 0;
55005
55006 /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
55007 ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
55008 ** NULL, the caller expects a table b-tree. If this is not the case,
55009 ** return an SQLITE_CORRUPT error. */
55010 assert( pCur->apPage[0]->intKey==1 || pCur->apPage[0]->intKey==0 );
55011 if( (pCur->pKeyInfo==0)!=pCur->apPage[0]->intKey ){
55012 return SQLITE_CORRUPT_BKPT;
55013 }
55014 }
55015
55016 /* Assert that the root page is of the correct type. This must be the
55017 ** case as the call to this function that loaded the root-page (either
55018 ** this call or a previous invocation) would have detected corruption
55019 ** if the assumption were not true, and it is not possible for the flags
55020 ** byte to have been modified while this cursor is holding a reference
55021 ** to the page. */
55022 pRoot = pCur->apPage[0];
55023 assert( pRoot->pgno==pCur->pgnoRoot );
55024 assert( pRoot->isInit && (pCur->pKeyInfo==0)==pRoot->intKey );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55025
55026 pCur->aiIdx[0] = 0;
55027 pCur->info.nSize = 0;
55028 pCur->atLast = 0;
55029 pCur->validNKey = 0;
@@ -55861,10 +55863,11 @@
55861 releasePage(pTrunk);
55862 releasePage(pPrevTrunk);
55863 if( rc==SQLITE_OK ){
55864 if( sqlite3PagerPageRefcount((*ppPage)->pDbPage)>1 ){
55865 releasePage(*ppPage);
 
55866 return SQLITE_CORRUPT_BKPT;
55867 }
55868 (*ppPage)->isInit = 0;
55869 }else{
55870 *ppPage = 0;
@@ -75127,11 +75130,11 @@
75127 sqlite3 *db = pParse->db; /* The database connection */
75128 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
75129 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
75130 NameContext *pTopNC = pNC; /* First namecontext in the list */
75131 Schema *pSchema = 0; /* Schema of the expression */
75132 int isTrigger = 0; /* True if resolved to a trigger column */
75133 Table *pTab = 0; /* Table hold the row */
75134 Column *pCol; /* A column of pTab */
75135
75136 assert( pNC ); /* the name context cannot be NULL. */
75137 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -75167,10 +75170,26 @@
75167
75168 /* Start at the inner-most context and move outward until a match is found */
75169 while( pNC && cnt==0 ){
75170 ExprList *pEList;
75171 SrcList *pSrcList = pNC->pSrcList;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75172
75173 if( pSrcList ){
75174 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
75175 pTab = pItem->pTab;
75176 assert( pTab!=0 && pTab->zName!=0 );
@@ -75272,11 +75291,11 @@
75272 testcase( iCol==32 );
75273 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
75274 }
75275 pExpr->iColumn = (i16)iCol;
75276 pExpr->pTab = pTab;
75277 isTrigger = 1;
75278 }
75279 }
75280 }
75281 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75282
@@ -75396,15 +75415,15 @@
75396 */
75397 sqlite3ExprDelete(db, pExpr->pLeft);
75398 pExpr->pLeft = 0;
75399 sqlite3ExprDelete(db, pExpr->pRight);
75400 pExpr->pRight = 0;
75401 pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
75402 lookupname_end:
75403 if( cnt==1 ){
75404 assert( pNC!=0 );
75405 if( pExpr->op!=TK_AS ){
75406 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
75407 }
75408 /* Increment the nRef value on all name contexts from TopNC up to
75409 ** the point where the name matched. */
75410 for(;;){
@@ -76097,10 +76116,11 @@
76097
76098 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
76099 ** resolve the result-set expression list.
76100 */
76101 sNC.ncFlags = NC_AllowAgg;
 
76102 sNC.pSrcList = p->pSrc;
76103 sNC.pNext = pOuterNC;
76104
76105 /* Resolve names in the result set. */
76106 pEList = p->pEList;
@@ -76175,10 +76195,14 @@
76175 "the GROUP BY clause");
76176 return WRC_Abort;
76177 }
76178 }
76179 }
 
 
 
 
76180
76181 /* Advance to the next term of the compound
76182 */
76183 p = p->pPrior;
76184 nCompound++;
@@ -78811,10 +78835,16 @@
78811 inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
78812 pExpr->iColumn, iTab, target,
78813 pExpr->op2);
78814 break;
78815 }
 
 
 
 
 
 
78816 case TK_INTEGER: {
78817 codeInteger(pParse, pExpr, 0, target);
78818 break;
78819 }
78820 #ifndef SQLITE_OMIT_FLOATING_POINT
@@ -79434,10 +79464,11 @@
79434 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79435 int r2;
79436 pExpr = sqlite3ExprSkipCollate(pExpr);
79437 if( ConstFactorOk(pParse)
79438 && pExpr->op!=TK_REGISTER
 
79439 && sqlite3ExprIsConstantNotJoin(pExpr)
79440 ){
79441 ExprList *p = pParse->pConstExpr;
79442 int i;
79443 *pReg = 0;
@@ -101208,21 +101239,23 @@
101208 goto multi_select_end;
101209 }
101210
101211 #ifndef SQLITE_OMIT_CTE
101212 if( p->selFlags & SF_Recursive ){
101213 SrcList *pSrc = p->pSrc;
101214 int nCol = p->pEList->nExpr;
101215 int addrNext;
101216 int addrSwap;
101217 int iCont, iBreak;
101218 int tmp1; /* Intermediate table */
101219 int tmp2; /* Next intermediate table */
101220 int tmp3 = 0; /* To ensure unique results if UNION */
101221 int eDest = SRT_Table;
101222 SelectDest tmp2dest;
101223 int i;
 
 
101224
101225 /* Check that there is no ORDER BY or LIMIT clause. Neither of these
101226 ** are supported on recursive queries. */
101227 assert( p->pOffset==0 || p->pLimit );
101228 if( p->pOrderBy || p->pLimit ){
@@ -101260,10 +101293,18 @@
101260 }
101261
101262 /* Store the results of the initial SELECT in tmp2. */
101263 rc = sqlite3Select(pParse, pPrior, &tmp2dest);
101264 if( rc ) goto multi_select_end;
 
 
 
 
 
 
 
 
101265
101266 /* Clear tmp1. Then switch the contents of tmp1 and tmp2. Then return
101267 ** the contents of tmp1 to the caller. Or, if tmp1 is empty at this
101268 ** point, the recursive query has finished - jump to address iBreak. */
101269 addrSwap = sqlite3VdbeAddOp2(v, OP_SwapCursors, tmp1, tmp2);
@@ -101271,10 +101312,14 @@
101271 addrNext = sqlite3VdbeCurrentAddr(v);
101272 selectInnerLoop(pParse, p, p->pEList, tmp1, p->pEList->nExpr,
101273 0, 0, &dest, iCont, iBreak);
101274 sqlite3VdbeResolveLabel(v, iCont);
101275 sqlite3VdbeAddOp2(v, OP_Next, tmp1, addrNext);
 
 
 
 
101276
101277 /* Execute the recursive SELECT. Store the results in tmp2. While this
101278 ** SELECT is running, the contents of tmp1 are read by recursive
101279 ** references to the current CTE. */
101280 p->pPrior = 0;
@@ -101283,10 +101328,11 @@
101283 p->pPrior = pPrior;
101284 if( rc ) goto multi_select_end;
101285
101286 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrSwap);
101287 sqlite3VdbeResolveLabel(v, iBreak);
 
101288 }else
101289 #endif
101290
101291 /* Compound SELECTs that have an ORDER BY clause are handled separately.
101292 */
@@ -103011,10 +103057,11 @@
103011 if( pCte->zErr ){
103012 sqlite3ErrorMsg(pParse, pCte->zErr, pCte->zName);
103013 return SQLITE_ERROR;
103014 }
103015
 
103016 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
103017 if( pTab==0 ) return WRC_Abort;
103018 pTab->nRef = 1;
103019 pTab->zName = sqlite3DbStrDup(db, pCte->zName);
103020 pTab->iPKey = -1;
@@ -110432,11 +110479,12 @@
110432 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
110433 if( pTerm->leftCursor != pSrc->iCursor ) continue;
110434 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
110435 testcase( pTerm->eOperator & WO_IN );
110436 testcase( pTerm->eOperator & WO_ISNULL );
110437 if( pTerm->eOperator & (WO_ISNULL) ) continue;
 
110438 if( pTerm->wtFlags & TERM_VNULL ) continue;
110439 nTerm++;
110440 }
110441
110442 /* If the ORDER BY clause contains only columns in the current
@@ -110484,11 +110532,12 @@
110484 u8 op;
110485 if( pTerm->leftCursor != pSrc->iCursor ) continue;
110486 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
110487 testcase( pTerm->eOperator & WO_IN );
110488 testcase( pTerm->eOperator & WO_ISNULL );
110489 if( pTerm->eOperator & (WO_ISNULL) ) continue;
 
110490 if( pTerm->wtFlags & TERM_VNULL ) continue;
110491 pIdxCons[j].iColumn = pTerm->u.leftColumn;
110492 pIdxCons[j].iTermOffset = i;
110493 op = (u8)pTerm->eOperator & WO_ALL;
110494 if( op==WO_IN ) op = WO_EQ;
110495
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2014-01-21 00:19:43 cc1cb3217800ff666a00bf4f544a5a477589bc1b"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -8200,10 +8200,11 @@
8200 #define TK_AGG_FUNCTION 155
8201 #define TK_AGG_COLUMN 156
8202 #define TK_UMINUS 157
8203 #define TK_UPLUS 158
8204 #define TK_REGISTER 159
8205 #define TK_LEVEL 160
8206
8207 /************** End of parse.h ***********************************************/
8208 /************** Continuing where we left off in sqliteInt.h ******************/
8209 #include <stdio.h>
8210 #include <stdlib.h>
@@ -10759,11 +10760,10 @@
10760 #define TF_Ephemeral 0x02 /* An ephemeral table */
10761 #define TF_HasPrimaryKey 0x04 /* Table has a primary key */
10762 #define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */
10763 #define TF_Virtual 0x10 /* Is a virtual table */
10764 #define TF_WithoutRowid 0x20 /* No rowid used. PRIMARY KEY is the key */
 
10765
10766
10767 /*
10768 ** Test to see whether or not a table is a virtual table. This is
10769 ** done as a macro so that it will be optimized out when virtual
@@ -11430,10 +11430,12 @@
11430 #define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
11431 #define NC_HasAgg 0x02 /* One or more aggregate functions seen */
11432 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11433 #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11434 #define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
11435 #define NC_Recursive 0x20 /* Resolvingn a recursive CTE definition */
11436 #define NC_UsesLevel 0x40 /* The LEVEL pseudo-column has been seen */
11437
11438 /*
11439 ** An instance of the following structure contains all information
11440 ** needed to generate code for a single SELECT statement.
11441 **
@@ -11487,10 +11489,11 @@
11489 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11490 #define SF_Materialize 0x0100 /* Force materialization of views */
11491 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11492 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11493 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11494 #define SF_UsesLevel 0x1000 /* Uses the LEVEL pseudo-column */
11495
11496
11497 /*
11498 ** The results of a select can be distributed in several ways. The
11499 ** "SRT" prefix means "SELECT Result Type".
@@ -11693,10 +11696,11 @@
11696 Table **apVtabLock; /* Pointer to virtual tables needing locking */
11697 #endif
11698 Table *pZombieTab; /* List of Table objects to delete after code gen */
11699 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
11700 With *pWith; /* Current WITH clause, or NULL */
11701 int regLevel; /* Register holding the LEVEL variable */
11702 u8 bFreeWith; /* True if pWith should be freed with parser */
11703 };
11704
11705 /*
11706 ** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -54364,11 +54368,11 @@
54368 static void assertCellInfo(BtCursor *pCur){
54369 CellInfo info;
54370 int iPage = pCur->iPage;
54371 memset(&info, 0, sizeof(info));
54372 btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
54373 assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
54374 }
54375 #else
54376 #define assertCellInfo(x)
54377 #endif
54378 #ifdef _MSC_VER
@@ -55000,30 +55004,28 @@
55004 if( rc!=SQLITE_OK ){
55005 pCur->eState = CURSOR_INVALID;
55006 return rc;
55007 }
55008 pCur->iPage = 0;
55009 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55010 pRoot = pCur->apPage[0];
55011 assert( pRoot->pgno==pCur->pgnoRoot );
55012
55013 /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
55014 ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
55015 ** NULL, the caller expects a table b-tree. If this is not the case,
55016 ** return an SQLITE_CORRUPT error.
55017 **
55018 ** Earlier versions of SQLite assumed that this test could not fail
55019 ** if the root page was already loaded when this function was called (i.e.
55020 ** if pCur->iPage>=0). But this is not so if the database is corrupted
55021 ** in such a way that page pRoot is linked into a second b-tree table
55022 ** (or the freelist). */
55023 assert( pRoot->intKey==1 || pRoot->intKey==0 );
55024 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
55025 return SQLITE_CORRUPT_BKPT;
55026 }
55027
55028 pCur->aiIdx[0] = 0;
55029 pCur->info.nSize = 0;
55030 pCur->atLast = 0;
55031 pCur->validNKey = 0;
@@ -55861,10 +55863,11 @@
55863 releasePage(pTrunk);
55864 releasePage(pPrevTrunk);
55865 if( rc==SQLITE_OK ){
55866 if( sqlite3PagerPageRefcount((*ppPage)->pDbPage)>1 ){
55867 releasePage(*ppPage);
55868 *ppPage = 0;
55869 return SQLITE_CORRUPT_BKPT;
55870 }
55871 (*ppPage)->isInit = 0;
55872 }else{
55873 *ppPage = 0;
@@ -75127,11 +75130,11 @@
75130 sqlite3 *db = pParse->db; /* The database connection */
75131 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
75132 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
75133 NameContext *pTopNC = pNC; /* First namecontext in the list */
75134 Schema *pSchema = 0; /* Schema of the expression */
75135 u8 newOp = TK_COLUMN; /* pExpr->op after resolving name */
75136 Table *pTab = 0; /* Table hold the row */
75137 Column *pCol; /* A column of pTab */
75138
75139 assert( pNC ); /* the name context cannot be NULL. */
75140 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -75167,10 +75170,26 @@
75170
75171 /* Start at the inner-most context and move outward until a match is found */
75172 while( pNC && cnt==0 ){
75173 ExprList *pEList;
75174 SrcList *pSrcList = pNC->pSrcList;
75175
75176 #ifndef SQLITE_OMIT_CTE
75177 /* The identifier "LEVEL", with a table or database qualifier and within a
75178 ** recursive common table expression, resolves to the special LEVEL pseudo-column.
75179 ** To access table names called "level", add a table qualifier.
75180 */
75181 if( (pNC->ncFlags&NC_Recursive)!=0 && zTab==0 && sqlite3_stricmp(zCol,"level")==0 ){
75182 assert( cnt==0 );
75183 cnt = 1;
75184 newOp = TK_LEVEL;
75185 pExpr->iColumn = -1;
75186 pExpr->affinity = SQLITE_AFF_INTEGER;
75187 pNC->ncFlags |= NC_UsesLevel;
75188 break;
75189 }
75190 #endif
75191
75192 if( pSrcList ){
75193 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
75194 pTab = pItem->pTab;
75195 assert( pTab!=0 && pTab->zName!=0 );
@@ -75272,11 +75291,11 @@
75291 testcase( iCol==32 );
75292 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
75293 }
75294 pExpr->iColumn = (i16)iCol;
75295 pExpr->pTab = pTab;
75296 newOp = TK_TRIGGER;
75297 }
75298 }
75299 }
75300 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75301
@@ -75396,15 +75415,15 @@
75415 */
75416 sqlite3ExprDelete(db, pExpr->pLeft);
75417 pExpr->pLeft = 0;
75418 sqlite3ExprDelete(db, pExpr->pRight);
75419 pExpr->pRight = 0;
75420 pExpr->op = newOp;
75421 lookupname_end:
75422 if( cnt==1 ){
75423 assert( pNC!=0 );
75424 if( pExpr->op!=TK_AS && pExpr->op!=TK_LEVEL ){
75425 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
75426 }
75427 /* Increment the nRef value on all name contexts from TopNC up to
75428 ** the point where the name matched. */
75429 for(;;){
@@ -76097,10 +76116,11 @@
76116
76117 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
76118 ** resolve the result-set expression list.
76119 */
76120 sNC.ncFlags = NC_AllowAgg;
76121 if( p->selFlags & SF_Recursive ) sNC.ncFlags |= NC_Recursive;
76122 sNC.pSrcList = p->pSrc;
76123 sNC.pNext = pOuterNC;
76124
76125 /* Resolve names in the result set. */
76126 pEList = p->pEList;
@@ -76175,10 +76195,14 @@
76195 "the GROUP BY clause");
76196 return WRC_Abort;
76197 }
76198 }
76199 }
76200 if( sNC.ncFlags & NC_UsesLevel ){
76201 p->selFlags |= SF_UsesLevel;
76202 }
76203 sNC.ncFlags &= ~(NC_Recursive|NC_UsesLevel);
76204
76205 /* Advance to the next term of the compound
76206 */
76207 p = p->pPrior;
76208 nCompound++;
@@ -78811,10 +78835,16 @@
78835 inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
78836 pExpr->iColumn, iTab, target,
78837 pExpr->op2);
78838 break;
78839 }
78840 #ifndef SQLITE_OMIT_CTE
78841 case TK_LEVEL: {
78842 inReg = pParse->regLevel;
78843 break;
78844 }
78845 #endif
78846 case TK_INTEGER: {
78847 codeInteger(pParse, pExpr, 0, target);
78848 break;
78849 }
78850 #ifndef SQLITE_OMIT_FLOATING_POINT
@@ -79434,10 +79464,11 @@
79464 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79465 int r2;
79466 pExpr = sqlite3ExprSkipCollate(pExpr);
79467 if( ConstFactorOk(pParse)
79468 && pExpr->op!=TK_REGISTER
79469 && pExpr->op!=TK_LEVEL
79470 && sqlite3ExprIsConstantNotJoin(pExpr)
79471 ){
79472 ExprList *p = pParse->pConstExpr;
79473 int i;
79474 *pReg = 0;
@@ -101208,21 +101239,23 @@
101239 goto multi_select_end;
101240 }
101241
101242 #ifndef SQLITE_OMIT_CTE
101243 if( p->selFlags & SF_Recursive ){
101244 SrcList *pSrc = p->pSrc; /* The FROM clause of the right-most SELECT */
101245 int nCol = p->pEList->nExpr; /* Number of columns in the result set */
101246 int addrNext;
101247 int addrSwap;
101248 int iCont, iBreak;
101249 int tmp1; /* Intermediate table */
101250 int tmp2; /* Next intermediate table */
101251 int tmp3 = 0; /* To ensure unique results if UNION */
101252 int eDest = SRT_Table;
101253 SelectDest tmp2dest;
101254 int i;
101255 int regLevel = 0; /* Register for LEVEL value */
101256 int savedRegLevel; /* Saved value of pParse->regLevel */
101257
101258 /* Check that there is no ORDER BY or LIMIT clause. Neither of these
101259 ** are supported on recursive queries. */
101260 assert( p->pOffset==0 || p->pLimit );
101261 if( p->pOrderBy || p->pLimit ){
@@ -101260,10 +101293,18 @@
101293 }
101294
101295 /* Store the results of the initial SELECT in tmp2. */
101296 rc = sqlite3Select(pParse, pPrior, &tmp2dest);
101297 if( rc ) goto multi_select_end;
101298
101299 /* Allocate and initialize a register to hold the LEVEL pseudo-column */
101300 savedRegLevel = pParse->regLevel;
101301 if( p->selFlags & SF_UsesLevel ){
101302 regLevel = pParse->regLevel = ++pParse->nMem;
101303 sqlite3VdbeAddOp2(v, OP_Integer, 0, regLevel);
101304 VdbeComment((v, "level=0"));
101305 }
101306
101307 /* Clear tmp1. Then switch the contents of tmp1 and tmp2. Then return
101308 ** the contents of tmp1 to the caller. Or, if tmp1 is empty at this
101309 ** point, the recursive query has finished - jump to address iBreak. */
101310 addrSwap = sqlite3VdbeAddOp2(v, OP_SwapCursors, tmp1, tmp2);
@@ -101271,10 +101312,14 @@
101312 addrNext = sqlite3VdbeCurrentAddr(v);
101313 selectInnerLoop(pParse, p, p->pEList, tmp1, p->pEList->nExpr,
101314 0, 0, &dest, iCont, iBreak);
101315 sqlite3VdbeResolveLabel(v, iCont);
101316 sqlite3VdbeAddOp2(v, OP_Next, tmp1, addrNext);
101317 if( regLevel ){
101318 sqlite3VdbeAddOp2(v, OP_AddImm, regLevel, 1);
101319 VdbeComment((v, "level++"));
101320 }
101321
101322 /* Execute the recursive SELECT. Store the results in tmp2. While this
101323 ** SELECT is running, the contents of tmp1 are read by recursive
101324 ** references to the current CTE. */
101325 p->pPrior = 0;
@@ -101283,10 +101328,11 @@
101328 p->pPrior = pPrior;
101329 if( rc ) goto multi_select_end;
101330
101331 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrSwap);
101332 sqlite3VdbeResolveLabel(v, iBreak);
101333 pParse->regLevel = savedRegLevel;
101334 }else
101335 #endif
101336
101337 /* Compound SELECTs that have an ORDER BY clause are handled separately.
101338 */
@@ -103011,10 +103057,11 @@
103057 if( pCte->zErr ){
103058 sqlite3ErrorMsg(pParse, pCte->zErr, pCte->zName);
103059 return SQLITE_ERROR;
103060 }
103061
103062 assert( pFrom->pTab==0 );
103063 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
103064 if( pTab==0 ) return WRC_Abort;
103065 pTab->nRef = 1;
103066 pTab->zName = sqlite3DbStrDup(db, pCte->zName);
103067 pTab->iPKey = -1;
@@ -110432,11 +110479,12 @@
110479 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
110480 if( pTerm->leftCursor != pSrc->iCursor ) continue;
110481 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
110482 testcase( pTerm->eOperator & WO_IN );
110483 testcase( pTerm->eOperator & WO_ISNULL );
110484 testcase( pTerm->eOperator & WO_ALL );
110485 if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV))==0 ) continue;
110486 if( pTerm->wtFlags & TERM_VNULL ) continue;
110487 nTerm++;
110488 }
110489
110490 /* If the ORDER BY clause contains only columns in the current
@@ -110484,11 +110532,12 @@
110532 u8 op;
110533 if( pTerm->leftCursor != pSrc->iCursor ) continue;
110534 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
110535 testcase( pTerm->eOperator & WO_IN );
110536 testcase( pTerm->eOperator & WO_ISNULL );
110537 testcase( pTerm->eOperator & WO_ALL );
110538 if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV))==0 ) continue;
110539 if( pTerm->wtFlags & TERM_VNULL ) continue;
110540 pIdxCons[j].iColumn = pTerm->u.leftColumn;
110541 pIdxCons[j].iTermOffset = i;
110542 op = (u8)pTerm->eOperator & WO_ALL;
110543 if( op==WO_IN ) op = WO_EQ;
110544
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.3"
111111
#define SQLITE_VERSION_NUMBER 3008003
112
-#define SQLITE_SOURCE_ID "2014-01-18 15:22:53 2ad4583c0cc7988f0dfe78fd0a2eb0fdb92d835a"
112
+#define SQLITE_SOURCE_ID "2014-01-21 00:19:43 cc1cb3217800ff666a00bf4f544a5a477589bc1b"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2014-01-18 15:22:53 2ad4583c0cc7988f0dfe78fd0a2eb0fdb92d835a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2014-01-21 00:19:43 cc1cb3217800ff666a00bf4f544a5a477589bc1b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button