diff options
author | dan <dan@noemail.net> | 2019-08-05 20:53:19 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2019-08-05 20:53:19 +0000 |
commit | 5978a7a525c58e1402b87ba957d287f650e0f9ab (patch) | |
tree | 50bb16d0813c95ba856b00c5cd0c80e31d97c65c /src | |
parent | 1194904b814d6da63930dee75bc468094706226a (diff) | |
parent | 0a8d06a93f308e2ad450a62b961a09d43c15bba6 (diff) | |
download | sqlite-5978a7a525c58e1402b87ba957d287f650e0f9ab.tar.gz sqlite-5978a7a525c58e1402b87ba957d287f650e0f9ab.zip |
Ensure that columns of views and sub-queries that are expressions with no affinity are not assigned BLOB affinity. This matches the documentation. Fix for [61c853857f40da49].
FossilOrigin-Name: e15a0977ddfad3d0f4c7654c5665ff10830c25b20ecf6ef500b1ba23fb89e31f
Diffstat (limited to 'src')
-rw-r--r-- | src/build.c | 8 | ||||
-rw-r--r-- | src/insert.c | 10 | ||||
-rw-r--r-- | src/select.c | 11 | ||||
-rw-r--r-- | src/sqliteInt.h | 4 | ||||
-rw-r--r-- | src/window.c | 2 |
5 files changed, 18 insertions, 17 deletions
diff --git a/src/build.c b/src/build.c index 80bc4eb0d..2a33dbb89 100644 --- a/src/build.c +++ b/src/build.c @@ -2160,7 +2160,7 @@ void sqlite3EndTable( addrTop = sqlite3VdbeCurrentAddr(v) + 1; sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); if( pParse->nErr ) return; - pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect); + pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect, SQLITE_AFF_BLOB); if( pSelTab==0 ) return; assert( p->aCol==0 ); p->nCol = pSelTab->nCol; @@ -2424,10 +2424,10 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ #ifndef SQLITE_OMIT_AUTHORIZATION xAuth = db->xAuth; db->xAuth = 0; - pSelTab = sqlite3ResultSetOfSelect(pParse, pSel); + pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, 0); db->xAuth = xAuth; #else - pSelTab = sqlite3ResultSetOfSelect(pParse, pSel); + pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, 0); #endif pParse->nTab = n; if( pTable->pCheck ){ @@ -2443,7 +2443,7 @@ int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ && pParse->nErr==0 && pTable->nCol==pSel->pEList->nExpr ){ - sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel); + sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel, 0); } }else if( pSelTab ){ /* CREATE VIEW name AS... without an argument list. Construct diff --git a/src/insert.c b/src/insert.c index 2fe015fa0..2f1a19952 100644 --- a/src/insert.c +++ b/src/insert.c @@ -88,18 +88,18 @@ const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){ } for(n=0; n<pIdx->nColumn; n++){ i16 x = pIdx->aiColumn[n]; + char aff; if( x>=0 ){ - pIdx->zColAff[n] = pTab->aCol[x].affinity; + aff = pTab->aCol[x].affinity; }else if( x==XN_ROWID ){ - pIdx->zColAff[n] = SQLITE_AFF_INTEGER; + aff = SQLITE_AFF_INTEGER; }else{ - char aff; assert( x==XN_EXPR ); assert( pIdx->aColExpr!=0 ); aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr); - if( aff==0 ) aff = SQLITE_AFF_BLOB; - pIdx->zColAff[n] = aff; } + if( aff==0 ) aff = SQLITE_AFF_BLOB; + pIdx->zColAff[n] = aff; } pIdx->zColAff[n] = 0; } diff --git a/src/select.c b/src/select.c index 1feee02b7..d3e4fd246 100644 --- a/src/select.c +++ b/src/select.c @@ -2035,7 +2035,8 @@ int sqlite3ColumnsFromExprList( void sqlite3SelectAddColumnTypeAndCollation( Parse *pParse, /* Parsing contexts */ Table *pTab, /* Add column type information to this table */ - Select *pSelect /* SELECT used to determine types and collations */ + Select *pSelect, /* SELECT used to determine types and collations */ + char aff /* Default affinity for columns */ ){ sqlite3 *db = pParse->db; NameContext sNC; @@ -2068,7 +2069,7 @@ void sqlite3SelectAddColumnTypeAndCollation( pCol->colFlags |= COLFLAG_HASTYPE; } } - if( pCol->affinity==0 ) pCol->affinity = SQLITE_AFF_BLOB; + if( pCol->affinity==0 ) pCol->affinity = aff; pColl = sqlite3ExprCollSeq(pParse, p); if( pColl && pCol->zColl==0 ){ pCol->zColl = sqlite3DbStrDup(db, pColl->zName); @@ -2081,7 +2082,7 @@ void sqlite3SelectAddColumnTypeAndCollation( ** Given a SELECT statement, generate a Table structure that describes ** the result set of that SELECT. */ -Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){ +Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect, char aff){ Table *pTab; sqlite3 *db = pParse->db; u64 savedFlags; @@ -2101,7 +2102,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){ pTab->zName = 0; pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) ); sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol); - sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect); + sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect, aff); pTab->iPKey = -1; if( db->mallocFailed ){ sqlite3DeleteTable(db, pTab); @@ -5195,7 +5196,7 @@ static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){ Select *pSel = pFrom->pSelect; if( pSel ){ while( pSel->pPrior ) pSel = pSel->pPrior; - sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSel); + sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSel, 0); } } } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 6d4c07677..821bfdbd0 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -3911,8 +3911,8 @@ void sqlite3CollapseDatabaseArray(sqlite3*); void sqlite3CommitInternalChanges(sqlite3*); void sqlite3DeleteColumnNames(sqlite3*,Table*); int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**); -void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*); -Table *sqlite3ResultSetOfSelect(Parse*,Select*); +void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char); +Table *sqlite3ResultSetOfSelect(Parse*,Select*,char); void sqlite3OpenMasterTable(Parse *, int); Index *sqlite3PrimaryKeyIndex(Table*); i16 sqlite3ColumnOfIndex(Index*, i16); diff --git a/src/window.c b/src/window.c index 199185013..ef62ddda3 100644 --- a/src/window.c +++ b/src/window.c @@ -994,7 +994,7 @@ int sqlite3WindowRewrite(Parse *pParse, Select *p){ p->pSrc->a[0].pSelect = pSub; sqlite3SrcListAssignCursors(pParse, p->pSrc); pSub->selFlags |= SF_Expanded; - pTab2 = sqlite3ResultSetOfSelect(pParse, pSub); + pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, 0); if( pTab2==0 ){ rc = SQLITE_NOMEM; }else{ |