| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.16.0. By combining all the individual C code files into this |
| 3 | +** version 3.16.1. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -379,13 +379,13 @@ |
| 379 | 379 | ** |
| 380 | 380 | ** See also: [sqlite3_libversion()], |
| 381 | 381 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 382 | 382 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 383 | 383 | */ |
| 384 | | -#define SQLITE_VERSION "3.16.0" |
| 385 | | -#define SQLITE_VERSION_NUMBER 3016000 |
| 386 | | -#define SQLITE_SOURCE_ID "2017-01-02 11:57:58 04ac0b75b1716541b2b97704f4809cb7ef19cccf" |
| 384 | +#define SQLITE_VERSION "3.16.1" |
| 385 | +#define SQLITE_VERSION_NUMBER 3016001 |
| 386 | +#define SQLITE_SOURCE_ID "2017-01-03 18:27:03 979f04392853b8053817a3eea2fc679947b437fd" |
| 387 | 387 | |
| 388 | 388 | /* |
| 389 | 389 | ** CAPI3REF: Run-Time Library Version Numbers |
| 390 | 390 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 391 | 391 | ** |
| | @@ -90661,13 +90661,14 @@ |
| 90661 | 90661 | Expr *pRet; |
| 90662 | 90662 | if( pVector->op==TK_SELECT ){ |
| 90663 | 90663 | assert( pVector->flags & EP_xIsSelect ); |
| 90664 | 90664 | /* The TK_SELECT_COLUMN Expr node: |
| 90665 | 90665 | ** |
| 90666 | | - ** pLeft: pVector containing TK_SELECT |
| 90666 | + ** pLeft: pVector containing TK_SELECT. Not deleted. |
| 90667 | 90667 | ** pRight: not used. But recursively deleted. |
| 90668 | 90668 | ** iColumn: Index of a column in pVector |
| 90669 | + ** iTable: 0 or the number of columns on the LHS of an assignment |
| 90669 | 90670 | ** pLeft->iTable: First in an array of register holding result, or 0 |
| 90670 | 90671 | ** if the result is not yet computed. |
| 90671 | 90672 | ** |
| 90672 | 90673 | ** sqlite3ExprDelete() specifically skips the recursive delete of |
| 90673 | 90674 | ** pLeft on TK_SELECT_COLUMN nodes. But pRight is followed, so pVector |
| | @@ -91335,11 +91336,11 @@ |
| 91335 | 91336 | static int dupedExprStructSize(Expr *p, int flags){ |
| 91336 | 91337 | int nSize; |
| 91337 | 91338 | assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */ |
| 91338 | 91339 | assert( EXPR_FULLSIZE<=0xfff ); |
| 91339 | 91340 | assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 ); |
| 91340 | | - if( 0==flags ){ |
| 91341 | + if( 0==flags || p->op==TK_SELECT_COLUMN ){ |
| 91341 | 91342 | nSize = EXPR_FULLSIZE; |
| 91342 | 91343 | }else{ |
| 91343 | 91344 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 91344 | 91345 | assert( !ExprHasProperty(p, EP_FromJoin) ); |
| 91345 | 91346 | assert( !ExprHasProperty(p, EP_MemToken) ); |
| | @@ -91478,10 +91479,12 @@ |
| 91478 | 91479 | } |
| 91479 | 91480 | }else{ |
| 91480 | 91481 | if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){ |
| 91481 | 91482 | if( pNew->op==TK_SELECT_COLUMN ){ |
| 91482 | 91483 | pNew->pLeft = p->pLeft; |
| 91484 | + assert( p->iColumn==0 || p->pRight==0 ); |
| 91485 | + assert( p->pRight==0 || p->pRight==p->pLeft ); |
| 91483 | 91486 | }else{ |
| 91484 | 91487 | pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0); |
| 91485 | 91488 | } |
| 91486 | 91489 | pNew->pRight = sqlite3ExprDup(db, p->pRight, 0); |
| 91487 | 91490 | } |
| | @@ -91540,10 +91543,11 @@ |
| 91540 | 91543 | } |
| 91541 | 91544 | SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){ |
| 91542 | 91545 | ExprList *pNew; |
| 91543 | 91546 | struct ExprList_item *pItem, *pOldItem; |
| 91544 | 91547 | int i; |
| 91548 | + Expr *pPriorSelectCol = 0; |
| 91545 | 91549 | assert( db!=0 ); |
| 91546 | 91550 | if( p==0 ) return 0; |
| 91547 | 91551 | pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) ); |
| 91548 | 91552 | if( pNew==0 ) return 0; |
| 91549 | 91553 | pNew->nExpr = i = p->nExpr; |
| | @@ -91554,11 +91558,28 @@ |
| 91554 | 91558 | return 0; |
| 91555 | 91559 | } |
| 91556 | 91560 | pOldItem = p->a; |
| 91557 | 91561 | for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){ |
| 91558 | 91562 | Expr *pOldExpr = pOldItem->pExpr; |
| 91563 | + Expr *pNewExpr; |
| 91559 | 91564 | pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags); |
| 91565 | + if( pOldExpr |
| 91566 | + && pOldExpr->op==TK_SELECT_COLUMN |
| 91567 | + && (pNewExpr = pItem->pExpr)!=0 |
| 91568 | + ){ |
| 91569 | + assert( pNewExpr->iColumn==0 || i>0 ); |
| 91570 | + if( pNewExpr->iColumn==0 ){ |
| 91571 | + assert( pOldExpr->pLeft==pOldExpr->pRight ); |
| 91572 | + pPriorSelectCol = pNewExpr->pLeft = pNewExpr->pRight; |
| 91573 | + }else{ |
| 91574 | + assert( i>0 ); |
| 91575 | + assert( pItem[-1].pExpr!=0 ); |
| 91576 | + assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 ); |
| 91577 | + assert( pPriorSelectCol==pItem[-1].pExpr->pLeft ); |
| 91578 | + pNewExpr->pLeft = pPriorSelectCol; |
| 91579 | + } |
| 91580 | + } |
| 91560 | 91581 | pItem->zName = sqlite3DbStrDup(db, pOldItem->zName); |
| 91561 | 91582 | pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan); |
| 91562 | 91583 | pItem->sortOrder = pOldItem->sortOrder; |
| 91563 | 91584 | pItem->done = 0; |
| 91564 | 91585 | pItem->bSpanIsTab = pOldItem->bSpanIsTab; |
| | @@ -91746,30 +91767,45 @@ |
| 91746 | 91767 | int iFirst = pList ? pList->nExpr : 0; |
| 91747 | 91768 | /* pColumns can only be NULL due to an OOM but an OOM will cause an |
| 91748 | 91769 | ** exit prior to this routine being invoked */ |
| 91749 | 91770 | if( NEVER(pColumns==0) ) goto vector_append_error; |
| 91750 | 91771 | if( pExpr==0 ) goto vector_append_error; |
| 91751 | | - n = sqlite3ExprVectorSize(pExpr); |
| 91752 | | - if( pColumns->nId!=n ){ |
| 91772 | + |
| 91773 | + /* If the RHS is a vector, then we can immediately check to see that |
| 91774 | + ** the size of the RHS and LHS match. But if the RHS is a SELECT, |
| 91775 | + ** wildcards ("*") in the result set of the SELECT must be expanded before |
| 91776 | + ** we can do the size check, so defer the size check until code generation. |
| 91777 | + */ |
| 91778 | + if( pExpr->op!=TK_SELECT && pColumns->nId!=(n=sqlite3ExprVectorSize(pExpr)) ){ |
| 91753 | 91779 | sqlite3ErrorMsg(pParse, "%d columns assigned %d values", |
| 91754 | 91780 | pColumns->nId, n); |
| 91755 | 91781 | goto vector_append_error; |
| 91756 | 91782 | } |
| 91757 | | - for(i=0; i<n; i++){ |
| 91783 | + |
| 91784 | + for(i=0; i<pColumns->nId; i++){ |
| 91758 | 91785 | Expr *pSubExpr = sqlite3ExprForVectorField(pParse, pExpr, i); |
| 91759 | 91786 | pList = sqlite3ExprListAppend(pParse, pList, pSubExpr); |
| 91760 | 91787 | if( pList ){ |
| 91761 | 91788 | assert( pList->nExpr==iFirst+i+1 ); |
| 91762 | 91789 | pList->a[pList->nExpr-1].zName = pColumns->a[i].zName; |
| 91763 | 91790 | pColumns->a[i].zName = 0; |
| 91764 | 91791 | } |
| 91765 | 91792 | } |
| 91793 | + |
| 91766 | 91794 | if( pExpr->op==TK_SELECT ){ |
| 91767 | 91795 | if( pList && pList->a[iFirst].pExpr ){ |
| 91768 | | - assert( pList->a[iFirst].pExpr->op==TK_SELECT_COLUMN ); |
| 91769 | | - pList->a[iFirst].pExpr->pRight = pExpr; |
| 91796 | + Expr *pFirst = pList->a[iFirst].pExpr; |
| 91797 | + assert( pFirst->op==TK_SELECT_COLUMN ); |
| 91798 | + |
| 91799 | + /* Store the SELECT statement in pRight so it will be deleted when |
| 91800 | + ** sqlite3ExprListDelete() is called */ |
| 91801 | + pFirst->pRight = pExpr; |
| 91770 | 91802 | pExpr = 0; |
| 91803 | + |
| 91804 | + /* Remember the size of the LHS in iTable so that we can check that |
| 91805 | + ** the RHS and LHS sizes match during code generation. */ |
| 91806 | + pFirst->iTable = pColumns->nId; |
| 91771 | 91807 | } |
| 91772 | 91808 | } |
| 91773 | 91809 | |
| 91774 | 91810 | vector_append_error: |
| 91775 | 91811 | sqlite3ExprDelete(db, pExpr); |
| | @@ -93959,12 +93995,20 @@ |
| 93959 | 93995 | return sqlite3CodeSubselect(pParse, pExpr, 0, 0); |
| 93960 | 93996 | } |
| 93961 | 93997 | break; |
| 93962 | 93998 | } |
| 93963 | 93999 | case TK_SELECT_COLUMN: { |
| 94000 | + int n; |
| 93964 | 94001 | if( pExpr->pLeft->iTable==0 ){ |
| 93965 | 94002 | pExpr->pLeft->iTable = sqlite3CodeSubselect(pParse, pExpr->pLeft, 0, 0); |
| 94003 | + } |
| 94004 | + assert( pExpr->iTable==0 || pExpr->pLeft->op==TK_SELECT ); |
| 94005 | + if( pExpr->iTable |
| 94006 | + && pExpr->iTable!=(n = sqlite3ExprVectorSize(pExpr->pLeft)) |
| 94007 | + ){ |
| 94008 | + sqlite3ErrorMsg(pParse, "%d columns assigned %d values", |
| 94009 | + pExpr->iTable, n); |
| 93966 | 94010 | } |
| 93967 | 94011 | return pExpr->pLeft->iTable + pExpr->iColumn; |
| 93968 | 94012 | } |
| 93969 | 94013 | case TK_IN: { |
| 93970 | 94014 | int destIfFalse = sqlite3VdbeMakeLabel(v); |
| | @@ -196770,11 +196814,11 @@ |
| 196770 | 196814 | int nArg, /* Number of args */ |
| 196771 | 196815 | sqlite3_value **apUnused /* Function arguments */ |
| 196772 | 196816 | ){ |
| 196773 | 196817 | assert( nArg==0 ); |
| 196774 | 196818 | UNUSED_PARAM2(nArg, apUnused); |
| 196775 | | - sqlite3_result_text(pCtx, "fts5: 2017-01-02 11:57:58 04ac0b75b1716541b2b97704f4809cb7ef19cccf", -1, SQLITE_TRANSIENT); |
| 196819 | + sqlite3_result_text(pCtx, "fts5: 2017-01-03 18:27:03 979f04392853b8053817a3eea2fc679947b437fd", -1, SQLITE_TRANSIENT); |
| 196776 | 196820 | } |
| 196777 | 196821 | |
| 196778 | 196822 | static int fts5Init(sqlite3 *db){ |
| 196779 | 196823 | static const sqlite3_module fts5Mod = { |
| 196780 | 196824 | /* iVersion */ 2, |
| 196781 | 196825 | |