Fossil SCM

Update the built-in SQLite to the latest 3.8.0 beta with the ORDER BY and GROUP BY name resolution fixes, in order to test SQLite.

drh 2013-08-15 22:45 trunk
Commit b67b42fea8afe1c8c95a84261aa748ca510c1c7d
2 files changed +71 -56 +2 -2
+71 -56
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656656
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657657
** [sqlite_version()] and [sqlite_source_id()].
658658
*/
659659
#define SQLITE_VERSION "3.8.0"
660660
#define SQLITE_VERSION_NUMBER 3008000
661
-#define SQLITE_SOURCE_ID "2013-08-06 07:45:08 924f7e4d7a8fa2fe9100836663f3733b6e1a9084"
661
+#define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e"
662662
663663
/*
664664
** CAPI3REF: Run-Time Library Version Numbers
665665
** KEYWORDS: sqlite3_version, sqlite3_sourceid
666666
**
@@ -7780,11 +7780,11 @@
77807780
#endif
77817781
77827782
#if 0
77837783
} /* End of the 'extern "C"' block */
77847784
#endif
7785
-#endif
7785
+#endif /* _SQLITE3_H_ */
77867786
77877787
/*
77887788
** 2010 August 30
77897789
**
77907790
** The author disclaims copyright to this source code. In place of
@@ -11214,11 +11214,11 @@
1121411214
** subqueries looking for a match.
1121511215
*/
1121611216
struct NameContext {
1121711217
Parse *pParse; /* The parser */
1121811218
SrcList *pSrcList; /* One or more tables used to resolve names */
11219
- ExprList *pEList; /* Optional list of named expressions */
11219
+ ExprList *pEList; /* Optional list of result-set columns */
1122011220
AggInfo *pAggInfo; /* Information about aggregates at this level */
1122111221
NameContext *pNext; /* Next outer name context. NULL for outermost */
1122211222
int nRef; /* Number of names resolved by this context */
1122311223
int nErr; /* Number of errors encountered while resolving names */
1122411224
u8 ncFlags; /* Zero or more NC_* flags defined below */
@@ -11229,13 +11229,11 @@
1122911229
*/
1123011230
#define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
1123111231
#define NC_HasAgg 0x02 /* One or more aggregate functions seen */
1123211232
#define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
1123311233
#define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11234
-#define NC_AsMaybe 0x10 /* Resolve to AS terms of the result set only
11235
- ** if no other resolution is available */
11236
-#define NC_PartIdx 0x20 /* True if resolving a partial index WHERE */
11234
+#define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
1123711235
1123811236
/*
1123911237
** An instance of the following structure contains all information
1124011238
** needed to generate code for a single SELECT statement.
1124111239
**
@@ -17231,17 +17229,17 @@
1723117229
u8 *aCtrl;
1723217230
1723317231
} mem5;
1723417232
1723517233
/*
17236
-** Access the static variable through a macro for SQLITE_OMIT_WSD
17234
+** Access the static variable through a macro for SQLITE_OMIT_WSD.
1723717235
*/
1723817236
#define mem5 GLOBAL(struct Mem5Global, mem5)
1723917237
1724017238
/*
1724117239
** Assuming mem5.zPool is divided up into an array of Mem5Link
17242
-** structures, return a pointer to the idx-th such lik.
17240
+** structures, return a pointer to the idx-th such link.
1724317241
*/
1724417242
#define MEM5LINK(idx) ((Mem5Link *)(&mem5.zPool[(idx)*mem5.szAtom]))
1724517243
1724617244
/*
1724717245
** Unlink the chunk at mem5.aPool[i] from list it is currently
@@ -17333,11 +17331,11 @@
1733317331
1733417332
/*
1733517333
** Return a block of memory of at least nBytes in size.
1733617334
** Return NULL if unable. Return NULL if nBytes==0.
1733717335
**
17338
-** The caller guarantees that nByte positive.
17336
+** The caller guarantees that nByte is positive.
1733917337
**
1734017338
** The caller has obtained a mutex prior to invoking this
1734117339
** routine so there is never any chance that two or more
1734217340
** threads can be in this routine at the same time.
1734317341
*/
@@ -17455,11 +17453,11 @@
1745517453
}
1745617454
memsys5Link(iBlock, iLogsize);
1745717455
}
1745817456
1745917457
/*
17460
-** Allocate nBytes of memory
17458
+** Allocate nBytes of memory.
1746117459
*/
1746217460
static void *memsys5Malloc(int nBytes){
1746317461
sqlite3_int64 *p = 0;
1746417462
if( nBytes>0 ){
1746517463
memsys5Enter();
@@ -74041,22 +74039,23 @@
7404174039
**
7404274040
** The reason for suppressing the TK_AS term when the expression is a simple
7404374041
** column reference is so that the column reference will be recognized as
7404474042
** usable by indices within the WHERE clause processing logic.
7404574043
**
74046
-** Hack: The TK_AS operator is inhibited if zType[0]=='G'. This means
74044
+** The TK_AS operator is inhibited if zType[0]=='G'. This means
7404774045
** that in a GROUP BY clause, the expression is evaluated twice. Hence:
7404874046
**
7404974047
** SELECT random()%5 AS x, count(*) FROM tab GROUP BY x
7405074048
**
7405174049
** Is equivalent to:
7405274050
**
7405374051
** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
7405474052
**
7405574053
** The result of random()%5 in the GROUP BY clause is probably different
74056
-** from the result in the result-set. We might fix this someday. Or
74057
-** then again, we might not...
74054
+** from the result in the result-set. On the other hand Standard SQL does
74055
+** not allow the GROUP BY clause to contain references to result-set columns.
74056
+** So this should never come up in well-formed queries.
7405874057
**
7405974058
** If the reference is followed by a COLLATE operator, then make sure
7406074059
** the COLLATE operator is preserved. For example:
7406174060
**
7406274061
** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
@@ -74382,14 +74381,20 @@
7438274381
**
7438374382
** In cases like this, replace pExpr with a copy of the expression that
7438474383
** forms the result set entry ("a+b" in the example) and return immediately.
7438574384
** Note that the expression in the result set should have already been
7438674385
** resolved by the time the WHERE clause is resolved.
74386
+ **
74387
+ ** The ability to use an output result-set column in the WHERE, GROUP BY,
74388
+ ** or HAVING clauses, or as part of a larger expression in the ORDRE BY
74389
+ ** clause is not standard SQL. This is a (goofy) SQLite extension, that
74390
+ ** is supported for backwards compatibility only. TO DO: Issue a warning
74391
+ ** on sqlite3_log() whenever the capability is used.
7438774392
*/
7438874393
if( (pEList = pNC->pEList)!=0
7438974394
&& zTab==0
74390
- && ((pNC->ncFlags & NC_AsMaybe)==0 || cnt==0)
74395
+ && cnt==0
7439174396
){
7439274397
for(j=0; j<pEList->nExpr; j++){
7439374398
char *zAs = pEList->a[j].zName;
7439474399
if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
7439574400
Expr *pOrig;
@@ -74947,11 +74952,11 @@
7494774952
}
7494874953
7494974954
/*
7495074955
** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
7495174956
** the SELECT statement pSelect. If any term is reference to a
74952
-** result set expression (as determined by the ExprList.a.iCol field)
74957
+** result set expression (as determined by the ExprList.a.iOrderByCol field)
7495374958
** then convert that term into a copy of the corresponding result set
7495474959
** column.
7495574960
**
7495674961
** If any errors are detected, add an error message to pParse and
7495774962
** return non-zero. Return zero if no errors are seen.
@@ -74995,11 +75000,11 @@
7499575000
**
7499675001
** This routine resolves each term of the clause into an expression.
7499775002
** If the order-by term is an integer I between 1 and N (where N is the
7499875003
** number of columns in the result set of the SELECT) then the expression
7499975004
** in the resolution is a copy of the I-th result-set expression. If
75000
-** the order-by term is an identify that corresponds to the AS-name of
75005
+** the order-by term is an identifier that corresponds to the AS-name of
7500175006
** a result-set expression, then the term resolves to a copy of the
7500275007
** result-set expression. Otherwise, the expression is resolved in
7500375008
** the usual way - using sqlite3ResolveExprNames().
7500475009
**
7500575010
** This routine returns the number of errors. If errors occur, then
@@ -75021,20 +75026,23 @@
7502175026
if( pOrderBy==0 ) return 0;
7502275027
nResult = pSelect->pEList->nExpr;
7502375028
pParse = pNC->pParse;
7502475029
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
7502575030
Expr *pE = pItem->pExpr;
75026
- iCol = resolveAsName(pParse, pSelect->pEList, pE);
75027
- if( iCol>0 ){
75028
- /* If an AS-name match is found, mark this ORDER BY column as being
75029
- ** a copy of the iCol-th result-set column. The subsequent call to
75030
- ** sqlite3ResolveOrderGroupBy() will convert the expression to a
75031
- ** copy of the iCol-th result-set expression. */
75032
- pItem->iOrderByCol = (u16)iCol;
75033
- continue;
75034
- }
75035
- if( sqlite3ExprIsInteger(sqlite3ExprSkipCollate(pE), &iCol) ){
75031
+ Expr *pE2 = sqlite3ExprSkipCollate(pE);
75032
+ if( zType[0]!='G' ){
75033
+ iCol = resolveAsName(pParse, pSelect->pEList, pE2);
75034
+ if( iCol>0 ){
75035
+ /* If an AS-name match is found, mark this ORDER BY column as being
75036
+ ** a copy of the iCol-th result-set column. The subsequent call to
75037
+ ** sqlite3ResolveOrderGroupBy() will convert the expression to a
75038
+ ** copy of the iCol-th result-set expression. */
75039
+ pItem->iOrderByCol = (u16)iCol;
75040
+ continue;
75041
+ }
75042
+ }
75043
+ if( sqlite3ExprIsInteger(pE2, &iCol) ){
7503675044
/* The ORDER BY term is an integer constant. Again, set the column
7503775045
** number so that sqlite3ResolveOrderGroupBy() will convert the
7503875046
** order-by term to a copy of the result-set expression */
7503975047
if( iCol<1 || iCol>0xffff ){
7504075048
resolveOutOfRangeError(pParse, zType, i+1, nResult);
@@ -75173,23 +75181,21 @@
7517375181
if( p->pHaving && !pGroupBy ){
7517475182
sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
7517575183
return WRC_Abort;
7517675184
}
7517775185
75178
- /* Add the expression list to the name-context before parsing the
75186
+ /* Add the output column list to the name-context before parsing the
7517975187
** other expressions in the SELECT statement. This is so that
7518075188
** expressions in the WHERE clause (etc.) can refer to expressions by
7518175189
** aliases in the result set.
7518275190
**
7518375191
** Minor point: If this is the case, then the expression will be
7518475192
** re-evaluated for each reference to it.
7518575193
*/
7518675194
sNC.pEList = p->pEList;
75187
- sNC.ncFlags |= NC_AsMaybe;
7518875195
if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
7518975196
if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
75190
- sNC.ncFlags &= ~NC_AsMaybe;
7519175197
7519275198
/* The ORDER BY and GROUP BY clauses may not refer to terms in
7519375199
** outer queries
7519475200
*/
7519575201
sNC.pNext = 0;
@@ -77134,19 +77140,21 @@
7713477140
assert( !isRowid );
7713577141
sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
7713677142
dest.affSdst = (u8)affinity;
7713777143
assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
7713877144
pExpr->x.pSelect->iLimit = 0;
77145
+ testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
7713977146
if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
7714077147
sqlite3DbFree(pParse->db, pKeyInfo);
7714177148
return 0;
7714277149
}
7714377150
pEList = pExpr->x.pSelect->pEList;
77144
- if( pKeyInfo && ALWAYS(pEList!=0 && pEList->nExpr>0) ){
77145
- pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
77146
- pEList->a[0].pExpr);
77147
- }
77151
+ assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
77152
+ assert( pEList!=0 );
77153
+ assert( pEList->nExpr>0 );
77154
+ pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
77155
+ pEList->a[0].pExpr);
7714877156
}else if( ALWAYS(pExpr->x.pList!=0) ){
7714977157
/* Case 2: expr IN (exprlist)
7715077158
**
7715177159
** For each expression, build an index key from the evaluation and
7715277160
** store it in the temporary table. If <expr> is a column, then use
@@ -104711,11 +104719,11 @@
104711104719
# define WHERETRACE_ENABLED 1
104712104720
#else
104713104721
# define WHERETRACE(K,X)
104714104722
#endif
104715104723
104716
-/* Forward reference
104724
+/* Forward references
104717104725
*/
104718104726
typedef struct WhereClause WhereClause;
104719104727
typedef struct WhereMaskSet WhereMaskSet;
104720104728
typedef struct WhereOrInfo WhereOrInfo;
104721104729
typedef struct WhereAndInfo WhereAndInfo;
@@ -104733,18 +104741,19 @@
104733104741
** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
104734104742
** (Virtual tables can return a larger cost, but let's assume they do not.)
104735104743
** So all costs can be stored in a 16-bit unsigned integer without risk
104736104744
** of overflow.
104737104745
**
104738
-** Costs are estimates, so don't go to the computational trouble to compute
104739
-** 10*log2(X) exactly. Instead, a close estimate is used. Any value of
104740
-** X<=1 is stored as 0. X=2 is 10. X=3 is 16. X=1000 is 99. etc.
104746
+** Costs are estimates, so no effort is made to compute 10*log2(X) exactly.
104747
+** Instead, a close estimate is used. Any value of X<=1 is stored as 0.
104748
+** X=2 is 10. X=3 is 16. X=1000 is 99. etc.
104741104749
**
104742104750
** The tool/wherecosttest.c source file implements a command-line program
104743
-** that will convert between WhereCost to integers and do addition and
104744
-** multiplication on WhereCost values. That command-line program is a
104745
-** useful utility to have around when working with this module.
104751
+** that will convert WhereCosts to integers, convert integers to WhereCosts
104752
+** and do addition and multiplication on WhereCost values. The wherecosttest
104753
+** command-line program is a useful utility to have around when working with
104754
+** this module.
104746104755
*/
104747104756
typedef unsigned short int WhereCost;
104748104757
104749104758
/*
104750104759
** This object contains information needed to implement a single nested
@@ -104843,12 +104852,12 @@
104843104852
WhereCost rRun; /* Cost of running this subquery */
104844104853
WhereCost nOut; /* Number of outputs for this subquery */
104845104854
};
104846104855
104847104856
/* The WhereOrSet object holds a set of possible WhereOrCosts that
104848
-** correspond to the subquery(s) of OR-clause processing. At most
104849
-** favorable N_OR_COST elements are retained.
104857
+** correspond to the subquery(s) of OR-clause processing. Only the
104858
+** best N_OR_COST elements are retained.
104850104859
*/
104851104860
#define N_OR_COST 3
104852104861
struct WhereOrSet {
104853104862
u16 n; /* Number of valid a[] entries */
104854104863
WhereOrCost a[N_OR_COST]; /* Set of best costs */
@@ -104910,13 +104919,13 @@
104910104919
**
104911104920
** A WhereTerm might also be two or more subterms connected by OR:
104912104921
**
104913104922
** (t1.X <op> <expr>) OR (t1.Y <op> <expr>) OR ....
104914104923
**
104915
-** In this second case, wtFlag as the TERM_ORINFO set and eOperator==WO_OR
104924
+** In this second case, wtFlag has the TERM_ORINFO bit set and eOperator==WO_OR
104916104925
** and the WhereTerm.u.pOrInfo field points to auxiliary information that
104917
-** is collected about the
104926
+** is collected about the OR clause.
104918104927
**
104919104928
** If a term in the WHERE clause does not match either of the two previous
104920104929
** categories, then eOperator==0. The WhereTerm.pExpr field is still set
104921104930
** to the original subexpression content and wtFlags is set up appropriately
104922104931
** but no other fields in the WhereTerm object are meaningful.
@@ -105424,11 +105433,11 @@
105424105433
assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
105425105434
pMaskSet->ix[pMaskSet->n++] = iCursor;
105426105435
}
105427105436
105428105437
/*
105429
-** These routine walk (recursively) an expression tree and generates
105438
+** These routines walk (recursively) an expression tree and generate
105430105439
** a bitmask indicating which tables are used in that expression
105431105440
** tree.
105432105441
*/
105433105442
static Bitmask exprListTableUsage(WhereMaskSet*, ExprList*);
105434105443
static Bitmask exprSelectTableUsage(WhereMaskSet*, Select*);
@@ -105941,14 +105950,14 @@
105941105950
** u.pAndInfo set to a dynamically allocated WhereAndTerm object.
105942105951
**
105943105952
** From another point of view, "indexable" means that the subterm could
105944105953
** potentially be used with an index if an appropriate index exists.
105945105954
** This analysis does not consider whether or not the index exists; that
105946
-** is something the bestIndex() routine will determine. This analysis
105947
-** only looks at whether subterms appropriate for indexing exist.
105955
+** is decided elsewhere. This analysis only looks at whether subterms
105956
+** appropriate for indexing exist.
105948105957
**
105949
-** All examples A through E above all satisfy case 2. But if a term
105958
+** All examples A through E above satisfy case 2. But if a term
105950105959
** also statisfies case 1 (such as B) we know that the optimizer will
105951105960
** always prefer case 1, so in that case we pretend that case 2 is not
105952105961
** satisfied.
105953105962
**
105954105963
** It might be the case that multiple tables are indexable. For example,
@@ -106611,11 +106620,11 @@
106611106620
106612106621
return 0;
106613106622
}
106614106623
106615106624
/*
106616
-** The (an approximate) sum of two WhereCosts. This computation is
106625
+** Find (an approximate) sum of two WhereCosts. This computation is
106617106626
** not a simple "+" operator because WhereCost is stored as a logarithmic
106618106627
** value.
106619106628
**
106620106629
*/
106621106630
static WhereCost whereCostAdd(WhereCost a, WhereCost b){
@@ -115614,10 +115623,13 @@
115614115623
** without blocking.
115615115624
*/
115616115625
SQLITE_API int sqlite3_initialize(void){
115617115626
MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
115618115627
int rc; /* Result code */
115628
+#ifdef SQLITE_EXTRA_INIT
115629
+ int bRunExtraInit = 0; /* Extra initialization needed */
115630
+#endif
115619115631
115620115632
#ifdef SQLITE_OMIT_WSD
115621115633
rc = sqlite3_wsd_init(4096, 24);
115622115634
if( rc!=SQLITE_OK ){
115623115635
return rc;
@@ -115711,10 +115723,13 @@
115711115723
}
115712115724
if( rc==SQLITE_OK ){
115713115725
sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
115714115726
sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
115715115727
sqlite3GlobalConfig.isInit = 1;
115728
+#ifdef SQLITE_EXTRA_INIT
115729
+ bRunExtraInit = 1;
115730
+#endif
115716115731
}
115717115732
sqlite3GlobalConfig.inProgress = 0;
115718115733
}
115719115734
sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
115720115735
@@ -115751,11 +115766,11 @@
115751115766
115752115767
/* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
115753115768
** compile-time option.
115754115769
*/
115755115770
#ifdef SQLITE_EXTRA_INIT
115756
- if( rc==SQLITE_OK && sqlite3GlobalConfig.isInit ){
115771
+ if( bRunExtraInit ){
115757115772
int SQLITE_EXTRA_INIT(const char*);
115758115773
rc = SQLITE_EXTRA_INIT(0);
115759115774
}
115760115775
#endif
115761115776
@@ -115939,12 +115954,12 @@
115939115954
** run.
115940115955
*/
115941115956
memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
115942115957
}else{
115943115958
/* The heap pointer is not NULL, then install one of the
115944
- ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor
115945
- ** ENABLE_MEMSYS5 is defined, return an error.
115959
+ ** mem5.c/mem3.c methods. The enclosing #if guarantees at
115960
+ ** least one of these methods is currently enabled.
115946115961
*/
115947115962
#ifdef SQLITE_ENABLE_MEMSYS3
115948115963
sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
115949115964
#endif
115950115965
#ifdef SQLITE_ENABLE_MEMSYS5
@@ -115959,11 +115974,11 @@
115959115974
sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
115960115975
sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
115961115976
break;
115962115977
}
115963115978
115964
- /* Record a pointer to the logger funcction and its first argument.
115979
+ /* Record a pointer to the logger function and its first argument.
115965115980
** The default is NULL. Logging is disabled if the function pointer is
115966115981
** NULL.
115967115982
*/
115968115983
case SQLITE_CONFIG_LOG: {
115969115984
/* MSVC is picky about pulling func ptrs from va lists.
@@ -117675,24 +117690,24 @@
117675117690
117676117691
for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
117677117692
zFile = sqlite3_malloc(nByte);
117678117693
if( !zFile ) return SQLITE_NOMEM;
117679117694
117695
+ iIn = 5;
117696
+#ifndef SQLITE_ALLOW_URI_AUTHORITY
117680117697
/* Discard the scheme and authority segments of the URI. */
117681117698
if( zUri[5]=='/' && zUri[6]=='/' ){
117682117699
iIn = 7;
117683117700
while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
117684
-
117685117701
if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
117686117702
*pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
117687117703
iIn-7, &zUri[7]);
117688117704
rc = SQLITE_ERROR;
117689117705
goto parse_uri_out;
117690117706
}
117691
- }else{
117692
- iIn = 5;
117693117707
}
117708
+#endif
117694117709
117695117710
/* Copy the filename and any query parameters into the zFile buffer.
117696117711
** Decode %HH escape codes along the way.
117697117712
**
117698117713
** Within this loop, variable eState may be set to 0, 1 or 2, depending
117699117714
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.8.0"
660 #define SQLITE_VERSION_NUMBER 3008000
661 #define SQLITE_SOURCE_ID "2013-08-06 07:45:08 924f7e4d7a8fa2fe9100836663f3733b6e1a9084"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -7780,11 +7780,11 @@
7780 #endif
7781
7782 #if 0
7783 } /* End of the 'extern "C"' block */
7784 #endif
7785 #endif
7786
7787 /*
7788 ** 2010 August 30
7789 **
7790 ** The author disclaims copyright to this source code. In place of
@@ -11214,11 +11214,11 @@
11214 ** subqueries looking for a match.
11215 */
11216 struct NameContext {
11217 Parse *pParse; /* The parser */
11218 SrcList *pSrcList; /* One or more tables used to resolve names */
11219 ExprList *pEList; /* Optional list of named expressions */
11220 AggInfo *pAggInfo; /* Information about aggregates at this level */
11221 NameContext *pNext; /* Next outer name context. NULL for outermost */
11222 int nRef; /* Number of names resolved by this context */
11223 int nErr; /* Number of errors encountered while resolving names */
11224 u8 ncFlags; /* Zero or more NC_* flags defined below */
@@ -11229,13 +11229,11 @@
11229 */
11230 #define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
11231 #define NC_HasAgg 0x02 /* One or more aggregate functions seen */
11232 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11233 #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11234 #define NC_AsMaybe 0x10 /* Resolve to AS terms of the result set only
11235 ** if no other resolution is available */
11236 #define NC_PartIdx 0x20 /* True if resolving a partial index WHERE */
11237
11238 /*
11239 ** An instance of the following structure contains all information
11240 ** needed to generate code for a single SELECT statement.
11241 **
@@ -17231,17 +17229,17 @@
17231 u8 *aCtrl;
17232
17233 } mem5;
17234
17235 /*
17236 ** Access the static variable through a macro for SQLITE_OMIT_WSD
17237 */
17238 #define mem5 GLOBAL(struct Mem5Global, mem5)
17239
17240 /*
17241 ** Assuming mem5.zPool is divided up into an array of Mem5Link
17242 ** structures, return a pointer to the idx-th such lik.
17243 */
17244 #define MEM5LINK(idx) ((Mem5Link *)(&mem5.zPool[(idx)*mem5.szAtom]))
17245
17246 /*
17247 ** Unlink the chunk at mem5.aPool[i] from list it is currently
@@ -17333,11 +17331,11 @@
17333
17334 /*
17335 ** Return a block of memory of at least nBytes in size.
17336 ** Return NULL if unable. Return NULL if nBytes==0.
17337 **
17338 ** The caller guarantees that nByte positive.
17339 **
17340 ** The caller has obtained a mutex prior to invoking this
17341 ** routine so there is never any chance that two or more
17342 ** threads can be in this routine at the same time.
17343 */
@@ -17455,11 +17453,11 @@
17455 }
17456 memsys5Link(iBlock, iLogsize);
17457 }
17458
17459 /*
17460 ** Allocate nBytes of memory
17461 */
17462 static void *memsys5Malloc(int nBytes){
17463 sqlite3_int64 *p = 0;
17464 if( nBytes>0 ){
17465 memsys5Enter();
@@ -74041,22 +74039,23 @@
74041 **
74042 ** The reason for suppressing the TK_AS term when the expression is a simple
74043 ** column reference is so that the column reference will be recognized as
74044 ** usable by indices within the WHERE clause processing logic.
74045 **
74046 ** Hack: The TK_AS operator is inhibited if zType[0]=='G'. This means
74047 ** that in a GROUP BY clause, the expression is evaluated twice. Hence:
74048 **
74049 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY x
74050 **
74051 ** Is equivalent to:
74052 **
74053 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
74054 **
74055 ** The result of random()%5 in the GROUP BY clause is probably different
74056 ** from the result in the result-set. We might fix this someday. Or
74057 ** then again, we might not...
 
74058 **
74059 ** If the reference is followed by a COLLATE operator, then make sure
74060 ** the COLLATE operator is preserved. For example:
74061 **
74062 ** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
@@ -74382,14 +74381,20 @@
74382 **
74383 ** In cases like this, replace pExpr with a copy of the expression that
74384 ** forms the result set entry ("a+b" in the example) and return immediately.
74385 ** Note that the expression in the result set should have already been
74386 ** resolved by the time the WHERE clause is resolved.
 
 
 
 
 
 
74387 */
74388 if( (pEList = pNC->pEList)!=0
74389 && zTab==0
74390 && ((pNC->ncFlags & NC_AsMaybe)==0 || cnt==0)
74391 ){
74392 for(j=0; j<pEList->nExpr; j++){
74393 char *zAs = pEList->a[j].zName;
74394 if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
74395 Expr *pOrig;
@@ -74947,11 +74952,11 @@
74947 }
74948
74949 /*
74950 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
74951 ** the SELECT statement pSelect. If any term is reference to a
74952 ** result set expression (as determined by the ExprList.a.iCol field)
74953 ** then convert that term into a copy of the corresponding result set
74954 ** column.
74955 **
74956 ** If any errors are detected, add an error message to pParse and
74957 ** return non-zero. Return zero if no errors are seen.
@@ -74995,11 +75000,11 @@
74995 **
74996 ** This routine resolves each term of the clause into an expression.
74997 ** If the order-by term is an integer I between 1 and N (where N is the
74998 ** number of columns in the result set of the SELECT) then the expression
74999 ** in the resolution is a copy of the I-th result-set expression. If
75000 ** the order-by term is an identify that corresponds to the AS-name of
75001 ** a result-set expression, then the term resolves to a copy of the
75002 ** result-set expression. Otherwise, the expression is resolved in
75003 ** the usual way - using sqlite3ResolveExprNames().
75004 **
75005 ** This routine returns the number of errors. If errors occur, then
@@ -75021,20 +75026,23 @@
75021 if( pOrderBy==0 ) return 0;
75022 nResult = pSelect->pEList->nExpr;
75023 pParse = pNC->pParse;
75024 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
75025 Expr *pE = pItem->pExpr;
75026 iCol = resolveAsName(pParse, pSelect->pEList, pE);
75027 if( iCol>0 ){
75028 /* If an AS-name match is found, mark this ORDER BY column as being
75029 ** a copy of the iCol-th result-set column. The subsequent call to
75030 ** sqlite3ResolveOrderGroupBy() will convert the expression to a
75031 ** copy of the iCol-th result-set expression. */
75032 pItem->iOrderByCol = (u16)iCol;
75033 continue;
75034 }
75035 if( sqlite3ExprIsInteger(sqlite3ExprSkipCollate(pE), &iCol) ){
 
 
 
75036 /* The ORDER BY term is an integer constant. Again, set the column
75037 ** number so that sqlite3ResolveOrderGroupBy() will convert the
75038 ** order-by term to a copy of the result-set expression */
75039 if( iCol<1 || iCol>0xffff ){
75040 resolveOutOfRangeError(pParse, zType, i+1, nResult);
@@ -75173,23 +75181,21 @@
75173 if( p->pHaving && !pGroupBy ){
75174 sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
75175 return WRC_Abort;
75176 }
75177
75178 /* Add the expression list to the name-context before parsing the
75179 ** other expressions in the SELECT statement. This is so that
75180 ** expressions in the WHERE clause (etc.) can refer to expressions by
75181 ** aliases in the result set.
75182 **
75183 ** Minor point: If this is the case, then the expression will be
75184 ** re-evaluated for each reference to it.
75185 */
75186 sNC.pEList = p->pEList;
75187 sNC.ncFlags |= NC_AsMaybe;
75188 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
75189 if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
75190 sNC.ncFlags &= ~NC_AsMaybe;
75191
75192 /* The ORDER BY and GROUP BY clauses may not refer to terms in
75193 ** outer queries
75194 */
75195 sNC.pNext = 0;
@@ -77134,19 +77140,21 @@
77134 assert( !isRowid );
77135 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
77136 dest.affSdst = (u8)affinity;
77137 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
77138 pExpr->x.pSelect->iLimit = 0;
 
77139 if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
77140 sqlite3DbFree(pParse->db, pKeyInfo);
77141 return 0;
77142 }
77143 pEList = pExpr->x.pSelect->pEList;
77144 if( pKeyInfo && ALWAYS(pEList!=0 && pEList->nExpr>0) ){
77145 pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
77146 pEList->a[0].pExpr);
77147 }
 
77148 }else if( ALWAYS(pExpr->x.pList!=0) ){
77149 /* Case 2: expr IN (exprlist)
77150 **
77151 ** For each expression, build an index key from the evaluation and
77152 ** store it in the temporary table. If <expr> is a column, then use
@@ -104711,11 +104719,11 @@
104711 # define WHERETRACE_ENABLED 1
104712 #else
104713 # define WHERETRACE(K,X)
104714 #endif
104715
104716 /* Forward reference
104717 */
104718 typedef struct WhereClause WhereClause;
104719 typedef struct WhereMaskSet WhereMaskSet;
104720 typedef struct WhereOrInfo WhereOrInfo;
104721 typedef struct WhereAndInfo WhereAndInfo;
@@ -104733,18 +104741,19 @@
104733 ** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
104734 ** (Virtual tables can return a larger cost, but let's assume they do not.)
104735 ** So all costs can be stored in a 16-bit unsigned integer without risk
104736 ** of overflow.
104737 **
104738 ** Costs are estimates, so don't go to the computational trouble to compute
104739 ** 10*log2(X) exactly. Instead, a close estimate is used. Any value of
104740 ** X<=1 is stored as 0. X=2 is 10. X=3 is 16. X=1000 is 99. etc.
104741 **
104742 ** The tool/wherecosttest.c source file implements a command-line program
104743 ** that will convert between WhereCost to integers and do addition and
104744 ** multiplication on WhereCost values. That command-line program is a
104745 ** useful utility to have around when working with this module.
 
104746 */
104747 typedef unsigned short int WhereCost;
104748
104749 /*
104750 ** This object contains information needed to implement a single nested
@@ -104843,12 +104852,12 @@
104843 WhereCost rRun; /* Cost of running this subquery */
104844 WhereCost nOut; /* Number of outputs for this subquery */
104845 };
104846
104847 /* The WhereOrSet object holds a set of possible WhereOrCosts that
104848 ** correspond to the subquery(s) of OR-clause processing. At most
104849 ** favorable N_OR_COST elements are retained.
104850 */
104851 #define N_OR_COST 3
104852 struct WhereOrSet {
104853 u16 n; /* Number of valid a[] entries */
104854 WhereOrCost a[N_OR_COST]; /* Set of best costs */
@@ -104910,13 +104919,13 @@
104910 **
104911 ** A WhereTerm might also be two or more subterms connected by OR:
104912 **
104913 ** (t1.X <op> <expr>) OR (t1.Y <op> <expr>) OR ....
104914 **
104915 ** In this second case, wtFlag as the TERM_ORINFO set and eOperator==WO_OR
104916 ** and the WhereTerm.u.pOrInfo field points to auxiliary information that
104917 ** is collected about the
104918 **
104919 ** If a term in the WHERE clause does not match either of the two previous
104920 ** categories, then eOperator==0. The WhereTerm.pExpr field is still set
104921 ** to the original subexpression content and wtFlags is set up appropriately
104922 ** but no other fields in the WhereTerm object are meaningful.
@@ -105424,11 +105433,11 @@
105424 assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
105425 pMaskSet->ix[pMaskSet->n++] = iCursor;
105426 }
105427
105428 /*
105429 ** These routine walk (recursively) an expression tree and generates
105430 ** a bitmask indicating which tables are used in that expression
105431 ** tree.
105432 */
105433 static Bitmask exprListTableUsage(WhereMaskSet*, ExprList*);
105434 static Bitmask exprSelectTableUsage(WhereMaskSet*, Select*);
@@ -105941,14 +105950,14 @@
105941 ** u.pAndInfo set to a dynamically allocated WhereAndTerm object.
105942 **
105943 ** From another point of view, "indexable" means that the subterm could
105944 ** potentially be used with an index if an appropriate index exists.
105945 ** This analysis does not consider whether or not the index exists; that
105946 ** is something the bestIndex() routine will determine. This analysis
105947 ** only looks at whether subterms appropriate for indexing exist.
105948 **
105949 ** All examples A through E above all satisfy case 2. But if a term
105950 ** also statisfies case 1 (such as B) we know that the optimizer will
105951 ** always prefer case 1, so in that case we pretend that case 2 is not
105952 ** satisfied.
105953 **
105954 ** It might be the case that multiple tables are indexable. For example,
@@ -106611,11 +106620,11 @@
106611
106612 return 0;
106613 }
106614
106615 /*
106616 ** The (an approximate) sum of two WhereCosts. This computation is
106617 ** not a simple "+" operator because WhereCost is stored as a logarithmic
106618 ** value.
106619 **
106620 */
106621 static WhereCost whereCostAdd(WhereCost a, WhereCost b){
@@ -115614,10 +115623,13 @@
115614 ** without blocking.
115615 */
115616 SQLITE_API int sqlite3_initialize(void){
115617 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
115618 int rc; /* Result code */
 
 
 
115619
115620 #ifdef SQLITE_OMIT_WSD
115621 rc = sqlite3_wsd_init(4096, 24);
115622 if( rc!=SQLITE_OK ){
115623 return rc;
@@ -115711,10 +115723,13 @@
115711 }
115712 if( rc==SQLITE_OK ){
115713 sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
115714 sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
115715 sqlite3GlobalConfig.isInit = 1;
 
 
 
115716 }
115717 sqlite3GlobalConfig.inProgress = 0;
115718 }
115719 sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
115720
@@ -115751,11 +115766,11 @@
115751
115752 /* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
115753 ** compile-time option.
115754 */
115755 #ifdef SQLITE_EXTRA_INIT
115756 if( rc==SQLITE_OK && sqlite3GlobalConfig.isInit ){
115757 int SQLITE_EXTRA_INIT(const char*);
115758 rc = SQLITE_EXTRA_INIT(0);
115759 }
115760 #endif
115761
@@ -115939,12 +115954,12 @@
115939 ** run.
115940 */
115941 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
115942 }else{
115943 /* The heap pointer is not NULL, then install one of the
115944 ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor
115945 ** ENABLE_MEMSYS5 is defined, return an error.
115946 */
115947 #ifdef SQLITE_ENABLE_MEMSYS3
115948 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
115949 #endif
115950 #ifdef SQLITE_ENABLE_MEMSYS5
@@ -115959,11 +115974,11 @@
115959 sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
115960 sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
115961 break;
115962 }
115963
115964 /* Record a pointer to the logger funcction and its first argument.
115965 ** The default is NULL. Logging is disabled if the function pointer is
115966 ** NULL.
115967 */
115968 case SQLITE_CONFIG_LOG: {
115969 /* MSVC is picky about pulling func ptrs from va lists.
@@ -117675,24 +117690,24 @@
117675
117676 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
117677 zFile = sqlite3_malloc(nByte);
117678 if( !zFile ) return SQLITE_NOMEM;
117679
 
 
117680 /* Discard the scheme and authority segments of the URI. */
117681 if( zUri[5]=='/' && zUri[6]=='/' ){
117682 iIn = 7;
117683 while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
117684
117685 if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
117686 *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
117687 iIn-7, &zUri[7]);
117688 rc = SQLITE_ERROR;
117689 goto parse_uri_out;
117690 }
117691 }else{
117692 iIn = 5;
117693 }
 
117694
117695 /* Copy the filename and any query parameters into the zFile buffer.
117696 ** Decode %HH escape codes along the way.
117697 **
117698 ** Within this loop, variable eState may be set to 0, 1 or 2, depending
117699
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -656,11 +656,11 @@
656 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
657 ** [sqlite_version()] and [sqlite_source_id()].
658 */
659 #define SQLITE_VERSION "3.8.0"
660 #define SQLITE_VERSION_NUMBER 3008000
661 #define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e"
662
663 /*
664 ** CAPI3REF: Run-Time Library Version Numbers
665 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
666 **
@@ -7780,11 +7780,11 @@
7780 #endif
7781
7782 #if 0
7783 } /* End of the 'extern "C"' block */
7784 #endif
7785 #endif /* _SQLITE3_H_ */
7786
7787 /*
7788 ** 2010 August 30
7789 **
7790 ** The author disclaims copyright to this source code. In place of
@@ -11214,11 +11214,11 @@
11214 ** subqueries looking for a match.
11215 */
11216 struct NameContext {
11217 Parse *pParse; /* The parser */
11218 SrcList *pSrcList; /* One or more tables used to resolve names */
11219 ExprList *pEList; /* Optional list of result-set columns */
11220 AggInfo *pAggInfo; /* Information about aggregates at this level */
11221 NameContext *pNext; /* Next outer name context. NULL for outermost */
11222 int nRef; /* Number of names resolved by this context */
11223 int nErr; /* Number of errors encountered while resolving names */
11224 u8 ncFlags; /* Zero or more NC_* flags defined below */
@@ -11229,13 +11229,11 @@
11229 */
11230 #define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
11231 #define NC_HasAgg 0x02 /* One or more aggregate functions seen */
11232 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11233 #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11234 #define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
 
 
11235
11236 /*
11237 ** An instance of the following structure contains all information
11238 ** needed to generate code for a single SELECT statement.
11239 **
@@ -17231,17 +17229,17 @@
17229 u8 *aCtrl;
17230
17231 } mem5;
17232
17233 /*
17234 ** Access the static variable through a macro for SQLITE_OMIT_WSD.
17235 */
17236 #define mem5 GLOBAL(struct Mem5Global, mem5)
17237
17238 /*
17239 ** Assuming mem5.zPool is divided up into an array of Mem5Link
17240 ** structures, return a pointer to the idx-th such link.
17241 */
17242 #define MEM5LINK(idx) ((Mem5Link *)(&mem5.zPool[(idx)*mem5.szAtom]))
17243
17244 /*
17245 ** Unlink the chunk at mem5.aPool[i] from list it is currently
@@ -17333,11 +17331,11 @@
17331
17332 /*
17333 ** Return a block of memory of at least nBytes in size.
17334 ** Return NULL if unable. Return NULL if nBytes==0.
17335 **
17336 ** The caller guarantees that nByte is positive.
17337 **
17338 ** The caller has obtained a mutex prior to invoking this
17339 ** routine so there is never any chance that two or more
17340 ** threads can be in this routine at the same time.
17341 */
@@ -17455,11 +17453,11 @@
17453 }
17454 memsys5Link(iBlock, iLogsize);
17455 }
17456
17457 /*
17458 ** Allocate nBytes of memory.
17459 */
17460 static void *memsys5Malloc(int nBytes){
17461 sqlite3_int64 *p = 0;
17462 if( nBytes>0 ){
17463 memsys5Enter();
@@ -74041,22 +74039,23 @@
74039 **
74040 ** The reason for suppressing the TK_AS term when the expression is a simple
74041 ** column reference is so that the column reference will be recognized as
74042 ** usable by indices within the WHERE clause processing logic.
74043 **
74044 ** The TK_AS operator is inhibited if zType[0]=='G'. This means
74045 ** that in a GROUP BY clause, the expression is evaluated twice. Hence:
74046 **
74047 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY x
74048 **
74049 ** Is equivalent to:
74050 **
74051 ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5
74052 **
74053 ** The result of random()%5 in the GROUP BY clause is probably different
74054 ** from the result in the result-set. On the other hand Standard SQL does
74055 ** not allow the GROUP BY clause to contain references to result-set columns.
74056 ** So this should never come up in well-formed queries.
74057 **
74058 ** If the reference is followed by a COLLATE operator, then make sure
74059 ** the COLLATE operator is preserved. For example:
74060 **
74061 ** SELECT a+b, c+d FROM t1 ORDER BY 1 COLLATE nocase;
@@ -74382,14 +74381,20 @@
74381 **
74382 ** In cases like this, replace pExpr with a copy of the expression that
74383 ** forms the result set entry ("a+b" in the example) and return immediately.
74384 ** Note that the expression in the result set should have already been
74385 ** resolved by the time the WHERE clause is resolved.
74386 **
74387 ** The ability to use an output result-set column in the WHERE, GROUP BY,
74388 ** or HAVING clauses, or as part of a larger expression in the ORDRE BY
74389 ** clause is not standard SQL. This is a (goofy) SQLite extension, that
74390 ** is supported for backwards compatibility only. TO DO: Issue a warning
74391 ** on sqlite3_log() whenever the capability is used.
74392 */
74393 if( (pEList = pNC->pEList)!=0
74394 && zTab==0
74395 && cnt==0
74396 ){
74397 for(j=0; j<pEList->nExpr; j++){
74398 char *zAs = pEList->a[j].zName;
74399 if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
74400 Expr *pOrig;
@@ -74947,11 +74952,11 @@
74952 }
74953
74954 /*
74955 ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of
74956 ** the SELECT statement pSelect. If any term is reference to a
74957 ** result set expression (as determined by the ExprList.a.iOrderByCol field)
74958 ** then convert that term into a copy of the corresponding result set
74959 ** column.
74960 **
74961 ** If any errors are detected, add an error message to pParse and
74962 ** return non-zero. Return zero if no errors are seen.
@@ -74995,11 +75000,11 @@
75000 **
75001 ** This routine resolves each term of the clause into an expression.
75002 ** If the order-by term is an integer I between 1 and N (where N is the
75003 ** number of columns in the result set of the SELECT) then the expression
75004 ** in the resolution is a copy of the I-th result-set expression. If
75005 ** the order-by term is an identifier that corresponds to the AS-name of
75006 ** a result-set expression, then the term resolves to a copy of the
75007 ** result-set expression. Otherwise, the expression is resolved in
75008 ** the usual way - using sqlite3ResolveExprNames().
75009 **
75010 ** This routine returns the number of errors. If errors occur, then
@@ -75021,20 +75026,23 @@
75026 if( pOrderBy==0 ) return 0;
75027 nResult = pSelect->pEList->nExpr;
75028 pParse = pNC->pParse;
75029 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
75030 Expr *pE = pItem->pExpr;
75031 Expr *pE2 = sqlite3ExprSkipCollate(pE);
75032 if( zType[0]!='G' ){
75033 iCol = resolveAsName(pParse, pSelect->pEList, pE2);
75034 if( iCol>0 ){
75035 /* If an AS-name match is found, mark this ORDER BY column as being
75036 ** a copy of the iCol-th result-set column. The subsequent call to
75037 ** sqlite3ResolveOrderGroupBy() will convert the expression to a
75038 ** copy of the iCol-th result-set expression. */
75039 pItem->iOrderByCol = (u16)iCol;
75040 continue;
75041 }
75042 }
75043 if( sqlite3ExprIsInteger(pE2, &iCol) ){
75044 /* The ORDER BY term is an integer constant. Again, set the column
75045 ** number so that sqlite3ResolveOrderGroupBy() will convert the
75046 ** order-by term to a copy of the result-set expression */
75047 if( iCol<1 || iCol>0xffff ){
75048 resolveOutOfRangeError(pParse, zType, i+1, nResult);
@@ -75173,23 +75181,21 @@
75181 if( p->pHaving && !pGroupBy ){
75182 sqlite3ErrorMsg(pParse, "a GROUP BY clause is required before HAVING");
75183 return WRC_Abort;
75184 }
75185
75186 /* Add the output column list to the name-context before parsing the
75187 ** other expressions in the SELECT statement. This is so that
75188 ** expressions in the WHERE clause (etc.) can refer to expressions by
75189 ** aliases in the result set.
75190 **
75191 ** Minor point: If this is the case, then the expression will be
75192 ** re-evaluated for each reference to it.
75193 */
75194 sNC.pEList = p->pEList;
 
75195 if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort;
75196 if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
 
75197
75198 /* The ORDER BY and GROUP BY clauses may not refer to terms in
75199 ** outer queries
75200 */
75201 sNC.pNext = 0;
@@ -77134,19 +77140,21 @@
77140 assert( !isRowid );
77141 sqlite3SelectDestInit(&dest, SRT_Set, pExpr->iTable);
77142 dest.affSdst = (u8)affinity;
77143 assert( (pExpr->iTable&0x0000FFFF)==pExpr->iTable );
77144 pExpr->x.pSelect->iLimit = 0;
77145 testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
77146 if( sqlite3Select(pParse, pExpr->x.pSelect, &dest) ){
77147 sqlite3DbFree(pParse->db, pKeyInfo);
77148 return 0;
77149 }
77150 pEList = pExpr->x.pSelect->pEList;
77151 assert( pKeyInfo!=0 ); /* OOM will cause exit after sqlite3Select() */
77152 assert( pEList!=0 );
77153 assert( pEList->nExpr>0 );
77154 pKeyInfo->aColl[0] = sqlite3BinaryCompareCollSeq(pParse, pExpr->pLeft,
77155 pEList->a[0].pExpr);
77156 }else if( ALWAYS(pExpr->x.pList!=0) ){
77157 /* Case 2: expr IN (exprlist)
77158 **
77159 ** For each expression, build an index key from the evaluation and
77160 ** store it in the temporary table. If <expr> is a column, then use
@@ -104711,11 +104719,11 @@
104719 # define WHERETRACE_ENABLED 1
104720 #else
104721 # define WHERETRACE(K,X)
104722 #endif
104723
104724 /* Forward references
104725 */
104726 typedef struct WhereClause WhereClause;
104727 typedef struct WhereMaskSet WhereMaskSet;
104728 typedef struct WhereOrInfo WhereOrInfo;
104729 typedef struct WhereAndInfo WhereAndInfo;
@@ -104733,18 +104741,19 @@
104741 ** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
104742 ** (Virtual tables can return a larger cost, but let's assume they do not.)
104743 ** So all costs can be stored in a 16-bit unsigned integer without risk
104744 ** of overflow.
104745 **
104746 ** Costs are estimates, so no effort is made to compute 10*log2(X) exactly.
104747 ** Instead, a close estimate is used. Any value of X<=1 is stored as 0.
104748 ** X=2 is 10. X=3 is 16. X=1000 is 99. etc.
104749 **
104750 ** The tool/wherecosttest.c source file implements a command-line program
104751 ** that will convert WhereCosts to integers, convert integers to WhereCosts
104752 ** and do addition and multiplication on WhereCost values. The wherecosttest
104753 ** command-line program is a useful utility to have around when working with
104754 ** this module.
104755 */
104756 typedef unsigned short int WhereCost;
104757
104758 /*
104759 ** This object contains information needed to implement a single nested
@@ -104843,12 +104852,12 @@
104852 WhereCost rRun; /* Cost of running this subquery */
104853 WhereCost nOut; /* Number of outputs for this subquery */
104854 };
104855
104856 /* The WhereOrSet object holds a set of possible WhereOrCosts that
104857 ** correspond to the subquery(s) of OR-clause processing. Only the
104858 ** best N_OR_COST elements are retained.
104859 */
104860 #define N_OR_COST 3
104861 struct WhereOrSet {
104862 u16 n; /* Number of valid a[] entries */
104863 WhereOrCost a[N_OR_COST]; /* Set of best costs */
@@ -104910,13 +104919,13 @@
104919 **
104920 ** A WhereTerm might also be two or more subterms connected by OR:
104921 **
104922 ** (t1.X <op> <expr>) OR (t1.Y <op> <expr>) OR ....
104923 **
104924 ** In this second case, wtFlag has the TERM_ORINFO bit set and eOperator==WO_OR
104925 ** and the WhereTerm.u.pOrInfo field points to auxiliary information that
104926 ** is collected about the OR clause.
104927 **
104928 ** If a term in the WHERE clause does not match either of the two previous
104929 ** categories, then eOperator==0. The WhereTerm.pExpr field is still set
104930 ** to the original subexpression content and wtFlags is set up appropriately
104931 ** but no other fields in the WhereTerm object are meaningful.
@@ -105424,11 +105433,11 @@
105433 assert( pMaskSet->n < ArraySize(pMaskSet->ix) );
105434 pMaskSet->ix[pMaskSet->n++] = iCursor;
105435 }
105436
105437 /*
105438 ** These routines walk (recursively) an expression tree and generate
105439 ** a bitmask indicating which tables are used in that expression
105440 ** tree.
105441 */
105442 static Bitmask exprListTableUsage(WhereMaskSet*, ExprList*);
105443 static Bitmask exprSelectTableUsage(WhereMaskSet*, Select*);
@@ -105941,14 +105950,14 @@
105950 ** u.pAndInfo set to a dynamically allocated WhereAndTerm object.
105951 **
105952 ** From another point of view, "indexable" means that the subterm could
105953 ** potentially be used with an index if an appropriate index exists.
105954 ** This analysis does not consider whether or not the index exists; that
105955 ** is decided elsewhere. This analysis only looks at whether subterms
105956 ** appropriate for indexing exist.
105957 **
105958 ** All examples A through E above satisfy case 2. But if a term
105959 ** also statisfies case 1 (such as B) we know that the optimizer will
105960 ** always prefer case 1, so in that case we pretend that case 2 is not
105961 ** satisfied.
105962 **
105963 ** It might be the case that multiple tables are indexable. For example,
@@ -106611,11 +106620,11 @@
106620
106621 return 0;
106622 }
106623
106624 /*
106625 ** Find (an approximate) sum of two WhereCosts. This computation is
106626 ** not a simple "+" operator because WhereCost is stored as a logarithmic
106627 ** value.
106628 **
106629 */
106630 static WhereCost whereCostAdd(WhereCost a, WhereCost b){
@@ -115614,10 +115623,13 @@
115623 ** without blocking.
115624 */
115625 SQLITE_API int sqlite3_initialize(void){
115626 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
115627 int rc; /* Result code */
115628 #ifdef SQLITE_EXTRA_INIT
115629 int bRunExtraInit = 0; /* Extra initialization needed */
115630 #endif
115631
115632 #ifdef SQLITE_OMIT_WSD
115633 rc = sqlite3_wsd_init(4096, 24);
115634 if( rc!=SQLITE_OK ){
115635 return rc;
@@ -115711,10 +115723,13 @@
115723 }
115724 if( rc==SQLITE_OK ){
115725 sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage,
115726 sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage);
115727 sqlite3GlobalConfig.isInit = 1;
115728 #ifdef SQLITE_EXTRA_INIT
115729 bRunExtraInit = 1;
115730 #endif
115731 }
115732 sqlite3GlobalConfig.inProgress = 0;
115733 }
115734 sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
115735
@@ -115751,11 +115766,11 @@
115766
115767 /* Do extra initialization steps requested by the SQLITE_EXTRA_INIT
115768 ** compile-time option.
115769 */
115770 #ifdef SQLITE_EXTRA_INIT
115771 if( bRunExtraInit ){
115772 int SQLITE_EXTRA_INIT(const char*);
115773 rc = SQLITE_EXTRA_INIT(0);
115774 }
115775 #endif
115776
@@ -115939,12 +115954,12 @@
115954 ** run.
115955 */
115956 memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m));
115957 }else{
115958 /* The heap pointer is not NULL, then install one of the
115959 ** mem5.c/mem3.c methods. The enclosing #if guarantees at
115960 ** least one of these methods is currently enabled.
115961 */
115962 #ifdef SQLITE_ENABLE_MEMSYS3
115963 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3();
115964 #endif
115965 #ifdef SQLITE_ENABLE_MEMSYS5
@@ -115959,11 +115974,11 @@
115974 sqlite3GlobalConfig.szLookaside = va_arg(ap, int);
115975 sqlite3GlobalConfig.nLookaside = va_arg(ap, int);
115976 break;
115977 }
115978
115979 /* Record a pointer to the logger function and its first argument.
115980 ** The default is NULL. Logging is disabled if the function pointer is
115981 ** NULL.
115982 */
115983 case SQLITE_CONFIG_LOG: {
115984 /* MSVC is picky about pulling func ptrs from va lists.
@@ -117675,24 +117690,24 @@
117690
117691 for(iIn=0; iIn<nUri; iIn++) nByte += (zUri[iIn]=='&');
117692 zFile = sqlite3_malloc(nByte);
117693 if( !zFile ) return SQLITE_NOMEM;
117694
117695 iIn = 5;
117696 #ifndef SQLITE_ALLOW_URI_AUTHORITY
117697 /* Discard the scheme and authority segments of the URI. */
117698 if( zUri[5]=='/' && zUri[6]=='/' ){
117699 iIn = 7;
117700 while( zUri[iIn] && zUri[iIn]!='/' ) iIn++;
 
117701 if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){
117702 *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s",
117703 iIn-7, &zUri[7]);
117704 rc = SQLITE_ERROR;
117705 goto parse_uri_out;
117706 }
 
 
117707 }
117708 #endif
117709
117710 /* Copy the filename and any query parameters into the zFile buffer.
117711 ** Decode %HH escape codes along the way.
117712 **
117713 ** Within this loop, variable eState may be set to 0, 1 or 2, depending
117714
+2 -2
--- 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.0"
111111
#define SQLITE_VERSION_NUMBER 3008000
112
-#define SQLITE_SOURCE_ID "2013-08-06 07:45:08 924f7e4d7a8fa2fe9100836663f3733b6e1a9084"
112
+#define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -7231,11 +7231,11 @@
72317231
#endif
72327232
72337233
#ifdef __cplusplus
72347234
} /* End of the 'extern "C"' block */
72357235
#endif
7236
-#endif
7236
+#endif /* _SQLITE3_H_ */
72377237
72387238
/*
72397239
** 2010 August 30
72407240
**
72417241
** The author disclaims copyright to this source code. In place of
72427242
--- 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.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-08-06 07:45:08 924f7e4d7a8fa2fe9100836663f3733b6e1a9084"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -7231,11 +7231,11 @@
7231 #endif
7232
7233 #ifdef __cplusplus
7234 } /* End of the 'extern "C"' block */
7235 #endif
7236 #endif
7237
7238 /*
7239 ** 2010 August 30
7240 **
7241 ** The author disclaims copyright to this source code. In place of
7242
--- 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.0"
111 #define SQLITE_VERSION_NUMBER 3008000
112 #define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -7231,11 +7231,11 @@
7231 #endif
7232
7233 #ifdef __cplusplus
7234 } /* End of the 'extern "C"' block */
7235 #endif
7236 #endif /* _SQLITE3_H_ */
7237
7238 /*
7239 ** 2010 August 30
7240 **
7241 ** The author disclaims copyright to this source code. In place of
7242

Keyboard Shortcuts

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