Fossil SCM

Update the built-in SQLite to 3.12.0 final.

drh 2016-03-29 10:38 trunk
Commit 996705f5aa7c643bd4e8a008888ab3ec9dc86f4a
2 files changed +95 -56 +1 -1
+95 -56
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -336,11 +336,11 @@
336336
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
337337
** [sqlite_version()] and [sqlite_source_id()].
338338
*/
339339
#define SQLITE_VERSION "3.12.0"
340340
#define SQLITE_VERSION_NUMBER 3012000
341
-#define SQLITE_SOURCE_ID "2016-03-22 15:26:03 142cd359d37f1d8d53de32e329523d9a93c7d6e5"
341
+#define SQLITE_SOURCE_ID "2016-03-29 10:14:15 e9bb4cf40f4971974a74468ef922bdee481c988b"
342342
343343
/*
344344
** CAPI3REF: Run-Time Library Version Numbers
345345
** KEYWORDS: sqlite3_version, sqlite3_sourceid
346346
**
@@ -9071,12 +9071,12 @@
90719071
90729072
/*
90739073
** The suggested maximum number of in-memory pages to use for
90749074
** the main database table and for temporary tables.
90759075
**
9076
-** IMPLEMENTATION-OF: R-31093-59126 The default suggested cache size
9077
-** is 2000*1024 bytes.
9076
+** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000,
9077
+** which means the cache size is limited to 2048000 bytes of memory.
90789078
** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
90799079
** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
90809080
*/
90819081
#ifndef SQLITE_DEFAULT_CACHE_SIZE
90829082
# define SQLITE_DEFAULT_CACHE_SIZE -2000
@@ -12538,10 +12538,11 @@
1253812538
1253912539
/* Allowed values for Column.colFlags:
1254012540
*/
1254112541
#define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
1254212542
#define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
12543
+#define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */
1254312544
1254412545
/*
1254512546
** A "Collating Sequence" is defined by an instance of the following
1254612547
** structure. Conceptually, a collating sequence consists of a name and
1254712548
** a comparison routine that defines the order of that sequence.
@@ -14241,11 +14242,11 @@
1424114242
/*
1424214243
** Internal function prototypes
1424314244
*/
1424414245
SQLITE_PRIVATE int sqlite3StrICmp(const char*,const char*);
1424514246
SQLITE_PRIVATE int sqlite3Strlen30(const char*);
14246
-SQLITE_PRIVATE const char *sqlite3StrNext(const char*);
14247
+SQLITE_PRIVATE char *sqlite3ColumnType(Column*,char*);
1424714248
#define sqlite3StrNICmp sqlite3_strnicmp
1424814249
1424914250
SQLITE_PRIVATE int sqlite3MallocInit(void);
1425014251
SQLITE_PRIVATE void sqlite3MallocEnd(void);
1425114252
SQLITE_PRIVATE void *sqlite3Malloc(u64);
@@ -25497,15 +25498,19 @@
2549725498
if( z==0 ) return 0;
2549825499
return 0x3fffffff & (int)strlen(z);
2549925500
}
2550025501
2550125502
/*
25502
-** The string z[] is followed immediately by another string. Return
25503
-** a poiner to that other string.
25503
+** Return the declared type of a column. Or return zDflt if the column
25504
+** has no declared type.
25505
+**
25506
+** The column type is an extra string stored after the zero-terminator on
25507
+** the column name if and only if the COLFLAG_HASTYPE flag is set.
2550425508
*/
25505
-SQLITE_PRIVATE const char *sqlite3StrNext(const char *z){
25506
- return z + strlen(z) + 1;
25509
+SQLITE_PRIVATE char *sqlite3ColumnType(Column *pCol, char *zDflt){
25510
+ if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt;
25511
+ return pCol->zName + strlen(pCol->zName) + 1;
2550725512
}
2550825513
2550925514
/*
2551025515
** Helper function for sqlite3Error() - called rarely. Broken out into
2551125516
** a separate routine to avoid unnecessary register saves on entry to
@@ -35627,15 +35632,27 @@
3562735632
*/
3562835633
#ifndef SQLITE_WIN32_HEAP_CREATE
3562935634
# define SQLITE_WIN32_HEAP_CREATE (TRUE)
3563035635
#endif
3563135636
35637
+/*
35638
+ * This is cache size used in the calculation of the initial size of the
35639
+ * Win32-specific heap. It cannot be negative.
35640
+ */
35641
+#ifndef SQLITE_WIN32_CACHE_SIZE
35642
+# if SQLITE_DEFAULT_CACHE_SIZE>=0
35643
+# define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
35644
+# else
35645
+# define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
35646
+# endif
35647
+#endif
35648
+
3563235649
/*
3563335650
* The initial size of the Win32-specific heap. This value may be zero.
3563435651
*/
3563535652
#ifndef SQLITE_WIN32_HEAP_INIT_SIZE
35636
-# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \
35653
+# define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
3563735654
(SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
3563835655
#endif
3563935656
3564035657
/*
3564135658
* The maximum size of the Win32-specific heap. This value may be zero.
@@ -40707,11 +40724,11 @@
4070740724
return nBuf;
4070840725
#else
4070940726
EntropyGatherer e;
4071040727
UNUSED_PARAMETER(pVfs);
4071140728
memset(zBuf, 0, nBuf);
40712
-#if defined(_MSC_VER) && _MSC_VER>=1400
40729
+#if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE
4071340730
rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */
4071440731
#endif /* defined(_MSC_VER) && _MSC_VER>=1400 */
4071540732
e.a = (unsigned char*)zBuf;
4071640733
e.na = nBuf;
4071740734
e.nXor = 0;
@@ -76978,23 +76995,25 @@
7697876995
pC->aType[i++] = t;
7697976996
aOffset[i] = (u32)(offset64 & 0xffffffff);
7698076997
}while( i<=p2 && zHdr<zEndHdr );
7698176998
pC->nHdrParsed = i;
7698276999
pC->iHdrOffset = (u32)(zHdr - zData);
76983
- if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
7698477000
7698577001
/* The record is corrupt if any of the following are true:
7698677002
** (1) the bytes of the header extend past the declared header size
7698777003
** (2) the entire header was used but not all data was used
7698877004
** (3) the end of the data extends beyond the end of the record.
7698977005
*/
7699077006
if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
7699177007
|| (offset64 > pC->payloadSize)
7699277008
){
77009
+ if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
7699377010
rc = SQLITE_CORRUPT_BKPT;
7699477011
goto abort_due_to_error;
7699577012
}
77013
+ if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
77014
+
7699677015
}else{
7699777016
t = 0;
7699877017
}
7699977018
7700077019
/* If after trying to extract new entries from the header, nHdrParsed is
@@ -95509,13 +95528,10 @@
9550995528
z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
9551095529
if( z==0 ) return;
9551195530
memcpy(z, pName->z, pName->n);
9551295531
z[pName->n] = 0;
9551395532
sqlite3Dequote(z);
95514
- zType = z + sqlite3Strlen30(z) + 1;
95515
- memcpy(zType, pType->z, pType->n);
95516
- zType[pType->n] = 0;
9551795533
for(i=0; i<p->nCol; i++){
9551895534
if( sqlite3_stricmp(z, p->aCol[i].zName)==0 ){
9551995535
sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
9552095536
sqlite3DbFree(db, z);
9552195537
return;
@@ -95539,11 +95555,15 @@
9553995555
/* If there is no type specified, columns have the default affinity
9554095556
** 'BLOB'. */
9554195557
pCol->affinity = SQLITE_AFF_BLOB;
9554295558
pCol->szEst = 1;
9554395559
}else{
95560
+ zType = z + sqlite3Strlen30(z) + 1;
95561
+ memcpy(zType, pType->z, pType->n);
95562
+ zType[pType->n] = 0;
9554495563
pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
95564
+ pCol->colFlags |= COLFLAG_HASTYPE;
9554595565
}
9554695566
p->nCol++;
9554795567
pParse->constraintName.n = 0;
9554895568
}
9554995569
@@ -95735,11 +95755,11 @@
9573595755
int onError, /* What to do with a uniqueness conflict */
9573695756
int autoInc, /* True if the AUTOINCREMENT keyword is present */
9573795757
int sortOrder /* SQLITE_SO_ASC or SQLITE_SO_DESC */
9573895758
){
9573995759
Table *pTab = pParse->pNewTable;
95740
- const char *zName = 0;
95760
+ Column *pCol = 0;
9574195761
int iCol = -1, i;
9574295762
int nTerm;
9574395763
if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
9574495764
if( pTab->tabFlags & TF_HasPrimaryKey ){
9574595765
sqlite3ErrorMsg(pParse,
@@ -95747,12 +95767,12 @@
9574795767
goto primary_key_exit;
9574895768
}
9574995769
pTab->tabFlags |= TF_HasPrimaryKey;
9575095770
if( pList==0 ){
9575195771
iCol = pTab->nCol - 1;
95752
- pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
95753
- zName = pTab->aCol[iCol].zName;
95772
+ pCol = &pTab->aCol[iCol];
95773
+ pCol->colFlags |= COLFLAG_PRIMKEY;
9575495774
nTerm = 1;
9575595775
}else{
9575695776
nTerm = pList->nExpr;
9575795777
for(i=0; i<nTerm; i++){
9575895778
Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
@@ -95760,21 +95780,21 @@
9576095780
sqlite3StringToId(pCExpr);
9576195781
if( pCExpr->op==TK_ID ){
9576295782
const char *zCName = pCExpr->u.zToken;
9576395783
for(iCol=0; iCol<pTab->nCol; iCol++){
9576495784
if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
95765
- pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
95766
- zName = pTab->aCol[iCol].zName;
95785
+ pCol = &pTab->aCol[iCol];
95786
+ pCol->colFlags |= COLFLAG_PRIMKEY;
9576795787
break;
9576895788
}
9576995789
}
9577095790
}
9577195791
}
9577295792
}
9577395793
if( nTerm==1
95774
- && zName
95775
- && sqlite3StrICmp(sqlite3StrNext(zName), "INTEGER")==0
95794
+ && pCol
95795
+ && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
9577695796
&& sortOrder!=SQLITE_SO_DESC
9577795797
){
9577895798
pTab->iPKey = iCol;
9577995799
pTab->keyConf = (u8)onError;
9578095800
assert( autoInc==0 || autoInc==1 );
@@ -108679,11 +108699,10 @@
108679108699
pParse->nMem = 6;
108680108700
sqlite3CodeVerifySchema(pParse, iDb);
108681108701
setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
108682108702
sqlite3ViewGetColumnNames(pParse, pTab);
108683108703
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
108684
- const char *zName;
108685108704
if( IsHiddenColumn(pCol) ){
108686108705
nHidden++;
108687108706
continue;
108688108707
}
108689108708
if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
@@ -108692,15 +108711,14 @@
108692108711
k = 1;
108693108712
}else{
108694108713
for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
108695108714
}
108696108715
assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN );
108697
- zName = pCol->zName;
108698108716
sqlite3VdbeMultiLoad(v, 1, "issisi",
108699108717
i-nHidden,
108700
- zName,
108701
- sqlite3StrNext(zName),
108718
+ pCol->zName,
108719
+ sqlite3ColumnType(pCol,""),
108702108720
pCol->notNull ? 1 : 0,
108703108721
pCol->pDflt ? pCol->pDflt->u.zToken : 0,
108704108722
k);
108705108723
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
108706108724
}
@@ -111899,11 +111917,11 @@
111899111917
if( iCol<0 ){
111900111918
zType = "INTEGER";
111901111919
zOrigCol = "rowid";
111902111920
}else{
111903111921
zOrigCol = pTab->aCol[iCol].zName;
111904
- zType = sqlite3StrNext(zOrigCol);
111922
+ zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
111905111923
estWidth = pTab->aCol[iCol].szEst;
111906111924
}
111907111925
zOrigTab = pTab->zName;
111908111926
if( pNC->pParse ){
111909111927
int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
@@ -111911,11 +111929,11 @@
111911111929
}
111912111930
#else
111913111931
if( iCol<0 ){
111914111932
zType = "INTEGER";
111915111933
}else{
111916
- zType = sqlite3StrNext(pTab->aCol[iCol].zName);
111934
+ zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
111917111935
estWidth = pTab->aCol[iCol].szEst;
111918111936
}
111919111937
#endif
111920111938
}
111921111939
break;
@@ -119190,26 +119208,20 @@
119190119208
** the type string. */
119191119209
pVTable->pNext = pTab->pVTable;
119192119210
pTab->pVTable = pVTable;
119193119211
119194119212
for(iCol=0; iCol<pTab->nCol; iCol++){
119195
- char *zType = (char*)sqlite3StrNext(pTab->aCol[iCol].zName);
119213
+ char *zType = sqlite3ColumnType(&pTab->aCol[iCol], "");
119196119214
int nType;
119197119215
int i = 0;
119198
- if( !zType[0] ){
119199
- pTab->tabFlags |= oooHidden;
119200
- continue;
119201
- }
119202119216
nType = sqlite3Strlen30(zType);
119203
- if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
119204
- for(i=0; i<nType; i++){
119205
- if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
119206
- && (zType[i+7]=='\0' || zType[i+7]==' ')
119207
- ){
119208
- i++;
119209
- break;
119210
- }
119217
+ for(i=0; i<nType; i++){
119218
+ if( 0==sqlite3StrNICmp("hidden", &zType[i], 6)
119219
+ && (i==0 || zType[i-1]==' ')
119220
+ && (zType[i+6]=='\0' || zType[i+6]==' ')
119221
+ ){
119222
+ break;
119211119223
}
119212119224
}
119213119225
if( i<nType ){
119214119226
int j;
119215119227
int nDel = 6 + (zType[i+6] ? 1 : 0);
@@ -136523,12 +136535,11 @@
136523136535
**
136524136536
** 2. The table is not a view and the column name identified an
136525136537
** explicitly declared column. Copy meta information from *pCol.
136526136538
*/
136527136539
if( pCol ){
136528
- zDataType = sqlite3StrNext(pCol->zName);
136529
- if( zDataType[0]==0 ) zDataType = 0;
136540
+ zDataType = sqlite3ColumnType(pCol,0);
136530136541
zCollSeq = pCol->zColl;
136531136542
notnull = pCol->notNull!=0;
136532136543
primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
136533136544
autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
136534136545
}else{
@@ -169247,10 +169258,14 @@
169247169258
# define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
169248169259
# define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
169249169260
169250169261
#endif
169251169262
169263
+/* Truncate very long tokens to this many bytes. Hard limit is
169264
+** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
169265
+** field that occurs at the start of each leaf page (see fts5_index.c). */
169266
+#define FTS5_MAX_TOKEN_SIZE 32768
169252169267
169253169268
/*
169254169269
** Maximum number of prefix indexes on single FTS5 table. This must be
169255169270
** less than 32. If it is set to anything large than that, an #error
169256169271
** directive in fts5_index.c will cause the build to fail.
@@ -174637,10 +174652,11 @@
174637174652
174638174653
UNUSED_PARAM2(iUnused1, iUnused2);
174639174654
174640174655
/* If an error has already occurred, this is a no-op */
174641174656
if( pCtx->rc!=SQLITE_OK ) return pCtx->rc;
174657
+ if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
174642174658
174643174659
if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
174644174660
Fts5ExprTerm *pSyn;
174645174661
int nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
174646174662
pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte);
@@ -175639,10 +175655,11 @@
175639175655
Fts5Expr *pExpr = p->pExpr;
175640175656
int i;
175641175657
175642175658
UNUSED_PARAM2(iUnused1, iUnused2);
175643175659
175660
+ if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
175644175661
if( (tflags & FTS5_TOKEN_COLOCATED)==0 ) p->iOff++;
175645175662
for(i=0; i<pExpr->nPhrase; i++){
175646175663
Fts5ExprTerm *pTerm;
175647175664
if( p->aPopulator[i].bOk==0 ) continue;
175648175665
for(pTerm=&pExpr->apExprPhrase[i]->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
@@ -178648,10 +178665,22 @@
178648178665
pIter->iPgidxOff = iPgidx;
178649178666
178650178667
fts5SegIterLoadRowid(p, pIter);
178651178668
fts5SegIterLoadNPos(p, pIter);
178652178669
}
178670
+
178671
+static sqlite3_stmt *fts5IdxSelectStmt(Fts5Index *p){
178672
+ if( p->pIdxSelect==0 ){
178673
+ Fts5Config *pConfig = p->pConfig;
178674
+ fts5IndexPrepareStmt(p, &p->pIdxSelect, sqlite3_mprintf(
178675
+ "SELECT pgno FROM '%q'.'%q_idx' WHERE "
178676
+ "segid=? AND term<=? ORDER BY term DESC LIMIT 1",
178677
+ pConfig->zDb, pConfig->zName
178678
+ ));
178679
+ }
178680
+ return p->pIdxSelect;
178681
+}
178653178682
178654178683
/*
178655178684
** Initialize the object pIter to point to term pTerm/nTerm within segment
178656178685
** pSeg. If there is no such term in the index, the iterator is set to EOF.
178657178686
**
@@ -178666,35 +178695,29 @@
178666178695
Fts5SegIter *pIter /* Object to populate */
178667178696
){
178668178697
int iPg = 1;
178669178698
int bGe = (flags & FTS5INDEX_QUERY_SCAN);
178670178699
int bDlidx = 0; /* True if there is a doclist-index */
178700
+ sqlite3_stmt *pIdxSelect = 0;
178671178701
178672178702
assert( bGe==0 || (flags & FTS5INDEX_QUERY_DESC)==0 );
178673178703
assert( pTerm && nTerm );
178674178704
memset(pIter, 0, sizeof(*pIter));
178675178705
pIter->pSeg = pSeg;
178676178706
178677178707
/* This block sets stack variable iPg to the leaf page number that may
178678178708
** contain term (pTerm/nTerm), if it is present in the segment. */
178679
- if( p->pIdxSelect==0 ){
178680
- Fts5Config *pConfig = p->pConfig;
178681
- fts5IndexPrepareStmt(p, &p->pIdxSelect, sqlite3_mprintf(
178682
- "SELECT pgno FROM '%q'.'%q_idx' WHERE "
178683
- "segid=? AND term<=? ORDER BY term DESC LIMIT 1",
178684
- pConfig->zDb, pConfig->zName
178685
- ));
178686
- }
178709
+ pIdxSelect = fts5IdxSelectStmt(p);
178687178710
if( p->rc ) return;
178688
- sqlite3_bind_int(p->pIdxSelect, 1, pSeg->iSegid);
178689
- sqlite3_bind_blob(p->pIdxSelect, 2, pTerm, nTerm, SQLITE_STATIC);
178690
- if( SQLITE_ROW==sqlite3_step(p->pIdxSelect) ){
178691
- i64 val = sqlite3_column_int(p->pIdxSelect, 0);
178711
+ sqlite3_bind_int(pIdxSelect, 1, pSeg->iSegid);
178712
+ sqlite3_bind_blob(pIdxSelect, 2, pTerm, nTerm, SQLITE_STATIC);
178713
+ if( SQLITE_ROW==sqlite3_step(pIdxSelect) ){
178714
+ i64 val = sqlite3_column_int(pIdxSelect, 0);
178692178715
iPg = (int)(val>>1);
178693178716
bDlidx = (val & 0x0001);
178694178717
}
178695
- p->rc = sqlite3_reset(p->pIdxSelect);
178718
+ p->rc = sqlite3_reset(pIdxSelect);
178696178719
178697178720
if( iPg<pSeg->pgnoFirst ){
178698178721
iPg = pSeg->pgnoFirst;
178699178722
bDlidx = 0;
178700178723
}
@@ -179880,10 +179903,21 @@
179880179903
for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
179881179904
assert( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
179882179905
}
179883179906
}
179884179907
assert( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
179908
+
179909
+ {
179910
+ sqlite3_stmt *pIdxSelect = fts5IdxSelectStmt(p);
179911
+ if( p->rc==SQLITE_OK ){
179912
+ u8 aBlob[2] = {0xff, 0xff};
179913
+ sqlite3_bind_int(pIdxSelect, 1, iSegid);
179914
+ sqlite3_bind_blob(pIdxSelect, 2, aBlob, 2, SQLITE_STATIC);
179915
+ assert( sqlite3_step(pIdxSelect)!=SQLITE_ROW );
179916
+ p->rc = sqlite3_reset(pIdxSelect);
179917
+ }
179918
+ }
179885179919
#endif
179886179920
}
179887179921
}
179888179922
179889179923
return iSegid;
@@ -180125,10 +180159,13 @@
180125180159
180126180160
static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
180127180161
static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
180128180162
Fts5PageWriter *pPage = &pWriter->writer;
180129180163
i64 iRowid;
180164
+
180165
+static int nCall = 0;
180166
+nCall++;
180130180167
180131180168
assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
180132180169
180133180170
/* Set the szLeaf header field. */
180134180171
assert( 0==fts5GetU16(&pPage->buf.p[2]) );
@@ -185385,11 +185422,11 @@
185385185422
int nArg, /* Number of args */
185386185423
sqlite3_value **apUnused /* Function arguments */
185387185424
){
185388185425
assert( nArg==0 );
185389185426
UNUSED_PARAM2(nArg, apUnused);
185390
- sqlite3_result_text(pCtx, "fts5: 2016-03-22 15:01:54 e1ab2d376a72786098125a41c1ea8140fcbd15c6", -1, SQLITE_TRANSIENT);
185427
+ sqlite3_result_text(pCtx, "fts5: 2016-03-29 10:14:15 e9bb4cf40f4971974a74468ef922bdee481c988b", -1, SQLITE_TRANSIENT);
185391185428
}
185392185429
185393185430
static int fts5Init(sqlite3 *db){
185394185431
static const sqlite3_module fts5Mod = {
185395185432
/* iVersion */ 2,
@@ -185872,10 +185909,11 @@
185872185909
int iUnused2 /* End offset of token */
185873185910
){
185874185911
Fts5InsertCtx *pCtx = (Fts5InsertCtx*)pContext;
185875185912
Fts5Index *pIdx = pCtx->pStorage->pIndex;
185876185913
UNUSED_PARAM2(iUnused1, iUnused2);
185914
+ if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
185877185915
if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
185878185916
pCtx->szCol++;
185879185917
}
185880185918
return sqlite3Fts5IndexWrite(pIdx, pCtx->iCol, pCtx->szCol-1, pToken, nToken);
185881185919
}
@@ -186318,10 +186356,11 @@
186318186356
int rc = SQLITE_OK;
186319186357
int iPos;
186320186358
int iCol;
186321186359
186322186360
UNUSED_PARAM2(iUnused1, iUnused2);
186361
+ if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
186323186362
186324186363
if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
186325186364
pCtx->szCol++;
186326186365
}
186327186366
186328186367
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -336,11 +336,11 @@
336 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
337 ** [sqlite_version()] and [sqlite_source_id()].
338 */
339 #define SQLITE_VERSION "3.12.0"
340 #define SQLITE_VERSION_NUMBER 3012000
341 #define SQLITE_SOURCE_ID "2016-03-22 15:26:03 142cd359d37f1d8d53de32e329523d9a93c7d6e5"
342
343 /*
344 ** CAPI3REF: Run-Time Library Version Numbers
345 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
346 **
@@ -9071,12 +9071,12 @@
9071
9072 /*
9073 ** The suggested maximum number of in-memory pages to use for
9074 ** the main database table and for temporary tables.
9075 **
9076 ** IMPLEMENTATION-OF: R-31093-59126 The default suggested cache size
9077 ** is 2000*1024 bytes.
9078 ** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
9079 ** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
9080 */
9081 #ifndef SQLITE_DEFAULT_CACHE_SIZE
9082 # define SQLITE_DEFAULT_CACHE_SIZE -2000
@@ -12538,10 +12538,11 @@
12538
12539 /* Allowed values for Column.colFlags:
12540 */
12541 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
12542 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
 
12543
12544 /*
12545 ** A "Collating Sequence" is defined by an instance of the following
12546 ** structure. Conceptually, a collating sequence consists of a name and
12547 ** a comparison routine that defines the order of that sequence.
@@ -14241,11 +14242,11 @@
14241 /*
14242 ** Internal function prototypes
14243 */
14244 SQLITE_PRIVATE int sqlite3StrICmp(const char*,const char*);
14245 SQLITE_PRIVATE int sqlite3Strlen30(const char*);
14246 SQLITE_PRIVATE const char *sqlite3StrNext(const char*);
14247 #define sqlite3StrNICmp sqlite3_strnicmp
14248
14249 SQLITE_PRIVATE int sqlite3MallocInit(void);
14250 SQLITE_PRIVATE void sqlite3MallocEnd(void);
14251 SQLITE_PRIVATE void *sqlite3Malloc(u64);
@@ -25497,15 +25498,19 @@
25497 if( z==0 ) return 0;
25498 return 0x3fffffff & (int)strlen(z);
25499 }
25500
25501 /*
25502 ** The string z[] is followed immediately by another string. Return
25503 ** a poiner to that other string.
 
 
 
25504 */
25505 SQLITE_PRIVATE const char *sqlite3StrNext(const char *z){
25506 return z + strlen(z) + 1;
 
25507 }
25508
25509 /*
25510 ** Helper function for sqlite3Error() - called rarely. Broken out into
25511 ** a separate routine to avoid unnecessary register saves on entry to
@@ -35627,15 +35632,27 @@
35627 */
35628 #ifndef SQLITE_WIN32_HEAP_CREATE
35629 # define SQLITE_WIN32_HEAP_CREATE (TRUE)
35630 #endif
35631
 
 
 
 
 
 
 
 
 
 
 
 
35632 /*
35633 * The initial size of the Win32-specific heap. This value may be zero.
35634 */
35635 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE
35636 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_DEFAULT_CACHE_SIZE) * \
35637 (SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
35638 #endif
35639
35640 /*
35641 * The maximum size of the Win32-specific heap. This value may be zero.
@@ -40707,11 +40724,11 @@
40707 return nBuf;
40708 #else
40709 EntropyGatherer e;
40710 UNUSED_PARAMETER(pVfs);
40711 memset(zBuf, 0, nBuf);
40712 #if defined(_MSC_VER) && _MSC_VER>=1400
40713 rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */
40714 #endif /* defined(_MSC_VER) && _MSC_VER>=1400 */
40715 e.a = (unsigned char*)zBuf;
40716 e.na = nBuf;
40717 e.nXor = 0;
@@ -76978,23 +76995,25 @@
76978 pC->aType[i++] = t;
76979 aOffset[i] = (u32)(offset64 & 0xffffffff);
76980 }while( i<=p2 && zHdr<zEndHdr );
76981 pC->nHdrParsed = i;
76982 pC->iHdrOffset = (u32)(zHdr - zData);
76983 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
76984
76985 /* The record is corrupt if any of the following are true:
76986 ** (1) the bytes of the header extend past the declared header size
76987 ** (2) the entire header was used but not all data was used
76988 ** (3) the end of the data extends beyond the end of the record.
76989 */
76990 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
76991 || (offset64 > pC->payloadSize)
76992 ){
 
76993 rc = SQLITE_CORRUPT_BKPT;
76994 goto abort_due_to_error;
76995 }
 
 
76996 }else{
76997 t = 0;
76998 }
76999
77000 /* If after trying to extract new entries from the header, nHdrParsed is
@@ -95509,13 +95528,10 @@
95509 z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
95510 if( z==0 ) return;
95511 memcpy(z, pName->z, pName->n);
95512 z[pName->n] = 0;
95513 sqlite3Dequote(z);
95514 zType = z + sqlite3Strlen30(z) + 1;
95515 memcpy(zType, pType->z, pType->n);
95516 zType[pType->n] = 0;
95517 for(i=0; i<p->nCol; i++){
95518 if( sqlite3_stricmp(z, p->aCol[i].zName)==0 ){
95519 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
95520 sqlite3DbFree(db, z);
95521 return;
@@ -95539,11 +95555,15 @@
95539 /* If there is no type specified, columns have the default affinity
95540 ** 'BLOB'. */
95541 pCol->affinity = SQLITE_AFF_BLOB;
95542 pCol->szEst = 1;
95543 }else{
 
 
 
95544 pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
 
95545 }
95546 p->nCol++;
95547 pParse->constraintName.n = 0;
95548 }
95549
@@ -95735,11 +95755,11 @@
95735 int onError, /* What to do with a uniqueness conflict */
95736 int autoInc, /* True if the AUTOINCREMENT keyword is present */
95737 int sortOrder /* SQLITE_SO_ASC or SQLITE_SO_DESC */
95738 ){
95739 Table *pTab = pParse->pNewTable;
95740 const char *zName = 0;
95741 int iCol = -1, i;
95742 int nTerm;
95743 if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
95744 if( pTab->tabFlags & TF_HasPrimaryKey ){
95745 sqlite3ErrorMsg(pParse,
@@ -95747,12 +95767,12 @@
95747 goto primary_key_exit;
95748 }
95749 pTab->tabFlags |= TF_HasPrimaryKey;
95750 if( pList==0 ){
95751 iCol = pTab->nCol - 1;
95752 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
95753 zName = pTab->aCol[iCol].zName;
95754 nTerm = 1;
95755 }else{
95756 nTerm = pList->nExpr;
95757 for(i=0; i<nTerm; i++){
95758 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
@@ -95760,21 +95780,21 @@
95760 sqlite3StringToId(pCExpr);
95761 if( pCExpr->op==TK_ID ){
95762 const char *zCName = pCExpr->u.zToken;
95763 for(iCol=0; iCol<pTab->nCol; iCol++){
95764 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
95765 pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
95766 zName = pTab->aCol[iCol].zName;
95767 break;
95768 }
95769 }
95770 }
95771 }
95772 }
95773 if( nTerm==1
95774 && zName
95775 && sqlite3StrICmp(sqlite3StrNext(zName), "INTEGER")==0
95776 && sortOrder!=SQLITE_SO_DESC
95777 ){
95778 pTab->iPKey = iCol;
95779 pTab->keyConf = (u8)onError;
95780 assert( autoInc==0 || autoInc==1 );
@@ -108679,11 +108699,10 @@
108679 pParse->nMem = 6;
108680 sqlite3CodeVerifySchema(pParse, iDb);
108681 setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
108682 sqlite3ViewGetColumnNames(pParse, pTab);
108683 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
108684 const char *zName;
108685 if( IsHiddenColumn(pCol) ){
108686 nHidden++;
108687 continue;
108688 }
108689 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
@@ -108692,15 +108711,14 @@
108692 k = 1;
108693 }else{
108694 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
108695 }
108696 assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN );
108697 zName = pCol->zName;
108698 sqlite3VdbeMultiLoad(v, 1, "issisi",
108699 i-nHidden,
108700 zName,
108701 sqlite3StrNext(zName),
108702 pCol->notNull ? 1 : 0,
108703 pCol->pDflt ? pCol->pDflt->u.zToken : 0,
108704 k);
108705 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
108706 }
@@ -111899,11 +111917,11 @@
111899 if( iCol<0 ){
111900 zType = "INTEGER";
111901 zOrigCol = "rowid";
111902 }else{
111903 zOrigCol = pTab->aCol[iCol].zName;
111904 zType = sqlite3StrNext(zOrigCol);
111905 estWidth = pTab->aCol[iCol].szEst;
111906 }
111907 zOrigTab = pTab->zName;
111908 if( pNC->pParse ){
111909 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
@@ -111911,11 +111929,11 @@
111911 }
111912 #else
111913 if( iCol<0 ){
111914 zType = "INTEGER";
111915 }else{
111916 zType = sqlite3StrNext(pTab->aCol[iCol].zName);
111917 estWidth = pTab->aCol[iCol].szEst;
111918 }
111919 #endif
111920 }
111921 break;
@@ -119190,26 +119208,20 @@
119190 ** the type string. */
119191 pVTable->pNext = pTab->pVTable;
119192 pTab->pVTable = pVTable;
119193
119194 for(iCol=0; iCol<pTab->nCol; iCol++){
119195 char *zType = (char*)sqlite3StrNext(pTab->aCol[iCol].zName);
119196 int nType;
119197 int i = 0;
119198 if( !zType[0] ){
119199 pTab->tabFlags |= oooHidden;
119200 continue;
119201 }
119202 nType = sqlite3Strlen30(zType);
119203 if( sqlite3StrNICmp("hidden", zType, 6)||(zType[6] && zType[6]!=' ') ){
119204 for(i=0; i<nType; i++){
119205 if( (0==sqlite3StrNICmp(" hidden", &zType[i], 7))
119206 && (zType[i+7]=='\0' || zType[i+7]==' ')
119207 ){
119208 i++;
119209 break;
119210 }
119211 }
119212 }
119213 if( i<nType ){
119214 int j;
119215 int nDel = 6 + (zType[i+6] ? 1 : 0);
@@ -136523,12 +136535,11 @@
136523 **
136524 ** 2. The table is not a view and the column name identified an
136525 ** explicitly declared column. Copy meta information from *pCol.
136526 */
136527 if( pCol ){
136528 zDataType = sqlite3StrNext(pCol->zName);
136529 if( zDataType[0]==0 ) zDataType = 0;
136530 zCollSeq = pCol->zColl;
136531 notnull = pCol->notNull!=0;
136532 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
136533 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
136534 }else{
@@ -169247,10 +169258,14 @@
169247 # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
169248 # define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
169249
169250 #endif
169251
 
 
 
 
169252
169253 /*
169254 ** Maximum number of prefix indexes on single FTS5 table. This must be
169255 ** less than 32. If it is set to anything large than that, an #error
169256 ** directive in fts5_index.c will cause the build to fail.
@@ -174637,10 +174652,11 @@
174637
174638 UNUSED_PARAM2(iUnused1, iUnused2);
174639
174640 /* If an error has already occurred, this is a no-op */
174641 if( pCtx->rc!=SQLITE_OK ) return pCtx->rc;
 
174642
174643 if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
174644 Fts5ExprTerm *pSyn;
174645 int nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
174646 pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte);
@@ -175639,10 +175655,11 @@
175639 Fts5Expr *pExpr = p->pExpr;
175640 int i;
175641
175642 UNUSED_PARAM2(iUnused1, iUnused2);
175643
 
175644 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ) p->iOff++;
175645 for(i=0; i<pExpr->nPhrase; i++){
175646 Fts5ExprTerm *pTerm;
175647 if( p->aPopulator[i].bOk==0 ) continue;
175648 for(pTerm=&pExpr->apExprPhrase[i]->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
@@ -178648,10 +178665,22 @@
178648 pIter->iPgidxOff = iPgidx;
178649
178650 fts5SegIterLoadRowid(p, pIter);
178651 fts5SegIterLoadNPos(p, pIter);
178652 }
 
 
 
 
 
 
 
 
 
 
 
 
178653
178654 /*
178655 ** Initialize the object pIter to point to term pTerm/nTerm within segment
178656 ** pSeg. If there is no such term in the index, the iterator is set to EOF.
178657 **
@@ -178666,35 +178695,29 @@
178666 Fts5SegIter *pIter /* Object to populate */
178667 ){
178668 int iPg = 1;
178669 int bGe = (flags & FTS5INDEX_QUERY_SCAN);
178670 int bDlidx = 0; /* True if there is a doclist-index */
 
178671
178672 assert( bGe==0 || (flags & FTS5INDEX_QUERY_DESC)==0 );
178673 assert( pTerm && nTerm );
178674 memset(pIter, 0, sizeof(*pIter));
178675 pIter->pSeg = pSeg;
178676
178677 /* This block sets stack variable iPg to the leaf page number that may
178678 ** contain term (pTerm/nTerm), if it is present in the segment. */
178679 if( p->pIdxSelect==0 ){
178680 Fts5Config *pConfig = p->pConfig;
178681 fts5IndexPrepareStmt(p, &p->pIdxSelect, sqlite3_mprintf(
178682 "SELECT pgno FROM '%q'.'%q_idx' WHERE "
178683 "segid=? AND term<=? ORDER BY term DESC LIMIT 1",
178684 pConfig->zDb, pConfig->zName
178685 ));
178686 }
178687 if( p->rc ) return;
178688 sqlite3_bind_int(p->pIdxSelect, 1, pSeg->iSegid);
178689 sqlite3_bind_blob(p->pIdxSelect, 2, pTerm, nTerm, SQLITE_STATIC);
178690 if( SQLITE_ROW==sqlite3_step(p->pIdxSelect) ){
178691 i64 val = sqlite3_column_int(p->pIdxSelect, 0);
178692 iPg = (int)(val>>1);
178693 bDlidx = (val & 0x0001);
178694 }
178695 p->rc = sqlite3_reset(p->pIdxSelect);
178696
178697 if( iPg<pSeg->pgnoFirst ){
178698 iPg = pSeg->pgnoFirst;
178699 bDlidx = 0;
178700 }
@@ -179880,10 +179903,21 @@
179880 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
179881 assert( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
179882 }
179883 }
179884 assert( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
 
 
 
 
 
 
 
 
 
 
 
179885 #endif
179886 }
179887 }
179888
179889 return iSegid;
@@ -180125,10 +180159,13 @@
180125
180126 static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
180127 static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
180128 Fts5PageWriter *pPage = &pWriter->writer;
180129 i64 iRowid;
 
 
 
180130
180131 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
180132
180133 /* Set the szLeaf header field. */
180134 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
@@ -185385,11 +185422,11 @@
185385 int nArg, /* Number of args */
185386 sqlite3_value **apUnused /* Function arguments */
185387 ){
185388 assert( nArg==0 );
185389 UNUSED_PARAM2(nArg, apUnused);
185390 sqlite3_result_text(pCtx, "fts5: 2016-03-22 15:01:54 e1ab2d376a72786098125a41c1ea8140fcbd15c6", -1, SQLITE_TRANSIENT);
185391 }
185392
185393 static int fts5Init(sqlite3 *db){
185394 static const sqlite3_module fts5Mod = {
185395 /* iVersion */ 2,
@@ -185872,10 +185909,11 @@
185872 int iUnused2 /* End offset of token */
185873 ){
185874 Fts5InsertCtx *pCtx = (Fts5InsertCtx*)pContext;
185875 Fts5Index *pIdx = pCtx->pStorage->pIndex;
185876 UNUSED_PARAM2(iUnused1, iUnused2);
 
185877 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
185878 pCtx->szCol++;
185879 }
185880 return sqlite3Fts5IndexWrite(pIdx, pCtx->iCol, pCtx->szCol-1, pToken, nToken);
185881 }
@@ -186318,10 +186356,11 @@
186318 int rc = SQLITE_OK;
186319 int iPos;
186320 int iCol;
186321
186322 UNUSED_PARAM2(iUnused1, iUnused2);
 
186323
186324 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
186325 pCtx->szCol++;
186326 }
186327
186328
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -336,11 +336,11 @@
336 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
337 ** [sqlite_version()] and [sqlite_source_id()].
338 */
339 #define SQLITE_VERSION "3.12.0"
340 #define SQLITE_VERSION_NUMBER 3012000
341 #define SQLITE_SOURCE_ID "2016-03-29 10:14:15 e9bb4cf40f4971974a74468ef922bdee481c988b"
342
343 /*
344 ** CAPI3REF: Run-Time Library Version Numbers
345 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
346 **
@@ -9071,12 +9071,12 @@
9071
9072 /*
9073 ** The suggested maximum number of in-memory pages to use for
9074 ** the main database table and for temporary tables.
9075 **
9076 ** IMPLEMENTATION-OF: R-30185-15359 The default suggested cache size is -2000,
9077 ** which means the cache size is limited to 2048000 bytes of memory.
9078 ** IMPLEMENTATION-OF: R-48205-43578 The default suggested cache size can be
9079 ** altered using the SQLITE_DEFAULT_CACHE_SIZE compile-time options.
9080 */
9081 #ifndef SQLITE_DEFAULT_CACHE_SIZE
9082 # define SQLITE_DEFAULT_CACHE_SIZE -2000
@@ -12538,10 +12538,11 @@
12538
12539 /* Allowed values for Column.colFlags:
12540 */
12541 #define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
12542 #define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
12543 #define COLFLAG_HASTYPE 0x0004 /* Type name follows column name */
12544
12545 /*
12546 ** A "Collating Sequence" is defined by an instance of the following
12547 ** structure. Conceptually, a collating sequence consists of a name and
12548 ** a comparison routine that defines the order of that sequence.
@@ -14241,11 +14242,11 @@
14242 /*
14243 ** Internal function prototypes
14244 */
14245 SQLITE_PRIVATE int sqlite3StrICmp(const char*,const char*);
14246 SQLITE_PRIVATE int sqlite3Strlen30(const char*);
14247 SQLITE_PRIVATE char *sqlite3ColumnType(Column*,char*);
14248 #define sqlite3StrNICmp sqlite3_strnicmp
14249
14250 SQLITE_PRIVATE int sqlite3MallocInit(void);
14251 SQLITE_PRIVATE void sqlite3MallocEnd(void);
14252 SQLITE_PRIVATE void *sqlite3Malloc(u64);
@@ -25497,15 +25498,19 @@
25498 if( z==0 ) return 0;
25499 return 0x3fffffff & (int)strlen(z);
25500 }
25501
25502 /*
25503 ** Return the declared type of a column. Or return zDflt if the column
25504 ** has no declared type.
25505 **
25506 ** The column type is an extra string stored after the zero-terminator on
25507 ** the column name if and only if the COLFLAG_HASTYPE flag is set.
25508 */
25509 SQLITE_PRIVATE char *sqlite3ColumnType(Column *pCol, char *zDflt){
25510 if( (pCol->colFlags & COLFLAG_HASTYPE)==0 ) return zDflt;
25511 return pCol->zName + strlen(pCol->zName) + 1;
25512 }
25513
25514 /*
25515 ** Helper function for sqlite3Error() - called rarely. Broken out into
25516 ** a separate routine to avoid unnecessary register saves on entry to
@@ -35627,15 +35632,27 @@
35632 */
35633 #ifndef SQLITE_WIN32_HEAP_CREATE
35634 # define SQLITE_WIN32_HEAP_CREATE (TRUE)
35635 #endif
35636
35637 /*
35638 * This is cache size used in the calculation of the initial size of the
35639 * Win32-specific heap. It cannot be negative.
35640 */
35641 #ifndef SQLITE_WIN32_CACHE_SIZE
35642 # if SQLITE_DEFAULT_CACHE_SIZE>=0
35643 # define SQLITE_WIN32_CACHE_SIZE (SQLITE_DEFAULT_CACHE_SIZE)
35644 # else
35645 # define SQLITE_WIN32_CACHE_SIZE (-(SQLITE_DEFAULT_CACHE_SIZE))
35646 # endif
35647 #endif
35648
35649 /*
35650 * The initial size of the Win32-specific heap. This value may be zero.
35651 */
35652 #ifndef SQLITE_WIN32_HEAP_INIT_SIZE
35653 # define SQLITE_WIN32_HEAP_INIT_SIZE ((SQLITE_WIN32_CACHE_SIZE) * \
35654 (SQLITE_DEFAULT_PAGE_SIZE) + 4194304)
35655 #endif
35656
35657 /*
35658 * The maximum size of the Win32-specific heap. This value may be zero.
@@ -40707,11 +40724,11 @@
40724 return nBuf;
40725 #else
40726 EntropyGatherer e;
40727 UNUSED_PARAMETER(pVfs);
40728 memset(zBuf, 0, nBuf);
40729 #if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE
40730 rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */
40731 #endif /* defined(_MSC_VER) && _MSC_VER>=1400 */
40732 e.a = (unsigned char*)zBuf;
40733 e.na = nBuf;
40734 e.nXor = 0;
@@ -76978,23 +76995,25 @@
76995 pC->aType[i++] = t;
76996 aOffset[i] = (u32)(offset64 & 0xffffffff);
76997 }while( i<=p2 && zHdr<zEndHdr );
76998 pC->nHdrParsed = i;
76999 pC->iHdrOffset = (u32)(zHdr - zData);
 
77000
77001 /* The record is corrupt if any of the following are true:
77002 ** (1) the bytes of the header extend past the declared header size
77003 ** (2) the entire header was used but not all data was used
77004 ** (3) the end of the data extends beyond the end of the record.
77005 */
77006 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
77007 || (offset64 > pC->payloadSize)
77008 ){
77009 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
77010 rc = SQLITE_CORRUPT_BKPT;
77011 goto abort_due_to_error;
77012 }
77013 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
77014
77015 }else{
77016 t = 0;
77017 }
77018
77019 /* If after trying to extract new entries from the header, nHdrParsed is
@@ -95509,13 +95528,10 @@
95528 z = sqlite3DbMallocRaw(db, pName->n + pType->n + 2);
95529 if( z==0 ) return;
95530 memcpy(z, pName->z, pName->n);
95531 z[pName->n] = 0;
95532 sqlite3Dequote(z);
 
 
 
95533 for(i=0; i<p->nCol; i++){
95534 if( sqlite3_stricmp(z, p->aCol[i].zName)==0 ){
95535 sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
95536 sqlite3DbFree(db, z);
95537 return;
@@ -95539,11 +95555,15 @@
95555 /* If there is no type specified, columns have the default affinity
95556 ** 'BLOB'. */
95557 pCol->affinity = SQLITE_AFF_BLOB;
95558 pCol->szEst = 1;
95559 }else{
95560 zType = z + sqlite3Strlen30(z) + 1;
95561 memcpy(zType, pType->z, pType->n);
95562 zType[pType->n] = 0;
95563 pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
95564 pCol->colFlags |= COLFLAG_HASTYPE;
95565 }
95566 p->nCol++;
95567 pParse->constraintName.n = 0;
95568 }
95569
@@ -95735,11 +95755,11 @@
95755 int onError, /* What to do with a uniqueness conflict */
95756 int autoInc, /* True if the AUTOINCREMENT keyword is present */
95757 int sortOrder /* SQLITE_SO_ASC or SQLITE_SO_DESC */
95758 ){
95759 Table *pTab = pParse->pNewTable;
95760 Column *pCol = 0;
95761 int iCol = -1, i;
95762 int nTerm;
95763 if( pTab==0 || IN_DECLARE_VTAB ) goto primary_key_exit;
95764 if( pTab->tabFlags & TF_HasPrimaryKey ){
95765 sqlite3ErrorMsg(pParse,
@@ -95747,12 +95767,12 @@
95767 goto primary_key_exit;
95768 }
95769 pTab->tabFlags |= TF_HasPrimaryKey;
95770 if( pList==0 ){
95771 iCol = pTab->nCol - 1;
95772 pCol = &pTab->aCol[iCol];
95773 pCol->colFlags |= COLFLAG_PRIMKEY;
95774 nTerm = 1;
95775 }else{
95776 nTerm = pList->nExpr;
95777 for(i=0; i<nTerm; i++){
95778 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
@@ -95760,21 +95780,21 @@
95780 sqlite3StringToId(pCExpr);
95781 if( pCExpr->op==TK_ID ){
95782 const char *zCName = pCExpr->u.zToken;
95783 for(iCol=0; iCol<pTab->nCol; iCol++){
95784 if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
95785 pCol = &pTab->aCol[iCol];
95786 pCol->colFlags |= COLFLAG_PRIMKEY;
95787 break;
95788 }
95789 }
95790 }
95791 }
95792 }
95793 if( nTerm==1
95794 && pCol
95795 && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
95796 && sortOrder!=SQLITE_SO_DESC
95797 ){
95798 pTab->iPKey = iCol;
95799 pTab->keyConf = (u8)onError;
95800 assert( autoInc==0 || autoInc==1 );
@@ -108679,11 +108699,10 @@
108699 pParse->nMem = 6;
108700 sqlite3CodeVerifySchema(pParse, iDb);
108701 setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
108702 sqlite3ViewGetColumnNames(pParse, pTab);
108703 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
 
108704 if( IsHiddenColumn(pCol) ){
108705 nHidden++;
108706 continue;
108707 }
108708 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
@@ -108692,15 +108711,14 @@
108711 k = 1;
108712 }else{
108713 for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){}
108714 }
108715 assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN );
 
108716 sqlite3VdbeMultiLoad(v, 1, "issisi",
108717 i-nHidden,
108718 pCol->zName,
108719 sqlite3ColumnType(pCol,""),
108720 pCol->notNull ? 1 : 0,
108721 pCol->pDflt ? pCol->pDflt->u.zToken : 0,
108722 k);
108723 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
108724 }
@@ -111899,11 +111917,11 @@
111917 if( iCol<0 ){
111918 zType = "INTEGER";
111919 zOrigCol = "rowid";
111920 }else{
111921 zOrigCol = pTab->aCol[iCol].zName;
111922 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
111923 estWidth = pTab->aCol[iCol].szEst;
111924 }
111925 zOrigTab = pTab->zName;
111926 if( pNC->pParse ){
111927 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);
@@ -111911,11 +111929,11 @@
111929 }
111930 #else
111931 if( iCol<0 ){
111932 zType = "INTEGER";
111933 }else{
111934 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);
111935 estWidth = pTab->aCol[iCol].szEst;
111936 }
111937 #endif
111938 }
111939 break;
@@ -119190,26 +119208,20 @@
119208 ** the type string. */
119209 pVTable->pNext = pTab->pVTable;
119210 pTab->pVTable = pVTable;
119211
119212 for(iCol=0; iCol<pTab->nCol; iCol++){
119213 char *zType = sqlite3ColumnType(&pTab->aCol[iCol], "");
119214 int nType;
119215 int i = 0;
 
 
 
 
119216 nType = sqlite3Strlen30(zType);
119217 for(i=0; i<nType; i++){
119218 if( 0==sqlite3StrNICmp("hidden", &zType[i], 6)
119219 && (i==0 || zType[i-1]==' ')
119220 && (zType[i+6]=='\0' || zType[i+6]==' ')
119221 ){
119222 break;
 
 
119223 }
119224 }
119225 if( i<nType ){
119226 int j;
119227 int nDel = 6 + (zType[i+6] ? 1 : 0);
@@ -136523,12 +136535,11 @@
136535 **
136536 ** 2. The table is not a view and the column name identified an
136537 ** explicitly declared column. Copy meta information from *pCol.
136538 */
136539 if( pCol ){
136540 zDataType = sqlite3ColumnType(pCol,0);
 
136541 zCollSeq = pCol->zColl;
136542 notnull = pCol->notNull!=0;
136543 primarykey = (pCol->colFlags & COLFLAG_PRIMKEY)!=0;
136544 autoinc = pTab->iPKey==iCol && (pTab->tabFlags & TF_Autoincrement)!=0;
136545 }else{
@@ -169247,10 +169258,14 @@
169258 # define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
169259 # define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
169260
169261 #endif
169262
169263 /* Truncate very long tokens to this many bytes. Hard limit is
169264 ** (65536-1-1-4-9)==65521 bytes. The limiting factor is the 16-bit offset
169265 ** field that occurs at the start of each leaf page (see fts5_index.c). */
169266 #define FTS5_MAX_TOKEN_SIZE 32768
169267
169268 /*
169269 ** Maximum number of prefix indexes on single FTS5 table. This must be
169270 ** less than 32. If it is set to anything large than that, an #error
169271 ** directive in fts5_index.c will cause the build to fail.
@@ -174637,10 +174652,11 @@
174652
174653 UNUSED_PARAM2(iUnused1, iUnused2);
174654
174655 /* If an error has already occurred, this is a no-op */
174656 if( pCtx->rc!=SQLITE_OK ) return pCtx->rc;
174657 if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
174658
174659 if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
174660 Fts5ExprTerm *pSyn;
174661 int nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
174662 pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte);
@@ -175639,10 +175655,11 @@
175655 Fts5Expr *pExpr = p->pExpr;
175656 int i;
175657
175658 UNUSED_PARAM2(iUnused1, iUnused2);
175659
175660 if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
175661 if( (tflags & FTS5_TOKEN_COLOCATED)==0 ) p->iOff++;
175662 for(i=0; i<pExpr->nPhrase; i++){
175663 Fts5ExprTerm *pTerm;
175664 if( p->aPopulator[i].bOk==0 ) continue;
175665 for(pTerm=&pExpr->apExprPhrase[i]->aTerm[0]; pTerm; pTerm=pTerm->pSynonym){
@@ -178648,10 +178665,22 @@
178665 pIter->iPgidxOff = iPgidx;
178666
178667 fts5SegIterLoadRowid(p, pIter);
178668 fts5SegIterLoadNPos(p, pIter);
178669 }
178670
178671 static sqlite3_stmt *fts5IdxSelectStmt(Fts5Index *p){
178672 if( p->pIdxSelect==0 ){
178673 Fts5Config *pConfig = p->pConfig;
178674 fts5IndexPrepareStmt(p, &p->pIdxSelect, sqlite3_mprintf(
178675 "SELECT pgno FROM '%q'.'%q_idx' WHERE "
178676 "segid=? AND term<=? ORDER BY term DESC LIMIT 1",
178677 pConfig->zDb, pConfig->zName
178678 ));
178679 }
178680 return p->pIdxSelect;
178681 }
178682
178683 /*
178684 ** Initialize the object pIter to point to term pTerm/nTerm within segment
178685 ** pSeg. If there is no such term in the index, the iterator is set to EOF.
178686 **
@@ -178666,35 +178695,29 @@
178695 Fts5SegIter *pIter /* Object to populate */
178696 ){
178697 int iPg = 1;
178698 int bGe = (flags & FTS5INDEX_QUERY_SCAN);
178699 int bDlidx = 0; /* True if there is a doclist-index */
178700 sqlite3_stmt *pIdxSelect = 0;
178701
178702 assert( bGe==0 || (flags & FTS5INDEX_QUERY_DESC)==0 );
178703 assert( pTerm && nTerm );
178704 memset(pIter, 0, sizeof(*pIter));
178705 pIter->pSeg = pSeg;
178706
178707 /* This block sets stack variable iPg to the leaf page number that may
178708 ** contain term (pTerm/nTerm), if it is present in the segment. */
178709 pIdxSelect = fts5IdxSelectStmt(p);
 
 
 
 
 
 
 
178710 if( p->rc ) return;
178711 sqlite3_bind_int(pIdxSelect, 1, pSeg->iSegid);
178712 sqlite3_bind_blob(pIdxSelect, 2, pTerm, nTerm, SQLITE_STATIC);
178713 if( SQLITE_ROW==sqlite3_step(pIdxSelect) ){
178714 i64 val = sqlite3_column_int(pIdxSelect, 0);
178715 iPg = (int)(val>>1);
178716 bDlidx = (val & 0x0001);
178717 }
178718 p->rc = sqlite3_reset(pIdxSelect);
178719
178720 if( iPg<pSeg->pgnoFirst ){
178721 iPg = pSeg->pgnoFirst;
178722 bDlidx = 0;
178723 }
@@ -179880,10 +179903,21 @@
179903 for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
179904 assert( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
179905 }
179906 }
179907 assert( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
179908
179909 {
179910 sqlite3_stmt *pIdxSelect = fts5IdxSelectStmt(p);
179911 if( p->rc==SQLITE_OK ){
179912 u8 aBlob[2] = {0xff, 0xff};
179913 sqlite3_bind_int(pIdxSelect, 1, iSegid);
179914 sqlite3_bind_blob(pIdxSelect, 2, aBlob, 2, SQLITE_STATIC);
179915 assert( sqlite3_step(pIdxSelect)!=SQLITE_ROW );
179916 p->rc = sqlite3_reset(pIdxSelect);
179917 }
179918 }
179919 #endif
179920 }
179921 }
179922
179923 return iSegid;
@@ -180125,10 +180159,13 @@
180159
180160 static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
180161 static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
180162 Fts5PageWriter *pPage = &pWriter->writer;
180163 i64 iRowid;
180164
180165 static int nCall = 0;
180166 nCall++;
180167
180168 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
180169
180170 /* Set the szLeaf header field. */
180171 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
@@ -185385,11 +185422,11 @@
185422 int nArg, /* Number of args */
185423 sqlite3_value **apUnused /* Function arguments */
185424 ){
185425 assert( nArg==0 );
185426 UNUSED_PARAM2(nArg, apUnused);
185427 sqlite3_result_text(pCtx, "fts5: 2016-03-29 10:14:15 e9bb4cf40f4971974a74468ef922bdee481c988b", -1, SQLITE_TRANSIENT);
185428 }
185429
185430 static int fts5Init(sqlite3 *db){
185431 static const sqlite3_module fts5Mod = {
185432 /* iVersion */ 2,
@@ -185872,10 +185909,11 @@
185909 int iUnused2 /* End offset of token */
185910 ){
185911 Fts5InsertCtx *pCtx = (Fts5InsertCtx*)pContext;
185912 Fts5Index *pIdx = pCtx->pStorage->pIndex;
185913 UNUSED_PARAM2(iUnused1, iUnused2);
185914 if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
185915 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
185916 pCtx->szCol++;
185917 }
185918 return sqlite3Fts5IndexWrite(pIdx, pCtx->iCol, pCtx->szCol-1, pToken, nToken);
185919 }
@@ -186318,10 +186356,11 @@
186356 int rc = SQLITE_OK;
186357 int iPos;
186358 int iCol;
186359
186360 UNUSED_PARAM2(iUnused1, iUnused2);
186361 if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
186362
186363 if( (tflags & FTS5_TOKEN_COLOCATED)==0 || pCtx->szCol==0 ){
186364 pCtx->szCol++;
186365 }
186366
186367
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.12.0"
115115
#define SQLITE_VERSION_NUMBER 3012000
116
-#define SQLITE_SOURCE_ID "2016-03-22 15:26:03 142cd359d37f1d8d53de32e329523d9a93c7d6e5"
116
+#define SQLITE_SOURCE_ID "2016-03-29 10:14:15 e9bb4cf40f4971974a74468ef922bdee481c988b"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
122122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.12.0"
115 #define SQLITE_VERSION_NUMBER 3012000
116 #define SQLITE_SOURCE_ID "2016-03-22 15:26:03 142cd359d37f1d8d53de32e329523d9a93c7d6e5"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.12.0"
115 #define SQLITE_VERSION_NUMBER 3012000
116 #define SQLITE_SOURCE_ID "2016-03-29 10:14:15 e9bb4cf40f4971974a74468ef922bdee481c988b"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
122

Keyboard Shortcuts

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