| | @@ -1162,11 +1162,11 @@ |
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.27.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3027000 |
| 1167 | | -#define SQLITE_SOURCE_ID "2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5ccb8" |
| 1167 | +#define SQLITE_SOURCE_ID "2019-02-05 20:51:41 4d0a949fd92e19fbf243a2e3a1a7c2cdb111f9a6943949d2420dd846bc7d9285" |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| | @@ -4466,10 +4466,12 @@ |
| 4466 | 4466 | ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and |
| 4467 | 4467 | ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and |
| 4468 | 4468 | ** is not a database file pathname pointer that SQLite passed into the xOpen |
| 4469 | 4469 | ** VFS method, then the behavior of this routine is undefined and probably |
| 4470 | 4470 | ** undesirable. |
| 4471 | +** |
| 4472 | +** See the [URI filename] documentation for additional information. |
| 4471 | 4473 | */ |
| 4472 | 4474 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); |
| 4473 | 4475 | SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); |
| 4474 | 4476 | SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 4475 | 4477 | |
| | @@ -14556,10 +14558,11 @@ |
| 14556 | 14558 | SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*); |
| 14557 | 14559 | #endif |
| 14558 | 14560 | SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*); |
| 14559 | 14561 | SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); |
| 14560 | 14562 | SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*); |
| 14563 | +SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*); |
| 14561 | 14564 | |
| 14562 | 14565 | SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*); |
| 14563 | 14566 | SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); |
| 14564 | 14567 | SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*); |
| 14565 | 14568 | |
| | @@ -18772,10 +18775,15 @@ |
| 18772 | 18775 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*); |
| 18773 | 18776 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 18774 | 18777 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); |
| 18775 | 18778 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 18776 | 18779 | sqlite3_vfs**,char**,char **); |
| 18780 | +#ifdef SQLITE_HAS_CODEC |
| 18781 | +SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*); |
| 18782 | +#else |
| 18783 | +# define sqlite3CodecQueryParameters(A,B,C) 0 |
| 18784 | +#endif |
| 18777 | 18785 | SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*); |
| 18778 | 18786 | |
| 18779 | 18787 | #ifdef SQLITE_UNTESTABLE |
| 18780 | 18788 | # define sqlite3FaultSim(X) SQLITE_OK |
| 18781 | 18789 | #else |
| | @@ -27323,10 +27331,31 @@ |
| 27323 | 27331 | static char *getTextArg(PrintfArguments *p){ |
| 27324 | 27332 | if( p->nArg<=p->nUsed ) return 0; |
| 27325 | 27333 | return (char*)sqlite3_value_text(p->apArg[p->nUsed++]); |
| 27326 | 27334 | } |
| 27327 | 27335 | |
| 27336 | +/* |
| 27337 | +** Allocate memory for a temporary buffer needed for printf rendering. |
| 27338 | +** |
| 27339 | +** If the requested size of the temp buffer is larger than the size |
| 27340 | +** of the output buffer in pAccum, then cause an SQLITE_TOOBIG error. |
| 27341 | +** Do the size check before the memory allocation to prevent rogue |
| 27342 | +** SQL from requesting large allocations using the precision or width |
| 27343 | +** field of the printf() function. |
| 27344 | +*/ |
| 27345 | +static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){ |
| 27346 | + char *z; |
| 27347 | + if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){ |
| 27348 | + setStrAccumError(pAccum, SQLITE_TOOBIG); |
| 27349 | + return 0; |
| 27350 | + } |
| 27351 | + z = sqlite3DbMallocRaw(pAccum->db, n); |
| 27352 | + if( z==0 ){ |
| 27353 | + setStrAccumError(pAccum, SQLITE_NOMEM); |
| 27354 | + } |
| 27355 | + return z; |
| 27356 | +} |
| 27328 | 27357 | |
| 27329 | 27358 | /* |
| 27330 | 27359 | ** On machines with a small stack size, you can redefine the |
| 27331 | 27360 | ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. |
| 27332 | 27361 | */ |
| | @@ -27405,10 +27434,13 @@ |
| 27405 | 27434 | } |
| 27406 | 27435 | /* Find out what flags are present */ |
| 27407 | 27436 | flag_leftjustify = flag_prefix = cThousand = |
| 27408 | 27437 | flag_alternateform = flag_altform2 = flag_zeropad = 0; |
| 27409 | 27438 | done = 0; |
| 27439 | + width = 0; |
| 27440 | + flag_long = 0; |
| 27441 | + precision = -1; |
| 27410 | 27442 | do{ |
| 27411 | 27443 | switch( c ){ |
| 27412 | 27444 | case '-': flag_leftjustify = 1; break; |
| 27413 | 27445 | case '+': flag_prefix = '+'; break; |
| 27414 | 27446 | case ' ': flag_prefix = ' '; break; |
| | @@ -27415,84 +27447,97 @@ |
| 27415 | 27447 | case '#': flag_alternateform = 1; break; |
| 27416 | 27448 | case '!': flag_altform2 = 1; break; |
| 27417 | 27449 | case '0': flag_zeropad = 1; break; |
| 27418 | 27450 | case ',': cThousand = ','; break; |
| 27419 | 27451 | default: done = 1; break; |
| 27452 | + case 'l': { |
| 27453 | + flag_long = 1; |
| 27454 | + c = *++fmt; |
| 27455 | + if( c=='l' ){ |
| 27456 | + c = *++fmt; |
| 27457 | + flag_long = 2; |
| 27458 | + } |
| 27459 | + done = 1; |
| 27460 | + break; |
| 27461 | + } |
| 27462 | + case '1': case '2': case '3': case '4': case '5': |
| 27463 | + case '6': case '7': case '8': case '9': { |
| 27464 | + unsigned wx = c - '0'; |
| 27465 | + while( (c = *++fmt)>='0' && c<='9' ){ |
| 27466 | + wx = wx*10 + c - '0'; |
| 27467 | + } |
| 27468 | + testcase( wx>0x7fffffff ); |
| 27469 | + width = wx & 0x7fffffff; |
| 27470 | +#ifdef SQLITE_PRINTF_PRECISION_LIMIT |
| 27471 | + if( width>SQLITE_PRINTF_PRECISION_LIMIT ){ |
| 27472 | + width = SQLITE_PRINTF_PRECISION_LIMIT; |
| 27473 | + } |
| 27474 | +#endif |
| 27475 | + if( c!='.' && c!='l' ){ |
| 27476 | + done = 1; |
| 27477 | + }else{ |
| 27478 | + fmt--; |
| 27479 | + } |
| 27480 | + break; |
| 27481 | + } |
| 27482 | + case '*': { |
| 27483 | + if( bArgList ){ |
| 27484 | + width = (int)getIntArg(pArgList); |
| 27485 | + }else{ |
| 27486 | + width = va_arg(ap,int); |
| 27487 | + } |
| 27488 | + if( width<0 ){ |
| 27489 | + flag_leftjustify = 1; |
| 27490 | + width = width >= -2147483647 ? -width : 0; |
| 27491 | + } |
| 27492 | +#ifdef SQLITE_PRINTF_PRECISION_LIMIT |
| 27493 | + if( width>SQLITE_PRINTF_PRECISION_LIMIT ){ |
| 27494 | + width = SQLITE_PRINTF_PRECISION_LIMIT; |
| 27495 | + } |
| 27496 | +#endif |
| 27497 | + if( (c = fmt[1])!='.' && c!='l' ){ |
| 27498 | + c = *++fmt; |
| 27499 | + done = 1; |
| 27500 | + } |
| 27501 | + break; |
| 27502 | + } |
| 27503 | + case '.': { |
| 27504 | + c = *++fmt; |
| 27505 | + if( c=='*' ){ |
| 27506 | + if( bArgList ){ |
| 27507 | + precision = (int)getIntArg(pArgList); |
| 27508 | + }else{ |
| 27509 | + precision = va_arg(ap,int); |
| 27510 | + } |
| 27511 | + if( precision<0 ){ |
| 27512 | + precision = precision >= -2147483647 ? -precision : -1; |
| 27513 | + } |
| 27514 | + c = *++fmt; |
| 27515 | + }else{ |
| 27516 | + unsigned px = 0; |
| 27517 | + while( c>='0' && c<='9' ){ |
| 27518 | + px = px*10 + c - '0'; |
| 27519 | + c = *++fmt; |
| 27520 | + } |
| 27521 | + testcase( px>0x7fffffff ); |
| 27522 | + precision = px & 0x7fffffff; |
| 27523 | + } |
| 27524 | +#ifdef SQLITE_PRINTF_PRECISION_LIMIT |
| 27525 | + if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){ |
| 27526 | + precision = SQLITE_PRINTF_PRECISION_LIMIT; |
| 27527 | + } |
| 27528 | +#endif |
| 27529 | + if( c=='l' ){ |
| 27530 | + --fmt; |
| 27531 | + }else{ |
| 27532 | + done = 1; |
| 27533 | + } |
| 27534 | + break; |
| 27535 | + } |
| 27420 | 27536 | } |
| 27421 | 27537 | }while( !done && (c=(*++fmt))!=0 ); |
| 27422 | | - /* Get the field width */ |
| 27423 | | - if( c=='*' ){ |
| 27424 | | - if( bArgList ){ |
| 27425 | | - width = (int)getIntArg(pArgList); |
| 27426 | | - }else{ |
| 27427 | | - width = va_arg(ap,int); |
| 27428 | | - } |
| 27429 | | - if( width<0 ){ |
| 27430 | | - flag_leftjustify = 1; |
| 27431 | | - width = width >= -2147483647 ? -width : 0; |
| 27432 | | - } |
| 27433 | | - c = *++fmt; |
| 27434 | | - }else{ |
| 27435 | | - unsigned wx = 0; |
| 27436 | | - while( c>='0' && c<='9' ){ |
| 27437 | | - wx = wx*10 + c - '0'; |
| 27438 | | - c = *++fmt; |
| 27439 | | - } |
| 27440 | | - testcase( wx>0x7fffffff ); |
| 27441 | | - width = wx & 0x7fffffff; |
| 27442 | | - } |
| 27443 | | - assert( width>=0 ); |
| 27444 | | -#ifdef SQLITE_PRINTF_PRECISION_LIMIT |
| 27445 | | - if( width>SQLITE_PRINTF_PRECISION_LIMIT ){ |
| 27446 | | - width = SQLITE_PRINTF_PRECISION_LIMIT; |
| 27447 | | - } |
| 27448 | | -#endif |
| 27449 | | - |
| 27450 | | - /* Get the precision */ |
| 27451 | | - if( c=='.' ){ |
| 27452 | | - c = *++fmt; |
| 27453 | | - if( c=='*' ){ |
| 27454 | | - if( bArgList ){ |
| 27455 | | - precision = (int)getIntArg(pArgList); |
| 27456 | | - }else{ |
| 27457 | | - precision = va_arg(ap,int); |
| 27458 | | - } |
| 27459 | | - c = *++fmt; |
| 27460 | | - if( precision<0 ){ |
| 27461 | | - precision = precision >= -2147483647 ? -precision : -1; |
| 27462 | | - } |
| 27463 | | - }else{ |
| 27464 | | - unsigned px = 0; |
| 27465 | | - while( c>='0' && c<='9' ){ |
| 27466 | | - px = px*10 + c - '0'; |
| 27467 | | - c = *++fmt; |
| 27468 | | - } |
| 27469 | | - testcase( px>0x7fffffff ); |
| 27470 | | - precision = px & 0x7fffffff; |
| 27471 | | - } |
| 27472 | | - }else{ |
| 27473 | | - precision = -1; |
| 27474 | | - } |
| 27475 | | - assert( precision>=(-1) ); |
| 27476 | | -#ifdef SQLITE_PRINTF_PRECISION_LIMIT |
| 27477 | | - if( precision>SQLITE_PRINTF_PRECISION_LIMIT ){ |
| 27478 | | - precision = SQLITE_PRINTF_PRECISION_LIMIT; |
| 27479 | | - } |
| 27480 | | -#endif |
| 27481 | | - |
| 27482 | | - |
| 27483 | | - /* Get the conversion type modifier */ |
| 27484 | | - if( c=='l' ){ |
| 27485 | | - flag_long = 1; |
| 27486 | | - c = *++fmt; |
| 27487 | | - if( c=='l' ){ |
| 27488 | | - flag_long = 2; |
| 27489 | | - c = *++fmt; |
| 27490 | | - } |
| 27491 | | - }else{ |
| 27492 | | - flag_long = 0; |
| 27493 | | - } |
| 27538 | + |
| 27494 | 27539 | /* Fetch the info entry for the field */ |
| 27495 | 27540 | infop = &fmtinfo[0]; |
| 27496 | 27541 | xtype = etINVALID; |
| 27497 | 27542 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| 27498 | 27543 | if( c==fmtinfo[idx].fmttype ){ |
| | @@ -27573,16 +27618,15 @@ |
| 27573 | 27618 | } |
| 27574 | 27619 | if( precision<etBUFSIZE-10-etBUFSIZE/3 ){ |
| 27575 | 27620 | nOut = etBUFSIZE; |
| 27576 | 27621 | zOut = buf; |
| 27577 | 27622 | }else{ |
| 27578 | | - u64 n = (u64)precision + 10 + precision/3; |
| 27579 | | - zOut = zExtra = sqlite3Malloc( n ); |
| 27580 | | - if( zOut==0 ){ |
| 27581 | | - setStrAccumError(pAccum, SQLITE_NOMEM); |
| 27582 | | - return; |
| 27583 | | - } |
| 27623 | + u64 n; |
| 27624 | + n = (u64)precision + 10; |
| 27625 | + if( cThousand ) n += precision/3; |
| 27626 | + zOut = zExtra = printfTempBuf(pAccum, n); |
| 27627 | + if( zOut==0 ) return; |
| 27584 | 27628 | nOut = (int)n; |
| 27585 | 27629 | } |
| 27586 | 27630 | bufpt = &zOut[nOut-1]; |
| 27587 | 27631 | if( xtype==etORDINAL ){ |
| 27588 | 27632 | static const char zOrd[] = "thstndrd"; |
| | @@ -27697,16 +27741,16 @@ |
| 27697 | 27741 | if( xtype==etEXP ){ |
| 27698 | 27742 | e2 = 0; |
| 27699 | 27743 | }else{ |
| 27700 | 27744 | e2 = exp; |
| 27701 | 27745 | } |
| 27702 | | - if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){ |
| 27703 | | - bufpt = zExtra |
| 27704 | | - = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 ); |
| 27705 | | - if( bufpt==0 ){ |
| 27706 | | - setStrAccumError(pAccum, SQLITE_NOMEM); |
| 27707 | | - return; |
| 27746 | + { |
| 27747 | + i64 szBufNeeded; /* Size of a temporary buffer needed */ |
| 27748 | + szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15; |
| 27749 | + if( szBufNeeded > etBUFSIZE ){ |
| 27750 | + bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded); |
| 27751 | + if( bufpt==0 ) return; |
| 27708 | 27752 | } |
| 27709 | 27753 | } |
| 27710 | 27754 | zOut = bufpt; |
| 27711 | 27755 | nsd = 16 + flag_altform2*10; |
| 27712 | 27756 | flag_dp = (precision>0 ?1:0) | flag_alternateform | flag_altform2; |
| | @@ -27926,15 +27970,12 @@ |
| 27926 | 27970 | } |
| 27927 | 27971 | } |
| 27928 | 27972 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 27929 | 27973 | n += i + 3; |
| 27930 | 27974 | if( n>etBUFSIZE ){ |
| 27931 | | - bufpt = zExtra = sqlite3Malloc( n ); |
| 27932 | | - if( bufpt==0 ){ |
| 27933 | | - setStrAccumError(pAccum, SQLITE_NOMEM); |
| 27934 | | - return; |
| 27935 | | - } |
| 27975 | + bufpt = zExtra = printfTempBuf(pAccum, n); |
| 27976 | + if( bufpt==0 ) return; |
| 27936 | 27977 | }else{ |
| 27937 | 27978 | bufpt = buf; |
| 27938 | 27979 | } |
| 27939 | 27980 | j = 0; |
| 27940 | 27981 | if( needQuote ) bufpt[j++] = q; |
| | @@ -67525,10 +67566,29 @@ |
| 67525 | 67566 | assert( cursorHoldsMutex(pCur) ); |
| 67526 | 67567 | assert( pCur->eState==CURSOR_VALID ); |
| 67527 | 67568 | getCellInfo(pCur); |
| 67528 | 67569 | return pCur->info.nPayload; |
| 67529 | 67570 | } |
| 67571 | + |
| 67572 | +/* |
| 67573 | +** Return an upper bound on the size of any record for the table |
| 67574 | +** that the cursor is pointing into. |
| 67575 | +** |
| 67576 | +** This is an optimization. Everything will still work if this |
| 67577 | +** routine always returns 2147483647 (which is the largest record |
| 67578 | +** that SQLite can handle) or more. But returning a smaller value might |
| 67579 | +** prevent large memory allocations when trying to interpret a |
| 67580 | +** corrupt datrabase. |
| 67581 | +** |
| 67582 | +** The current implementation merely returns the size of the underlying |
| 67583 | +** database file. |
| 67584 | +*/ |
| 67585 | +SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){ |
| 67586 | + assert( cursorHoldsMutex(pCur) ); |
| 67587 | + assert( pCur->eState==CURSOR_VALID ); |
| 67588 | + return pCur->pBt->pageSize * (sqlite3_int64)pCur->pBt->nPage; |
| 67589 | +} |
| 67530 | 67590 | |
| 67531 | 67591 | /* |
| 67532 | 67592 | ** Given the page number of an overflow page in the database (parameter |
| 67533 | 67593 | ** ovfl), this function finds the page number of the next page in the |
| 67534 | 67594 | ** linked list of overflow pages. If possible, it uses the auto-vacuum |
| | @@ -75268,10 +75328,13 @@ |
| 75268 | 75328 | u32 amt, /* Number of bytes to return. */ |
| 75269 | 75329 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 75270 | 75330 | ){ |
| 75271 | 75331 | int rc; |
| 75272 | 75332 | pMem->flags = MEM_Null; |
| 75333 | + if( sqlite3BtreeMaxRecordSize(pCur)<offset+amt ){ |
| 75334 | + return SQLITE_CORRUPT_BKPT; |
| 75335 | + } |
| 75273 | 75336 | if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+1)) ){ |
| 75274 | 75337 | rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z); |
| 75275 | 75338 | if( rc==SQLITE_OK ){ |
| 75276 | 75339 | pMem->z[amt] = 0; /* Overrun area used when reading malformed records */ |
| 75277 | 75340 | pMem->flags = MEM_Blob; |
| | @@ -101539,18 +101602,20 @@ |
| 101539 | 101602 | if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune; |
| 101540 | 101603 | switch( pExpr->op ){ |
| 101541 | 101604 | case TK_ISNOT: |
| 101542 | 101605 | case TK_NOT: |
| 101543 | 101606 | case TK_ISNULL: |
| 101607 | + case TK_NOTNULL: |
| 101544 | 101608 | case TK_IS: |
| 101545 | 101609 | case TK_OR: |
| 101546 | 101610 | case TK_CASE: |
| 101547 | 101611 | case TK_IN: |
| 101548 | 101612 | case TK_FUNCTION: |
| 101549 | 101613 | testcase( pExpr->op==TK_ISNOT ); |
| 101550 | 101614 | testcase( pExpr->op==TK_NOT ); |
| 101551 | 101615 | testcase( pExpr->op==TK_ISNULL ); |
| 101616 | + testcase( pExpr->op==TK_NOTNULL ); |
| 101552 | 101617 | testcase( pExpr->op==TK_IS ); |
| 101553 | 101618 | testcase( pExpr->op==TK_OR ); |
| 101554 | 101619 | testcase( pExpr->op==TK_CASE ); |
| 101555 | 101620 | testcase( pExpr->op==TK_IN ); |
| 101556 | 101621 | testcase( pExpr->op==TK_FUNCTION ); |
| | @@ -105763,12 +105828,12 @@ |
| 105763 | 105828 | return; |
| 105764 | 105829 | } |
| 105765 | 105830 | assert( pVfs ); |
| 105766 | 105831 | flags |= SQLITE_OPEN_MAIN_DB; |
| 105767 | 105832 | rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags); |
| 105768 | | - sqlite3_free( zPath ); |
| 105769 | 105833 | db->nDb++; |
| 105834 | + pNew->zDbSName = sqlite3DbStrDup(db, zName); |
| 105770 | 105835 | } |
| 105771 | 105836 | db->noSharedCache = 0; |
| 105772 | 105837 | if( rc==SQLITE_CONSTRAINT ){ |
| 105773 | 105838 | rc = SQLITE_ERROR; |
| 105774 | 105839 | zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
| | @@ -105792,11 +105857,10 @@ |
| 105792 | 105857 | PAGER_SYNCHRONOUS_FULL | (db->flags & PAGER_FLAGS_MASK)); |
| 105793 | 105858 | #endif |
| 105794 | 105859 | sqlite3BtreeLeave(pNew->pBt); |
| 105795 | 105860 | } |
| 105796 | 105861 | pNew->safety_level = SQLITE_DEFAULT_SYNCHRONOUS+1; |
| 105797 | | - if( !REOPEN_AS_MEMDB(db) ) pNew->zDbSName = sqlite3DbStrDup(db, zName); |
| 105798 | 105862 | if( rc==SQLITE_OK && pNew->zDbSName==0 ){ |
| 105799 | 105863 | rc = SQLITE_NOMEM_BKPT; |
| 105800 | 105864 | } |
| 105801 | 105865 | |
| 105802 | 105866 | |
| | @@ -105820,19 +105884,23 @@ |
| 105820 | 105884 | zKey = (char *)sqlite3_value_blob(argv[2]); |
| 105821 | 105885 | rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); |
| 105822 | 105886 | break; |
| 105823 | 105887 | |
| 105824 | 105888 | case SQLITE_NULL: |
| 105825 | | - /* No key specified. Use the key from the main database */ |
| 105826 | | - sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); |
| 105827 | | - if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){ |
| 105828 | | - rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); |
| 105889 | + /* No key specified. Use the key from URI filename, or if none, |
| 105890 | + ** use the key from the main database. */ |
| 105891 | + if( sqlite3CodecQueryParameters(db, zName, zPath)==0 ){ |
| 105892 | + sqlite3CodecGetKey(db, 0, (void**)&zKey, &nKey); |
| 105893 | + if( nKey || sqlite3BtreeGetOptimalReserve(db->aDb[0].pBt)>0 ){ |
| 105894 | + rc = sqlite3CodecAttach(db, db->nDb-1, zKey, nKey); |
| 105895 | + } |
| 105829 | 105896 | } |
| 105830 | 105897 | break; |
| 105831 | 105898 | } |
| 105832 | 105899 | } |
| 105833 | 105900 | #endif |
| 105901 | + sqlite3_free( zPath ); |
| 105834 | 105902 | |
| 105835 | 105903 | /* If the file was opened successfully, read the schema for the new database. |
| 105836 | 105904 | ** If this fails, or if opening the file failed, then close the file and |
| 105837 | 105905 | ** remove the entry from the db->aDb[] array. i.e. put everything back the |
| 105838 | 105906 | ** way we found it. |
| | @@ -118594,11 +118662,11 @@ |
| 118594 | 118662 | if( zSql==0 ) zSql = ""; |
| 118595 | 118663 | |
| 118596 | 118664 | sqlite3_mutex_enter(db->mutex); |
| 118597 | 118665 | sqlite3Error(db, SQLITE_OK); |
| 118598 | 118666 | while( rc==SQLITE_OK && zSql[0] ){ |
| 118599 | | - int nCol; |
| 118667 | + int nCol = 0; |
| 118600 | 118668 | char **azVals = 0; |
| 118601 | 118669 | |
| 118602 | 118670 | pStmt = 0; |
| 118603 | 118671 | rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover); |
| 118604 | 118672 | assert( rc==SQLITE_OK || pStmt==0 ); |
| | @@ -118608,13 +118676,11 @@ |
| 118608 | 118676 | if( !pStmt ){ |
| 118609 | 118677 | /* this happens for a comment or white-space */ |
| 118610 | 118678 | zSql = zLeftover; |
| 118611 | 118679 | continue; |
| 118612 | 118680 | } |
| 118613 | | - |
| 118614 | 118681 | callbackIsInit = 0; |
| 118615 | | - nCol = sqlite3_column_count(pStmt); |
| 118616 | 118682 | |
| 118617 | 118683 | while( 1 ){ |
| 118618 | 118684 | int i; |
| 118619 | 118685 | rc = sqlite3_step(pStmt); |
| 118620 | 118686 | |
| | @@ -118621,10 +118687,11 @@ |
| 118621 | 118687 | /* Invoke the callback function if required */ |
| 118622 | 118688 | if( xCallback && (SQLITE_ROW==rc || |
| 118623 | 118689 | (SQLITE_DONE==rc && !callbackIsInit |
| 118624 | 118690 | && db->flags&SQLITE_NullCallback)) ){ |
| 118625 | 118691 | if( !callbackIsInit ){ |
| 118692 | + nCol = sqlite3_column_count(pStmt); |
| 118626 | 118693 | azCols = sqlite3DbMallocRaw(db, (2*nCol+1)*sizeof(const char*)); |
| 118627 | 118694 | if( azCols==0 ){ |
| 118628 | 118695 | goto exec_out; |
| 118629 | 118696 | } |
| 118630 | 118697 | for(i=0; i<nCol; i++){ |
| | @@ -120404,17 +120471,15 @@ |
| 120404 | 120471 | /* ColNames: */ 0, 0, |
| 120405 | 120472 | /* iArg: */ SQLITE_CountRows }, |
| 120406 | 120473 | #endif |
| 120407 | 120474 | #endif |
| 120408 | 120475 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN |
| 120409 | | -#if !defined(SQLITE_OMIT_DEPRECATED) |
| 120410 | 120476 | {/* zName: */ "data_store_directory", |
| 120411 | 120477 | /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY, |
| 120412 | 120478 | /* ePragFlg: */ PragFlg_NoColumns1, |
| 120413 | 120479 | /* ColNames: */ 0, 0, |
| 120414 | 120480 | /* iArg: */ 0 }, |
| 120415 | | -#endif |
| 120416 | 120481 | #endif |
| 120417 | 120482 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 120418 | 120483 | {/* zName: */ "data_version", |
| 120419 | 120484 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 120420 | 120485 | /* ePragFlg: */ PragFlg_ReadOnly|PragFlg_Result0, |
| | @@ -120787,19 +120852,15 @@ |
| 120787 | 120852 | {/* zName: */ "temp_store", |
| 120788 | 120853 | /* ePragTyp: */ PragTyp_TEMP_STORE, |
| 120789 | 120854 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 120790 | 120855 | /* ColNames: */ 0, 0, |
| 120791 | 120856 | /* iArg: */ 0 }, |
| 120792 | | -#endif |
| 120793 | | -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 120794 | | -#if !defined(SQLITE_OMIT_DEPRECATED) |
| 120795 | 120857 | {/* zName: */ "temp_store_directory", |
| 120796 | 120858 | /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, |
| 120797 | 120859 | /* ePragFlg: */ PragFlg_NoColumns1, |
| 120798 | 120860 | /* ColNames: */ 0, 0, |
| 120799 | 120861 | /* iArg: */ 0 }, |
| 120800 | | -#endif |
| 120801 | 120862 | #endif |
| 120802 | 120863 | #if defined(SQLITE_HAS_CODEC) |
| 120803 | 120864 | {/* zName: */ "textkey", |
| 120804 | 120865 | /* ePragTyp: */ PragTyp_KEY, |
| 120805 | 120866 | /* ePragFlg: */ 0, |
| | @@ -134945,10 +135006,11 @@ |
| 134945 | 135006 | for(i=0; rc==SQLITE_OK && i<db->nVTrans; i++){ |
| 134946 | 135007 | VTable *pVTab = db->aVTrans[i]; |
| 134947 | 135008 | const sqlite3_module *pMod = pVTab->pMod->pModule; |
| 134948 | 135009 | if( pVTab->pVtab && pMod->iVersion>=2 ){ |
| 134949 | 135010 | int (*xMethod)(sqlite3_vtab *, int); |
| 135011 | + sqlite3VtabLock(pVTab); |
| 134950 | 135012 | switch( op ){ |
| 134951 | 135013 | case SAVEPOINT_BEGIN: |
| 134952 | 135014 | xMethod = pMod->xSavepoint; |
| 134953 | 135015 | pVTab->iSavepoint = iSavepoint+1; |
| 134954 | 135016 | break; |
| | @@ -134960,10 +135022,11 @@ |
| 134960 | 135022 | break; |
| 134961 | 135023 | } |
| 134962 | 135024 | if( xMethod && pVTab->iSavepoint>iSavepoint ){ |
| 134963 | 135025 | rc = xMethod(pVTab->pVtab, iSavepoint); |
| 134964 | 135026 | } |
| 135027 | + sqlite3VtabUnlock(pVTab); |
| 134965 | 135028 | } |
| 134966 | 135029 | } |
| 134967 | 135030 | } |
| 134968 | 135031 | return rc; |
| 134969 | 135032 | } |
| | @@ -153130,11 +153193,11 @@ |
| 153130 | 153193 | ){ |
| 153131 | 153194 | sqlite3 *db; /* The database connection */ |
| 153132 | 153195 | int i; /* Next unread byte of zSql[] */ |
| 153133 | 153196 | int n; /* length of current token */ |
| 153134 | 153197 | int tokenType; /* type of current token */ |
| 153135 | | - int prevType; /* Previous non-whitespace token */ |
| 153198 | + int prevType = 0; /* Previous non-whitespace token */ |
| 153136 | 153199 | int nParen; /* Number of nested levels of parentheses */ |
| 153137 | 153200 | int iStartIN; /* Start of RHS of IN operator in z[] */ |
| 153138 | 153201 | int nParenAtIN; /* Value of nParent at start of RHS of IN operator */ |
| 153139 | 153202 | int j; /* Bytes of normalized SQL generated so far */ |
| 153140 | 153203 | sqlite3_str *pStr; /* The normalized SQL string under construction */ |
| | @@ -156574,10 +156637,44 @@ |
| 156574 | 156637 | *pFlags = flags; |
| 156575 | 156638 | *pzFile = zFile; |
| 156576 | 156639 | return rc; |
| 156577 | 156640 | } |
| 156578 | 156641 | |
| 156642 | +#if defined(SQLITE_HAS_CODEC) |
| 156643 | +/* |
| 156644 | +** Process URI filename query parameters relevant to the SQLite Encryption |
| 156645 | +** Extension. Return true if any of the relevant query parameters are |
| 156646 | +** seen and return false if not. |
| 156647 | +*/ |
| 156648 | +SQLITE_PRIVATE int sqlite3CodecQueryParameters( |
| 156649 | + sqlite3 *db, /* Database connection */ |
| 156650 | + const char *zDb, /* Which schema is being created/attached */ |
| 156651 | + const char *zUri /* URI filename */ |
| 156652 | +){ |
| 156653 | + const char *zKey; |
| 156654 | + if( (zKey = sqlite3_uri_parameter(zUri, "hexkey"))!=0 && zKey[0] ){ |
| 156655 | + u8 iByte; |
| 156656 | + int i; |
| 156657 | + char zDecoded[40]; |
| 156658 | + for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){ |
| 156659 | + iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]); |
| 156660 | + if( (i&1)!=0 ) zDecoded[i/2] = iByte; |
| 156661 | + } |
| 156662 | + sqlite3_key_v2(db, zDb, zDecoded, i/2); |
| 156663 | + return 1; |
| 156664 | + }else if( (zKey = sqlite3_uri_parameter(zUri, "key"))!=0 ){ |
| 156665 | + sqlite3_key_v2(db, zDb, zKey, sqlite3Strlen30(zKey)); |
| 156666 | + return 1; |
| 156667 | + }else if( (zKey = sqlite3_uri_parameter(zUri, "textkey"))!=0 ){ |
| 156668 | + sqlite3_key_v2(db, zDb, zKey, -1); |
| 156669 | + return 1; |
| 156670 | + }else{ |
| 156671 | + return 0; |
| 156672 | + } |
| 156673 | +} |
| 156674 | +#endif |
| 156675 | + |
| 156579 | 156676 | |
| 156580 | 156677 | /* |
| 156581 | 156678 | ** This routine does the work of opening a database on behalf of |
| 156582 | 156679 | ** sqlite3_open() and sqlite3_open16(). The database filename "zFilename" |
| 156583 | 156680 | ** is UTF-8 encoded. |
| | @@ -156919,29 +157016,16 @@ |
| 156919 | 157016 | void *pArg = sqlite3GlobalConfig.pSqllogArg; |
| 156920 | 157017 | sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); |
| 156921 | 157018 | } |
| 156922 | 157019 | #endif |
| 156923 | 157020 | #if defined(SQLITE_HAS_CODEC) |
| 156924 | | - if( rc==SQLITE_OK ){ |
| 156925 | | - const char *zKey; |
| 156926 | | - if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){ |
| 156927 | | - u8 iByte; |
| 156928 | | - int i; |
| 156929 | | - char zDecoded[40]; |
| 156930 | | - for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){ |
| 156931 | | - iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]); |
| 156932 | | - if( (i&1)!=0 ) zDecoded[i/2] = iByte; |
| 156933 | | - } |
| 156934 | | - sqlite3_key_v2(db, 0, zDecoded, i/2); |
| 156935 | | - }else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){ |
| 156936 | | - sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey)); |
| 156937 | | - } |
| 156938 | | - } |
| 157021 | + if( rc==SQLITE_OK ) sqlite3CodecQueryParameters(db, 0, zOpen); |
| 156939 | 157022 | #endif |
| 156940 | 157023 | sqlite3_free(zOpen); |
| 156941 | 157024 | return rc & 0xff; |
| 156942 | 157025 | } |
| 157026 | + |
| 156943 | 157027 | |
| 156944 | 157028 | /* |
| 156945 | 157029 | ** Open a new database handle. |
| 156946 | 157030 | */ |
| 156947 | 157031 | SQLITE_API int sqlite3_open( |
| | @@ -175558,15 +175642,18 @@ |
| 175558 | 175642 | assert( rc==SQLITE_OK || pCsr==0 ); |
| 175559 | 175643 | if( pCsr ){ |
| 175560 | 175644 | int iFirst = 0; |
| 175561 | 175645 | pPhrase->pList = pCsr; |
| 175562 | 175646 | fts3GetDeltaPosition(&pCsr, &iFirst); |
| 175563 | | - assert( iFirst>=0 ); |
| 175564 | | - pPhrase->pHead = pCsr; |
| 175565 | | - pPhrase->pTail = pCsr; |
| 175566 | | - pPhrase->iHead = iFirst; |
| 175567 | | - pPhrase->iTail = iFirst; |
| 175647 | + if( iFirst<0 ){ |
| 175648 | + rc = FTS_CORRUPT_VTAB; |
| 175649 | + }else{ |
| 175650 | + pPhrase->pHead = pCsr; |
| 175651 | + pPhrase->pTail = pCsr; |
| 175652 | + pPhrase->iHead = iFirst; |
| 175653 | + pPhrase->iTail = iFirst; |
| 175654 | + } |
| 175568 | 175655 | }else{ |
| 175569 | 175656 | assert( rc!=SQLITE_OK || ( |
| 175570 | 175657 | pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0 |
| 175571 | 175658 | )); |
| 175572 | 175659 | } |
| | @@ -212324,10 +212411,11 @@ |
| 212324 | 212411 | if( writer.bFirstRowidInPage ){ |
| 212325 | 212412 | fts5PutU16(&pBuf->p[0], (u16)pBuf->n); /* first rowid on page */ |
| 212326 | 212413 | pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid); |
| 212327 | 212414 | writer.bFirstRowidInPage = 0; |
| 212328 | 212415 | fts5WriteDlidxAppend(p, &writer, iRowid); |
| 212416 | + if( p->rc!=SQLITE_OK ) break; |
| 212329 | 212417 | }else{ |
| 212330 | 212418 | pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iDelta); |
| 212331 | 212419 | } |
| 212332 | 212420 | assert( pBuf->n<=pBuf->nSpace ); |
| 212333 | 212421 | |
| | @@ -212555,15 +212643,17 @@ |
| 212555 | 212643 | i64 iDelta, |
| 212556 | 212644 | Fts5Iter *pMulti, |
| 212557 | 212645 | Fts5Buffer *pBuf |
| 212558 | 212646 | ){ |
| 212559 | 212647 | int nData = pMulti->base.nData; |
| 212648 | + int nByte = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING; |
| 212560 | 212649 | assert( nData>0 ); |
| 212561 | | - if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nData+9+9) ){ |
| 212650 | + if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nByte) ){ |
| 212562 | 212651 | fts5BufferSafeAppendVarint(pBuf, iDelta); |
| 212563 | 212652 | fts5BufferSafeAppendVarint(pBuf, nData*2); |
| 212564 | 212653 | fts5BufferSafeAppendBlob(pBuf, pMulti->base.pData, nData); |
| 212654 | + memset(&pBuf->p[pBuf->n], 0, FTS5_DATA_ZERO_PADDING); |
| 212565 | 212655 | } |
| 212566 | 212656 | } |
| 212567 | 212657 | |
| 212568 | 212658 | |
| 212569 | 212659 | static void fts5DoclistIterNext(Fts5DoclistIter *pIter){ |
| | @@ -214199,10 +214289,14 @@ |
| 214199 | 214289 | fts5DecodePoslist(&rc, &s, &a[4], iOff-4); |
| 214200 | 214290 | |
| 214201 | 214291 | /* Decode any more doclist data that appears on the page before the |
| 214202 | 214292 | ** first term. */ |
| 214203 | 214293 | nDoclist = (iTermOff ? iTermOff : szLeaf) - iOff; |
| 214294 | + if( nDoclist+iOff>n ){ |
| 214295 | + rc = FTS5_CORRUPT; |
| 214296 | + goto decode_out; |
| 214297 | + } |
| 214204 | 214298 | fts5DecodeDoclist(&rc, &s, &a[iOff], nDoclist); |
| 214205 | 214299 | |
| 214206 | 214300 | while( iPgidxOff<n && rc==SQLITE_OK ){ |
| 214207 | 214301 | int bFirst = (iPgidxOff==szLeaf); /* True for first term on page */ |
| 214208 | 214302 | int nByte; /* Bytes of data */ |
| | @@ -214617,11 +214711,11 @@ |
| 214617 | 214711 | p->ts.iSavepoint = iSavepoint-1; |
| 214618 | 214712 | break; |
| 214619 | 214713 | |
| 214620 | 214714 | case FTS5_ROLLBACKTO: |
| 214621 | 214715 | assert( p->ts.eState==1 ); |
| 214622 | | - assert( iSavepoint>=0 ); |
| 214716 | + assert( iSavepoint>=-1 ); |
| 214623 | 214717 | assert( iSavepoint<=p->ts.iSavepoint ); |
| 214624 | 214718 | p->ts.iSavepoint = iSavepoint; |
| 214625 | 214719 | break; |
| 214626 | 214720 | } |
| 214627 | 214721 | } |
| | @@ -216977,11 +217071,11 @@ |
| 216977 | 217071 | int nArg, /* Number of args */ |
| 216978 | 217072 | sqlite3_value **apUnused /* Function arguments */ |
| 216979 | 217073 | ){ |
| 216980 | 217074 | assert( nArg==0 ); |
| 216981 | 217075 | UNUSED_PARAM2(nArg, apUnused); |
| 216982 | | - sqlite3_result_text(pCtx, "fts5: 2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5ccb8", -1, SQLITE_TRANSIENT); |
| 217076 | + sqlite3_result_text(pCtx, "fts5: 2019-02-05 19:52:39 2f468da4e9fb3edb5e902fa5d3c528726d1fb64d749d29e558ba3243c76bcb95", -1, SQLITE_TRANSIENT); |
| 216983 | 217077 | } |
| 216984 | 217078 | |
| 216985 | 217079 | /* |
| 216986 | 217080 | ** Return true if zName is the extension on one of the shadow tables used |
| 216987 | 217081 | ** by this module. |
| | @@ -221741,12 +221835,12 @@ |
| 221741 | 221835 | } |
| 221742 | 221836 | #endif /* SQLITE_CORE */ |
| 221743 | 221837 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 221744 | 221838 | |
| 221745 | 221839 | /************** End of stmt.c ************************************************/ |
| 221746 | | -#if __LINE__!=221746 |
| 221840 | +#if __LINE__!=221840 |
| 221747 | 221841 | #undef SQLITE_SOURCE_ID |
| 221748 | | -#define SQLITE_SOURCE_ID "2019-02-01 15:06:27 4ca9d5d53d41d08fbce29f9da8cc0948df9c4c3136210af88b499cf889b5alt2" |
| 221842 | +#define SQLITE_SOURCE_ID "2019-02-05 20:51:41 4d0a949fd92e19fbf243a2e3a1a7c2cdb111f9a6943949d2420dd846bc7dalt2" |
| 221749 | 221843 | #endif |
| 221750 | 221844 | /* Return the source-id for this library */ |
| 221751 | 221845 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 221752 | 221846 | /************************** End of sqlite3.c ******************************/ |
| 221753 | 221847 | |