Fossil SCM

Update the built-in SQLite to the first 3.8.12 beta.

drh 2015-10-07 17:31 trunk
Commit b4b551aa66dcb534a1b658e037951de64cc5b5a2
2 files changed +192 -157 +1 -1
+192 -157
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325325
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326326
** [sqlite_version()] and [sqlite_source_id()].
327327
*/
328328
#define SQLITE_VERSION "3.8.12"
329329
#define SQLITE_VERSION_NUMBER 3008012
330
-#define SQLITE_SOURCE_ID "2015-10-01 18:31:29 6f90839e91024e2006042f5eb7f21ca5b47a9b4a"
330
+#define SQLITE_SOURCE_ID "2015-10-07 17:06:17 13adcd038fc20dd1b6f344f79b449b4034f8f8f2"
331331
332332
/*
333333
** CAPI3REF: Run-Time Library Version Numbers
334334
** KEYWORDS: sqlite3_version, sqlite3_sourceid
335335
**
@@ -8433,10 +8433,11 @@
84338433
# if defined(_MSC_VER) && _MSC_VER>=1300
84348434
# if !defined(_WIN32_WCE)
84358435
# include <intrin.h>
84368436
# pragma intrinsic(_byteswap_ushort)
84378437
# pragma intrinsic(_byteswap_ulong)
8438
+# pragma intrinsic(_ReadWriteBarrier)
84388439
# else
84398440
# include <cmnintrin.h>
84408441
# endif
84418442
# endif
84428443
#endif
@@ -10047,13 +10048,13 @@
1004710048
#define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
1004810049
#define OP_Param 134
1004910050
#define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */
1005010051
#define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */
1005110052
#define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */
10052
-#define OP_IfPos 138 /* synopsis: if r[P1]>0 goto P2 */
10053
-#define OP_IfNeg 139 /* synopsis: r[P1]+=P3, if r[P1]<0 goto P2 */
10054
-#define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2 */
10053
+#define OP_IfPos 138 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
10054
+#define OP_SetIfNotPos 139 /* synopsis: if r[P1]<=0 then r[P2]=P3 */
10055
+#define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
1005510056
#define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */
1005610057
#define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */
1005710058
#define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */
1005810059
#define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */
1005910060
#define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */
@@ -10100,11 +10101,11 @@
1010010101
/* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1010110102
/* 104 */ 0x10, 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04,\
1010210103
/* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\
1010310104
/* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
1010410105
/* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\
10105
-/* 136 */ 0x01, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00,\
10106
+/* 136 */ 0x01, 0x04, 0x03, 0x06, 0x03, 0x03, 0x03, 0x00,\
1010610107
/* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
1010710108
/* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\
1010810109
/* 160 */ 0x00,}
1010910110
1011010111
/************** End of opcodes.h *********************************************/
@@ -20498,11 +20499,14 @@
2049820499
SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
2049920500
#if defined(SQLITE_MEMORY_BARRIER)
2050020501
SQLITE_MEMORY_BARRIER;
2050120502
#elif defined(__GNUC__)
2050220503
__sync_synchronize();
20503
-#else
20504
+#elif !defined(SQLITE_DISABLE_INTRINSIC) && \
20505
+ defined(_MSC_VER) && _MSC_VER>=1300
20506
+ _ReadWriteBarrier();
20507
+#elif defined(MemoryBarrier)
2050420508
MemoryBarrier();
2050520509
#endif
2050620510
}
2050720511
2050820512
/*
@@ -25860,13 +25864,13 @@
2586025864
/* 133 */ "Real" OpHelp("r[P2]=P4"),
2586125865
/* 134 */ "Param" OpHelp(""),
2586225866
/* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
2586325867
/* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
2586425868
/* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
25865
- /* 138 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
25866
- /* 139 */ "IfNeg" OpHelp("r[P1]+=P3, if r[P1]<0 goto P2"),
25867
- /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]+=P3, goto P2"),
25869
+ /* 138 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
25870
+ /* 139 */ "SetIfNotPos" OpHelp("if r[P1]<=0 then r[P2]=P3"),
25871
+ /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
2586825872
/* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
2586925873
/* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
2587025874
/* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
2587125875
/* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
2587225876
/* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
@@ -78032,56 +78036,62 @@
7803278036
}
7803378037
break;
7803478038
}
7803578039
#endif /* SQLITE_OMIT_AUTOINCREMENT */
7803678040
78037
-/* Opcode: IfPos P1 P2 * * *
78038
-** Synopsis: if r[P1]>0 goto P2
78041
+/* Opcode: IfPos P1 P2 P3 * *
78042
+** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
7803978043
**
7804078044
** Register P1 must contain an integer.
78041
-** If the value of register P1 is 1 or greater, jump to P2 and
78042
-** add the literal value P3 to register P1.
78045
+** If the value of register P1 is 1 or greater, subtract P3 from the
78046
+** value in P1 and jump to P2.
7804378047
**
7804478048
** If the initial value of register P1 is less than 1, then the
7804578049
** value is unchanged and control passes through to the next instruction.
7804678050
*/
7804778051
case OP_IfPos: { /* jump, in1 */
7804878052
pIn1 = &aMem[pOp->p1];
7804978053
assert( pIn1->flags&MEM_Int );
7805078054
VdbeBranchTaken( pIn1->u.i>0, 2);
78051
- if( pIn1->u.i>0 ) goto jump_to_p2;
78055
+ if( pIn1->u.i>0 ){
78056
+ pIn1->u.i -= pOp->p3;
78057
+ goto jump_to_p2;
78058
+ }
7805278059
break;
7805378060
}
7805478061
78055
-/* Opcode: IfNeg P1 P2 P3 * *
78056
-** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
78062
+/* Opcode: SetIfNotPos P1 P2 P3 * *
78063
+** Synopsis: if r[P1]<=0 then r[P2]=P3
7805778064
**
78058
-** Register P1 must contain an integer. Add literal P3 to the value in
78059
-** register P1 then if the value of register P1 is less than zero, jump to P2.
78065
+** Register P1 must contain an integer.
78066
+** If the value of register P1 is not positive (if it is less than 1) then
78067
+** set the value of register P2 to be the integer P3.
7806078068
*/
78061
-case OP_IfNeg: { /* jump, in1 */
78069
+case OP_SetIfNotPos: { /* in1, in2 */
7806278070
pIn1 = &aMem[pOp->p1];
7806378071
assert( pIn1->flags&MEM_Int );
78064
- pIn1->u.i += pOp->p3;
78065
- VdbeBranchTaken(pIn1->u.i<0, 2);
78066
- if( pIn1->u.i<0 ) goto jump_to_p2;
78072
+ if( pIn1->u.i<=0 ){
78073
+ pOut = out2Prerelease(p, pOp);
78074
+ pOut->u.i = pOp->p3;
78075
+ }
7806778076
break;
7806878077
}
7806978078
7807078079
/* Opcode: IfNotZero P1 P2 P3 * *
78071
-** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
78080
+** Synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2
7807278081
**
7807378082
** Register P1 must contain an integer. If the content of register P1 is
78074
-** initially nonzero, then add P3 to P1 and jump to P2. If register P1 is
78075
-** initially zero, leave it unchanged and fall through.
78083
+** initially nonzero, then subtract P3 from the value in register P1 and
78084
+** jump to P2. If register P1 is initially zero, leave it unchanged
78085
+** and fall through.
7807678086
*/
7807778087
case OP_IfNotZero: { /* jump, in1 */
7807878088
pIn1 = &aMem[pOp->p1];
7807978089
assert( pIn1->flags&MEM_Int );
7808078090
VdbeBranchTaken(pIn1->u.i<0, 2);
7808178091
if( pIn1->u.i ){
78082
- pIn1->u.i += pOp->p3;
78092
+ pIn1->u.i -= pOp->p3;
7808378093
goto jump_to_p2;
7808478094
}
7808578095
break;
7808678096
}
7808778097
@@ -106628,12 +106638,13 @@
106628106638
** messages have been generated, output OK. Otherwise output the
106629106639
** error message
106630106640
*/
106631106641
static const int iLn = VDBE_OFFSET_LINENO(2);
106632106642
static const VdbeOpList endCode[] = {
106633
- { OP_IfNeg, 1, 0, 0}, /* 0 */
106634
- { OP_String8, 0, 3, 0}, /* 1 */
106643
+ { OP_AddImm, 1, 0, 0}, /* 0 */
106644
+ { OP_If, 1, 0, 0}, /* 1 */
106645
+ { OP_String8, 0, 3, 0}, /* 2 */
106635106646
{ OP_ResultRow, 3, 1, 0},
106636106647
};
106637106648
106638106649
int isQuick = (sqlite3Tolower(zLeft[0])=='q');
106639106650
@@ -106830,13 +106841,13 @@
106830106841
}
106831106842
#endif /* SQLITE_OMIT_BTREECOUNT */
106832106843
}
106833106844
}
106834106845
addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
106835
- sqlite3VdbeChangeP3(v, addr, -mxErr);
106836
- sqlite3VdbeJumpHere(v, addr);
106837
- sqlite3VdbeChangeP4(v, addr+1, "ok", P4_STATIC);
106846
+ sqlite3VdbeChangeP2(v, addr, -mxErr);
106847
+ sqlite3VdbeJumpHere(v, addr+1);
106848
+ sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
106838106849
}
106839106850
break;
106840106851
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
106841106852
106842106853
#ifndef SQLITE_OMIT_UTF16
@@ -108669,11 +108680,11 @@
108669108680
if( pSelect->iOffset ){
108670108681
iLimit = pSelect->iOffset+1;
108671108682
}else{
108672108683
iLimit = pSelect->iLimit;
108673108684
}
108674
- addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, -1); VdbeCoverage(v);
108685
+ addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, 1); VdbeCoverage(v);
108675108686
sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
108676108687
sqlite3VdbeAddOp1(v, OP_Delete, pSort->iECursor);
108677108688
sqlite3VdbeJumpHere(v, addr);
108678108689
}
108679108690
}
@@ -108685,15 +108696,12 @@
108685108696
Vdbe *v, /* Generate code into this VM */
108686108697
int iOffset, /* Register holding the offset counter */
108687108698
int iContinue /* Jump here to skip the current record */
108688108699
){
108689108700
if( iOffset>0 ){
108690
- int addr;
108691
- addr = sqlite3VdbeAddOp3(v, OP_IfNeg, iOffset, 0, -1); VdbeCoverage(v);
108692
- sqlite3VdbeGoto(v, iContinue);
108693
- VdbeComment((v, "skip OFFSET records"));
108694
- sqlite3VdbeJumpHere(v, addr);
108701
+ sqlite3VdbeAddOp3(v, OP_IfPos, iOffset, iContinue, 1); VdbeCoverage(v);
108702
+ VdbeComment((v, "OFFSET"));
108695108703
}
108696108704
}
108697108705
108698108706
/*
108699108707
** Add code that will check to make sure the N registers starting at iMem
@@ -109905,11 +109913,11 @@
109905109913
*/
109906109914
static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
109907109915
Vdbe *v = 0;
109908109916
int iLimit = 0;
109909109917
int iOffset;
109910
- int addr1, n;
109918
+ int n;
109911109919
if( p->iLimit ) return;
109912109920
109913109921
/*
109914109922
** "LIMIT -1" always shows all rows. There is some
109915109923
** controversy about what the correct behavior should be.
@@ -109940,18 +109948,14 @@
109940109948
p->iOffset = iOffset = ++pParse->nMem;
109941109949
pParse->nMem++; /* Allocate an extra register for limit+offset */
109942109950
sqlite3ExprCode(pParse, p->pOffset, iOffset);
109943109951
sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
109944109952
VdbeComment((v, "OFFSET counter"));
109945
- addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); VdbeCoverage(v);
109946
- sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
109947
- sqlite3VdbeJumpHere(v, addr1);
109953
+ sqlite3VdbeAddOp3(v, OP_SetIfNotPos, iOffset, iOffset, 0);
109948109954
sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
109949109955
VdbeComment((v, "LIMIT+OFFSET"));
109950
- addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); VdbeCoverage(v);
109951
- sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
109952
- sqlite3VdbeJumpHere(v, addr1);
109956
+ sqlite3VdbeAddOp3(v, OP_SetIfNotPos, iLimit, iOffset+1, -1);
109953109957
}
109954109958
}
109955109959
}
109956109960
109957109961
#ifndef SQLITE_OMIT_COMPOUND_SELECT
@@ -110363,10 +110367,15 @@
110363110367
p->iLimit = pPrior->iLimit;
110364110368
p->iOffset = pPrior->iOffset;
110365110369
if( p->iLimit ){
110366110370
addr = sqlite3VdbeAddOp1(v, OP_IfNot, p->iLimit); VdbeCoverage(v);
110367110371
VdbeComment((v, "Jump ahead if LIMIT reached"));
110372
+ if( p->iOffset ){
110373
+ sqlite3VdbeAddOp3(v, OP_SetIfNotPos, p->iOffset, p->iOffset, 0);
110374
+ sqlite3VdbeAddOp3(v, OP_Add, p->iLimit, p->iOffset, p->iOffset+1);
110375
+ sqlite3VdbeAddOp3(v, OP_SetIfNotPos, p->iLimit, p->iOffset+1, -1);
110376
+ }
110368110377
}
110369110378
explainSetInteger(iSub2, pParse->iNextSelectId);
110370110379
rc = sqlite3Select(pParse, p, &dest);
110371110380
testcase( rc!=SQLITE_OK );
110372110381
pDelete = p->pPrior;
@@ -142556,129 +142565,155 @@
142556142565
142557142566
if( nMaxDepth==0 ){
142558142567
rc = SQLITE_ERROR;
142559142568
}
142560142569
142561
- if( rc==SQLITE_OK && (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
142562
- Fts3Expr **apLeaf;
142563
- apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
142564
- if( 0==apLeaf ){
142565
- rc = SQLITE_NOMEM;
142566
- }else{
142567
- memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
142568
- }
142569
-
142570
- if( rc==SQLITE_OK ){
142571
- int i;
142572
- Fts3Expr *p;
142573
-
142574
- /* Set $p to point to the left-most leaf in the tree of eType nodes. */
142575
- for(p=pRoot; p->eType==eType; p=p->pLeft){
142576
- assert( p->pParent==0 || p->pParent->pLeft==p );
142577
- assert( p->pLeft && p->pRight );
142578
- }
142579
-
142580
- /* This loop runs once for each leaf in the tree of eType nodes. */
142581
- while( 1 ){
142582
- int iLvl;
142583
- Fts3Expr *pParent = p->pParent; /* Current parent of p */
142584
-
142585
- assert( pParent==0 || pParent->pLeft==p );
142586
- p->pParent = 0;
142587
- if( pParent ){
142588
- pParent->pLeft = 0;
142589
- }else{
142590
- pRoot = 0;
142591
- }
142592
- rc = fts3ExprBalance(&p, nMaxDepth-1);
142593
- if( rc!=SQLITE_OK ) break;
142594
-
142595
- for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
142596
- if( apLeaf[iLvl]==0 ){
142597
- apLeaf[iLvl] = p;
142598
- p = 0;
142599
- }else{
142600
- assert( pFree );
142601
- pFree->pLeft = apLeaf[iLvl];
142602
- pFree->pRight = p;
142603
- pFree->pLeft->pParent = pFree;
142604
- pFree->pRight->pParent = pFree;
142605
-
142606
- p = pFree;
142607
- pFree = pFree->pParent;
142608
- p->pParent = 0;
142609
- apLeaf[iLvl] = 0;
142610
- }
142611
- }
142612
- if( p ){
142613
- sqlite3Fts3ExprFree(p);
142614
- rc = SQLITE_TOOBIG;
142615
- break;
142616
- }
142617
-
142618
- /* If that was the last leaf node, break out of the loop */
142619
- if( pParent==0 ) break;
142620
-
142621
- /* Set $p to point to the next leaf in the tree of eType nodes */
142622
- for(p=pParent->pRight; p->eType==eType; p=p->pLeft);
142623
-
142624
- /* Remove pParent from the original tree. */
142625
- assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
142626
- pParent->pRight->pParent = pParent->pParent;
142627
- if( pParent->pParent ){
142628
- pParent->pParent->pLeft = pParent->pRight;
142629
- }else{
142630
- assert( pParent==pRoot );
142631
- pRoot = pParent->pRight;
142632
- }
142633
-
142634
- /* Link pParent into the free node list. It will be used as an
142635
- ** internal node of the new tree. */
142636
- pParent->pParent = pFree;
142637
- pFree = pParent;
142638
- }
142639
-
142640
- if( rc==SQLITE_OK ){
142641
- p = 0;
142642
- for(i=0; i<nMaxDepth; i++){
142643
- if( apLeaf[i] ){
142644
- if( p==0 ){
142645
- p = apLeaf[i];
142646
- p->pParent = 0;
142647
- }else{
142648
- assert( pFree!=0 );
142649
- pFree->pRight = p;
142650
- pFree->pLeft = apLeaf[i];
142570
+ if( rc==SQLITE_OK ){
142571
+ if( (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
142572
+ Fts3Expr **apLeaf;
142573
+ apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
142574
+ if( 0==apLeaf ){
142575
+ rc = SQLITE_NOMEM;
142576
+ }else{
142577
+ memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
142578
+ }
142579
+
142580
+ if( rc==SQLITE_OK ){
142581
+ int i;
142582
+ Fts3Expr *p;
142583
+
142584
+ /* Set $p to point to the left-most leaf in the tree of eType nodes. */
142585
+ for(p=pRoot; p->eType==eType; p=p->pLeft){
142586
+ assert( p->pParent==0 || p->pParent->pLeft==p );
142587
+ assert( p->pLeft && p->pRight );
142588
+ }
142589
+
142590
+ /* This loop runs once for each leaf in the tree of eType nodes. */
142591
+ while( 1 ){
142592
+ int iLvl;
142593
+ Fts3Expr *pParent = p->pParent; /* Current parent of p */
142594
+
142595
+ assert( pParent==0 || pParent->pLeft==p );
142596
+ p->pParent = 0;
142597
+ if( pParent ){
142598
+ pParent->pLeft = 0;
142599
+ }else{
142600
+ pRoot = 0;
142601
+ }
142602
+ rc = fts3ExprBalance(&p, nMaxDepth-1);
142603
+ if( rc!=SQLITE_OK ) break;
142604
+
142605
+ for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
142606
+ if( apLeaf[iLvl]==0 ){
142607
+ apLeaf[iLvl] = p;
142608
+ p = 0;
142609
+ }else{
142610
+ assert( pFree );
142611
+ pFree->pLeft = apLeaf[iLvl];
142612
+ pFree->pRight = p;
142651142613
pFree->pLeft->pParent = pFree;
142652142614
pFree->pRight->pParent = pFree;
142653142615
142654142616
p = pFree;
142655142617
pFree = pFree->pParent;
142656142618
p->pParent = 0;
142657
- }
142658
- }
142659
- }
142660
- pRoot = p;
142661
- }else{
142662
- /* An error occurred. Delete the contents of the apLeaf[] array
142663
- ** and pFree list. Everything else is cleaned up by the call to
142664
- ** sqlite3Fts3ExprFree(pRoot) below. */
142665
- Fts3Expr *pDel;
142666
- for(i=0; i<nMaxDepth; i++){
142667
- sqlite3Fts3ExprFree(apLeaf[i]);
142668
- }
142669
- while( (pDel=pFree)!=0 ){
142670
- pFree = pDel->pParent;
142671
- sqlite3_free(pDel);
142672
- }
142673
- }
142674
-
142675
- assert( pFree==0 );
142676
- sqlite3_free( apLeaf );
142677
- }
142678
- }
142679
-
142619
+ apLeaf[iLvl] = 0;
142620
+ }
142621
+ }
142622
+ if( p ){
142623
+ sqlite3Fts3ExprFree(p);
142624
+ rc = SQLITE_TOOBIG;
142625
+ break;
142626
+ }
142627
+
142628
+ /* If that was the last leaf node, break out of the loop */
142629
+ if( pParent==0 ) break;
142630
+
142631
+ /* Set $p to point to the next leaf in the tree of eType nodes */
142632
+ for(p=pParent->pRight; p->eType==eType; p=p->pLeft);
142633
+
142634
+ /* Remove pParent from the original tree. */
142635
+ assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
142636
+ pParent->pRight->pParent = pParent->pParent;
142637
+ if( pParent->pParent ){
142638
+ pParent->pParent->pLeft = pParent->pRight;
142639
+ }else{
142640
+ assert( pParent==pRoot );
142641
+ pRoot = pParent->pRight;
142642
+ }
142643
+
142644
+ /* Link pParent into the free node list. It will be used as an
142645
+ ** internal node of the new tree. */
142646
+ pParent->pParent = pFree;
142647
+ pFree = pParent;
142648
+ }
142649
+
142650
+ if( rc==SQLITE_OK ){
142651
+ p = 0;
142652
+ for(i=0; i<nMaxDepth; i++){
142653
+ if( apLeaf[i] ){
142654
+ if( p==0 ){
142655
+ p = apLeaf[i];
142656
+ p->pParent = 0;
142657
+ }else{
142658
+ assert( pFree!=0 );
142659
+ pFree->pRight = p;
142660
+ pFree->pLeft = apLeaf[i];
142661
+ pFree->pLeft->pParent = pFree;
142662
+ pFree->pRight->pParent = pFree;
142663
+
142664
+ p = pFree;
142665
+ pFree = pFree->pParent;
142666
+ p->pParent = 0;
142667
+ }
142668
+ }
142669
+ }
142670
+ pRoot = p;
142671
+ }else{
142672
+ /* An error occurred. Delete the contents of the apLeaf[] array
142673
+ ** and pFree list. Everything else is cleaned up by the call to
142674
+ ** sqlite3Fts3ExprFree(pRoot) below. */
142675
+ Fts3Expr *pDel;
142676
+ for(i=0; i<nMaxDepth; i++){
142677
+ sqlite3Fts3ExprFree(apLeaf[i]);
142678
+ }
142679
+ while( (pDel=pFree)!=0 ){
142680
+ pFree = pDel->pParent;
142681
+ sqlite3_free(pDel);
142682
+ }
142683
+ }
142684
+
142685
+ assert( pFree==0 );
142686
+ sqlite3_free( apLeaf );
142687
+ }
142688
+ }else if( eType==FTSQUERY_NOT ){
142689
+ Fts3Expr *pLeft = pRoot->pLeft;
142690
+ Fts3Expr *pRight = pRoot->pRight;
142691
+
142692
+ pRoot->pLeft = 0;
142693
+ pRoot->pRight = 0;
142694
+ pLeft->pParent = 0;
142695
+ pRight->pParent = 0;
142696
+
142697
+ rc = fts3ExprBalance(&pLeft, nMaxDepth-1);
142698
+ if( rc==SQLITE_OK ){
142699
+ rc = fts3ExprBalance(&pRight, nMaxDepth-1);
142700
+ }
142701
+
142702
+ if( rc!=SQLITE_OK ){
142703
+ sqlite3Fts3ExprFree(pRight);
142704
+ sqlite3Fts3ExprFree(pLeft);
142705
+ }else{
142706
+ assert( pLeft && pRight );
142707
+ pRoot->pLeft = pLeft;
142708
+ pLeft->pParent = pRoot;
142709
+ pRoot->pRight = pRight;
142710
+ pRight->pParent = pRoot;
142711
+ }
142712
+ }
142713
+ }
142714
+
142680142715
if( rc!=SQLITE_OK ){
142681142716
sqlite3Fts3ExprFree(pRoot);
142682142717
pRoot = 0;
142683142718
}
142684142719
*pp = pRoot;
142685142720
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.8.12"
329 #define SQLITE_VERSION_NUMBER 3008012
330 #define SQLITE_SOURCE_ID "2015-10-01 18:31:29 6f90839e91024e2006042f5eb7f21ca5b47a9b4a"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -8433,10 +8433,11 @@
8433 # if defined(_MSC_VER) && _MSC_VER>=1300
8434 # if !defined(_WIN32_WCE)
8435 # include <intrin.h>
8436 # pragma intrinsic(_byteswap_ushort)
8437 # pragma intrinsic(_byteswap_ulong)
 
8438 # else
8439 # include <cmnintrin.h>
8440 # endif
8441 # endif
8442 #endif
@@ -10047,13 +10048,13 @@
10047 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
10048 #define OP_Param 134
10049 #define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */
10050 #define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */
10051 #define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */
10052 #define OP_IfPos 138 /* synopsis: if r[P1]>0 goto P2 */
10053 #define OP_IfNeg 139 /* synopsis: r[P1]+=P3, if r[P1]<0 goto P2 */
10054 #define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2 */
10055 #define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */
10056 #define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */
10057 #define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */
10058 #define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */
10059 #define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */
@@ -10100,11 +10101,11 @@
10100 /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
10101 /* 104 */ 0x10, 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04,\
10102 /* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\
10103 /* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
10104 /* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\
10105 /* 136 */ 0x01, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00,\
10106 /* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
10107 /* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\
10108 /* 160 */ 0x00,}
10109
10110 /************** End of opcodes.h *********************************************/
@@ -20498,11 +20499,14 @@
20498 SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
20499 #if defined(SQLITE_MEMORY_BARRIER)
20500 SQLITE_MEMORY_BARRIER;
20501 #elif defined(__GNUC__)
20502 __sync_synchronize();
20503 #else
 
 
 
20504 MemoryBarrier();
20505 #endif
20506 }
20507
20508 /*
@@ -25860,13 +25864,13 @@
25860 /* 133 */ "Real" OpHelp("r[P2]=P4"),
25861 /* 134 */ "Param" OpHelp(""),
25862 /* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
25863 /* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
25864 /* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
25865 /* 138 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
25866 /* 139 */ "IfNeg" OpHelp("r[P1]+=P3, if r[P1]<0 goto P2"),
25867 /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]+=P3, goto P2"),
25868 /* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
25869 /* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
25870 /* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
25871 /* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
25872 /* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
@@ -78032,56 +78036,62 @@
78032 }
78033 break;
78034 }
78035 #endif /* SQLITE_OMIT_AUTOINCREMENT */
78036
78037 /* Opcode: IfPos P1 P2 * * *
78038 ** Synopsis: if r[P1]>0 goto P2
78039 **
78040 ** Register P1 must contain an integer.
78041 ** If the value of register P1 is 1 or greater, jump to P2 and
78042 ** add the literal value P3 to register P1.
78043 **
78044 ** If the initial value of register P1 is less than 1, then the
78045 ** value is unchanged and control passes through to the next instruction.
78046 */
78047 case OP_IfPos: { /* jump, in1 */
78048 pIn1 = &aMem[pOp->p1];
78049 assert( pIn1->flags&MEM_Int );
78050 VdbeBranchTaken( pIn1->u.i>0, 2);
78051 if( pIn1->u.i>0 ) goto jump_to_p2;
 
 
 
78052 break;
78053 }
78054
78055 /* Opcode: IfNeg P1 P2 P3 * *
78056 ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2
78057 **
78058 ** Register P1 must contain an integer. Add literal P3 to the value in
78059 ** register P1 then if the value of register P1 is less than zero, jump to P2.
 
78060 */
78061 case OP_IfNeg: { /* jump, in1 */
78062 pIn1 = &aMem[pOp->p1];
78063 assert( pIn1->flags&MEM_Int );
78064 pIn1->u.i += pOp->p3;
78065 VdbeBranchTaken(pIn1->u.i<0, 2);
78066 if( pIn1->u.i<0 ) goto jump_to_p2;
 
78067 break;
78068 }
78069
78070 /* Opcode: IfNotZero P1 P2 P3 * *
78071 ** Synopsis: if r[P1]!=0 then r[P1]+=P3, goto P2
78072 **
78073 ** Register P1 must contain an integer. If the content of register P1 is
78074 ** initially nonzero, then add P3 to P1 and jump to P2. If register P1 is
78075 ** initially zero, leave it unchanged and fall through.
 
78076 */
78077 case OP_IfNotZero: { /* jump, in1 */
78078 pIn1 = &aMem[pOp->p1];
78079 assert( pIn1->flags&MEM_Int );
78080 VdbeBranchTaken(pIn1->u.i<0, 2);
78081 if( pIn1->u.i ){
78082 pIn1->u.i += pOp->p3;
78083 goto jump_to_p2;
78084 }
78085 break;
78086 }
78087
@@ -106628,12 +106638,13 @@
106628 ** messages have been generated, output OK. Otherwise output the
106629 ** error message
106630 */
106631 static const int iLn = VDBE_OFFSET_LINENO(2);
106632 static const VdbeOpList endCode[] = {
106633 { OP_IfNeg, 1, 0, 0}, /* 0 */
106634 { OP_String8, 0, 3, 0}, /* 1 */
 
106635 { OP_ResultRow, 3, 1, 0},
106636 };
106637
106638 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
106639
@@ -106830,13 +106841,13 @@
106830 }
106831 #endif /* SQLITE_OMIT_BTREECOUNT */
106832 }
106833 }
106834 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
106835 sqlite3VdbeChangeP3(v, addr, -mxErr);
106836 sqlite3VdbeJumpHere(v, addr);
106837 sqlite3VdbeChangeP4(v, addr+1, "ok", P4_STATIC);
106838 }
106839 break;
106840 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
106841
106842 #ifndef SQLITE_OMIT_UTF16
@@ -108669,11 +108680,11 @@
108669 if( pSelect->iOffset ){
108670 iLimit = pSelect->iOffset+1;
108671 }else{
108672 iLimit = pSelect->iLimit;
108673 }
108674 addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, -1); VdbeCoverage(v);
108675 sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
108676 sqlite3VdbeAddOp1(v, OP_Delete, pSort->iECursor);
108677 sqlite3VdbeJumpHere(v, addr);
108678 }
108679 }
@@ -108685,15 +108696,12 @@
108685 Vdbe *v, /* Generate code into this VM */
108686 int iOffset, /* Register holding the offset counter */
108687 int iContinue /* Jump here to skip the current record */
108688 ){
108689 if( iOffset>0 ){
108690 int addr;
108691 addr = sqlite3VdbeAddOp3(v, OP_IfNeg, iOffset, 0, -1); VdbeCoverage(v);
108692 sqlite3VdbeGoto(v, iContinue);
108693 VdbeComment((v, "skip OFFSET records"));
108694 sqlite3VdbeJumpHere(v, addr);
108695 }
108696 }
108697
108698 /*
108699 ** Add code that will check to make sure the N registers starting at iMem
@@ -109905,11 +109913,11 @@
109905 */
109906 static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
109907 Vdbe *v = 0;
109908 int iLimit = 0;
109909 int iOffset;
109910 int addr1, n;
109911 if( p->iLimit ) return;
109912
109913 /*
109914 ** "LIMIT -1" always shows all rows. There is some
109915 ** controversy about what the correct behavior should be.
@@ -109940,18 +109948,14 @@
109940 p->iOffset = iOffset = ++pParse->nMem;
109941 pParse->nMem++; /* Allocate an extra register for limit+offset */
109942 sqlite3ExprCode(pParse, p->pOffset, iOffset);
109943 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
109944 VdbeComment((v, "OFFSET counter"));
109945 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); VdbeCoverage(v);
109946 sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
109947 sqlite3VdbeJumpHere(v, addr1);
109948 sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
109949 VdbeComment((v, "LIMIT+OFFSET"));
109950 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); VdbeCoverage(v);
109951 sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
109952 sqlite3VdbeJumpHere(v, addr1);
109953 }
109954 }
109955 }
109956
109957 #ifndef SQLITE_OMIT_COMPOUND_SELECT
@@ -110363,10 +110367,15 @@
110363 p->iLimit = pPrior->iLimit;
110364 p->iOffset = pPrior->iOffset;
110365 if( p->iLimit ){
110366 addr = sqlite3VdbeAddOp1(v, OP_IfNot, p->iLimit); VdbeCoverage(v);
110367 VdbeComment((v, "Jump ahead if LIMIT reached"));
 
 
 
 
 
110368 }
110369 explainSetInteger(iSub2, pParse->iNextSelectId);
110370 rc = sqlite3Select(pParse, p, &dest);
110371 testcase( rc!=SQLITE_OK );
110372 pDelete = p->pPrior;
@@ -142556,129 +142565,155 @@
142556
142557 if( nMaxDepth==0 ){
142558 rc = SQLITE_ERROR;
142559 }
142560
142561 if( rc==SQLITE_OK && (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
142562 Fts3Expr **apLeaf;
142563 apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
142564 if( 0==apLeaf ){
142565 rc = SQLITE_NOMEM;
142566 }else{
142567 memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
142568 }
142569
142570 if( rc==SQLITE_OK ){
142571 int i;
142572 Fts3Expr *p;
142573
142574 /* Set $p to point to the left-most leaf in the tree of eType nodes. */
142575 for(p=pRoot; p->eType==eType; p=p->pLeft){
142576 assert( p->pParent==0 || p->pParent->pLeft==p );
142577 assert( p->pLeft && p->pRight );
142578 }
142579
142580 /* This loop runs once for each leaf in the tree of eType nodes. */
142581 while( 1 ){
142582 int iLvl;
142583 Fts3Expr *pParent = p->pParent; /* Current parent of p */
142584
142585 assert( pParent==0 || pParent->pLeft==p );
142586 p->pParent = 0;
142587 if( pParent ){
142588 pParent->pLeft = 0;
142589 }else{
142590 pRoot = 0;
142591 }
142592 rc = fts3ExprBalance(&p, nMaxDepth-1);
142593 if( rc!=SQLITE_OK ) break;
142594
142595 for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
142596 if( apLeaf[iLvl]==0 ){
142597 apLeaf[iLvl] = p;
142598 p = 0;
142599 }else{
142600 assert( pFree );
142601 pFree->pLeft = apLeaf[iLvl];
142602 pFree->pRight = p;
142603 pFree->pLeft->pParent = pFree;
142604 pFree->pRight->pParent = pFree;
142605
142606 p = pFree;
142607 pFree = pFree->pParent;
142608 p->pParent = 0;
142609 apLeaf[iLvl] = 0;
142610 }
142611 }
142612 if( p ){
142613 sqlite3Fts3ExprFree(p);
142614 rc = SQLITE_TOOBIG;
142615 break;
142616 }
142617
142618 /* If that was the last leaf node, break out of the loop */
142619 if( pParent==0 ) break;
142620
142621 /* Set $p to point to the next leaf in the tree of eType nodes */
142622 for(p=pParent->pRight; p->eType==eType; p=p->pLeft);
142623
142624 /* Remove pParent from the original tree. */
142625 assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
142626 pParent->pRight->pParent = pParent->pParent;
142627 if( pParent->pParent ){
142628 pParent->pParent->pLeft = pParent->pRight;
142629 }else{
142630 assert( pParent==pRoot );
142631 pRoot = pParent->pRight;
142632 }
142633
142634 /* Link pParent into the free node list. It will be used as an
142635 ** internal node of the new tree. */
142636 pParent->pParent = pFree;
142637 pFree = pParent;
142638 }
142639
142640 if( rc==SQLITE_OK ){
142641 p = 0;
142642 for(i=0; i<nMaxDepth; i++){
142643 if( apLeaf[i] ){
142644 if( p==0 ){
142645 p = apLeaf[i];
142646 p->pParent = 0;
142647 }else{
142648 assert( pFree!=0 );
142649 pFree->pRight = p;
142650 pFree->pLeft = apLeaf[i];
142651 pFree->pLeft->pParent = pFree;
142652 pFree->pRight->pParent = pFree;
142653
142654 p = pFree;
142655 pFree = pFree->pParent;
142656 p->pParent = 0;
142657 }
142658 }
142659 }
142660 pRoot = p;
142661 }else{
142662 /* An error occurred. Delete the contents of the apLeaf[] array
142663 ** and pFree list. Everything else is cleaned up by the call to
142664 ** sqlite3Fts3ExprFree(pRoot) below. */
142665 Fts3Expr *pDel;
142666 for(i=0; i<nMaxDepth; i++){
142667 sqlite3Fts3ExprFree(apLeaf[i]);
142668 }
142669 while( (pDel=pFree)!=0 ){
142670 pFree = pDel->pParent;
142671 sqlite3_free(pDel);
142672 }
142673 }
142674
142675 assert( pFree==0 );
142676 sqlite3_free( apLeaf );
142677 }
142678 }
142679
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142680 if( rc!=SQLITE_OK ){
142681 sqlite3Fts3ExprFree(pRoot);
142682 pRoot = 0;
142683 }
142684 *pp = pRoot;
142685
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -325,11 +325,11 @@
325 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
326 ** [sqlite_version()] and [sqlite_source_id()].
327 */
328 #define SQLITE_VERSION "3.8.12"
329 #define SQLITE_VERSION_NUMBER 3008012
330 #define SQLITE_SOURCE_ID "2015-10-07 17:06:17 13adcd038fc20dd1b6f344f79b449b4034f8f8f2"
331
332 /*
333 ** CAPI3REF: Run-Time Library Version Numbers
334 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
335 **
@@ -8433,10 +8433,11 @@
8433 # if defined(_MSC_VER) && _MSC_VER>=1300
8434 # if !defined(_WIN32_WCE)
8435 # include <intrin.h>
8436 # pragma intrinsic(_byteswap_ushort)
8437 # pragma intrinsic(_byteswap_ulong)
8438 # pragma intrinsic(_ReadWriteBarrier)
8439 # else
8440 # include <cmnintrin.h>
8441 # endif
8442 # endif
8443 #endif
@@ -10047,13 +10048,13 @@
10048 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
10049 #define OP_Param 134
10050 #define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */
10051 #define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */
10052 #define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */
10053 #define OP_IfPos 138 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
10054 #define OP_SetIfNotPos 139 /* synopsis: if r[P1]<=0 then r[P2]=P3 */
10055 #define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
10056 #define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */
10057 #define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */
10058 #define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */
10059 #define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */
10060 #define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */
@@ -10100,11 +10101,11 @@
10101 /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
10102 /* 104 */ 0x10, 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04,\
10103 /* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\
10104 /* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
10105 /* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\
10106 /* 136 */ 0x01, 0x04, 0x03, 0x06, 0x03, 0x03, 0x03, 0x00,\
10107 /* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
10108 /* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\
10109 /* 160 */ 0x00,}
10110
10111 /************** End of opcodes.h *********************************************/
@@ -20498,11 +20499,14 @@
20499 SQLITE_PRIVATE void sqlite3MemoryBarrier(void){
20500 #if defined(SQLITE_MEMORY_BARRIER)
20501 SQLITE_MEMORY_BARRIER;
20502 #elif defined(__GNUC__)
20503 __sync_synchronize();
20504 #elif !defined(SQLITE_DISABLE_INTRINSIC) && \
20505 defined(_MSC_VER) && _MSC_VER>=1300
20506 _ReadWriteBarrier();
20507 #elif defined(MemoryBarrier)
20508 MemoryBarrier();
20509 #endif
20510 }
20511
20512 /*
@@ -25860,13 +25864,13 @@
25864 /* 133 */ "Real" OpHelp("r[P2]=P4"),
25865 /* 134 */ "Param" OpHelp(""),
25866 /* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
25867 /* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
25868 /* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
25869 /* 138 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
25870 /* 139 */ "SetIfNotPos" OpHelp("if r[P1]<=0 then r[P2]=P3"),
25871 /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
25872 /* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
25873 /* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
25874 /* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
25875 /* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
25876 /* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
@@ -78032,56 +78036,62 @@
78036 }
78037 break;
78038 }
78039 #endif /* SQLITE_OMIT_AUTOINCREMENT */
78040
78041 /* Opcode: IfPos P1 P2 P3 * *
78042 ** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
78043 **
78044 ** Register P1 must contain an integer.
78045 ** If the value of register P1 is 1 or greater, subtract P3 from the
78046 ** value in P1 and jump to P2.
78047 **
78048 ** If the initial value of register P1 is less than 1, then the
78049 ** value is unchanged and control passes through to the next instruction.
78050 */
78051 case OP_IfPos: { /* jump, in1 */
78052 pIn1 = &aMem[pOp->p1];
78053 assert( pIn1->flags&MEM_Int );
78054 VdbeBranchTaken( pIn1->u.i>0, 2);
78055 if( pIn1->u.i>0 ){
78056 pIn1->u.i -= pOp->p3;
78057 goto jump_to_p2;
78058 }
78059 break;
78060 }
78061
78062 /* Opcode: SetIfNotPos P1 P2 P3 * *
78063 ** Synopsis: if r[P1]<=0 then r[P2]=P3
78064 **
78065 ** Register P1 must contain an integer.
78066 ** If the value of register P1 is not positive (if it is less than 1) then
78067 ** set the value of register P2 to be the integer P3.
78068 */
78069 case OP_SetIfNotPos: { /* in1, in2 */
78070 pIn1 = &aMem[pOp->p1];
78071 assert( pIn1->flags&MEM_Int );
78072 if( pIn1->u.i<=0 ){
78073 pOut = out2Prerelease(p, pOp);
78074 pOut->u.i = pOp->p3;
78075 }
78076 break;
78077 }
78078
78079 /* Opcode: IfNotZero P1 P2 P3 * *
78080 ** Synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2
78081 **
78082 ** Register P1 must contain an integer. If the content of register P1 is
78083 ** initially nonzero, then subtract P3 from the value in register P1 and
78084 ** jump to P2. If register P1 is initially zero, leave it unchanged
78085 ** and fall through.
78086 */
78087 case OP_IfNotZero: { /* jump, in1 */
78088 pIn1 = &aMem[pOp->p1];
78089 assert( pIn1->flags&MEM_Int );
78090 VdbeBranchTaken(pIn1->u.i<0, 2);
78091 if( pIn1->u.i ){
78092 pIn1->u.i -= pOp->p3;
78093 goto jump_to_p2;
78094 }
78095 break;
78096 }
78097
@@ -106628,12 +106638,13 @@
106638 ** messages have been generated, output OK. Otherwise output the
106639 ** error message
106640 */
106641 static const int iLn = VDBE_OFFSET_LINENO(2);
106642 static const VdbeOpList endCode[] = {
106643 { OP_AddImm, 1, 0, 0}, /* 0 */
106644 { OP_If, 1, 0, 0}, /* 1 */
106645 { OP_String8, 0, 3, 0}, /* 2 */
106646 { OP_ResultRow, 3, 1, 0},
106647 };
106648
106649 int isQuick = (sqlite3Tolower(zLeft[0])=='q');
106650
@@ -106830,13 +106841,13 @@
106841 }
106842 #endif /* SQLITE_OMIT_BTREECOUNT */
106843 }
106844 }
106845 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
106846 sqlite3VdbeChangeP2(v, addr, -mxErr);
106847 sqlite3VdbeJumpHere(v, addr+1);
106848 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
106849 }
106850 break;
106851 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
106852
106853 #ifndef SQLITE_OMIT_UTF16
@@ -108669,11 +108680,11 @@
108680 if( pSelect->iOffset ){
108681 iLimit = pSelect->iOffset+1;
108682 }else{
108683 iLimit = pSelect->iLimit;
108684 }
108685 addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, 1); VdbeCoverage(v);
108686 sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
108687 sqlite3VdbeAddOp1(v, OP_Delete, pSort->iECursor);
108688 sqlite3VdbeJumpHere(v, addr);
108689 }
108690 }
@@ -108685,15 +108696,12 @@
108696 Vdbe *v, /* Generate code into this VM */
108697 int iOffset, /* Register holding the offset counter */
108698 int iContinue /* Jump here to skip the current record */
108699 ){
108700 if( iOffset>0 ){
108701 sqlite3VdbeAddOp3(v, OP_IfPos, iOffset, iContinue, 1); VdbeCoverage(v);
108702 VdbeComment((v, "OFFSET"));
 
 
 
108703 }
108704 }
108705
108706 /*
108707 ** Add code that will check to make sure the N registers starting at iMem
@@ -109905,11 +109913,11 @@
109913 */
109914 static void computeLimitRegisters(Parse *pParse, Select *p, int iBreak){
109915 Vdbe *v = 0;
109916 int iLimit = 0;
109917 int iOffset;
109918 int n;
109919 if( p->iLimit ) return;
109920
109921 /*
109922 ** "LIMIT -1" always shows all rows. There is some
109923 ** controversy about what the correct behavior should be.
@@ -109940,18 +109948,14 @@
109948 p->iOffset = iOffset = ++pParse->nMem;
109949 pParse->nMem++; /* Allocate an extra register for limit+offset */
109950 sqlite3ExprCode(pParse, p->pOffset, iOffset);
109951 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
109952 VdbeComment((v, "OFFSET counter"));
109953 sqlite3VdbeAddOp3(v, OP_SetIfNotPos, iOffset, iOffset, 0);
 
 
109954 sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
109955 VdbeComment((v, "LIMIT+OFFSET"));
109956 sqlite3VdbeAddOp3(v, OP_SetIfNotPos, iLimit, iOffset+1, -1);
 
 
109957 }
109958 }
109959 }
109960
109961 #ifndef SQLITE_OMIT_COMPOUND_SELECT
@@ -110363,10 +110367,15 @@
110367 p->iLimit = pPrior->iLimit;
110368 p->iOffset = pPrior->iOffset;
110369 if( p->iLimit ){
110370 addr = sqlite3VdbeAddOp1(v, OP_IfNot, p->iLimit); VdbeCoverage(v);
110371 VdbeComment((v, "Jump ahead if LIMIT reached"));
110372 if( p->iOffset ){
110373 sqlite3VdbeAddOp3(v, OP_SetIfNotPos, p->iOffset, p->iOffset, 0);
110374 sqlite3VdbeAddOp3(v, OP_Add, p->iLimit, p->iOffset, p->iOffset+1);
110375 sqlite3VdbeAddOp3(v, OP_SetIfNotPos, p->iLimit, p->iOffset+1, -1);
110376 }
110377 }
110378 explainSetInteger(iSub2, pParse->iNextSelectId);
110379 rc = sqlite3Select(pParse, p, &dest);
110380 testcase( rc!=SQLITE_OK );
110381 pDelete = p->pPrior;
@@ -142556,129 +142565,155 @@
142565
142566 if( nMaxDepth==0 ){
142567 rc = SQLITE_ERROR;
142568 }
142569
142570 if( rc==SQLITE_OK ){
142571 if( (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
142572 Fts3Expr **apLeaf;
142573 apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
142574 if( 0==apLeaf ){
142575 rc = SQLITE_NOMEM;
142576 }else{
142577 memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
142578 }
142579
142580 if( rc==SQLITE_OK ){
142581 int i;
142582 Fts3Expr *p;
142583
142584 /* Set $p to point to the left-most leaf in the tree of eType nodes. */
142585 for(p=pRoot; p->eType==eType; p=p->pLeft){
142586 assert( p->pParent==0 || p->pParent->pLeft==p );
142587 assert( p->pLeft && p->pRight );
142588 }
142589
142590 /* This loop runs once for each leaf in the tree of eType nodes. */
142591 while( 1 ){
142592 int iLvl;
142593 Fts3Expr *pParent = p->pParent; /* Current parent of p */
142594
142595 assert( pParent==0 || pParent->pLeft==p );
142596 p->pParent = 0;
142597 if( pParent ){
142598 pParent->pLeft = 0;
142599 }else{
142600 pRoot = 0;
142601 }
142602 rc = fts3ExprBalance(&p, nMaxDepth-1);
142603 if( rc!=SQLITE_OK ) break;
142604
142605 for(iLvl=0; p && iLvl<nMaxDepth; iLvl++){
142606 if( apLeaf[iLvl]==0 ){
142607 apLeaf[iLvl] = p;
142608 p = 0;
142609 }else{
142610 assert( pFree );
142611 pFree->pLeft = apLeaf[iLvl];
142612 pFree->pRight = p;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142613 pFree->pLeft->pParent = pFree;
142614 pFree->pRight->pParent = pFree;
142615
142616 p = pFree;
142617 pFree = pFree->pParent;
142618 p->pParent = 0;
142619 apLeaf[iLvl] = 0;
142620 }
142621 }
142622 if( p ){
142623 sqlite3Fts3ExprFree(p);
142624 rc = SQLITE_TOOBIG;
142625 break;
142626 }
142627
142628 /* If that was the last leaf node, break out of the loop */
142629 if( pParent==0 ) break;
142630
142631 /* Set $p to point to the next leaf in the tree of eType nodes */
142632 for(p=pParent->pRight; p->eType==eType; p=p->pLeft);
142633
142634 /* Remove pParent from the original tree. */
142635 assert( pParent->pParent==0 || pParent->pParent->pLeft==pParent );
142636 pParent->pRight->pParent = pParent->pParent;
142637 if( pParent->pParent ){
142638 pParent->pParent->pLeft = pParent->pRight;
142639 }else{
142640 assert( pParent==pRoot );
142641 pRoot = pParent->pRight;
142642 }
142643
142644 /* Link pParent into the free node list. It will be used as an
142645 ** internal node of the new tree. */
142646 pParent->pParent = pFree;
142647 pFree = pParent;
142648 }
142649
142650 if( rc==SQLITE_OK ){
142651 p = 0;
142652 for(i=0; i<nMaxDepth; i++){
142653 if( apLeaf[i] ){
142654 if( p==0 ){
142655 p = apLeaf[i];
142656 p->pParent = 0;
142657 }else{
142658 assert( pFree!=0 );
142659 pFree->pRight = p;
142660 pFree->pLeft = apLeaf[i];
142661 pFree->pLeft->pParent = pFree;
142662 pFree->pRight->pParent = pFree;
142663
142664 p = pFree;
142665 pFree = pFree->pParent;
142666 p->pParent = 0;
142667 }
142668 }
142669 }
142670 pRoot = p;
142671 }else{
142672 /* An error occurred. Delete the contents of the apLeaf[] array
142673 ** and pFree list. Everything else is cleaned up by the call to
142674 ** sqlite3Fts3ExprFree(pRoot) below. */
142675 Fts3Expr *pDel;
142676 for(i=0; i<nMaxDepth; i++){
142677 sqlite3Fts3ExprFree(apLeaf[i]);
142678 }
142679 while( (pDel=pFree)!=0 ){
142680 pFree = pDel->pParent;
142681 sqlite3_free(pDel);
142682 }
142683 }
142684
142685 assert( pFree==0 );
142686 sqlite3_free( apLeaf );
142687 }
142688 }else if( eType==FTSQUERY_NOT ){
142689 Fts3Expr *pLeft = pRoot->pLeft;
142690 Fts3Expr *pRight = pRoot->pRight;
142691
142692 pRoot->pLeft = 0;
142693 pRoot->pRight = 0;
142694 pLeft->pParent = 0;
142695 pRight->pParent = 0;
142696
142697 rc = fts3ExprBalance(&pLeft, nMaxDepth-1);
142698 if( rc==SQLITE_OK ){
142699 rc = fts3ExprBalance(&pRight, nMaxDepth-1);
142700 }
142701
142702 if( rc!=SQLITE_OK ){
142703 sqlite3Fts3ExprFree(pRight);
142704 sqlite3Fts3ExprFree(pLeft);
142705 }else{
142706 assert( pLeft && pRight );
142707 pRoot->pLeft = pLeft;
142708 pLeft->pParent = pRoot;
142709 pRoot->pRight = pRight;
142710 pRight->pParent = pRoot;
142711 }
142712 }
142713 }
142714
142715 if( rc!=SQLITE_OK ){
142716 sqlite3Fts3ExprFree(pRoot);
142717 pRoot = 0;
142718 }
142719 *pp = pRoot;
142720
+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.8.12"
115115
#define SQLITE_VERSION_NUMBER 3008012
116
-#define SQLITE_SOURCE_ID "2015-10-01 18:31:29 6f90839e91024e2006042f5eb7f21ca5b47a9b4a"
116
+#define SQLITE_SOURCE_ID "2015-10-07 17:06:17 13adcd038fc20dd1b6f344f79b449b4034f8f8f2"
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.8.12"
115 #define SQLITE_VERSION_NUMBER 3008012
116 #define SQLITE_SOURCE_ID "2015-10-01 18:31:29 6f90839e91024e2006042f5eb7f21ca5b47a9b4a"
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.8.12"
115 #define SQLITE_VERSION_NUMBER 3008012
116 #define SQLITE_SOURCE_ID "2015-10-07 17:06:17 13adcd038fc20dd1b6f344f79b449b4034f8f8f2"
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