Fossil SCM
Bring in the latest SQLite with VDBE and Btree performance optimizations.
Commit
187845b5746ec92334dc4f55717740a9642bfe38
Parent
9d50b77e1298f2e…
2 files changed
+111
-65
+1
-1
+111
-65
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -656,11 +656,11 @@ | ||
| 656 | 656 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 657 | 657 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 658 | 658 | */ |
| 659 | 659 | #define SQLITE_VERSION "3.8.0" |
| 660 | 660 | #define SQLITE_VERSION_NUMBER 3008000 |
| 661 | -#define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a" | |
| 661 | +#define SQLITE_SOURCE_ID "2013-08-20 03:13:51 7f72fc4f47445a2c01910b268335873de9f75059" | |
| 662 | 662 | |
| 663 | 663 | /* |
| 664 | 664 | ** CAPI3REF: Run-Time Library Version Numbers |
| 665 | 665 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 666 | 666 | ** |
| @@ -13486,14 +13486,15 @@ | ||
| 13486 | 13486 | struct sqlite3_context { |
| 13487 | 13487 | FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ |
| 13488 | 13488 | Mem s; /* The return value is stored here */ |
| 13489 | 13489 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 13490 | 13490 | CollSeq *pColl; /* Collating sequence */ |
| 13491 | - int isError; /* Error code returned by the function. */ | |
| 13492 | - int skipFlag; /* Skip skip accumulator loading if true */ | |
| 13491 | + Vdbe *pVdbe; /* The VM that owns this context */ | |
| 13493 | 13492 | int iOp; /* Instruction number of OP_Function */ |
| 13494 | - Vdbe *pVdbe; /* The VM that owns this context */ | |
| 13493 | + int isError; /* Error code returned by the function. */ | |
| 13494 | + u8 skipFlag; /* Skip skip accumulator loading if true */ | |
| 13495 | + u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */ | |
| 13495 | 13496 | }; |
| 13496 | 13497 | |
| 13497 | 13498 | /* |
| 13498 | 13499 | ** An Explain object accumulates indented output which is helpful |
| 13499 | 13500 | ** in describing recursive data structures. |
| @@ -13565,11 +13566,11 @@ | ||
| 13565 | 13566 | bft doingRerun:1; /* True if rerunning after an auto-reprepare */ |
| 13566 | 13567 | int nChange; /* Number of db changes made since last reset */ |
| 13567 | 13568 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 13568 | 13569 | yDbMask lockMask; /* Subset of btreeMask that requires a lock */ |
| 13569 | 13570 | int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 13570 | - int aCounter[4]; /* Counters used by sqlite3_stmt_status() */ | |
| 13571 | + u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */ | |
| 13571 | 13572 | #ifndef SQLITE_OMIT_TRACE |
| 13572 | 13573 | i64 startTime; /* Time when query started - used for profiling */ |
| 13573 | 13574 | #endif |
| 13574 | 13575 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 13575 | 13576 | i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| @@ -37447,10 +37448,11 @@ | ||
| 37447 | 37448 | } |
| 37448 | 37449 | |
| 37449 | 37450 | if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){ |
| 37450 | 37451 | goto fetch_out; |
| 37451 | 37452 | } |
| 37453 | + assert( pCache->nHash>0 && pCache->apHash ); | |
| 37452 | 37454 | |
| 37453 | 37455 | /* Step 4. Try to recycle a page. */ |
| 37454 | 37456 | if( pCache->bPurgeable && pGroup->pLruTail && ( |
| 37455 | 37457 | (pCache->nPage+1>=pCache->nMax) |
| 37456 | 37458 | || pGroup->nCurrentPage>=pGroup->nMaxPage |
| @@ -49181,18 +49183,23 @@ | ||
| 49181 | 49183 | }; |
| 49182 | 49184 | |
| 49183 | 49185 | /* |
| 49184 | 49186 | ** Potential values for BtCursor.eState. |
| 49185 | 49187 | ** |
| 49186 | -** CURSOR_VALID: | |
| 49187 | -** Cursor points to a valid entry. getPayload() etc. may be called. | |
| 49188 | -** | |
| 49189 | 49188 | ** CURSOR_INVALID: |
| 49190 | 49189 | ** Cursor does not point to a valid entry. This can happen (for example) |
| 49191 | 49190 | ** because the table is empty or because BtreeCursorFirst() has not been |
| 49192 | 49191 | ** called. |
| 49193 | 49192 | ** |
| 49193 | +** CURSOR_VALID: | |
| 49194 | +** Cursor points to a valid entry. getPayload() etc. may be called. | |
| 49195 | +** | |
| 49196 | +** CURSOR_SKIPNEXT: | |
| 49197 | +** Cursor is valid except that the Cursor.skipNext field is non-zero | |
| 49198 | +** indicating that the next sqlite3BtreeNext() or sqlite3BtreePrevious() | |
| 49199 | +** operation should be a no-op. | |
| 49200 | +** | |
| 49194 | 49201 | ** CURSOR_REQUIRESEEK: |
| 49195 | 49202 | ** The table that this cursor was opened on still exists, but has been |
| 49196 | 49203 | ** modified since the cursor was last used. The cursor position is saved |
| 49197 | 49204 | ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in |
| 49198 | 49205 | ** this state, restoreCursorPosition() can be called to attempt to |
| @@ -49205,12 +49212,13 @@ | ||
| 49205 | 49212 | ** Do nothing else with this cursor. Any attempt to use the cursor |
| 49206 | 49213 | ** should return the error code stored in BtCursor.skip |
| 49207 | 49214 | */ |
| 49208 | 49215 | #define CURSOR_INVALID 0 |
| 49209 | 49216 | #define CURSOR_VALID 1 |
| 49210 | -#define CURSOR_REQUIRESEEK 2 | |
| 49211 | -#define CURSOR_FAULT 3 | |
| 49217 | +#define CURSOR_SKIPNEXT 2 | |
| 49218 | +#define CURSOR_REQUIRESEEK 3 | |
| 49219 | +#define CURSOR_FAULT 4 | |
| 49212 | 49220 | |
| 49213 | 49221 | /* |
| 49214 | 49222 | ** The database page the PENDING_BYTE occupies. This page is never used. |
| 49215 | 49223 | */ |
| 49216 | 49224 | # define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt) |
| @@ -50320,10 +50328,13 @@ | ||
| 50320 | 50328 | rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skipNext); |
| 50321 | 50329 | if( rc==SQLITE_OK ){ |
| 50322 | 50330 | sqlite3_free(pCur->pKey); |
| 50323 | 50331 | pCur->pKey = 0; |
| 50324 | 50332 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); |
| 50333 | + if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ | |
| 50334 | + pCur->eState = CURSOR_SKIPNEXT; | |
| 50335 | + } | |
| 50325 | 50336 | } |
| 50326 | 50337 | return rc; |
| 50327 | 50338 | } |
| 50328 | 50339 | |
| 50329 | 50340 | #define restoreCursorPosition(p) \ |
| @@ -50345,11 +50356,11 @@ | ||
| 50345 | 50356 | rc = restoreCursorPosition(pCur); |
| 50346 | 50357 | if( rc ){ |
| 50347 | 50358 | *pHasMoved = 1; |
| 50348 | 50359 | return rc; |
| 50349 | 50360 | } |
| 50350 | - if( pCur->eState!=CURSOR_VALID || pCur->skipNext!=0 ){ | |
| 50361 | + if( pCur->eState!=CURSOR_VALID || NEVER(pCur->skipNext!=0) ){ | |
| 50351 | 50362 | *pHasMoved = 1; |
| 50352 | 50363 | }else{ |
| 50353 | 50364 | *pHasMoved = 0; |
| 50354 | 50365 | } |
| 50355 | 50366 | return SQLITE_OK; |
| @@ -54392,25 +54403,33 @@ | ||
| 54392 | 54403 | int rc; |
| 54393 | 54404 | int idx; |
| 54394 | 54405 | MemPage *pPage; |
| 54395 | 54406 | |
| 54396 | 54407 | assert( cursorHoldsMutex(pCur) ); |
| 54397 | - rc = restoreCursorPosition(pCur); | |
| 54398 | - if( rc!=SQLITE_OK ){ | |
| 54399 | - return rc; | |
| 54400 | - } | |
| 54401 | 54408 | assert( pRes!=0 ); |
| 54402 | - if( CURSOR_INVALID==pCur->eState ){ | |
| 54403 | - *pRes = 1; | |
| 54404 | - return SQLITE_OK; | |
| 54405 | - } | |
| 54406 | - if( pCur->skipNext>0 ){ | |
| 54407 | - pCur->skipNext = 0; | |
| 54408 | - *pRes = 0; | |
| 54409 | - return SQLITE_OK; | |
| 54410 | - } | |
| 54411 | - pCur->skipNext = 0; | |
| 54409 | + assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); | |
| 54410 | + if( pCur->eState!=CURSOR_VALID ){ | |
| 54411 | + rc = restoreCursorPosition(pCur); | |
| 54412 | + if( rc!=SQLITE_OK ){ | |
| 54413 | + *pRes = 0; | |
| 54414 | + return rc; | |
| 54415 | + } | |
| 54416 | + if( CURSOR_INVALID==pCur->eState ){ | |
| 54417 | + *pRes = 1; | |
| 54418 | + return SQLITE_OK; | |
| 54419 | + } | |
| 54420 | + if( pCur->skipNext ){ | |
| 54421 | + assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); | |
| 54422 | + pCur->eState = CURSOR_VALID; | |
| 54423 | + if( pCur->skipNext>0 ){ | |
| 54424 | + pCur->skipNext = 0; | |
| 54425 | + *pRes = 0; | |
| 54426 | + return SQLITE_OK; | |
| 54427 | + } | |
| 54428 | + pCur->skipNext = 0; | |
| 54429 | + } | |
| 54430 | + } | |
| 54412 | 54431 | |
| 54413 | 54432 | pPage = pCur->apPage[pCur->iPage]; |
| 54414 | 54433 | idx = ++pCur->aiIdx[pCur->iPage]; |
| 54415 | 54434 | assert( pPage->isInit ); |
| 54416 | 54435 | |
| @@ -54424,11 +54443,14 @@ | ||
| 54424 | 54443 | pCur->info.nSize = 0; |
| 54425 | 54444 | pCur->validNKey = 0; |
| 54426 | 54445 | if( idx>=pPage->nCell ){ |
| 54427 | 54446 | if( !pPage->leaf ){ |
| 54428 | 54447 | rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8])); |
| 54429 | - if( rc ) return rc; | |
| 54448 | + if( rc ){ | |
| 54449 | + *pRes = 0; | |
| 54450 | + return rc; | |
| 54451 | + } | |
| 54430 | 54452 | rc = moveToLeftmost(pCur); |
| 54431 | 54453 | *pRes = 0; |
| 54432 | 54454 | return rc; |
| 54433 | 54455 | } |
| 54434 | 54456 | do{ |
| @@ -54466,32 +54488,44 @@ | ||
| 54466 | 54488 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){ |
| 54467 | 54489 | int rc; |
| 54468 | 54490 | MemPage *pPage; |
| 54469 | 54491 | |
| 54470 | 54492 | assert( cursorHoldsMutex(pCur) ); |
| 54471 | - rc = restoreCursorPosition(pCur); | |
| 54472 | - if( rc!=SQLITE_OK ){ | |
| 54473 | - return rc; | |
| 54474 | - } | |
| 54493 | + assert( pRes!=0 ); | |
| 54494 | + assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); | |
| 54475 | 54495 | pCur->atLast = 0; |
| 54476 | - if( CURSOR_INVALID==pCur->eState ){ | |
| 54477 | - *pRes = 1; | |
| 54478 | - return SQLITE_OK; | |
| 54479 | - } | |
| 54480 | - if( pCur->skipNext<0 ){ | |
| 54481 | - pCur->skipNext = 0; | |
| 54482 | - *pRes = 0; | |
| 54483 | - return SQLITE_OK; | |
| 54484 | - } | |
| 54485 | - pCur->skipNext = 0; | |
| 54496 | + if( pCur->eState!=CURSOR_VALID ){ | |
| 54497 | + if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){ | |
| 54498 | + rc = btreeRestoreCursorPosition(pCur); | |
| 54499 | + if( rc!=SQLITE_OK ){ | |
| 54500 | + *pRes = 0; | |
| 54501 | + return rc; | |
| 54502 | + } | |
| 54503 | + } | |
| 54504 | + if( CURSOR_INVALID==pCur->eState ){ | |
| 54505 | + *pRes = 1; | |
| 54506 | + return SQLITE_OK; | |
| 54507 | + } | |
| 54508 | + if( pCur->skipNext ){ | |
| 54509 | + assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); | |
| 54510 | + pCur->eState = CURSOR_VALID; | |
| 54511 | + if( pCur->skipNext<0 ){ | |
| 54512 | + pCur->skipNext = 0; | |
| 54513 | + *pRes = 0; | |
| 54514 | + return SQLITE_OK; | |
| 54515 | + } | |
| 54516 | + pCur->skipNext = 0; | |
| 54517 | + } | |
| 54518 | + } | |
| 54486 | 54519 | |
| 54487 | 54520 | pPage = pCur->apPage[pCur->iPage]; |
| 54488 | 54521 | assert( pPage->isInit ); |
| 54489 | 54522 | if( !pPage->leaf ){ |
| 54490 | 54523 | int idx = pCur->aiIdx[pCur->iPage]; |
| 54491 | 54524 | rc = moveToChild(pCur, get4byte(findCell(pPage, idx))); |
| 54492 | 54525 | if( rc ){ |
| 54526 | + *pRes = 0; | |
| 54493 | 54527 | return rc; |
| 54494 | 54528 | } |
| 54495 | 54529 | rc = moveToRightmost(pCur); |
| 54496 | 54530 | }else{ |
| 54497 | 54531 | while( pCur->aiIdx[pCur->iPage]==0 ){ |
| @@ -63508,16 +63542,18 @@ | ||
| 63508 | 63542 | sqlite3VdbeMemSetDouble(&pCtx->s, rVal); |
| 63509 | 63543 | } |
| 63510 | 63544 | SQLITE_API void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ |
| 63511 | 63545 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63512 | 63546 | pCtx->isError = SQLITE_ERROR; |
| 63547 | + pCtx->fErrorOrAux = 1; | |
| 63513 | 63548 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63514 | 63549 | } |
| 63515 | 63550 | #ifndef SQLITE_OMIT_UTF16 |
| 63516 | 63551 | SQLITE_API void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ |
| 63517 | 63552 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63518 | 63553 | pCtx->isError = SQLITE_ERROR; |
| 63554 | + pCtx->fErrorOrAux = 1; | |
| 63519 | 63555 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); |
| 63520 | 63556 | } |
| 63521 | 63557 | #endif |
| 63522 | 63558 | SQLITE_API void sqlite3_result_int(sqlite3_context *pCtx, int iVal){ |
| 63523 | 63559 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| @@ -63577,10 +63613,11 @@ | ||
| 63577 | 63613 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63578 | 63614 | sqlite3VdbeMemSetZeroBlob(&pCtx->s, n); |
| 63579 | 63615 | } |
| 63580 | 63616 | SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ |
| 63581 | 63617 | pCtx->isError = errCode; |
| 63618 | + pCtx->fErrorOrAux = 1; | |
| 63582 | 63619 | if( pCtx->s.flags & MEM_Null ){ |
| 63583 | 63620 | sqlite3VdbeMemSetStr(&pCtx->s, sqlite3ErrStr(errCode), -1, |
| 63584 | 63621 | SQLITE_UTF8, SQLITE_STATIC); |
| 63585 | 63622 | } |
| 63586 | 63623 | } |
| @@ -63587,19 +63624,21 @@ | ||
| 63587 | 63624 | |
| 63588 | 63625 | /* Force an SQLITE_TOOBIG error. */ |
| 63589 | 63626 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){ |
| 63590 | 63627 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63591 | 63628 | pCtx->isError = SQLITE_TOOBIG; |
| 63629 | + pCtx->fErrorOrAux = 1; | |
| 63592 | 63630 | sqlite3VdbeMemSetStr(&pCtx->s, "string or blob too big", -1, |
| 63593 | 63631 | SQLITE_UTF8, SQLITE_STATIC); |
| 63594 | 63632 | } |
| 63595 | 63633 | |
| 63596 | 63634 | /* An SQLITE_NOMEM error. */ |
| 63597 | 63635 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){ |
| 63598 | 63636 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63599 | 63637 | sqlite3VdbeMemSetNull(&pCtx->s); |
| 63600 | 63638 | pCtx->isError = SQLITE_NOMEM; |
| 63639 | + pCtx->fErrorOrAux = 1; | |
| 63601 | 63640 | pCtx->s.db->mallocFailed = 1; |
| 63602 | 63641 | } |
| 63603 | 63642 | |
| 63604 | 63643 | /* |
| 63605 | 63644 | ** This function is called after a transaction has been committed. It |
| @@ -63918,10 +63957,14 @@ | ||
| 63918 | 63957 | if( !pAuxData ) goto failed; |
| 63919 | 63958 | pAuxData->iOp = pCtx->iOp; |
| 63920 | 63959 | pAuxData->iArg = iArg; |
| 63921 | 63960 | pAuxData->pNext = pVdbe->pAuxData; |
| 63922 | 63961 | pVdbe->pAuxData = pAuxData; |
| 63962 | + if( pCtx->fErrorOrAux==0 ){ | |
| 63963 | + pCtx->isError = 0; | |
| 63964 | + pCtx->fErrorOrAux = 1; | |
| 63965 | + } | |
| 63923 | 63966 | }else if( pAuxData->xDelete ){ |
| 63924 | 63967 | pAuxData->xDelete(pAuxData->pAux); |
| 63925 | 63968 | } |
| 63926 | 63969 | |
| 63927 | 63970 | pAuxData->pAux = pAux; |
| @@ -64586,13 +64629,13 @@ | ||
| 64586 | 64629 | /* |
| 64587 | 64630 | ** Return the value of a status counter for a prepared statement |
| 64588 | 64631 | */ |
| 64589 | 64632 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 64590 | 64633 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 64591 | - int v = pVdbe->aCounter[op-1]; | |
| 64592 | - if( resetFlag ) pVdbe->aCounter[op-1] = 0; | |
| 64593 | - return v; | |
| 64634 | + u32 v = pVdbe->aCounter[op]; | |
| 64635 | + if( resetFlag ) pVdbe->aCounter[op] = 0; | |
| 64636 | + return (int)v; | |
| 64594 | 64637 | } |
| 64595 | 64638 | |
| 64596 | 64639 | /************** End of vdbeapi.c *********************************************/ |
| 64597 | 64640 | /************** Begin file vdbetrace.c ***************************************/ |
| 64598 | 64641 | /* |
| @@ -65995,11 +66038,11 @@ | ||
| 65995 | 66038 | CHECK_FOR_INTERRUPT; |
| 65996 | 66039 | sqlite3VdbeIOTraceSql(p); |
| 65997 | 66040 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 65998 | 66041 | if( db->xProgress ){ |
| 65999 | 66042 | assert( 0 < db->nProgressOps ); |
| 66000 | - nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1]; | |
| 66043 | + nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; | |
| 66001 | 66044 | if( nProgressLimit==0 ){ |
| 66002 | 66045 | nProgressLimit = db->nProgressOps; |
| 66003 | 66046 | }else{ |
| 66004 | 66047 | nProgressLimit %= (unsigned)db->nProgressOps; |
| 66005 | 66048 | } |
| @@ -66874,11 +66917,11 @@ | ||
| 66874 | 66917 | ** the already allocated buffer instead of allocating a new one. |
| 66875 | 66918 | */ |
| 66876 | 66919 | sqlite3VdbeMemMove(&u.ai.ctx.s, pOut); |
| 66877 | 66920 | MemSetTypeFlag(&u.ai.ctx.s, MEM_Null); |
| 66878 | 66921 | |
| 66879 | - u.ai.ctx.isError = 0; | |
| 66922 | + u.ai.ctx.fErrorOrAux = 0; | |
| 66880 | 66923 | if( u.ai.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){ |
| 66881 | 66924 | assert( pOp>aOp ); |
| 66882 | 66925 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 66883 | 66926 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 66884 | 66927 | u.ai.ctx.pColl = pOp[-1].p4.pColl; |
| @@ -66885,15 +66928,10 @@ | ||
| 66885 | 66928 | } |
| 66886 | 66929 | db->lastRowid = lastRowid; |
| 66887 | 66930 | (*u.ai.ctx.pFunc->xFunc)(&u.ai.ctx, u.ai.n, u.ai.apVal); /* IMP: R-24505-23230 */ |
| 66888 | 66931 | lastRowid = db->lastRowid; |
| 66889 | 66932 | |
| 66890 | - /* If any auxiliary data functions have been called by this user function, | |
| 66891 | - ** immediately call the destructor for any non-static values. | |
| 66892 | - */ | |
| 66893 | - sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); | |
| 66894 | - | |
| 66895 | 66933 | if( db->mallocFailed ){ |
| 66896 | 66934 | /* Even though a malloc() has failed, the implementation of the |
| 66897 | 66935 | ** user function may have called an sqlite3_result_XXX() function |
| 66898 | 66936 | ** to return a value. The following call releases any resources |
| 66899 | 66937 | ** associated with such a value. |
| @@ -66901,13 +66939,16 @@ | ||
| 66901 | 66939 | sqlite3VdbeMemRelease(&u.ai.ctx.s); |
| 66902 | 66940 | goto no_mem; |
| 66903 | 66941 | } |
| 66904 | 66942 | |
| 66905 | 66943 | /* If the function returned an error, throw an exception */ |
| 66906 | - if( u.ai.ctx.isError ){ | |
| 66907 | - sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ai.ctx.s)); | |
| 66908 | - rc = u.ai.ctx.isError; | |
| 66944 | + if( u.ai.ctx.fErrorOrAux ){ | |
| 66945 | + if( u.ai.ctx.isError ){ | |
| 66946 | + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ai.ctx.s)); | |
| 66947 | + rc = u.ai.ctx.isError; | |
| 66948 | + } | |
| 66949 | + sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); | |
| 66909 | 66950 | } |
| 66910 | 66951 | |
| 66911 | 66952 | /* Copy the result of the function into register P3 */ |
| 66912 | 66953 | sqlite3VdbeChangeEncoding(&u.ai.ctx.s, encoding); |
| 66913 | 66954 | sqlite3VdbeMemMove(pOut, &u.ai.ctx.s); |
| @@ -67279,16 +67320,16 @@ | ||
| 67279 | 67320 | }else{ |
| 67280 | 67321 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 67281 | 67322 | ** then the result is always NULL. |
| 67282 | 67323 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| 67283 | 67324 | */ |
| 67284 | - if( pOp->p5 & SQLITE_STOREP2 ){ | |
| 67325 | + if( pOp->p5 & SQLITE_JUMPIFNULL ){ | |
| 67326 | + pc = pOp->p2-1; | |
| 67327 | + }else if( pOp->p5 & SQLITE_STOREP2 ){ | |
| 67285 | 67328 | pOut = &aMem[pOp->p2]; |
| 67286 | 67329 | MemSetTypeFlag(pOut, MEM_Null); |
| 67287 | 67330 | REGISTER_TRACE(pOp->p2, pOut); |
| 67288 | - }else if( pOp->p5 & SQLITE_JUMPIFNULL ){ | |
| 67289 | - pc = pOp->p2-1; | |
| 67290 | 67331 | } |
| 67291 | 67332 | break; |
| 67292 | 67333 | } |
| 67293 | 67334 | }else{ |
| 67294 | 67335 | /* Neither operand is NULL. Do a comparison. */ |
| @@ -69931,11 +69972,11 @@ | ||
| 69931 | 69972 | case OP_Sort: { /* jump */ |
| 69932 | 69973 | #ifdef SQLITE_TEST |
| 69933 | 69974 | sqlite3_sort_count++; |
| 69934 | 69975 | sqlite3_search_count--; |
| 69935 | 69976 | #endif |
| 69936 | - p->aCounter[SQLITE_STMTSTATUS_SORT-1]++; | |
| 69977 | + p->aCounter[SQLITE_STMTSTATUS_SORT]++; | |
| 69937 | 69978 | /* Fall through into OP_Rewind */ |
| 69938 | 69979 | } |
| 69939 | 69980 | /* Opcode: Rewind P1 P2 * * * |
| 69940 | 69981 | ** |
| 69941 | 69982 | ** The next use of the Rowid or Column or Next instruction for P1 |
| @@ -70014,21 +70055,21 @@ | ||
| 70014 | 70055 | VdbeCursor *pC; |
| 70015 | 70056 | int res; |
| 70016 | 70057 | #endif /* local variables moved into u.br */ |
| 70017 | 70058 | |
| 70018 | 70059 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70019 | - assert( pOp->p5<=ArraySize(p->aCounter) ); | |
| 70060 | + assert( pOp->p5<ArraySize(p->aCounter) ); | |
| 70020 | 70061 | u.br.pC = p->apCsr[pOp->p1]; |
| 70021 | 70062 | if( u.br.pC==0 ){ |
| 70022 | 70063 | break; /* See ticket #2273 */ |
| 70023 | 70064 | } |
| 70024 | 70065 | assert( u.br.pC->isSorter==(pOp->opcode==OP_SorterNext) ); |
| 70025 | 70066 | if( isSorter(u.br.pC) ){ |
| 70026 | 70067 | assert( pOp->opcode==OP_SorterNext ); |
| 70027 | 70068 | rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res); |
| 70028 | 70069 | }else{ |
| 70029 | - u.br.res = 1; | |
| 70070 | + /* u.br.res = 1; // Always initialized by the xAdvance() call */ | |
| 70030 | 70071 | assert( u.br.pC->deferredMoveto==0 ); |
| 70031 | 70072 | assert( u.br.pC->pCursor ); |
| 70032 | 70073 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70033 | 70074 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 70034 | 70075 | rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res); |
| @@ -70035,11 +70076,11 @@ | ||
| 70035 | 70076 | } |
| 70036 | 70077 | u.br.pC->nullRow = (u8)u.br.res; |
| 70037 | 70078 | u.br.pC->cacheStatus = CACHE_STALE; |
| 70038 | 70079 | if( u.br.res==0 ){ |
| 70039 | 70080 | pc = pOp->p2 - 1; |
| 70040 | - if( pOp->p5 ) p->aCounter[pOp->p5-1]++; | |
| 70081 | + p->aCounter[pOp->p5]++; | |
| 70041 | 70082 | #ifdef SQLITE_TEST |
| 70042 | 70083 | sqlite3_search_count++; |
| 70043 | 70084 | #endif |
| 70044 | 70085 | } |
| 70045 | 70086 | u.br.pC->rowidIsValid = 0; |
| @@ -71792,11 +71833,11 @@ | ||
| 71792 | 71833 | ** release the mutexes on btrees that were acquired at the |
| 71793 | 71834 | ** top. */ |
| 71794 | 71835 | vdbe_return: |
| 71795 | 71836 | db->lastRowid = lastRowid; |
| 71796 | 71837 | testcase( nVmStep>0 ); |
| 71797 | - p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep; | |
| 71838 | + p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; | |
| 71798 | 71839 | sqlite3VdbeLeave(p); |
| 71799 | 71840 | return rc; |
| 71800 | 71841 | |
| 71801 | 71842 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 71802 | 71843 | ** is encountered. |
| @@ -76717,10 +76758,11 @@ | ||
| 76717 | 76758 | break; |
| 76718 | 76759 | } |
| 76719 | 76760 | case TK_UMINUS: { |
| 76720 | 76761 | int v; |
| 76721 | 76762 | if( sqlite3ExprIsInteger(p->pLeft, &v) ){ |
| 76763 | + assert( v!=-2147483648 ); | |
| 76722 | 76764 | *pValue = -v; |
| 76723 | 76765 | rc = 1; |
| 76724 | 76766 | } |
| 76725 | 76767 | break; |
| 76726 | 76768 | } |
| @@ -109074,11 +109116,13 @@ | ||
| 109074 | 109116 | rLogSize = estLog(whereCost(pProbe->aiRowEst[0])); |
| 109075 | 109117 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 109076 | 109118 | int nIn = 0; |
| 109077 | 109119 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 109078 | 109120 | #ifdef SQLITE_ENABLE_STAT3 |
| 109079 | - if( (pTerm->wtFlags & TERM_VNULL)!=0 && pSrc->pTab->aCol[iCol].notNull ){ | |
| 109121 | + if( (pTerm->wtFlags & TERM_VNULL)!=0 | |
| 109122 | + && (iCol<0 || pSrc->pTab->aCol[iCol].notNull) | |
| 109123 | + ){ | |
| 109080 | 109124 | continue; /* skip IS NOT NULL constraints on a NOT NULL column */ |
| 109081 | 109125 | } |
| 109082 | 109126 | #endif |
| 109083 | 109127 | pNew->wsFlags = saved_wsFlags; |
| 109084 | 109128 | pNew->u.btree.nEq = saved_nEq; |
| @@ -109217,10 +109261,11 @@ | ||
| 109217 | 109261 | static Bitmask columnsInIndex(Index *pIdx){ |
| 109218 | 109262 | Bitmask m = 0; |
| 109219 | 109263 | int j; |
| 109220 | 109264 | for(j=pIdx->nColumn-1; j>=0; j--){ |
| 109221 | 109265 | int x = pIdx->aiColumn[j]; |
| 109266 | + assert( x>=0 ); | |
| 109222 | 109267 | testcase( x==BMS-1 ); |
| 109223 | 109268 | testcase( x==BMS-2 ); |
| 109224 | 109269 | if( x<BMS-1 ) m |= MASKBIT(x); |
| 109225 | 109270 | } |
| 109226 | 109271 | return m; |
| @@ -130932,11 +130977,11 @@ | ||
| 130932 | 130977 | while( 1 ){ |
| 130933 | 130978 | |
| 130934 | 130979 | /* The following line of code (and the "p++" below the while() loop) is |
| 130935 | 130980 | ** normally all that is required to move pointer p to the desired |
| 130936 | 130981 | ** position. The exception is if this node is being loaded from disk |
| 130937 | - ** incrementally and pointer "p" now points to the first byte passed | |
| 130982 | + ** incrementally and pointer "p" now points to the first byte past | |
| 130938 | 130983 | ** the populated part of pReader->aNode[]. |
| 130939 | 130984 | */ |
| 130940 | 130985 | while( *p | c ) c = *p++ & 0x80; |
| 130941 | 130986 | assert( *p==0 ); |
| 130942 | 130987 | |
| @@ -132319,12 +132364,12 @@ | ||
| 132319 | 132364 | fts3SegReaderFirstDocid(p, apSegment[i]); |
| 132320 | 132365 | } |
| 132321 | 132366 | fts3SegReaderSort(apSegment, nMerge, nMerge, xCmp); |
| 132322 | 132367 | while( apSegment[0]->pOffsetList ){ |
| 132323 | 132368 | int j; /* Number of segments that share a docid */ |
| 132324 | - char *pList; | |
| 132325 | - int nList; | |
| 132369 | + char *pList = 0; | |
| 132370 | + int nList = 0; | |
| 132326 | 132371 | int nByte; |
| 132327 | 132372 | sqlite3_int64 iDocid = apSegment[0]->iDocid; |
| 132328 | 132373 | fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList); |
| 132329 | 132374 | j = 1; |
| 132330 | 132375 | while( j<nMerge |
| @@ -135393,10 +135438,11 @@ | ||
| 135393 | 135438 | return SQLITE_NOMEM; |
| 135394 | 135439 | } |
| 135395 | 135440 | pStr->z = zNew; |
| 135396 | 135441 | pStr->nAlloc = nAlloc; |
| 135397 | 135442 | } |
| 135443 | + assert( pStr->z!=0 && (pStr->nAlloc >= pStr->n+nAppend+1) ); | |
| 135398 | 135444 | |
| 135399 | 135445 | /* Append the data to the string buffer. */ |
| 135400 | 135446 | memcpy(&pStr->z[pStr->n], zAppend, nAppend); |
| 135401 | 135447 | pStr->n += nAppend; |
| 135402 | 135448 | pStr->z[pStr->n] = '\0'; |
| 135403 | 135449 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -656,11 +656,11 @@ | |
| 656 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 657 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 658 | */ |
| 659 | #define SQLITE_VERSION "3.8.0" |
| 660 | #define SQLITE_VERSION_NUMBER 3008000 |
| 661 | #define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a" |
| 662 | |
| 663 | /* |
| 664 | ** CAPI3REF: Run-Time Library Version Numbers |
| 665 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 666 | ** |
| @@ -13486,14 +13486,15 @@ | |
| 13486 | struct sqlite3_context { |
| 13487 | FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ |
| 13488 | Mem s; /* The return value is stored here */ |
| 13489 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 13490 | CollSeq *pColl; /* Collating sequence */ |
| 13491 | int isError; /* Error code returned by the function. */ |
| 13492 | int skipFlag; /* Skip skip accumulator loading if true */ |
| 13493 | int iOp; /* Instruction number of OP_Function */ |
| 13494 | Vdbe *pVdbe; /* The VM that owns this context */ |
| 13495 | }; |
| 13496 | |
| 13497 | /* |
| 13498 | ** An Explain object accumulates indented output which is helpful |
| 13499 | ** in describing recursive data structures. |
| @@ -13565,11 +13566,11 @@ | |
| 13565 | bft doingRerun:1; /* True if rerunning after an auto-reprepare */ |
| 13566 | int nChange; /* Number of db changes made since last reset */ |
| 13567 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 13568 | yDbMask lockMask; /* Subset of btreeMask that requires a lock */ |
| 13569 | int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 13570 | int aCounter[4]; /* Counters used by sqlite3_stmt_status() */ |
| 13571 | #ifndef SQLITE_OMIT_TRACE |
| 13572 | i64 startTime; /* Time when query started - used for profiling */ |
| 13573 | #endif |
| 13574 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 13575 | i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| @@ -37447,10 +37448,11 @@ | |
| 37447 | } |
| 37448 | |
| 37449 | if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){ |
| 37450 | goto fetch_out; |
| 37451 | } |
| 37452 | |
| 37453 | /* Step 4. Try to recycle a page. */ |
| 37454 | if( pCache->bPurgeable && pGroup->pLruTail && ( |
| 37455 | (pCache->nPage+1>=pCache->nMax) |
| 37456 | || pGroup->nCurrentPage>=pGroup->nMaxPage |
| @@ -49181,18 +49183,23 @@ | |
| 49181 | }; |
| 49182 | |
| 49183 | /* |
| 49184 | ** Potential values for BtCursor.eState. |
| 49185 | ** |
| 49186 | ** CURSOR_VALID: |
| 49187 | ** Cursor points to a valid entry. getPayload() etc. may be called. |
| 49188 | ** |
| 49189 | ** CURSOR_INVALID: |
| 49190 | ** Cursor does not point to a valid entry. This can happen (for example) |
| 49191 | ** because the table is empty or because BtreeCursorFirst() has not been |
| 49192 | ** called. |
| 49193 | ** |
| 49194 | ** CURSOR_REQUIRESEEK: |
| 49195 | ** The table that this cursor was opened on still exists, but has been |
| 49196 | ** modified since the cursor was last used. The cursor position is saved |
| 49197 | ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in |
| 49198 | ** this state, restoreCursorPosition() can be called to attempt to |
| @@ -49205,12 +49212,13 @@ | |
| 49205 | ** Do nothing else with this cursor. Any attempt to use the cursor |
| 49206 | ** should return the error code stored in BtCursor.skip |
| 49207 | */ |
| 49208 | #define CURSOR_INVALID 0 |
| 49209 | #define CURSOR_VALID 1 |
| 49210 | #define CURSOR_REQUIRESEEK 2 |
| 49211 | #define CURSOR_FAULT 3 |
| 49212 | |
| 49213 | /* |
| 49214 | ** The database page the PENDING_BYTE occupies. This page is never used. |
| 49215 | */ |
| 49216 | # define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt) |
| @@ -50320,10 +50328,13 @@ | |
| 50320 | rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skipNext); |
| 50321 | if( rc==SQLITE_OK ){ |
| 50322 | sqlite3_free(pCur->pKey); |
| 50323 | pCur->pKey = 0; |
| 50324 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); |
| 50325 | } |
| 50326 | return rc; |
| 50327 | } |
| 50328 | |
| 50329 | #define restoreCursorPosition(p) \ |
| @@ -50345,11 +50356,11 @@ | |
| 50345 | rc = restoreCursorPosition(pCur); |
| 50346 | if( rc ){ |
| 50347 | *pHasMoved = 1; |
| 50348 | return rc; |
| 50349 | } |
| 50350 | if( pCur->eState!=CURSOR_VALID || pCur->skipNext!=0 ){ |
| 50351 | *pHasMoved = 1; |
| 50352 | }else{ |
| 50353 | *pHasMoved = 0; |
| 50354 | } |
| 50355 | return SQLITE_OK; |
| @@ -54392,25 +54403,33 @@ | |
| 54392 | int rc; |
| 54393 | int idx; |
| 54394 | MemPage *pPage; |
| 54395 | |
| 54396 | assert( cursorHoldsMutex(pCur) ); |
| 54397 | rc = restoreCursorPosition(pCur); |
| 54398 | if( rc!=SQLITE_OK ){ |
| 54399 | return rc; |
| 54400 | } |
| 54401 | assert( pRes!=0 ); |
| 54402 | if( CURSOR_INVALID==pCur->eState ){ |
| 54403 | *pRes = 1; |
| 54404 | return SQLITE_OK; |
| 54405 | } |
| 54406 | if( pCur->skipNext>0 ){ |
| 54407 | pCur->skipNext = 0; |
| 54408 | *pRes = 0; |
| 54409 | return SQLITE_OK; |
| 54410 | } |
| 54411 | pCur->skipNext = 0; |
| 54412 | |
| 54413 | pPage = pCur->apPage[pCur->iPage]; |
| 54414 | idx = ++pCur->aiIdx[pCur->iPage]; |
| 54415 | assert( pPage->isInit ); |
| 54416 | |
| @@ -54424,11 +54443,14 @@ | |
| 54424 | pCur->info.nSize = 0; |
| 54425 | pCur->validNKey = 0; |
| 54426 | if( idx>=pPage->nCell ){ |
| 54427 | if( !pPage->leaf ){ |
| 54428 | rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8])); |
| 54429 | if( rc ) return rc; |
| 54430 | rc = moveToLeftmost(pCur); |
| 54431 | *pRes = 0; |
| 54432 | return rc; |
| 54433 | } |
| 54434 | do{ |
| @@ -54466,32 +54488,44 @@ | |
| 54466 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){ |
| 54467 | int rc; |
| 54468 | MemPage *pPage; |
| 54469 | |
| 54470 | assert( cursorHoldsMutex(pCur) ); |
| 54471 | rc = restoreCursorPosition(pCur); |
| 54472 | if( rc!=SQLITE_OK ){ |
| 54473 | return rc; |
| 54474 | } |
| 54475 | pCur->atLast = 0; |
| 54476 | if( CURSOR_INVALID==pCur->eState ){ |
| 54477 | *pRes = 1; |
| 54478 | return SQLITE_OK; |
| 54479 | } |
| 54480 | if( pCur->skipNext<0 ){ |
| 54481 | pCur->skipNext = 0; |
| 54482 | *pRes = 0; |
| 54483 | return SQLITE_OK; |
| 54484 | } |
| 54485 | pCur->skipNext = 0; |
| 54486 | |
| 54487 | pPage = pCur->apPage[pCur->iPage]; |
| 54488 | assert( pPage->isInit ); |
| 54489 | if( !pPage->leaf ){ |
| 54490 | int idx = pCur->aiIdx[pCur->iPage]; |
| 54491 | rc = moveToChild(pCur, get4byte(findCell(pPage, idx))); |
| 54492 | if( rc ){ |
| 54493 | return rc; |
| 54494 | } |
| 54495 | rc = moveToRightmost(pCur); |
| 54496 | }else{ |
| 54497 | while( pCur->aiIdx[pCur->iPage]==0 ){ |
| @@ -63508,16 +63542,18 @@ | |
| 63508 | sqlite3VdbeMemSetDouble(&pCtx->s, rVal); |
| 63509 | } |
| 63510 | SQLITE_API void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ |
| 63511 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63512 | pCtx->isError = SQLITE_ERROR; |
| 63513 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63514 | } |
| 63515 | #ifndef SQLITE_OMIT_UTF16 |
| 63516 | SQLITE_API void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ |
| 63517 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63518 | pCtx->isError = SQLITE_ERROR; |
| 63519 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); |
| 63520 | } |
| 63521 | #endif |
| 63522 | SQLITE_API void sqlite3_result_int(sqlite3_context *pCtx, int iVal){ |
| 63523 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| @@ -63577,10 +63613,11 @@ | |
| 63577 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63578 | sqlite3VdbeMemSetZeroBlob(&pCtx->s, n); |
| 63579 | } |
| 63580 | SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ |
| 63581 | pCtx->isError = errCode; |
| 63582 | if( pCtx->s.flags & MEM_Null ){ |
| 63583 | sqlite3VdbeMemSetStr(&pCtx->s, sqlite3ErrStr(errCode), -1, |
| 63584 | SQLITE_UTF8, SQLITE_STATIC); |
| 63585 | } |
| 63586 | } |
| @@ -63587,19 +63624,21 @@ | |
| 63587 | |
| 63588 | /* Force an SQLITE_TOOBIG error. */ |
| 63589 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){ |
| 63590 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63591 | pCtx->isError = SQLITE_TOOBIG; |
| 63592 | sqlite3VdbeMemSetStr(&pCtx->s, "string or blob too big", -1, |
| 63593 | SQLITE_UTF8, SQLITE_STATIC); |
| 63594 | } |
| 63595 | |
| 63596 | /* An SQLITE_NOMEM error. */ |
| 63597 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){ |
| 63598 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63599 | sqlite3VdbeMemSetNull(&pCtx->s); |
| 63600 | pCtx->isError = SQLITE_NOMEM; |
| 63601 | pCtx->s.db->mallocFailed = 1; |
| 63602 | } |
| 63603 | |
| 63604 | /* |
| 63605 | ** This function is called after a transaction has been committed. It |
| @@ -63918,10 +63957,14 @@ | |
| 63918 | if( !pAuxData ) goto failed; |
| 63919 | pAuxData->iOp = pCtx->iOp; |
| 63920 | pAuxData->iArg = iArg; |
| 63921 | pAuxData->pNext = pVdbe->pAuxData; |
| 63922 | pVdbe->pAuxData = pAuxData; |
| 63923 | }else if( pAuxData->xDelete ){ |
| 63924 | pAuxData->xDelete(pAuxData->pAux); |
| 63925 | } |
| 63926 | |
| 63927 | pAuxData->pAux = pAux; |
| @@ -64586,13 +64629,13 @@ | |
| 64586 | /* |
| 64587 | ** Return the value of a status counter for a prepared statement |
| 64588 | */ |
| 64589 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 64590 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 64591 | int v = pVdbe->aCounter[op-1]; |
| 64592 | if( resetFlag ) pVdbe->aCounter[op-1] = 0; |
| 64593 | return v; |
| 64594 | } |
| 64595 | |
| 64596 | /************** End of vdbeapi.c *********************************************/ |
| 64597 | /************** Begin file vdbetrace.c ***************************************/ |
| 64598 | /* |
| @@ -65995,11 +66038,11 @@ | |
| 65995 | CHECK_FOR_INTERRUPT; |
| 65996 | sqlite3VdbeIOTraceSql(p); |
| 65997 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 65998 | if( db->xProgress ){ |
| 65999 | assert( 0 < db->nProgressOps ); |
| 66000 | nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1]; |
| 66001 | if( nProgressLimit==0 ){ |
| 66002 | nProgressLimit = db->nProgressOps; |
| 66003 | }else{ |
| 66004 | nProgressLimit %= (unsigned)db->nProgressOps; |
| 66005 | } |
| @@ -66874,11 +66917,11 @@ | |
| 66874 | ** the already allocated buffer instead of allocating a new one. |
| 66875 | */ |
| 66876 | sqlite3VdbeMemMove(&u.ai.ctx.s, pOut); |
| 66877 | MemSetTypeFlag(&u.ai.ctx.s, MEM_Null); |
| 66878 | |
| 66879 | u.ai.ctx.isError = 0; |
| 66880 | if( u.ai.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){ |
| 66881 | assert( pOp>aOp ); |
| 66882 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 66883 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 66884 | u.ai.ctx.pColl = pOp[-1].p4.pColl; |
| @@ -66885,15 +66928,10 @@ | |
| 66885 | } |
| 66886 | db->lastRowid = lastRowid; |
| 66887 | (*u.ai.ctx.pFunc->xFunc)(&u.ai.ctx, u.ai.n, u.ai.apVal); /* IMP: R-24505-23230 */ |
| 66888 | lastRowid = db->lastRowid; |
| 66889 | |
| 66890 | /* If any auxiliary data functions have been called by this user function, |
| 66891 | ** immediately call the destructor for any non-static values. |
| 66892 | */ |
| 66893 | sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 66894 | |
| 66895 | if( db->mallocFailed ){ |
| 66896 | /* Even though a malloc() has failed, the implementation of the |
| 66897 | ** user function may have called an sqlite3_result_XXX() function |
| 66898 | ** to return a value. The following call releases any resources |
| 66899 | ** associated with such a value. |
| @@ -66901,13 +66939,16 @@ | |
| 66901 | sqlite3VdbeMemRelease(&u.ai.ctx.s); |
| 66902 | goto no_mem; |
| 66903 | } |
| 66904 | |
| 66905 | /* If the function returned an error, throw an exception */ |
| 66906 | if( u.ai.ctx.isError ){ |
| 66907 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ai.ctx.s)); |
| 66908 | rc = u.ai.ctx.isError; |
| 66909 | } |
| 66910 | |
| 66911 | /* Copy the result of the function into register P3 */ |
| 66912 | sqlite3VdbeChangeEncoding(&u.ai.ctx.s, encoding); |
| 66913 | sqlite3VdbeMemMove(pOut, &u.ai.ctx.s); |
| @@ -67279,16 +67320,16 @@ | |
| 67279 | }else{ |
| 67280 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 67281 | ** then the result is always NULL. |
| 67282 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| 67283 | */ |
| 67284 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 67285 | pOut = &aMem[pOp->p2]; |
| 67286 | MemSetTypeFlag(pOut, MEM_Null); |
| 67287 | REGISTER_TRACE(pOp->p2, pOut); |
| 67288 | }else if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 67289 | pc = pOp->p2-1; |
| 67290 | } |
| 67291 | break; |
| 67292 | } |
| 67293 | }else{ |
| 67294 | /* Neither operand is NULL. Do a comparison. */ |
| @@ -69931,11 +69972,11 @@ | |
| 69931 | case OP_Sort: { /* jump */ |
| 69932 | #ifdef SQLITE_TEST |
| 69933 | sqlite3_sort_count++; |
| 69934 | sqlite3_search_count--; |
| 69935 | #endif |
| 69936 | p->aCounter[SQLITE_STMTSTATUS_SORT-1]++; |
| 69937 | /* Fall through into OP_Rewind */ |
| 69938 | } |
| 69939 | /* Opcode: Rewind P1 P2 * * * |
| 69940 | ** |
| 69941 | ** The next use of the Rowid or Column or Next instruction for P1 |
| @@ -70014,21 +70055,21 @@ | |
| 70014 | VdbeCursor *pC; |
| 70015 | int res; |
| 70016 | #endif /* local variables moved into u.br */ |
| 70017 | |
| 70018 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70019 | assert( pOp->p5<=ArraySize(p->aCounter) ); |
| 70020 | u.br.pC = p->apCsr[pOp->p1]; |
| 70021 | if( u.br.pC==0 ){ |
| 70022 | break; /* See ticket #2273 */ |
| 70023 | } |
| 70024 | assert( u.br.pC->isSorter==(pOp->opcode==OP_SorterNext) ); |
| 70025 | if( isSorter(u.br.pC) ){ |
| 70026 | assert( pOp->opcode==OP_SorterNext ); |
| 70027 | rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res); |
| 70028 | }else{ |
| 70029 | u.br.res = 1; |
| 70030 | assert( u.br.pC->deferredMoveto==0 ); |
| 70031 | assert( u.br.pC->pCursor ); |
| 70032 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70033 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 70034 | rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res); |
| @@ -70035,11 +70076,11 @@ | |
| 70035 | } |
| 70036 | u.br.pC->nullRow = (u8)u.br.res; |
| 70037 | u.br.pC->cacheStatus = CACHE_STALE; |
| 70038 | if( u.br.res==0 ){ |
| 70039 | pc = pOp->p2 - 1; |
| 70040 | if( pOp->p5 ) p->aCounter[pOp->p5-1]++; |
| 70041 | #ifdef SQLITE_TEST |
| 70042 | sqlite3_search_count++; |
| 70043 | #endif |
| 70044 | } |
| 70045 | u.br.pC->rowidIsValid = 0; |
| @@ -71792,11 +71833,11 @@ | |
| 71792 | ** release the mutexes on btrees that were acquired at the |
| 71793 | ** top. */ |
| 71794 | vdbe_return: |
| 71795 | db->lastRowid = lastRowid; |
| 71796 | testcase( nVmStep>0 ); |
| 71797 | p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep; |
| 71798 | sqlite3VdbeLeave(p); |
| 71799 | return rc; |
| 71800 | |
| 71801 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 71802 | ** is encountered. |
| @@ -76717,10 +76758,11 @@ | |
| 76717 | break; |
| 76718 | } |
| 76719 | case TK_UMINUS: { |
| 76720 | int v; |
| 76721 | if( sqlite3ExprIsInteger(p->pLeft, &v) ){ |
| 76722 | *pValue = -v; |
| 76723 | rc = 1; |
| 76724 | } |
| 76725 | break; |
| 76726 | } |
| @@ -109074,11 +109116,13 @@ | |
| 109074 | rLogSize = estLog(whereCost(pProbe->aiRowEst[0])); |
| 109075 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 109076 | int nIn = 0; |
| 109077 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 109078 | #ifdef SQLITE_ENABLE_STAT3 |
| 109079 | if( (pTerm->wtFlags & TERM_VNULL)!=0 && pSrc->pTab->aCol[iCol].notNull ){ |
| 109080 | continue; /* skip IS NOT NULL constraints on a NOT NULL column */ |
| 109081 | } |
| 109082 | #endif |
| 109083 | pNew->wsFlags = saved_wsFlags; |
| 109084 | pNew->u.btree.nEq = saved_nEq; |
| @@ -109217,10 +109261,11 @@ | |
| 109217 | static Bitmask columnsInIndex(Index *pIdx){ |
| 109218 | Bitmask m = 0; |
| 109219 | int j; |
| 109220 | for(j=pIdx->nColumn-1; j>=0; j--){ |
| 109221 | int x = pIdx->aiColumn[j]; |
| 109222 | testcase( x==BMS-1 ); |
| 109223 | testcase( x==BMS-2 ); |
| 109224 | if( x<BMS-1 ) m |= MASKBIT(x); |
| 109225 | } |
| 109226 | return m; |
| @@ -130932,11 +130977,11 @@ | |
| 130932 | while( 1 ){ |
| 130933 | |
| 130934 | /* The following line of code (and the "p++" below the while() loop) is |
| 130935 | ** normally all that is required to move pointer p to the desired |
| 130936 | ** position. The exception is if this node is being loaded from disk |
| 130937 | ** incrementally and pointer "p" now points to the first byte passed |
| 130938 | ** the populated part of pReader->aNode[]. |
| 130939 | */ |
| 130940 | while( *p | c ) c = *p++ & 0x80; |
| 130941 | assert( *p==0 ); |
| 130942 | |
| @@ -132319,12 +132364,12 @@ | |
| 132319 | fts3SegReaderFirstDocid(p, apSegment[i]); |
| 132320 | } |
| 132321 | fts3SegReaderSort(apSegment, nMerge, nMerge, xCmp); |
| 132322 | while( apSegment[0]->pOffsetList ){ |
| 132323 | int j; /* Number of segments that share a docid */ |
| 132324 | char *pList; |
| 132325 | int nList; |
| 132326 | int nByte; |
| 132327 | sqlite3_int64 iDocid = apSegment[0]->iDocid; |
| 132328 | fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList); |
| 132329 | j = 1; |
| 132330 | while( j<nMerge |
| @@ -135393,10 +135438,11 @@ | |
| 135393 | return SQLITE_NOMEM; |
| 135394 | } |
| 135395 | pStr->z = zNew; |
| 135396 | pStr->nAlloc = nAlloc; |
| 135397 | } |
| 135398 | |
| 135399 | /* Append the data to the string buffer. */ |
| 135400 | memcpy(&pStr->z[pStr->n], zAppend, nAppend); |
| 135401 | pStr->n += nAppend; |
| 135402 | pStr->z[pStr->n] = '\0'; |
| 135403 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -656,11 +656,11 @@ | |
| 656 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 657 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 658 | */ |
| 659 | #define SQLITE_VERSION "3.8.0" |
| 660 | #define SQLITE_VERSION_NUMBER 3008000 |
| 661 | #define SQLITE_SOURCE_ID "2013-08-20 03:13:51 7f72fc4f47445a2c01910b268335873de9f75059" |
| 662 | |
| 663 | /* |
| 664 | ** CAPI3REF: Run-Time Library Version Numbers |
| 665 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 666 | ** |
| @@ -13486,14 +13486,15 @@ | |
| 13486 | struct sqlite3_context { |
| 13487 | FuncDef *pFunc; /* Pointer to function information. MUST BE FIRST */ |
| 13488 | Mem s; /* The return value is stored here */ |
| 13489 | Mem *pMem; /* Memory cell used to store aggregate context */ |
| 13490 | CollSeq *pColl; /* Collating sequence */ |
| 13491 | Vdbe *pVdbe; /* The VM that owns this context */ |
| 13492 | int iOp; /* Instruction number of OP_Function */ |
| 13493 | int isError; /* Error code returned by the function. */ |
| 13494 | u8 skipFlag; /* Skip skip accumulator loading if true */ |
| 13495 | u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */ |
| 13496 | }; |
| 13497 | |
| 13498 | /* |
| 13499 | ** An Explain object accumulates indented output which is helpful |
| 13500 | ** in describing recursive data structures. |
| @@ -13565,11 +13566,11 @@ | |
| 13566 | bft doingRerun:1; /* True if rerunning after an auto-reprepare */ |
| 13567 | int nChange; /* Number of db changes made since last reset */ |
| 13568 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 13569 | yDbMask lockMask; /* Subset of btreeMask that requires a lock */ |
| 13570 | int iStatement; /* Statement number (or 0 if has not opened stmt) */ |
| 13571 | u32 aCounter[5]; /* Counters used by sqlite3_stmt_status() */ |
| 13572 | #ifndef SQLITE_OMIT_TRACE |
| 13573 | i64 startTime; /* Time when query started - used for profiling */ |
| 13574 | #endif |
| 13575 | i64 nFkConstraint; /* Number of imm. FK constraints this VM */ |
| 13576 | i64 nStmtDefCons; /* Number of def. constraints when stmt started */ |
| @@ -37447,10 +37448,11 @@ | |
| 37448 | } |
| 37449 | |
| 37450 | if( pCache->nPage>=pCache->nHash && pcache1ResizeHash(pCache) ){ |
| 37451 | goto fetch_out; |
| 37452 | } |
| 37453 | assert( pCache->nHash>0 && pCache->apHash ); |
| 37454 | |
| 37455 | /* Step 4. Try to recycle a page. */ |
| 37456 | if( pCache->bPurgeable && pGroup->pLruTail && ( |
| 37457 | (pCache->nPage+1>=pCache->nMax) |
| 37458 | || pGroup->nCurrentPage>=pGroup->nMaxPage |
| @@ -49181,18 +49183,23 @@ | |
| 49183 | }; |
| 49184 | |
| 49185 | /* |
| 49186 | ** Potential values for BtCursor.eState. |
| 49187 | ** |
| 49188 | ** CURSOR_INVALID: |
| 49189 | ** Cursor does not point to a valid entry. This can happen (for example) |
| 49190 | ** because the table is empty or because BtreeCursorFirst() has not been |
| 49191 | ** called. |
| 49192 | ** |
| 49193 | ** CURSOR_VALID: |
| 49194 | ** Cursor points to a valid entry. getPayload() etc. may be called. |
| 49195 | ** |
| 49196 | ** CURSOR_SKIPNEXT: |
| 49197 | ** Cursor is valid except that the Cursor.skipNext field is non-zero |
| 49198 | ** indicating that the next sqlite3BtreeNext() or sqlite3BtreePrevious() |
| 49199 | ** operation should be a no-op. |
| 49200 | ** |
| 49201 | ** CURSOR_REQUIRESEEK: |
| 49202 | ** The table that this cursor was opened on still exists, but has been |
| 49203 | ** modified since the cursor was last used. The cursor position is saved |
| 49204 | ** in variables BtCursor.pKey and BtCursor.nKey. When a cursor is in |
| 49205 | ** this state, restoreCursorPosition() can be called to attempt to |
| @@ -49205,12 +49212,13 @@ | |
| 49212 | ** Do nothing else with this cursor. Any attempt to use the cursor |
| 49213 | ** should return the error code stored in BtCursor.skip |
| 49214 | */ |
| 49215 | #define CURSOR_INVALID 0 |
| 49216 | #define CURSOR_VALID 1 |
| 49217 | #define CURSOR_SKIPNEXT 2 |
| 49218 | #define CURSOR_REQUIRESEEK 3 |
| 49219 | #define CURSOR_FAULT 4 |
| 49220 | |
| 49221 | /* |
| 49222 | ** The database page the PENDING_BYTE occupies. This page is never used. |
| 49223 | */ |
| 49224 | # define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt) |
| @@ -50320,10 +50328,13 @@ | |
| 50328 | rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skipNext); |
| 50329 | if( rc==SQLITE_OK ){ |
| 50330 | sqlite3_free(pCur->pKey); |
| 50331 | pCur->pKey = 0; |
| 50332 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID ); |
| 50333 | if( pCur->skipNext && pCur->eState==CURSOR_VALID ){ |
| 50334 | pCur->eState = CURSOR_SKIPNEXT; |
| 50335 | } |
| 50336 | } |
| 50337 | return rc; |
| 50338 | } |
| 50339 | |
| 50340 | #define restoreCursorPosition(p) \ |
| @@ -50345,11 +50356,11 @@ | |
| 50356 | rc = restoreCursorPosition(pCur); |
| 50357 | if( rc ){ |
| 50358 | *pHasMoved = 1; |
| 50359 | return rc; |
| 50360 | } |
| 50361 | if( pCur->eState!=CURSOR_VALID || NEVER(pCur->skipNext!=0) ){ |
| 50362 | *pHasMoved = 1; |
| 50363 | }else{ |
| 50364 | *pHasMoved = 0; |
| 50365 | } |
| 50366 | return SQLITE_OK; |
| @@ -54392,25 +54403,33 @@ | |
| 54403 | int rc; |
| 54404 | int idx; |
| 54405 | MemPage *pPage; |
| 54406 | |
| 54407 | assert( cursorHoldsMutex(pCur) ); |
| 54408 | assert( pRes!=0 ); |
| 54409 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 54410 | if( pCur->eState!=CURSOR_VALID ){ |
| 54411 | rc = restoreCursorPosition(pCur); |
| 54412 | if( rc!=SQLITE_OK ){ |
| 54413 | *pRes = 0; |
| 54414 | return rc; |
| 54415 | } |
| 54416 | if( CURSOR_INVALID==pCur->eState ){ |
| 54417 | *pRes = 1; |
| 54418 | return SQLITE_OK; |
| 54419 | } |
| 54420 | if( pCur->skipNext ){ |
| 54421 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); |
| 54422 | pCur->eState = CURSOR_VALID; |
| 54423 | if( pCur->skipNext>0 ){ |
| 54424 | pCur->skipNext = 0; |
| 54425 | *pRes = 0; |
| 54426 | return SQLITE_OK; |
| 54427 | } |
| 54428 | pCur->skipNext = 0; |
| 54429 | } |
| 54430 | } |
| 54431 | |
| 54432 | pPage = pCur->apPage[pCur->iPage]; |
| 54433 | idx = ++pCur->aiIdx[pCur->iPage]; |
| 54434 | assert( pPage->isInit ); |
| 54435 | |
| @@ -54424,11 +54443,14 @@ | |
| 54443 | pCur->info.nSize = 0; |
| 54444 | pCur->validNKey = 0; |
| 54445 | if( idx>=pPage->nCell ){ |
| 54446 | if( !pPage->leaf ){ |
| 54447 | rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8])); |
| 54448 | if( rc ){ |
| 54449 | *pRes = 0; |
| 54450 | return rc; |
| 54451 | } |
| 54452 | rc = moveToLeftmost(pCur); |
| 54453 | *pRes = 0; |
| 54454 | return rc; |
| 54455 | } |
| 54456 | do{ |
| @@ -54466,32 +54488,44 @@ | |
| 54488 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){ |
| 54489 | int rc; |
| 54490 | MemPage *pPage; |
| 54491 | |
| 54492 | assert( cursorHoldsMutex(pCur) ); |
| 54493 | assert( pRes!=0 ); |
| 54494 | assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID ); |
| 54495 | pCur->atLast = 0; |
| 54496 | if( pCur->eState!=CURSOR_VALID ){ |
| 54497 | if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){ |
| 54498 | rc = btreeRestoreCursorPosition(pCur); |
| 54499 | if( rc!=SQLITE_OK ){ |
| 54500 | *pRes = 0; |
| 54501 | return rc; |
| 54502 | } |
| 54503 | } |
| 54504 | if( CURSOR_INVALID==pCur->eState ){ |
| 54505 | *pRes = 1; |
| 54506 | return SQLITE_OK; |
| 54507 | } |
| 54508 | if( pCur->skipNext ){ |
| 54509 | assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT ); |
| 54510 | pCur->eState = CURSOR_VALID; |
| 54511 | if( pCur->skipNext<0 ){ |
| 54512 | pCur->skipNext = 0; |
| 54513 | *pRes = 0; |
| 54514 | return SQLITE_OK; |
| 54515 | } |
| 54516 | pCur->skipNext = 0; |
| 54517 | } |
| 54518 | } |
| 54519 | |
| 54520 | pPage = pCur->apPage[pCur->iPage]; |
| 54521 | assert( pPage->isInit ); |
| 54522 | if( !pPage->leaf ){ |
| 54523 | int idx = pCur->aiIdx[pCur->iPage]; |
| 54524 | rc = moveToChild(pCur, get4byte(findCell(pPage, idx))); |
| 54525 | if( rc ){ |
| 54526 | *pRes = 0; |
| 54527 | return rc; |
| 54528 | } |
| 54529 | rc = moveToRightmost(pCur); |
| 54530 | }else{ |
| 54531 | while( pCur->aiIdx[pCur->iPage]==0 ){ |
| @@ -63508,16 +63542,18 @@ | |
| 63542 | sqlite3VdbeMemSetDouble(&pCtx->s, rVal); |
| 63543 | } |
| 63544 | SQLITE_API void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){ |
| 63545 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63546 | pCtx->isError = SQLITE_ERROR; |
| 63547 | pCtx->fErrorOrAux = 1; |
| 63548 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63549 | } |
| 63550 | #ifndef SQLITE_OMIT_UTF16 |
| 63551 | SQLITE_API void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){ |
| 63552 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63553 | pCtx->isError = SQLITE_ERROR; |
| 63554 | pCtx->fErrorOrAux = 1; |
| 63555 | sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT); |
| 63556 | } |
| 63557 | #endif |
| 63558 | SQLITE_API void sqlite3_result_int(sqlite3_context *pCtx, int iVal){ |
| 63559 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| @@ -63577,10 +63613,11 @@ | |
| 63613 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63614 | sqlite3VdbeMemSetZeroBlob(&pCtx->s, n); |
| 63615 | } |
| 63616 | SQLITE_API void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){ |
| 63617 | pCtx->isError = errCode; |
| 63618 | pCtx->fErrorOrAux = 1; |
| 63619 | if( pCtx->s.flags & MEM_Null ){ |
| 63620 | sqlite3VdbeMemSetStr(&pCtx->s, sqlite3ErrStr(errCode), -1, |
| 63621 | SQLITE_UTF8, SQLITE_STATIC); |
| 63622 | } |
| 63623 | } |
| @@ -63587,19 +63624,21 @@ | |
| 63624 | |
| 63625 | /* Force an SQLITE_TOOBIG error. */ |
| 63626 | SQLITE_API void sqlite3_result_error_toobig(sqlite3_context *pCtx){ |
| 63627 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63628 | pCtx->isError = SQLITE_TOOBIG; |
| 63629 | pCtx->fErrorOrAux = 1; |
| 63630 | sqlite3VdbeMemSetStr(&pCtx->s, "string or blob too big", -1, |
| 63631 | SQLITE_UTF8, SQLITE_STATIC); |
| 63632 | } |
| 63633 | |
| 63634 | /* An SQLITE_NOMEM error. */ |
| 63635 | SQLITE_API void sqlite3_result_error_nomem(sqlite3_context *pCtx){ |
| 63636 | assert( sqlite3_mutex_held(pCtx->s.db->mutex) ); |
| 63637 | sqlite3VdbeMemSetNull(&pCtx->s); |
| 63638 | pCtx->isError = SQLITE_NOMEM; |
| 63639 | pCtx->fErrorOrAux = 1; |
| 63640 | pCtx->s.db->mallocFailed = 1; |
| 63641 | } |
| 63642 | |
| 63643 | /* |
| 63644 | ** This function is called after a transaction has been committed. It |
| @@ -63918,10 +63957,14 @@ | |
| 63957 | if( !pAuxData ) goto failed; |
| 63958 | pAuxData->iOp = pCtx->iOp; |
| 63959 | pAuxData->iArg = iArg; |
| 63960 | pAuxData->pNext = pVdbe->pAuxData; |
| 63961 | pVdbe->pAuxData = pAuxData; |
| 63962 | if( pCtx->fErrorOrAux==0 ){ |
| 63963 | pCtx->isError = 0; |
| 63964 | pCtx->fErrorOrAux = 1; |
| 63965 | } |
| 63966 | }else if( pAuxData->xDelete ){ |
| 63967 | pAuxData->xDelete(pAuxData->pAux); |
| 63968 | } |
| 63969 | |
| 63970 | pAuxData->pAux = pAux; |
| @@ -64586,13 +64629,13 @@ | |
| 64629 | /* |
| 64630 | ** Return the value of a status counter for a prepared statement |
| 64631 | */ |
| 64632 | SQLITE_API int sqlite3_stmt_status(sqlite3_stmt *pStmt, int op, int resetFlag){ |
| 64633 | Vdbe *pVdbe = (Vdbe*)pStmt; |
| 64634 | u32 v = pVdbe->aCounter[op]; |
| 64635 | if( resetFlag ) pVdbe->aCounter[op] = 0; |
| 64636 | return (int)v; |
| 64637 | } |
| 64638 | |
| 64639 | /************** End of vdbeapi.c *********************************************/ |
| 64640 | /************** Begin file vdbetrace.c ***************************************/ |
| 64641 | /* |
| @@ -65995,11 +66038,11 @@ | |
| 66038 | CHECK_FOR_INTERRUPT; |
| 66039 | sqlite3VdbeIOTraceSql(p); |
| 66040 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| 66041 | if( db->xProgress ){ |
| 66042 | assert( 0 < db->nProgressOps ); |
| 66043 | nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP]; |
| 66044 | if( nProgressLimit==0 ){ |
| 66045 | nProgressLimit = db->nProgressOps; |
| 66046 | }else{ |
| 66047 | nProgressLimit %= (unsigned)db->nProgressOps; |
| 66048 | } |
| @@ -66874,11 +66917,11 @@ | |
| 66917 | ** the already allocated buffer instead of allocating a new one. |
| 66918 | */ |
| 66919 | sqlite3VdbeMemMove(&u.ai.ctx.s, pOut); |
| 66920 | MemSetTypeFlag(&u.ai.ctx.s, MEM_Null); |
| 66921 | |
| 66922 | u.ai.ctx.fErrorOrAux = 0; |
| 66923 | if( u.ai.ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){ |
| 66924 | assert( pOp>aOp ); |
| 66925 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 66926 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 66927 | u.ai.ctx.pColl = pOp[-1].p4.pColl; |
| @@ -66885,15 +66928,10 @@ | |
| 66928 | } |
| 66929 | db->lastRowid = lastRowid; |
| 66930 | (*u.ai.ctx.pFunc->xFunc)(&u.ai.ctx, u.ai.n, u.ai.apVal); /* IMP: R-24505-23230 */ |
| 66931 | lastRowid = db->lastRowid; |
| 66932 | |
| 66933 | if( db->mallocFailed ){ |
| 66934 | /* Even though a malloc() has failed, the implementation of the |
| 66935 | ** user function may have called an sqlite3_result_XXX() function |
| 66936 | ** to return a value. The following call releases any resources |
| 66937 | ** associated with such a value. |
| @@ -66901,13 +66939,16 @@ | |
| 66939 | sqlite3VdbeMemRelease(&u.ai.ctx.s); |
| 66940 | goto no_mem; |
| 66941 | } |
| 66942 | |
| 66943 | /* If the function returned an error, throw an exception */ |
| 66944 | if( u.ai.ctx.fErrorOrAux ){ |
| 66945 | if( u.ai.ctx.isError ){ |
| 66946 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.ai.ctx.s)); |
| 66947 | rc = u.ai.ctx.isError; |
| 66948 | } |
| 66949 | sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 66950 | } |
| 66951 | |
| 66952 | /* Copy the result of the function into register P3 */ |
| 66953 | sqlite3VdbeChangeEncoding(&u.ai.ctx.s, encoding); |
| 66954 | sqlite3VdbeMemMove(pOut, &u.ai.ctx.s); |
| @@ -67279,16 +67320,16 @@ | |
| 67320 | }else{ |
| 67321 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 67322 | ** then the result is always NULL. |
| 67323 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| 67324 | */ |
| 67325 | if( pOp->p5 & SQLITE_JUMPIFNULL ){ |
| 67326 | pc = pOp->p2-1; |
| 67327 | }else if( pOp->p5 & SQLITE_STOREP2 ){ |
| 67328 | pOut = &aMem[pOp->p2]; |
| 67329 | MemSetTypeFlag(pOut, MEM_Null); |
| 67330 | REGISTER_TRACE(pOp->p2, pOut); |
| 67331 | } |
| 67332 | break; |
| 67333 | } |
| 67334 | }else{ |
| 67335 | /* Neither operand is NULL. Do a comparison. */ |
| @@ -69931,11 +69972,11 @@ | |
| 69972 | case OP_Sort: { /* jump */ |
| 69973 | #ifdef SQLITE_TEST |
| 69974 | sqlite3_sort_count++; |
| 69975 | sqlite3_search_count--; |
| 69976 | #endif |
| 69977 | p->aCounter[SQLITE_STMTSTATUS_SORT]++; |
| 69978 | /* Fall through into OP_Rewind */ |
| 69979 | } |
| 69980 | /* Opcode: Rewind P1 P2 * * * |
| 69981 | ** |
| 69982 | ** The next use of the Rowid or Column or Next instruction for P1 |
| @@ -70014,21 +70055,21 @@ | |
| 70055 | VdbeCursor *pC; |
| 70056 | int res; |
| 70057 | #endif /* local variables moved into u.br */ |
| 70058 | |
| 70059 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70060 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 70061 | u.br.pC = p->apCsr[pOp->p1]; |
| 70062 | if( u.br.pC==0 ){ |
| 70063 | break; /* See ticket #2273 */ |
| 70064 | } |
| 70065 | assert( u.br.pC->isSorter==(pOp->opcode==OP_SorterNext) ); |
| 70066 | if( isSorter(u.br.pC) ){ |
| 70067 | assert( pOp->opcode==OP_SorterNext ); |
| 70068 | rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res); |
| 70069 | }else{ |
| 70070 | /* u.br.res = 1; // Always initialized by the xAdvance() call */ |
| 70071 | assert( u.br.pC->deferredMoveto==0 ); |
| 70072 | assert( u.br.pC->pCursor ); |
| 70073 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70074 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 70075 | rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res); |
| @@ -70035,11 +70076,11 @@ | |
| 70076 | } |
| 70077 | u.br.pC->nullRow = (u8)u.br.res; |
| 70078 | u.br.pC->cacheStatus = CACHE_STALE; |
| 70079 | if( u.br.res==0 ){ |
| 70080 | pc = pOp->p2 - 1; |
| 70081 | p->aCounter[pOp->p5]++; |
| 70082 | #ifdef SQLITE_TEST |
| 70083 | sqlite3_search_count++; |
| 70084 | #endif |
| 70085 | } |
| 70086 | u.br.pC->rowidIsValid = 0; |
| @@ -71792,11 +71833,11 @@ | |
| 71833 | ** release the mutexes on btrees that were acquired at the |
| 71834 | ** top. */ |
| 71835 | vdbe_return: |
| 71836 | db->lastRowid = lastRowid; |
| 71837 | testcase( nVmStep>0 ); |
| 71838 | p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; |
| 71839 | sqlite3VdbeLeave(p); |
| 71840 | return rc; |
| 71841 | |
| 71842 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| 71843 | ** is encountered. |
| @@ -76717,10 +76758,11 @@ | |
| 76758 | break; |
| 76759 | } |
| 76760 | case TK_UMINUS: { |
| 76761 | int v; |
| 76762 | if( sqlite3ExprIsInteger(p->pLeft, &v) ){ |
| 76763 | assert( v!=-2147483648 ); |
| 76764 | *pValue = -v; |
| 76765 | rc = 1; |
| 76766 | } |
| 76767 | break; |
| 76768 | } |
| @@ -109074,11 +109116,13 @@ | |
| 109116 | rLogSize = estLog(whereCost(pProbe->aiRowEst[0])); |
| 109117 | for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){ |
| 109118 | int nIn = 0; |
| 109119 | if( pTerm->prereqRight & pNew->maskSelf ) continue; |
| 109120 | #ifdef SQLITE_ENABLE_STAT3 |
| 109121 | if( (pTerm->wtFlags & TERM_VNULL)!=0 |
| 109122 | && (iCol<0 || pSrc->pTab->aCol[iCol].notNull) |
| 109123 | ){ |
| 109124 | continue; /* skip IS NOT NULL constraints on a NOT NULL column */ |
| 109125 | } |
| 109126 | #endif |
| 109127 | pNew->wsFlags = saved_wsFlags; |
| 109128 | pNew->u.btree.nEq = saved_nEq; |
| @@ -109217,10 +109261,11 @@ | |
| 109261 | static Bitmask columnsInIndex(Index *pIdx){ |
| 109262 | Bitmask m = 0; |
| 109263 | int j; |
| 109264 | for(j=pIdx->nColumn-1; j>=0; j--){ |
| 109265 | int x = pIdx->aiColumn[j]; |
| 109266 | assert( x>=0 ); |
| 109267 | testcase( x==BMS-1 ); |
| 109268 | testcase( x==BMS-2 ); |
| 109269 | if( x<BMS-1 ) m |= MASKBIT(x); |
| 109270 | } |
| 109271 | return m; |
| @@ -130932,11 +130977,11 @@ | |
| 130977 | while( 1 ){ |
| 130978 | |
| 130979 | /* The following line of code (and the "p++" below the while() loop) is |
| 130980 | ** normally all that is required to move pointer p to the desired |
| 130981 | ** position. The exception is if this node is being loaded from disk |
| 130982 | ** incrementally and pointer "p" now points to the first byte past |
| 130983 | ** the populated part of pReader->aNode[]. |
| 130984 | */ |
| 130985 | while( *p | c ) c = *p++ & 0x80; |
| 130986 | assert( *p==0 ); |
| 130987 | |
| @@ -132319,12 +132364,12 @@ | |
| 132364 | fts3SegReaderFirstDocid(p, apSegment[i]); |
| 132365 | } |
| 132366 | fts3SegReaderSort(apSegment, nMerge, nMerge, xCmp); |
| 132367 | while( apSegment[0]->pOffsetList ){ |
| 132368 | int j; /* Number of segments that share a docid */ |
| 132369 | char *pList = 0; |
| 132370 | int nList = 0; |
| 132371 | int nByte; |
| 132372 | sqlite3_int64 iDocid = apSegment[0]->iDocid; |
| 132373 | fts3SegReaderNextDocid(p, apSegment[0], &pList, &nList); |
| 132374 | j = 1; |
| 132375 | while( j<nMerge |
| @@ -135393,10 +135438,11 @@ | |
| 135438 | return SQLITE_NOMEM; |
| 135439 | } |
| 135440 | pStr->z = zNew; |
| 135441 | pStr->nAlloc = nAlloc; |
| 135442 | } |
| 135443 | assert( pStr->z!=0 && (pStr->nAlloc >= pStr->n+nAppend+1) ); |
| 135444 | |
| 135445 | /* Append the data to the string buffer. */ |
| 135446 | memcpy(&pStr->z[pStr->n], zAppend, nAppend); |
| 135447 | pStr->n += nAppend; |
| 135448 | pStr->z[pStr->n] = '\0'; |
| 135449 |
+1
-1
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.8.0" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3008000 |
| 112 | -#define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a" | |
| 112 | +#define SQLITE_SOURCE_ID "2013-08-20 03:13:51 7f72fc4f47445a2c01910b268335873de9f75059" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| 118 | 118 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.0" |
| 111 | #define SQLITE_VERSION_NUMBER 3008000 |
| 112 | #define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| 118 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.0" |
| 111 | #define SQLITE_VERSION_NUMBER 3008000 |
| 112 | #define SQLITE_SOURCE_ID "2013-08-20 03:13:51 7f72fc4f47445a2c01910b268335873de9f75059" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| 118 |