mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Merge recent trunk changes, and especially the fix for the R-Tree problem
described in ticket [d2889096e7bdeac6]. FossilOrigin-Name: 8f1beeade0ddf802900c9d203a4fd678d1190394
This commit is contained in:
166
src/vdbe.c
166
src/vdbe.c
@@ -234,21 +234,21 @@ static VdbeCursor *allocateCursor(
|
||||
** look like a number, leave it alone.
|
||||
*/
|
||||
static void applyNumericAffinity(Mem *pRec){
|
||||
if( (pRec->flags & (MEM_Real|MEM_Int))==0 ){
|
||||
double rValue;
|
||||
i64 iValue;
|
||||
u8 enc = pRec->enc;
|
||||
if( (pRec->flags&MEM_Str)==0 ) return;
|
||||
if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
|
||||
if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
|
||||
pRec->u.i = iValue;
|
||||
pRec->flags |= MEM_Int;
|
||||
}else{
|
||||
pRec->r = rValue;
|
||||
pRec->flags |= MEM_Real;
|
||||
}
|
||||
double rValue;
|
||||
i64 iValue;
|
||||
u8 enc = pRec->enc;
|
||||
if( (pRec->flags&MEM_Str)==0 ) return;
|
||||
if( sqlite3AtoF(pRec->z, &rValue, pRec->n, enc)==0 ) return;
|
||||
if( 0==sqlite3Atoi64(pRec->z, &iValue, pRec->n, enc) ){
|
||||
pRec->u.i = iValue;
|
||||
pRec->flags |= MEM_Int;
|
||||
}else{
|
||||
pRec->r = rValue;
|
||||
pRec->flags |= MEM_Real;
|
||||
}
|
||||
}
|
||||
#define ApplyNumericAffinity(X) \
|
||||
if(((X)->flags&(MEM_Real|MEM_Int))==0){applyNumericAffinity(X);}
|
||||
|
||||
/*
|
||||
** Processing is determine by the affinity parameter:
|
||||
@@ -285,7 +285,7 @@ static void applyAffinity(
|
||||
}else if( affinity!=SQLITE_AFF_NONE ){
|
||||
assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
|
||||
|| affinity==SQLITE_AFF_NUMERIC );
|
||||
applyNumericAffinity(pRec);
|
||||
ApplyNumericAffinity(pRec);
|
||||
if( pRec->flags & MEM_Real ){
|
||||
sqlite3VdbeIntegerAffinity(pRec);
|
||||
}
|
||||
@@ -777,12 +777,14 @@ case OP_Return: { /* in1 */
|
||||
|
||||
/* Opcode: InitCoroutine P1 P2 P3 * *
|
||||
**
|
||||
** Set up register P1 so that it will OP_Yield to the co-routine
|
||||
** Set up register P1 so that it will Yield to the coroutine
|
||||
** located at address P3.
|
||||
**
|
||||
** If P2!=0 then the co-routine implementation immediately follows
|
||||
** this opcode. So jump over the co-routine implementation to
|
||||
** If P2!=0 then the coroutine implementation immediately follows
|
||||
** this opcode. So jump over the coroutine implementation to
|
||||
** address P2.
|
||||
**
|
||||
** See also: EndCoroutine
|
||||
*/
|
||||
case OP_InitCoroutine: { /* jump */
|
||||
assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
|
||||
@@ -798,9 +800,11 @@ case OP_InitCoroutine: { /* jump */
|
||||
|
||||
/* Opcode: EndCoroutine P1 * * * *
|
||||
**
|
||||
** The instruction at the address in register P1 is an OP_Yield.
|
||||
** Jump to the P2 parameter of that OP_Yield.
|
||||
** The instruction at the address in register P1 is an Yield.
|
||||
** Jump to the P2 parameter of that Yield.
|
||||
** After the jump, register P1 becomes undefined.
|
||||
**
|
||||
** See also: InitCoroutine
|
||||
*/
|
||||
case OP_EndCoroutine: { /* in1 */
|
||||
VdbeOp *pCaller;
|
||||
@@ -817,11 +821,16 @@ case OP_EndCoroutine: { /* in1 */
|
||||
|
||||
/* Opcode: Yield P1 P2 * * *
|
||||
**
|
||||
** Swap the program counter with the value in register P1.
|
||||
** Swap the program counter with the value in register P1. This
|
||||
** has the effect of yielding to a coroutine.
|
||||
**
|
||||
** If the co-routine ends with OP_Yield or OP_Return then continue
|
||||
** to the next instruction. But if the co-routine ends with
|
||||
** OP_EndCoroutine, jump immediately to P2.
|
||||
** If the coroutine that is launched by this instruction ends with
|
||||
** Yield or Return then continue to the next instruction. But if
|
||||
** the coroutine launched by this instruction ends with
|
||||
** EndCoroutine, then jump to P2 rather than continuing with the
|
||||
** next instruction.
|
||||
**
|
||||
** See also: InitCoroutine
|
||||
*/
|
||||
case OP_Yield: { /* in1, jump */
|
||||
int pcDest;
|
||||
@@ -2206,10 +2215,14 @@ case OP_BitNot: { /* same as TK_BITNOT, in1, out2 */
|
||||
|
||||
/* Opcode: Once P1 P2 * * *
|
||||
**
|
||||
** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
|
||||
** set the flag and fall through to the next instruction. In other words,
|
||||
** this opcode causes all following opcodes up through P2 (but not including
|
||||
** P2) to run just once and to be skipped on subsequent times through the loop.
|
||||
** Check the "once" flag number P1. If it is set, jump to instruction P2.
|
||||
** Otherwise, set the flag and fall through to the next instruction.
|
||||
** In other words, this opcode causes all following opcodes up through P2
|
||||
** (but not including P2) to run just once and to be skipped on subsequent
|
||||
** times through the loop.
|
||||
**
|
||||
** All "once" flags are initially cleared whenever a prepared statement
|
||||
** first begins to run.
|
||||
*/
|
||||
case OP_Once: { /* jump */
|
||||
assert( pOp->p1<p->nOnceFlag );
|
||||
@@ -3491,7 +3504,7 @@ case OP_Close: {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Opcode: SeekGe P1 P2 P3 P4 *
|
||||
/* Opcode: SeekGE P1 P2 P3 P4 *
|
||||
** Synopsis: key=r[P3@P4]
|
||||
**
|
||||
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
|
||||
@@ -3503,9 +3516,13 @@ case OP_Close: {
|
||||
** is greater than or equal to the key value. If there are no records
|
||||
** greater than or equal to the key and P2 is not zero, then jump to P2.
|
||||
**
|
||||
** This opcode leaves the cursor configured to move in forward order,
|
||||
** from the begining toward the end. In other words, the cursor is
|
||||
** configured to use Next, not Prev.
|
||||
**
|
||||
** See also: Found, NotFound, SeekLt, SeekGt, SeekLe
|
||||
*/
|
||||
/* Opcode: SeekGt P1 P2 P3 P4 *
|
||||
/* Opcode: SeekGT P1 P2 P3 P4 *
|
||||
** Synopsis: key=r[P3@P4]
|
||||
**
|
||||
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
|
||||
@@ -3517,9 +3534,13 @@ case OP_Close: {
|
||||
** is greater than the key value. If there are no records greater than
|
||||
** the key and P2 is not zero, then jump to P2.
|
||||
**
|
||||
** This opcode leaves the cursor configured to move in forward order,
|
||||
** from the begining toward the end. In other words, the cursor is
|
||||
** configured to use Next, not Prev.
|
||||
**
|
||||
** See also: Found, NotFound, SeekLt, SeekGe, SeekLe
|
||||
*/
|
||||
/* Opcode: SeekLt P1 P2 P3 P4 *
|
||||
/* Opcode: SeekLT P1 P2 P3 P4 *
|
||||
** Synopsis: key=r[P3@P4]
|
||||
**
|
||||
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
|
||||
@@ -3531,9 +3552,13 @@ case OP_Close: {
|
||||
** is less than the key value. If there are no records less than
|
||||
** the key and P2 is not zero, then jump to P2.
|
||||
**
|
||||
** This opcode leaves the cursor configured to move in reverse order,
|
||||
** from the end toward the beginning. In other words, the cursor is
|
||||
** configured to use Prev, not Next.
|
||||
**
|
||||
** See also: Found, NotFound, SeekGt, SeekGe, SeekLe
|
||||
*/
|
||||
/* Opcode: SeekLe P1 P2 P3 P4 *
|
||||
/* Opcode: SeekLE P1 P2 P3 P4 *
|
||||
** Synopsis: key=r[P3@P4]
|
||||
**
|
||||
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
|
||||
@@ -3545,6 +3570,10 @@ case OP_Close: {
|
||||
** is less than or equal to the key value. If there are no records
|
||||
** less than or equal to the key and P2 is not zero, then jump to P2.
|
||||
**
|
||||
** This opcode leaves the cursor configured to move in reverse order,
|
||||
** from the end toward the beginning. In other words, the cursor is
|
||||
** configured to use Prev, not Next.
|
||||
**
|
||||
** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
|
||||
*/
|
||||
case OP_SeekLT: /* jump, in3 */
|
||||
@@ -3570,12 +3599,15 @@ case OP_SeekGT: { /* jump, in3 */
|
||||
assert( pC->pCursor!=0 );
|
||||
oc = pOp->opcode;
|
||||
pC->nullRow = 0;
|
||||
#ifdef SQLITE_DEBUG
|
||||
pC->seekOp = pOp->opcode;
|
||||
#endif
|
||||
if( pC->isTable ){
|
||||
/* The input value in P3 might be of any type: integer, real, string,
|
||||
** blob, or NULL. But it needs to be an integer before we can do
|
||||
** the seek, so covert it. */
|
||||
pIn3 = &aMem[pOp->p3];
|
||||
applyNumericAffinity(pIn3);
|
||||
ApplyNumericAffinity(pIn3);
|
||||
iKey = sqlite3VdbeIntValue(pIn3);
|
||||
pC->rowidIsValid = 0;
|
||||
|
||||
@@ -3725,6 +3757,10 @@ case OP_Seek: { /* in2 */
|
||||
** is a prefix of any entry in P1 then a jump is made to P2 and
|
||||
** P1 is left pointing at the matching entry.
|
||||
**
|
||||
** This operation leaves the cursor in a state where it cannot be
|
||||
** advanced in either direction. In other words, the Next and Prev
|
||||
** opcodes do not work after this operation.
|
||||
**
|
||||
** See also: NotFound, NoConflict, NotExists. SeekGe
|
||||
*/
|
||||
/* Opcode: NotFound P1 P2 P3 P4 *
|
||||
@@ -3740,6 +3776,10 @@ case OP_Seek: { /* in2 */
|
||||
** falls through to the next instruction and P1 is left pointing at the
|
||||
** matching entry.
|
||||
**
|
||||
** This operation leaves the cursor in a state where it cannot be
|
||||
** advanced in either direction. In other words, the Next and Prev
|
||||
** opcodes do not work after this operation.
|
||||
**
|
||||
** See also: Found, NotExists, NoConflict
|
||||
*/
|
||||
/* Opcode: NoConflict P1 P2 P3 P4 *
|
||||
@@ -3759,6 +3799,10 @@ case OP_Seek: { /* in2 */
|
||||
** This opcode is similar to OP_NotFound with the exceptions that the
|
||||
** branch is always taken if any part of the search key input is NULL.
|
||||
**
|
||||
** This operation leaves the cursor in a state where it cannot be
|
||||
** advanced in either direction. In other words, the Next and Prev
|
||||
** opcodes do not work after this operation.
|
||||
**
|
||||
** See also: NotFound, Found, NotExists
|
||||
*/
|
||||
case OP_NoConflict: /* jump, in3 */
|
||||
@@ -3781,6 +3825,9 @@ case OP_Found: { /* jump, in3 */
|
||||
assert( pOp->p4type==P4_INT32 );
|
||||
pC = p->apCsr[pOp->p1];
|
||||
assert( pC!=0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
pC->seekOp = 0;
|
||||
#endif
|
||||
pIn3 = &aMem[pOp->p3];
|
||||
assert( pC->pCursor!=0 );
|
||||
assert( pC->isTable==0 );
|
||||
@@ -3852,6 +3899,10 @@ case OP_Found: { /* jump, in3 */
|
||||
** The OP_NotFound opcode performs the same operation on index btrees
|
||||
** (with arbitrary multi-value keys).
|
||||
**
|
||||
** This opcode leaves the cursor in a state where it cannot be advanced
|
||||
** in either direction. In other words, the Next and Prev opcodes will
|
||||
** not work following this opcode.
|
||||
**
|
||||
** See also: Found, NotFound, NoConflict
|
||||
*/
|
||||
case OP_NotExists: { /* jump, in3 */
|
||||
@@ -3865,6 +3916,9 @@ case OP_NotExists: { /* jump, in3 */
|
||||
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
|
||||
pC = p->apCsr[pOp->p1];
|
||||
assert( pC!=0 );
|
||||
#ifdef SQLITE_DEBUG
|
||||
pC->seekOp = 0;
|
||||
#endif
|
||||
assert( pC->isTable );
|
||||
assert( pC->pseudoTableReg==0 );
|
||||
pCrsr = pC->pCursor;
|
||||
@@ -4482,11 +4536,15 @@ case OP_NullRow: {
|
||||
|
||||
/* Opcode: Last P1 P2 * * *
|
||||
**
|
||||
** The next use of the Rowid or Column or Next instruction for P1
|
||||
** The next use of the Rowid or Column or Prev instruction for P1
|
||||
** will refer to the last entry in the database table or index.
|
||||
** If the table or index is empty and P2>0, then jump immediately to P2.
|
||||
** If P2 is 0 or if the table or index is not empty, fall through
|
||||
** to the following instruction.
|
||||
**
|
||||
** This opcode leaves the cursor configured to move in reverse order,
|
||||
** from the end toward the beginning. In other words, the cursor is
|
||||
** configured to use Prev, not Next.
|
||||
*/
|
||||
case OP_Last: { /* jump */
|
||||
VdbeCursor *pC;
|
||||
@@ -4504,6 +4562,9 @@ case OP_Last: { /* jump */
|
||||
pC->deferredMoveto = 0;
|
||||
pC->rowidIsValid = 0;
|
||||
pC->cacheStatus = CACHE_STALE;
|
||||
#ifdef SQLITE_DEBUG
|
||||
pC->seekOp = OP_Last;
|
||||
#endif
|
||||
if( pOp->p2>0 ){
|
||||
VdbeBranchTaken(res!=0,2);
|
||||
if( res ) pc = pOp->p2 - 1;
|
||||
@@ -4540,6 +4601,10 @@ case OP_Sort: { /* jump */
|
||||
** If the table or index is empty and P2>0, then jump immediately to P2.
|
||||
** If P2 is 0 or if the table or index is not empty, fall through
|
||||
** to the following instruction.
|
||||
**
|
||||
** This opcode leaves the cursor configured to move in forward order,
|
||||
** from the begining toward the end. In other words, the cursor is
|
||||
** configured to use Next, not Prev.
|
||||
*/
|
||||
case OP_Rewind: { /* jump */
|
||||
VdbeCursor *pC;
|
||||
@@ -4551,6 +4616,9 @@ case OP_Rewind: { /* jump */
|
||||
assert( pC!=0 );
|
||||
assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
|
||||
res = 1;
|
||||
#ifdef SQLITE_DEBUG
|
||||
pC->seekOp = OP_Rewind;
|
||||
#endif
|
||||
if( isSorter(pC) ){
|
||||
rc = sqlite3VdbeSorterRewind(db, pC, &res);
|
||||
}else{
|
||||
@@ -4577,6 +4645,10 @@ case OP_Rewind: { /* jump */
|
||||
** to the following instruction. But if the cursor advance was successful,
|
||||
** jump immediately to P2.
|
||||
**
|
||||
** The Next opcode is only valid following an SeekGT, SeekGE, or
|
||||
** OP_Rewind opcode used to position the cursor. Next is not allowed
|
||||
** to follow SeekLT, SeekLE, or OP_Last.
|
||||
**
|
||||
** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
|
||||
** been opened prior to this opcode or the program will segfault.
|
||||
**
|
||||
@@ -4595,7 +4667,7 @@ case OP_Rewind: { /* jump */
|
||||
*/
|
||||
/* Opcode: NextIfOpen P1 P2 P3 P4 P5
|
||||
**
|
||||
** This opcode works just like OP_Next except that if cursor P1 is not
|
||||
** This opcode works just like Next except that if cursor P1 is not
|
||||
** open it behaves a no-op.
|
||||
*/
|
||||
/* Opcode: Prev P1 P2 P3 P4 P5
|
||||
@@ -4605,6 +4677,11 @@ case OP_Rewind: { /* jump */
|
||||
** to the following instruction. But if the cursor backup was successful,
|
||||
** jump immediately to P2.
|
||||
**
|
||||
**
|
||||
** The Prev opcode is only valid following an SeekLT, SeekLE, or
|
||||
** OP_Last opcode used to position the cursor. Prev is not allowed
|
||||
** to follow SeekGT, SeekGE, or OP_Rewind.
|
||||
**
|
||||
** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
|
||||
** not open then the behavior is undefined.
|
||||
**
|
||||
@@ -4621,7 +4698,7 @@ case OP_Rewind: { /* jump */
|
||||
*/
|
||||
/* Opcode: PrevIfOpen P1 P2 P3 P4 P5
|
||||
**
|
||||
** This opcode works just like OP_Prev except that if cursor P1 is not
|
||||
** This opcode works just like Prev except that if cursor P1 is not
|
||||
** open it behaves a no-op.
|
||||
*/
|
||||
case OP_SorterNext: { /* jump */
|
||||
@@ -4652,6 +4729,16 @@ case OP_Next: /* jump */
|
||||
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
|
||||
assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
|
||||
assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
|
||||
|
||||
/* The Next opcode is only used after SeekGT, SeekGE, and Rewind.
|
||||
** The Prev opcode is only used after SeekLT, SeekLE, and Last. */
|
||||
assert( pOp->opcode!=OP_Next || pOp->opcode!=OP_NextIfOpen
|
||||
|| pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE
|
||||
|| pC->seekOp==OP_Rewind );
|
||||
assert( pOp->opcode!=OP_Prev || pOp->opcode!=OP_PrevIfOpen
|
||||
|| pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE
|
||||
|| pC->seekOp==OP_Last );
|
||||
|
||||
rc = pOp->p4.xAdvance(pC->pCursor, &res);
|
||||
next_tail:
|
||||
pC->cacheStatus = CACHE_STALE;
|
||||
@@ -5132,7 +5219,8 @@ case OP_LoadAnalysis: {
|
||||
**
|
||||
** Remove the internal (in-memory) data structures that describe
|
||||
** the table named P4 in database P1. This is called after a table
|
||||
** is dropped in order to keep the internal representation of the
|
||||
** is dropped from disk (using the Destroy opcode) in order to keep
|
||||
** the internal representation of the
|
||||
** schema consistent with what is on disk.
|
||||
*/
|
||||
case OP_DropTable: {
|
||||
@@ -5144,7 +5232,8 @@ case OP_DropTable: {
|
||||
**
|
||||
** Remove the internal (in-memory) data structures that describe
|
||||
** the index named P4 in database P1. This is called after an index
|
||||
** is dropped in order to keep the internal representation of the
|
||||
** is dropped from disk (using the Destroy opcode)
|
||||
** in order to keep the internal representation of the
|
||||
** schema consistent with what is on disk.
|
||||
*/
|
||||
case OP_DropIndex: {
|
||||
@@ -5156,7 +5245,8 @@ case OP_DropIndex: {
|
||||
**
|
||||
** Remove the internal (in-memory) data structures that describe
|
||||
** the trigger named P4 in database P1. This is called after a trigger
|
||||
** is dropped in order to keep the internal representation of the
|
||||
** is dropped from disk (using the Destroy opcode) in order to keep
|
||||
** the internal representation of the
|
||||
** schema consistent with what is on disk.
|
||||
*/
|
||||
case OP_DropTrigger: {
|
||||
|
Reference in New Issue
Block a user