| OLD | NEW |
| 1 /* | 1 /* |
| 2 ** 2001 September 15 | 2 ** 2001 September 15 |
| 3 ** | 3 ** |
| 4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
| 5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
| 6 ** | 6 ** |
| 7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
| 8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
| 9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
| 10 ** | 10 ** |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 ** | 158 ** |
| 159 ** This routine converts an ephemeral string into a dynamically allocated | 159 ** This routine converts an ephemeral string into a dynamically allocated |
| 160 ** string that the register itself controls. In other words, it | 160 ** string that the register itself controls. In other words, it |
| 161 ** converts an MEM_Ephem string into a string with P.z==P.zMalloc. | 161 ** converts an MEM_Ephem string into a string with P.z==P.zMalloc. |
| 162 */ | 162 */ |
| 163 #define Deephemeralize(P) \ | 163 #define Deephemeralize(P) \ |
| 164 if( ((P)->flags&MEM_Ephem)!=0 \ | 164 if( ((P)->flags&MEM_Ephem)!=0 \ |
| 165 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;} | 165 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;} |
| 166 | 166 |
| 167 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */ | 167 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */ |
| 168 #define isSorter(x) ((x)->pSorter!=0) | 168 #define isSorter(x) ((x)->eCurType==CURTYPE_SORTER) |
| 169 | 169 |
| 170 /* | 170 /* |
| 171 ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL | 171 ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL |
| 172 ** if we run out of memory. | 172 ** if we run out of memory. |
| 173 */ | 173 */ |
| 174 static VdbeCursor *allocateCursor( | 174 static VdbeCursor *allocateCursor( |
| 175 Vdbe *p, /* The virtual machine */ | 175 Vdbe *p, /* The virtual machine */ |
| 176 int iCur, /* Index of the new VdbeCursor */ | 176 int iCur, /* Index of the new VdbeCursor */ |
| 177 int nField, /* Number of fields in the table or index */ | 177 int nField, /* Number of fields in the table or index */ |
| 178 int iDb, /* Database the cursor belongs to, or -1 */ | 178 int iDb, /* Database the cursor belongs to, or -1 */ |
| 179 int isBtreeCursor /* True for B-Tree. False for pseudo-table or vtab */ | 179 u8 eCurType /* Type of the new cursor */ |
| 180 ){ | 180 ){ |
| 181 /* Find the memory cell that will be used to store the blob of memory | 181 /* Find the memory cell that will be used to store the blob of memory |
| 182 ** required for this VdbeCursor structure. It is convenient to use a | 182 ** required for this VdbeCursor structure. It is convenient to use a |
| 183 ** vdbe memory cell to manage the memory allocation required for a | 183 ** vdbe memory cell to manage the memory allocation required for a |
| 184 ** VdbeCursor structure for the following reasons: | 184 ** VdbeCursor structure for the following reasons: |
| 185 ** | 185 ** |
| 186 ** * Sometimes cursor numbers are used for a couple of different | 186 ** * Sometimes cursor numbers are used for a couple of different |
| 187 ** purposes in a vdbe program. The different uses might require | 187 ** purposes in a vdbe program. The different uses might require |
| 188 ** different sized allocations. Memory cells provide growable | 188 ** different sized allocations. Memory cells provide growable |
| 189 ** allocations. | 189 ** allocations. |
| 190 ** | 190 ** |
| 191 ** * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can | 191 ** * When using ENABLE_MEMORY_MANAGEMENT, memory cell buffers can |
| 192 ** be freed lazily via the sqlite3_release_memory() API. This | 192 ** be freed lazily via the sqlite3_release_memory() API. This |
| 193 ** minimizes the number of malloc calls made by the system. | 193 ** minimizes the number of malloc calls made by the system. |
| 194 ** | 194 ** |
| 195 ** Memory cells for cursors are allocated at the top of the address | 195 ** Memory cells for cursors are allocated at the top of the address |
| 196 ** space. Memory cell (p->nMem) corresponds to cursor 0. Space for | 196 ** space. Memory cell (p->nMem) corresponds to cursor 0. Space for |
| 197 ** cursor 1 is managed by memory cell (p->nMem-1), etc. | 197 ** cursor 1 is managed by memory cell (p->nMem-1), etc. |
| 198 */ | 198 */ |
| 199 Mem *pMem = &p->aMem[p->nMem-iCur]; | 199 Mem *pMem = &p->aMem[p->nMem-iCur]; |
| 200 | 200 |
| 201 int nByte; | 201 int nByte; |
| 202 VdbeCursor *pCx = 0; | 202 VdbeCursor *pCx = 0; |
| 203 nByte = | 203 nByte = |
| 204 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + | 204 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + |
| 205 (isBtreeCursor?sqlite3BtreeCursorSize():0); | 205 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0); |
| 206 | 206 |
| 207 assert( iCur<p->nCursor ); | 207 assert( iCur<p->nCursor ); |
| 208 if( p->apCsr[iCur] ){ | 208 if( p->apCsr[iCur] ){ |
| 209 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); | 209 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); |
| 210 p->apCsr[iCur] = 0; | 210 p->apCsr[iCur] = 0; |
| 211 } | 211 } |
| 212 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){ | 212 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){ |
| 213 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; | 213 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; |
| 214 memset(pCx, 0, sizeof(VdbeCursor)); | 214 memset(pCx, 0, sizeof(VdbeCursor)); |
| 215 pCx->eCurType = eCurType; |
| 215 pCx->iDb = iDb; | 216 pCx->iDb = iDb; |
| 216 pCx->nField = nField; | 217 pCx->nField = nField; |
| 217 pCx->aOffset = &pCx->aType[nField]; | 218 pCx->aOffset = &pCx->aType[nField]; |
| 218 if( isBtreeCursor ){ | 219 if( eCurType==CURTYPE_BTREE ){ |
| 219 pCx->pCursor = (BtCursor*) | 220 pCx->uc.pCursor = (BtCursor*) |
| 220 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField]; | 221 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField]; |
| 221 sqlite3BtreeCursorZero(pCx->pCursor); | 222 sqlite3BtreeCursorZero(pCx->uc.pCursor); |
| 222 } | 223 } |
| 223 } | 224 } |
| 224 return pCx; | 225 return pCx; |
| 225 } | 226 } |
| 226 | 227 |
| 227 /* | 228 /* |
| 228 ** Try to convert a value into a numeric representation if we can | 229 ** Try to convert a value into a numeric representation if we can |
| 229 ** do so without loss of information. In other words, if the string | 230 ** do so without loss of information. In other words, if the string |
| 230 ** looks like a number, convert it into a number. If it does not | 231 ** looks like a number, convert it into a number. If it does not |
| 231 ** look like a number, leave it alone. | 232 ** look like a number, leave it alone. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 ** SQLITE_AFF_NUMERIC: | 264 ** SQLITE_AFF_NUMERIC: |
| 264 ** Try to convert pRec to an integer representation or a | 265 ** Try to convert pRec to an integer representation or a |
| 265 ** floating-point representation if an integer representation | 266 ** floating-point representation if an integer representation |
| 266 ** is not possible. Note that the integer representation is | 267 ** is not possible. Note that the integer representation is |
| 267 ** always preferred, even if the affinity is REAL, because | 268 ** always preferred, even if the affinity is REAL, because |
| 268 ** an integer representation is more space efficient on disk. | 269 ** an integer representation is more space efficient on disk. |
| 269 ** | 270 ** |
| 270 ** SQLITE_AFF_TEXT: | 271 ** SQLITE_AFF_TEXT: |
| 271 ** Convert pRec to a text representation. | 272 ** Convert pRec to a text representation. |
| 272 ** | 273 ** |
| 273 ** SQLITE_AFF_NONE: | 274 ** SQLITE_AFF_BLOB: |
| 274 ** No-op. pRec is unchanged. | 275 ** No-op. pRec is unchanged. |
| 275 */ | 276 */ |
| 276 static void applyAffinity( | 277 static void applyAffinity( |
| 277 Mem *pRec, /* The value to apply affinity to */ | 278 Mem *pRec, /* The value to apply affinity to */ |
| 278 char affinity, /* The affinity to be applied */ | 279 char affinity, /* The affinity to be applied */ |
| 279 u8 enc /* Use this text encoding */ | 280 u8 enc /* Use this text encoding */ |
| 280 ){ | 281 ){ |
| 281 if( affinity>=SQLITE_AFF_NUMERIC ){ | 282 if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 282 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL | 283 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL |
| 283 || affinity==SQLITE_AFF_NUMERIC ); | 284 || affinity==SQLITE_AFF_NUMERIC ); |
| 284 if( (pRec->flags & MEM_Int)==0 ){ | 285 if( (pRec->flags & MEM_Int)==0 ){ |
| 285 if( (pRec->flags & MEM_Real)==0 ){ | 286 if( (pRec->flags & MEM_Real)==0 ){ |
| 286 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1); | 287 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1); |
| 287 }else{ | 288 }else{ |
| 288 sqlite3VdbeIntegerAffinity(pRec); | 289 sqlite3VdbeIntegerAffinity(pRec); |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 }else if( affinity==SQLITE_AFF_TEXT ){ | 292 }else if( affinity==SQLITE_AFF_TEXT ){ |
| 292 /* Only attempt the conversion to TEXT if there is an integer or real | 293 /* Only attempt the conversion to TEXT if there is an integer or real |
| 293 ** representation (blob and NULL do not get converted) but no string | 294 ** representation (blob and NULL do not get converted) but no string |
| 294 ** representation. | 295 ** representation. |
| 295 */ | 296 */ |
| 296 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){ | 297 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){ |
| 297 sqlite3VdbeMemStringify(pRec, enc, 1); | 298 sqlite3VdbeMemStringify(pRec, enc, 1); |
| 298 } | 299 } |
| 300 pRec->flags &= ~(MEM_Real|MEM_Int); |
| 299 } | 301 } |
| 300 } | 302 } |
| 301 | 303 |
| 302 /* | 304 /* |
| 303 ** Try to convert the type of a function argument or a result column | 305 ** Try to convert the type of a function argument or a result column |
| 304 ** into a numeric representation. Use either INTEGER or REAL whichever | 306 ** into a numeric representation. Use either INTEGER or REAL whichever |
| 305 ** is appropriate. But only do the conversion if it is possible without | 307 ** is appropriate. But only do the conversion if it is possible without |
| 306 ** loss of information and return the revised type of the argument. | 308 ** loss of information and return the revised type of the argument. |
| 307 */ | 309 */ |
| 308 int sqlite3_value_numeric_type(sqlite3_value *pVal){ | 310 int sqlite3_value_numeric_type(sqlite3_value *pVal){ |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 */ | 509 */ |
| 508 static int checkSavepointCount(sqlite3 *db){ | 510 static int checkSavepointCount(sqlite3 *db){ |
| 509 int n = 0; | 511 int n = 0; |
| 510 Savepoint *p; | 512 Savepoint *p; |
| 511 for(p=db->pSavepoint; p; p=p->pNext) n++; | 513 for(p=db->pSavepoint; p; p=p->pNext) n++; |
| 512 assert( n==(db->nSavepoint + db->isTransactionSavepoint) ); | 514 assert( n==(db->nSavepoint + db->isTransactionSavepoint) ); |
| 513 return 1; | 515 return 1; |
| 514 } | 516 } |
| 515 #endif | 517 #endif |
| 516 | 518 |
| 519 /* |
| 520 ** Return the register of pOp->p2 after first preparing it to be |
| 521 ** overwritten with an integer value. |
| 522 */ |
| 523 static SQLITE_NOINLINE Mem *out2PrereleaseWithClear(Mem *pOut){ |
| 524 sqlite3VdbeMemSetNull(pOut); |
| 525 pOut->flags = MEM_Int; |
| 526 return pOut; |
| 527 } |
| 528 static Mem *out2Prerelease(Vdbe *p, VdbeOp *pOp){ |
| 529 Mem *pOut; |
| 530 assert( pOp->p2>0 ); |
| 531 assert( pOp->p2<=(p->nMem-p->nCursor) ); |
| 532 pOut = &p->aMem[pOp->p2]; |
| 533 memAboutToChange(p, pOut); |
| 534 if( VdbeMemDynamic(pOut) ){ |
| 535 return out2PrereleaseWithClear(pOut); |
| 536 }else{ |
| 537 pOut->flags = MEM_Int; |
| 538 return pOut; |
| 539 } |
| 540 } |
| 541 |
| 517 | 542 |
| 518 /* | 543 /* |
| 519 ** Execute as much of a VDBE program as we can. | 544 ** Execute as much of a VDBE program as we can. |
| 520 ** This is the core of sqlite3_step(). | 545 ** This is the core of sqlite3_step(). |
| 521 */ | 546 */ |
| 522 int sqlite3VdbeExec( | 547 int sqlite3VdbeExec( |
| 523 Vdbe *p /* The VDBE */ | 548 Vdbe *p /* The VDBE */ |
| 524 ){ | 549 ){ |
| 525 int pc=0; /* The program counter */ | |
| 526 Op *aOp = p->aOp; /* Copy of p->aOp */ | 550 Op *aOp = p->aOp; /* Copy of p->aOp */ |
| 527 Op *pOp; /* Current operation */ | 551 Op *pOp = aOp; /* Current operation */ |
| 552 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 553 Op *pOrigOp; /* Value of pOp at the top of the loop */ |
| 554 #endif |
| 528 int rc = SQLITE_OK; /* Value to return */ | 555 int rc = SQLITE_OK; /* Value to return */ |
| 529 sqlite3 *db = p->db; /* The database */ | 556 sqlite3 *db = p->db; /* The database */ |
| 530 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ | 557 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */ |
| 531 u8 encoding = ENC(db); /* The database encoding */ | 558 u8 encoding = ENC(db); /* The database encoding */ |
| 532 int iCompare = 0; /* Result of last OP_Compare operation */ | 559 int iCompare = 0; /* Result of last OP_Compare operation */ |
| 533 unsigned nVmStep = 0; /* Number of virtual machine steps */ | 560 unsigned nVmStep = 0; /* Number of virtual machine steps */ |
| 534 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK | 561 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 535 unsigned nProgressLimit = 0;/* Invoke xProgress() when nVmStep reaches this */ | 562 unsigned nProgressLimit = 0;/* Invoke xProgress() when nVmStep reaches this */ |
| 536 #endif | 563 #endif |
| 537 Mem *aMem = p->aMem; /* Copy of p->aMem */ | 564 Mem *aMem = p->aMem; /* Copy of p->aMem */ |
| 538 Mem *pIn1 = 0; /* 1st input operand */ | 565 Mem *pIn1 = 0; /* 1st input operand */ |
| 539 Mem *pIn2 = 0; /* 2nd input operand */ | 566 Mem *pIn2 = 0; /* 2nd input operand */ |
| 540 Mem *pIn3 = 0; /* 3rd input operand */ | 567 Mem *pIn3 = 0; /* 3rd input operand */ |
| 541 Mem *pOut = 0; /* Output operand */ | 568 Mem *pOut = 0; /* Output operand */ |
| 542 int *aPermute = 0; /* Permutation of columns for OP_Compare */ | 569 int *aPermute = 0; /* Permutation of columns for OP_Compare */ |
| 543 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ | 570 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ |
| 544 #ifdef VDBE_PROFILE | 571 #ifdef VDBE_PROFILE |
| 545 u64 start; /* CPU clock count at start of opcode */ | 572 u64 start; /* CPU clock count at start of opcode */ |
| 546 #endif | 573 #endif |
| 547 /*** INSERT STACK UNION HERE ***/ | 574 /*** INSERT STACK UNION HERE ***/ |
| 548 | 575 |
| 549 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ | 576 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 550 sqlite3VdbeEnter(p); | 577 sqlite3VdbeEnter(p); |
| 551 if( p->rc==SQLITE_NOMEM ){ | 578 if( p->rc==SQLITE_NOMEM ){ |
| 552 /* This happens if a malloc() inside a call to sqlite3_column_text() or | 579 /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| 553 ** sqlite3_column_text16() failed. */ | 580 ** sqlite3_column_text16() failed. */ |
| 554 goto no_mem; | 581 goto no_mem; |
| 555 } | 582 } |
| 556 assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY ); | 583 assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY ); |
| 557 assert( p->bIsReader || p->readOnly!=0 ); | 584 assert( p->bIsReader || p->readOnly!=0 ); |
| 558 p->rc = SQLITE_OK; | 585 p->rc = SQLITE_OK; |
| 559 p->iCurrentTime = 0; | 586 p->iCurrentTime = 0; |
| 560 assert( p->explain==0 ); | 587 assert( p->explain==0 ); |
| 561 p->pResultSet = 0; | 588 p->pResultSet = 0; |
| 562 db->busyHandler.nBusy = 0; | 589 db->busyHandler.nBusy = 0; |
| 563 if( db->u1.isInterrupted ) goto abort_due_to_interrupt; | 590 if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| 564 sqlite3VdbeIOTraceSql(p); | 591 sqlite3VdbeIOTraceSql(p); |
| 565 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK | 592 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 566 if( db->xProgress ){ | 593 if( db->xProgress ){ |
| 594 u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; |
| 567 assert( 0 < db->nProgressOps ); | 595 assert( 0 < db->nProgressOps ); |
| 568 nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; | 596 nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps); |
| 569 if( nProgressLimit==0 ){ | |
| 570 nProgressLimit = db->nProgressOps; | |
| 571 }else{ | |
| 572 nProgressLimit %= (unsigned)db->nProgressOps; | |
| 573 } | |
| 574 } | 597 } |
| 575 #endif | 598 #endif |
| 576 #ifdef SQLITE_DEBUG | 599 #ifdef SQLITE_DEBUG |
| 577 sqlite3BeginBenignMalloc(); | 600 sqlite3BeginBenignMalloc(); |
| 578 if( p->pc==0 | 601 if( p->pc==0 |
| 579 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0 | 602 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0 |
| 580 ){ | 603 ){ |
| 581 int i; | 604 int i; |
| 582 int once = 1; | 605 int once = 1; |
| 583 sqlite3VdbePrintSql(p); | 606 sqlite3VdbePrintSql(p); |
| 584 if( p->db->flags & SQLITE_VdbeListing ){ | 607 if( p->db->flags & SQLITE_VdbeListing ){ |
| 585 printf("VDBE Program Listing:\n"); | 608 printf("VDBE Program Listing:\n"); |
| 586 for(i=0; i<p->nOp; i++){ | 609 for(i=0; i<p->nOp; i++){ |
| 587 sqlite3VdbePrintOp(stdout, i, &aOp[i]); | 610 sqlite3VdbePrintOp(stdout, i, &aOp[i]); |
| 588 } | 611 } |
| 589 } | 612 } |
| 590 if( p->db->flags & SQLITE_VdbeEQP ){ | 613 if( p->db->flags & SQLITE_VdbeEQP ){ |
| 591 for(i=0; i<p->nOp; i++){ | 614 for(i=0; i<p->nOp; i++){ |
| 592 if( aOp[i].opcode==OP_Explain ){ | 615 if( aOp[i].opcode==OP_Explain ){ |
| 593 if( once ) printf("VDBE Query Plan:\n"); | 616 if( once ) printf("VDBE Query Plan:\n"); |
| 594 printf("%s\n", aOp[i].p4.z); | 617 printf("%s\n", aOp[i].p4.z); |
| 595 once = 0; | 618 once = 0; |
| 596 } | 619 } |
| 597 } | 620 } |
| 598 } | 621 } |
| 599 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n"); | 622 if( p->db->flags & SQLITE_VdbeTrace ) printf("VDBE Trace:\n"); |
| 600 } | 623 } |
| 601 sqlite3EndBenignMalloc(); | 624 sqlite3EndBenignMalloc(); |
| 602 #endif | 625 #endif |
| 603 for(pc=p->pc; rc==SQLITE_OK; pc++){ | 626 for(pOp=&aOp[p->pc]; rc==SQLITE_OK; pOp++){ |
| 604 assert( pc>=0 && pc<p->nOp ); | 627 assert( pOp>=aOp && pOp<&aOp[p->nOp]); |
| 605 if( db->mallocFailed ) goto no_mem; | 628 if( db->mallocFailed ) goto no_mem; |
| 606 #ifdef VDBE_PROFILE | 629 #ifdef VDBE_PROFILE |
| 607 start = sqlite3Hwtime(); | 630 start = sqlite3Hwtime(); |
| 608 #endif | 631 #endif |
| 609 nVmStep++; | 632 nVmStep++; |
| 610 pOp = &aOp[pc]; | 633 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 634 if( p->anExec ) p->anExec[(int)(pOp-aOp)]++; |
| 635 #endif |
| 611 | 636 |
| 612 /* Only allow tracing if SQLITE_DEBUG is defined. | 637 /* Only allow tracing if SQLITE_DEBUG is defined. |
| 613 */ | 638 */ |
| 614 #ifdef SQLITE_DEBUG | 639 #ifdef SQLITE_DEBUG |
| 615 if( db->flags & SQLITE_VdbeTrace ){ | 640 if( db->flags & SQLITE_VdbeTrace ){ |
| 616 sqlite3VdbePrintOp(stdout, pc, pOp); | 641 sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp); |
| 617 } | 642 } |
| 618 #endif | 643 #endif |
| 619 | 644 |
| 620 | 645 |
| 621 /* Check to see if we need to simulate an interrupt. This only happens | 646 /* Check to see if we need to simulate an interrupt. This only happens |
| 622 ** if we have a special test build. | 647 ** if we have a special test build. |
| 623 */ | 648 */ |
| 624 #ifdef SQLITE_TEST | 649 #ifdef SQLITE_TEST |
| 625 if( sqlite3_interrupt_count>0 ){ | 650 if( sqlite3_interrupt_count>0 ){ |
| 626 sqlite3_interrupt_count--; | 651 sqlite3_interrupt_count--; |
| 627 if( sqlite3_interrupt_count==0 ){ | 652 if( sqlite3_interrupt_count==0 ){ |
| 628 sqlite3_interrupt(db); | 653 sqlite3_interrupt(db); |
| 629 } | 654 } |
| 630 } | 655 } |
| 631 #endif | 656 #endif |
| 632 | 657 |
| 633 /* On any opcode with the "out2-prerelease" tag, free any | |
| 634 ** external allocations out of mem[p2] and set mem[p2] to be | |
| 635 ** an undefined integer. Opcodes will either fill in the integer | |
| 636 ** value or convert mem[p2] to a different type. | |
| 637 */ | |
| 638 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); | |
| 639 if( pOp->opflags & OPFLG_OUT2_PRERELEASE ){ | |
| 640 assert( pOp->p2>0 ); | |
| 641 assert( pOp->p2<=(p->nMem-p->nCursor) ); | |
| 642 pOut = &aMem[pOp->p2]; | |
| 643 memAboutToChange(p, pOut); | |
| 644 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut); | |
| 645 pOut->flags = MEM_Int; | |
| 646 } | |
| 647 | |
| 648 /* Sanity checking on other operands */ | 658 /* Sanity checking on other operands */ |
| 649 #ifdef SQLITE_DEBUG | 659 #ifdef SQLITE_DEBUG |
| 660 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); |
| 650 if( (pOp->opflags & OPFLG_IN1)!=0 ){ | 661 if( (pOp->opflags & OPFLG_IN1)!=0 ){ |
| 651 assert( pOp->p1>0 ); | 662 assert( pOp->p1>0 ); |
| 652 assert( pOp->p1<=(p->nMem-p->nCursor) ); | 663 assert( pOp->p1<=(p->nMem-p->nCursor) ); |
| 653 assert( memIsValid(&aMem[pOp->p1]) ); | 664 assert( memIsValid(&aMem[pOp->p1]) ); |
| 654 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) ); | 665 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) ); |
| 655 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]); | 666 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]); |
| 656 } | 667 } |
| 657 if( (pOp->opflags & OPFLG_IN2)!=0 ){ | 668 if( (pOp->opflags & OPFLG_IN2)!=0 ){ |
| 658 assert( pOp->p2>0 ); | 669 assert( pOp->p2>0 ); |
| 659 assert( pOp->p2<=(p->nMem-p->nCursor) ); | 670 assert( pOp->p2<=(p->nMem-p->nCursor) ); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 672 assert( pOp->p2>0 ); | 683 assert( pOp->p2>0 ); |
| 673 assert( pOp->p2<=(p->nMem-p->nCursor) ); | 684 assert( pOp->p2<=(p->nMem-p->nCursor) ); |
| 674 memAboutToChange(p, &aMem[pOp->p2]); | 685 memAboutToChange(p, &aMem[pOp->p2]); |
| 675 } | 686 } |
| 676 if( (pOp->opflags & OPFLG_OUT3)!=0 ){ | 687 if( (pOp->opflags & OPFLG_OUT3)!=0 ){ |
| 677 assert( pOp->p3>0 ); | 688 assert( pOp->p3>0 ); |
| 678 assert( pOp->p3<=(p->nMem-p->nCursor) ); | 689 assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 679 memAboutToChange(p, &aMem[pOp->p3]); | 690 memAboutToChange(p, &aMem[pOp->p3]); |
| 680 } | 691 } |
| 681 #endif | 692 #endif |
| 693 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 694 pOrigOp = pOp; |
| 695 #endif |
| 682 | 696 |
| 683 switch( pOp->opcode ){ | 697 switch( pOp->opcode ){ |
| 684 | 698 |
| 685 /***************************************************************************** | 699 /***************************************************************************** |
| 686 ** What follows is a massive switch statement where each case implements a | 700 ** What follows is a massive switch statement where each case implements a |
| 687 ** separate instruction in the virtual machine. If we follow the usual | 701 ** separate instruction in the virtual machine. If we follow the usual |
| 688 ** indentation conventions, each case should be indented by 6 spaces. But | 702 ** indentation conventions, each case should be indented by 6 spaces. But |
| 689 ** that is a lot of wasted space on the left margin. So the code within | 703 ** that is a lot of wasted space on the left margin. So the code within |
| 690 ** the switch statement will break with convention and be flush-left. Another | 704 ** the switch statement will break with convention and be flush-left. Another |
| 691 ** big comment (similar to this one) will mark the point in the code where | 705 ** big comment (similar to this one) will mark the point in the code where |
| 692 ** we transition back to normal indentation. | 706 ** we transition back to normal indentation. |
| 693 ** | 707 ** |
| 694 ** The formatting of each case is important. The makefile for SQLite | 708 ** The formatting of each case is important. The makefile for SQLite |
| 695 ** generates two C files "opcodes.h" and "opcodes.c" by scanning this | 709 ** generates two C files "opcodes.h" and "opcodes.c" by scanning this |
| 696 ** file looking for lines that begin with "case OP_". The opcodes.h files | 710 ** file looking for lines that begin with "case OP_". The opcodes.h files |
| 697 ** will be filled with #defines that give unique integer values to each | 711 ** will be filled with #defines that give unique integer values to each |
| 698 ** opcode and the opcodes.c file is filled with an array of strings where | 712 ** opcode and the opcodes.c file is filled with an array of strings where |
| 699 ** each string is the symbolic name for the corresponding opcode. If the | 713 ** each string is the symbolic name for the corresponding opcode. If the |
| 700 ** case statement is followed by a comment of the form "/# same as ... #/" | 714 ** case statement is followed by a comment of the form "/# same as ... #/" |
| 701 ** that comment is used to determine the particular value of the opcode. | 715 ** that comment is used to determine the particular value of the opcode. |
| 702 ** | 716 ** |
| 703 ** Other keywords in the comment that follows each case are used to | 717 ** Other keywords in the comment that follows each case are used to |
| 704 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[]. | 718 ** construct the OPFLG_INITIALIZER value that initializes opcodeProperty[]. |
| 705 ** Keywords include: in1, in2, in3, out2_prerelease, out2, out3. See | 719 ** Keywords include: in1, in2, in3, out2, out3. See |
| 706 ** the mkopcodeh.awk script for additional information. | 720 ** the mkopcodeh.awk script for additional information. |
| 707 ** | 721 ** |
| 708 ** Documentation about VDBE opcodes is generated by scanning this file | 722 ** Documentation about VDBE opcodes is generated by scanning this file |
| 709 ** for lines of that contain "Opcode:". That line and all subsequent | 723 ** for lines of that contain "Opcode:". That line and all subsequent |
| 710 ** comment lines are used in the generation of the opcode.html documentation | 724 ** comment lines are used in the generation of the opcode.html documentation |
| 711 ** file. | 725 ** file. |
| 712 ** | 726 ** |
| 713 ** SUMMARY: | 727 ** SUMMARY: |
| 714 ** | 728 ** |
| 715 ** Formatting is important to scripts that scan this file. | 729 ** Formatting is important to scripts that scan this file. |
| 716 ** Do not deviate from the formatting style currently in use. | 730 ** Do not deviate from the formatting style currently in use. |
| 717 ** | 731 ** |
| 718 *****************************************************************************/ | 732 *****************************************************************************/ |
| 719 | 733 |
| 720 /* Opcode: Goto * P2 * * * | 734 /* Opcode: Goto * P2 * * * |
| 721 ** | 735 ** |
| 722 ** An unconditional jump to address P2. | 736 ** An unconditional jump to address P2. |
| 723 ** The next instruction executed will be | 737 ** The next instruction executed will be |
| 724 ** the one at index P2 from the beginning of | 738 ** the one at index P2 from the beginning of |
| 725 ** the program. | 739 ** the program. |
| 726 ** | 740 ** |
| 727 ** The P1 parameter is not actually used by this opcode. However, it | 741 ** The P1 parameter is not actually used by this opcode. However, it |
| 728 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell | 742 ** is sometimes set to 1 instead of 0 as a hint to the command-line shell |
| 729 ** that this Goto is the bottom of a loop and that the lines from P2 down | 743 ** that this Goto is the bottom of a loop and that the lines from P2 down |
| 730 ** to the current line should be indented for EXPLAIN output. | 744 ** to the current line should be indented for EXPLAIN output. |
| 731 */ | 745 */ |
| 732 case OP_Goto: { /* jump */ | 746 case OP_Goto: { /* jump */ |
| 733 pc = pOp->p2 - 1; | 747 jump_to_p2_and_check_for_interrupt: |
| 748 pOp = &aOp[pOp->p2 - 1]; |
| 734 | 749 |
| 735 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, | 750 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, |
| 736 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon | 751 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon |
| 737 ** completion. Check to see if sqlite3_interrupt() has been called | 752 ** completion. Check to see if sqlite3_interrupt() has been called |
| 738 ** or if the progress callback needs to be invoked. | 753 ** or if the progress callback needs to be invoked. |
| 739 ** | 754 ** |
| 740 ** This code uses unstructured "goto" statements and does not look clean. | 755 ** This code uses unstructured "goto" statements and does not look clean. |
| 741 ** But that is not due to sloppy coding habits. The code is written this | 756 ** But that is not due to sloppy coding habits. The code is written this |
| 742 ** way for performance, to avoid having to run the interrupt and progress | 757 ** way for performance, to avoid having to run the interrupt and progress |
| 743 ** checks on every opcode. This helps sqlite3_step() to run about 1.5% | 758 ** checks on every opcode. This helps sqlite3_step() to run about 1.5% |
| (...skipping 24 matching lines...) Expand all Loading... |
| 768 ** | 783 ** |
| 769 ** Write the current address onto register P1 | 784 ** Write the current address onto register P1 |
| 770 ** and then jump to address P2. | 785 ** and then jump to address P2. |
| 771 */ | 786 */ |
| 772 case OP_Gosub: { /* jump */ | 787 case OP_Gosub: { /* jump */ |
| 773 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); | 788 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 774 pIn1 = &aMem[pOp->p1]; | 789 pIn1 = &aMem[pOp->p1]; |
| 775 assert( VdbeMemDynamic(pIn1)==0 ); | 790 assert( VdbeMemDynamic(pIn1)==0 ); |
| 776 memAboutToChange(p, pIn1); | 791 memAboutToChange(p, pIn1); |
| 777 pIn1->flags = MEM_Int; | 792 pIn1->flags = MEM_Int; |
| 778 pIn1->u.i = pc; | 793 pIn1->u.i = (int)(pOp-aOp); |
| 779 REGISTER_TRACE(pOp->p1, pIn1); | 794 REGISTER_TRACE(pOp->p1, pIn1); |
| 780 pc = pOp->p2 - 1; | 795 |
| 796 /* Most jump operations do a goto to this spot in order to update |
| 797 ** the pOp pointer. */ |
| 798 jump_to_p2: |
| 799 pOp = &aOp[pOp->p2 - 1]; |
| 781 break; | 800 break; |
| 782 } | 801 } |
| 783 | 802 |
| 784 /* Opcode: Return P1 * * * * | 803 /* Opcode: Return P1 * * * * |
| 785 ** | 804 ** |
| 786 ** Jump to the next instruction after the address in register P1. After | 805 ** Jump to the next instruction after the address in register P1. After |
| 787 ** the jump, register P1 becomes undefined. | 806 ** the jump, register P1 becomes undefined. |
| 788 */ | 807 */ |
| 789 case OP_Return: { /* in1 */ | 808 case OP_Return: { /* in1 */ |
| 790 pIn1 = &aMem[pOp->p1]; | 809 pIn1 = &aMem[pOp->p1]; |
| 791 assert( pIn1->flags==MEM_Int ); | 810 assert( pIn1->flags==MEM_Int ); |
| 792 pc = (int)pIn1->u.i; | 811 pOp = &aOp[pIn1->u.i]; |
| 793 pIn1->flags = MEM_Undefined; | 812 pIn1->flags = MEM_Undefined; |
| 794 break; | 813 break; |
| 795 } | 814 } |
| 796 | 815 |
| 797 /* Opcode: InitCoroutine P1 P2 P3 * * | 816 /* Opcode: InitCoroutine P1 P2 P3 * * |
| 798 ** | 817 ** |
| 799 ** Set up register P1 so that it will Yield to the coroutine | 818 ** Set up register P1 so that it will Yield to the coroutine |
| 800 ** located at address P3. | 819 ** located at address P3. |
| 801 ** | 820 ** |
| 802 ** If P2!=0 then the coroutine implementation immediately follows | 821 ** If P2!=0 then the coroutine implementation immediately follows |
| 803 ** this opcode. So jump over the coroutine implementation to | 822 ** this opcode. So jump over the coroutine implementation to |
| 804 ** address P2. | 823 ** address P2. |
| 805 ** | 824 ** |
| 806 ** See also: EndCoroutine | 825 ** See also: EndCoroutine |
| 807 */ | 826 */ |
| 808 case OP_InitCoroutine: { /* jump */ | 827 case OP_InitCoroutine: { /* jump */ |
| 809 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); | 828 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 810 assert( pOp->p2>=0 && pOp->p2<p->nOp ); | 829 assert( pOp->p2>=0 && pOp->p2<p->nOp ); |
| 811 assert( pOp->p3>=0 && pOp->p3<p->nOp ); | 830 assert( pOp->p3>=0 && pOp->p3<p->nOp ); |
| 812 pOut = &aMem[pOp->p1]; | 831 pOut = &aMem[pOp->p1]; |
| 813 assert( !VdbeMemDynamic(pOut) ); | 832 assert( !VdbeMemDynamic(pOut) ); |
| 814 pOut->u.i = pOp->p3 - 1; | 833 pOut->u.i = pOp->p3 - 1; |
| 815 pOut->flags = MEM_Int; | 834 pOut->flags = MEM_Int; |
| 816 if( pOp->p2 ) pc = pOp->p2 - 1; | 835 if( pOp->p2 ) goto jump_to_p2; |
| 817 break; | 836 break; |
| 818 } | 837 } |
| 819 | 838 |
| 820 /* Opcode: EndCoroutine P1 * * * * | 839 /* Opcode: EndCoroutine P1 * * * * |
| 821 ** | 840 ** |
| 822 ** The instruction at the address in register P1 is a Yield. | 841 ** The instruction at the address in register P1 is a Yield. |
| 823 ** Jump to the P2 parameter of that Yield. | 842 ** Jump to the P2 parameter of that Yield. |
| 824 ** After the jump, register P1 becomes undefined. | 843 ** After the jump, register P1 becomes undefined. |
| 825 ** | 844 ** |
| 826 ** See also: InitCoroutine | 845 ** See also: InitCoroutine |
| 827 */ | 846 */ |
| 828 case OP_EndCoroutine: { /* in1 */ | 847 case OP_EndCoroutine: { /* in1 */ |
| 829 VdbeOp *pCaller; | 848 VdbeOp *pCaller; |
| 830 pIn1 = &aMem[pOp->p1]; | 849 pIn1 = &aMem[pOp->p1]; |
| 831 assert( pIn1->flags==MEM_Int ); | 850 assert( pIn1->flags==MEM_Int ); |
| 832 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp ); | 851 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp ); |
| 833 pCaller = &aOp[pIn1->u.i]; | 852 pCaller = &aOp[pIn1->u.i]; |
| 834 assert( pCaller->opcode==OP_Yield ); | 853 assert( pCaller->opcode==OP_Yield ); |
| 835 assert( pCaller->p2>=0 && pCaller->p2<p->nOp ); | 854 assert( pCaller->p2>=0 && pCaller->p2<p->nOp ); |
| 836 pc = pCaller->p2 - 1; | 855 pOp = &aOp[pCaller->p2 - 1]; |
| 837 pIn1->flags = MEM_Undefined; | 856 pIn1->flags = MEM_Undefined; |
| 838 break; | 857 break; |
| 839 } | 858 } |
| 840 | 859 |
| 841 /* Opcode: Yield P1 P2 * * * | 860 /* Opcode: Yield P1 P2 * * * |
| 842 ** | 861 ** |
| 843 ** Swap the program counter with the value in register P1. This | 862 ** Swap the program counter with the value in register P1. This |
| 844 ** has the effect of yielding to a coroutine. | 863 ** has the effect of yielding to a coroutine. |
| 845 ** | 864 ** |
| 846 ** If the coroutine that is launched by this instruction ends with | 865 ** If the coroutine that is launched by this instruction ends with |
| 847 ** Yield or Return then continue to the next instruction. But if | 866 ** Yield or Return then continue to the next instruction. But if |
| 848 ** the coroutine launched by this instruction ends with | 867 ** the coroutine launched by this instruction ends with |
| 849 ** EndCoroutine, then jump to P2 rather than continuing with the | 868 ** EndCoroutine, then jump to P2 rather than continuing with the |
| 850 ** next instruction. | 869 ** next instruction. |
| 851 ** | 870 ** |
| 852 ** See also: InitCoroutine | 871 ** See also: InitCoroutine |
| 853 */ | 872 */ |
| 854 case OP_Yield: { /* in1, jump */ | 873 case OP_Yield: { /* in1, jump */ |
| 855 int pcDest; | 874 int pcDest; |
| 856 pIn1 = &aMem[pOp->p1]; | 875 pIn1 = &aMem[pOp->p1]; |
| 857 assert( VdbeMemDynamic(pIn1)==0 ); | 876 assert( VdbeMemDynamic(pIn1)==0 ); |
| 858 pIn1->flags = MEM_Int; | 877 pIn1->flags = MEM_Int; |
| 859 pcDest = (int)pIn1->u.i; | 878 pcDest = (int)pIn1->u.i; |
| 860 pIn1->u.i = pc; | 879 pIn1->u.i = (int)(pOp - aOp); |
| 861 REGISTER_TRACE(pOp->p1, pIn1); | 880 REGISTER_TRACE(pOp->p1, pIn1); |
| 862 pc = pcDest; | 881 pOp = &aOp[pcDest]; |
| 863 break; | 882 break; |
| 864 } | 883 } |
| 865 | 884 |
| 866 /* Opcode: HaltIfNull P1 P2 P3 P4 P5 | 885 /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 867 ** Synopsis: if r[P3]=null halt | 886 ** Synopsis: if r[P3]=null halt |
| 868 ** | 887 ** |
| 869 ** Check the value in register P3. If it is NULL then Halt using | 888 ** Check the value in register P3. If it is NULL then Halt using |
| 870 ** parameter P1, P2, and P4 as if this were a Halt instruction. If the | 889 ** parameter P1, P2, and P4 as if this were a Halt instruction. If the |
| 871 ** value in register P3 is not NULL, then this routine is a no-op. | 890 ** value in register P3 is not NULL, then this routine is a no-op. |
| 872 ** The P5 parameter should be 1. | 891 ** The P5 parameter should be 1. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 903 ** If P5 is not zero and P4 is NULL, then everything after the ":" is | 922 ** If P5 is not zero and P4 is NULL, then everything after the ":" is |
| 904 ** omitted. | 923 ** omitted. |
| 905 ** | 924 ** |
| 906 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of | 925 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of |
| 907 ** every program. So a jump past the last instruction of the program | 926 ** every program. So a jump past the last instruction of the program |
| 908 ** is the same as executing Halt. | 927 ** is the same as executing Halt. |
| 909 */ | 928 */ |
| 910 case OP_Halt: { | 929 case OP_Halt: { |
| 911 const char *zType; | 930 const char *zType; |
| 912 const char *zLogFmt; | 931 const char *zLogFmt; |
| 932 VdbeFrame *pFrame; |
| 933 int pcx; |
| 913 | 934 |
| 935 pcx = (int)(pOp - aOp); |
| 914 if( pOp->p1==SQLITE_OK && p->pFrame ){ | 936 if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 915 /* Halt the sub-program. Return control to the parent frame. */ | 937 /* Halt the sub-program. Return control to the parent frame. */ |
| 916 VdbeFrame *pFrame = p->pFrame; | 938 pFrame = p->pFrame; |
| 917 p->pFrame = pFrame->pParent; | 939 p->pFrame = pFrame->pParent; |
| 918 p->nFrame--; | 940 p->nFrame--; |
| 919 sqlite3VdbeSetChanges(db, p->nChange); | 941 sqlite3VdbeSetChanges(db, p->nChange); |
| 920 pc = sqlite3VdbeFrameRestore(pFrame); | 942 pcx = sqlite3VdbeFrameRestore(pFrame); |
| 921 lastRowid = db->lastRowid; | 943 lastRowid = db->lastRowid; |
| 922 if( pOp->p2==OE_Ignore ){ | 944 if( pOp->p2==OE_Ignore ){ |
| 923 /* Instruction pc is the OP_Program that invoked the sub-program | 945 /* Instruction pcx is the OP_Program that invoked the sub-program |
| 924 ** currently being halted. If the p2 instruction of this OP_Halt | 946 ** currently being halted. If the p2 instruction of this OP_Halt |
| 925 ** instruction is set to OE_Ignore, then the sub-program is throwing | 947 ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 926 ** an IGNORE exception. In this case jump to the address specified | 948 ** an IGNORE exception. In this case jump to the address specified |
| 927 ** as the p2 of the calling OP_Program. */ | 949 ** as the p2 of the calling OP_Program. */ |
| 928 pc = p->aOp[pc].p2-1; | 950 pcx = p->aOp[pcx].p2-1; |
| 929 } | 951 } |
| 930 aOp = p->aOp; | 952 aOp = p->aOp; |
| 931 aMem = p->aMem; | 953 aMem = p->aMem; |
| 954 pOp = &aOp[pcx]; |
| 932 break; | 955 break; |
| 933 } | 956 } |
| 934 p->rc = pOp->p1; | 957 p->rc = pOp->p1; |
| 935 p->errorAction = (u8)pOp->p2; | 958 p->errorAction = (u8)pOp->p2; |
| 936 p->pc = pc; | 959 p->pc = pcx; |
| 937 if( p->rc ){ | 960 if( p->rc ){ |
| 938 if( pOp->p5 ){ | 961 if( pOp->p5 ){ |
| 939 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", | 962 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", |
| 940 "FOREIGN KEY" }; | 963 "FOREIGN KEY" }; |
| 941 assert( pOp->p5>=1 && pOp->p5<=4 ); | 964 assert( pOp->p5>=1 && pOp->p5<=4 ); |
| 942 testcase( pOp->p5==1 ); | 965 testcase( pOp->p5==1 ); |
| 943 testcase( pOp->p5==2 ); | 966 testcase( pOp->p5==2 ); |
| 944 testcase( pOp->p5==3 ); | 967 testcase( pOp->p5==3 ); |
| 945 testcase( pOp->p5==4 ); | 968 testcase( pOp->p5==4 ); |
| 946 zType = azType[pOp->p5-1]; | 969 zType = azType[pOp->p5-1]; |
| 947 }else{ | 970 }else{ |
| 948 zType = 0; | 971 zType = 0; |
| 949 } | 972 } |
| 950 assert( zType!=0 || pOp->p4.z!=0 ); | 973 assert( zType!=0 || pOp->p4.z!=0 ); |
| 951 zLogFmt = "abort at %d in [%s]: %s"; | 974 zLogFmt = "abort at %d in [%s]: %s"; |
| 952 if( zType && pOp->p4.z ){ | 975 if( zType && pOp->p4.z ){ |
| 953 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s", | 976 sqlite3VdbeError(p, "%s constraint failed: %s", zType, pOp->p4.z); |
| 954 zType, pOp->p4.z); | |
| 955 }else if( pOp->p4.z ){ | 977 }else if( pOp->p4.z ){ |
| 956 sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); | 978 sqlite3VdbeError(p, "%s", pOp->p4.z); |
| 957 }else{ | 979 }else{ |
| 958 sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); | 980 sqlite3VdbeError(p, "%s constraint failed", zType); |
| 959 } | 981 } |
| 960 sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg); | 982 sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg); |
| 961 } | 983 } |
| 962 rc = sqlite3VdbeHalt(p); | 984 rc = sqlite3VdbeHalt(p); |
| 963 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); | 985 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 964 if( rc==SQLITE_BUSY ){ | 986 if( rc==SQLITE_BUSY ){ |
| 965 p->rc = rc = SQLITE_BUSY; | 987 p->rc = rc = SQLITE_BUSY; |
| 966 }else{ | 988 }else{ |
| 967 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ); | 989 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ); |
| 968 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 ); | 990 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 ); |
| 969 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; | 991 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; |
| 970 } | 992 } |
| 971 goto vdbe_return; | 993 goto vdbe_return; |
| 972 } | 994 } |
| 973 | 995 |
| 974 /* Opcode: Integer P1 P2 * * * | 996 /* Opcode: Integer P1 P2 * * * |
| 975 ** Synopsis: r[P2]=P1 | 997 ** Synopsis: r[P2]=P1 |
| 976 ** | 998 ** |
| 977 ** The 32-bit integer value P1 is written into register P2. | 999 ** The 32-bit integer value P1 is written into register P2. |
| 978 */ | 1000 */ |
| 979 case OP_Integer: { /* out2-prerelease */ | 1001 case OP_Integer: { /* out2 */ |
| 1002 pOut = out2Prerelease(p, pOp); |
| 980 pOut->u.i = pOp->p1; | 1003 pOut->u.i = pOp->p1; |
| 981 break; | 1004 break; |
| 982 } | 1005 } |
| 983 | 1006 |
| 984 /* Opcode: Int64 * P2 * P4 * | 1007 /* Opcode: Int64 * P2 * P4 * |
| 985 ** Synopsis: r[P2]=P4 | 1008 ** Synopsis: r[P2]=P4 |
| 986 ** | 1009 ** |
| 987 ** P4 is a pointer to a 64-bit integer value. | 1010 ** P4 is a pointer to a 64-bit integer value. |
| 988 ** Write that value into register P2. | 1011 ** Write that value into register P2. |
| 989 */ | 1012 */ |
| 990 case OP_Int64: { /* out2-prerelease */ | 1013 case OP_Int64: { /* out2 */ |
| 1014 pOut = out2Prerelease(p, pOp); |
| 991 assert( pOp->p4.pI64!=0 ); | 1015 assert( pOp->p4.pI64!=0 ); |
| 992 pOut->u.i = *pOp->p4.pI64; | 1016 pOut->u.i = *pOp->p4.pI64; |
| 993 break; | 1017 break; |
| 994 } | 1018 } |
| 995 | 1019 |
| 996 #ifndef SQLITE_OMIT_FLOATING_POINT | 1020 #ifndef SQLITE_OMIT_FLOATING_POINT |
| 997 /* Opcode: Real * P2 * P4 * | 1021 /* Opcode: Real * P2 * P4 * |
| 998 ** Synopsis: r[P2]=P4 | 1022 ** Synopsis: r[P2]=P4 |
| 999 ** | 1023 ** |
| 1000 ** P4 is a pointer to a 64-bit floating point value. | 1024 ** P4 is a pointer to a 64-bit floating point value. |
| 1001 ** Write that value into register P2. | 1025 ** Write that value into register P2. |
| 1002 */ | 1026 */ |
| 1003 case OP_Real: { /* same as TK_FLOAT, out2-prerelease */ | 1027 case OP_Real: { /* same as TK_FLOAT, out2 */ |
| 1028 pOut = out2Prerelease(p, pOp); |
| 1004 pOut->flags = MEM_Real; | 1029 pOut->flags = MEM_Real; |
| 1005 assert( !sqlite3IsNaN(*pOp->p4.pReal) ); | 1030 assert( !sqlite3IsNaN(*pOp->p4.pReal) ); |
| 1006 pOut->u.r = *pOp->p4.pReal; | 1031 pOut->u.r = *pOp->p4.pReal; |
| 1007 break; | 1032 break; |
| 1008 } | 1033 } |
| 1009 #endif | 1034 #endif |
| 1010 | 1035 |
| 1011 /* Opcode: String8 * P2 * P4 * | 1036 /* Opcode: String8 * P2 * P4 * |
| 1012 ** Synopsis: r[P2]='P4' | 1037 ** Synopsis: r[P2]='P4' |
| 1013 ** | 1038 ** |
| 1014 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed | 1039 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed |
| 1015 ** into a String before it is executed for the first time. During | 1040 ** into a String opcode before it is executed for the first time. During |
| 1016 ** this transformation, the length of string P4 is computed and stored | 1041 ** this transformation, the length of string P4 is computed and stored |
| 1017 ** as the P1 parameter. | 1042 ** as the P1 parameter. |
| 1018 */ | 1043 */ |
| 1019 case OP_String8: { /* same as TK_STRING, out2-prerelease */ | 1044 case OP_String8: { /* same as TK_STRING, out2 */ |
| 1020 assert( pOp->p4.z!=0 ); | 1045 assert( pOp->p4.z!=0 ); |
| 1046 pOut = out2Prerelease(p, pOp); |
| 1021 pOp->opcode = OP_String; | 1047 pOp->opcode = OP_String; |
| 1022 pOp->p1 = sqlite3Strlen30(pOp->p4.z); | 1048 pOp->p1 = sqlite3Strlen30(pOp->p4.z); |
| 1023 | 1049 |
| 1024 #ifndef SQLITE_OMIT_UTF16 | 1050 #ifndef SQLITE_OMIT_UTF16 |
| 1025 if( encoding!=SQLITE_UTF8 ){ | 1051 if( encoding!=SQLITE_UTF8 ){ |
| 1026 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC); | 1052 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC); |
| 1027 if( rc==SQLITE_TOOBIG ) goto too_big; | 1053 if( rc==SQLITE_TOOBIG ) goto too_big; |
| 1028 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem; | 1054 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem; |
| 1029 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z ); | 1055 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z ); |
| 1030 assert( VdbeMemDynamic(pOut)==0 ); | 1056 assert( VdbeMemDynamic(pOut)==0 ); |
| 1031 pOut->szMalloc = 0; | 1057 pOut->szMalloc = 0; |
| 1032 pOut->flags |= MEM_Static; | 1058 pOut->flags |= MEM_Static; |
| 1033 if( pOp->p4type==P4_DYNAMIC ){ | 1059 if( pOp->p4type==P4_DYNAMIC ){ |
| 1034 sqlite3DbFree(db, pOp->p4.z); | 1060 sqlite3DbFree(db, pOp->p4.z); |
| 1035 } | 1061 } |
| 1036 pOp->p4type = P4_DYNAMIC; | 1062 pOp->p4type = P4_DYNAMIC; |
| 1037 pOp->p4.z = pOut->z; | 1063 pOp->p4.z = pOut->z; |
| 1038 pOp->p1 = pOut->n; | 1064 pOp->p1 = pOut->n; |
| 1039 } | 1065 } |
| 1040 #endif | 1066 #endif |
| 1041 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | 1067 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 1042 goto too_big; | 1068 goto too_big; |
| 1043 } | 1069 } |
| 1044 /* Fall through to the next case, OP_String */ | 1070 /* Fall through to the next case, OP_String */ |
| 1045 } | 1071 } |
| 1046 | 1072 |
| 1047 /* Opcode: String P1 P2 * P4 * | 1073 /* Opcode: String P1 P2 P3 P4 P5 |
| 1048 ** Synopsis: r[P2]='P4' (len=P1) | 1074 ** Synopsis: r[P2]='P4' (len=P1) |
| 1049 ** | 1075 ** |
| 1050 ** The string value P4 of length P1 (bytes) is stored in register P2. | 1076 ** The string value P4 of length P1 (bytes) is stored in register P2. |
| 1077 ** |
| 1078 ** If P5!=0 and the content of register P3 is greater than zero, then |
| 1079 ** the datatype of the register P2 is converted to BLOB. The content is |
| 1080 ** the same sequence of bytes, it is merely interpreted as a BLOB instead |
| 1081 ** of a string, as if it had been CAST. |
| 1051 */ | 1082 */ |
| 1052 case OP_String: { /* out2-prerelease */ | 1083 case OP_String: { /* out2 */ |
| 1053 assert( pOp->p4.z!=0 ); | 1084 assert( pOp->p4.z!=0 ); |
| 1085 pOut = out2Prerelease(p, pOp); |
| 1054 pOut->flags = MEM_Str|MEM_Static|MEM_Term; | 1086 pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 1055 pOut->z = pOp->p4.z; | 1087 pOut->z = pOp->p4.z; |
| 1056 pOut->n = pOp->p1; | 1088 pOut->n = pOp->p1; |
| 1057 pOut->enc = encoding; | 1089 pOut->enc = encoding; |
| 1058 UPDATE_MAX_BLOBSIZE(pOut); | 1090 UPDATE_MAX_BLOBSIZE(pOut); |
| 1091 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 1092 if( pOp->p5 ){ |
| 1093 assert( pOp->p3>0 ); |
| 1094 assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 1095 pIn3 = &aMem[pOp->p3]; |
| 1096 assert( pIn3->flags & MEM_Int ); |
| 1097 if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term; |
| 1098 } |
| 1099 #endif |
| 1059 break; | 1100 break; |
| 1060 } | 1101 } |
| 1061 | 1102 |
| 1062 /* Opcode: Null P1 P2 P3 * * | 1103 /* Opcode: Null P1 P2 P3 * * |
| 1063 ** Synopsis: r[P2..P3]=NULL | 1104 ** Synopsis: r[P2..P3]=NULL |
| 1064 ** | 1105 ** |
| 1065 ** Write a NULL into registers P2. If P3 greater than P2, then also write | 1106 ** Write a NULL into registers P2. If P3 greater than P2, then also write |
| 1066 ** NULL into register P3 and every register in between P2 and P3. If P3 | 1107 ** NULL into register P3 and every register in between P2 and P3. If P3 |
| 1067 ** is less than P2 (typically P3 is zero) then only register P2 is | 1108 ** is less than P2 (typically P3 is zero) then only register P2 is |
| 1068 ** set to NULL. | 1109 ** set to NULL. |
| 1069 ** | 1110 ** |
| 1070 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that | 1111 ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 1071 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on | 1112 ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 1072 ** OP_Ne or OP_Eq. | 1113 ** OP_Ne or OP_Eq. |
| 1073 */ | 1114 */ |
| 1074 case OP_Null: { /* out2-prerelease */ | 1115 case OP_Null: { /* out2 */ |
| 1075 int cnt; | 1116 int cnt; |
| 1076 u16 nullFlag; | 1117 u16 nullFlag; |
| 1118 pOut = out2Prerelease(p, pOp); |
| 1077 cnt = pOp->p3-pOp->p2; | 1119 cnt = pOp->p3-pOp->p2; |
| 1078 assert( pOp->p3<=(p->nMem-p->nCursor) ); | 1120 assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 1079 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; | 1121 pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 1080 while( cnt>0 ){ | 1122 while( cnt>0 ){ |
| 1081 pOut++; | 1123 pOut++; |
| 1082 memAboutToChange(p, pOut); | 1124 memAboutToChange(p, pOut); |
| 1083 sqlite3VdbeMemSetNull(pOut); | 1125 sqlite3VdbeMemSetNull(pOut); |
| 1084 pOut->flags = nullFlag; | 1126 pOut->flags = nullFlag; |
| 1085 cnt--; | 1127 cnt--; |
| 1086 } | 1128 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1101 pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined; | 1143 pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined; |
| 1102 break; | 1144 break; |
| 1103 } | 1145 } |
| 1104 | 1146 |
| 1105 /* Opcode: Blob P1 P2 * P4 * | 1147 /* Opcode: Blob P1 P2 * P4 * |
| 1106 ** Synopsis: r[P2]=P4 (len=P1) | 1148 ** Synopsis: r[P2]=P4 (len=P1) |
| 1107 ** | 1149 ** |
| 1108 ** P4 points to a blob of data P1 bytes long. Store this | 1150 ** P4 points to a blob of data P1 bytes long. Store this |
| 1109 ** blob in register P2. | 1151 ** blob in register P2. |
| 1110 */ | 1152 */ |
| 1111 case OP_Blob: { /* out2-prerelease */ | 1153 case OP_Blob: { /* out2 */ |
| 1112 assert( pOp->p1 <= SQLITE_MAX_LENGTH ); | 1154 assert( pOp->p1 <= SQLITE_MAX_LENGTH ); |
| 1155 pOut = out2Prerelease(p, pOp); |
| 1113 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); | 1156 sqlite3VdbeMemSetStr(pOut, pOp->p4.z, pOp->p1, 0, 0); |
| 1114 pOut->enc = encoding; | 1157 pOut->enc = encoding; |
| 1115 UPDATE_MAX_BLOBSIZE(pOut); | 1158 UPDATE_MAX_BLOBSIZE(pOut); |
| 1116 break; | 1159 break; |
| 1117 } | 1160 } |
| 1118 | 1161 |
| 1119 /* Opcode: Variable P1 P2 * P4 * | 1162 /* Opcode: Variable P1 P2 * P4 * |
| 1120 ** Synopsis: r[P2]=parameter(P1,P4) | 1163 ** Synopsis: r[P2]=parameter(P1,P4) |
| 1121 ** | 1164 ** |
| 1122 ** Transfer the values of bound parameter P1 into register P2 | 1165 ** Transfer the values of bound parameter P1 into register P2 |
| 1123 ** | 1166 ** |
| 1124 ** If the parameter is named, then its name appears in P4. | 1167 ** If the parameter is named, then its name appears in P4. |
| 1125 ** The P4 value is used by sqlite3_bind_parameter_name(). | 1168 ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 1126 */ | 1169 */ |
| 1127 case OP_Variable: { /* out2-prerelease */ | 1170 case OP_Variable: { /* out2 */ |
| 1128 Mem *pVar; /* Value being transferred */ | 1171 Mem *pVar; /* Value being transferred */ |
| 1129 | 1172 |
| 1130 assert( pOp->p1>0 && pOp->p1<=p->nVar ); | 1173 assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 1131 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); | 1174 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 1132 pVar = &p->aVar[pOp->p1 - 1]; | 1175 pVar = &p->aVar[pOp->p1 - 1]; |
| 1133 if( sqlite3VdbeMemTooBig(pVar) ){ | 1176 if( sqlite3VdbeMemTooBig(pVar) ){ |
| 1134 goto too_big; | 1177 goto too_big; |
| 1135 } | 1178 } |
| 1179 pOut = out2Prerelease(p, pOp); |
| 1136 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); | 1180 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 1137 UPDATE_MAX_BLOBSIZE(pOut); | 1181 UPDATE_MAX_BLOBSIZE(pOut); |
| 1138 break; | 1182 break; |
| 1139 } | 1183 } |
| 1140 | 1184 |
| 1141 /* Opcode: Move P1 P2 P3 * * | 1185 /* Opcode: Move P1 P2 P3 * * |
| 1142 ** Synopsis: r[P2@P3]=r[P1@P3] | 1186 ** Synopsis: r[P2@P3]=r[P1@P3] |
| 1143 ** | 1187 ** |
| 1144 ** Move the P3 values in register P1..P1+P3-1 over into | 1188 ** Move the P3 values in register P1..P1+P3-1 over into |
| 1145 ** registers P2..P2+P3-1. Registers P1..P1+P3-1 are | 1189 ** registers P2..P2+P3-1. Registers P1..P1+P3-1 are |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1160 | 1204 |
| 1161 pIn1 = &aMem[p1]; | 1205 pIn1 = &aMem[p1]; |
| 1162 pOut = &aMem[p2]; | 1206 pOut = &aMem[p2]; |
| 1163 do{ | 1207 do{ |
| 1164 assert( pOut<=&aMem[(p->nMem-p->nCursor)] ); | 1208 assert( pOut<=&aMem[(p->nMem-p->nCursor)] ); |
| 1165 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); | 1209 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 1166 assert( memIsValid(pIn1) ); | 1210 assert( memIsValid(pIn1) ); |
| 1167 memAboutToChange(p, pOut); | 1211 memAboutToChange(p, pOut); |
| 1168 sqlite3VdbeMemMove(pOut, pIn1); | 1212 sqlite3VdbeMemMove(pOut, pIn1); |
| 1169 #ifdef SQLITE_DEBUG | 1213 #ifdef SQLITE_DEBUG |
| 1170 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){ | 1214 if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){ |
| 1171 pOut->pScopyFrom += p1 - pOp->p2; | 1215 pOut->pScopyFrom += pOp->p2 - p1; |
| 1172 } | 1216 } |
| 1173 #endif | 1217 #endif |
| 1218 Deephemeralize(pOut); |
| 1174 REGISTER_TRACE(p2++, pOut); | 1219 REGISTER_TRACE(p2++, pOut); |
| 1175 pIn1++; | 1220 pIn1++; |
| 1176 pOut++; | 1221 pOut++; |
| 1177 }while( --n ); | 1222 }while( --n ); |
| 1178 break; | 1223 break; |
| 1179 } | 1224 } |
| 1180 | 1225 |
| 1181 /* Opcode: Copy P1 P2 P3 * * | 1226 /* Opcode: Copy P1 P2 P3 * * |
| 1182 ** Synopsis: r[P2@P3+1]=r[P1@P3+1] | 1227 ** Synopsis: r[P2@P3+1]=r[P1@P3+1] |
| 1183 ** | 1228 ** |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 pIn1 = &aMem[pOp->p1]; | 1269 pIn1 = &aMem[pOp->p1]; |
| 1225 pOut = &aMem[pOp->p2]; | 1270 pOut = &aMem[pOp->p2]; |
| 1226 assert( pOut!=pIn1 ); | 1271 assert( pOut!=pIn1 ); |
| 1227 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); | 1272 sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); |
| 1228 #ifdef SQLITE_DEBUG | 1273 #ifdef SQLITE_DEBUG |
| 1229 if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1; | 1274 if( pOut->pScopyFrom==0 ) pOut->pScopyFrom = pIn1; |
| 1230 #endif | 1275 #endif |
| 1231 break; | 1276 break; |
| 1232 } | 1277 } |
| 1233 | 1278 |
| 1279 /* Opcode: IntCopy P1 P2 * * * |
| 1280 ** Synopsis: r[P2]=r[P1] |
| 1281 ** |
| 1282 ** Transfer the integer value held in register P1 into register P2. |
| 1283 ** |
| 1284 ** This is an optimized version of SCopy that works only for integer |
| 1285 ** values. |
| 1286 */ |
| 1287 case OP_IntCopy: { /* out2 */ |
| 1288 pIn1 = &aMem[pOp->p1]; |
| 1289 assert( (pIn1->flags & MEM_Int)!=0 ); |
| 1290 pOut = &aMem[pOp->p2]; |
| 1291 sqlite3VdbeMemSetInt64(pOut, pIn1->u.i); |
| 1292 break; |
| 1293 } |
| 1294 |
| 1234 /* Opcode: ResultRow P1 P2 * * * | 1295 /* Opcode: ResultRow P1 P2 * * * |
| 1235 ** Synopsis: output=r[P1@P2] | 1296 ** Synopsis: output=r[P1@P2] |
| 1236 ** | 1297 ** |
| 1237 ** The registers P1 through P1+P2-1 contain a single row of | 1298 ** The registers P1 through P1+P2-1 contain a single row of |
| 1238 ** results. This opcode causes the sqlite3_step() call to terminate | 1299 ** results. This opcode causes the sqlite3_step() call to terminate |
| 1239 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt | 1300 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt |
| 1240 ** structure to provide access to the r(P1)..r(P1+P2-1) values as | 1301 ** structure to provide access to the r(P1)..r(P1+P2-1) values as |
| 1241 ** the result row. | 1302 ** the result row. |
| 1242 */ | 1303 */ |
| 1243 case OP_ResultRow: { | 1304 case OP_ResultRow: { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 Deephemeralize(&pMem[i]); | 1363 Deephemeralize(&pMem[i]); |
| 1303 assert( (pMem[i].flags & MEM_Ephem)==0 | 1364 assert( (pMem[i].flags & MEM_Ephem)==0 |
| 1304 || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 ); | 1365 || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 ); |
| 1305 sqlite3VdbeMemNulTerminate(&pMem[i]); | 1366 sqlite3VdbeMemNulTerminate(&pMem[i]); |
| 1306 REGISTER_TRACE(pOp->p1+i, &pMem[i]); | 1367 REGISTER_TRACE(pOp->p1+i, &pMem[i]); |
| 1307 } | 1368 } |
| 1308 if( db->mallocFailed ) goto no_mem; | 1369 if( db->mallocFailed ) goto no_mem; |
| 1309 | 1370 |
| 1310 /* Return SQLITE_ROW | 1371 /* Return SQLITE_ROW |
| 1311 */ | 1372 */ |
| 1312 p->pc = pc + 1; | 1373 p->pc = (int)(pOp - aOp) + 1; |
| 1313 rc = SQLITE_ROW; | 1374 rc = SQLITE_ROW; |
| 1314 goto vdbe_return; | 1375 goto vdbe_return; |
| 1315 } | 1376 } |
| 1316 | 1377 |
| 1317 /* Opcode: Concat P1 P2 P3 * * | 1378 /* Opcode: Concat P1 P2 P3 * * |
| 1318 ** Synopsis: r[P3]=r[P2]+r[P1] | 1379 ** Synopsis: r[P3]=r[P2]+r[P1] |
| 1319 ** | 1380 ** |
| 1320 ** Add the text in register P1 onto the end of the text in | 1381 ** Add the text in register P1 onto the end of the text in |
| 1321 ** register P2 and store the result in register P3. | 1382 ** register P2 and store the result in register P3. |
| 1322 ** If either the P1 or P2 text are NULL then store NULL in P3. | 1383 ** If either the P1 or P2 text are NULL then store NULL in P3. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will | 1556 ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will |
| 1496 ** be returned. This is used by the built-in min(), max() and nullif() | 1557 ** be returned. This is used by the built-in min(), max() and nullif() |
| 1497 ** functions. | 1558 ** functions. |
| 1498 ** | 1559 ** |
| 1499 ** If P1 is not zero, then it is a register that a subsequent min() or | 1560 ** If P1 is not zero, then it is a register that a subsequent min() or |
| 1500 ** max() aggregate will set to 1 if the current row is not the minimum or | 1561 ** max() aggregate will set to 1 if the current row is not the minimum or |
| 1501 ** maximum. The P1 register is initialized to 0 by this instruction. | 1562 ** maximum. The P1 register is initialized to 0 by this instruction. |
| 1502 ** | 1563 ** |
| 1503 ** The interface used by the implementation of the aforementioned functions | 1564 ** The interface used by the implementation of the aforementioned functions |
| 1504 ** to retrieve the collation sequence set by this opcode is not available | 1565 ** to retrieve the collation sequence set by this opcode is not available |
| 1505 ** publicly, only to user functions defined in func.c. | 1566 ** publicly. Only built-in functions have access to this feature. |
| 1506 */ | 1567 */ |
| 1507 case OP_CollSeq: { | 1568 case OP_CollSeq: { |
| 1508 assert( pOp->p4type==P4_COLLSEQ ); | 1569 assert( pOp->p4type==P4_COLLSEQ ); |
| 1509 if( pOp->p1 ){ | 1570 if( pOp->p1 ){ |
| 1510 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0); | 1571 sqlite3VdbeMemSetInt64(&aMem[pOp->p1], 0); |
| 1511 } | 1572 } |
| 1512 break; | 1573 break; |
| 1513 } | 1574 } |
| 1514 | 1575 |
| 1515 /* Opcode: Function P1 P2 P3 P4 P5 | 1576 /* Opcode: Function0 P1 P2 P3 P4 P5 |
| 1516 ** Synopsis: r[P3]=func(r[P2@P5]) | 1577 ** Synopsis: r[P3]=func(r[P2@P5]) |
| 1517 ** | 1578 ** |
| 1518 ** Invoke a user function (P4 is a pointer to a Function structure that | 1579 ** Invoke a user function (P4 is a pointer to a FuncDef object that |
| 1519 ** defines the function) with P5 arguments taken from register P2 and | 1580 ** defines the function) with P5 arguments taken from register P2 and |
| 1520 ** successors. The result of the function is stored in register P3. | 1581 ** successors. The result of the function is stored in register P3. |
| 1521 ** Register P3 must not be one of the function inputs. | 1582 ** Register P3 must not be one of the function inputs. |
| 1522 ** | 1583 ** |
| 1523 ** P1 is a 32-bit bitmask indicating whether or not each argument to the | 1584 ** P1 is a 32-bit bitmask indicating whether or not each argument to the |
| 1524 ** function was determined to be constant at compile time. If the first | 1585 ** function was determined to be constant at compile time. If the first |
| 1525 ** argument was constant then bit 0 of P1 is set. This is used to determine | 1586 ** argument was constant then bit 0 of P1 is set. This is used to determine |
| 1526 ** whether meta data associated with a user function argument using the | 1587 ** whether meta data associated with a user function argument using the |
| 1527 ** sqlite3_set_auxdata() API may be safely retained until the next | 1588 ** sqlite3_set_auxdata() API may be safely retained until the next |
| 1528 ** invocation of this opcode. | 1589 ** invocation of this opcode. |
| 1529 ** | 1590 ** |
| 1530 ** See also: AggStep and AggFinal | 1591 ** See also: Function, AggStep, AggFinal |
| 1531 */ | 1592 */ |
| 1593 /* Opcode: Function P1 P2 P3 P4 P5 |
| 1594 ** Synopsis: r[P3]=func(r[P2@P5]) |
| 1595 ** |
| 1596 ** Invoke a user function (P4 is a pointer to an sqlite3_context object that |
| 1597 ** contains a pointer to the function to be run) with P5 arguments taken |
| 1598 ** from register P2 and successors. The result of the function is stored |
| 1599 ** in register P3. Register P3 must not be one of the function inputs. |
| 1600 ** |
| 1601 ** P1 is a 32-bit bitmask indicating whether or not each argument to the |
| 1602 ** function was determined to be constant at compile time. If the first |
| 1603 ** argument was constant then bit 0 of P1 is set. This is used to determine |
| 1604 ** whether meta data associated with a user function argument using the |
| 1605 ** sqlite3_set_auxdata() API may be safely retained until the next |
| 1606 ** invocation of this opcode. |
| 1607 ** |
| 1608 ** SQL functions are initially coded as OP_Function0 with P4 pointing |
| 1609 ** to a FuncDef object. But on first evaluation, the P4 operand is |
| 1610 ** automatically converted into an sqlite3_context object and the operation |
| 1611 ** changed to this OP_Function opcode. In this way, the initialization of |
| 1612 ** the sqlite3_context object occurs only once, rather than once for each |
| 1613 ** evaluation of the function. |
| 1614 ** |
| 1615 ** See also: Function0, AggStep, AggFinal |
| 1616 */ |
| 1617 case OP_Function0: { |
| 1618 int n; |
| 1619 sqlite3_context *pCtx; |
| 1620 |
| 1621 assert( pOp->p4type==P4_FUNCDEF ); |
| 1622 n = pOp->p5; |
| 1623 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 1624 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) ); |
| 1625 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n ); |
| 1626 pCtx = sqlite3DbMallocRaw(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*)); |
| 1627 if( pCtx==0 ) goto no_mem; |
| 1628 pCtx->pOut = 0; |
| 1629 pCtx->pFunc = pOp->p4.pFunc; |
| 1630 pCtx->iOp = (int)(pOp - aOp); |
| 1631 pCtx->pVdbe = p; |
| 1632 pCtx->argc = n; |
| 1633 pOp->p4type = P4_FUNCCTX; |
| 1634 pOp->p4.pCtx = pCtx; |
| 1635 pOp->opcode = OP_Function; |
| 1636 /* Fall through into OP_Function */ |
| 1637 } |
| 1532 case OP_Function: { | 1638 case OP_Function: { |
| 1533 int i; | 1639 int i; |
| 1534 Mem *pArg; | 1640 sqlite3_context *pCtx; |
| 1535 sqlite3_context ctx; | |
| 1536 sqlite3_value **apVal; | |
| 1537 int n; | |
| 1538 | 1641 |
| 1539 n = pOp->p5; | 1642 assert( pOp->p4type==P4_FUNCCTX ); |
| 1540 apVal = p->apArg; | 1643 pCtx = pOp->p4.pCtx; |
| 1541 assert( apVal || n==0 ); | |
| 1542 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); | |
| 1543 ctx.pOut = &aMem[pOp->p3]; | |
| 1544 memAboutToChange(p, ctx.pOut); | |
| 1545 | 1644 |
| 1546 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) ); | 1645 /* If this function is inside of a trigger, the register array in aMem[] |
| 1547 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n ); | 1646 ** might change from one evaluation to the next. The next block of code |
| 1548 pArg = &aMem[pOp->p2]; | 1647 ** checks to see if the register array has changed, and if so it |
| 1549 for(i=0; i<n; i++, pArg++){ | 1648 ** reinitializes the relavant parts of the sqlite3_context object */ |
| 1550 assert( memIsValid(pArg) ); | 1649 pOut = &aMem[pOp->p3]; |
| 1551 apVal[i] = pArg; | 1650 if( pCtx->pOut != pOut ){ |
| 1552 Deephemeralize(pArg); | 1651 pCtx->pOut = pOut; |
| 1553 REGISTER_TRACE(pOp->p2+i, pArg); | 1652 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; |
| 1554 } | 1653 } |
| 1555 | 1654 |
| 1556 assert( pOp->p4type==P4_FUNCDEF ); | 1655 memAboutToChange(p, pCtx->pOut); |
| 1557 ctx.pFunc = pOp->p4.pFunc; | 1656 #ifdef SQLITE_DEBUG |
| 1558 ctx.iOp = pc; | 1657 for(i=0; i<pCtx->argc; i++){ |
| 1559 ctx.pVdbe = p; | 1658 assert( memIsValid(pCtx->argv[i]) ); |
| 1560 MemSetTypeFlag(ctx.pOut, MEM_Null); | 1659 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]); |
| 1561 ctx.fErrorOrAux = 0; | 1660 } |
| 1661 #endif |
| 1662 MemSetTypeFlag(pCtx->pOut, MEM_Null); |
| 1663 pCtx->fErrorOrAux = 0; |
| 1562 db->lastRowid = lastRowid; | 1664 db->lastRowid = lastRowid; |
| 1563 (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ | 1665 (*pCtx->pFunc->xFunc)(pCtx, pCtx->argc, pCtx->argv); /* IMP: R-24505-23230 */ |
| 1564 lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */ | 1666 lastRowid = db->lastRowid; /* Remember rowid changes made by xFunc */ |
| 1565 | 1667 |
| 1566 /* If the function returned an error, throw an exception */ | 1668 /* If the function returned an error, throw an exception */ |
| 1567 if( ctx.fErrorOrAux ){ | 1669 if( pCtx->fErrorOrAux ){ |
| 1568 if( ctx.isError ){ | 1670 if( pCtx->isError ){ |
| 1569 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(ctx.pOut)); | 1671 sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| 1570 rc = ctx.isError; | 1672 rc = pCtx->isError; |
| 1571 } | 1673 } |
| 1572 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); | 1674 sqlite3VdbeDeleteAuxData(p, pCtx->iOp, pOp->p1); |
| 1573 } | 1675 } |
| 1574 | 1676 |
| 1575 /* Copy the result of the function into register P3 */ | 1677 /* Copy the result of the function into register P3 */ |
| 1576 sqlite3VdbeChangeEncoding(ctx.pOut, encoding); | 1678 if( pOut->flags & (MEM_Str|MEM_Blob) ){ |
| 1577 if( sqlite3VdbeMemTooBig(ctx.pOut) ){ | 1679 sqlite3VdbeChangeEncoding(pCtx->pOut, encoding); |
| 1578 goto too_big; | 1680 if( sqlite3VdbeMemTooBig(pCtx->pOut) ) goto too_big; |
| 1579 } | 1681 } |
| 1580 | 1682 |
| 1581 REGISTER_TRACE(pOp->p3, ctx.pOut); | 1683 REGISTER_TRACE(pOp->p3, pCtx->pOut); |
| 1582 UPDATE_MAX_BLOBSIZE(ctx.pOut); | 1684 UPDATE_MAX_BLOBSIZE(pCtx->pOut); |
| 1583 break; | 1685 break; |
| 1584 } | 1686 } |
| 1585 | 1687 |
| 1586 /* Opcode: BitAnd P1 P2 P3 * * | 1688 /* Opcode: BitAnd P1 P2 P3 * * |
| 1587 ** Synopsis: r[P3]=r[P1]&r[P2] | 1689 ** Synopsis: r[P3]=r[P1]&r[P2] |
| 1588 ** | 1690 ** |
| 1589 ** Take the bit-wise AND of the values in register P1 and P2 and | 1691 ** Take the bit-wise AND of the values in register P1 and P2 and |
| 1590 ** store the result in register P3. | 1692 ** store the result in register P3. |
| 1591 ** If either input is NULL, the result is NULL. | 1693 ** If either input is NULL, the result is NULL. |
| 1592 */ | 1694 */ |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 case OP_MustBeInt: { /* jump, in1 */ | 1793 case OP_MustBeInt: { /* jump, in1 */ |
| 1692 pIn1 = &aMem[pOp->p1]; | 1794 pIn1 = &aMem[pOp->p1]; |
| 1693 if( (pIn1->flags & MEM_Int)==0 ){ | 1795 if( (pIn1->flags & MEM_Int)==0 ){ |
| 1694 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding); | 1796 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding); |
| 1695 VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2); | 1797 VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2); |
| 1696 if( (pIn1->flags & MEM_Int)==0 ){ | 1798 if( (pIn1->flags & MEM_Int)==0 ){ |
| 1697 if( pOp->p2==0 ){ | 1799 if( pOp->p2==0 ){ |
| 1698 rc = SQLITE_MISMATCH; | 1800 rc = SQLITE_MISMATCH; |
| 1699 goto abort_due_to_error; | 1801 goto abort_due_to_error; |
| 1700 }else{ | 1802 }else{ |
| 1701 pc = pOp->p2 - 1; | 1803 goto jump_to_p2; |
| 1702 break; | |
| 1703 } | 1804 } |
| 1704 } | 1805 } |
| 1705 } | 1806 } |
| 1706 MemSetTypeFlag(pIn1, MEM_Int); | 1807 MemSetTypeFlag(pIn1, MEM_Int); |
| 1707 break; | 1808 break; |
| 1708 } | 1809 } |
| 1709 | 1810 |
| 1710 #ifndef SQLITE_OMIT_FLOATING_POINT | 1811 #ifndef SQLITE_OMIT_FLOATING_POINT |
| 1711 /* Opcode: RealAffinity P1 * * * * | 1812 /* Opcode: RealAffinity P1 * * * * |
| 1712 ** | 1813 ** |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1736 ** <li value="97"> TEXT | 1837 ** <li value="97"> TEXT |
| 1737 ** <li value="98"> BLOB | 1838 ** <li value="98"> BLOB |
| 1738 ** <li value="99"> NUMERIC | 1839 ** <li value="99"> NUMERIC |
| 1739 ** <li value="100"> INTEGER | 1840 ** <li value="100"> INTEGER |
| 1740 ** <li value="101"> REAL | 1841 ** <li value="101"> REAL |
| 1741 ** </ul> | 1842 ** </ul> |
| 1742 ** | 1843 ** |
| 1743 ** A NULL value is not changed by this routine. It remains NULL. | 1844 ** A NULL value is not changed by this routine. It remains NULL. |
| 1744 */ | 1845 */ |
| 1745 case OP_Cast: { /* in1 */ | 1846 case OP_Cast: { /* in1 */ |
| 1746 assert( pOp->p2>=SQLITE_AFF_NONE && pOp->p2<=SQLITE_AFF_REAL ); | 1847 assert( pOp->p2>=SQLITE_AFF_BLOB && pOp->p2<=SQLITE_AFF_REAL ); |
| 1747 testcase( pOp->p2==SQLITE_AFF_TEXT ); | 1848 testcase( pOp->p2==SQLITE_AFF_TEXT ); |
| 1748 testcase( pOp->p2==SQLITE_AFF_NONE ); | 1849 testcase( pOp->p2==SQLITE_AFF_BLOB ); |
| 1749 testcase( pOp->p2==SQLITE_AFF_NUMERIC ); | 1850 testcase( pOp->p2==SQLITE_AFF_NUMERIC ); |
| 1750 testcase( pOp->p2==SQLITE_AFF_INTEGER ); | 1851 testcase( pOp->p2==SQLITE_AFF_INTEGER ); |
| 1751 testcase( pOp->p2==SQLITE_AFF_REAL ); | 1852 testcase( pOp->p2==SQLITE_AFF_REAL ); |
| 1752 pIn1 = &aMem[pOp->p1]; | 1853 pIn1 = &aMem[pOp->p1]; |
| 1753 memAboutToChange(p, pIn1); | 1854 memAboutToChange(p, pIn1); |
| 1754 rc = ExpandBlob(pIn1); | 1855 rc = ExpandBlob(pIn1); |
| 1755 sqlite3VdbeMemCast(pIn1, pOp->p2, encoding); | 1856 sqlite3VdbeMemCast(pIn1, pOp->p2, encoding); |
| 1756 UPDATE_MAX_BLOBSIZE(pIn1); | 1857 UPDATE_MAX_BLOBSIZE(pIn1); |
| 1757 break; | 1858 break; |
| 1758 } | 1859 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1873 }else{ | 1974 }else{ |
| 1874 res = 1; /* Results are not equal */ | 1975 res = 1; /* Results are not equal */ |
| 1875 } | 1976 } |
| 1876 }else{ | 1977 }else{ |
| 1877 /* SQLITE_NULLEQ is clear and at least one operand is NULL, | 1978 /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 1878 ** then the result is always NULL. | 1979 ** then the result is always NULL. |
| 1879 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. | 1980 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| 1880 */ | 1981 */ |
| 1881 if( pOp->p5 & SQLITE_STOREP2 ){ | 1982 if( pOp->p5 & SQLITE_STOREP2 ){ |
| 1882 pOut = &aMem[pOp->p2]; | 1983 pOut = &aMem[pOp->p2]; |
| 1984 memAboutToChange(p, pOut); |
| 1883 MemSetTypeFlag(pOut, MEM_Null); | 1985 MemSetTypeFlag(pOut, MEM_Null); |
| 1884 REGISTER_TRACE(pOp->p2, pOut); | 1986 REGISTER_TRACE(pOp->p2, pOut); |
| 1885 }else{ | 1987 }else{ |
| 1886 VdbeBranchTaken(2,3); | 1988 VdbeBranchTaken(2,3); |
| 1887 if( pOp->p5 & SQLITE_JUMPIFNULL ){ | 1989 if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 1888 pc = pOp->p2-1; | 1990 goto jump_to_p2; |
| 1889 } | 1991 } |
| 1890 } | 1992 } |
| 1891 break; | 1993 break; |
| 1892 } | 1994 } |
| 1893 }else{ | 1995 }else{ |
| 1894 /* Neither operand is NULL. Do a comparison. */ | 1996 /* Neither operand is NULL. Do a comparison. */ |
| 1895 affinity = pOp->p5 & SQLITE_AFF_MASK; | 1997 affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 1896 if( affinity>=SQLITE_AFF_NUMERIC ){ | 1998 if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 1897 if( (pIn1->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ | 1999 if( (flags1 & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ |
| 1898 applyNumericAffinity(pIn1,0); | 2000 applyNumericAffinity(pIn1,0); |
| 1899 } | 2001 } |
| 1900 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ | 2002 if( (flags3 & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ |
| 1901 applyNumericAffinity(pIn3,0); | 2003 applyNumericAffinity(pIn3,0); |
| 1902 } | 2004 } |
| 1903 }else if( affinity==SQLITE_AFF_TEXT ){ | 2005 }else if( affinity==SQLITE_AFF_TEXT ){ |
| 1904 if( (pIn1->flags & MEM_Str)==0 && (pIn1->flags & (MEM_Int|MEM_Real))!=0 ){ | 2006 if( (flags1 & MEM_Str)==0 && (flags1 & (MEM_Int|MEM_Real))!=0 ){ |
| 1905 testcase( pIn1->flags & MEM_Int ); | 2007 testcase( pIn1->flags & MEM_Int ); |
| 1906 testcase( pIn1->flags & MEM_Real ); | 2008 testcase( pIn1->flags & MEM_Real ); |
| 1907 sqlite3VdbeMemStringify(pIn1, encoding, 1); | 2009 sqlite3VdbeMemStringify(pIn1, encoding, 1); |
| 2010 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) ); |
| 2011 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask); |
| 1908 } | 2012 } |
| 1909 if( (pIn3->flags & MEM_Str)==0 && (pIn3->flags & (MEM_Int|MEM_Real))!=0 ){ | 2013 if( (flags3 & MEM_Str)==0 && (flags3 & (MEM_Int|MEM_Real))!=0 ){ |
| 1910 testcase( pIn3->flags & MEM_Int ); | 2014 testcase( pIn3->flags & MEM_Int ); |
| 1911 testcase( pIn3->flags & MEM_Real ); | 2015 testcase( pIn3->flags & MEM_Real ); |
| 1912 sqlite3VdbeMemStringify(pIn3, encoding, 1); | 2016 sqlite3VdbeMemStringify(pIn3, encoding, 1); |
| 2017 testcase( (flags3&MEM_Dyn) != (pIn3->flags&MEM_Dyn) ); |
| 2018 flags3 = (pIn3->flags & ~MEM_TypeMask) | (flags3 & MEM_TypeMask); |
| 1913 } | 2019 } |
| 1914 } | 2020 } |
| 1915 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); | 2021 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); |
| 1916 if( pIn1->flags & MEM_Zero ){ | 2022 if( flags1 & MEM_Zero ){ |
| 1917 sqlite3VdbeMemExpandBlob(pIn1); | 2023 sqlite3VdbeMemExpandBlob(pIn1); |
| 1918 flags1 &= ~MEM_Zero; | 2024 flags1 &= ~MEM_Zero; |
| 1919 } | 2025 } |
| 1920 if( pIn3->flags & MEM_Zero ){ | 2026 if( flags3 & MEM_Zero ){ |
| 1921 sqlite3VdbeMemExpandBlob(pIn3); | 2027 sqlite3VdbeMemExpandBlob(pIn3); |
| 1922 flags3 &= ~MEM_Zero; | 2028 flags3 &= ~MEM_Zero; |
| 1923 } | 2029 } |
| 1924 if( db->mallocFailed ) goto no_mem; | |
| 1925 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); | 2030 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); |
| 1926 } | 2031 } |
| 1927 switch( pOp->opcode ){ | 2032 switch( pOp->opcode ){ |
| 1928 case OP_Eq: res = res==0; break; | 2033 case OP_Eq: res = res==0; break; |
| 1929 case OP_Ne: res = res!=0; break; | 2034 case OP_Ne: res = res!=0; break; |
| 1930 case OP_Lt: res = res<0; break; | 2035 case OP_Lt: res = res<0; break; |
| 1931 case OP_Le: res = res<=0; break; | 2036 case OP_Le: res = res<=0; break; |
| 1932 case OP_Gt: res = res>0; break; | 2037 case OP_Gt: res = res>0; break; |
| 1933 default: res = res>=0; break; | 2038 default: res = res>=0; break; |
| 1934 } | 2039 } |
| 1935 | 2040 |
| 2041 /* Undo any changes made by applyAffinity() to the input registers. */ |
| 2042 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) ); |
| 2043 pIn1->flags = flags1; |
| 2044 assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) ); |
| 2045 pIn3->flags = flags3; |
| 2046 |
| 1936 if( pOp->p5 & SQLITE_STOREP2 ){ | 2047 if( pOp->p5 & SQLITE_STOREP2 ){ |
| 1937 pOut = &aMem[pOp->p2]; | 2048 pOut = &aMem[pOp->p2]; |
| 1938 memAboutToChange(p, pOut); | 2049 memAboutToChange(p, pOut); |
| 1939 MemSetTypeFlag(pOut, MEM_Int); | 2050 MemSetTypeFlag(pOut, MEM_Int); |
| 1940 pOut->u.i = res; | 2051 pOut->u.i = res; |
| 1941 REGISTER_TRACE(pOp->p2, pOut); | 2052 REGISTER_TRACE(pOp->p2, pOut); |
| 1942 }else{ | 2053 }else{ |
| 1943 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); | 2054 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3); |
| 1944 if( res ){ | 2055 if( res ){ |
| 1945 pc = pOp->p2-1; | 2056 goto jump_to_p2; |
| 1946 } | 2057 } |
| 1947 } | 2058 } |
| 1948 /* Undo any changes made by applyAffinity() to the input registers. */ | |
| 1949 pIn1->flags = flags1; | |
| 1950 pIn3->flags = flags3; | |
| 1951 break; | 2059 break; |
| 1952 } | 2060 } |
| 1953 | 2061 |
| 1954 /* Opcode: Permutation * * * P4 * | 2062 /* Opcode: Permutation * * * P4 * |
| 1955 ** | 2063 ** |
| 1956 ** Set the permutation used by the OP_Compare operator to be the array | 2064 ** Set the permutation used by the OP_Compare operator to be the array |
| 1957 ** of integers in P4. | 2065 ** of integers in P4. |
| 1958 ** | 2066 ** |
| 1959 ** The permutation is only valid until the next OP_Compare that has | 2067 ** The permutation is only valid until the next OP_Compare that has |
| 1960 ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should | 2068 ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2035 } | 2143 } |
| 2036 | 2144 |
| 2037 /* Opcode: Jump P1 P2 P3 * * | 2145 /* Opcode: Jump P1 P2 P3 * * |
| 2038 ** | 2146 ** |
| 2039 ** Jump to the instruction at address P1, P2, or P3 depending on whether | 2147 ** Jump to the instruction at address P1, P2, or P3 depending on whether |
| 2040 ** in the most recent OP_Compare instruction the P1 vector was less than | 2148 ** in the most recent OP_Compare instruction the P1 vector was less than |
| 2041 ** equal to, or greater than the P2 vector, respectively. | 2149 ** equal to, or greater than the P2 vector, respectively. |
| 2042 */ | 2150 */ |
| 2043 case OP_Jump: { /* jump */ | 2151 case OP_Jump: { /* jump */ |
| 2044 if( iCompare<0 ){ | 2152 if( iCompare<0 ){ |
| 2045 pc = pOp->p1 - 1; VdbeBranchTaken(0,3); | 2153 VdbeBranchTaken(0,3); pOp = &aOp[pOp->p1 - 1]; |
| 2046 }else if( iCompare==0 ){ | 2154 }else if( iCompare==0 ){ |
| 2047 pc = pOp->p2 - 1; VdbeBranchTaken(1,3); | 2155 VdbeBranchTaken(1,3); pOp = &aOp[pOp->p2 - 1]; |
| 2048 }else{ | 2156 }else{ |
| 2049 pc = pOp->p3 - 1; VdbeBranchTaken(2,3); | 2157 VdbeBranchTaken(2,3); pOp = &aOp[pOp->p3 - 1]; |
| 2050 } | 2158 } |
| 2051 break; | 2159 break; |
| 2052 } | 2160 } |
| 2053 | 2161 |
| 2054 /* Opcode: And P1 P2 P3 * * | 2162 /* Opcode: And P1 P2 P3 * * |
| 2055 ** Synopsis: r[P3]=(r[P1] && r[P2]) | 2163 ** Synopsis: r[P3]=(r[P1] && r[P2]) |
| 2056 ** | 2164 ** |
| 2057 ** Take the logical AND of the values in registers P1 and P2 and | 2165 ** Take the logical AND of the values in registers P1 and P2 and |
| 2058 ** write the result into register P3. | 2166 ** write the result into register P3. |
| 2059 ** | 2167 ** |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2149 ** (but not including P2) to run just once and to be skipped on subsequent | 2257 ** (but not including P2) to run just once and to be skipped on subsequent |
| 2150 ** times through the loop. | 2258 ** times through the loop. |
| 2151 ** | 2259 ** |
| 2152 ** All "once" flags are initially cleared whenever a prepared statement | 2260 ** All "once" flags are initially cleared whenever a prepared statement |
| 2153 ** first begins to run. | 2261 ** first begins to run. |
| 2154 */ | 2262 */ |
| 2155 case OP_Once: { /* jump */ | 2263 case OP_Once: { /* jump */ |
| 2156 assert( pOp->p1<p->nOnceFlag ); | 2264 assert( pOp->p1<p->nOnceFlag ); |
| 2157 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); | 2265 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2); |
| 2158 if( p->aOnceFlag[pOp->p1] ){ | 2266 if( p->aOnceFlag[pOp->p1] ){ |
| 2159 pc = pOp->p2-1; | 2267 goto jump_to_p2; |
| 2160 }else{ | 2268 }else{ |
| 2161 p->aOnceFlag[pOp->p1] = 1; | 2269 p->aOnceFlag[pOp->p1] = 1; |
| 2162 } | 2270 } |
| 2163 break; | 2271 break; |
| 2164 } | 2272 } |
| 2165 | 2273 |
| 2166 /* Opcode: If P1 P2 P3 * * | 2274 /* Opcode: If P1 P2 P3 * * |
| 2167 ** | 2275 ** |
| 2168 ** Jump to P2 if the value in register P1 is true. The value | 2276 ** Jump to P2 if the value in register P1 is true. The value |
| 2169 ** is considered true if it is numeric and non-zero. If the value | 2277 ** is considered true if it is numeric and non-zero. If the value |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2184 }else{ | 2292 }else{ |
| 2185 #ifdef SQLITE_OMIT_FLOATING_POINT | 2293 #ifdef SQLITE_OMIT_FLOATING_POINT |
| 2186 c = sqlite3VdbeIntValue(pIn1)!=0; | 2294 c = sqlite3VdbeIntValue(pIn1)!=0; |
| 2187 #else | 2295 #else |
| 2188 c = sqlite3VdbeRealValue(pIn1)!=0.0; | 2296 c = sqlite3VdbeRealValue(pIn1)!=0.0; |
| 2189 #endif | 2297 #endif |
| 2190 if( pOp->opcode==OP_IfNot ) c = !c; | 2298 if( pOp->opcode==OP_IfNot ) c = !c; |
| 2191 } | 2299 } |
| 2192 VdbeBranchTaken(c!=0, 2); | 2300 VdbeBranchTaken(c!=0, 2); |
| 2193 if( c ){ | 2301 if( c ){ |
| 2194 pc = pOp->p2-1; | 2302 goto jump_to_p2; |
| 2195 } | 2303 } |
| 2196 break; | 2304 break; |
| 2197 } | 2305 } |
| 2198 | 2306 |
| 2199 /* Opcode: IsNull P1 P2 * * * | 2307 /* Opcode: IsNull P1 P2 * * * |
| 2200 ** Synopsis: if r[P1]==NULL goto P2 | 2308 ** Synopsis: if r[P1]==NULL goto P2 |
| 2201 ** | 2309 ** |
| 2202 ** Jump to P2 if the value in register P1 is NULL. | 2310 ** Jump to P2 if the value in register P1 is NULL. |
| 2203 */ | 2311 */ |
| 2204 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */ | 2312 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */ |
| 2205 pIn1 = &aMem[pOp->p1]; | 2313 pIn1 = &aMem[pOp->p1]; |
| 2206 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2); | 2314 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2); |
| 2207 if( (pIn1->flags & MEM_Null)!=0 ){ | 2315 if( (pIn1->flags & MEM_Null)!=0 ){ |
| 2208 pc = pOp->p2 - 1; | 2316 goto jump_to_p2; |
| 2209 } | 2317 } |
| 2210 break; | 2318 break; |
| 2211 } | 2319 } |
| 2212 | 2320 |
| 2213 /* Opcode: NotNull P1 P2 * * * | 2321 /* Opcode: NotNull P1 P2 * * * |
| 2214 ** Synopsis: if r[P1]!=NULL goto P2 | 2322 ** Synopsis: if r[P1]!=NULL goto P2 |
| 2215 ** | 2323 ** |
| 2216 ** Jump to P2 if the value in register P1 is not NULL. | 2324 ** Jump to P2 if the value in register P1 is not NULL. |
| 2217 */ | 2325 */ |
| 2218 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */ | 2326 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */ |
| 2219 pIn1 = &aMem[pOp->p1]; | 2327 pIn1 = &aMem[pOp->p1]; |
| 2220 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2); | 2328 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2); |
| 2221 if( (pIn1->flags & MEM_Null)==0 ){ | 2329 if( (pIn1->flags & MEM_Null)==0 ){ |
| 2222 pc = pOp->p2 - 1; | 2330 goto jump_to_p2; |
| 2223 } | 2331 } |
| 2224 break; | 2332 break; |
| 2225 } | 2333 } |
| 2226 | 2334 |
| 2227 /* Opcode: Column P1 P2 P3 P4 P5 | 2335 /* Opcode: Column P1 P2 P3 P4 P5 |
| 2228 ** Synopsis: r[P3]=PX | 2336 ** Synopsis: r[P3]=PX |
| 2229 ** | 2337 ** |
| 2230 ** Interpret the data that cursor P1 points to as a structure built using | 2338 ** Interpret the data that cursor P1 points to as a structure built using |
| 2231 ** the MakeRecord instruction. (See the MakeRecord opcode for additional | 2339 ** the MakeRecord instruction. (See the MakeRecord opcode for additional |
| 2232 ** information about the format of the data.) Extract the P2-th column | 2340 ** information about the format of the data.) Extract the P2-th column |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2256 BtCursor *pCrsr; /* The BTree cursor */ | 2364 BtCursor *pCrsr; /* The BTree cursor */ |
| 2257 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ | 2365 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 2258 int len; /* The length of the serialized data for the column */ | 2366 int len; /* The length of the serialized data for the column */ |
| 2259 int i; /* Loop counter */ | 2367 int i; /* Loop counter */ |
| 2260 Mem *pDest; /* Where to write the extracted value */ | 2368 Mem *pDest; /* Where to write the extracted value */ |
| 2261 Mem sMem; /* For storing the record being decoded */ | 2369 Mem sMem; /* For storing the record being decoded */ |
| 2262 const u8 *zData; /* Part of the record being decoded */ | 2370 const u8 *zData; /* Part of the record being decoded */ |
| 2263 const u8 *zHdr; /* Next unparsed byte of the header */ | 2371 const u8 *zHdr; /* Next unparsed byte of the header */ |
| 2264 const u8 *zEndHdr; /* Pointer to first byte after the header */ | 2372 const u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 2265 u32 offset; /* Offset into the data */ | 2373 u32 offset; /* Offset into the data */ |
| 2266 u32 szField; /* Number of bytes in the content of a field */ | 2374 u64 offset64; /* 64-bit offset */ |
| 2267 u32 avail; /* Number of bytes of available data */ | 2375 u32 avail; /* Number of bytes of available data */ |
| 2268 u32 t; /* A type code from the record header */ | 2376 u32 t; /* A type code from the record header */ |
| 2269 u16 fx; /* pDest->flags value */ | 2377 u16 fx; /* pDest->flags value */ |
| 2270 Mem *pReg; /* PseudoTable input register */ | 2378 Mem *pReg; /* PseudoTable input register */ |
| 2271 | 2379 |
| 2272 p2 = pOp->p2; | 2380 p2 = pOp->p2; |
| 2273 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); | 2381 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 2274 pDest = &aMem[pOp->p3]; | 2382 pDest = &aMem[pOp->p3]; |
| 2275 memAboutToChange(p, pDest); | 2383 memAboutToChange(p, pDest); |
| 2276 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 2384 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 2277 pC = p->apCsr[pOp->p1]; | 2385 pC = p->apCsr[pOp->p1]; |
| 2278 assert( pC!=0 ); | 2386 assert( pC!=0 ); |
| 2279 assert( p2<pC->nField ); | 2387 assert( p2<pC->nField ); |
| 2280 aOffset = pC->aOffset; | 2388 aOffset = pC->aOffset; |
| 2281 #ifndef SQLITE_OMIT_VIRTUALTABLE | 2389 assert( pC->eCurType!=CURTYPE_VTAB ); |
| 2282 assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ | 2390 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow ); |
| 2283 #endif | 2391 assert( pC->eCurType!=CURTYPE_SORTER ); |
| 2284 pCrsr = pC->pCursor; | 2392 pCrsr = pC->uc.pCursor; |
| 2285 assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */ | |
| 2286 assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */ | |
| 2287 | 2393 |
| 2288 /* If the cursor cache is stale, bring it up-to-date */ | 2394 /* If the cursor cache is stale, bring it up-to-date */ |
| 2289 rc = sqlite3VdbeCursorMoveto(pC); | 2395 rc = sqlite3VdbeCursorMoveto(pC); |
| 2290 if( rc ) goto abort_due_to_error; | 2396 if( rc ) goto abort_due_to_error; |
| 2291 if( pC->cacheStatus!=p->cacheCtr ){ | 2397 if( pC->cacheStatus!=p->cacheCtr ){ |
| 2292 if( pC->nullRow ){ | 2398 if( pC->nullRow ){ |
| 2293 if( pCrsr==0 ){ | 2399 if( pC->eCurType==CURTYPE_PSEUDO ){ |
| 2294 assert( pC->pseudoTableReg>0 ); | 2400 assert( pC->uc.pseudoTableReg>0 ); |
| 2295 pReg = &aMem[pC->pseudoTableReg]; | 2401 pReg = &aMem[pC->uc.pseudoTableReg]; |
| 2296 assert( pReg->flags & MEM_Blob ); | 2402 assert( pReg->flags & MEM_Blob ); |
| 2297 assert( memIsValid(pReg) ); | 2403 assert( memIsValid(pReg) ); |
| 2298 pC->payloadSize = pC->szRow = avail = pReg->n; | 2404 pC->payloadSize = pC->szRow = avail = pReg->n; |
| 2299 pC->aRow = (u8*)pReg->z; | 2405 pC->aRow = (u8*)pReg->z; |
| 2300 }else{ | 2406 }else{ |
| 2301 sqlite3VdbeMemSetNull(pDest); | 2407 sqlite3VdbeMemSetNull(pDest); |
| 2302 goto op_column_out; | 2408 goto op_column_out; |
| 2303 } | 2409 } |
| 2304 }else{ | 2410 }else{ |
| 2411 assert( pC->eCurType==CURTYPE_BTREE ); |
| 2305 assert( pCrsr ); | 2412 assert( pCrsr ); |
| 2306 if( pC->isTable==0 ){ | 2413 if( pC->isTable==0 ){ |
| 2307 assert( sqlite3BtreeCursorIsValid(pCrsr) ); | 2414 assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 2308 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64); | 2415 VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64); |
| 2309 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ | 2416 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 2310 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the | 2417 /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the |
| 2311 ** payload size, so it is impossible for payloadSize64 to be | 2418 ** payload size, so it is impossible for payloadSize64 to be |
| 2312 ** larger than 32 bits. */ | 2419 ** larger than 32 bits. */ |
| 2313 assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 ); | 2420 assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 ); |
| 2314 pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail); | 2421 pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail); |
| 2315 pC->payloadSize = (u32)payloadSize64; | 2422 pC->payloadSize = (u32)payloadSize64; |
| 2316 }else{ | 2423 }else{ |
| 2317 assert( sqlite3BtreeCursorIsValid(pCrsr) ); | 2424 assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 2318 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize); | 2425 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize); |
| 2319 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ | 2426 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 2320 pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail); | 2427 pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail); |
| 2321 } | 2428 } |
| 2322 assert( avail<=65536 ); /* Maximum page size is 64KiB */ | 2429 assert( avail<=65536 ); /* Maximum page size is 64KiB */ |
| 2323 if( pC->payloadSize <= (u32)avail ){ | 2430 if( pC->payloadSize <= (u32)avail ){ |
| 2324 pC->szRow = pC->payloadSize; | 2431 pC->szRow = pC->payloadSize; |
| 2432 }else if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 2433 goto too_big; |
| 2325 }else{ | 2434 }else{ |
| 2326 pC->szRow = avail; | 2435 pC->szRow = avail; |
| 2327 } | 2436 } |
| 2328 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 2329 goto too_big; | |
| 2330 } | |
| 2331 } | 2437 } |
| 2332 pC->cacheStatus = p->cacheCtr; | 2438 pC->cacheStatus = p->cacheCtr; |
| 2333 pC->iHdrOffset = getVarint32(pC->aRow, offset); | 2439 pC->iHdrOffset = getVarint32(pC->aRow, offset); |
| 2334 pC->nHdrParsed = 0; | 2440 pC->nHdrParsed = 0; |
| 2335 aOffset[0] = offset; | 2441 aOffset[0] = offset; |
| 2336 | 2442 |
| 2337 /* Make sure a corrupt database has not given us an oversize header. | |
| 2338 ** Do this now to avoid an oversize memory allocation. | |
| 2339 ** | |
| 2340 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte | |
| 2341 ** types use so much data space that there can only be 4096 and 32 of | |
| 2342 ** them, respectively. So the maximum header length results from a | |
| 2343 ** 3-byte type for each of the maximum of 32768 columns plus three | |
| 2344 ** extra bytes for the header length itself. 32768*3 + 3 = 98307. | |
| 2345 */ | |
| 2346 if( offset > 98307 || offset > pC->payloadSize ){ | |
| 2347 rc = SQLITE_CORRUPT_BKPT; | |
| 2348 goto op_column_error; | |
| 2349 } | |
| 2350 | 2443 |
| 2351 if( avail<offset ){ | 2444 if( avail<offset ){ |
| 2352 /* pC->aRow does not have to hold the entire row, but it does at least | 2445 /* pC->aRow does not have to hold the entire row, but it does at least |
| 2353 ** need to cover the header of the record. If pC->aRow does not contain | 2446 ** need to cover the header of the record. If pC->aRow does not contain |
| 2354 ** the complete header, then set it to zero, forcing the header to be | 2447 ** the complete header, then set it to zero, forcing the header to be |
| 2355 ** dynamically allocated. */ | 2448 ** dynamically allocated. */ |
| 2356 pC->aRow = 0; | 2449 pC->aRow = 0; |
| 2357 pC->szRow = 0; | 2450 pC->szRow = 0; |
| 2451 |
| 2452 /* Make sure a corrupt database has not given us an oversize header. |
| 2453 ** Do this now to avoid an oversize memory allocation. |
| 2454 ** |
| 2455 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte |
| 2456 ** types use so much data space that there can only be 4096 and 32 of |
| 2457 ** them, respectively. So the maximum header length results from a |
| 2458 ** 3-byte type for each of the maximum of 32768 columns plus three |
| 2459 ** extra bytes for the header length itself. 32768*3 + 3 = 98307. |
| 2460 */ |
| 2461 if( offset > 98307 || offset > pC->payloadSize ){ |
| 2462 rc = SQLITE_CORRUPT_BKPT; |
| 2463 goto op_column_error; |
| 2464 } |
| 2358 } | 2465 } |
| 2359 | 2466 |
| 2360 /* The following goto is an optimization. It can be omitted and | 2467 /* The following goto is an optimization. It can be omitted and |
| 2361 ** everything will still work. But OP_Column is measurably faster | 2468 ** everything will still work. But OP_Column is measurably faster |
| 2362 ** by skipping the subsequent conditional, which is always true. | 2469 ** by skipping the subsequent conditional, which is always true. |
| 2363 */ | 2470 */ |
| 2364 assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */ | 2471 assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */ |
| 2365 goto op_column_read_header; | 2472 goto op_column_read_header; |
| 2366 } | 2473 } |
| 2367 | 2474 |
| 2368 /* Make sure at least the first p2+1 entries of the header have been | 2475 /* Make sure at least the first p2+1 entries of the header have been |
| 2369 ** parsed and valid information is in aOffset[] and pC->aType[]. | 2476 ** parsed and valid information is in aOffset[] and pC->aType[]. |
| 2370 */ | 2477 */ |
| 2371 if( pC->nHdrParsed<=p2 ){ | 2478 if( pC->nHdrParsed<=p2 ){ |
| 2372 /* If there is more header available for parsing in the record, try | 2479 /* If there is more header available for parsing in the record, try |
| 2373 ** to extract additional fields up through the p2+1-th field | 2480 ** to extract additional fields up through the p2+1-th field |
| 2374 */ | 2481 */ |
| 2375 op_column_read_header: | 2482 op_column_read_header: |
| 2376 if( pC->iHdrOffset<aOffset[0] ){ | 2483 if( pC->iHdrOffset<aOffset[0] ){ |
| 2377 /* Make sure zData points to enough of the record to cover the header. */ | 2484 /* Make sure zData points to enough of the record to cover the header. */ |
| 2378 if( pC->aRow==0 ){ | 2485 if( pC->aRow==0 ){ |
| 2379 memset(&sMem, 0, sizeof(sMem)); | 2486 memset(&sMem, 0, sizeof(sMem)); |
| 2380 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], | 2487 rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], !pC->isTable, &sMem); |
| 2381 !pC->isTable, &sMem); | 2488 if( rc!=SQLITE_OK ) goto op_column_error; |
| 2382 if( rc!=SQLITE_OK ){ | |
| 2383 goto op_column_error; | |
| 2384 } | |
| 2385 zData = (u8*)sMem.z; | 2489 zData = (u8*)sMem.z; |
| 2386 }else{ | 2490 }else{ |
| 2387 zData = pC->aRow; | 2491 zData = pC->aRow; |
| 2388 } | 2492 } |
| 2389 | 2493 |
| 2390 /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */ | 2494 /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */ |
| 2391 i = pC->nHdrParsed; | 2495 i = pC->nHdrParsed; |
| 2392 offset = aOffset[i]; | 2496 offset64 = aOffset[i]; |
| 2393 zHdr = zData + pC->iHdrOffset; | 2497 zHdr = zData + pC->iHdrOffset; |
| 2394 zEndHdr = zData + aOffset[0]; | 2498 zEndHdr = zData + aOffset[0]; |
| 2395 assert( i<=p2 && zHdr<zEndHdr ); | 2499 assert( i<=p2 && zHdr<zEndHdr ); |
| 2396 do{ | 2500 do{ |
| 2397 if( zHdr[0]<0x80 ){ | 2501 if( (t = zHdr[0])<0x80 ){ |
| 2398 t = zHdr[0]; | |
| 2399 zHdr++; | 2502 zHdr++; |
| 2503 offset64 += sqlite3VdbeOneByteSerialTypeLen(t); |
| 2400 }else{ | 2504 }else{ |
| 2401 zHdr += sqlite3GetVarint32(zHdr, &t); | 2505 zHdr += sqlite3GetVarint32(zHdr, &t); |
| 2506 offset64 += sqlite3VdbeSerialTypeLen(t); |
| 2402 } | 2507 } |
| 2403 pC->aType[i] = t; | 2508 pC->aType[i++] = t; |
| 2404 szField = sqlite3VdbeSerialTypeLen(t); | 2509 aOffset[i] = (u32)(offset64 & 0xffffffff); |
| 2405 offset += szField; | |
| 2406 if( offset<szField ){ /* True if offset overflows */ | |
| 2407 zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ | |
| 2408 break; | |
| 2409 } | |
| 2410 i++; | |
| 2411 aOffset[i] = offset; | |
| 2412 }while( i<=p2 && zHdr<zEndHdr ); | 2510 }while( i<=p2 && zHdr<zEndHdr ); |
| 2413 pC->nHdrParsed = i; | 2511 pC->nHdrParsed = i; |
| 2414 pC->iHdrOffset = (u32)(zHdr - zData); | 2512 pC->iHdrOffset = (u32)(zHdr - zData); |
| 2415 if( pC->aRow==0 ){ | 2513 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem); |
| 2416 sqlite3VdbeMemRelease(&sMem); | |
| 2417 sMem.flags = MEM_Null; | |
| 2418 } | |
| 2419 | 2514 |
| 2420 /* The record is corrupt if any of the following are true: | 2515 /* The record is corrupt if any of the following are true: |
| 2421 ** (1) the bytes of the header extend past the declared header size | 2516 ** (1) the bytes of the header extend past the declared header size |
| 2422 ** (zHdr>zEndHdr) | |
| 2423 ** (2) the entire header was used but not all data was used | 2517 ** (2) the entire header was used but not all data was used |
| 2424 ** (zHdr==zEndHdr && offset!=pC->payloadSize) | |
| 2425 ** (3) the end of the data extends beyond the end of the record. | 2518 ** (3) the end of the data extends beyond the end of the record. |
| 2426 ** (offset > pC->payloadSize) | |
| 2427 */ | 2519 */ |
| 2428 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset!=pC->payloadSize)) | 2520 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize)) |
| 2429 || (offset > pC->payloadSize) | 2521 || (offset64 > pC->payloadSize) |
| 2430 ){ | 2522 ){ |
| 2431 rc = SQLITE_CORRUPT_BKPT; | 2523 rc = SQLITE_CORRUPT_BKPT; |
| 2432 goto op_column_error; | 2524 goto op_column_error; |
| 2433 } | 2525 } |
| 2526 }else{ |
| 2527 t = 0; |
| 2434 } | 2528 } |
| 2435 | 2529 |
| 2436 /* If after trying to extra new entries from the header, nHdrParsed is | 2530 /* If after trying to extract new entries from the header, nHdrParsed is |
| 2437 ** still not up to p2, that means that the record has fewer than p2 | 2531 ** still not up to p2, that means that the record has fewer than p2 |
| 2438 ** columns. So the result will be either the default value or a NULL. | 2532 ** columns. So the result will be either the default value or a NULL. |
| 2439 */ | 2533 */ |
| 2440 if( pC->nHdrParsed<=p2 ){ | 2534 if( pC->nHdrParsed<=p2 ){ |
| 2441 if( pOp->p4type==P4_MEM ){ | 2535 if( pOp->p4type==P4_MEM ){ |
| 2442 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); | 2536 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); |
| 2443 }else{ | 2537 }else{ |
| 2444 sqlite3VdbeMemSetNull(pDest); | 2538 sqlite3VdbeMemSetNull(pDest); |
| 2445 } | 2539 } |
| 2446 goto op_column_out; | 2540 goto op_column_out; |
| 2447 } | 2541 } |
| 2542 }else{ |
| 2543 t = pC->aType[p2]; |
| 2448 } | 2544 } |
| 2449 | 2545 |
| 2450 /* Extract the content for the p2+1-th column. Control can only | 2546 /* Extract the content for the p2+1-th column. Control can only |
| 2451 ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are | 2547 ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are |
| 2452 ** all valid. | 2548 ** all valid. |
| 2453 */ | 2549 */ |
| 2454 assert( p2<pC->nHdrParsed ); | 2550 assert( p2<pC->nHdrParsed ); |
| 2455 assert( rc==SQLITE_OK ); | 2551 assert( rc==SQLITE_OK ); |
| 2456 assert( sqlite3VdbeCheckMemInvariants(pDest) ); | 2552 assert( sqlite3VdbeCheckMemInvariants(pDest) ); |
| 2457 if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest); | 2553 if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest); |
| 2458 t = pC->aType[p2]; | 2554 assert( t==pC->aType[p2] ); |
| 2459 if( pC->szRow>=aOffset[p2+1] ){ | 2555 if( pC->szRow>=aOffset[p2+1] ){ |
| 2460 /* This is the common case where the desired content fits on the original | 2556 /* This is the common case where the desired content fits on the original |
| 2461 ** page - where the content is not on an overflow page */ | 2557 ** page - where the content is not on an overflow page */ |
| 2462 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], t, pDest); | 2558 sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], t, pDest); |
| 2463 }else{ | 2559 }else{ |
| 2464 /* This branch happens only when content is on overflow pages */ | 2560 /* This branch happens only when content is on overflow pages */ |
| 2465 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 | 2561 if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 2466 && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) | 2562 && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) |
| 2467 || (len = sqlite3VdbeSerialTypeLen(t))==0 | 2563 || (len = sqlite3VdbeSerialTypeLen(t))==0 |
| 2468 ){ | 2564 ){ |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2542 ** use as a data record in a database table or as a key | 2638 ** use as a data record in a database table or as a key |
| 2543 ** in an index. The OP_Column opcode can decode the record later. | 2639 ** in an index. The OP_Column opcode can decode the record later. |
| 2544 ** | 2640 ** |
| 2545 ** P4 may be a string that is P2 characters long. The nth character of the | 2641 ** P4 may be a string that is P2 characters long. The nth character of the |
| 2546 ** string indicates the column affinity that should be used for the nth | 2642 ** string indicates the column affinity that should be used for the nth |
| 2547 ** field of the index key. | 2643 ** field of the index key. |
| 2548 ** | 2644 ** |
| 2549 ** The mapping from character to affinity is given by the SQLITE_AFF_ | 2645 ** The mapping from character to affinity is given by the SQLITE_AFF_ |
| 2550 ** macros defined in sqliteInt.h. | 2646 ** macros defined in sqliteInt.h. |
| 2551 ** | 2647 ** |
| 2552 ** If P4 is NULL then all index fields have the affinity NONE. | 2648 ** If P4 is NULL then all index fields have the affinity BLOB. |
| 2553 */ | 2649 */ |
| 2554 case OP_MakeRecord: { | 2650 case OP_MakeRecord: { |
| 2555 u8 *zNewRecord; /* A buffer to hold the data for the new record */ | 2651 u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 2556 Mem *pRec; /* The new record */ | 2652 Mem *pRec; /* The new record */ |
| 2557 u64 nData; /* Number of bytes of data space */ | 2653 u64 nData; /* Number of bytes of data space */ |
| 2558 int nHdr; /* Number of bytes of header space */ | 2654 int nHdr; /* Number of bytes of header space */ |
| 2559 i64 nByte; /* Data space required for this record */ | 2655 i64 nByte; /* Data space required for this record */ |
| 2560 int nZero; /* Number of zero bytes at the end of the record */ | 2656 i64 nZero; /* Number of zero bytes at the end of the record */ |
| 2561 int nVarint; /* Number of bytes in a varint */ | 2657 int nVarint; /* Number of bytes in a varint */ |
| 2562 u32 serial_type; /* Type field */ | 2658 u32 serial_type; /* Type field */ |
| 2563 Mem *pData0; /* First field to be combined into the record */ | 2659 Mem *pData0; /* First field to be combined into the record */ |
| 2564 Mem *pLast; /* Last field of the record */ | 2660 Mem *pLast; /* Last field of the record */ |
| 2565 int nField; /* Number of fields in the record */ | 2661 int nField; /* Number of fields in the record */ |
| 2566 char *zAffinity; /* The affinity string for the record */ | 2662 char *zAffinity; /* The affinity string for the record */ |
| 2567 int file_format; /* File format to use for encoding */ | 2663 int file_format; /* File format to use for encoding */ |
| 2568 int i; /* Space used in zNewRecord[] header */ | 2664 int i; /* Space used in zNewRecord[] header */ |
| 2569 int j; /* Space used in zNewRecord[] content */ | 2665 int j; /* Space used in zNewRecord[] content */ |
| 2570 int len; /* Length of a field */ | 2666 u32 len; /* Length of a field */ |
| 2571 | 2667 |
| 2572 /* Assuming the record contains N fields, the record format looks | 2668 /* Assuming the record contains N fields, the record format looks |
| 2573 ** like this: | 2669 ** like this: |
| 2574 ** | 2670 ** |
| 2575 ** ------------------------------------------------------------------------ | 2671 ** ------------------------------------------------------------------------ |
| 2576 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | | 2672 ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | |
| 2577 ** ------------------------------------------------------------------------ | 2673 ** ------------------------------------------------------------------------ |
| 2578 ** | 2674 ** |
| 2579 ** Data(0) is taken from register P1. Data(1) comes from register P1+1 | 2675 ** Data(0) is taken from register P1. Data(1) comes from register P1+1 |
| 2580 ** and so forth. | 2676 ** and so forth. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2610 assert( zAffinity[0]==0 || pRec<=pLast ); | 2706 assert( zAffinity[0]==0 || pRec<=pLast ); |
| 2611 }while( zAffinity[0] ); | 2707 }while( zAffinity[0] ); |
| 2612 } | 2708 } |
| 2613 | 2709 |
| 2614 /* Loop through the elements that will make up the record to figure | 2710 /* Loop through the elements that will make up the record to figure |
| 2615 ** out how much space is required for the new record. | 2711 ** out how much space is required for the new record. |
| 2616 */ | 2712 */ |
| 2617 pRec = pLast; | 2713 pRec = pLast; |
| 2618 do{ | 2714 do{ |
| 2619 assert( memIsValid(pRec) ); | 2715 assert( memIsValid(pRec) ); |
| 2620 pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format); | 2716 pRec->uTemp = serial_type = sqlite3VdbeSerialType(pRec, file_format, &len); |
| 2621 len = sqlite3VdbeSerialTypeLen(serial_type); | |
| 2622 if( pRec->flags & MEM_Zero ){ | 2717 if( pRec->flags & MEM_Zero ){ |
| 2623 if( nData ){ | 2718 if( nData ){ |
| 2624 sqlite3VdbeMemExpandBlob(pRec); | 2719 if( sqlite3VdbeMemExpandBlob(pRec) ) goto no_mem; |
| 2625 }else{ | 2720 }else{ |
| 2626 nZero += pRec->u.nZero; | 2721 nZero += pRec->u.nZero; |
| 2627 len -= pRec->u.nZero; | 2722 len -= pRec->u.nZero; |
| 2628 } | 2723 } |
| 2629 } | 2724 } |
| 2630 nData += len; | 2725 nData += len; |
| 2631 testcase( serial_type==127 ); | 2726 testcase( serial_type==127 ); |
| 2632 testcase( serial_type==128 ); | 2727 testcase( serial_type==128 ); |
| 2633 nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type); | 2728 nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type); |
| 2634 }while( (--pRec)>=pData0 ); | 2729 }while( (--pRec)>=pData0 ); |
| 2635 | 2730 |
| 2636 /* Add the initial header varint and total the size */ | 2731 /* EVIDENCE-OF: R-22564-11647 The header begins with a single varint |
| 2732 ** which determines the total number of bytes in the header. The varint |
| 2733 ** value is the size of the header in bytes including the size varint |
| 2734 ** itself. */ |
| 2637 testcase( nHdr==126 ); | 2735 testcase( nHdr==126 ); |
| 2638 testcase( nHdr==127 ); | 2736 testcase( nHdr==127 ); |
| 2639 if( nHdr<=126 ){ | 2737 if( nHdr<=126 ){ |
| 2640 /* The common case */ | 2738 /* The common case */ |
| 2641 nHdr += 1; | 2739 nHdr += 1; |
| 2642 }else{ | 2740 }else{ |
| 2643 /* Rare case of a really large header */ | 2741 /* Rare case of a really large header */ |
| 2644 nVarint = sqlite3VarintLen(nHdr); | 2742 nVarint = sqlite3VarintLen(nHdr); |
| 2645 nHdr += nVarint; | 2743 nHdr += nVarint; |
| 2646 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; | 2744 if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; |
| 2647 } | 2745 } |
| 2648 nByte = nHdr+nData; | 2746 nByte = nHdr+nData; |
| 2649 if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | 2747 if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 2650 goto too_big; | 2748 goto too_big; |
| 2651 } | 2749 } |
| 2652 | 2750 |
| 2653 /* Make sure the output register has a buffer large enough to store | 2751 /* Make sure the output register has a buffer large enough to store |
| 2654 ** the new record. The output register (pOp->p3) is not allowed to | 2752 ** the new record. The output register (pOp->p3) is not allowed to |
| 2655 ** be one of the input registers (because the following call to | 2753 ** be one of the input registers (because the following call to |
| 2656 ** sqlite3VdbeMemClearAndResize() could clobber the value before it is used). | 2754 ** sqlite3VdbeMemClearAndResize() could clobber the value before it is used). |
| 2657 */ | 2755 */ |
| 2658 if( sqlite3VdbeMemClearAndResize(pOut, (int)nByte) ){ | 2756 if( sqlite3VdbeMemClearAndResize(pOut, (int)nByte) ){ |
| 2659 goto no_mem; | 2757 goto no_mem; |
| 2660 } | 2758 } |
| 2661 zNewRecord = (u8 *)pOut->z; | 2759 zNewRecord = (u8 *)pOut->z; |
| 2662 | 2760 |
| 2663 /* Write the record */ | 2761 /* Write the record */ |
| 2664 i = putVarint32(zNewRecord, nHdr); | 2762 i = putVarint32(zNewRecord, nHdr); |
| 2665 j = nHdr; | 2763 j = nHdr; |
| 2666 assert( pData0<=pLast ); | 2764 assert( pData0<=pLast ); |
| 2667 pRec = pData0; | 2765 pRec = pData0; |
| 2668 do{ | 2766 do{ |
| 2669 serial_type = pRec->uTemp; | 2767 serial_type = pRec->uTemp; |
| 2768 /* EVIDENCE-OF: R-06529-47362 Following the size varint are one or more |
| 2769 ** additional varints, one per column. */ |
| 2670 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */ | 2770 i += putVarint32(&zNewRecord[i], serial_type); /* serial type */ |
| 2771 /* EVIDENCE-OF: R-64536-51728 The values for each column in the record |
| 2772 ** immediately follow the header. */ |
| 2671 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */ | 2773 j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */ |
| 2672 }while( (++pRec)<=pLast ); | 2774 }while( (++pRec)<=pLast ); |
| 2673 assert( i==nHdr ); | 2775 assert( i==nHdr ); |
| 2674 assert( j==nByte ); | 2776 assert( j==nByte ); |
| 2675 | 2777 |
| 2676 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); | 2778 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 2677 pOut->n = (int)nByte; | 2779 pOut->n = (int)nByte; |
| 2678 pOut->flags = MEM_Blob; | 2780 pOut->flags = MEM_Blob; |
| 2679 if( nZero ){ | 2781 if( nZero ){ |
| 2680 pOut->u.nZero = nZero; | 2782 pOut->u.nZero = nZero; |
| 2681 pOut->flags |= MEM_Zero; | 2783 pOut->flags |= MEM_Zero; |
| 2682 } | 2784 } |
| 2683 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ | 2785 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ |
| 2684 REGISTER_TRACE(pOp->p3, pOut); | 2786 REGISTER_TRACE(pOp->p3, pOut); |
| 2685 UPDATE_MAX_BLOBSIZE(pOut); | 2787 UPDATE_MAX_BLOBSIZE(pOut); |
| 2686 break; | 2788 break; |
| 2687 } | 2789 } |
| 2688 | 2790 |
| 2689 /* Opcode: Count P1 P2 * * * | 2791 /* Opcode: Count P1 P2 * * * |
| 2690 ** Synopsis: r[P2]=count() | 2792 ** Synopsis: r[P2]=count() |
| 2691 ** | 2793 ** |
| 2692 ** Store the number of entries (an integer value) in the table or index | 2794 ** Store the number of entries (an integer value) in the table or index |
| 2693 ** opened by cursor P1 in register P2 | 2795 ** opened by cursor P1 in register P2 |
| 2694 */ | 2796 */ |
| 2695 #ifndef SQLITE_OMIT_BTREECOUNT | 2797 #ifndef SQLITE_OMIT_BTREECOUNT |
| 2696 case OP_Count: { /* out2-prerelease */ | 2798 case OP_Count: { /* out2 */ |
| 2697 i64 nEntry; | 2799 i64 nEntry; |
| 2698 BtCursor *pCrsr; | 2800 BtCursor *pCrsr; |
| 2699 | 2801 |
| 2700 pCrsr = p->apCsr[pOp->p1]->pCursor; | 2802 assert( p->apCsr[pOp->p1]->eCurType==CURTYPE_BTREE ); |
| 2803 pCrsr = p->apCsr[pOp->p1]->uc.pCursor; |
| 2701 assert( pCrsr ); | 2804 assert( pCrsr ); |
| 2702 nEntry = 0; /* Not needed. Only used to silence a warning. */ | 2805 nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 2703 rc = sqlite3BtreeCount(pCrsr, &nEntry); | 2806 rc = sqlite3BtreeCount(pCrsr, &nEntry); |
| 2807 pOut = out2Prerelease(p, pOp); |
| 2704 pOut->u.i = nEntry; | 2808 pOut->u.i = nEntry; |
| 2705 break; | 2809 break; |
| 2706 } | 2810 } |
| 2707 #endif | 2811 #endif |
| 2708 | 2812 |
| 2709 /* Opcode: Savepoint P1 * * P4 * | 2813 /* Opcode: Savepoint P1 * * P4 * |
| 2710 ** | 2814 ** |
| 2711 ** Open, release or rollback the savepoint named by parameter P4, depending | 2815 ** Open, release or rollback the savepoint named by parameter P4, depending |
| 2712 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an | 2816 ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an |
| 2713 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2. | 2817 ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2732 assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK ); | 2836 assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK ); |
| 2733 assert( db->pSavepoint || db->isTransactionSavepoint==0 ); | 2837 assert( db->pSavepoint || db->isTransactionSavepoint==0 ); |
| 2734 assert( checkSavepointCount(db) ); | 2838 assert( checkSavepointCount(db) ); |
| 2735 assert( p->bIsReader ); | 2839 assert( p->bIsReader ); |
| 2736 | 2840 |
| 2737 if( p1==SAVEPOINT_BEGIN ){ | 2841 if( p1==SAVEPOINT_BEGIN ){ |
| 2738 if( db->nVdbeWrite>0 ){ | 2842 if( db->nVdbeWrite>0 ){ |
| 2739 /* A new savepoint cannot be created if there are active write | 2843 /* A new savepoint cannot be created if there are active write |
| 2740 ** statements (i.e. open read/write incremental blob handles). | 2844 ** statements (i.e. open read/write incremental blob handles). |
| 2741 */ | 2845 */ |
| 2742 sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - " | 2846 sqlite3VdbeError(p, "cannot open savepoint - SQL statements in progress"); |
| 2743 "SQL statements in progress"); | |
| 2744 rc = SQLITE_BUSY; | 2847 rc = SQLITE_BUSY; |
| 2745 }else{ | 2848 }else{ |
| 2746 nName = sqlite3Strlen30(zName); | 2849 nName = sqlite3Strlen30(zName); |
| 2747 | 2850 |
| 2748 #ifndef SQLITE_OMIT_VIRTUALTABLE | 2851 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 2749 /* This call is Ok even if this savepoint is actually a transaction | 2852 /* This call is Ok even if this savepoint is actually a transaction |
| 2750 ** savepoint (and therefore should not prompt xSavepoint()) callbacks. | 2853 ** savepoint (and therefore should not prompt xSavepoint()) callbacks. |
| 2751 ** If this is a transaction savepoint being opened, it is guaranteed | 2854 ** If this is a transaction savepoint being opened, it is guaranteed |
| 2752 ** that the db->aVTrans[] array is empty. */ | 2855 ** that the db->aVTrans[] array is empty. */ |
| 2753 assert( db->autoCommit==0 || db->nVTrans==0 ); | 2856 assert( db->autoCommit==0 || db->nVTrans==0 ); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2784 /* Find the named savepoint. If there is no such savepoint, then an | 2887 /* Find the named savepoint. If there is no such savepoint, then an |
| 2785 ** an error is returned to the user. */ | 2888 ** an error is returned to the user. */ |
| 2786 for( | 2889 for( |
| 2787 pSavepoint = db->pSavepoint; | 2890 pSavepoint = db->pSavepoint; |
| 2788 pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName); | 2891 pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName); |
| 2789 pSavepoint = pSavepoint->pNext | 2892 pSavepoint = pSavepoint->pNext |
| 2790 ){ | 2893 ){ |
| 2791 iSavepoint++; | 2894 iSavepoint++; |
| 2792 } | 2895 } |
| 2793 if( !pSavepoint ){ | 2896 if( !pSavepoint ){ |
| 2794 sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName); | 2897 sqlite3VdbeError(p, "no such savepoint: %s", zName); |
| 2795 rc = SQLITE_ERROR; | 2898 rc = SQLITE_ERROR; |
| 2796 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){ | 2899 }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){ |
| 2797 /* It is not possible to release (commit) a savepoint if there are | 2900 /* It is not possible to release (commit) a savepoint if there are |
| 2798 ** active write statements. | 2901 ** active write statements. |
| 2799 */ | 2902 */ |
| 2800 sqlite3SetString(&p->zErrMsg, db, | 2903 sqlite3VdbeError(p, "cannot release savepoint - " |
| 2801 "cannot release savepoint - SQL statements in progress" | 2904 "SQL statements in progress"); |
| 2802 ); | |
| 2803 rc = SQLITE_BUSY; | 2905 rc = SQLITE_BUSY; |
| 2804 }else{ | 2906 }else{ |
| 2805 | 2907 |
| 2806 /* Determine whether or not this is a transaction savepoint. If so, | 2908 /* Determine whether or not this is a transaction savepoint. If so, |
| 2807 ** and this is a RELEASE command, then the current transaction | 2909 ** and this is a RELEASE command, then the current transaction |
| 2808 ** is committed. | 2910 ** is committed. |
| 2809 */ | 2911 */ |
| 2810 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint; | 2912 int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint; |
| 2811 if( isTransaction && p1==SAVEPOINT_RELEASE ){ | 2913 if( isTransaction && p1==SAVEPOINT_RELEASE ){ |
| 2812 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ | 2914 if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 2813 goto vdbe_return; | 2915 goto vdbe_return; |
| 2814 } | 2916 } |
| 2815 db->autoCommit = 1; | 2917 db->autoCommit = 1; |
| 2816 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ | 2918 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 2817 p->pc = pc; | 2919 p->pc = (int)(pOp - aOp); |
| 2818 db->autoCommit = 0; | 2920 db->autoCommit = 0; |
| 2819 p->rc = rc = SQLITE_BUSY; | 2921 p->rc = rc = SQLITE_BUSY; |
| 2820 goto vdbe_return; | 2922 goto vdbe_return; |
| 2821 } | 2923 } |
| 2822 db->isTransactionSavepoint = 0; | 2924 db->isTransactionSavepoint = 0; |
| 2823 rc = p->rc; | 2925 rc = p->rc; |
| 2824 }else{ | 2926 }else{ |
| 2825 int isSchemaChange; | 2927 int isSchemaChange; |
| 2826 iSavepoint = db->nSavepoint - iSavepoint - 1; | 2928 iSavepoint = db->nSavepoint - iSavepoint - 1; |
| 2827 if( p1==SAVEPOINT_ROLLBACK ){ | 2929 if( p1==SAVEPOINT_ROLLBACK ){ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2866 db->pSavepoint = pSavepoint->pNext; | 2968 db->pSavepoint = pSavepoint->pNext; |
| 2867 sqlite3DbFree(db, pSavepoint); | 2969 sqlite3DbFree(db, pSavepoint); |
| 2868 if( !isTransaction ){ | 2970 if( !isTransaction ){ |
| 2869 db->nSavepoint--; | 2971 db->nSavepoint--; |
| 2870 } | 2972 } |
| 2871 }else{ | 2973 }else{ |
| 2872 db->nDeferredCons = pSavepoint->nDeferredCons; | 2974 db->nDeferredCons = pSavepoint->nDeferredCons; |
| 2873 db->nDeferredImmCons = pSavepoint->nDeferredImmCons; | 2975 db->nDeferredImmCons = pSavepoint->nDeferredImmCons; |
| 2874 } | 2976 } |
| 2875 | 2977 |
| 2876 if( !isTransaction ){ | 2978 if( !isTransaction || p1==SAVEPOINT_ROLLBACK ){ |
| 2877 rc = sqlite3VtabSavepoint(db, p1, iSavepoint); | 2979 rc = sqlite3VtabSavepoint(db, p1, iSavepoint); |
| 2878 if( rc!=SQLITE_OK ) goto abort_due_to_error; | 2980 if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 2879 } | 2981 } |
| 2880 } | 2982 } |
| 2881 } | 2983 } |
| 2882 | 2984 |
| 2883 break; | 2985 break; |
| 2884 } | 2986 } |
| 2885 | 2987 |
| 2886 /* Opcode: AutoCommit P1 P2 * * * | 2988 /* Opcode: AutoCommit P1 P2 * * * |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2898 int turnOnAC; | 3000 int turnOnAC; |
| 2899 | 3001 |
| 2900 desiredAutoCommit = pOp->p1; | 3002 desiredAutoCommit = pOp->p1; |
| 2901 iRollback = pOp->p2; | 3003 iRollback = pOp->p2; |
| 2902 turnOnAC = desiredAutoCommit && !db->autoCommit; | 3004 turnOnAC = desiredAutoCommit && !db->autoCommit; |
| 2903 assert( desiredAutoCommit==1 || desiredAutoCommit==0 ); | 3005 assert( desiredAutoCommit==1 || desiredAutoCommit==0 ); |
| 2904 assert( desiredAutoCommit==1 || iRollback==0 ); | 3006 assert( desiredAutoCommit==1 || iRollback==0 ); |
| 2905 assert( db->nVdbeActive>0 ); /* At least this one VM is active */ | 3007 assert( db->nVdbeActive>0 ); /* At least this one VM is active */ |
| 2906 assert( p->bIsReader ); | 3008 assert( p->bIsReader ); |
| 2907 | 3009 |
| 2908 #if 0 | |
| 2909 if( turnOnAC && iRollback && db->nVdbeActive>1 ){ | |
| 2910 /* If this instruction implements a ROLLBACK and other VMs are | |
| 2911 ** still running, and a transaction is active, return an error indicating | |
| 2912 ** that the other VMs must complete first. | |
| 2913 */ | |
| 2914 sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - " | |
| 2915 "SQL statements in progress"); | |
| 2916 rc = SQLITE_BUSY; | |
| 2917 }else | |
| 2918 #endif | |
| 2919 if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){ | 3010 if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){ |
| 2920 /* If this instruction implements a COMMIT and other VMs are writing | 3011 /* If this instruction implements a COMMIT and other VMs are writing |
| 2921 ** return an error indicating that the other VMs must complete first. | 3012 ** return an error indicating that the other VMs must complete first. |
| 2922 */ | 3013 */ |
| 2923 sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - " | 3014 sqlite3VdbeError(p, "cannot commit transaction - " |
| 2924 "SQL statements in progress"); | 3015 "SQL statements in progress"); |
| 2925 rc = SQLITE_BUSY; | 3016 rc = SQLITE_BUSY; |
| 2926 }else if( desiredAutoCommit!=db->autoCommit ){ | 3017 }else if( desiredAutoCommit!=db->autoCommit ){ |
| 2927 if( iRollback ){ | 3018 if( iRollback ){ |
| 2928 assert( desiredAutoCommit==1 ); | 3019 assert( desiredAutoCommit==1 ); |
| 2929 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); | 3020 sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 2930 db->autoCommit = 1; | 3021 db->autoCommit = 1; |
| 2931 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ | 3022 }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 2932 goto vdbe_return; | 3023 goto vdbe_return; |
| 2933 }else{ | 3024 }else{ |
| 2934 db->autoCommit = (u8)desiredAutoCommit; | 3025 db->autoCommit = (u8)desiredAutoCommit; |
| 2935 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ | 3026 } |
| 2936 p->pc = pc; | 3027 if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 2937 db->autoCommit = (u8)(1-desiredAutoCommit); | 3028 p->pc = (int)(pOp - aOp); |
| 2938 p->rc = rc = SQLITE_BUSY; | 3029 db->autoCommit = (u8)(1-desiredAutoCommit); |
| 2939 goto vdbe_return; | 3030 p->rc = rc = SQLITE_BUSY; |
| 2940 } | 3031 goto vdbe_return; |
| 2941 } | 3032 } |
| 2942 assert( db->nStatement==0 ); | 3033 assert( db->nStatement==0 ); |
| 2943 sqlite3CloseSavepoints(db); | 3034 sqlite3CloseSavepoints(db); |
| 2944 if( p->rc==SQLITE_OK ){ | 3035 if( p->rc==SQLITE_OK ){ |
| 2945 rc = SQLITE_DONE; | 3036 rc = SQLITE_DONE; |
| 2946 }else{ | 3037 }else{ |
| 2947 rc = SQLITE_ERROR; | 3038 rc = SQLITE_ERROR; |
| 2948 } | 3039 } |
| 2949 goto vdbe_return; | 3040 goto vdbe_return; |
| 2950 }else{ | 3041 }else{ |
| 2951 sqlite3SetString(&p->zErrMsg, db, | 3042 sqlite3VdbeError(p, |
| 2952 (!desiredAutoCommit)?"cannot start a transaction within a transaction":( | 3043 (!desiredAutoCommit)?"cannot start a transaction within a transaction":( |
| 2953 (iRollback)?"cannot rollback - no transaction is active": | 3044 (iRollback)?"cannot rollback - no transaction is active": |
| 2954 "cannot commit - no transaction is active")); | 3045 "cannot commit - no transaction is active")); |
| 2955 | 3046 |
| 2956 rc = SQLITE_ERROR; | 3047 rc = SQLITE_ERROR; |
| 2957 } | 3048 } |
| 2958 break; | 3049 break; |
| 2959 } | 3050 } |
| 2960 | 3051 |
| 2961 /* Opcode: Transaction P1 P2 P3 P4 P5 | 3052 /* Opcode: Transaction P1 P2 P3 P4 P5 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3002 assert( pOp->p1>=0 && pOp->p1<db->nDb ); | 3093 assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 3003 assert( DbMaskTest(p->btreeMask, pOp->p1) ); | 3094 assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 3004 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ | 3095 if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ |
| 3005 rc = SQLITE_READONLY; | 3096 rc = SQLITE_READONLY; |
| 3006 goto abort_due_to_error; | 3097 goto abort_due_to_error; |
| 3007 } | 3098 } |
| 3008 pBt = db->aDb[pOp->p1].pBt; | 3099 pBt = db->aDb[pOp->p1].pBt; |
| 3009 | 3100 |
| 3010 if( pBt ){ | 3101 if( pBt ){ |
| 3011 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); | 3102 rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); |
| 3012 if( rc==SQLITE_BUSY ){ | 3103 testcase( rc==SQLITE_BUSY_SNAPSHOT ); |
| 3013 p->pc = pc; | 3104 testcase( rc==SQLITE_BUSY_RECOVERY ); |
| 3014 p->rc = rc = SQLITE_BUSY; | 3105 if( (rc&0xff)==SQLITE_BUSY ){ |
| 3106 p->pc = (int)(pOp - aOp); |
| 3107 p->rc = rc; |
| 3015 goto vdbe_return; | 3108 goto vdbe_return; |
| 3016 } | 3109 } |
| 3017 if( rc!=SQLITE_OK ){ | 3110 if( rc!=SQLITE_OK ){ |
| 3018 goto abort_due_to_error; | 3111 goto abort_due_to_error; |
| 3019 } | 3112 } |
| 3020 | 3113 |
| 3021 if( pOp->p2 && p->usesStmtJournal | 3114 if( pOp->p2 && p->usesStmtJournal |
| 3022 && (db->autoCommit==0 || db->nVdbeRead>1) | 3115 && (db->autoCommit==0 || db->nVdbeRead>1) |
| 3023 ){ | 3116 ){ |
| 3024 assert( sqlite3BtreeIsInTrans(pBt) ); | 3117 assert( sqlite3BtreeIsInTrans(pBt) ); |
| 3025 if( p->iStatement==0 ){ | 3118 if( p->iStatement==0 ){ |
| 3026 assert( db->nStatement>=0 && db->nSavepoint>=0 ); | 3119 assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 3027 db->nStatement++; | 3120 db->nStatement++; |
| 3028 p->iStatement = db->nSavepoint + db->nStatement; | 3121 p->iStatement = db->nSavepoint + db->nStatement; |
| 3029 } | 3122 } |
| 3030 | 3123 |
| 3031 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1); | 3124 rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1); |
| 3032 if( rc==SQLITE_OK ){ | 3125 if( rc==SQLITE_OK ){ |
| 3033 rc = sqlite3BtreeBeginStmt(pBt, p->iStatement); | 3126 rc = sqlite3BtreeBeginStmt(pBt, p->iStatement); |
| 3034 } | 3127 } |
| 3035 | 3128 |
| 3036 /* Store the current value of the database handles deferred constraint | 3129 /* Store the current value of the database handles deferred constraint |
| 3037 ** counter. If the statement transaction needs to be rolled back, | 3130 ** counter. If the statement transaction needs to be rolled back, |
| 3038 ** the value of this counter needs to be restored too. */ | 3131 ** the value of this counter needs to be restored too. */ |
| 3039 p->nStmtDefCons = db->nDeferredCons; | 3132 p->nStmtDefCons = db->nDeferredCons; |
| 3040 p->nStmtDefImmCons = db->nDeferredImmCons; | 3133 p->nStmtDefImmCons = db->nDeferredImmCons; |
| 3041 } | 3134 } |
| 3042 | 3135 |
| 3043 /* Gather the schema version number for checking */ | 3136 /* Gather the schema version number for checking: |
| 3137 ** IMPLEMENTATION-OF: R-32195-19465 The schema version is used by SQLite |
| 3138 ** each time a query is executed to ensure that the internal cache of the |
| 3139 ** schema used when compiling the SQL query matches the schema of the |
| 3140 ** database against which the compiled query is actually executed. |
| 3141 */ |
| 3044 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta); | 3142 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta); |
| 3045 iGen = db->aDb[pOp->p1].pSchema->iGeneration; | 3143 iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 3046 }else{ | 3144 }else{ |
| 3047 iGen = iMeta = 0; | 3145 iGen = iMeta = 0; |
| 3048 } | 3146 } |
| 3049 assert( pOp->p5==0 || pOp->p4type==P4_INT32 ); | 3147 assert( pOp->p5==0 || pOp->p4type==P4_INT32 ); |
| 3050 if( pOp->p5 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){ | 3148 if( pOp->p5 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){ |
| 3051 sqlite3DbFree(db, p->zErrMsg); | 3149 sqlite3DbFree(db, p->zErrMsg); |
| 3052 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); | 3150 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 3053 /* If the schema-cookie from the database file matches the cookie | 3151 /* If the schema-cookie from the database file matches the cookie |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3077 ** Read cookie number P3 from database P1 and write it into register P2. | 3175 ** Read cookie number P3 from database P1 and write it into register P2. |
| 3078 ** P3==1 is the schema version. P3==2 is the database format. | 3176 ** P3==1 is the schema version. P3==2 is the database format. |
| 3079 ** P3==3 is the recommended pager cache size, and so forth. P1==0 is | 3177 ** P3==3 is the recommended pager cache size, and so forth. P1==0 is |
| 3080 ** the main database file and P1==1 is the database file used to store | 3178 ** the main database file and P1==1 is the database file used to store |
| 3081 ** temporary tables. | 3179 ** temporary tables. |
| 3082 ** | 3180 ** |
| 3083 ** There must be a read-lock on the database (either a transaction | 3181 ** There must be a read-lock on the database (either a transaction |
| 3084 ** must be started or there must be an open cursor) before | 3182 ** must be started or there must be an open cursor) before |
| 3085 ** executing this instruction. | 3183 ** executing this instruction. |
| 3086 */ | 3184 */ |
| 3087 case OP_ReadCookie: { /* out2-prerelease */ | 3185 case OP_ReadCookie: { /* out2 */ |
| 3088 int iMeta; | 3186 int iMeta; |
| 3089 int iDb; | 3187 int iDb; |
| 3090 int iCookie; | 3188 int iCookie; |
| 3091 | 3189 |
| 3092 assert( p->bIsReader ); | 3190 assert( p->bIsReader ); |
| 3093 iDb = pOp->p1; | 3191 iDb = pOp->p1; |
| 3094 iCookie = pOp->p3; | 3192 iCookie = pOp->p3; |
| 3095 assert( pOp->p3<SQLITE_N_BTREE_META ); | 3193 assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 3096 assert( iDb>=0 && iDb<db->nDb ); | 3194 assert( iDb>=0 && iDb<db->nDb ); |
| 3097 assert( db->aDb[iDb].pBt!=0 ); | 3195 assert( db->aDb[iDb].pBt!=0 ); |
| 3098 assert( DbMaskTest(p->btreeMask, iDb) ); | 3196 assert( DbMaskTest(p->btreeMask, iDb) ); |
| 3099 | 3197 |
| 3100 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); | 3198 sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); |
| 3199 pOut = out2Prerelease(p, pOp); |
| 3101 pOut->u.i = iMeta; | 3200 pOut->u.i = iMeta; |
| 3102 break; | 3201 break; |
| 3103 } | 3202 } |
| 3104 | 3203 |
| 3105 /* Opcode: SetCookie P1 P2 P3 * * | 3204 /* Opcode: SetCookie P1 P2 P3 * * |
| 3106 ** | 3205 ** |
| 3107 ** Write the content of register P3 (interpreted as an integer) | 3206 ** Write the content of register P3 (interpreted as an integer) |
| 3108 ** into cookie number P2 of database P1. P2==1 is the schema version. | 3207 ** into cookie number P2 of database P1. P2==1 is the schema version. |
| 3109 ** P2==2 is the database format. P2==3 is the recommended pager cache | 3208 ** P2==2 is the database format. P2==3 is the recommended pager cache |
| 3110 ** size, and so forth. P1==0 is the main database file and P1==1 is the | 3209 ** size, and so forth. P1==0 is the main database file and P1==1 is the |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3201 ** value, it is set to the number of columns in the table, or to the | 3300 ** value, it is set to the number of columns in the table, or to the |
| 3202 ** largest index of any column of the table that is actually used. | 3301 ** largest index of any column of the table that is actually used. |
| 3203 ** | 3302 ** |
| 3204 ** This instruction works just like OpenRead except that it opens the cursor | 3303 ** This instruction works just like OpenRead except that it opens the cursor |
| 3205 ** in read/write mode. For a given table, there can be one or more read-only | 3304 ** in read/write mode. For a given table, there can be one or more read-only |
| 3206 ** cursors or a single read/write cursor but not both. | 3305 ** cursors or a single read/write cursor but not both. |
| 3207 ** | 3306 ** |
| 3208 ** See also OpenRead. | 3307 ** See also OpenRead. |
| 3209 */ | 3308 */ |
| 3210 case OP_ReopenIdx: { | 3309 case OP_ReopenIdx: { |
| 3211 VdbeCursor *pCur; | |
| 3212 | |
| 3213 assert( pOp->p5==0 ); | |
| 3214 assert( pOp->p4type==P4_KEYINFO ); | |
| 3215 pCur = p->apCsr[pOp->p1]; | |
| 3216 if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){ | |
| 3217 assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */ | |
| 3218 break; | |
| 3219 } | |
| 3220 /* If the cursor is not currently open or is open on a different | |
| 3221 ** index, then fall through into OP_OpenRead to force a reopen */ | |
| 3222 } | |
| 3223 case OP_OpenRead: | |
| 3224 case OP_OpenWrite: { | |
| 3225 int nField; | 3310 int nField; |
| 3226 KeyInfo *pKeyInfo; | 3311 KeyInfo *pKeyInfo; |
| 3227 int p2; | 3312 int p2; |
| 3228 int iDb; | 3313 int iDb; |
| 3229 int wrFlag; | 3314 int wrFlag; |
| 3230 Btree *pX; | 3315 Btree *pX; |
| 3231 VdbeCursor *pCur; | 3316 VdbeCursor *pCur; |
| 3232 Db *pDb; | 3317 Db *pDb; |
| 3233 | 3318 |
| 3234 assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 ); | 3319 assert( pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ ); |
| 3235 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 ); | 3320 assert( pOp->p4type==P4_KEYINFO ); |
| 3321 pCur = p->apCsr[pOp->p1]; |
| 3322 if( pCur && pCur->pgnoRoot==(u32)pOp->p2 ){ |
| 3323 assert( pCur->iDb==pOp->p3 ); /* Guaranteed by the code generator */ |
| 3324 goto open_cursor_set_hints; |
| 3325 } |
| 3326 /* If the cursor is not currently open or is open on a different |
| 3327 ** index, then fall through into OP_OpenRead to force a reopen */ |
| 3328 case OP_OpenRead: |
| 3329 case OP_OpenWrite: |
| 3330 |
| 3331 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ ); |
| 3236 assert( p->bIsReader ); | 3332 assert( p->bIsReader ); |
| 3237 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx | 3333 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx |
| 3238 || p->readOnly==0 ); | 3334 || p->readOnly==0 ); |
| 3239 | 3335 |
| 3240 if( p->expired ){ | 3336 if( p->expired ){ |
| 3241 rc = SQLITE_ABORT_ROLLBACK; | 3337 rc = SQLITE_ABORT_ROLLBACK; |
| 3242 break; | 3338 break; |
| 3243 } | 3339 } |
| 3244 | 3340 |
| 3245 nField = 0; | 3341 nField = 0; |
| 3246 pKeyInfo = 0; | 3342 pKeyInfo = 0; |
| 3247 p2 = pOp->p2; | 3343 p2 = pOp->p2; |
| 3248 iDb = pOp->p3; | 3344 iDb = pOp->p3; |
| 3249 assert( iDb>=0 && iDb<db->nDb ); | 3345 assert( iDb>=0 && iDb<db->nDb ); |
| 3250 assert( DbMaskTest(p->btreeMask, iDb) ); | 3346 assert( DbMaskTest(p->btreeMask, iDb) ); |
| 3251 pDb = &db->aDb[iDb]; | 3347 pDb = &db->aDb[iDb]; |
| 3252 pX = pDb->pBt; | 3348 pX = pDb->pBt; |
| 3253 assert( pX!=0 ); | 3349 assert( pX!=0 ); |
| 3254 if( pOp->opcode==OP_OpenWrite ){ | 3350 if( pOp->opcode==OP_OpenWrite ){ |
| 3255 wrFlag = 1; | 3351 assert( OPFLAG_FORDELETE==BTREE_FORDELETE ); |
| 3352 wrFlag = BTREE_WRCSR | (pOp->p5 & OPFLAG_FORDELETE); |
| 3256 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | 3353 assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 3257 if( pDb->pSchema->file_format < p->minWriteFileFormat ){ | 3354 if( pDb->pSchema->file_format < p->minWriteFileFormat ){ |
| 3258 p->minWriteFileFormat = pDb->pSchema->file_format; | 3355 p->minWriteFileFormat = pDb->pSchema->file_format; |
| 3259 } | 3356 } |
| 3260 }else{ | 3357 }else{ |
| 3261 wrFlag = 0; | 3358 wrFlag = 0; |
| 3262 } | 3359 } |
| 3263 if( pOp->p5 & OPFLAG_P2ISREG ){ | 3360 if( pOp->p5 & OPFLAG_P2ISREG ){ |
| 3264 assert( p2>0 ); | 3361 assert( p2>0 ); |
| 3265 assert( p2<=(p->nMem-p->nCursor) ); | 3362 assert( p2<=(p->nMem-p->nCursor) ); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3281 pKeyInfo = pOp->p4.pKeyInfo; | 3378 pKeyInfo = pOp->p4.pKeyInfo; |
| 3282 assert( pKeyInfo->enc==ENC(db) ); | 3379 assert( pKeyInfo->enc==ENC(db) ); |
| 3283 assert( pKeyInfo->db==db ); | 3380 assert( pKeyInfo->db==db ); |
| 3284 nField = pKeyInfo->nField+pKeyInfo->nXField; | 3381 nField = pKeyInfo->nField+pKeyInfo->nXField; |
| 3285 }else if( pOp->p4type==P4_INT32 ){ | 3382 }else if( pOp->p4type==P4_INT32 ){ |
| 3286 nField = pOp->p4.i; | 3383 nField = pOp->p4.i; |
| 3287 } | 3384 } |
| 3288 assert( pOp->p1>=0 ); | 3385 assert( pOp->p1>=0 ); |
| 3289 assert( nField>=0 ); | 3386 assert( nField>=0 ); |
| 3290 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ | 3387 testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ |
| 3291 pCur = allocateCursor(p, pOp->p1, nField, iDb, 1); | 3388 pCur = allocateCursor(p, pOp->p1, nField, iDb, CURTYPE_BTREE); |
| 3292 if( pCur==0 ) goto no_mem; | 3389 if( pCur==0 ) goto no_mem; |
| 3293 pCur->nullRow = 1; | 3390 pCur->nullRow = 1; |
| 3294 pCur->isOrdered = 1; | 3391 pCur->isOrdered = 1; |
| 3295 pCur->pgnoRoot = p2; | 3392 pCur->pgnoRoot = p2; |
| 3296 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor); | 3393 rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->uc.pCursor); |
| 3297 pCur->pKeyInfo = pKeyInfo; | 3394 pCur->pKeyInfo = pKeyInfo; |
| 3298 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); | |
| 3299 sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR)); | |
| 3300 | |
| 3301 /* Set the VdbeCursor.isTable variable. Previous versions of | 3395 /* Set the VdbeCursor.isTable variable. Previous versions of |
| 3302 ** SQLite used to check if the root-page flags were sane at this point | 3396 ** SQLite used to check if the root-page flags were sane at this point |
| 3303 ** and report database corruption if they were not, but this check has | 3397 ** and report database corruption if they were not, but this check has |
| 3304 ** since moved into the btree layer. */ | 3398 ** since moved into the btree layer. */ |
| 3305 pCur->isTable = pOp->p4type!=P4_KEYINFO; | 3399 pCur->isTable = pOp->p4type!=P4_KEYINFO; |
| 3400 |
| 3401 open_cursor_set_hints: |
| 3402 assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); |
| 3403 assert( OPFLAG_SEEKEQ==BTREE_SEEK_EQ ); |
| 3404 testcase( pOp->p5 & OPFLAG_BULKCSR ); |
| 3405 #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 3406 testcase( pOp->p2 & OPFLAG_SEEKEQ ); |
| 3407 #endif |
| 3408 sqlite3BtreeCursorHintFlags(pCur->uc.pCursor, |
| 3409 (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ))); |
| 3306 break; | 3410 break; |
| 3307 } | 3411 } |
| 3308 | 3412 |
| 3309 /* Opcode: OpenEphemeral P1 P2 * P4 P5 | 3413 /* Opcode: OpenEphemeral P1 P2 * P4 P5 |
| 3310 ** Synopsis: nColumn=P2 | 3414 ** Synopsis: nColumn=P2 |
| 3311 ** | 3415 ** |
| 3312 ** Open a new cursor P1 to a transient table. | 3416 ** Open a new cursor P1 to a transient table. |
| 3313 ** The cursor is always opened read/write even if | 3417 ** The cursor is always opened read/write even if |
| 3314 ** the main database is read-only. The ephemeral | 3418 ** the main database is read-only. The ephemeral |
| 3315 ** table is deleted automatically when the cursor is closed. | 3419 ** table is deleted automatically when the cursor is closed. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3338 KeyInfo *pKeyInfo; | 3442 KeyInfo *pKeyInfo; |
| 3339 | 3443 |
| 3340 static const int vfsFlags = | 3444 static const int vfsFlags = |
| 3341 SQLITE_OPEN_READWRITE | | 3445 SQLITE_OPEN_READWRITE | |
| 3342 SQLITE_OPEN_CREATE | | 3446 SQLITE_OPEN_CREATE | |
| 3343 SQLITE_OPEN_EXCLUSIVE | | 3447 SQLITE_OPEN_EXCLUSIVE | |
| 3344 SQLITE_OPEN_DELETEONCLOSE | | 3448 SQLITE_OPEN_DELETEONCLOSE | |
| 3345 SQLITE_OPEN_TRANSIENT_DB; | 3449 SQLITE_OPEN_TRANSIENT_DB; |
| 3346 assert( pOp->p1>=0 ); | 3450 assert( pOp->p1>=0 ); |
| 3347 assert( pOp->p2>=0 ); | 3451 assert( pOp->p2>=0 ); |
| 3348 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); | 3452 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE); |
| 3349 if( pCx==0 ) goto no_mem; | 3453 if( pCx==0 ) goto no_mem; |
| 3350 pCx->nullRow = 1; | 3454 pCx->nullRow = 1; |
| 3351 pCx->isEphemeral = 1; | 3455 pCx->isEphemeral = 1; |
| 3352 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt, | 3456 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt, |
| 3353 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); | 3457 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| 3354 if( rc==SQLITE_OK ){ | 3458 if( rc==SQLITE_OK ){ |
| 3355 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1); | 3459 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1); |
| 3356 } | 3460 } |
| 3357 if( rc==SQLITE_OK ){ | 3461 if( rc==SQLITE_OK ){ |
| 3358 /* If a transient index is required, create it by calling | 3462 /* If a transient index is required, create it by calling |
| 3359 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before | 3463 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before |
| 3360 ** opening it. If a transient table is required, just use the | 3464 ** opening it. If a transient table is required, just use the |
| 3361 ** automatically created table with root-page 1 (an BLOB_INTKEY table). | 3465 ** automatically created table with root-page 1 (an BLOB_INTKEY table). |
| 3362 */ | 3466 */ |
| 3363 if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ | 3467 if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 3364 int pgno; | 3468 int pgno; |
| 3365 assert( pOp->p4type==P4_KEYINFO ); | 3469 assert( pOp->p4type==P4_KEYINFO ); |
| 3366 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); | 3470 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); |
| 3367 if( rc==SQLITE_OK ){ | 3471 if( rc==SQLITE_OK ){ |
| 3368 assert( pgno==MASTER_ROOT+1 ); | 3472 assert( pgno==MASTER_ROOT+1 ); |
| 3369 assert( pKeyInfo->db==db ); | 3473 assert( pKeyInfo->db==db ); |
| 3370 assert( pKeyInfo->enc==ENC(db) ); | 3474 assert( pKeyInfo->enc==ENC(db) ); |
| 3371 pCx->pKeyInfo = pKeyInfo; | 3475 pCx->pKeyInfo = pKeyInfo; |
| 3372 rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor); | 3476 rc = sqlite3BtreeCursor(pCx->pBt, pgno, BTREE_WRCSR, |
| 3477 pKeyInfo, pCx->uc.pCursor); |
| 3373 } | 3478 } |
| 3374 pCx->isTable = 0; | 3479 pCx->isTable = 0; |
| 3375 }else{ | 3480 }else{ |
| 3376 rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor); | 3481 rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, BTREE_WRCSR, |
| 3482 0, pCx->uc.pCursor); |
| 3377 pCx->isTable = 1; | 3483 pCx->isTable = 1; |
| 3378 } | 3484 } |
| 3379 } | 3485 } |
| 3380 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); | 3486 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 3381 break; | 3487 break; |
| 3382 } | 3488 } |
| 3383 | 3489 |
| 3384 /* Opcode: SorterOpen P1 P2 P3 P4 * | 3490 /* Opcode: SorterOpen P1 P2 P3 P4 * |
| 3385 ** | 3491 ** |
| 3386 ** This opcode works like OP_OpenEphemeral except that it opens | 3492 ** This opcode works like OP_OpenEphemeral except that it opens |
| 3387 ** a transient index that is specifically designed to sort large | 3493 ** a transient index that is specifically designed to sort large |
| 3388 ** tables using an external merge-sort algorithm. | 3494 ** tables using an external merge-sort algorithm. |
| 3389 ** | 3495 ** |
| 3390 ** If argument P3 is non-zero, then it indicates that the sorter may | 3496 ** If argument P3 is non-zero, then it indicates that the sorter may |
| 3391 ** assume that a stable sort considering the first P3 fields of each | 3497 ** assume that a stable sort considering the first P3 fields of each |
| 3392 ** key is sufficient to produce the required results. | 3498 ** key is sufficient to produce the required results. |
| 3393 */ | 3499 */ |
| 3394 case OP_SorterOpen: { | 3500 case OP_SorterOpen: { |
| 3395 VdbeCursor *pCx; | 3501 VdbeCursor *pCx; |
| 3396 | 3502 |
| 3397 assert( pOp->p1>=0 ); | 3503 assert( pOp->p1>=0 ); |
| 3398 assert( pOp->p2>=0 ); | 3504 assert( pOp->p2>=0 ); |
| 3399 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); | 3505 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_SORTER); |
| 3400 if( pCx==0 ) goto no_mem; | 3506 if( pCx==0 ) goto no_mem; |
| 3401 pCx->pKeyInfo = pOp->p4.pKeyInfo; | 3507 pCx->pKeyInfo = pOp->p4.pKeyInfo; |
| 3402 assert( pCx->pKeyInfo->db==db ); | 3508 assert( pCx->pKeyInfo->db==db ); |
| 3403 assert( pCx->pKeyInfo->enc==ENC(db) ); | 3509 assert( pCx->pKeyInfo->enc==ENC(db) ); |
| 3404 rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx); | 3510 rc = sqlite3VdbeSorterInit(db, pOp->p3, pCx); |
| 3405 break; | 3511 break; |
| 3406 } | 3512 } |
| 3407 | 3513 |
| 3408 /* Opcode: SequenceTest P1 P2 * * * | 3514 /* Opcode: SequenceTest P1 P2 * * * |
| 3409 ** Synopsis: if( cursor[P1].ctr++ ) pc = P2 | 3515 ** Synopsis: if( cursor[P1].ctr++ ) pc = P2 |
| 3410 ** | 3516 ** |
| 3411 ** P1 is a sorter cursor. If the sequence counter is currently zero, jump | 3517 ** P1 is a sorter cursor. If the sequence counter is currently zero, jump |
| 3412 ** to P2. Regardless of whether or not the jump is taken, increment the | 3518 ** to P2. Regardless of whether or not the jump is taken, increment the |
| 3413 ** the sequence value. | 3519 ** the sequence value. |
| 3414 */ | 3520 */ |
| 3415 case OP_SequenceTest: { | 3521 case OP_SequenceTest: { |
| 3416 VdbeCursor *pC; | 3522 VdbeCursor *pC; |
| 3417 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 3523 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 3418 pC = p->apCsr[pOp->p1]; | 3524 pC = p->apCsr[pOp->p1]; |
| 3419 assert( pC->pSorter ); | 3525 assert( isSorter(pC) ); |
| 3420 if( (pC->seqCount++)==0 ){ | 3526 if( (pC->seqCount++)==0 ){ |
| 3421 pc = pOp->p2 - 1; | 3527 goto jump_to_p2; |
| 3422 } | 3528 } |
| 3423 break; | 3529 break; |
| 3424 } | 3530 } |
| 3425 | 3531 |
| 3426 /* Opcode: OpenPseudo P1 P2 P3 * * | 3532 /* Opcode: OpenPseudo P1 P2 P3 * * |
| 3427 ** Synopsis: P3 columns in r[P2] | 3533 ** Synopsis: P3 columns in r[P2] |
| 3428 ** | 3534 ** |
| 3429 ** Open a new cursor that points to a fake table that contains a single | 3535 ** Open a new cursor that points to a fake table that contains a single |
| 3430 ** row of data. The content of that one row is the content of memory | 3536 ** row of data. The content of that one row is the content of memory |
| 3431 ** register P2. In other words, cursor P1 becomes an alias for the | 3537 ** register P2. In other words, cursor P1 becomes an alias for the |
| 3432 ** MEM_Blob content contained in register P2. | 3538 ** MEM_Blob content contained in register P2. |
| 3433 ** | 3539 ** |
| 3434 ** A pseudo-table created by this opcode is used to hold a single | 3540 ** A pseudo-table created by this opcode is used to hold a single |
| 3435 ** row output from the sorter so that the row can be decomposed into | 3541 ** row output from the sorter so that the row can be decomposed into |
| 3436 ** individual columns using the OP_Column opcode. The OP_Column opcode | 3542 ** individual columns using the OP_Column opcode. The OP_Column opcode |
| 3437 ** is the only cursor opcode that works with a pseudo-table. | 3543 ** is the only cursor opcode that works with a pseudo-table. |
| 3438 ** | 3544 ** |
| 3439 ** P3 is the number of fields in the records that will be stored by | 3545 ** P3 is the number of fields in the records that will be stored by |
| 3440 ** the pseudo-table. | 3546 ** the pseudo-table. |
| 3441 */ | 3547 */ |
| 3442 case OP_OpenPseudo: { | 3548 case OP_OpenPseudo: { |
| 3443 VdbeCursor *pCx; | 3549 VdbeCursor *pCx; |
| 3444 | 3550 |
| 3445 assert( pOp->p1>=0 ); | 3551 assert( pOp->p1>=0 ); |
| 3446 assert( pOp->p3>=0 ); | 3552 assert( pOp->p3>=0 ); |
| 3447 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); | 3553 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO); |
| 3448 if( pCx==0 ) goto no_mem; | 3554 if( pCx==0 ) goto no_mem; |
| 3449 pCx->nullRow = 1; | 3555 pCx->nullRow = 1; |
| 3450 pCx->pseudoTableReg = pOp->p2; | 3556 pCx->uc.pseudoTableReg = pOp->p2; |
| 3451 pCx->isTable = 1; | 3557 pCx->isTable = 1; |
| 3452 assert( pOp->p5==0 ); | 3558 assert( pOp->p5==0 ); |
| 3453 break; | 3559 break; |
| 3454 } | 3560 } |
| 3455 | 3561 |
| 3456 /* Opcode: Close P1 * * * * | 3562 /* Opcode: Close P1 * * * * |
| 3457 ** | 3563 ** |
| 3458 ** Close a cursor previously opened as P1. If P1 is not | 3564 ** Close a cursor previously opened as P1. If P1 is not |
| 3459 ** currently open, this instruction is a no-op. | 3565 ** currently open, this instruction is a no-op. |
| 3460 */ | 3566 */ |
| 3461 case OP_Close: { | 3567 case OP_Close: { |
| 3462 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 3568 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 3463 sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]); | 3569 sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]); |
| 3464 p->apCsr[pOp->p1] = 0; | 3570 p->apCsr[pOp->p1] = 0; |
| 3465 break; | 3571 break; |
| 3466 } | 3572 } |
| 3467 | 3573 |
| 3574 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK |
| 3575 /* Opcode: ColumnsUsed P1 * * P4 * |
| 3576 ** |
| 3577 ** This opcode (which only exists if SQLite was compiled with |
| 3578 ** SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of the |
| 3579 ** table or index for cursor P1 are used. P4 is a 64-bit integer |
| 3580 ** (P4_INT64) in which the first 63 bits are one for each of the |
| 3581 ** first 63 columns of the table or index that are actually used |
| 3582 ** by the cursor. The high-order bit is set if any column after |
| 3583 ** the 64th is used. |
| 3584 */ |
| 3585 case OP_ColumnsUsed: { |
| 3586 VdbeCursor *pC; |
| 3587 pC = p->apCsr[pOp->p1]; |
| 3588 assert( pC->eCurType==CURTYPE_BTREE ); |
| 3589 pC->maskUsed = *(u64*)pOp->p4.pI64; |
| 3590 break; |
| 3591 } |
| 3592 #endif |
| 3593 |
| 3468 /* Opcode: SeekGE P1 P2 P3 P4 * | 3594 /* Opcode: SeekGE P1 P2 P3 P4 * |
| 3469 ** Synopsis: key=r[P3@P4] | 3595 ** Synopsis: key=r[P3@P4] |
| 3470 ** | 3596 ** |
| 3471 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), | 3597 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), |
| 3472 ** use the value in register P3 as the key. If cursor P1 refers | 3598 ** use the value in register P3 as the key. If cursor P1 refers |
| 3473 ** to an SQL index, then P3 is the first in an array of P4 registers | 3599 ** to an SQL index, then P3 is the first in an array of P4 registers |
| 3474 ** that are used as an unpacked index key. | 3600 ** that are used as an unpacked index key. |
| 3475 ** | 3601 ** |
| 3476 ** Reposition cursor P1 so that it points to the smallest entry that | 3602 ** Reposition cursor P1 so that it points to the smallest entry that |
| 3477 ** is greater than or equal to the key value. If there are no records | 3603 ** is greater than or equal to the key value. If there are no records |
| 3478 ** greater than or equal to the key and P2 is not zero, then jump to P2. | 3604 ** greater than or equal to the key and P2 is not zero, then jump to P2. |
| 3479 ** | 3605 ** |
| 3606 ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this |
| 3607 ** opcode will always land on a record that equally equals the key, or |
| 3608 ** else jump immediately to P2. When the cursor is OPFLAG_SEEKEQ, this |
| 3609 ** opcode must be followed by an IdxLE opcode with the same arguments. |
| 3610 ** The IdxLE opcode will be skipped if this opcode succeeds, but the |
| 3611 ** IdxLE opcode will be used on subsequent loop iterations. |
| 3612 ** |
| 3480 ** This opcode leaves the cursor configured to move in forward order, | 3613 ** This opcode leaves the cursor configured to move in forward order, |
| 3481 ** from the beginning toward the end. In other words, the cursor is | 3614 ** from the beginning toward the end. In other words, the cursor is |
| 3482 ** configured to use Next, not Prev. | 3615 ** configured to use Next, not Prev. |
| 3483 ** | 3616 ** |
| 3484 ** See also: Found, NotFound, SeekLt, SeekGt, SeekLe | 3617 ** See also: Found, NotFound, SeekLt, SeekGt, SeekLe |
| 3485 */ | 3618 */ |
| 3486 /* Opcode: SeekGT P1 P2 P3 P4 * | 3619 /* Opcode: SeekGT P1 P2 P3 P4 * |
| 3487 ** Synopsis: key=r[P3@P4] | 3620 ** Synopsis: key=r[P3@P4] |
| 3488 ** | 3621 ** |
| 3489 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), | 3622 ** If cursor P1 refers to an SQL table (B-Tree that uses integer keys), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3528 ** that are used as an unpacked index key. | 3661 ** that are used as an unpacked index key. |
| 3529 ** | 3662 ** |
| 3530 ** Reposition cursor P1 so that it points to the largest entry that | 3663 ** Reposition cursor P1 so that it points to the largest entry that |
| 3531 ** is less than or equal to the key value. If there are no records | 3664 ** is less than or equal to the key value. If there are no records |
| 3532 ** less than or equal to the key and P2 is not zero, then jump to P2. | 3665 ** less than or equal to the key and P2 is not zero, then jump to P2. |
| 3533 ** | 3666 ** |
| 3534 ** This opcode leaves the cursor configured to move in reverse order, | 3667 ** This opcode leaves the cursor configured to move in reverse order, |
| 3535 ** from the end toward the beginning. In other words, the cursor is | 3668 ** from the end toward the beginning. In other words, the cursor is |
| 3536 ** configured to use Prev, not Next. | 3669 ** configured to use Prev, not Next. |
| 3537 ** | 3670 ** |
| 3671 ** If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this |
| 3672 ** opcode will always land on a record that equally equals the key, or |
| 3673 ** else jump immediately to P2. When the cursor is OPFLAG_SEEKEQ, this |
| 3674 ** opcode must be followed by an IdxGE opcode with the same arguments. |
| 3675 ** The IdxGE opcode will be skipped if this opcode succeeds, but the |
| 3676 ** IdxGE opcode will be used on subsequent loop iterations. |
| 3677 ** |
| 3538 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt | 3678 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt |
| 3539 */ | 3679 */ |
| 3540 case OP_SeekLT: /* jump, in3 */ | 3680 case OP_SeekLT: /* jump, in3 */ |
| 3541 case OP_SeekLE: /* jump, in3 */ | 3681 case OP_SeekLE: /* jump, in3 */ |
| 3542 case OP_SeekGE: /* jump, in3 */ | 3682 case OP_SeekGE: /* jump, in3 */ |
| 3543 case OP_SeekGT: { /* jump, in3 */ | 3683 case OP_SeekGT: { /* jump, in3 */ |
| 3544 int res; | 3684 int res; /* Comparison result */ |
| 3545 int oc; | 3685 int oc; /* Opcode */ |
| 3546 VdbeCursor *pC; | 3686 VdbeCursor *pC; /* The cursor to seek */ |
| 3547 UnpackedRecord r; | 3687 UnpackedRecord r; /* The key to seek for */ |
| 3548 int nField; | 3688 int nField; /* Number of columns or fields in the key */ |
| 3549 i64 iKey; /* The rowid we are to seek to */ | 3689 i64 iKey; /* The rowid we are to seek to */ |
| 3690 int eqOnly; /* Only interested in == results */ |
| 3550 | 3691 |
| 3551 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 3692 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 3552 assert( pOp->p2!=0 ); | 3693 assert( pOp->p2!=0 ); |
| 3553 pC = p->apCsr[pOp->p1]; | 3694 pC = p->apCsr[pOp->p1]; |
| 3554 assert( pC!=0 ); | 3695 assert( pC!=0 ); |
| 3555 assert( pC->pseudoTableReg==0 ); | 3696 assert( pC->eCurType==CURTYPE_BTREE ); |
| 3556 assert( OP_SeekLE == OP_SeekLT+1 ); | 3697 assert( OP_SeekLE == OP_SeekLT+1 ); |
| 3557 assert( OP_SeekGE == OP_SeekLT+2 ); | 3698 assert( OP_SeekGE == OP_SeekLT+2 ); |
| 3558 assert( OP_SeekGT == OP_SeekLT+3 ); | 3699 assert( OP_SeekGT == OP_SeekLT+3 ); |
| 3559 assert( pC->isOrdered ); | 3700 assert( pC->isOrdered ); |
| 3560 assert( pC->pCursor!=0 ); | 3701 assert( pC->uc.pCursor!=0 ); |
| 3561 oc = pOp->opcode; | 3702 oc = pOp->opcode; |
| 3703 eqOnly = 0; |
| 3562 pC->nullRow = 0; | 3704 pC->nullRow = 0; |
| 3563 #ifdef SQLITE_DEBUG | 3705 #ifdef SQLITE_DEBUG |
| 3564 pC->seekOp = pOp->opcode; | 3706 pC->seekOp = pOp->opcode; |
| 3565 #endif | 3707 #endif |
| 3708 |
| 3566 if( pC->isTable ){ | 3709 if( pC->isTable ){ |
| 3710 /* The BTREE_SEEK_EQ flag is only set on index cursors */ |
| 3711 assert( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ)==0 ); |
| 3712 |
| 3567 /* The input value in P3 might be of any type: integer, real, string, | 3713 /* The input value in P3 might be of any type: integer, real, string, |
| 3568 ** blob, or NULL. But it needs to be an integer before we can do | 3714 ** blob, or NULL. But it needs to be an integer before we can do |
| 3569 ** the seek, so convert it. */ | 3715 ** the seek, so convert it. */ |
| 3570 pIn3 = &aMem[pOp->p3]; | 3716 pIn3 = &aMem[pOp->p3]; |
| 3571 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ | 3717 if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_Str))==MEM_Str ){ |
| 3572 applyNumericAffinity(pIn3, 0); | 3718 applyNumericAffinity(pIn3, 0); |
| 3573 } | 3719 } |
| 3574 iKey = sqlite3VdbeIntValue(pIn3); | 3720 iKey = sqlite3VdbeIntValue(pIn3); |
| 3575 | 3721 |
| 3576 /* If the P3 value could not be converted into an integer without | 3722 /* If the P3 value could not be converted into an integer without |
| 3577 ** loss of information, then special processing is required... */ | 3723 ** loss of information, then special processing is required... */ |
| 3578 if( (pIn3->flags & MEM_Int)==0 ){ | 3724 if( (pIn3->flags & MEM_Int)==0 ){ |
| 3579 if( (pIn3->flags & MEM_Real)==0 ){ | 3725 if( (pIn3->flags & MEM_Real)==0 ){ |
| 3580 /* If the P3 value cannot be converted into any kind of a number, | 3726 /* If the P3 value cannot be converted into any kind of a number, |
| 3581 ** then the seek is not possible, so jump to P2 */ | 3727 ** then the seek is not possible, so jump to P2 */ |
| 3582 pc = pOp->p2 - 1; VdbeBranchTaken(1,2); | 3728 VdbeBranchTaken(1,2); goto jump_to_p2; |
| 3583 break; | 3729 break; |
| 3584 } | 3730 } |
| 3585 | 3731 |
| 3586 /* If the approximation iKey is larger than the actual real search | 3732 /* If the approximation iKey is larger than the actual real search |
| 3587 ** term, substitute >= for > and < for <=. e.g. if the search term | 3733 ** term, substitute >= for > and < for <=. e.g. if the search term |
| 3588 ** is 4.9 and the integer approximation 5: | 3734 ** is 4.9 and the integer approximation 5: |
| 3589 ** | 3735 ** |
| 3590 ** (x > 4.9) -> (x >= 5) | 3736 ** (x > 4.9) -> (x >= 5) |
| 3591 ** (x <= 4.9) -> (x < 5) | 3737 ** (x <= 4.9) -> (x < 5) |
| 3592 */ | 3738 */ |
| 3593 if( pIn3->u.r<(double)iKey ){ | 3739 if( pIn3->u.r<(double)iKey ){ |
| 3594 assert( OP_SeekGE==(OP_SeekGT-1) ); | 3740 assert( OP_SeekGE==(OP_SeekGT-1) ); |
| 3595 assert( OP_SeekLT==(OP_SeekLE-1) ); | 3741 assert( OP_SeekLT==(OP_SeekLE-1) ); |
| 3596 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) ); | 3742 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) ); |
| 3597 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--; | 3743 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--; |
| 3598 } | 3744 } |
| 3599 | 3745 |
| 3600 /* If the approximation iKey is smaller than the actual real search | 3746 /* If the approximation iKey is smaller than the actual real search |
| 3601 ** term, substitute <= for < and > for >=. */ | 3747 ** term, substitute <= for < and > for >=. */ |
| 3602 else if( pIn3->u.r>(double)iKey ){ | 3748 else if( pIn3->u.r>(double)iKey ){ |
| 3603 assert( OP_SeekLE==(OP_SeekLT+1) ); | 3749 assert( OP_SeekLE==(OP_SeekLT+1) ); |
| 3604 assert( OP_SeekGT==(OP_SeekGE+1) ); | 3750 assert( OP_SeekGT==(OP_SeekGE+1) ); |
| 3605 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) ); | 3751 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) ); |
| 3606 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++; | 3752 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++; |
| 3607 } | 3753 } |
| 3608 } | 3754 } |
| 3609 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res); | 3755 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)iKey, 0, &res); |
| 3610 pC->movetoTarget = iKey; /* Used by OP_Delete */ | 3756 pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 3611 if( rc!=SQLITE_OK ){ | 3757 if( rc!=SQLITE_OK ){ |
| 3612 goto abort_due_to_error; | 3758 goto abort_due_to_error; |
| 3613 } | 3759 } |
| 3614 }else{ | 3760 }else{ |
| 3761 /* For a cursor with the BTREE_SEEK_EQ hint, only the OP_SeekGE and |
| 3762 ** OP_SeekLE opcodes are allowed, and these must be immediately followed |
| 3763 ** by an OP_IdxGT or OP_IdxLT opcode, respectively, with the same key. |
| 3764 */ |
| 3765 if( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ) ){ |
| 3766 eqOnly = 1; |
| 3767 assert( pOp->opcode==OP_SeekGE || pOp->opcode==OP_SeekLE ); |
| 3768 assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); |
| 3769 assert( pOp[1].p1==pOp[0].p1 ); |
| 3770 assert( pOp[1].p2==pOp[0].p2 ); |
| 3771 assert( pOp[1].p3==pOp[0].p3 ); |
| 3772 assert( pOp[1].p4.i==pOp[0].p4.i ); |
| 3773 } |
| 3774 |
| 3615 nField = pOp->p4.i; | 3775 nField = pOp->p4.i; |
| 3616 assert( pOp->p4type==P4_INT32 ); | 3776 assert( pOp->p4type==P4_INT32 ); |
| 3617 assert( nField>0 ); | 3777 assert( nField>0 ); |
| 3618 r.pKeyInfo = pC->pKeyInfo; | 3778 r.pKeyInfo = pC->pKeyInfo; |
| 3619 r.nField = (u16)nField; | 3779 r.nField = (u16)nField; |
| 3620 | 3780 |
| 3621 /* The next line of code computes as follows, only faster: | 3781 /* The next line of code computes as follows, only faster: |
| 3622 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){ | 3782 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){ |
| 3623 ** r.default_rc = -1; | 3783 ** r.default_rc = -1; |
| 3624 ** }else{ | 3784 ** }else{ |
| 3625 ** r.default_rc = +1; | 3785 ** r.default_rc = +1; |
| 3626 ** } | 3786 ** } |
| 3627 */ | 3787 */ |
| 3628 r.default_rc = ((1 & (oc - OP_SeekLT)) ? -1 : +1); | 3788 r.default_rc = ((1 & (oc - OP_SeekLT)) ? -1 : +1); |
| 3629 assert( oc!=OP_SeekGT || r.default_rc==-1 ); | 3789 assert( oc!=OP_SeekGT || r.default_rc==-1 ); |
| 3630 assert( oc!=OP_SeekLE || r.default_rc==-1 ); | 3790 assert( oc!=OP_SeekLE || r.default_rc==-1 ); |
| 3631 assert( oc!=OP_SeekGE || r.default_rc==+1 ); | 3791 assert( oc!=OP_SeekGE || r.default_rc==+1 ); |
| 3632 assert( oc!=OP_SeekLT || r.default_rc==+1 ); | 3792 assert( oc!=OP_SeekLT || r.default_rc==+1 ); |
| 3633 | 3793 |
| 3634 r.aMem = &aMem[pOp->p3]; | 3794 r.aMem = &aMem[pOp->p3]; |
| 3635 #ifdef SQLITE_DEBUG | 3795 #ifdef SQLITE_DEBUG |
| 3636 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } | 3796 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 3637 #endif | 3797 #endif |
| 3638 ExpandBlob(r.aMem); | 3798 ExpandBlob(r.aMem); |
| 3639 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res); | 3799 r.eqSeen = 0; |
| 3800 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, &r, 0, 0, &res); |
| 3640 if( rc!=SQLITE_OK ){ | 3801 if( rc!=SQLITE_OK ){ |
| 3641 goto abort_due_to_error; | 3802 goto abort_due_to_error; |
| 3642 } | 3803 } |
| 3804 if( eqOnly && r.eqSeen==0 ){ |
| 3805 assert( res!=0 ); |
| 3806 goto seek_not_found; |
| 3807 } |
| 3643 } | 3808 } |
| 3644 pC->deferredMoveto = 0; | 3809 pC->deferredMoveto = 0; |
| 3645 pC->cacheStatus = CACHE_STALE; | 3810 pC->cacheStatus = CACHE_STALE; |
| 3646 #ifdef SQLITE_TEST | 3811 #ifdef SQLITE_TEST |
| 3647 sqlite3_search_count++; | 3812 sqlite3_search_count++; |
| 3648 #endif | 3813 #endif |
| 3649 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT ); | 3814 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT ); |
| 3650 if( res<0 || (res==0 && oc==OP_SeekGT) ){ | 3815 if( res<0 || (res==0 && oc==OP_SeekGT) ){ |
| 3651 res = 0; | 3816 res = 0; |
| 3652 rc = sqlite3BtreeNext(pC->pCursor, &res); | 3817 rc = sqlite3BtreeNext(pC->uc.pCursor, &res); |
| 3653 if( rc!=SQLITE_OK ) goto abort_due_to_error; | 3818 if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 3654 }else{ | 3819 }else{ |
| 3655 res = 0; | 3820 res = 0; |
| 3656 } | 3821 } |
| 3657 }else{ | 3822 }else{ |
| 3658 assert( oc==OP_SeekLT || oc==OP_SeekLE ); | 3823 assert( oc==OP_SeekLT || oc==OP_SeekLE ); |
| 3659 if( res>0 || (res==0 && oc==OP_SeekLT) ){ | 3824 if( res>0 || (res==0 && oc==OP_SeekLT) ){ |
| 3660 res = 0; | 3825 res = 0; |
| 3661 rc = sqlite3BtreePrevious(pC->pCursor, &res); | 3826 rc = sqlite3BtreePrevious(pC->uc.pCursor, &res); |
| 3662 if( rc!=SQLITE_OK ) goto abort_due_to_error; | 3827 if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 3663 }else{ | 3828 }else{ |
| 3664 /* res might be negative because the table is empty. Check to | 3829 /* res might be negative because the table is empty. Check to |
| 3665 ** see if this is the case. | 3830 ** see if this is the case. |
| 3666 */ | 3831 */ |
| 3667 res = sqlite3BtreeEof(pC->pCursor); | 3832 res = sqlite3BtreeEof(pC->uc.pCursor); |
| 3668 } | 3833 } |
| 3669 } | 3834 } |
| 3835 seek_not_found: |
| 3670 assert( pOp->p2>0 ); | 3836 assert( pOp->p2>0 ); |
| 3671 VdbeBranchTaken(res!=0,2); | 3837 VdbeBranchTaken(res!=0,2); |
| 3672 if( res ){ | 3838 if( res ){ |
| 3673 pc = pOp->p2 - 1; | 3839 goto jump_to_p2; |
| 3840 }else if( eqOnly ){ |
| 3841 assert( pOp[1].opcode==OP_IdxLT || pOp[1].opcode==OP_IdxGT ); |
| 3842 pOp++; /* Skip the OP_IdxLt or OP_IdxGT that follows */ |
| 3674 } | 3843 } |
| 3675 break; | 3844 break; |
| 3676 } | 3845 } |
| 3677 | 3846 |
| 3678 /* Opcode: Seek P1 P2 * * * | 3847 /* Opcode: Seek P1 P2 * * * |
| 3679 ** Synopsis: intkey=r[P2] | 3848 ** Synopsis: intkey=r[P2] |
| 3680 ** | 3849 ** |
| 3681 ** P1 is an open table cursor and P2 is a rowid integer. Arrange | 3850 ** P1 is an open table cursor and P2 is a rowid integer. Arrange |
| 3682 ** for P1 to move so that it points to the rowid given by P2. | 3851 ** for P1 to move so that it points to the rowid given by P2. |
| 3683 ** | 3852 ** |
| 3684 ** This is actually a deferred seek. Nothing actually happens until | 3853 ** This is actually a deferred seek. Nothing actually happens until |
| 3685 ** the cursor is used to read a record. That way, if no reads | 3854 ** the cursor is used to read a record. That way, if no reads |
| 3686 ** occur, no unnecessary I/O happens. | 3855 ** occur, no unnecessary I/O happens. |
| 3687 */ | 3856 */ |
| 3688 case OP_Seek: { /* in2 */ | 3857 case OP_Seek: { /* in2 */ |
| 3689 VdbeCursor *pC; | 3858 VdbeCursor *pC; |
| 3690 | 3859 |
| 3691 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 3860 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 3692 pC = p->apCsr[pOp->p1]; | 3861 pC = p->apCsr[pOp->p1]; |
| 3693 assert( pC!=0 ); | 3862 assert( pC!=0 ); |
| 3694 assert( pC->pCursor!=0 ); | 3863 assert( pC->eCurType==CURTYPE_BTREE ); |
| 3864 assert( pC->uc.pCursor!=0 ); |
| 3695 assert( pC->isTable ); | 3865 assert( pC->isTable ); |
| 3696 pC->nullRow = 0; | 3866 pC->nullRow = 0; |
| 3697 pIn2 = &aMem[pOp->p2]; | 3867 pIn2 = &aMem[pOp->p2]; |
| 3698 pC->movetoTarget = sqlite3VdbeIntValue(pIn2); | 3868 pC->movetoTarget = sqlite3VdbeIntValue(pIn2); |
| 3699 pC->deferredMoveto = 1; | 3869 pC->deferredMoveto = 1; |
| 3700 break; | 3870 break; |
| 3701 } | 3871 } |
| 3702 | 3872 |
| 3703 | 3873 |
| 3704 /* Opcode: Found P1 P2 P3 P4 * | 3874 /* Opcode: Found P1 P2 P3 P4 * |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3757 ** This operation leaves the cursor in a state where it cannot be | 3927 ** This operation leaves the cursor in a state where it cannot be |
| 3758 ** advanced in either direction. In other words, the Next and Prev | 3928 ** advanced in either direction. In other words, the Next and Prev |
| 3759 ** opcodes do not work after this operation. | 3929 ** opcodes do not work after this operation. |
| 3760 ** | 3930 ** |
| 3761 ** See also: NotFound, Found, NotExists | 3931 ** See also: NotFound, Found, NotExists |
| 3762 */ | 3932 */ |
| 3763 case OP_NoConflict: /* jump, in3 */ | 3933 case OP_NoConflict: /* jump, in3 */ |
| 3764 case OP_NotFound: /* jump, in3 */ | 3934 case OP_NotFound: /* jump, in3 */ |
| 3765 case OP_Found: { /* jump, in3 */ | 3935 case OP_Found: { /* jump, in3 */ |
| 3766 int alreadyExists; | 3936 int alreadyExists; |
| 3937 int takeJump; |
| 3767 int ii; | 3938 int ii; |
| 3768 VdbeCursor *pC; | 3939 VdbeCursor *pC; |
| 3769 int res; | 3940 int res; |
| 3770 char *pFree; | 3941 char *pFree; |
| 3771 UnpackedRecord *pIdxKey; | 3942 UnpackedRecord *pIdxKey; |
| 3772 UnpackedRecord r; | 3943 UnpackedRecord r; |
| 3773 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; | 3944 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; |
| 3774 | 3945 |
| 3775 #ifdef SQLITE_TEST | 3946 #ifdef SQLITE_TEST |
| 3776 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++; | 3947 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++; |
| 3777 #endif | 3948 #endif |
| 3778 | 3949 |
| 3779 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 3950 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 3780 assert( pOp->p4type==P4_INT32 ); | 3951 assert( pOp->p4type==P4_INT32 ); |
| 3781 pC = p->apCsr[pOp->p1]; | 3952 pC = p->apCsr[pOp->p1]; |
| 3782 assert( pC!=0 ); | 3953 assert( pC!=0 ); |
| 3783 #ifdef SQLITE_DEBUG | 3954 #ifdef SQLITE_DEBUG |
| 3784 pC->seekOp = pOp->opcode; | 3955 pC->seekOp = pOp->opcode; |
| 3785 #endif | 3956 #endif |
| 3786 pIn3 = &aMem[pOp->p3]; | 3957 pIn3 = &aMem[pOp->p3]; |
| 3787 assert( pC->pCursor!=0 ); | 3958 assert( pC->eCurType==CURTYPE_BTREE ); |
| 3959 assert( pC->uc.pCursor!=0 ); |
| 3788 assert( pC->isTable==0 ); | 3960 assert( pC->isTable==0 ); |
| 3789 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ | 3961 pFree = 0; |
| 3790 if( pOp->p4.i>0 ){ | 3962 if( pOp->p4.i>0 ){ |
| 3791 r.pKeyInfo = pC->pKeyInfo; | 3963 r.pKeyInfo = pC->pKeyInfo; |
| 3792 r.nField = (u16)pOp->p4.i; | 3964 r.nField = (u16)pOp->p4.i; |
| 3793 r.aMem = pIn3; | 3965 r.aMem = pIn3; |
| 3794 for(ii=0; ii<r.nField; ii++){ | 3966 for(ii=0; ii<r.nField; ii++){ |
| 3795 assert( memIsValid(&r.aMem[ii]) ); | 3967 assert( memIsValid(&r.aMem[ii]) ); |
| 3796 ExpandBlob(&r.aMem[ii]); | 3968 ExpandBlob(&r.aMem[ii]); |
| 3797 #ifdef SQLITE_DEBUG | 3969 #ifdef SQLITE_DEBUG |
| 3798 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]); | 3970 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]); |
| 3799 #endif | 3971 #endif |
| 3800 } | 3972 } |
| 3801 pIdxKey = &r; | 3973 pIdxKey = &r; |
| 3802 }else{ | 3974 }else{ |
| 3803 pIdxKey = sqlite3VdbeAllocUnpackedRecord( | 3975 pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 3804 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree | 3976 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree |
| 3805 ); | 3977 ); |
| 3806 if( pIdxKey==0 ) goto no_mem; | 3978 if( pIdxKey==0 ) goto no_mem; |
| 3807 assert( pIn3->flags & MEM_Blob ); | 3979 assert( pIn3->flags & MEM_Blob ); |
| 3808 assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */ | 3980 ExpandBlob(pIn3); |
| 3809 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); | 3981 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 3810 } | 3982 } |
| 3811 pIdxKey->default_rc = 0; | 3983 pIdxKey->default_rc = 0; |
| 3984 takeJump = 0; |
| 3812 if( pOp->opcode==OP_NoConflict ){ | 3985 if( pOp->opcode==OP_NoConflict ){ |
| 3813 /* For the OP_NoConflict opcode, take the jump if any of the | 3986 /* For the OP_NoConflict opcode, take the jump if any of the |
| 3814 ** input fields are NULL, since any key with a NULL will not | 3987 ** input fields are NULL, since any key with a NULL will not |
| 3815 ** conflict */ | 3988 ** conflict */ |
| 3816 for(ii=0; ii<r.nField; ii++){ | 3989 for(ii=0; ii<pIdxKey->nField; ii++){ |
| 3817 if( r.aMem[ii].flags & MEM_Null ){ | 3990 if( pIdxKey->aMem[ii].flags & MEM_Null ){ |
| 3818 pc = pOp->p2 - 1; VdbeBranchTaken(1,2); | 3991 takeJump = 1; |
| 3819 break; | 3992 break; |
| 3820 } | 3993 } |
| 3821 } | 3994 } |
| 3822 } | 3995 } |
| 3823 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); | 3996 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res); |
| 3824 if( pOp->p4.i==0 ){ | 3997 sqlite3DbFree(db, pFree); |
| 3825 sqlite3DbFree(db, pFree); | |
| 3826 } | |
| 3827 if( rc!=SQLITE_OK ){ | 3998 if( rc!=SQLITE_OK ){ |
| 3828 break; | 3999 break; |
| 3829 } | 4000 } |
| 3830 pC->seekResult = res; | 4001 pC->seekResult = res; |
| 3831 alreadyExists = (res==0); | 4002 alreadyExists = (res==0); |
| 3832 pC->nullRow = 1-alreadyExists; | 4003 pC->nullRow = 1-alreadyExists; |
| 3833 pC->deferredMoveto = 0; | 4004 pC->deferredMoveto = 0; |
| 3834 pC->cacheStatus = CACHE_STALE; | 4005 pC->cacheStatus = CACHE_STALE; |
| 3835 if( pOp->opcode==OP_Found ){ | 4006 if( pOp->opcode==OP_Found ){ |
| 3836 VdbeBranchTaken(alreadyExists!=0,2); | 4007 VdbeBranchTaken(alreadyExists!=0,2); |
| 3837 if( alreadyExists ) pc = pOp->p2 - 1; | 4008 if( alreadyExists ) goto jump_to_p2; |
| 3838 }else{ | 4009 }else{ |
| 3839 VdbeBranchTaken(alreadyExists==0,2); | 4010 VdbeBranchTaken(takeJump||alreadyExists==0,2); |
| 3840 if( !alreadyExists ) pc = pOp->p2 - 1; | 4011 if( takeJump || !alreadyExists ) goto jump_to_p2; |
| 3841 } | 4012 } |
| 3842 break; | 4013 break; |
| 3843 } | 4014 } |
| 3844 | 4015 |
| 3845 /* Opcode: NotExists P1 P2 P3 * * | 4016 /* Opcode: NotExists P1 P2 P3 * * |
| 3846 ** Synopsis: intkey=r[P3] | 4017 ** Synopsis: intkey=r[P3] |
| 3847 ** | 4018 ** |
| 3848 ** P1 is the index of a cursor open on an SQL table btree (with integer | 4019 ** P1 is the index of a cursor open on an SQL table btree (with integer |
| 3849 ** keys). P3 is an integer rowid. If P1 does not contain a record with | 4020 ** keys). P3 is an integer rowid. If P1 does not contain a record with |
| 3850 ** rowid P3 then jump immediately to P2. If P1 does contain a record | 4021 ** rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an |
| 3851 ** with rowid P3 then leave the cursor pointing at that record and fall | 4022 ** SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then |
| 3852 ** through to the next instruction. | 4023 ** leave the cursor pointing at that record and fall through to the next |
| 4024 ** instruction. |
| 3853 ** | 4025 ** |
| 3854 ** The OP_NotFound opcode performs the same operation on index btrees | 4026 ** The OP_NotFound opcode performs the same operation on index btrees |
| 3855 ** (with arbitrary multi-value keys). | 4027 ** (with arbitrary multi-value keys). |
| 3856 ** | 4028 ** |
| 3857 ** This opcode leaves the cursor in a state where it cannot be advanced | 4029 ** This opcode leaves the cursor in a state where it cannot be advanced |
| 3858 ** in either direction. In other words, the Next and Prev opcodes will | 4030 ** in either direction. In other words, the Next and Prev opcodes will |
| 3859 ** not work following this opcode. | 4031 ** not work following this opcode. |
| 3860 ** | 4032 ** |
| 3861 ** See also: Found, NotFound, NoConflict | 4033 ** See also: Found, NotFound, NoConflict |
| 3862 */ | 4034 */ |
| 3863 case OP_NotExists: { /* jump, in3 */ | 4035 case OP_NotExists: { /* jump, in3 */ |
| 3864 VdbeCursor *pC; | 4036 VdbeCursor *pC; |
| 3865 BtCursor *pCrsr; | 4037 BtCursor *pCrsr; |
| 3866 int res; | 4038 int res; |
| 3867 u64 iKey; | 4039 u64 iKey; |
| 3868 | 4040 |
| 3869 pIn3 = &aMem[pOp->p3]; | 4041 pIn3 = &aMem[pOp->p3]; |
| 3870 assert( pIn3->flags & MEM_Int ); | 4042 assert( pIn3->flags & MEM_Int ); |
| 3871 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4043 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 3872 pC = p->apCsr[pOp->p1]; | 4044 pC = p->apCsr[pOp->p1]; |
| 3873 assert( pC!=0 ); | 4045 assert( pC!=0 ); |
| 3874 #ifdef SQLITE_DEBUG | 4046 #ifdef SQLITE_DEBUG |
| 3875 pC->seekOp = 0; | 4047 pC->seekOp = 0; |
| 3876 #endif | 4048 #endif |
| 3877 assert( pC->isTable ); | 4049 assert( pC->isTable ); |
| 3878 assert( pC->pseudoTableReg==0 ); | 4050 assert( pC->eCurType==CURTYPE_BTREE ); |
| 3879 pCrsr = pC->pCursor; | 4051 pCrsr = pC->uc.pCursor; |
| 3880 assert( pCrsr!=0 ); | 4052 assert( pCrsr!=0 ); |
| 3881 res = 0; | 4053 res = 0; |
| 3882 iKey = pIn3->u.i; | 4054 iKey = pIn3->u.i; |
| 3883 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); | 4055 rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); |
| 4056 assert( rc==SQLITE_OK || res==0 ); |
| 3884 pC->movetoTarget = iKey; /* Used by OP_Delete */ | 4057 pC->movetoTarget = iKey; /* Used by OP_Delete */ |
| 3885 pC->nullRow = 0; | 4058 pC->nullRow = 0; |
| 3886 pC->cacheStatus = CACHE_STALE; | 4059 pC->cacheStatus = CACHE_STALE; |
| 3887 pC->deferredMoveto = 0; | 4060 pC->deferredMoveto = 0; |
| 3888 VdbeBranchTaken(res!=0,2); | 4061 VdbeBranchTaken(res!=0,2); |
| 4062 pC->seekResult = res; |
| 3889 if( res!=0 ){ | 4063 if( res!=0 ){ |
| 3890 pc = pOp->p2 - 1; | 4064 assert( rc==SQLITE_OK ); |
| 4065 if( pOp->p2==0 ){ |
| 4066 rc = SQLITE_CORRUPT_BKPT; |
| 4067 }else{ |
| 4068 goto jump_to_p2; |
| 4069 } |
| 3891 } | 4070 } |
| 3892 pC->seekResult = res; | |
| 3893 break; | 4071 break; |
| 3894 } | 4072 } |
| 3895 | 4073 |
| 3896 /* Opcode: Sequence P1 P2 * * * | 4074 /* Opcode: Sequence P1 P2 * * * |
| 3897 ** Synopsis: r[P2]=cursor[P1].ctr++ | 4075 ** Synopsis: r[P2]=cursor[P1].ctr++ |
| 3898 ** | 4076 ** |
| 3899 ** Find the next available sequence number for cursor P1. | 4077 ** Find the next available sequence number for cursor P1. |
| 3900 ** Write the sequence number into register P2. | 4078 ** Write the sequence number into register P2. |
| 3901 ** The sequence number on the cursor is incremented after this | 4079 ** The sequence number on the cursor is incremented after this |
| 3902 ** instruction. | 4080 ** instruction. |
| 3903 */ | 4081 */ |
| 3904 case OP_Sequence: { /* out2-prerelease */ | 4082 case OP_Sequence: { /* out2 */ |
| 3905 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4083 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 3906 assert( p->apCsr[pOp->p1]!=0 ); | 4084 assert( p->apCsr[pOp->p1]!=0 ); |
| 4085 assert( p->apCsr[pOp->p1]->eCurType!=CURTYPE_VTAB ); |
| 4086 pOut = out2Prerelease(p, pOp); |
| 3907 pOut->u.i = p->apCsr[pOp->p1]->seqCount++; | 4087 pOut->u.i = p->apCsr[pOp->p1]->seqCount++; |
| 3908 break; | 4088 break; |
| 3909 } | 4089 } |
| 3910 | 4090 |
| 3911 | 4091 |
| 3912 /* Opcode: NewRowid P1 P2 P3 * * | 4092 /* Opcode: NewRowid P1 P2 P3 * * |
| 3913 ** Synopsis: r[P2]=rowid | 4093 ** Synopsis: r[P2]=rowid |
| 3914 ** | 4094 ** |
| 3915 ** Get a new integer record number (a.k.a "rowid") used as the key to a table. | 4095 ** Get a new integer record number (a.k.a "rowid") used as the key to a table. |
| 3916 ** The record number is not previously used as a key in the database | 4096 ** The record number is not previously used as a key in the database |
| 3917 ** table that cursor P1 points to. The new record number is written | 4097 ** table that cursor P1 points to. The new record number is written |
| 3918 ** written to register P2. | 4098 ** written to register P2. |
| 3919 ** | 4099 ** |
| 3920 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds | 4100 ** If P3>0 then P3 is a register in the root frame of this VDBE that holds |
| 3921 ** the largest previously generated record number. No new record numbers are | 4101 ** the largest previously generated record number. No new record numbers are |
| 3922 ** allowed to be less than this value. When this value reaches its maximum, | 4102 ** allowed to be less than this value. When this value reaches its maximum, |
| 3923 ** an SQLITE_FULL error is generated. The P3 register is updated with the ' | 4103 ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 3924 ** generated record number. This P3 mechanism is used to help implement the | 4104 ** generated record number. This P3 mechanism is used to help implement the |
| 3925 ** AUTOINCREMENT feature. | 4105 ** AUTOINCREMENT feature. |
| 3926 */ | 4106 */ |
| 3927 case OP_NewRowid: { /* out2-prerelease */ | 4107 case OP_NewRowid: { /* out2 */ |
| 3928 i64 v; /* The new rowid */ | 4108 i64 v; /* The new rowid */ |
| 3929 VdbeCursor *pC; /* Cursor of table to get the new rowid */ | 4109 VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 3930 int res; /* Result of an sqlite3BtreeLast() */ | 4110 int res; /* Result of an sqlite3BtreeLast() */ |
| 3931 int cnt; /* Counter to limit the number of searches */ | 4111 int cnt; /* Counter to limit the number of searches */ |
| 3932 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ | 4112 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 3933 VdbeFrame *pFrame; /* Root frame of VDBE */ | 4113 VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 3934 | 4114 |
| 3935 v = 0; | 4115 v = 0; |
| 3936 res = 0; | 4116 res = 0; |
| 4117 pOut = out2Prerelease(p, pOp); |
| 3937 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4118 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 3938 pC = p->apCsr[pOp->p1]; | 4119 pC = p->apCsr[pOp->p1]; |
| 3939 assert( pC!=0 ); | 4120 assert( pC!=0 ); |
| 3940 if( NEVER(pC->pCursor==0) ){ | 4121 assert( pC->eCurType==CURTYPE_BTREE ); |
| 3941 /* The zero initialization above is all that is needed */ | 4122 assert( pC->uc.pCursor!=0 ); |
| 3942 }else{ | 4123 { |
| 3943 /* The next rowid or record number (different terms for the same | 4124 /* The next rowid or record number (different terms for the same |
| 3944 ** thing) is obtained in a two-step algorithm. | 4125 ** thing) is obtained in a two-step algorithm. |
| 3945 ** | 4126 ** |
| 3946 ** First we attempt to find the largest existing rowid and add one | 4127 ** First we attempt to find the largest existing rowid and add one |
| 3947 ** to that. But if the largest existing rowid is already the maximum | 4128 ** to that. But if the largest existing rowid is already the maximum |
| 3948 ** positive integer, we have to fall through to the second | 4129 ** positive integer, we have to fall through to the second |
| 3949 ** probabilistic algorithm | 4130 ** probabilistic algorithm |
| 3950 ** | 4131 ** |
| 3951 ** The second algorithm is to select a rowid at random and see if | 4132 ** The second algorithm is to select a rowid at random and see if |
| 3952 ** it already exists in the table. If it does not exist, we have | 4133 ** it already exists in the table. If it does not exist, we have |
| 3953 ** succeeded. If the random rowid does exist, we select a new one | 4134 ** succeeded. If the random rowid does exist, we select a new one |
| 3954 ** and try again, up to 100 times. | 4135 ** and try again, up to 100 times. |
| 3955 */ | 4136 */ |
| 3956 assert( pC->isTable ); | 4137 assert( pC->isTable ); |
| 3957 | 4138 |
| 3958 #ifdef SQLITE_32BIT_ROWID | 4139 #ifdef SQLITE_32BIT_ROWID |
| 3959 # define MAX_ROWID 0x7fffffff | 4140 # define MAX_ROWID 0x7fffffff |
| 3960 #else | 4141 #else |
| 3961 /* Some compilers complain about constants of the form 0x7fffffffffffffff. | 4142 /* Some compilers complain about constants of the form 0x7fffffffffffffff. |
| 3962 ** Others complain about 0x7ffffffffffffffffLL. The following macro seems | 4143 ** Others complain about 0x7ffffffffffffffffLL. The following macro seems |
| 3963 ** to provide the constant while making all compilers happy. | 4144 ** to provide the constant while making all compilers happy. |
| 3964 */ | 4145 */ |
| 3965 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff ) | 4146 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff ) |
| 3966 #endif | 4147 #endif |
| 3967 | 4148 |
| 3968 if( !pC->useRandomRowid ){ | 4149 if( !pC->useRandomRowid ){ |
| 3969 rc = sqlite3BtreeLast(pC->pCursor, &res); | 4150 rc = sqlite3BtreeLast(pC->uc.pCursor, &res); |
| 3970 if( rc!=SQLITE_OK ){ | 4151 if( rc!=SQLITE_OK ){ |
| 3971 goto abort_due_to_error; | 4152 goto abort_due_to_error; |
| 3972 } | 4153 } |
| 3973 if( res ){ | 4154 if( res ){ |
| 3974 v = 1; /* IMP: R-61914-48074 */ | 4155 v = 1; /* IMP: R-61914-48074 */ |
| 3975 }else{ | 4156 }else{ |
| 3976 assert( sqlite3BtreeCursorIsValid(pC->pCursor) ); | 4157 assert( sqlite3BtreeCursorIsValid(pC->uc.pCursor) ); |
| 3977 rc = sqlite3BtreeKeySize(pC->pCursor, &v); | 4158 rc = sqlite3BtreeKeySize(pC->uc.pCursor, &v); |
| 3978 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ | 4159 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ |
| 3979 if( v>=MAX_ROWID ){ | 4160 if( v>=MAX_ROWID ){ |
| 3980 pC->useRandomRowid = 1; | 4161 pC->useRandomRowid = 1; |
| 3981 }else{ | 4162 }else{ |
| 3982 v++; /* IMP: R-29538-34987 */ | 4163 v++; /* IMP: R-29538-34987 */ |
| 3983 } | 4164 } |
| 3984 } | 4165 } |
| 3985 } | 4166 } |
| 3986 | 4167 |
| 3987 #ifndef SQLITE_OMIT_AUTOINCREMENT | 4168 #ifndef SQLITE_OMIT_AUTOINCREMENT |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4018 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the | 4199 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the |
| 4019 ** largest possible integer (9223372036854775807) then the database | 4200 ** largest possible integer (9223372036854775807) then the database |
| 4020 ** engine starts picking positive candidate ROWIDs at random until | 4201 ** engine starts picking positive candidate ROWIDs at random until |
| 4021 ** it finds one that is not previously used. */ | 4202 ** it finds one that is not previously used. */ |
| 4022 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is | 4203 assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is |
| 4023 ** an AUTOINCREMENT table. */ | 4204 ** an AUTOINCREMENT table. */ |
| 4024 cnt = 0; | 4205 cnt = 0; |
| 4025 do{ | 4206 do{ |
| 4026 sqlite3_randomness(sizeof(v), &v); | 4207 sqlite3_randomness(sizeof(v), &v); |
| 4027 v &= (MAX_ROWID>>1); v++; /* Ensure that v is greater than zero */ | 4208 v &= (MAX_ROWID>>1); v++; /* Ensure that v is greater than zero */ |
| 4028 }while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v, | 4209 }while( ((rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, 0, (u64)v, |
| 4029 0, &res))==SQLITE_OK) | 4210 0, &res))==SQLITE_OK) |
| 4030 && (res==0) | 4211 && (res==0) |
| 4031 && (++cnt<100)); | 4212 && (++cnt<100)); |
| 4032 if( rc==SQLITE_OK && res==0 ){ | 4213 if( rc==SQLITE_OK && res==0 ){ |
| 4033 rc = SQLITE_FULL; /* IMP: R-38219-53002 */ | 4214 rc = SQLITE_FULL; /* IMP: R-38219-53002 */ |
| 4034 goto abort_due_to_error; | 4215 goto abort_due_to_error; |
| 4035 } | 4216 } |
| 4036 assert( v>0 ); /* EV: R-40812-03570 */ | 4217 assert( v>0 ); /* EV: R-40812-03570 */ |
| 4037 } | 4218 } |
| 4038 pC->deferredMoveto = 0; | 4219 pC->deferredMoveto = 0; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4098 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ | 4279 int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ |
| 4099 const char *zDb; /* database name - used by the update hook */ | 4280 const char *zDb; /* database name - used by the update hook */ |
| 4100 const char *zTbl; /* Table name - used by the opdate hook */ | 4281 const char *zTbl; /* Table name - used by the opdate hook */ |
| 4101 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ | 4282 int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ |
| 4102 | 4283 |
| 4103 pData = &aMem[pOp->p2]; | 4284 pData = &aMem[pOp->p2]; |
| 4104 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4285 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4105 assert( memIsValid(pData) ); | 4286 assert( memIsValid(pData) ); |
| 4106 pC = p->apCsr[pOp->p1]; | 4287 pC = p->apCsr[pOp->p1]; |
| 4107 assert( pC!=0 ); | 4288 assert( pC!=0 ); |
| 4108 assert( pC->pCursor!=0 ); | 4289 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4109 assert( pC->pseudoTableReg==0 ); | 4290 assert( pC->uc.pCursor!=0 ); |
| 4110 assert( pC->isTable ); | 4291 assert( pC->isTable ); |
| 4111 REGISTER_TRACE(pOp->p2, pData); | 4292 REGISTER_TRACE(pOp->p2, pData); |
| 4112 | 4293 |
| 4113 if( pOp->opcode==OP_Insert ){ | 4294 if( pOp->opcode==OP_Insert ){ |
| 4114 pKey = &aMem[pOp->p3]; | 4295 pKey = &aMem[pOp->p3]; |
| 4115 assert( pKey->flags & MEM_Int ); | 4296 assert( pKey->flags & MEM_Int ); |
| 4116 assert( memIsValid(pKey) ); | 4297 assert( memIsValid(pKey) ); |
| 4117 REGISTER_TRACE(pOp->p3, pKey); | 4298 REGISTER_TRACE(pOp->p3, pKey); |
| 4118 iKey = pKey->u.i; | 4299 iKey = pKey->u.i; |
| 4119 }else{ | 4300 }else{ |
| 4120 assert( pOp->opcode==OP_InsertInt ); | 4301 assert( pOp->opcode==OP_InsertInt ); |
| 4121 iKey = pOp->p3; | 4302 iKey = pOp->p3; |
| 4122 } | 4303 } |
| 4123 | 4304 |
| 4124 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; | 4305 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 4125 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey; | 4306 if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey; |
| 4126 if( pData->flags & MEM_Null ){ | 4307 if( pData->flags & MEM_Null ){ |
| 4127 pData->z = 0; | 4308 pData->z = 0; |
| 4128 pData->n = 0; | 4309 pData->n = 0; |
| 4129 }else{ | 4310 }else{ |
| 4130 assert( pData->flags & (MEM_Blob|MEM_Str) ); | 4311 assert( pData->flags & (MEM_Blob|MEM_Str) ); |
| 4131 } | 4312 } |
| 4132 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0); | 4313 seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0); |
| 4133 if( pData->flags & MEM_Zero ){ | 4314 if( pData->flags & MEM_Zero ){ |
| 4134 nZero = pData->u.nZero; | 4315 nZero = pData->u.nZero; |
| 4135 }else{ | 4316 }else{ |
| 4136 nZero = 0; | 4317 nZero = 0; |
| 4137 } | 4318 } |
| 4138 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, | 4319 rc = sqlite3BtreeInsert(pC->uc.pCursor, 0, iKey, |
| 4139 pData->z, pData->n, nZero, | 4320 pData->z, pData->n, nZero, |
| 4140 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult | 4321 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult |
| 4141 ); | 4322 ); |
| 4142 pC->deferredMoveto = 0; | 4323 pC->deferredMoveto = 0; |
| 4143 pC->cacheStatus = CACHE_STALE; | 4324 pC->cacheStatus = CACHE_STALE; |
| 4144 | 4325 |
| 4145 /* Invoke the update-hook if required. */ | 4326 /* Invoke the update-hook if required. */ |
| 4146 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){ | 4327 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){ |
| 4147 zDb = db->aDb[pC->iDb].zName; | 4328 zDb = db->aDb[pC->iDb].zName; |
| 4148 zTbl = pOp->p4.z; | 4329 zTbl = pOp->p4.z; |
| 4149 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); | 4330 op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); |
| 4150 assert( pC->isTable ); | 4331 assert( pC->isTable ); |
| 4151 db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey); | 4332 db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey); |
| 4152 assert( pC->iDb>=0 ); | 4333 assert( pC->iDb>=0 ); |
| 4153 } | 4334 } |
| 4154 break; | 4335 break; |
| 4155 } | 4336 } |
| 4156 | 4337 |
| 4157 /* Opcode: Delete P1 P2 * P4 * | 4338 /* Opcode: Delete P1 P2 * P4 P5 |
| 4158 ** | 4339 ** |
| 4159 ** Delete the record at which the P1 cursor is currently pointing. | 4340 ** Delete the record at which the P1 cursor is currently pointing. |
| 4160 ** | 4341 ** |
| 4161 ** The cursor will be left pointing at either the next or the previous | 4342 ** If the P5 parameter is non-zero, the cursor will be left pointing at |
| 4162 ** record in the table. If it is left pointing at the next record, then | 4343 ** either the next or the previous record in the table. If it is left |
| 4163 ** the next Next instruction will be a no-op. Hence it is OK to delete | 4344 ** pointing at the next record, then the next Next instruction will be a |
| 4164 ** a record from within a Next loop. | 4345 ** no-op. As a result, in this case it is OK to delete a record from within a |
| 4346 ** Next loop. If P5 is zero, then the cursor is left in an undefined state. |
| 4165 ** | 4347 ** |
| 4166 ** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is | 4348 ** If the OPFLAG_NCHANGE flag of P2 is set, then the row change count is |
| 4167 ** incremented (otherwise not). | 4349 ** incremented (otherwise not). |
| 4168 ** | 4350 ** |
| 4169 ** P1 must not be pseudo-table. It has to be a real table with | 4351 ** P1 must not be pseudo-table. It has to be a real table with |
| 4170 ** multiple rows. | 4352 ** multiple rows. |
| 4171 ** | 4353 ** |
| 4172 ** If P4 is not NULL, then it is the name of the table that P1 is | 4354 ** If P4 is not NULL, then it is the name of the table that P1 is |
| 4173 ** pointing to. The update hook will be invoked, if it exists. | 4355 ** pointing to. The update hook will be invoked, if it exists. |
| 4174 ** If P4 is not NULL then the P1 cursor must have been positioned | 4356 ** If P4 is not NULL then the P1 cursor must have been positioned |
| 4175 ** using OP_NotFound prior to invoking this opcode. | 4357 ** using OP_NotFound prior to invoking this opcode. |
| 4176 */ | 4358 */ |
| 4177 case OP_Delete: { | 4359 case OP_Delete: { |
| 4178 VdbeCursor *pC; | 4360 VdbeCursor *pC; |
| 4361 u8 hasUpdateCallback; |
| 4179 | 4362 |
| 4180 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4363 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4181 pC = p->apCsr[pOp->p1]; | 4364 pC = p->apCsr[pOp->p1]; |
| 4182 assert( pC!=0 ); | 4365 assert( pC!=0 ); |
| 4183 assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ | 4366 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4367 assert( pC->uc.pCursor!=0 ); |
| 4184 assert( pC->deferredMoveto==0 ); | 4368 assert( pC->deferredMoveto==0 ); |
| 4185 | 4369 |
| 4370 hasUpdateCallback = db->xUpdateCallback && pOp->p4.z && pC->isTable; |
| 4371 if( pOp->p5 && hasUpdateCallback ){ |
| 4372 sqlite3BtreeKeySize(pC->uc.pCursor, &pC->movetoTarget); |
| 4373 } |
| 4374 |
| 4186 #ifdef SQLITE_DEBUG | 4375 #ifdef SQLITE_DEBUG |
| 4187 /* The seek operation that positioned the cursor prior to OP_Delete will | 4376 /* The seek operation that positioned the cursor prior to OP_Delete will |
| 4188 ** have also set the pC->movetoTarget field to the rowid of the row that | 4377 ** have also set the pC->movetoTarget field to the rowid of the row that |
| 4189 ** is being deleted */ | 4378 ** is being deleted */ |
| 4190 if( pOp->p4.z && pC->isTable ){ | 4379 if( pOp->p4.z && pC->isTable && pOp->p5==0 ){ |
| 4191 i64 iKey = 0; | 4380 i64 iKey = 0; |
| 4192 sqlite3BtreeKeySize(pC->pCursor, &iKey); | 4381 sqlite3BtreeKeySize(pC->uc.pCursor, &iKey); |
| 4193 assert( pC->movetoTarget==iKey ); | 4382 assert( pC->movetoTarget==iKey ); |
| 4194 } | 4383 } |
| 4195 #endif | 4384 #endif |
| 4196 | 4385 |
| 4197 rc = sqlite3BtreeDelete(pC->pCursor); | 4386 rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5); |
| 4198 pC->cacheStatus = CACHE_STALE; | 4387 pC->cacheStatus = CACHE_STALE; |
| 4199 | 4388 |
| 4200 /* Invoke the update-hook if required. */ | 4389 /* Invoke the update-hook if required. */ |
| 4201 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ | 4390 if( rc==SQLITE_OK && hasUpdateCallback ){ |
| 4202 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, | 4391 db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 4203 db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget); | 4392 db->aDb[pC->iDb].zName, pOp->p4.z, pC->movetoTarget); |
| 4204 assert( pC->iDb>=0 ); | 4393 assert( pC->iDb>=0 ); |
| 4205 } | 4394 } |
| 4206 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; | 4395 if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| 4207 break; | 4396 break; |
| 4208 } | 4397 } |
| 4209 /* Opcode: ResetCount * * * * * | 4398 /* Opcode: ResetCount * * * * * |
| 4210 ** | 4399 ** |
| 4211 ** The value of the change counter is copied to the database handle | 4400 ** The value of the change counter is copied to the database handle |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4240 int nKeyCol; | 4429 int nKeyCol; |
| 4241 | 4430 |
| 4242 pC = p->apCsr[pOp->p1]; | 4431 pC = p->apCsr[pOp->p1]; |
| 4243 assert( isSorter(pC) ); | 4432 assert( isSorter(pC) ); |
| 4244 assert( pOp->p4type==P4_INT32 ); | 4433 assert( pOp->p4type==P4_INT32 ); |
| 4245 pIn3 = &aMem[pOp->p3]; | 4434 pIn3 = &aMem[pOp->p3]; |
| 4246 nKeyCol = pOp->p4.i; | 4435 nKeyCol = pOp->p4.i; |
| 4247 res = 0; | 4436 res = 0; |
| 4248 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res); | 4437 rc = sqlite3VdbeSorterCompare(pC, pIn3, nKeyCol, &res); |
| 4249 VdbeBranchTaken(res!=0,2); | 4438 VdbeBranchTaken(res!=0,2); |
| 4250 if( res ){ | 4439 if( res ) goto jump_to_p2; |
| 4251 pc = pOp->p2-1; | |
| 4252 } | |
| 4253 break; | 4440 break; |
| 4254 }; | 4441 }; |
| 4255 | 4442 |
| 4256 /* Opcode: SorterData P1 P2 P3 * * | 4443 /* Opcode: SorterData P1 P2 P3 * * |
| 4257 ** Synopsis: r[P2]=data | 4444 ** Synopsis: r[P2]=data |
| 4258 ** | 4445 ** |
| 4259 ** Write into register P2 the current sorter data for sorter cursor P1. | 4446 ** Write into register P2 the current sorter data for sorter cursor P1. |
| 4260 ** Then clear the column header cache on cursor P3. | 4447 ** Then clear the column header cache on cursor P3. |
| 4261 ** | 4448 ** |
| 4262 ** This opcode is normally use to move a record out of the sorter and into | 4449 ** This opcode is normally use to move a record out of the sorter and into |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4306 BtCursor *pCrsr; | 4493 BtCursor *pCrsr; |
| 4307 u32 n; | 4494 u32 n; |
| 4308 i64 n64; | 4495 i64 n64; |
| 4309 | 4496 |
| 4310 pOut = &aMem[pOp->p2]; | 4497 pOut = &aMem[pOp->p2]; |
| 4311 memAboutToChange(p, pOut); | 4498 memAboutToChange(p, pOut); |
| 4312 | 4499 |
| 4313 /* Note that RowKey and RowData are really exactly the same instruction */ | 4500 /* Note that RowKey and RowData are really exactly the same instruction */ |
| 4314 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4501 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4315 pC = p->apCsr[pOp->p1]; | 4502 pC = p->apCsr[pOp->p1]; |
| 4503 assert( pC!=0 ); |
| 4504 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4316 assert( isSorter(pC)==0 ); | 4505 assert( isSorter(pC)==0 ); |
| 4317 assert( pC->isTable || pOp->opcode!=OP_RowData ); | 4506 assert( pC->isTable || pOp->opcode!=OP_RowData ); |
| 4318 assert( pC->isTable==0 || pOp->opcode==OP_RowData ); | 4507 assert( pC->isTable==0 || pOp->opcode==OP_RowData ); |
| 4319 assert( pC!=0 ); | |
| 4320 assert( pC->nullRow==0 ); | 4508 assert( pC->nullRow==0 ); |
| 4321 assert( pC->pseudoTableReg==0 ); | 4509 assert( pC->uc.pCursor!=0 ); |
| 4322 assert( pC->pCursor!=0 ); | 4510 pCrsr = pC->uc.pCursor; |
| 4323 pCrsr = pC->pCursor; | |
| 4324 | 4511 |
| 4325 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or | 4512 /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or |
| 4326 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate | 4513 ** OP_Rewind/Op_Next with no intervening instructions that might invalidate |
| 4327 ** the cursor. If this where not the case, on of the following assert()s | 4514 ** the cursor. If this where not the case, on of the following assert()s |
| 4328 ** would fail. Should this ever change (because of changes in the code | 4515 ** would fail. Should this ever change (because of changes in the code |
| 4329 ** generator) then the fix would be to insert a call to | 4516 ** generator) then the fix would be to insert a call to |
| 4330 ** sqlite3VdbeCursorMoveto(). | 4517 ** sqlite3VdbeCursorMoveto(). |
| 4331 */ | 4518 */ |
| 4332 assert( pC->deferredMoveto==0 ); | 4519 assert( pC->deferredMoveto==0 ); |
| 4333 assert( sqlite3BtreeCursorIsValid(pCrsr) ); | 4520 assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4371 /* Opcode: Rowid P1 P2 * * * | 4558 /* Opcode: Rowid P1 P2 * * * |
| 4372 ** Synopsis: r[P2]=rowid | 4559 ** Synopsis: r[P2]=rowid |
| 4373 ** | 4560 ** |
| 4374 ** Store in register P2 an integer which is the key of the table entry that | 4561 ** Store in register P2 an integer which is the key of the table entry that |
| 4375 ** P1 is currently point to. | 4562 ** P1 is currently point to. |
| 4376 ** | 4563 ** |
| 4377 ** P1 can be either an ordinary table or a virtual table. There used to | 4564 ** P1 can be either an ordinary table or a virtual table. There used to |
| 4378 ** be a separate OP_VRowid opcode for use with virtual tables, but this | 4565 ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 4379 ** one opcode now works for both table types. | 4566 ** one opcode now works for both table types. |
| 4380 */ | 4567 */ |
| 4381 case OP_Rowid: { /* out2-prerelease */ | 4568 case OP_Rowid: { /* out2 */ |
| 4382 VdbeCursor *pC; | 4569 VdbeCursor *pC; |
| 4383 i64 v; | 4570 i64 v; |
| 4384 sqlite3_vtab *pVtab; | 4571 sqlite3_vtab *pVtab; |
| 4385 const sqlite3_module *pModule; | 4572 const sqlite3_module *pModule; |
| 4386 | 4573 |
| 4574 pOut = out2Prerelease(p, pOp); |
| 4387 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4575 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4388 pC = p->apCsr[pOp->p1]; | 4576 pC = p->apCsr[pOp->p1]; |
| 4389 assert( pC!=0 ); | 4577 assert( pC!=0 ); |
| 4390 assert( pC->pseudoTableReg==0 || pC->nullRow ); | 4578 assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow ); |
| 4391 if( pC->nullRow ){ | 4579 if( pC->nullRow ){ |
| 4392 pOut->flags = MEM_Null; | 4580 pOut->flags = MEM_Null; |
| 4393 break; | 4581 break; |
| 4394 }else if( pC->deferredMoveto ){ | 4582 }else if( pC->deferredMoveto ){ |
| 4395 v = pC->movetoTarget; | 4583 v = pC->movetoTarget; |
| 4396 #ifndef SQLITE_OMIT_VIRTUALTABLE | 4584 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 4397 }else if( pC->pVtabCursor ){ | 4585 }else if( pC->eCurType==CURTYPE_VTAB ){ |
| 4398 pVtab = pC->pVtabCursor->pVtab; | 4586 assert( pC->uc.pVCur!=0 ); |
| 4587 pVtab = pC->uc.pVCur->pVtab; |
| 4399 pModule = pVtab->pModule; | 4588 pModule = pVtab->pModule; |
| 4400 assert( pModule->xRowid ); | 4589 assert( pModule->xRowid ); |
| 4401 rc = pModule->xRowid(pC->pVtabCursor, &v); | 4590 rc = pModule->xRowid(pC->uc.pVCur, &v); |
| 4402 sqlite3VtabImportErrmsg(p, pVtab); | 4591 sqlite3VtabImportErrmsg(p, pVtab); |
| 4403 #endif /* SQLITE_OMIT_VIRTUALTABLE */ | 4592 #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 4404 }else{ | 4593 }else{ |
| 4405 assert( pC->pCursor!=0 ); | 4594 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4595 assert( pC->uc.pCursor!=0 ); |
| 4406 rc = sqlite3VdbeCursorRestore(pC); | 4596 rc = sqlite3VdbeCursorRestore(pC); |
| 4407 if( rc ) goto abort_due_to_error; | 4597 if( rc ) goto abort_due_to_error; |
| 4408 if( pC->nullRow ){ | 4598 if( pC->nullRow ){ |
| 4409 pOut->flags = MEM_Null; | 4599 pOut->flags = MEM_Null; |
| 4410 break; | 4600 break; |
| 4411 } | 4601 } |
| 4412 rc = sqlite3BtreeKeySize(pC->pCursor, &v); | 4602 rc = sqlite3BtreeKeySize(pC->uc.pCursor, &v); |
| 4413 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */ | 4603 assert( rc==SQLITE_OK ); /* Always so because of CursorRestore() above */ |
| 4414 } | 4604 } |
| 4415 pOut->u.i = v; | 4605 pOut->u.i = v; |
| 4416 break; | 4606 break; |
| 4417 } | 4607 } |
| 4418 | 4608 |
| 4419 /* Opcode: NullRow P1 * * * * | 4609 /* Opcode: NullRow P1 * * * * |
| 4420 ** | 4610 ** |
| 4421 ** Move the cursor P1 to a null row. Any OP_Column operations | 4611 ** Move the cursor P1 to a null row. Any OP_Column operations |
| 4422 ** that occur while the cursor is on the null row will always | 4612 ** that occur while the cursor is on the null row will always |
| 4423 ** write a NULL. | 4613 ** write a NULL. |
| 4424 */ | 4614 */ |
| 4425 case OP_NullRow: { | 4615 case OP_NullRow: { |
| 4426 VdbeCursor *pC; | 4616 VdbeCursor *pC; |
| 4427 | 4617 |
| 4428 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4618 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4429 pC = p->apCsr[pOp->p1]; | 4619 pC = p->apCsr[pOp->p1]; |
| 4430 assert( pC!=0 ); | 4620 assert( pC!=0 ); |
| 4431 pC->nullRow = 1; | 4621 pC->nullRow = 1; |
| 4432 pC->cacheStatus = CACHE_STALE; | 4622 pC->cacheStatus = CACHE_STALE; |
| 4433 if( pC->pCursor ){ | 4623 if( pC->eCurType==CURTYPE_BTREE ){ |
| 4434 sqlite3BtreeClearCursor(pC->pCursor); | 4624 assert( pC->uc.pCursor!=0 ); |
| 4625 sqlite3BtreeClearCursor(pC->uc.pCursor); |
| 4435 } | 4626 } |
| 4436 break; | 4627 break; |
| 4437 } | 4628 } |
| 4438 | 4629 |
| 4439 /* Opcode: Last P1 P2 * * * | 4630 /* Opcode: Last P1 P2 P3 * * |
| 4440 ** | 4631 ** |
| 4441 ** The next use of the Rowid or Column or Prev instruction for P1 | 4632 ** The next use of the Rowid or Column or Prev instruction for P1 |
| 4442 ** will refer to the last entry in the database table or index. | 4633 ** will refer to the last entry in the database table or index. |
| 4443 ** If the table or index is empty and P2>0, then jump immediately to P2. | 4634 ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 4444 ** If P2 is 0 or if the table or index is not empty, fall through | 4635 ** If P2 is 0 or if the table or index is not empty, fall through |
| 4445 ** to the following instruction. | 4636 ** to the following instruction. |
| 4446 ** | 4637 ** |
| 4447 ** This opcode leaves the cursor configured to move in reverse order, | 4638 ** This opcode leaves the cursor configured to move in reverse order, |
| 4448 ** from the end toward the beginning. In other words, the cursor is | 4639 ** from the end toward the beginning. In other words, the cursor is |
| 4449 ** configured to use Prev, not Next. | 4640 ** configured to use Prev, not Next. |
| 4450 */ | 4641 */ |
| 4451 case OP_Last: { /* jump */ | 4642 case OP_Last: { /* jump */ |
| 4452 VdbeCursor *pC; | 4643 VdbeCursor *pC; |
| 4453 BtCursor *pCrsr; | 4644 BtCursor *pCrsr; |
| 4454 int res; | 4645 int res; |
| 4455 | 4646 |
| 4456 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4647 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4457 pC = p->apCsr[pOp->p1]; | 4648 pC = p->apCsr[pOp->p1]; |
| 4458 assert( pC!=0 ); | 4649 assert( pC!=0 ); |
| 4459 pCrsr = pC->pCursor; | 4650 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4651 pCrsr = pC->uc.pCursor; |
| 4460 res = 0; | 4652 res = 0; |
| 4461 assert( pCrsr!=0 ); | 4653 assert( pCrsr!=0 ); |
| 4462 rc = sqlite3BtreeLast(pCrsr, &res); | 4654 rc = sqlite3BtreeLast(pCrsr, &res); |
| 4463 pC->nullRow = (u8)res; | 4655 pC->nullRow = (u8)res; |
| 4464 pC->deferredMoveto = 0; | 4656 pC->deferredMoveto = 0; |
| 4465 pC->cacheStatus = CACHE_STALE; | 4657 pC->cacheStatus = CACHE_STALE; |
| 4658 pC->seekResult = pOp->p3; |
| 4466 #ifdef SQLITE_DEBUG | 4659 #ifdef SQLITE_DEBUG |
| 4467 pC->seekOp = OP_Last; | 4660 pC->seekOp = OP_Last; |
| 4468 #endif | 4661 #endif |
| 4469 if( pOp->p2>0 ){ | 4662 if( pOp->p2>0 ){ |
| 4470 VdbeBranchTaken(res!=0,2); | 4663 VdbeBranchTaken(res!=0,2); |
| 4471 if( res ) pc = pOp->p2 - 1; | 4664 if( res ) goto jump_to_p2; |
| 4472 } | 4665 } |
| 4473 break; | 4666 break; |
| 4474 } | 4667 } |
| 4475 | 4668 |
| 4476 | 4669 |
| 4477 /* Opcode: Sort P1 P2 * * * | 4670 /* Opcode: Sort P1 P2 * * * |
| 4478 ** | 4671 ** |
| 4479 ** This opcode does exactly the same thing as OP_Rewind except that | 4672 ** This opcode does exactly the same thing as OP_Rewind except that |
| 4480 ** it increments an undocumented global variable used for testing. | 4673 ** it increments an undocumented global variable used for testing. |
| 4481 ** | 4674 ** |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4492 sqlite3_sort_count++; | 4685 sqlite3_sort_count++; |
| 4493 sqlite3_search_count--; | 4686 sqlite3_search_count--; |
| 4494 #endif | 4687 #endif |
| 4495 p->aCounter[SQLITE_STMTSTATUS_SORT]++; | 4688 p->aCounter[SQLITE_STMTSTATUS_SORT]++; |
| 4496 /* Fall through into OP_Rewind */ | 4689 /* Fall through into OP_Rewind */ |
| 4497 } | 4690 } |
| 4498 /* Opcode: Rewind P1 P2 * * * | 4691 /* Opcode: Rewind P1 P2 * * * |
| 4499 ** | 4692 ** |
| 4500 ** The next use of the Rowid or Column or Next instruction for P1 | 4693 ** The next use of the Rowid or Column or Next instruction for P1 |
| 4501 ** will refer to the first entry in the database table or index. | 4694 ** will refer to the first entry in the database table or index. |
| 4502 ** If the table or index is empty and P2>0, then jump immediately to P2. | 4695 ** If the table or index is empty, jump immediately to P2. |
| 4503 ** If P2 is 0 or if the table or index is not empty, fall through | 4696 ** If the table or index is not empty, fall through to the following |
| 4504 ** to the following instruction. | 4697 ** instruction. |
| 4505 ** | 4698 ** |
| 4506 ** This opcode leaves the cursor configured to move in forward order, | 4699 ** This opcode leaves the cursor configured to move in forward order, |
| 4507 ** from the beginning toward the end. In other words, the cursor is | 4700 ** from the beginning toward the end. In other words, the cursor is |
| 4508 ** configured to use Next, not Prev. | 4701 ** configured to use Next, not Prev. |
| 4509 */ | 4702 */ |
| 4510 case OP_Rewind: { /* jump */ | 4703 case OP_Rewind: { /* jump */ |
| 4511 VdbeCursor *pC; | 4704 VdbeCursor *pC; |
| 4512 BtCursor *pCrsr; | 4705 BtCursor *pCrsr; |
| 4513 int res; | 4706 int res; |
| 4514 | 4707 |
| 4515 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4708 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4516 pC = p->apCsr[pOp->p1]; | 4709 pC = p->apCsr[pOp->p1]; |
| 4517 assert( pC!=0 ); | 4710 assert( pC!=0 ); |
| 4518 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) ); | 4711 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) ); |
| 4519 res = 1; | 4712 res = 1; |
| 4520 #ifdef SQLITE_DEBUG | 4713 #ifdef SQLITE_DEBUG |
| 4521 pC->seekOp = OP_Rewind; | 4714 pC->seekOp = OP_Rewind; |
| 4522 #endif | 4715 #endif |
| 4523 if( isSorter(pC) ){ | 4716 if( isSorter(pC) ){ |
| 4524 rc = sqlite3VdbeSorterRewind(pC, &res); | 4717 rc = sqlite3VdbeSorterRewind(pC, &res); |
| 4525 }else{ | 4718 }else{ |
| 4526 pCrsr = pC->pCursor; | 4719 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4720 pCrsr = pC->uc.pCursor; |
| 4527 assert( pCrsr ); | 4721 assert( pCrsr ); |
| 4528 rc = sqlite3BtreeFirst(pCrsr, &res); | 4722 rc = sqlite3BtreeFirst(pCrsr, &res); |
| 4529 pC->deferredMoveto = 0; | 4723 pC->deferredMoveto = 0; |
| 4530 pC->cacheStatus = CACHE_STALE; | 4724 pC->cacheStatus = CACHE_STALE; |
| 4531 } | 4725 } |
| 4532 pC->nullRow = (u8)res; | 4726 pC->nullRow = (u8)res; |
| 4533 assert( pOp->p2>0 && pOp->p2<p->nOp ); | 4727 assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 4534 VdbeBranchTaken(res!=0,2); | 4728 VdbeBranchTaken(res!=0,2); |
| 4535 if( res ){ | 4729 if( res ) goto jump_to_p2; |
| 4536 pc = pOp->p2 - 1; | |
| 4537 } | |
| 4538 break; | 4730 break; |
| 4539 } | 4731 } |
| 4540 | 4732 |
| 4541 /* Opcode: Next P1 P2 P3 P4 P5 | 4733 /* Opcode: Next P1 P2 P3 P4 P5 |
| 4542 ** | 4734 ** |
| 4543 ** Advance cursor P1 so that it points to the next key/data pair in its | 4735 ** Advance cursor P1 so that it points to the next key/data pair in its |
| 4544 ** table or index. If there are no more key/value pairs then fall through | 4736 ** table or index. If there are no more key/value pairs then fall through |
| 4545 ** to the following instruction. But if the cursor advance was successful, | 4737 ** to the following instruction. But if the cursor advance was successful, |
| 4546 ** jump immediately to P2. | 4738 ** jump immediately to P2. |
| 4547 ** | 4739 ** |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4615 if( p->apCsr[pOp->p1]==0 ) break; | 4807 if( p->apCsr[pOp->p1]==0 ) break; |
| 4616 /* Fall through */ | 4808 /* Fall through */ |
| 4617 case OP_Prev: /* jump */ | 4809 case OP_Prev: /* jump */ |
| 4618 case OP_Next: /* jump */ | 4810 case OP_Next: /* jump */ |
| 4619 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4811 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4620 assert( pOp->p5<ArraySize(p->aCounter) ); | 4812 assert( pOp->p5<ArraySize(p->aCounter) ); |
| 4621 pC = p->apCsr[pOp->p1]; | 4813 pC = p->apCsr[pOp->p1]; |
| 4622 res = pOp->p3; | 4814 res = pOp->p3; |
| 4623 assert( pC!=0 ); | 4815 assert( pC!=0 ); |
| 4624 assert( pC->deferredMoveto==0 ); | 4816 assert( pC->deferredMoveto==0 ); |
| 4625 assert( pC->pCursor ); | 4817 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4626 assert( res==0 || (res==1 && pC->isTable==0) ); | 4818 assert( res==0 || (res==1 && pC->isTable==0) ); |
| 4627 testcase( res==1 ); | 4819 testcase( res==1 ); |
| 4628 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); | 4820 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 4629 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); | 4821 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 4630 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); | 4822 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 4631 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); | 4823 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); |
| 4632 | 4824 |
| 4633 /* The Next opcode is only used after SeekGT, SeekGE, and Rewind. | 4825 /* The Next opcode is only used after SeekGT, SeekGE, and Rewind. |
| 4634 ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */ | 4826 ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */ |
| 4635 assert( pOp->opcode!=OP_Next || pOp->opcode!=OP_NextIfOpen | 4827 assert( pOp->opcode!=OP_Next || pOp->opcode!=OP_NextIfOpen |
| 4636 || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE | 4828 || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE |
| 4637 || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found); | 4829 || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found); |
| 4638 assert( pOp->opcode!=OP_Prev || pOp->opcode!=OP_PrevIfOpen | 4830 assert( pOp->opcode!=OP_Prev || pOp->opcode!=OP_PrevIfOpen |
| 4639 || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE | 4831 || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE |
| 4640 || pC->seekOp==OP_Last ); | 4832 || pC->seekOp==OP_Last ); |
| 4641 | 4833 |
| 4642 rc = pOp->p4.xAdvance(pC->pCursor, &res); | 4834 rc = pOp->p4.xAdvance(pC->uc.pCursor, &res); |
| 4643 next_tail: | 4835 next_tail: |
| 4644 pC->cacheStatus = CACHE_STALE; | 4836 pC->cacheStatus = CACHE_STALE; |
| 4645 VdbeBranchTaken(res==0,2); | 4837 VdbeBranchTaken(res==0,2); |
| 4646 if( res==0 ){ | 4838 if( res==0 ){ |
| 4647 pC->nullRow = 0; | 4839 pC->nullRow = 0; |
| 4648 pc = pOp->p2 - 1; | |
| 4649 p->aCounter[pOp->p5]++; | 4840 p->aCounter[pOp->p5]++; |
| 4650 #ifdef SQLITE_TEST | 4841 #ifdef SQLITE_TEST |
| 4651 sqlite3_search_count++; | 4842 sqlite3_search_count++; |
| 4652 #endif | 4843 #endif |
| 4844 goto jump_to_p2_and_check_for_interrupt; |
| 4653 }else{ | 4845 }else{ |
| 4654 pC->nullRow = 1; | 4846 pC->nullRow = 1; |
| 4655 } | 4847 } |
| 4656 goto check_for_interrupt; | 4848 goto check_for_interrupt; |
| 4657 } | 4849 } |
| 4658 | 4850 |
| 4659 /* Opcode: IdxInsert P1 P2 P3 * P5 | 4851 /* Opcode: IdxInsert P1 P2 P3 * P5 |
| 4660 ** Synopsis: key=r[P2] | 4852 ** Synopsis: key=r[P2] |
| 4661 ** | 4853 ** |
| 4662 ** Register P2 holds an SQL index key made using the | 4854 ** Register P2 holds an SQL index key made using the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4673 ** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have | 4865 ** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have |
| 4674 ** just done a seek to the spot where the new entry is to be inserted. | 4866 ** just done a seek to the spot where the new entry is to be inserted. |
| 4675 ** This flag avoids doing an extra seek. | 4867 ** This flag avoids doing an extra seek. |
| 4676 ** | 4868 ** |
| 4677 ** This instruction only works for indices. The equivalent instruction | 4869 ** This instruction only works for indices. The equivalent instruction |
| 4678 ** for tables is OP_Insert. | 4870 ** for tables is OP_Insert. |
| 4679 */ | 4871 */ |
| 4680 case OP_SorterInsert: /* in2 */ | 4872 case OP_SorterInsert: /* in2 */ |
| 4681 case OP_IdxInsert: { /* in2 */ | 4873 case OP_IdxInsert: { /* in2 */ |
| 4682 VdbeCursor *pC; | 4874 VdbeCursor *pC; |
| 4683 BtCursor *pCrsr; | |
| 4684 int nKey; | 4875 int nKey; |
| 4685 const char *zKey; | 4876 const char *zKey; |
| 4686 | 4877 |
| 4687 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4878 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4688 pC = p->apCsr[pOp->p1]; | 4879 pC = p->apCsr[pOp->p1]; |
| 4689 assert( pC!=0 ); | 4880 assert( pC!=0 ); |
| 4690 assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) ); | 4881 assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) ); |
| 4691 pIn2 = &aMem[pOp->p2]; | 4882 pIn2 = &aMem[pOp->p2]; |
| 4692 assert( pIn2->flags & MEM_Blob ); | 4883 assert( pIn2->flags & MEM_Blob ); |
| 4693 pCrsr = pC->pCursor; | |
| 4694 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; | 4884 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 4695 assert( pCrsr!=0 ); | 4885 assert( pC->eCurType==CURTYPE_BTREE || pOp->opcode==OP_SorterInsert ); |
| 4696 assert( pC->isTable==0 ); | 4886 assert( pC->isTable==0 ); |
| 4697 rc = ExpandBlob(pIn2); | 4887 rc = ExpandBlob(pIn2); |
| 4698 if( rc==SQLITE_OK ){ | 4888 if( rc==SQLITE_OK ){ |
| 4699 if( isSorter(pC) ){ | 4889 if( pOp->opcode==OP_SorterInsert ){ |
| 4700 rc = sqlite3VdbeSorterWrite(pC, pIn2); | 4890 rc = sqlite3VdbeSorterWrite(pC, pIn2); |
| 4701 }else{ | 4891 }else{ |
| 4702 nKey = pIn2->n; | 4892 nKey = pIn2->n; |
| 4703 zKey = pIn2->z; | 4893 zKey = pIn2->z; |
| 4704 rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3, | 4894 rc = sqlite3BtreeInsert(pC->uc.pCursor, zKey, nKey, "", 0, 0, pOp->p3, |
| 4705 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) | 4895 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 4706 ); | 4896 ); |
| 4707 assert( pC->deferredMoveto==0 ); | 4897 assert( pC->deferredMoveto==0 ); |
| 4708 pC->cacheStatus = CACHE_STALE; | 4898 pC->cacheStatus = CACHE_STALE; |
| 4709 } | 4899 } |
| 4710 } | 4900 } |
| 4711 break; | 4901 break; |
| 4712 } | 4902 } |
| 4713 | 4903 |
| 4714 /* Opcode: IdxDelete P1 P2 P3 * * | 4904 /* Opcode: IdxDelete P1 P2 P3 * * |
| 4715 ** Synopsis: key=r[P2@P3] | 4905 ** Synopsis: key=r[P2@P3] |
| 4716 ** | 4906 ** |
| 4717 ** The content of P3 registers starting at register P2 form | 4907 ** The content of P3 registers starting at register P2 form |
| 4718 ** an unpacked index key. This opcode removes that entry from the | 4908 ** an unpacked index key. This opcode removes that entry from the |
| 4719 ** index opened by cursor P1. | 4909 ** index opened by cursor P1. |
| 4720 */ | 4910 */ |
| 4721 case OP_IdxDelete: { | 4911 case OP_IdxDelete: { |
| 4722 VdbeCursor *pC; | 4912 VdbeCursor *pC; |
| 4723 BtCursor *pCrsr; | 4913 BtCursor *pCrsr; |
| 4724 int res; | 4914 int res; |
| 4725 UnpackedRecord r; | 4915 UnpackedRecord r; |
| 4726 | 4916 |
| 4727 assert( pOp->p3>0 ); | 4917 assert( pOp->p3>0 ); |
| 4728 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 ); | 4918 assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 ); |
| 4729 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4919 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4730 pC = p->apCsr[pOp->p1]; | 4920 pC = p->apCsr[pOp->p1]; |
| 4731 assert( pC!=0 ); | 4921 assert( pC!=0 ); |
| 4732 pCrsr = pC->pCursor; | 4922 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4923 pCrsr = pC->uc.pCursor; |
| 4733 assert( pCrsr!=0 ); | 4924 assert( pCrsr!=0 ); |
| 4734 assert( pOp->p5==0 ); | 4925 assert( pOp->p5==0 ); |
| 4735 r.pKeyInfo = pC->pKeyInfo; | 4926 r.pKeyInfo = pC->pKeyInfo; |
| 4736 r.nField = (u16)pOp->p3; | 4927 r.nField = (u16)pOp->p3; |
| 4737 r.default_rc = 0; | 4928 r.default_rc = 0; |
| 4738 r.aMem = &aMem[pOp->p2]; | 4929 r.aMem = &aMem[pOp->p2]; |
| 4739 #ifdef SQLITE_DEBUG | 4930 #ifdef SQLITE_DEBUG |
| 4740 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } | 4931 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 4741 #endif | 4932 #endif |
| 4742 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); | 4933 rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 4743 if( rc==SQLITE_OK && res==0 ){ | 4934 if( rc==SQLITE_OK && res==0 ){ |
| 4744 rc = sqlite3BtreeDelete(pCrsr); | 4935 rc = sqlite3BtreeDelete(pCrsr, 0); |
| 4745 } | 4936 } |
| 4746 assert( pC->deferredMoveto==0 ); | 4937 assert( pC->deferredMoveto==0 ); |
| 4747 pC->cacheStatus = CACHE_STALE; | 4938 pC->cacheStatus = CACHE_STALE; |
| 4748 break; | 4939 break; |
| 4749 } | 4940 } |
| 4750 | 4941 |
| 4751 /* Opcode: IdxRowid P1 P2 * * * | 4942 /* Opcode: IdxRowid P1 P2 * * * |
| 4752 ** Synopsis: r[P2]=rowid | 4943 ** Synopsis: r[P2]=rowid |
| 4753 ** | 4944 ** |
| 4754 ** Write into register P2 an integer which is the last entry in the record at | 4945 ** Write into register P2 an integer which is the last entry in the record at |
| 4755 ** the end of the index key pointed to by cursor P1. This integer should be | 4946 ** the end of the index key pointed to by cursor P1. This integer should be |
| 4756 ** the rowid of the table entry to which this index entry points. | 4947 ** the rowid of the table entry to which this index entry points. |
| 4757 ** | 4948 ** |
| 4758 ** See also: Rowid, MakeRecord. | 4949 ** See also: Rowid, MakeRecord. |
| 4759 */ | 4950 */ |
| 4760 case OP_IdxRowid: { /* out2-prerelease */ | 4951 case OP_IdxRowid: { /* out2 */ |
| 4761 BtCursor *pCrsr; | 4952 BtCursor *pCrsr; |
| 4762 VdbeCursor *pC; | 4953 VdbeCursor *pC; |
| 4763 i64 rowid; | 4954 i64 rowid; |
| 4764 | 4955 |
| 4956 pOut = out2Prerelease(p, pOp); |
| 4765 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 4957 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4766 pC = p->apCsr[pOp->p1]; | 4958 pC = p->apCsr[pOp->p1]; |
| 4767 assert( pC!=0 ); | 4959 assert( pC!=0 ); |
| 4768 pCrsr = pC->pCursor; | 4960 assert( pC->eCurType==CURTYPE_BTREE ); |
| 4961 pCrsr = pC->uc.pCursor; |
| 4769 assert( pCrsr!=0 ); | 4962 assert( pCrsr!=0 ); |
| 4770 pOut->flags = MEM_Null; | 4963 pOut->flags = MEM_Null; |
| 4771 assert( pC->isTable==0 ); | 4964 assert( pC->isTable==0 ); |
| 4772 assert( pC->deferredMoveto==0 ); | 4965 assert( pC->deferredMoveto==0 ); |
| 4773 | 4966 |
| 4774 /* sqlite3VbeCursorRestore() can only fail if the record has been deleted | 4967 /* sqlite3VbeCursorRestore() can only fail if the record has been deleted |
| 4775 ** out from under the cursor. That will never happend for an IdxRowid | 4968 ** out from under the cursor. That will never happend for an IdxRowid |
| 4776 ** opcode, hence the NEVER() arround the check of the return value. | 4969 ** opcode, hence the NEVER() arround the check of the return value. |
| 4777 */ | 4970 */ |
| 4778 rc = sqlite3VdbeCursorRestore(pC); | 4971 rc = sqlite3VdbeCursorRestore(pC); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4839 case OP_IdxLT: /* jump */ | 5032 case OP_IdxLT: /* jump */ |
| 4840 case OP_IdxGE: { /* jump */ | 5033 case OP_IdxGE: { /* jump */ |
| 4841 VdbeCursor *pC; | 5034 VdbeCursor *pC; |
| 4842 int res; | 5035 int res; |
| 4843 UnpackedRecord r; | 5036 UnpackedRecord r; |
| 4844 | 5037 |
| 4845 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 5038 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4846 pC = p->apCsr[pOp->p1]; | 5039 pC = p->apCsr[pOp->p1]; |
| 4847 assert( pC!=0 ); | 5040 assert( pC!=0 ); |
| 4848 assert( pC->isOrdered ); | 5041 assert( pC->isOrdered ); |
| 4849 assert( pC->pCursor!=0); | 5042 assert( pC->eCurType==CURTYPE_BTREE ); |
| 5043 assert( pC->uc.pCursor!=0); |
| 4850 assert( pC->deferredMoveto==0 ); | 5044 assert( pC->deferredMoveto==0 ); |
| 4851 assert( pOp->p5==0 || pOp->p5==1 ); | 5045 assert( pOp->p5==0 || pOp->p5==1 ); |
| 4852 assert( pOp->p4type==P4_INT32 ); | 5046 assert( pOp->p4type==P4_INT32 ); |
| 4853 r.pKeyInfo = pC->pKeyInfo; | 5047 r.pKeyInfo = pC->pKeyInfo; |
| 4854 r.nField = (u16)pOp->p4.i; | 5048 r.nField = (u16)pOp->p4.i; |
| 4855 if( pOp->opcode<OP_IdxLT ){ | 5049 if( pOp->opcode<OP_IdxLT ){ |
| 4856 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT ); | 5050 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT ); |
| 4857 r.default_rc = -1; | 5051 r.default_rc = -1; |
| 4858 }else{ | 5052 }else{ |
| 4859 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT ); | 5053 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT ); |
| 4860 r.default_rc = 0; | 5054 r.default_rc = 0; |
| 4861 } | 5055 } |
| 4862 r.aMem = &aMem[pOp->p3]; | 5056 r.aMem = &aMem[pOp->p3]; |
| 4863 #ifdef SQLITE_DEBUG | 5057 #ifdef SQLITE_DEBUG |
| 4864 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } | 5058 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 4865 #endif | 5059 #endif |
| 4866 res = 0; /* Not needed. Only used to silence a warning. */ | 5060 res = 0; /* Not needed. Only used to silence a warning. */ |
| 4867 rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res); | 5061 rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res); |
| 4868 assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) ); | 5062 assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) ); |
| 4869 if( (pOp->opcode&1)==(OP_IdxLT&1) ){ | 5063 if( (pOp->opcode&1)==(OP_IdxLT&1) ){ |
| 4870 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT ); | 5064 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT ); |
| 4871 res = -res; | 5065 res = -res; |
| 4872 }else{ | 5066 }else{ |
| 4873 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT ); | 5067 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT ); |
| 4874 res++; | 5068 res++; |
| 4875 } | 5069 } |
| 4876 VdbeBranchTaken(res>0,2); | 5070 VdbeBranchTaken(res>0,2); |
| 4877 if( res>0 ){ | 5071 if( res>0 ) goto jump_to_p2; |
| 4878 pc = pOp->p2 - 1 ; | |
| 4879 } | |
| 4880 break; | 5072 break; |
| 4881 } | 5073 } |
| 4882 | 5074 |
| 4883 /* Opcode: Destroy P1 P2 P3 * * | 5075 /* Opcode: Destroy P1 P2 P3 * * |
| 4884 ** | 5076 ** |
| 4885 ** Delete an entire database table or index whose root page in the database | 5077 ** Delete an entire database table or index whose root page in the database |
| 4886 ** file is given by P1. | 5078 ** file is given by P1. |
| 4887 ** | 5079 ** |
| 4888 ** The table being destroyed is in the main database file if P3==0. If | 5080 ** The table being destroyed is in the main database file if P3==0. If |
| 4889 ** P3==1 then the table to be clear is in the auxiliary database file | 5081 ** P3==1 then the table to be clear is in the auxiliary database file |
| 4890 ** that is used to store tables create using CREATE TEMPORARY TABLE. | 5082 ** that is used to store tables create using CREATE TEMPORARY TABLE. |
| 4891 ** | 5083 ** |
| 4892 ** If AUTOVACUUM is enabled then it is possible that another root page | 5084 ** If AUTOVACUUM is enabled then it is possible that another root page |
| 4893 ** might be moved into the newly deleted root page in order to keep all | 5085 ** might be moved into the newly deleted root page in order to keep all |
| 4894 ** root pages contiguous at the beginning of the database. The former | 5086 ** root pages contiguous at the beginning of the database. The former |
| 4895 ** value of the root page that moved - its value before the move occurred - | 5087 ** value of the root page that moved - its value before the move occurred - |
| 4896 ** is stored in register P2. If no page | 5088 ** is stored in register P2. If no page |
| 4897 ** movement was required (because the table being dropped was already | 5089 ** movement was required (because the table being dropped was already |
| 4898 ** the last one in the database) then a zero is stored in register P2. | 5090 ** the last one in the database) then a zero is stored in register P2. |
| 4899 ** If AUTOVACUUM is disabled then a zero is stored in register P2. | 5091 ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 4900 ** | 5092 ** |
| 4901 ** See also: Clear | 5093 ** See also: Clear |
| 4902 */ | 5094 */ |
| 4903 case OP_Destroy: { /* out2-prerelease */ | 5095 case OP_Destroy: { /* out2 */ |
| 4904 int iMoved; | 5096 int iMoved; |
| 4905 int iCnt; | |
| 4906 Vdbe *pVdbe; | |
| 4907 int iDb; | 5097 int iDb; |
| 4908 | 5098 |
| 4909 assert( p->readOnly==0 ); | 5099 assert( p->readOnly==0 ); |
| 4910 #ifndef SQLITE_OMIT_VIRTUALTABLE | 5100 pOut = out2Prerelease(p, pOp); |
| 4911 iCnt = 0; | |
| 4912 for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){ | |
| 4913 if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader | |
| 4914 && pVdbe->inVtabMethod<2 && pVdbe->pc>=0 | |
| 4915 ){ | |
| 4916 iCnt++; | |
| 4917 } | |
| 4918 } | |
| 4919 #else | |
| 4920 iCnt = db->nVdbeRead; | |
| 4921 #endif | |
| 4922 pOut->flags = MEM_Null; | 5101 pOut->flags = MEM_Null; |
| 4923 if( iCnt>1 ){ | 5102 if( db->nVdbeRead > db->nVDestroy+1 ){ |
| 4924 rc = SQLITE_LOCKED; | 5103 rc = SQLITE_LOCKED; |
| 4925 p->errorAction = OE_Abort; | 5104 p->errorAction = OE_Abort; |
| 4926 }else{ | 5105 }else{ |
| 4927 iDb = pOp->p3; | 5106 iDb = pOp->p3; |
| 4928 assert( iCnt==1 ); | |
| 4929 assert( DbMaskTest(p->btreeMask, iDb) ); | 5107 assert( DbMaskTest(p->btreeMask, iDb) ); |
| 4930 iMoved = 0; /* Not needed. Only to silence a warning. */ | 5108 iMoved = 0; /* Not needed. Only to silence a warning. */ |
| 4931 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved); | 5109 rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved); |
| 4932 pOut->flags = MEM_Int; | 5110 pOut->flags = MEM_Int; |
| 4933 pOut->u.i = iMoved; | 5111 pOut->u.i = iMoved; |
| 4934 #ifndef SQLITE_OMIT_AUTOVACUUM | 5112 #ifndef SQLITE_OMIT_AUTOVACUUM |
| 4935 if( rc==SQLITE_OK && iMoved!=0 ){ | 5113 if( rc==SQLITE_OK && iMoved!=0 ){ |
| 4936 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1); | 5114 sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1); |
| 4937 /* All OP_Destroy operations occur on the same btree */ | 5115 /* All OP_Destroy operations occur on the same btree */ |
| 4938 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 ); | 5116 assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 ); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4988 ** | 5166 ** |
| 4989 ** This opcode only works for cursors used for sorting and | 5167 ** This opcode only works for cursors used for sorting and |
| 4990 ** opened with OP_OpenEphemeral or OP_SorterOpen. | 5168 ** opened with OP_OpenEphemeral or OP_SorterOpen. |
| 4991 */ | 5169 */ |
| 4992 case OP_ResetSorter: { | 5170 case OP_ResetSorter: { |
| 4993 VdbeCursor *pC; | 5171 VdbeCursor *pC; |
| 4994 | 5172 |
| 4995 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | 5173 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 4996 pC = p->apCsr[pOp->p1]; | 5174 pC = p->apCsr[pOp->p1]; |
| 4997 assert( pC!=0 ); | 5175 assert( pC!=0 ); |
| 4998 if( pC->pSorter ){ | 5176 if( isSorter(pC) ){ |
| 4999 sqlite3VdbeSorterReset(db, pC->pSorter); | 5177 sqlite3VdbeSorterReset(db, pC->uc.pSorter); |
| 5000 }else{ | 5178 }else{ |
| 5179 assert( pC->eCurType==CURTYPE_BTREE ); |
| 5001 assert( pC->isEphemeral ); | 5180 assert( pC->isEphemeral ); |
| 5002 rc = sqlite3BtreeClearTableOfCursor(pC->pCursor); | 5181 rc = sqlite3BtreeClearTableOfCursor(pC->uc.pCursor); |
| 5003 } | 5182 } |
| 5004 break; | 5183 break; |
| 5005 } | 5184 } |
| 5006 | 5185 |
| 5007 /* Opcode: CreateTable P1 P2 * * * | 5186 /* Opcode: CreateTable P1 P2 * * * |
| 5008 ** Synopsis: r[P2]=root iDb=P1 | 5187 ** Synopsis: r[P2]=root iDb=P1 |
| 5009 ** | 5188 ** |
| 5010 ** Allocate a new table in the main database file if P1==0 or in the | 5189 ** Allocate a new table in the main database file if P1==0 or in the |
| 5011 ** auxiliary database file if P1==1 or in an attached database if | 5190 ** auxiliary database file if P1==1 or in an attached database if |
| 5012 ** P1>1. Write the root page number of the new table into | 5191 ** P1>1. Write the root page number of the new table into |
| 5013 ** register P2 | 5192 ** register P2 |
| 5014 ** | 5193 ** |
| 5015 ** The difference between a table and an index is this: A table must | 5194 ** The difference between a table and an index is this: A table must |
| 5016 ** have a 4-byte integer key and can have arbitrary data. An index | 5195 ** have a 4-byte integer key and can have arbitrary data. An index |
| 5017 ** has an arbitrary key but no data. | 5196 ** has an arbitrary key but no data. |
| 5018 ** | 5197 ** |
| 5019 ** See also: CreateIndex | 5198 ** See also: CreateIndex |
| 5020 */ | 5199 */ |
| 5021 /* Opcode: CreateIndex P1 P2 * * * | 5200 /* Opcode: CreateIndex P1 P2 * * * |
| 5022 ** Synopsis: r[P2]=root iDb=P1 | 5201 ** Synopsis: r[P2]=root iDb=P1 |
| 5023 ** | 5202 ** |
| 5024 ** Allocate a new index in the main database file if P1==0 or in the | 5203 ** Allocate a new index in the main database file if P1==0 or in the |
| 5025 ** auxiliary database file if P1==1 or in an attached database if | 5204 ** auxiliary database file if P1==1 or in an attached database if |
| 5026 ** P1>1. Write the root page number of the new table into | 5205 ** P1>1. Write the root page number of the new table into |
| 5027 ** register P2. | 5206 ** register P2. |
| 5028 ** | 5207 ** |
| 5029 ** See documentation on OP_CreateTable for additional information. | 5208 ** See documentation on OP_CreateTable for additional information. |
| 5030 */ | 5209 */ |
| 5031 case OP_CreateIndex: /* out2-prerelease */ | 5210 case OP_CreateIndex: /* out2 */ |
| 5032 case OP_CreateTable: { /* out2-prerelease */ | 5211 case OP_CreateTable: { /* out2 */ |
| 5033 int pgno; | 5212 int pgno; |
| 5034 int flags; | 5213 int flags; |
| 5035 Db *pDb; | 5214 Db *pDb; |
| 5036 | 5215 |
| 5216 pOut = out2Prerelease(p, pOp); |
| 5037 pgno = 0; | 5217 pgno = 0; |
| 5038 assert( pOp->p1>=0 && pOp->p1<db->nDb ); | 5218 assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 5039 assert( DbMaskTest(p->btreeMask, pOp->p1) ); | 5219 assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 5040 assert( p->readOnly==0 ); | 5220 assert( p->readOnly==0 ); |
| 5041 pDb = &db->aDb[pOp->p1]; | 5221 pDb = &db->aDb[pOp->p1]; |
| 5042 assert( pDb->pBt!=0 ); | 5222 assert( pDb->pBt!=0 ); |
| 5043 if( pOp->opcode==OP_CreateTable ){ | 5223 if( pOp->opcode==OP_CreateTable ){ |
| 5044 /* flags = BTREE_INTKEY; */ | 5224 /* flags = BTREE_INTKEY; */ |
| 5045 flags = BTREE_INTKEY; | 5225 flags = BTREE_INTKEY; |
| 5046 }else{ | 5226 }else{ |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5252 */ | 5432 */ |
| 5253 case OP_RowSetRead: { /* jump, in1, out3 */ | 5433 case OP_RowSetRead: { /* jump, in1, out3 */ |
| 5254 i64 val; | 5434 i64 val; |
| 5255 | 5435 |
| 5256 pIn1 = &aMem[pOp->p1]; | 5436 pIn1 = &aMem[pOp->p1]; |
| 5257 if( (pIn1->flags & MEM_RowSet)==0 | 5437 if( (pIn1->flags & MEM_RowSet)==0 |
| 5258 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 | 5438 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 |
| 5259 ){ | 5439 ){ |
| 5260 /* The boolean index is empty */ | 5440 /* The boolean index is empty */ |
| 5261 sqlite3VdbeMemSetNull(pIn1); | 5441 sqlite3VdbeMemSetNull(pIn1); |
| 5262 pc = pOp->p2 - 1; | |
| 5263 VdbeBranchTaken(1,2); | 5442 VdbeBranchTaken(1,2); |
| 5443 goto jump_to_p2_and_check_for_interrupt; |
| 5264 }else{ | 5444 }else{ |
| 5265 /* A value was pulled from the index */ | 5445 /* A value was pulled from the index */ |
| 5446 VdbeBranchTaken(0,2); |
| 5266 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); | 5447 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); |
| 5267 VdbeBranchTaken(0,2); | |
| 5268 } | 5448 } |
| 5269 goto check_for_interrupt; | 5449 goto check_for_interrupt; |
| 5270 } | 5450 } |
| 5271 | 5451 |
| 5272 /* Opcode: RowSetTest P1 P2 P3 P4 | 5452 /* Opcode: RowSetTest P1 P2 P3 P4 |
| 5273 ** Synopsis: if r[P3] in rowset(P1) goto P2 | 5453 ** Synopsis: if r[P3] in rowset(P1) goto P2 |
| 5274 ** | 5454 ** |
| 5275 ** Register P3 is assumed to hold a 64-bit integer value. If register P1 | 5455 ** Register P3 is assumed to hold a 64-bit integer value. If register P1 |
| 5276 ** contains a RowSet object and that RowSet object contains | 5456 ** contains a RowSet object and that RowSet object contains |
| 5277 ** the value held in P3, jump to register P2. Otherwise, insert the | 5457 ** the value held in P3, jump to register P2. Otherwise, insert the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 5308 if( (pIn1->flags & MEM_RowSet)==0 ){ | 5488 if( (pIn1->flags & MEM_RowSet)==0 ){ |
| 5309 sqlite3VdbeMemSetRowSet(pIn1); | 5489 sqlite3VdbeMemSetRowSet(pIn1); |
| 5310 if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem; | 5490 if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem; |
| 5311 } | 5491 } |
| 5312 | 5492 |
| 5313 assert( pOp->p4type==P4_INT32 ); | 5493 assert( pOp->p4type==P4_INT32 ); |
| 5314 assert( iSet==-1 || iSet>=0 ); | 5494 assert( iSet==-1 || iSet>=0 ); |
| 5315 if( iSet ){ | 5495 if( iSet ){ |
| 5316 exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i); | 5496 exists = sqlite3RowSetTest(pIn1->u.pRowSet, iSet, pIn3->u.i); |
| 5317 VdbeBranchTaken(exists!=0,2); | 5497 VdbeBranchTaken(exists!=0,2); |
| 5318 if( exists ){ | 5498 if( exists ) goto jump_to_p2; |
| 5319 pc = pOp->p2 - 1; | |
| 5320 break; | |
| 5321 } | |
| 5322 } | 5499 } |
| 5323 if( iSet>=0 ){ | 5500 if( iSet>=0 ){ |
| 5324 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); | 5501 sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 5325 } | 5502 } |
| 5326 break; | 5503 break; |
| 5327 } | 5504 } |
| 5328 | 5505 |
| 5329 | 5506 |
| 5330 #ifndef SQLITE_OMIT_TRIGGER | 5507 #ifndef SQLITE_OMIT_TRIGGER |
| 5331 | 5508 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5370 ** single trigger all have the same value for the SubProgram.token | 5547 ** single trigger all have the same value for the SubProgram.token |
| 5371 ** variable. */ | 5548 ** variable. */ |
| 5372 if( pOp->p5 ){ | 5549 if( pOp->p5 ){ |
| 5373 t = pProgram->token; | 5550 t = pProgram->token; |
| 5374 for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent); | 5551 for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent); |
| 5375 if( pFrame ) break; | 5552 if( pFrame ) break; |
| 5376 } | 5553 } |
| 5377 | 5554 |
| 5378 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ | 5555 if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 5379 rc = SQLITE_ERROR; | 5556 rc = SQLITE_ERROR; |
| 5380 sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion"); | 5557 sqlite3VdbeError(p, "too many levels of trigger recursion"); |
| 5381 break; | 5558 break; |
| 5382 } | 5559 } |
| 5383 | 5560 |
| 5384 /* Register pRt is used to store the memory required to save the state | 5561 /* Register pRt is used to store the memory required to save the state |
| 5385 ** of the current program, and the memory required at runtime to execute | 5562 ** of the current program, and the memory required at runtime to execute |
| 5386 ** the trigger program. If this trigger has been fired before, then pRt | 5563 ** the trigger program. If this trigger has been fired before, then pRt |
| 5387 ** is already allocated. Otherwise, it must be initialized. */ | 5564 ** is already allocated. Otherwise, it must be initialized. */ |
| 5388 if( (pRt->flags&MEM_Frame)==0 ){ | 5565 if( (pRt->flags&MEM_Frame)==0 ){ |
| 5389 /* SubProgram.nMem is set to the number of memory cells used by the | 5566 /* SubProgram.nMem is set to the number of memory cells used by the |
| 5390 ** program stored in SubProgram.aOp. As well as these, one memory | 5567 ** program stored in SubProgram.aOp. As well as these, one memory |
| 5391 ** cell is required for each cursor used by the program. Set local | 5568 ** cell is required for each cursor used by the program. Set local |
| 5392 ** variable nMem (and later, VdbeFrame.nChildMem) to this value. | 5569 ** variable nMem (and later, VdbeFrame.nChildMem) to this value. |
| 5393 */ | 5570 */ |
| 5394 nMem = pProgram->nMem + pProgram->nCsr; | 5571 nMem = pProgram->nMem + pProgram->nCsr; |
| 5395 nByte = ROUND8(sizeof(VdbeFrame)) | 5572 nByte = ROUND8(sizeof(VdbeFrame)) |
| 5396 + nMem * sizeof(Mem) | 5573 + nMem * sizeof(Mem) |
| 5397 + pProgram->nCsr * sizeof(VdbeCursor *) | 5574 + pProgram->nCsr * sizeof(VdbeCursor *) |
| 5398 + pProgram->nOnce * sizeof(u8); | 5575 + pProgram->nOnce * sizeof(u8); |
| 5399 pFrame = sqlite3DbMallocZero(db, nByte); | 5576 pFrame = sqlite3DbMallocZero(db, nByte); |
| 5400 if( !pFrame ){ | 5577 if( !pFrame ){ |
| 5401 goto no_mem; | 5578 goto no_mem; |
| 5402 } | 5579 } |
| 5403 sqlite3VdbeMemRelease(pRt); | 5580 sqlite3VdbeMemRelease(pRt); |
| 5404 pRt->flags = MEM_Frame; | 5581 pRt->flags = MEM_Frame; |
| 5405 pRt->u.pFrame = pFrame; | 5582 pRt->u.pFrame = pFrame; |
| 5406 | 5583 |
| 5407 pFrame->v = p; | 5584 pFrame->v = p; |
| 5408 pFrame->nChildMem = nMem; | 5585 pFrame->nChildMem = nMem; |
| 5409 pFrame->nChildCsr = pProgram->nCsr; | 5586 pFrame->nChildCsr = pProgram->nCsr; |
| 5410 pFrame->pc = pc; | 5587 pFrame->pc = (int)(pOp - aOp); |
| 5411 pFrame->aMem = p->aMem; | 5588 pFrame->aMem = p->aMem; |
| 5412 pFrame->nMem = p->nMem; | 5589 pFrame->nMem = p->nMem; |
| 5413 pFrame->apCsr = p->apCsr; | 5590 pFrame->apCsr = p->apCsr; |
| 5414 pFrame->nCursor = p->nCursor; | 5591 pFrame->nCursor = p->nCursor; |
| 5415 pFrame->aOp = p->aOp; | 5592 pFrame->aOp = p->aOp; |
| 5416 pFrame->nOp = p->nOp; | 5593 pFrame->nOp = p->nOp; |
| 5417 pFrame->token = pProgram->token; | 5594 pFrame->token = pProgram->token; |
| 5418 pFrame->aOnceFlag = p->aOnceFlag; | 5595 pFrame->aOnceFlag = p->aOnceFlag; |
| 5419 pFrame->nOnceFlag = p->nOnceFlag; | 5596 pFrame->nOnceFlag = p->nOnceFlag; |
| 5597 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 5598 pFrame->anExec = p->anExec; |
| 5599 #endif |
| 5420 | 5600 |
| 5421 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; | 5601 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; |
| 5422 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ | 5602 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ |
| 5423 pMem->flags = MEM_Undefined; | 5603 pMem->flags = MEM_Undefined; |
| 5424 pMem->db = db; | 5604 pMem->db = db; |
| 5425 } | 5605 } |
| 5426 }else{ | 5606 }else{ |
| 5427 pFrame = pRt->u.pFrame; | 5607 pFrame = pRt->u.pFrame; |
| 5428 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); | 5608 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); |
| 5429 assert( pProgram->nCsr==pFrame->nChildCsr ); | 5609 assert( pProgram->nCsr==pFrame->nChildCsr ); |
| 5430 assert( pc==pFrame->pc ); | 5610 assert( (int)(pOp - aOp)==pFrame->pc ); |
| 5431 } | 5611 } |
| 5432 | 5612 |
| 5433 p->nFrame++; | 5613 p->nFrame++; |
| 5434 pFrame->pParent = p->pFrame; | 5614 pFrame->pParent = p->pFrame; |
| 5435 pFrame->lastRowid = lastRowid; | 5615 pFrame->lastRowid = lastRowid; |
| 5436 pFrame->nChange = p->nChange; | 5616 pFrame->nChange = p->nChange; |
| 5617 pFrame->nDbChange = p->db->nChange; |
| 5437 p->nChange = 0; | 5618 p->nChange = 0; |
| 5438 p->pFrame = pFrame; | 5619 p->pFrame = pFrame; |
| 5439 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; | 5620 p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; |
| 5440 p->nMem = pFrame->nChildMem; | 5621 p->nMem = pFrame->nChildMem; |
| 5441 p->nCursor = (u16)pFrame->nChildCsr; | 5622 p->nCursor = (u16)pFrame->nChildCsr; |
| 5442 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; | 5623 p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 5443 p->aOp = aOp = pProgram->aOp; | 5624 p->aOp = aOp = pProgram->aOp; |
| 5444 p->nOp = pProgram->nOp; | 5625 p->nOp = pProgram->nOp; |
| 5445 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; | 5626 p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 5446 p->nOnceFlag = pProgram->nOnce; | 5627 p->nOnceFlag = pProgram->nOnce; |
| 5447 pc = -1; | 5628 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 5629 p->anExec = 0; |
| 5630 #endif |
| 5631 pOp = &aOp[-1]; |
| 5448 memset(p->aOnceFlag, 0, p->nOnceFlag); | 5632 memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 5449 | 5633 |
| 5450 break; | 5634 break; |
| 5451 } | 5635 } |
| 5452 | 5636 |
| 5453 /* Opcode: Param P1 P2 * * * | 5637 /* Opcode: Param P1 P2 * * * |
| 5454 ** | 5638 ** |
| 5455 ** This opcode is only ever present in sub-programs called via the | 5639 ** This opcode is only ever present in sub-programs called via the |
| 5456 ** OP_Program instruction. Copy a value currently stored in a memory | 5640 ** OP_Program instruction. Copy a value currently stored in a memory |
| 5457 ** cell of the calling (parent) frame to cell P2 in the current frames | 5641 ** cell of the calling (parent) frame to cell P2 in the current frames |
| 5458 ** address space. This is used by trigger programs to access the new.* | 5642 ** address space. This is used by trigger programs to access the new.* |
| 5459 ** and old.* values. | 5643 ** and old.* values. |
| 5460 ** | 5644 ** |
| 5461 ** The address of the cell in the parent frame is determined by adding | 5645 ** The address of the cell in the parent frame is determined by adding |
| 5462 ** the value of the P1 argument to the value of the P1 argument to the | 5646 ** the value of the P1 argument to the value of the P1 argument to the |
| 5463 ** calling OP_Program instruction. | 5647 ** calling OP_Program instruction. |
| 5464 */ | 5648 */ |
| 5465 case OP_Param: { /* out2-prerelease */ | 5649 case OP_Param: { /* out2 */ |
| 5466 VdbeFrame *pFrame; | 5650 VdbeFrame *pFrame; |
| 5467 Mem *pIn; | 5651 Mem *pIn; |
| 5652 pOut = out2Prerelease(p, pOp); |
| 5468 pFrame = p->pFrame; | 5653 pFrame = p->pFrame; |
| 5469 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; | 5654 pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; |
| 5470 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); | 5655 sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); |
| 5471 break; | 5656 break; |
| 5472 } | 5657 } |
| 5473 | 5658 |
| 5474 #endif /* #ifndef SQLITE_OMIT_TRIGGER */ | 5659 #endif /* #ifndef SQLITE_OMIT_TRIGGER */ |
| 5475 | 5660 |
| 5476 #ifndef SQLITE_OMIT_FOREIGN_KEY | 5661 #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 5477 /* Opcode: FkCounter P1 P2 * * * | 5662 /* Opcode: FkCounter P1 P2 * * * |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5501 ** instruction. | 5686 ** instruction. |
| 5502 ** | 5687 ** |
| 5503 ** If P1 is non-zero, then the jump is taken if the database constraint-counter | 5688 ** If P1 is non-zero, then the jump is taken if the database constraint-counter |
| 5504 ** is zero (the one that counts deferred constraint violations). If P1 is | 5689 ** is zero (the one that counts deferred constraint violations). If P1 is |
| 5505 ** zero, the jump is taken if the statement constraint-counter is zero | 5690 ** zero, the jump is taken if the statement constraint-counter is zero |
| 5506 ** (immediate foreign key constraint violations). | 5691 ** (immediate foreign key constraint violations). |
| 5507 */ | 5692 */ |
| 5508 case OP_FkIfZero: { /* jump */ | 5693 case OP_FkIfZero: { /* jump */ |
| 5509 if( pOp->p1 ){ | 5694 if( pOp->p1 ){ |
| 5510 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2); | 5695 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2); |
| 5511 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; | 5696 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; |
| 5512 }else{ | 5697 }else{ |
| 5513 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2); | 5698 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2); |
| 5514 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1; | 5699 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) goto jump_to_p2; |
| 5515 } | 5700 } |
| 5516 break; | 5701 break; |
| 5517 } | 5702 } |
| 5518 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */ | 5703 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */ |
| 5519 | 5704 |
| 5520 #ifndef SQLITE_OMIT_AUTOINCREMENT | 5705 #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 5521 /* Opcode: MemMax P1 P2 * * * | 5706 /* Opcode: MemMax P1 P2 * * * |
| 5522 ** Synopsis: r[P1]=max(r[P1],r[P2]) | 5707 ** Synopsis: r[P1]=max(r[P1],r[P2]) |
| 5523 ** | 5708 ** |
| 5524 ** P1 is a register in the root frame of this VM (the root frame is | 5709 ** P1 is a register in the root frame of this VM (the root frame is |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5541 sqlite3VdbeMemIntegerify(pIn1); | 5726 sqlite3VdbeMemIntegerify(pIn1); |
| 5542 pIn2 = &aMem[pOp->p2]; | 5727 pIn2 = &aMem[pOp->p2]; |
| 5543 sqlite3VdbeMemIntegerify(pIn2); | 5728 sqlite3VdbeMemIntegerify(pIn2); |
| 5544 if( pIn1->u.i<pIn2->u.i){ | 5729 if( pIn1->u.i<pIn2->u.i){ |
| 5545 pIn1->u.i = pIn2->u.i; | 5730 pIn1->u.i = pIn2->u.i; |
| 5546 } | 5731 } |
| 5547 break; | 5732 break; |
| 5548 } | 5733 } |
| 5549 #endif /* SQLITE_OMIT_AUTOINCREMENT */ | 5734 #endif /* SQLITE_OMIT_AUTOINCREMENT */ |
| 5550 | 5735 |
| 5551 /* Opcode: IfPos P1 P2 * * * | 5736 /* Opcode: IfPos P1 P2 P3 * * |
| 5552 ** Synopsis: if r[P1]>0 goto P2 | 5737 ** Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 |
| 5553 ** | 5738 ** |
| 5554 ** If the value of register P1 is 1 or greater, jump to P2. | 5739 ** Register P1 must contain an integer. |
| 5740 ** If the value of register P1 is 1 or greater, subtract P3 from the |
| 5741 ** value in P1 and jump to P2. |
| 5555 ** | 5742 ** |
| 5556 ** It is illegal to use this instruction on a register that does | 5743 ** If the initial value of register P1 is less than 1, then the |
| 5557 ** not contain an integer. An assertion fault will result if you try. | 5744 ** value is unchanged and control passes through to the next instruction. |
| 5558 */ | 5745 */ |
| 5559 case OP_IfPos: { /* jump, in1 */ | 5746 case OP_IfPos: { /* jump, in1 */ |
| 5560 pIn1 = &aMem[pOp->p1]; | 5747 pIn1 = &aMem[pOp->p1]; |
| 5561 assert( pIn1->flags&MEM_Int ); | 5748 assert( pIn1->flags&MEM_Int ); |
| 5562 VdbeBranchTaken( pIn1->u.i>0, 2); | 5749 VdbeBranchTaken( pIn1->u.i>0, 2); |
| 5563 if( pIn1->u.i>0 ){ | 5750 if( pIn1->u.i>0 ){ |
| 5564 pc = pOp->p2 - 1; | 5751 pIn1->u.i -= pOp->p3; |
| 5752 goto jump_to_p2; |
| 5565 } | 5753 } |
| 5566 break; | 5754 break; |
| 5567 } | 5755 } |
| 5568 | 5756 |
| 5569 /* Opcode: IfNeg P1 P2 P3 * * | 5757 /* Opcode: SetIfNotPos P1 P2 P3 * * |
| 5570 ** Synopsis: r[P1]+=P3, if r[P1]<0 goto P2 | 5758 ** Synopsis: if r[P1]<=0 then r[P2]=P3 |
| 5571 ** | 5759 ** |
| 5572 ** Register P1 must contain an integer. Add literal P3 to the value in | 5760 ** Register P1 must contain an integer. |
| 5573 ** register P1 then if the value of register P1 is less than zero, jump to P2. | 5761 ** If the value of register P1 is not positive (if it is less than 1) then |
| 5762 ** set the value of register P2 to be the integer P3. |
| 5574 */ | 5763 */ |
| 5575 case OP_IfNeg: { /* jump, in1 */ | 5764 case OP_SetIfNotPos: { /* in1, in2 */ |
| 5576 pIn1 = &aMem[pOp->p1]; | 5765 pIn1 = &aMem[pOp->p1]; |
| 5577 assert( pIn1->flags&MEM_Int ); | 5766 assert( pIn1->flags&MEM_Int ); |
| 5578 pIn1->u.i += pOp->p3; | 5767 if( pIn1->u.i<=0 ){ |
| 5579 VdbeBranchTaken(pIn1->u.i<0, 2); | 5768 pOut = out2Prerelease(p, pOp); |
| 5580 if( pIn1->u.i<0 ){ | 5769 pOut->u.i = pOp->p3; |
| 5581 pc = pOp->p2 - 1; | |
| 5582 } | 5770 } |
| 5583 break; | 5771 break; |
| 5584 } | 5772 } |
| 5585 | 5773 |
| 5586 /* Opcode: IfZero P1 P2 P3 * * | 5774 /* Opcode: IfNotZero P1 P2 P3 * * |
| 5587 ** Synopsis: r[P1]+=P3, if r[P1]==0 goto P2 | 5775 ** Synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 |
| 5588 ** | 5776 ** |
| 5589 ** The register P1 must contain an integer. Add literal P3 to the | 5777 ** Register P1 must contain an integer. If the content of register P1 is |
| 5590 ** value in register P1. If the result is exactly 0, jump to P2. | 5778 ** initially nonzero, then subtract P3 from the value in register P1 and |
| 5779 ** jump to P2. If register P1 is initially zero, leave it unchanged |
| 5780 ** and fall through. |
| 5591 */ | 5781 */ |
| 5592 case OP_IfZero: { /* jump, in1 */ | 5782 case OP_IfNotZero: { /* jump, in1 */ |
| 5593 pIn1 = &aMem[pOp->p1]; | 5783 pIn1 = &aMem[pOp->p1]; |
| 5594 assert( pIn1->flags&MEM_Int ); | 5784 assert( pIn1->flags&MEM_Int ); |
| 5595 pIn1->u.i += pOp->p3; | 5785 VdbeBranchTaken(pIn1->u.i<0, 2); |
| 5596 VdbeBranchTaken(pIn1->u.i==0, 2); | 5786 if( pIn1->u.i ){ |
| 5597 if( pIn1->u.i==0 ){ | 5787 pIn1->u.i -= pOp->p3; |
| 5598 pc = pOp->p2 - 1; | 5788 goto jump_to_p2; |
| 5599 } | 5789 } |
| 5600 break; | 5790 break; |
| 5601 } | 5791 } |
| 5602 | 5792 |
| 5793 /* Opcode: DecrJumpZero P1 P2 * * * |
| 5794 ** Synopsis: if (--r[P1])==0 goto P2 |
| 5795 ** |
| 5796 ** Register P1 must hold an integer. Decrement the value in register P1 |
| 5797 ** then jump to P2 if the new value is exactly zero. |
| 5798 */ |
| 5799 case OP_DecrJumpZero: { /* jump, in1 */ |
| 5800 pIn1 = &aMem[pOp->p1]; |
| 5801 assert( pIn1->flags&MEM_Int ); |
| 5802 pIn1->u.i--; |
| 5803 VdbeBranchTaken(pIn1->u.i==0, 2); |
| 5804 if( pIn1->u.i==0 ) goto jump_to_p2; |
| 5805 break; |
| 5806 } |
| 5807 |
| 5808 |
| 5809 /* Opcode: JumpZeroIncr P1 P2 * * * |
| 5810 ** Synopsis: if (r[P1]++)==0 ) goto P2 |
| 5811 ** |
| 5812 ** The register P1 must contain an integer. If register P1 is initially |
| 5813 ** zero, then jump to P2. Increment register P1 regardless of whether or |
| 5814 ** not the jump is taken. |
| 5815 */ |
| 5816 case OP_JumpZeroIncr: { /* jump, in1 */ |
| 5817 pIn1 = &aMem[pOp->p1]; |
| 5818 assert( pIn1->flags&MEM_Int ); |
| 5819 VdbeBranchTaken(pIn1->u.i==0, 2); |
| 5820 if( (pIn1->u.i++)==0 ) goto jump_to_p2; |
| 5821 break; |
| 5822 } |
| 5823 |
| 5824 /* Opcode: AggStep0 * P2 P3 P4 P5 |
| 5825 ** Synopsis: accum=r[P3] step(r[P2@P5]) |
| 5826 ** |
| 5827 ** Execute the step function for an aggregate. The |
| 5828 ** function has P5 arguments. P4 is a pointer to the FuncDef |
| 5829 ** structure that specifies the function. Register P3 is the |
| 5830 ** accumulator. |
| 5831 ** |
| 5832 ** The P5 arguments are taken from register P2 and its |
| 5833 ** successors. |
| 5834 */ |
| 5603 /* Opcode: AggStep * P2 P3 P4 P5 | 5835 /* Opcode: AggStep * P2 P3 P4 P5 |
| 5604 ** Synopsis: accum=r[P3] step(r[P2@P5]) | 5836 ** Synopsis: accum=r[P3] step(r[P2@P5]) |
| 5605 ** | 5837 ** |
| 5606 ** Execute the step function for an aggregate. The | 5838 ** Execute the step function for an aggregate. The |
| 5607 ** function has P5 arguments. P4 is a pointer to the FuncDef | 5839 ** function has P5 arguments. P4 is a pointer to an sqlite3_context |
| 5608 ** structure that specifies the function. Use register | 5840 ** object that is used to run the function. Register P3 is |
| 5609 ** P3 as the accumulator. | 5841 ** as the accumulator. |
| 5610 ** | 5842 ** |
| 5611 ** The P5 arguments are taken from register P2 and its | 5843 ** The P5 arguments are taken from register P2 and its |
| 5612 ** successors. | 5844 ** successors. |
| 5845 ** |
| 5846 ** This opcode is initially coded as OP_AggStep0. On first evaluation, |
| 5847 ** the FuncDef stored in P4 is converted into an sqlite3_context and |
| 5848 ** the opcode is changed. In this way, the initialization of the |
| 5849 ** sqlite3_context only happens once, instead of on each call to the |
| 5850 ** step function. |
| 5613 */ | 5851 */ |
| 5852 case OP_AggStep0: { |
| 5853 int n; |
| 5854 sqlite3_context *pCtx; |
| 5855 |
| 5856 assert( pOp->p4type==P4_FUNCDEF ); |
| 5857 n = pOp->p5; |
| 5858 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 5859 assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) ); |
| 5860 assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n ); |
| 5861 pCtx = sqlite3DbMallocRaw(db, sizeof(*pCtx) + (n-1)*sizeof(sqlite3_value*)); |
| 5862 if( pCtx==0 ) goto no_mem; |
| 5863 pCtx->pMem = 0; |
| 5864 pCtx->pFunc = pOp->p4.pFunc; |
| 5865 pCtx->iOp = (int)(pOp - aOp); |
| 5866 pCtx->pVdbe = p; |
| 5867 pCtx->argc = n; |
| 5868 pOp->p4type = P4_FUNCCTX; |
| 5869 pOp->p4.pCtx = pCtx; |
| 5870 pOp->opcode = OP_AggStep; |
| 5871 /* Fall through into OP_AggStep */ |
| 5872 } |
| 5614 case OP_AggStep: { | 5873 case OP_AggStep: { |
| 5615 int n; | |
| 5616 int i; | 5874 int i; |
| 5875 sqlite3_context *pCtx; |
| 5617 Mem *pMem; | 5876 Mem *pMem; |
| 5618 Mem *pRec; | |
| 5619 Mem t; | 5877 Mem t; |
| 5620 sqlite3_context ctx; | |
| 5621 sqlite3_value **apVal; | |
| 5622 | 5878 |
| 5623 n = pOp->p5; | 5879 assert( pOp->p4type==P4_FUNCCTX ); |
| 5624 assert( n>=0 ); | 5880 pCtx = pOp->p4.pCtx; |
| 5625 pRec = &aMem[pOp->p2]; | 5881 pMem = &aMem[pOp->p3]; |
| 5626 apVal = p->apArg; | 5882 |
| 5627 assert( apVal || n==0 ); | 5883 /* If this function is inside of a trigger, the register array in aMem[] |
| 5628 for(i=0; i<n; i++, pRec++){ | 5884 ** might change from one evaluation to the next. The next block of code |
| 5629 assert( memIsValid(pRec) ); | 5885 ** checks to see if the register array has changed, and if so it |
| 5630 apVal[i] = pRec; | 5886 ** reinitializes the relavant parts of the sqlite3_context object */ |
| 5631 memAboutToChange(p, pRec); | 5887 if( pCtx->pMem != pMem ){ |
| 5888 pCtx->pMem = pMem; |
| 5889 for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; |
| 5632 } | 5890 } |
| 5633 ctx.pFunc = pOp->p4.pFunc; | 5891 |
| 5634 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); | 5892 #ifdef SQLITE_DEBUG |
| 5635 ctx.pMem = pMem = &aMem[pOp->p3]; | 5893 for(i=0; i<pCtx->argc; i++){ |
| 5894 assert( memIsValid(pCtx->argv[i]) ); |
| 5895 REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]); |
| 5896 } |
| 5897 #endif |
| 5898 |
| 5636 pMem->n++; | 5899 pMem->n++; |
| 5637 sqlite3VdbeMemInit(&t, db, MEM_Null); | 5900 sqlite3VdbeMemInit(&t, db, MEM_Null); |
| 5638 ctx.pOut = &t; | 5901 pCtx->pOut = &t; |
| 5639 ctx.isError = 0; | 5902 pCtx->fErrorOrAux = 0; |
| 5640 ctx.pVdbe = p; | 5903 pCtx->skipFlag = 0; |
| 5641 ctx.iOp = pc; | 5904 (pCtx->pFunc->xStep)(pCtx,pCtx->argc,pCtx->argv); /* IMP: R-24505-23230 */ |
| 5642 ctx.skipFlag = 0; | 5905 if( pCtx->fErrorOrAux ){ |
| 5643 (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ | 5906 if( pCtx->isError ){ |
| 5644 if( ctx.isError ){ | 5907 sqlite3VdbeError(p, "%s", sqlite3_value_text(&t)); |
| 5645 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&t)); | 5908 rc = pCtx->isError; |
| 5646 rc = ctx.isError; | 5909 } |
| 5910 sqlite3VdbeMemRelease(&t); |
| 5911 }else{ |
| 5912 assert( t.flags==MEM_Null ); |
| 5647 } | 5913 } |
| 5648 if( ctx.skipFlag ){ | 5914 if( pCtx->skipFlag ){ |
| 5649 assert( pOp[-1].opcode==OP_CollSeq ); | 5915 assert( pOp[-1].opcode==OP_CollSeq ); |
| 5650 i = pOp[-1].p1; | 5916 i = pOp[-1].p1; |
| 5651 if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); | 5917 if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); |
| 5652 } | 5918 } |
| 5653 sqlite3VdbeMemRelease(&t); | |
| 5654 break; | 5919 break; |
| 5655 } | 5920 } |
| 5656 | 5921 |
| 5657 /* Opcode: AggFinal P1 P2 * P4 * | 5922 /* Opcode: AggFinal P1 P2 * P4 * |
| 5658 ** Synopsis: accum=r[P1] N=P2 | 5923 ** Synopsis: accum=r[P1] N=P2 |
| 5659 ** | 5924 ** |
| 5660 ** Execute the finalizer function for an aggregate. P1 is | 5925 ** Execute the finalizer function for an aggregate. P1 is |
| 5661 ** the memory location that is the accumulator for the aggregate. | 5926 ** the memory location that is the accumulator for the aggregate. |
| 5662 ** | 5927 ** |
| 5663 ** P2 is the number of arguments that the step function takes and | 5928 ** P2 is the number of arguments that the step function takes and |
| 5664 ** P4 is a pointer to the FuncDef for this function. The P2 | 5929 ** P4 is a pointer to the FuncDef for this function. The P2 |
| 5665 ** argument is not used by this opcode. It is only there to disambiguate | 5930 ** argument is not used by this opcode. It is only there to disambiguate |
| 5666 ** functions that can take varying numbers of arguments. The | 5931 ** functions that can take varying numbers of arguments. The |
| 5667 ** P4 argument is only needed for the degenerate case where | 5932 ** P4 argument is only needed for the degenerate case where |
| 5668 ** the step function was not previously called. | 5933 ** the step function was not previously called. |
| 5669 */ | 5934 */ |
| 5670 case OP_AggFinal: { | 5935 case OP_AggFinal: { |
| 5671 Mem *pMem; | 5936 Mem *pMem; |
| 5672 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); | 5937 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 5673 pMem = &aMem[pOp->p1]; | 5938 pMem = &aMem[pOp->p1]; |
| 5674 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); | 5939 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 5675 rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc); | 5940 rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc); |
| 5676 if( rc ){ | 5941 if( rc ){ |
| 5677 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem)); | 5942 sqlite3VdbeError(p, "%s", sqlite3_value_text(pMem)); |
| 5678 } | 5943 } |
| 5679 sqlite3VdbeChangeEncoding(pMem, encoding); | 5944 sqlite3VdbeChangeEncoding(pMem, encoding); |
| 5680 UPDATE_MAX_BLOBSIZE(pMem); | 5945 UPDATE_MAX_BLOBSIZE(pMem); |
| 5681 if( sqlite3VdbeMemTooBig(pMem) ){ | 5946 if( sqlite3VdbeMemTooBig(pMem) ){ |
| 5682 goto too_big; | 5947 goto too_big; |
| 5683 } | 5948 } |
| 5684 break; | 5949 break; |
| 5685 } | 5950 } |
| 5686 | 5951 |
| 5687 #ifndef SQLITE_OMIT_WAL | 5952 #ifndef SQLITE_OMIT_WAL |
| 5688 /* Opcode: Checkpoint P1 P2 P3 * * | 5953 /* Opcode: Checkpoint P1 P2 P3 * * |
| 5689 ** | 5954 ** |
| 5690 ** Checkpoint database P1. This is a no-op if P1 is not currently in | 5955 ** Checkpoint database P1. This is a no-op if P1 is not currently in |
| 5691 ** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL | 5956 ** WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL, |
| 5692 ** or RESTART. Write 1 or 0 into mem[P3] if the checkpoint returns | 5957 ** RESTART, or TRUNCATE. Write 1 or 0 into mem[P3] if the checkpoint returns |
| 5693 ** SQLITE_BUSY or not, respectively. Write the number of pages in the | 5958 ** SQLITE_BUSY or not, respectively. Write the number of pages in the |
| 5694 ** WAL after the checkpoint into mem[P3+1] and the number of pages | 5959 ** WAL after the checkpoint into mem[P3+1] and the number of pages |
| 5695 ** in the WAL that have been checkpointed after the checkpoint | 5960 ** in the WAL that have been checkpointed after the checkpoint |
| 5696 ** completes into mem[P3+2]. However on an error, mem[P3+1] and | 5961 ** completes into mem[P3+2]. However on an error, mem[P3+1] and |
| 5697 ** mem[P3+2] are initialized to -1. | 5962 ** mem[P3+2] are initialized to -1. |
| 5698 */ | 5963 */ |
| 5699 case OP_Checkpoint: { | 5964 case OP_Checkpoint: { |
| 5700 int i; /* Loop counter */ | 5965 int i; /* Loop counter */ |
| 5701 int aRes[3]; /* Results */ | 5966 int aRes[3]; /* Results */ |
| 5702 Mem *pMem; /* Write results here */ | 5967 Mem *pMem; /* Write results here */ |
| 5703 | 5968 |
| 5704 assert( p->readOnly==0 ); | 5969 assert( p->readOnly==0 ); |
| 5705 aRes[0] = 0; | 5970 aRes[0] = 0; |
| 5706 aRes[1] = aRes[2] = -1; | 5971 aRes[1] = aRes[2] = -1; |
| 5707 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE | 5972 assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 5708 || pOp->p2==SQLITE_CHECKPOINT_FULL | 5973 || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 5709 || pOp->p2==SQLITE_CHECKPOINT_RESTART | 5974 || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 5975 || pOp->p2==SQLITE_CHECKPOINT_TRUNCATE |
| 5710 ); | 5976 ); |
| 5711 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); | 5977 rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); |
| 5712 if( rc==SQLITE_BUSY ){ | 5978 if( rc==SQLITE_BUSY ){ |
| 5713 rc = SQLITE_OK; | 5979 rc = SQLITE_OK; |
| 5714 aRes[0] = 1; | 5980 aRes[0] = 1; |
| 5715 } | 5981 } |
| 5716 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){ | 5982 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){ |
| 5717 sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]); | 5983 sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]); |
| 5718 } | 5984 } |
| 5719 break; | 5985 break; |
| 5720 }; | 5986 }; |
| 5721 #endif | 5987 #endif |
| 5722 | 5988 |
| 5723 #ifndef SQLITE_OMIT_PRAGMA | 5989 #ifndef SQLITE_OMIT_PRAGMA |
| 5724 /* Opcode: JournalMode P1 P2 P3 * * | 5990 /* Opcode: JournalMode P1 P2 P3 * * |
| 5725 ** | 5991 ** |
| 5726 ** Change the journal mode of database P1 to P3. P3 must be one of the | 5992 ** Change the journal mode of database P1 to P3. P3 must be one of the |
| 5727 ** PAGER_JOURNALMODE_XXX values. If changing between the various rollback | 5993 ** PAGER_JOURNALMODE_XXX values. If changing between the various rollback |
| 5728 ** modes (delete, truncate, persist, off and memory), this is a simple | 5994 ** modes (delete, truncate, persist, off and memory), this is a simple |
| 5729 ** operation. No IO is required. | 5995 ** operation. No IO is required. |
| 5730 ** | 5996 ** |
| 5731 ** If changing into or out of WAL mode the procedure is more complicated. | 5997 ** If changing into or out of WAL mode the procedure is more complicated. |
| 5732 ** | 5998 ** |
| 5733 ** Write a string containing the final journal-mode to register P2. | 5999 ** Write a string containing the final journal-mode to register P2. |
| 5734 */ | 6000 */ |
| 5735 case OP_JournalMode: { /* out2-prerelease */ | 6001 case OP_JournalMode: { /* out2 */ |
| 5736 Btree *pBt; /* Btree to change journal mode of */ | 6002 Btree *pBt; /* Btree to change journal mode of */ |
| 5737 Pager *pPager; /* Pager associated with pBt */ | 6003 Pager *pPager; /* Pager associated with pBt */ |
| 5738 int eNew; /* New journal mode */ | 6004 int eNew; /* New journal mode */ |
| 5739 int eOld; /* The old journal mode */ | 6005 int eOld; /* The old journal mode */ |
| 5740 #ifndef SQLITE_OMIT_WAL | 6006 #ifndef SQLITE_OMIT_WAL |
| 5741 const char *zFilename; /* Name of database file for pPager */ | 6007 const char *zFilename; /* Name of database file for pPager */ |
| 5742 #endif | 6008 #endif |
| 5743 | 6009 |
| 6010 pOut = out2Prerelease(p, pOp); |
| 5744 eNew = pOp->p3; | 6011 eNew = pOp->p3; |
| 5745 assert( eNew==PAGER_JOURNALMODE_DELETE | 6012 assert( eNew==PAGER_JOURNALMODE_DELETE |
| 5746 || eNew==PAGER_JOURNALMODE_TRUNCATE | 6013 || eNew==PAGER_JOURNALMODE_TRUNCATE |
| 5747 || eNew==PAGER_JOURNALMODE_PERSIST | 6014 || eNew==PAGER_JOURNALMODE_PERSIST |
| 5748 || eNew==PAGER_JOURNALMODE_OFF | 6015 || eNew==PAGER_JOURNALMODE_OFF |
| 5749 || eNew==PAGER_JOURNALMODE_MEMORY | 6016 || eNew==PAGER_JOURNALMODE_MEMORY |
| 5750 || eNew==PAGER_JOURNALMODE_WAL | 6017 || eNew==PAGER_JOURNALMODE_WAL |
| 5751 || eNew==PAGER_JOURNALMODE_QUERY | 6018 || eNew==PAGER_JOURNALMODE_QUERY |
| 5752 ); | 6019 ); |
| 5753 assert( pOp->p1>=0 && pOp->p1<db->nDb ); | 6020 assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5770 || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */ | 6037 || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */ |
| 5771 ){ | 6038 ){ |
| 5772 eNew = eOld; | 6039 eNew = eOld; |
| 5773 } | 6040 } |
| 5774 | 6041 |
| 5775 if( (eNew!=eOld) | 6042 if( (eNew!=eOld) |
| 5776 && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL) | 6043 && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL) |
| 5777 ){ | 6044 ){ |
| 5778 if( !db->autoCommit || db->nVdbeRead>1 ){ | 6045 if( !db->autoCommit || db->nVdbeRead>1 ){ |
| 5779 rc = SQLITE_ERROR; | 6046 rc = SQLITE_ERROR; |
| 5780 sqlite3SetString(&p->zErrMsg, db, | 6047 sqlite3VdbeError(p, |
| 5781 "cannot change %s wal mode from within a transaction", | 6048 "cannot change %s wal mode from within a transaction", |
| 5782 (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") | 6049 (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") |
| 5783 ); | 6050 ); |
| 5784 break; | 6051 break; |
| 5785 }else{ | 6052 }else{ |
| 5786 | 6053 |
| 5787 if( eOld==PAGER_JOURNALMODE_WAL ){ | 6054 if( eOld==PAGER_JOURNALMODE_WAL ){ |
| 5788 /* If leaving WAL mode, close the log file. If successful, the call | 6055 /* If leaving WAL mode, close the log file. If successful, the call |
| 5789 ** to PagerCloseWal() checkpoints and deletes the write-ahead-log | 6056 ** to PagerCloseWal() checkpoints and deletes the write-ahead-log |
| 5790 ** file. An EXCLUSIVE lock may still be held on the database file | 6057 ** file. An EXCLUSIVE lock may still be held on the database file |
| (...skipping 18 matching lines...) Expand all Loading... |
| 5809 } | 6076 } |
| 5810 } | 6077 } |
| 5811 } | 6078 } |
| 5812 #endif /* ifndef SQLITE_OMIT_WAL */ | 6079 #endif /* ifndef SQLITE_OMIT_WAL */ |
| 5813 | 6080 |
| 5814 if( rc ){ | 6081 if( rc ){ |
| 5815 eNew = eOld; | 6082 eNew = eOld; |
| 5816 } | 6083 } |
| 5817 eNew = sqlite3PagerSetJournalMode(pPager, eNew); | 6084 eNew = sqlite3PagerSetJournalMode(pPager, eNew); |
| 5818 | 6085 |
| 5819 pOut = &aMem[pOp->p2]; | |
| 5820 pOut->flags = MEM_Str|MEM_Static|MEM_Term; | 6086 pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 5821 pOut->z = (char *)sqlite3JournalModename(eNew); | 6087 pOut->z = (char *)sqlite3JournalModename(eNew); |
| 5822 pOut->n = sqlite3Strlen30(pOut->z); | 6088 pOut->n = sqlite3Strlen30(pOut->z); |
| 5823 pOut->enc = SQLITE_UTF8; | 6089 pOut->enc = SQLITE_UTF8; |
| 5824 sqlite3VdbeChangeEncoding(pOut, encoding); | 6090 sqlite3VdbeChangeEncoding(pOut, encoding); |
| 5825 break; | 6091 break; |
| 5826 }; | 6092 }; |
| 5827 #endif /* SQLITE_OMIT_PRAGMA */ | 6093 #endif /* SQLITE_OMIT_PRAGMA */ |
| 5828 | 6094 |
| 5829 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH) | 6095 #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5850 case OP_IncrVacuum: { /* jump */ | 6116 case OP_IncrVacuum: { /* jump */ |
| 5851 Btree *pBt; | 6117 Btree *pBt; |
| 5852 | 6118 |
| 5853 assert( pOp->p1>=0 && pOp->p1<db->nDb ); | 6119 assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 5854 assert( DbMaskTest(p->btreeMask, pOp->p1) ); | 6120 assert( DbMaskTest(p->btreeMask, pOp->p1) ); |
| 5855 assert( p->readOnly==0 ); | 6121 assert( p->readOnly==0 ); |
| 5856 pBt = db->aDb[pOp->p1].pBt; | 6122 pBt = db->aDb[pOp->p1].pBt; |
| 5857 rc = sqlite3BtreeIncrVacuum(pBt); | 6123 rc = sqlite3BtreeIncrVacuum(pBt); |
| 5858 VdbeBranchTaken(rc==SQLITE_DONE,2); | 6124 VdbeBranchTaken(rc==SQLITE_DONE,2); |
| 5859 if( rc==SQLITE_DONE ){ | 6125 if( rc==SQLITE_DONE ){ |
| 5860 pc = pOp->p2 - 1; | |
| 5861 rc = SQLITE_OK; | 6126 rc = SQLITE_OK; |
| 6127 goto jump_to_p2; |
| 5862 } | 6128 } |
| 5863 break; | 6129 break; |
| 5864 } | 6130 } |
| 5865 #endif | 6131 #endif |
| 5866 | 6132 |
| 5867 /* Opcode: Expire P1 * * * * | 6133 /* Opcode: Expire P1 * * * * |
| 5868 ** | 6134 ** |
| 5869 ** Cause precompiled statements to expire. When an expired statement | 6135 ** Cause precompiled statements to expire. When an expired statement |
| 5870 ** is executed using sqlite3_step() it will either automatically | 6136 ** is executed using sqlite3_step() it will either automatically |
| 5871 ** reprepare itself (if it was originally created using sqlite3_prepare_v2()) | 6137 ** reprepare itself (if it was originally created using sqlite3_prepare_v2()) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 5902 case OP_TableLock: { | 6168 case OP_TableLock: { |
| 5903 u8 isWriteLock = (u8)pOp->p3; | 6169 u8 isWriteLock = (u8)pOp->p3; |
| 5904 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){ | 6170 if( isWriteLock || 0==(db->flags&SQLITE_ReadUncommitted) ){ |
| 5905 int p1 = pOp->p1; | 6171 int p1 = pOp->p1; |
| 5906 assert( p1>=0 && p1<db->nDb ); | 6172 assert( p1>=0 && p1<db->nDb ); |
| 5907 assert( DbMaskTest(p->btreeMask, p1) ); | 6173 assert( DbMaskTest(p->btreeMask, p1) ); |
| 5908 assert( isWriteLock==0 || isWriteLock==1 ); | 6174 assert( isWriteLock==0 || isWriteLock==1 ); |
| 5909 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock); | 6175 rc = sqlite3BtreeLockTable(db->aDb[p1].pBt, pOp->p2, isWriteLock); |
| 5910 if( (rc&0xFF)==SQLITE_LOCKED ){ | 6176 if( (rc&0xFF)==SQLITE_LOCKED ){ |
| 5911 const char *z = pOp->p4.z; | 6177 const char *z = pOp->p4.z; |
| 5912 sqlite3SetString(&p->zErrMsg, db, "database table is locked: %s", z); | 6178 sqlite3VdbeError(p, "database table is locked: %s", z); |
| 5913 } | 6179 } |
| 5914 } | 6180 } |
| 5915 break; | 6181 break; |
| 5916 } | 6182 } |
| 5917 #endif /* SQLITE_OMIT_SHARED_CACHE */ | 6183 #endif /* SQLITE_OMIT_SHARED_CACHE */ |
| 5918 | 6184 |
| 5919 #ifndef SQLITE_OMIT_VIRTUALTABLE | 6185 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 5920 /* Opcode: VBegin * * * P4 * | 6186 /* Opcode: VBegin * * * P4 * |
| 5921 ** | 6187 ** |
| 5922 ** P4 may be a pointer to an sqlite3_vtab structure. If so, call the | 6188 ** P4 may be a pointer to an sqlite3_vtab structure. If so, call the |
| 5923 ** xBegin method for that table. | 6189 ** xBegin method for that table. |
| 5924 ** | 6190 ** |
| 5925 ** Also, whether or not P4 is set, check that this is not being called from | 6191 ** Also, whether or not P4 is set, check that this is not being called from |
| 5926 ** within a callback to a virtual table xSync() method. If it is, the error | 6192 ** within a callback to a virtual table xSync() method. If it is, the error |
| 5927 ** code will be set to SQLITE_LOCKED. | 6193 ** code will be set to SQLITE_LOCKED. |
| 5928 */ | 6194 */ |
| 5929 case OP_VBegin: { | 6195 case OP_VBegin: { |
| 5930 VTable *pVTab; | 6196 VTable *pVTab; |
| 5931 pVTab = pOp->p4.pVtab; | 6197 pVTab = pOp->p4.pVtab; |
| 5932 rc = sqlite3VtabBegin(db, pVTab); | 6198 rc = sqlite3VtabBegin(db, pVTab); |
| 5933 if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab); | 6199 if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab); |
| 5934 break; | 6200 break; |
| 5935 } | 6201 } |
| 5936 #endif /* SQLITE_OMIT_VIRTUALTABLE */ | 6202 #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 5937 | 6203 |
| 5938 #ifndef SQLITE_OMIT_VIRTUALTABLE | 6204 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 5939 /* Opcode: VCreate P1 * * P4 * | 6205 /* Opcode: VCreate P1 P2 * * * |
| 5940 ** | 6206 ** |
| 5941 ** P4 is the name of a virtual table in database P1. Call the xCreate method | 6207 ** P2 is a register that holds the name of a virtual table in database |
| 5942 ** for that table. | 6208 ** P1. Call the xCreate method for that table. |
| 5943 */ | 6209 */ |
| 5944 case OP_VCreate: { | 6210 case OP_VCreate: { |
| 5945 rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg); | 6211 Mem sMem; /* For storing the record being decoded */ |
| 6212 const char *zTab; /* Name of the virtual table */ |
| 6213 |
| 6214 memset(&sMem, 0, sizeof(sMem)); |
| 6215 sMem.db = db; |
| 6216 /* Because P2 is always a static string, it is impossible for the |
| 6217 ** sqlite3VdbeMemCopy() to fail */ |
| 6218 assert( (aMem[pOp->p2].flags & MEM_Str)!=0 ); |
| 6219 assert( (aMem[pOp->p2].flags & MEM_Static)!=0 ); |
| 6220 rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]); |
| 6221 assert( rc==SQLITE_OK ); |
| 6222 zTab = (const char*)sqlite3_value_text(&sMem); |
| 6223 assert( zTab || db->mallocFailed ); |
| 6224 if( zTab ){ |
| 6225 rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); |
| 6226 } |
| 6227 sqlite3VdbeMemRelease(&sMem); |
| 5946 break; | 6228 break; |
| 5947 } | 6229 } |
| 5948 #endif /* SQLITE_OMIT_VIRTUALTABLE */ | 6230 #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 5949 | 6231 |
| 5950 #ifndef SQLITE_OMIT_VIRTUALTABLE | 6232 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 5951 /* Opcode: VDestroy P1 * * P4 * | 6233 /* Opcode: VDestroy P1 * * P4 * |
| 5952 ** | 6234 ** |
| 5953 ** P4 is the name of a virtual table in database P1. Call the xDestroy method | 6235 ** P4 is the name of a virtual table in database P1. Call the xDestroy method |
| 5954 ** of that table. | 6236 ** of that table. |
| 5955 */ | 6237 */ |
| 5956 case OP_VDestroy: { | 6238 case OP_VDestroy: { |
| 5957 p->inVtabMethod = 2; | 6239 db->nVDestroy++; |
| 5958 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z); | 6240 rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z); |
| 5959 p->inVtabMethod = 0; | 6241 db->nVDestroy--; |
| 5960 break; | 6242 break; |
| 5961 } | 6243 } |
| 5962 #endif /* SQLITE_OMIT_VIRTUALTABLE */ | 6244 #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 5963 | 6245 |
| 5964 #ifndef SQLITE_OMIT_VIRTUALTABLE | 6246 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 5965 /* Opcode: VOpen P1 * * P4 * | 6247 /* Opcode: VOpen P1 * * P4 * |
| 5966 ** | 6248 ** |
| 5967 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. | 6249 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 5968 ** P1 is a cursor number. This opcode opens a cursor to the virtual | 6250 ** P1 is a cursor number. This opcode opens a cursor to the virtual |
| 5969 ** table and stores that cursor in P1. | 6251 ** table and stores that cursor in P1. |
| 5970 */ | 6252 */ |
| 5971 case OP_VOpen: { | 6253 case OP_VOpen: { |
| 5972 VdbeCursor *pCur; | 6254 VdbeCursor *pCur; |
| 5973 sqlite3_vtab_cursor *pVtabCursor; | 6255 sqlite3_vtab_cursor *pVCur; |
| 5974 sqlite3_vtab *pVtab; | 6256 sqlite3_vtab *pVtab; |
| 5975 sqlite3_module *pModule; | 6257 const sqlite3_module *pModule; |
| 5976 | 6258 |
| 5977 assert( p->bIsReader ); | 6259 assert( p->bIsReader ); |
| 5978 pCur = 0; | 6260 pCur = 0; |
| 5979 pVtabCursor = 0; | 6261 pVCur = 0; |
| 5980 pVtab = pOp->p4.pVtab->pVtab; | 6262 pVtab = pOp->p4.pVtab->pVtab; |
| 5981 pModule = (sqlite3_module *)pVtab->pModule; | 6263 if( pVtab==0 || NEVER(pVtab->pModule==0) ){ |
| 5982 assert(pVtab && pModule); | 6264 rc = SQLITE_LOCKED; |
| 5983 rc = pModule->xOpen(pVtab, &pVtabCursor); | 6265 break; |
| 6266 } |
| 6267 pModule = pVtab->pModule; |
| 6268 rc = pModule->xOpen(pVtab, &pVCur); |
| 5984 sqlite3VtabImportErrmsg(p, pVtab); | 6269 sqlite3VtabImportErrmsg(p, pVtab); |
| 5985 if( SQLITE_OK==rc ){ | 6270 if( SQLITE_OK==rc ){ |
| 5986 /* Initialize sqlite3_vtab_cursor base class */ | 6271 /* Initialize sqlite3_vtab_cursor base class */ |
| 5987 pVtabCursor->pVtab = pVtab; | 6272 pVCur->pVtab = pVtab; |
| 5988 | 6273 |
| 5989 /* Initialize vdbe cursor object */ | 6274 /* Initialize vdbe cursor object */ |
| 5990 pCur = allocateCursor(p, pOp->p1, 0, -1, 0); | 6275 pCur = allocateCursor(p, pOp->p1, 0, -1, CURTYPE_VTAB); |
| 5991 if( pCur ){ | 6276 if( pCur ){ |
| 5992 pCur->pVtabCursor = pVtabCursor; | 6277 pCur->uc.pVCur = pVCur; |
| 6278 pVtab->nRef++; |
| 5993 }else{ | 6279 }else{ |
| 5994 db->mallocFailed = 1; | 6280 assert( db->mallocFailed ); |
| 5995 pModule->xClose(pVtabCursor); | 6281 pModule->xClose(pVCur); |
| 6282 goto no_mem; |
| 5996 } | 6283 } |
| 5997 } | 6284 } |
| 5998 break; | 6285 break; |
| 5999 } | 6286 } |
| 6000 #endif /* SQLITE_OMIT_VIRTUALTABLE */ | 6287 #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 6001 | 6288 |
| 6002 #ifndef SQLITE_OMIT_VIRTUALTABLE | 6289 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 6003 /* Opcode: VFilter P1 P2 P3 P4 * | 6290 /* Opcode: VFilter P1 P2 P3 P4 * |
| 6004 ** Synopsis: iplan=r[P3] zplan='P4' | 6291 ** Synopsis: iplan=r[P3] zplan='P4' |
| 6005 ** | 6292 ** |
| (...skipping 12 matching lines...) Expand all Loading... |
| 6018 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter. | 6305 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter. |
| 6019 ** | 6306 ** |
| 6020 ** A jump is made to P2 if the result set after filtering would be empty. | 6307 ** A jump is made to P2 if the result set after filtering would be empty. |
| 6021 */ | 6308 */ |
| 6022 case OP_VFilter: { /* jump */ | 6309 case OP_VFilter: { /* jump */ |
| 6023 int nArg; | 6310 int nArg; |
| 6024 int iQuery; | 6311 int iQuery; |
| 6025 const sqlite3_module *pModule; | 6312 const sqlite3_module *pModule; |
| 6026 Mem *pQuery; | 6313 Mem *pQuery; |
| 6027 Mem *pArgc; | 6314 Mem *pArgc; |
| 6028 sqlite3_vtab_cursor *pVtabCursor; | 6315 sqlite3_vtab_cursor *pVCur; |
| 6029 sqlite3_vtab *pVtab; | 6316 sqlite3_vtab *pVtab; |
| 6030 VdbeCursor *pCur; | 6317 VdbeCursor *pCur; |
| 6031 int res; | 6318 int res; |
| 6032 int i; | 6319 int i; |
| 6033 Mem **apArg; | 6320 Mem **apArg; |
| 6034 | 6321 |
| 6035 pQuery = &aMem[pOp->p3]; | 6322 pQuery = &aMem[pOp->p3]; |
| 6036 pArgc = &pQuery[1]; | 6323 pArgc = &pQuery[1]; |
| 6037 pCur = p->apCsr[pOp->p1]; | 6324 pCur = p->apCsr[pOp->p1]; |
| 6038 assert( memIsValid(pQuery) ); | 6325 assert( memIsValid(pQuery) ); |
| 6039 REGISTER_TRACE(pOp->p3, pQuery); | 6326 REGISTER_TRACE(pOp->p3, pQuery); |
| 6040 assert( pCur->pVtabCursor ); | 6327 assert( pCur->eCurType==CURTYPE_VTAB ); |
| 6041 pVtabCursor = pCur->pVtabCursor; | 6328 pVCur = pCur->uc.pVCur; |
| 6042 pVtab = pVtabCursor->pVtab; | 6329 pVtab = pVCur->pVtab; |
| 6043 pModule = pVtab->pModule; | 6330 pModule = pVtab->pModule; |
| 6044 | 6331 |
| 6045 /* Grab the index number and argc parameters */ | 6332 /* Grab the index number and argc parameters */ |
| 6046 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); | 6333 assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); |
| 6047 nArg = (int)pArgc->u.i; | 6334 nArg = (int)pArgc->u.i; |
| 6048 iQuery = (int)pQuery->u.i; | 6335 iQuery = (int)pQuery->u.i; |
| 6049 | 6336 |
| 6050 /* Invoke the xFilter method */ | 6337 /* Invoke the xFilter method */ |
| 6051 { | 6338 res = 0; |
| 6052 res = 0; | 6339 apArg = p->apArg; |
| 6053 apArg = p->apArg; | 6340 for(i = 0; i<nArg; i++){ |
| 6054 for(i = 0; i<nArg; i++){ | 6341 apArg[i] = &pArgc[i+1]; |
| 6055 apArg[i] = &pArgc[i+1]; | 6342 } |
| 6056 } | 6343 rc = pModule->xFilter(pVCur, iQuery, pOp->p4.z, nArg, apArg); |
| 6057 | 6344 sqlite3VtabImportErrmsg(p, pVtab); |
| 6058 p->inVtabMethod = 1; | 6345 if( rc==SQLITE_OK ){ |
| 6059 rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); | 6346 res = pModule->xEof(pVCur); |
| 6060 p->inVtabMethod = 0; | |
| 6061 sqlite3VtabImportErrmsg(p, pVtab); | |
| 6062 if( rc==SQLITE_OK ){ | |
| 6063 res = pModule->xEof(pVtabCursor); | |
| 6064 } | |
| 6065 VdbeBranchTaken(res!=0,2); | |
| 6066 if( res ){ | |
| 6067 pc = pOp->p2 - 1; | |
| 6068 } | |
| 6069 } | 6347 } |
| 6070 pCur->nullRow = 0; | 6348 pCur->nullRow = 0; |
| 6071 | 6349 VdbeBranchTaken(res!=0,2); |
| 6350 if( res ) goto jump_to_p2; |
| 6072 break; | 6351 break; |
| 6073 } | 6352 } |
| 6074 #endif /* SQLITE_OMIT_VIRTUALTABLE */ | 6353 #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 6075 | 6354 |
| 6076 #ifndef SQLITE_OMIT_VIRTUALTABLE | 6355 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 6077 /* Opcode: VColumn P1 P2 P3 * * | 6356 /* Opcode: VColumn P1 P2 P3 * * |
| 6078 ** Synopsis: r[P3]=vcolumn(P2) | 6357 ** Synopsis: r[P3]=vcolumn(P2) |
| 6079 ** | 6358 ** |
| 6080 ** Store the value of the P2-th column of | 6359 ** Store the value of the P2-th column of |
| 6081 ** the row of the virtual-table that the | 6360 ** the row of the virtual-table that the |
| 6082 ** P1 cursor is pointing to into register P3. | 6361 ** P1 cursor is pointing to into register P3. |
| 6083 */ | 6362 */ |
| 6084 case OP_VColumn: { | 6363 case OP_VColumn: { |
| 6085 sqlite3_vtab *pVtab; | 6364 sqlite3_vtab *pVtab; |
| 6086 const sqlite3_module *pModule; | 6365 const sqlite3_module *pModule; |
| 6087 Mem *pDest; | 6366 Mem *pDest; |
| 6088 sqlite3_context sContext; | 6367 sqlite3_context sContext; |
| 6089 | 6368 |
| 6090 VdbeCursor *pCur = p->apCsr[pOp->p1]; | 6369 VdbeCursor *pCur = p->apCsr[pOp->p1]; |
| 6091 assert( pCur->pVtabCursor ); | 6370 assert( pCur->eCurType==CURTYPE_VTAB ); |
| 6092 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); | 6371 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 6093 pDest = &aMem[pOp->p3]; | 6372 pDest = &aMem[pOp->p3]; |
| 6094 memAboutToChange(p, pDest); | 6373 memAboutToChange(p, pDest); |
| 6095 if( pCur->nullRow ){ | 6374 if( pCur->nullRow ){ |
| 6096 sqlite3VdbeMemSetNull(pDest); | 6375 sqlite3VdbeMemSetNull(pDest); |
| 6097 break; | 6376 break; |
| 6098 } | 6377 } |
| 6099 pVtab = pCur->pVtabCursor->pVtab; | 6378 pVtab = pCur->uc.pVCur->pVtab; |
| 6100 pModule = pVtab->pModule; | 6379 pModule = pVtab->pModule; |
| 6101 assert( pModule->xColumn ); | 6380 assert( pModule->xColumn ); |
| 6102 memset(&sContext, 0, sizeof(sContext)); | 6381 memset(&sContext, 0, sizeof(sContext)); |
| 6103 sContext.pOut = pDest; | 6382 sContext.pOut = pDest; |
| 6104 MemSetTypeFlag(pDest, MEM_Null); | 6383 MemSetTypeFlag(pDest, MEM_Null); |
| 6105 rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2); | 6384 rc = pModule->xColumn(pCur->uc.pVCur, &sContext, pOp->p2); |
| 6106 sqlite3VtabImportErrmsg(p, pVtab); | 6385 sqlite3VtabImportErrmsg(p, pVtab); |
| 6107 if( sContext.isError ){ | 6386 if( sContext.isError ){ |
| 6108 rc = sContext.isError; | 6387 rc = sContext.isError; |
| 6109 } | 6388 } |
| 6110 sqlite3VdbeChangeEncoding(pDest, encoding); | 6389 sqlite3VdbeChangeEncoding(pDest, encoding); |
| 6111 REGISTER_TRACE(pOp->p3, pDest); | 6390 REGISTER_TRACE(pOp->p3, pDest); |
| 6112 UPDATE_MAX_BLOBSIZE(pDest); | 6391 UPDATE_MAX_BLOBSIZE(pDest); |
| 6113 | 6392 |
| 6114 if( sqlite3VdbeMemTooBig(pDest) ){ | 6393 if( sqlite3VdbeMemTooBig(pDest) ){ |
| 6115 goto too_big; | 6394 goto too_big; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6126 ** the end of its result set, then fall through to the next instruction. | 6405 ** the end of its result set, then fall through to the next instruction. |
| 6127 */ | 6406 */ |
| 6128 case OP_VNext: { /* jump */ | 6407 case OP_VNext: { /* jump */ |
| 6129 sqlite3_vtab *pVtab; | 6408 sqlite3_vtab *pVtab; |
| 6130 const sqlite3_module *pModule; | 6409 const sqlite3_module *pModule; |
| 6131 int res; | 6410 int res; |
| 6132 VdbeCursor *pCur; | 6411 VdbeCursor *pCur; |
| 6133 | 6412 |
| 6134 res = 0; | 6413 res = 0; |
| 6135 pCur = p->apCsr[pOp->p1]; | 6414 pCur = p->apCsr[pOp->p1]; |
| 6136 assert( pCur->pVtabCursor ); | 6415 assert( pCur->eCurType==CURTYPE_VTAB ); |
| 6137 if( pCur->nullRow ){ | 6416 if( pCur->nullRow ){ |
| 6138 break; | 6417 break; |
| 6139 } | 6418 } |
| 6140 pVtab = pCur->pVtabCursor->pVtab; | 6419 pVtab = pCur->uc.pVCur->pVtab; |
| 6141 pModule = pVtab->pModule; | 6420 pModule = pVtab->pModule; |
| 6142 assert( pModule->xNext ); | 6421 assert( pModule->xNext ); |
| 6143 | 6422 |
| 6144 /* Invoke the xNext() method of the module. There is no way for the | 6423 /* Invoke the xNext() method of the module. There is no way for the |
| 6145 ** underlying implementation to return an error if one occurs during | 6424 ** underlying implementation to return an error if one occurs during |
| 6146 ** xNext(). Instead, if an error occurs, true is returned (indicating that | 6425 ** xNext(). Instead, if an error occurs, true is returned (indicating that |
| 6147 ** data is available) and the error code returned when xColumn or | 6426 ** data is available) and the error code returned when xColumn or |
| 6148 ** some other method is next invoked on the save virtual table cursor. | 6427 ** some other method is next invoked on the save virtual table cursor. |
| 6149 */ | 6428 */ |
| 6150 p->inVtabMethod = 1; | 6429 rc = pModule->xNext(pCur->uc.pVCur); |
| 6151 rc = pModule->xNext(pCur->pVtabCursor); | |
| 6152 p->inVtabMethod = 0; | |
| 6153 sqlite3VtabImportErrmsg(p, pVtab); | 6430 sqlite3VtabImportErrmsg(p, pVtab); |
| 6154 if( rc==SQLITE_OK ){ | 6431 if( rc==SQLITE_OK ){ |
| 6155 res = pModule->xEof(pCur->pVtabCursor); | 6432 res = pModule->xEof(pCur->uc.pVCur); |
| 6156 } | 6433 } |
| 6157 VdbeBranchTaken(!res,2); | 6434 VdbeBranchTaken(!res,2); |
| 6158 if( !res ){ | 6435 if( !res ){ |
| 6159 /* If there is data, jump to P2 */ | 6436 /* If there is data, jump to P2 */ |
| 6160 pc = pOp->p2 - 1; | 6437 goto jump_to_p2_and_check_for_interrupt; |
| 6161 } | 6438 } |
| 6162 goto check_for_interrupt; | 6439 goto check_for_interrupt; |
| 6163 } | 6440 } |
| 6164 #endif /* SQLITE_OMIT_VIRTUALTABLE */ | 6441 #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 6165 | 6442 |
| 6166 #ifndef SQLITE_OMIT_VIRTUALTABLE | 6443 #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 6167 /* Opcode: VRename P1 * * P4 * | 6444 /* Opcode: VRename P1 * * P4 * |
| 6168 ** | 6445 ** |
| 6169 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. | 6446 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 6170 ** This opcode invokes the corresponding xRename method. The value | 6447 ** This opcode invokes the corresponding xRename method. The value |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6217 ** | 6494 ** |
| 6218 ** P1 is a boolean flag. If it is set to true and the xUpdate call | 6495 ** P1 is a boolean flag. If it is set to true and the xUpdate call |
| 6219 ** is successful, then the value returned by sqlite3_last_insert_rowid() | 6496 ** is successful, then the value returned by sqlite3_last_insert_rowid() |
| 6220 ** is set to the value of the rowid for the row just inserted. | 6497 ** is set to the value of the rowid for the row just inserted. |
| 6221 ** | 6498 ** |
| 6222 ** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to | 6499 ** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to |
| 6223 ** apply in the case of a constraint failure on an insert or update. | 6500 ** apply in the case of a constraint failure on an insert or update. |
| 6224 */ | 6501 */ |
| 6225 case OP_VUpdate: { | 6502 case OP_VUpdate: { |
| 6226 sqlite3_vtab *pVtab; | 6503 sqlite3_vtab *pVtab; |
| 6227 sqlite3_module *pModule; | 6504 const sqlite3_module *pModule; |
| 6228 int nArg; | 6505 int nArg; |
| 6229 int i; | 6506 int i; |
| 6230 sqlite_int64 rowid; | 6507 sqlite_int64 rowid; |
| 6231 Mem **apArg; | 6508 Mem **apArg; |
| 6232 Mem *pX; | 6509 Mem *pX; |
| 6233 | 6510 |
| 6234 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback | 6511 assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 6235 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace | 6512 || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| 6236 ); | 6513 ); |
| 6237 assert( p->readOnly==0 ); | 6514 assert( p->readOnly==0 ); |
| 6238 pVtab = pOp->p4.pVtab->pVtab; | 6515 pVtab = pOp->p4.pVtab->pVtab; |
| 6239 pModule = (sqlite3_module *)pVtab->pModule; | 6516 if( pVtab==0 || NEVER(pVtab->pModule==0) ){ |
| 6517 rc = SQLITE_LOCKED; |
| 6518 break; |
| 6519 } |
| 6520 pModule = pVtab->pModule; |
| 6240 nArg = pOp->p2; | 6521 nArg = pOp->p2; |
| 6241 assert( pOp->p4type==P4_VTAB ); | 6522 assert( pOp->p4type==P4_VTAB ); |
| 6242 if( ALWAYS(pModule->xUpdate) ){ | 6523 if( ALWAYS(pModule->xUpdate) ){ |
| 6243 u8 vtabOnConflict = db->vtabOnConflict; | 6524 u8 vtabOnConflict = db->vtabOnConflict; |
| 6244 apArg = p->apArg; | 6525 apArg = p->apArg; |
| 6245 pX = &aMem[pOp->p3]; | 6526 pX = &aMem[pOp->p3]; |
| 6246 for(i=0; i<nArg; i++){ | 6527 for(i=0; i<nArg; i++){ |
| 6247 assert( memIsValid(pX) ); | 6528 assert( memIsValid(pX) ); |
| 6248 memAboutToChange(p, pX); | 6529 memAboutToChange(p, pX); |
| 6249 apArg[i] = pX; | 6530 apArg[i] = pX; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 6269 } | 6550 } |
| 6270 break; | 6551 break; |
| 6271 } | 6552 } |
| 6272 #endif /* SQLITE_OMIT_VIRTUALTABLE */ | 6553 #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 6273 | 6554 |
| 6274 #ifndef SQLITE_OMIT_PAGER_PRAGMAS | 6555 #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 6275 /* Opcode: Pagecount P1 P2 * * * | 6556 /* Opcode: Pagecount P1 P2 * * * |
| 6276 ** | 6557 ** |
| 6277 ** Write the current number of pages in database P1 to memory cell P2. | 6558 ** Write the current number of pages in database P1 to memory cell P2. |
| 6278 */ | 6559 */ |
| 6279 case OP_Pagecount: { /* out2-prerelease */ | 6560 case OP_Pagecount: { /* out2 */ |
| 6561 pOut = out2Prerelease(p, pOp); |
| 6280 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt); | 6562 pOut->u.i = sqlite3BtreeLastPage(db->aDb[pOp->p1].pBt); |
| 6281 break; | 6563 break; |
| 6282 } | 6564 } |
| 6283 #endif | 6565 #endif |
| 6284 | 6566 |
| 6285 | 6567 |
| 6286 #ifndef SQLITE_OMIT_PAGER_PRAGMAS | 6568 #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 6287 /* Opcode: MaxPgcnt P1 P2 P3 * * | 6569 /* Opcode: MaxPgcnt P1 P2 P3 * * |
| 6288 ** | 6570 ** |
| 6289 ** Try to set the maximum page count for database P1 to the value in P3. | 6571 ** Try to set the maximum page count for database P1 to the value in P3. |
| 6290 ** Do not let the maximum page count fall below the current page count and | 6572 ** Do not let the maximum page count fall below the current page count and |
| 6291 ** do not change the maximum page count value if P3==0. | 6573 ** do not change the maximum page count value if P3==0. |
| 6292 ** | 6574 ** |
| 6293 ** Store the maximum page count after the change in register P2. | 6575 ** Store the maximum page count after the change in register P2. |
| 6294 */ | 6576 */ |
| 6295 case OP_MaxPgcnt: { /* out2-prerelease */ | 6577 case OP_MaxPgcnt: { /* out2 */ |
| 6296 unsigned int newMax; | 6578 unsigned int newMax; |
| 6297 Btree *pBt; | 6579 Btree *pBt; |
| 6298 | 6580 |
| 6581 pOut = out2Prerelease(p, pOp); |
| 6299 pBt = db->aDb[pOp->p1].pBt; | 6582 pBt = db->aDb[pOp->p1].pBt; |
| 6300 newMax = 0; | 6583 newMax = 0; |
| 6301 if( pOp->p3 ){ | 6584 if( pOp->p3 ){ |
| 6302 newMax = sqlite3BtreeLastPage(pBt); | 6585 newMax = sqlite3BtreeLastPage(pBt); |
| 6303 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3; | 6586 if( newMax < (unsigned)pOp->p3 ) newMax = (unsigned)pOp->p3; |
| 6304 } | 6587 } |
| 6305 pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax); | 6588 pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax); |
| 6306 break; | 6589 break; |
| 6307 } | 6590 } |
| 6308 #endif | 6591 #endif |
| 6309 | 6592 |
| 6310 | 6593 |
| 6311 /* Opcode: Init * P2 * P4 * | 6594 /* Opcode: Init * P2 * P4 * |
| 6312 ** Synopsis: Start at P2 | 6595 ** Synopsis: Start at P2 |
| 6313 ** | 6596 ** |
| 6314 ** Programs contain a single instance of this opcode as the very first | 6597 ** Programs contain a single instance of this opcode as the very first |
| 6315 ** opcode. | 6598 ** opcode. |
| 6316 ** | 6599 ** |
| 6317 ** If tracing is enabled (by the sqlite3_trace()) interface, then | 6600 ** If tracing is enabled (by the sqlite3_trace()) interface, then |
| 6318 ** the UTF-8 string contained in P4 is emitted on the trace callback. | 6601 ** the UTF-8 string contained in P4 is emitted on the trace callback. |
| 6319 ** Or if P4 is blank, use the string returned by sqlite3_sql(). | 6602 ** Or if P4 is blank, use the string returned by sqlite3_sql(). |
| 6320 ** | 6603 ** |
| 6321 ** If P2 is not zero, jump to instruction P2. | 6604 ** If P2 is not zero, jump to instruction P2. |
| 6322 */ | 6605 */ |
| 6323 case OP_Init: { /* jump */ | 6606 case OP_Init: { /* jump */ |
| 6324 char *zTrace; | 6607 char *zTrace; |
| 6325 char *z; | 6608 char *z; |
| 6326 | 6609 |
| 6327 if( pOp->p2 ){ | |
| 6328 pc = pOp->p2 - 1; | |
| 6329 } | |
| 6330 #ifndef SQLITE_OMIT_TRACE | 6610 #ifndef SQLITE_OMIT_TRACE |
| 6331 if( db->xTrace | 6611 if( db->xTrace |
| 6332 && !p->doingRerun | 6612 && !p->doingRerun |
| 6333 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 | 6613 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 6334 ){ | 6614 ){ |
| 6335 z = sqlite3VdbeExpandSql(p, zTrace); | 6615 z = sqlite3VdbeExpandSql(p, zTrace); |
| 6336 db->xTrace(db->pTraceArg, z); | 6616 db->xTrace(db->pTraceArg, z); |
| 6337 sqlite3DbFree(db, z); | 6617 sqlite3DbFree(db, z); |
| 6338 } | 6618 } |
| 6339 #ifdef SQLITE_USE_FCNTL_TRACE | 6619 #ifdef SQLITE_USE_FCNTL_TRACE |
| 6340 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); | 6620 zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); |
| 6341 if( zTrace ){ | 6621 if( zTrace ){ |
| 6342 int i; | 6622 int i; |
| 6343 for(i=0; i<db->nDb; i++){ | 6623 for(i=0; i<db->nDb; i++){ |
| 6344 if( DbMaskTest(p->btreeMask, i)==0 ) continue; | 6624 if( DbMaskTest(p->btreeMask, i)==0 ) continue; |
| 6345 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace); | 6625 sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace); |
| 6346 } | 6626 } |
| 6347 } | 6627 } |
| 6348 #endif /* SQLITE_USE_FCNTL_TRACE */ | 6628 #endif /* SQLITE_USE_FCNTL_TRACE */ |
| 6349 #ifdef SQLITE_DEBUG | 6629 #ifdef SQLITE_DEBUG |
| 6350 if( (db->flags & SQLITE_SqlTrace)!=0 | 6630 if( (db->flags & SQLITE_SqlTrace)!=0 |
| 6351 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 | 6631 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 6352 ){ | 6632 ){ |
| 6353 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); | 6633 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); |
| 6354 } | 6634 } |
| 6355 #endif /* SQLITE_DEBUG */ | 6635 #endif /* SQLITE_DEBUG */ |
| 6356 #endif /* SQLITE_OMIT_TRACE */ | 6636 #endif /* SQLITE_OMIT_TRACE */ |
| 6637 if( pOp->p2 ) goto jump_to_p2; |
| 6357 break; | 6638 break; |
| 6358 } | 6639 } |
| 6359 | 6640 |
| 6641 #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 6642 /* Opcode: CursorHint P1 * * P4 * |
| 6643 ** |
| 6644 ** Provide a hint to cursor P1 that it only needs to return rows that |
| 6645 ** satisfy the Expr in P4. TK_REGISTER terms in the P4 expression refer |
| 6646 ** to values currently held in registers. TK_COLUMN terms in the P4 |
| 6647 ** expression refer to columns in the b-tree to which cursor P1 is pointing. |
| 6648 */ |
| 6649 case OP_CursorHint: { |
| 6650 VdbeCursor *pC; |
| 6651 |
| 6652 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 6653 assert( pOp->p4type==P4_EXPR ); |
| 6654 pC = p->apCsr[pOp->p1]; |
| 6655 if( pC ){ |
| 6656 assert( pC->eCurType==CURTYPE_BTREE ); |
| 6657 sqlite3BtreeCursorHint(pC->uc.pCursor, BTREE_HINT_RANGE, |
| 6658 pOp->p4.pExpr, aMem); |
| 6659 } |
| 6660 break; |
| 6661 } |
| 6662 #endif /* SQLITE_ENABLE_CURSOR_HINTS */ |
| 6360 | 6663 |
| 6361 /* Opcode: Noop * * * * * | 6664 /* Opcode: Noop * * * * * |
| 6362 ** | 6665 ** |
| 6363 ** Do nothing. This instruction is often useful as a jump | 6666 ** Do nothing. This instruction is often useful as a jump |
| 6364 ** destination. | 6667 ** destination. |
| 6365 */ | 6668 */ |
| 6366 /* | 6669 /* |
| 6367 ** The magic Explain opcode are only inserted when explain==2 (which | 6670 ** The magic Explain opcode are only inserted when explain==2 (which |
| 6368 ** is to say when the EXPLAIN QUERY PLAN syntax is used.) | 6671 ** is to say when the EXPLAIN QUERY PLAN syntax is used.) |
| 6369 ** This opcode records information from the optimizer. It is the | 6672 ** This opcode records information from the optimizer. It is the |
| 6370 ** the same as a no-op. This opcodesnever appears in a real VM program. | 6673 ** the same as a no-op. This opcodesnever appears in a real VM program. |
| 6371 */ | 6674 */ |
| 6372 default: { /* This is really OP_Noop and OP_Explain */ | 6675 default: { /* This is really OP_Noop and OP_Explain */ |
| 6373 assert( pOp->opcode==OP_Noop || pOp->opcode==OP_Explain ); | 6676 assert( pOp->opcode==OP_Noop || pOp->opcode==OP_Explain ); |
| 6374 break; | 6677 break; |
| 6375 } | 6678 } |
| 6376 | 6679 |
| 6377 /***************************************************************************** | 6680 /***************************************************************************** |
| 6378 ** The cases of the switch statement above this line should all be indented | 6681 ** The cases of the switch statement above this line should all be indented |
| 6379 ** by 6 spaces. But the left-most 6 spaces have been removed to improve the | 6682 ** by 6 spaces. But the left-most 6 spaces have been removed to improve the |
| 6380 ** readability. From this point on down, the normal indentation rules are | 6683 ** readability. From this point on down, the normal indentation rules are |
| 6381 ** restored. | 6684 ** restored. |
| 6382 *****************************************************************************/ | 6685 *****************************************************************************/ |
| 6383 } | 6686 } |
| 6384 | 6687 |
| 6385 #ifdef VDBE_PROFILE | 6688 #ifdef VDBE_PROFILE |
| 6386 { | 6689 { |
| 6387 u64 endTime = sqlite3Hwtime(); | 6690 u64 endTime = sqlite3Hwtime(); |
| 6388 if( endTime>start ) pOp->cycles += endTime - start; | 6691 if( endTime>start ) pOrigOp->cycles += endTime - start; |
| 6389 pOp->cnt++; | 6692 pOrigOp->cnt++; |
| 6390 } | 6693 } |
| 6391 #endif | 6694 #endif |
| 6392 | 6695 |
| 6393 /* The following code adds nothing to the actual functionality | 6696 /* The following code adds nothing to the actual functionality |
| 6394 ** of the program. It is only here for testing and debugging. | 6697 ** of the program. It is only here for testing and debugging. |
| 6395 ** On the other hand, it does burn CPU cycles every time through | 6698 ** On the other hand, it does burn CPU cycles every time through |
| 6396 ** the evaluator loop. So we can leave it out when NDEBUG is defined. | 6699 ** the evaluator loop. So we can leave it out when NDEBUG is defined. |
| 6397 */ | 6700 */ |
| 6398 #ifndef NDEBUG | 6701 #ifndef NDEBUG |
| 6399 assert( pc>=-1 && pc<p->nOp ); | 6702 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] ); |
| 6400 | 6703 |
| 6401 #ifdef SQLITE_DEBUG | 6704 #ifdef SQLITE_DEBUG |
| 6402 if( db->flags & SQLITE_VdbeTrace ){ | 6705 if( db->flags & SQLITE_VdbeTrace ){ |
| 6403 if( rc!=0 ) printf("rc=%d\n",rc); | 6706 if( rc!=0 ) printf("rc=%d\n",rc); |
| 6404 if( pOp->opflags & (OPFLG_OUT2_PRERELEASE|OPFLG_OUT2) ){ | 6707 if( pOrigOp->opflags & (OPFLG_OUT2) ){ |
| 6405 registerTrace(pOp->p2, &aMem[pOp->p2]); | 6708 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]); |
| 6406 } | 6709 } |
| 6407 if( pOp->opflags & OPFLG_OUT3 ){ | 6710 if( pOrigOp->opflags & OPFLG_OUT3 ){ |
| 6408 registerTrace(pOp->p3, &aMem[pOp->p3]); | 6711 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); |
| 6409 } | 6712 } |
| 6410 } | 6713 } |
| 6411 #endif /* SQLITE_DEBUG */ | 6714 #endif /* SQLITE_DEBUG */ |
| 6412 #endif /* NDEBUG */ | 6715 #endif /* NDEBUG */ |
| 6413 } /* The end of the for(;;) loop the loops through opcodes */ | 6716 } /* The end of the for(;;) loop the loops through opcodes */ |
| 6414 | 6717 |
| 6415 /* If we reach this point, it means that execution is finished with | 6718 /* If we reach this point, it means that execution is finished with |
| 6416 ** an error of some kind. | 6719 ** an error of some kind. |
| 6417 */ | 6720 */ |
| 6418 vdbe_error_halt: | 6721 vdbe_error_halt: |
| 6419 assert( rc ); | 6722 assert( rc ); |
| 6420 p->rc = rc; | 6723 p->rc = rc; |
| 6421 testcase( sqlite3GlobalConfig.xLog!=0 ); | 6724 testcase( sqlite3GlobalConfig.xLog!=0 ); |
| 6422 sqlite3_log(rc, "statement aborts at %d: [%s] %s", | 6725 sqlite3_log(rc, "statement aborts at %d: [%s] %s", |
| 6423 pc, p->zSql, p->zErrMsg); | 6726 (int)(pOp - aOp), p->zSql, p->zErrMsg); |
| 6424 sqlite3VdbeHalt(p); | 6727 sqlite3VdbeHalt(p); |
| 6425 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; | 6728 if( rc==SQLITE_IOERR_NOMEM ) db->mallocFailed = 1; |
| 6426 rc = SQLITE_ERROR; | 6729 rc = SQLITE_ERROR; |
| 6427 if( resetSchemaOnFault>0 ){ | 6730 if( resetSchemaOnFault>0 ){ |
| 6428 sqlite3ResetOneSchema(db, resetSchemaOnFault-1); | 6731 sqlite3ResetOneSchema(db, resetSchemaOnFault-1); |
| 6429 } | 6732 } |
| 6430 | 6733 |
| 6431 /* This is the only way out of this procedure. We have to | 6734 /* This is the only way out of this procedure. We have to |
| 6432 ** release the mutexes on btrees that were acquired at the | 6735 ** release the mutexes on btrees that were acquired at the |
| 6433 ** top. */ | 6736 ** top. */ |
| 6434 vdbe_return: | 6737 vdbe_return: |
| 6435 db->lastRowid = lastRowid; | 6738 db->lastRowid = lastRowid; |
| 6436 testcase( nVmStep>0 ); | 6739 testcase( nVmStep>0 ); |
| 6437 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; | 6740 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; |
| 6438 sqlite3VdbeLeave(p); | 6741 sqlite3VdbeLeave(p); |
| 6439 return rc; | 6742 return rc; |
| 6440 | 6743 |
| 6441 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH | 6744 /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 6442 ** is encountered. | 6745 ** is encountered. |
| 6443 */ | 6746 */ |
| 6444 too_big: | 6747 too_big: |
| 6445 sqlite3SetString(&p->zErrMsg, db, "string or blob too big"); | 6748 sqlite3VdbeError(p, "string or blob too big"); |
| 6446 rc = SQLITE_TOOBIG; | 6749 rc = SQLITE_TOOBIG; |
| 6447 goto vdbe_error_halt; | 6750 goto vdbe_error_halt; |
| 6448 | 6751 |
| 6449 /* Jump to here if a malloc() fails. | 6752 /* Jump to here if a malloc() fails. |
| 6450 */ | 6753 */ |
| 6451 no_mem: | 6754 no_mem: |
| 6452 db->mallocFailed = 1; | 6755 db->mallocFailed = 1; |
| 6453 sqlite3SetString(&p->zErrMsg, db, "out of memory"); | 6756 sqlite3VdbeError(p, "out of memory"); |
| 6454 rc = SQLITE_NOMEM; | 6757 rc = SQLITE_NOMEM; |
| 6455 goto vdbe_error_halt; | 6758 goto vdbe_error_halt; |
| 6456 | 6759 |
| 6457 /* Jump to here for any other kind of fatal error. The "rc" variable | 6760 /* Jump to here for any other kind of fatal error. The "rc" variable |
| 6458 ** should hold the error number. | 6761 ** should hold the error number. |
| 6459 */ | 6762 */ |
| 6460 abort_due_to_error: | 6763 abort_due_to_error: |
| 6461 assert( p->zErrMsg==0 ); | 6764 assert( p->zErrMsg==0 ); |
| 6462 if( db->mallocFailed ) rc = SQLITE_NOMEM; | 6765 if( db->mallocFailed ) rc = SQLITE_NOMEM; |
| 6463 if( rc!=SQLITE_IOERR_NOMEM ){ | 6766 if( rc!=SQLITE_IOERR_NOMEM ){ |
| 6464 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc)); | 6767 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc)); |
| 6465 } | 6768 } |
| 6466 goto vdbe_error_halt; | 6769 goto vdbe_error_halt; |
| 6467 | 6770 |
| 6468 /* Jump to here if the sqlite3_interrupt() API sets the interrupt | 6771 /* Jump to here if the sqlite3_interrupt() API sets the interrupt |
| 6469 ** flag. | 6772 ** flag. |
| 6470 */ | 6773 */ |
| 6471 abort_due_to_interrupt: | 6774 abort_due_to_interrupt: |
| 6472 assert( db->u1.isInterrupted ); | 6775 assert( db->u1.isInterrupted ); |
| 6473 rc = SQLITE_INTERRUPT; | 6776 rc = SQLITE_INTERRUPT; |
| 6474 p->rc = rc; | 6777 p->rc = rc; |
| 6475 sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc)); | 6778 sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc)); |
| 6476 goto vdbe_error_halt; | 6779 goto vdbe_error_halt; |
| 6477 } | 6780 } |
| OLD | NEW |