| | @@ -398,11 +398,11 @@ |
| 398 | 398 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 399 | 399 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 400 | 400 | */ |
| 401 | 401 | #define SQLITE_VERSION "3.19.0" |
| 402 | 402 | #define SQLITE_VERSION_NUMBER 3019000 |
| 403 | | -#define SQLITE_SOURCE_ID "2017-05-02 18:00:31 430f539cbb3f806fb89191e0b759a5f8b49d9e5b6c95fe9a4b55a1aa0875762a" |
| 403 | +#define SQLITE_SOURCE_ID "2017-05-10 16:12:00 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c" |
| 404 | 404 | |
| 405 | 405 | /* |
| 406 | 406 | ** CAPI3REF: Run-Time Library Version Numbers |
| 407 | 407 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 408 | 408 | ** |
| | @@ -17272,13 +17272,20 @@ |
| 17272 | 17272 | ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options. |
| 17273 | 17273 | ** |
| 17274 | 17274 | ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally |
| 17275 | 17275 | ** disabled. The default value may be changed by compiling with the |
| 17276 | 17276 | ** SQLITE_USE_URI symbol defined. |
| 17277 | +** |
| 17278 | +** URI filenames are enabled by default if SQLITE_HAS_CODEC is |
| 17279 | +** enabled. |
| 17277 | 17280 | */ |
| 17278 | 17281 | #ifndef SQLITE_USE_URI |
| 17279 | | -# define SQLITE_USE_URI 0 |
| 17282 | +# ifdef SQLITE_HAS_CODEC |
| 17283 | +# define SQLITE_USE_URI 1 |
| 17284 | +# else |
| 17285 | +# define SQLITE_USE_URI 0 |
| 17286 | +# endif |
| 17280 | 17287 | #endif |
| 17281 | 17288 | |
| 17282 | 17289 | /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the |
| 17283 | 17290 | ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if |
| 17284 | 17291 | ** that compile-time option is omitted. |
| | @@ -28348,10 +28355,11 @@ |
| 28348 | 28355 | }else{ |
| 28349 | 28356 | return 0; |
| 28350 | 28357 | } |
| 28351 | 28358 | } |
| 28352 | 28359 | #endif |
| 28360 | + if( !sqlite3Isdigit(zNum[0]) ) return 0; |
| 28353 | 28361 | while( zNum[0]=='0' ) zNum++; |
| 28354 | 28362 | for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){ |
| 28355 | 28363 | v = v*10 + c; |
| 28356 | 28364 | } |
| 28357 | 28365 | |
| | @@ -49153,10 +49161,15 @@ |
| 49153 | 49161 | Pgno pgno; /* The page number of a page in journal */ |
| 49154 | 49162 | u32 cksum; /* Checksum used for sanity checking */ |
| 49155 | 49163 | char *aData; /* Temporary storage for the page */ |
| 49156 | 49164 | sqlite3_file *jfd; /* The file descriptor for the journal file */ |
| 49157 | 49165 | int isSynced; /* True if journal page is synced */ |
| 49166 | +#ifdef SQLITE_HAS_CODEC |
| 49167 | + /* The jrnlEnc flag is true if Journal pages should be passed through |
| 49168 | + ** the codec. It is false for pure in-memory journals. */ |
| 49169 | + const int jrnlEnc = (isMainJrnl || pPager->subjInMemory==0); |
| 49170 | +#endif |
| 49158 | 49171 | |
| 49159 | 49172 | assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */ |
| 49160 | 49173 | assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */ |
| 49161 | 49174 | assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */ |
| 49162 | 49175 | assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */ |
| | @@ -49276,18 +49289,38 @@ |
| 49276 | 49289 | && isSynced |
| 49277 | 49290 | ){ |
| 49278 | 49291 | i64 ofst = (pgno-1)*(i64)pPager->pageSize; |
| 49279 | 49292 | testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 ); |
| 49280 | 49293 | assert( !pagerUseWal(pPager) ); |
| 49294 | + |
| 49295 | + /* Write the data read from the journal back into the database file. |
| 49296 | + ** This is usually safe even for an encrypted database - as the data |
| 49297 | + ** was encrypted before it was written to the journal file. The exception |
| 49298 | + ** is if the data was just read from an in-memory sub-journal. In that |
| 49299 | + ** case it must be encrypted here before it is copied into the database |
| 49300 | + ** file. */ |
| 49301 | +#ifdef SQLITE_HAS_CODEC |
| 49302 | + if( !jrnlEnc ){ |
| 49303 | + CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData); |
| 49304 | + rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst); |
| 49305 | + CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT); |
| 49306 | + }else |
| 49307 | +#endif |
| 49281 | 49308 | rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst); |
| 49309 | + |
| 49282 | 49310 | if( pgno>pPager->dbFileSize ){ |
| 49283 | 49311 | pPager->dbFileSize = pgno; |
| 49284 | 49312 | } |
| 49285 | 49313 | if( pPager->pBackup ){ |
| 49286 | | - CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT); |
| 49314 | +#ifdef SQLITE_HAS_CODEC |
| 49315 | + if( jrnlEnc ){ |
| 49316 | + CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT); |
| 49317 | + sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData); |
| 49318 | + CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData); |
| 49319 | + }else |
| 49320 | +#endif |
| 49287 | 49321 | sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData); |
| 49288 | | - CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData); |
| 49289 | 49322 | } |
| 49290 | 49323 | }else if( !isMainJrnl && pPg==0 ){ |
| 49291 | 49324 | /* If this is a rollback of a savepoint and data was not written to |
| 49292 | 49325 | ** the database and the page is not in-memory, there is a potential |
| 49293 | 49326 | ** problem. When the page is next fetched by the b-tree layer, it |
| | @@ -49335,11 +49368,13 @@ |
| 49335 | 49368 | if( pgno==1 ){ |
| 49336 | 49369 | memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers)); |
| 49337 | 49370 | } |
| 49338 | 49371 | |
| 49339 | 49372 | /* Decode the page just read from disk */ |
| 49340 | | - CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); |
| 49373 | +#if SQLITE_HAS_CODEC |
| 49374 | + if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); } |
| 49375 | +#endif |
| 49341 | 49376 | sqlite3PcacheRelease(pPg); |
| 49342 | 49377 | } |
| 49343 | 49378 | return rc; |
| 49344 | 49379 | } |
| 49345 | 49380 | |
| | @@ -51347,12 +51382,17 @@ |
| 51347 | 51382 | ** write the journal record into the file. */ |
| 51348 | 51383 | if( rc==SQLITE_OK ){ |
| 51349 | 51384 | void *pData = pPg->pData; |
| 51350 | 51385 | i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize); |
| 51351 | 51386 | char *pData2; |
| 51352 | | - |
| 51353 | | - CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2); |
| 51387 | + |
| 51388 | +#if SQLITE_HAS_CODEC |
| 51389 | + if( !pPager->subjInMemory ){ |
| 51390 | + CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2); |
| 51391 | + }else |
| 51392 | +#endif |
| 51393 | + pData2 = pData; |
| 51354 | 51394 | PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno)); |
| 51355 | 51395 | rc = write32bits(pPager->sjfd, offset, pPg->pgno); |
| 51356 | 51396 | if( rc==SQLITE_OK ){ |
| 51357 | 51397 | rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4); |
| 51358 | 51398 | } |
| | @@ -92369,11 +92409,11 @@ |
| 92369 | 92409 | pList->a[pList->nExpr-1].zName = pColumns->a[i].zName; |
| 92370 | 92410 | pColumns->a[i].zName = 0; |
| 92371 | 92411 | } |
| 92372 | 92412 | } |
| 92373 | 92413 | |
| 92374 | | - if( pExpr->op==TK_SELECT && pList ){ |
| 92414 | + if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){ |
| 92375 | 92415 | Expr *pFirst = pList->a[iFirst].pExpr; |
| 92376 | 92416 | assert( pFirst!=0 ); |
| 92377 | 92417 | assert( pFirst->op==TK_SELECT_COLUMN ); |
| 92378 | 92418 | |
| 92379 | 92419 | /* Store the SELECT statement in pRight so it will be deleted when |
| | @@ -121536,17 +121576,34 @@ |
| 121536 | 121576 | #endif |
| 121537 | 121577 | return rc; |
| 121538 | 121578 | } |
| 121539 | 121579 | #endif |
| 121540 | 121580 | |
| 121541 | | - /* Generate code for all sub-queries in the FROM clause |
| 121581 | + /* For each term in the FROM clause, do two things: |
| 121582 | + ** (1) Authorized unreferenced tables |
| 121583 | + ** (2) Generate code for all sub-queries |
| 121542 | 121584 | */ |
| 121543 | | -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 121544 | 121585 | for(i=0; i<pTabList->nSrc; i++){ |
| 121545 | 121586 | struct SrcList_item *pItem = &pTabList->a[i]; |
| 121546 | 121587 | SelectDest dest; |
| 121547 | | - Select *pSub = pItem->pSelect; |
| 121588 | + Select *pSub; |
| 121589 | + |
| 121590 | + /* Issue SQLITE_READ authorizations with a NULL column name for any tables that |
| 121591 | + ** are referenced but from which no values are extracted. Examples of where these |
| 121592 | + ** kinds of null SQLITE_READ authorizations would occur: |
| 121593 | + ** |
| 121594 | + ** SELECT count(*) FROM t1; -- SQLITE_READ t1 null |
| 121595 | + ** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2 null |
| 121596 | + */ |
| 121597 | + if( pItem->colUsed==0 ){ |
| 121598 | + sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, pItem->zDatabase, 0); |
| 121599 | + } |
| 121600 | + |
| 121601 | +#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 121602 | + /* Generate code for all sub-queries in the FROM clause |
| 121603 | + */ |
| 121604 | + pSub = pItem->pSelect; |
| 121548 | 121605 | if( pSub==0 ) continue; |
| 121549 | 121606 | |
| 121550 | 121607 | /* Sometimes the code for a subquery will be generated more than |
| 121551 | 121608 | ** once, if the subquery is part of the WHERE clause in a LEFT JOIN, |
| 121552 | 121609 | ** for example. In that case, do not regenerate the code to manifest |
| | @@ -121663,12 +121720,12 @@ |
| 121663 | 121720 | sqlite3VdbeChangeP1(v, topAddr, retAddr); |
| 121664 | 121721 | sqlite3ClearTempRegCache(pParse); |
| 121665 | 121722 | } |
| 121666 | 121723 | if( db->mallocFailed ) goto select_end; |
| 121667 | 121724 | pParse->nHeight -= sqlite3SelectExprHeight(p); |
| 121725 | +#endif |
| 121668 | 121726 | } |
| 121669 | | -#endif |
| 121670 | 121727 | |
| 121671 | 121728 | /* Various elements of the SELECT copied into local variables for |
| 121672 | 121729 | ** convenience */ |
| 121673 | 121730 | pEList = p->pEList; |
| 121674 | 121731 | pWhere = p->pWhere; |
| | @@ -143421,20 +143478,22 @@ |
| 143421 | 143478 | sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0); |
| 143422 | 143479 | } |
| 143423 | 143480 | #endif |
| 143424 | 143481 | #if defined(SQLITE_HAS_CODEC) |
| 143425 | 143482 | if( rc==SQLITE_OK ){ |
| 143426 | | - const char *zHexKey = sqlite3_uri_parameter(zOpen, "hexkey"); |
| 143427 | | - if( zHexKey && zHexKey[0] ){ |
| 143483 | + const char *zKey; |
| 143484 | + if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){; |
| 143428 | 143485 | u8 iByte; |
| 143429 | 143486 | int i; |
| 143430 | | - char zKey[40]; |
| 143431 | | - for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zHexKey[i]); i++){ |
| 143432 | | - iByte = (iByte<<4) + sqlite3HexToInt(zHexKey[i]); |
| 143433 | | - if( (i&1)!=0 ) zKey[i/2] = iByte; |
| 143487 | + char zDecoded[40]; |
| 143488 | + for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){ |
| 143489 | + iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]); |
| 143490 | + if( (i&1)!=0 ) zDecoded[i/2] = iByte; |
| 143434 | 143491 | } |
| 143435 | | - sqlite3_key_v2(db, 0, zKey, i/2); |
| 143492 | + sqlite3_key_v2(db, 0, zDecoded, i/2); |
| 143493 | + }else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){ |
| 143494 | + sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey)); |
| 143436 | 143495 | } |
| 143437 | 143496 | } |
| 143438 | 143497 | #endif |
| 143439 | 143498 | sqlite3_free(zOpen); |
| 143440 | 143499 | return rc & 0xff; |
| | @@ -167122,10 +167181,11 @@ |
| 167122 | 167181 | ** COMMIT; |
| 167123 | 167182 | */ |
| 167124 | 167183 | static int rtreeSavepoint(sqlite3_vtab *pVtab, int iSavepoint){ |
| 167125 | 167184 | Rtree *pRtree = (Rtree *)pVtab; |
| 167126 | 167185 | int iwt = pRtree->inWrTrans; |
| 167186 | + UNUSED_PARAMETER(iSavepoint); |
| 167127 | 167187 | pRtree->inWrTrans = 0; |
| 167128 | 167188 | nodeBlobReset(pRtree); |
| 167129 | 167189 | pRtree->inWrTrans = iwt; |
| 167130 | 167190 | return SQLITE_OK; |
| 167131 | 167191 | } |
| | @@ -198848,11 +198908,11 @@ |
| 198848 | 198908 | int nArg, /* Number of args */ |
| 198849 | 198909 | sqlite3_value **apUnused /* Function arguments */ |
| 198850 | 198910 | ){ |
| 198851 | 198911 | assert( nArg==0 ); |
| 198852 | 198912 | UNUSED_PARAM2(nArg, apUnused); |
| 198853 | | - sqlite3_result_text(pCtx, "fts5: 2017-05-02 18:00:31 430f539cbb3f806fb89191e0b759a5f8b49d9e5b6c95fe9a4b55a1aa0875762a", -1, SQLITE_TRANSIENT); |
| 198913 | + sqlite3_result_text(pCtx, "fts5: 2017-05-10 16:12:00 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c", -1, SQLITE_TRANSIENT); |
| 198854 | 198914 | } |
| 198855 | 198915 | |
| 198856 | 198916 | static int fts5Init(sqlite3 *db){ |
| 198857 | 198917 | static const sqlite3_module fts5Mod = { |
| 198858 | 198918 | /* iVersion */ 2, |
| 198859 | 198919 | |