diff options
author | dan <dan@noemail.net> | 2014-01-15 15:27:51 +0000 |
---|---|---|
committer | dan <dan@noemail.net> | 2014-01-15 15:27:51 +0000 |
commit | 60e7068d75acc643cfd045a7cb90d635079f3457 (patch) | |
tree | e62cf743f08e3ee7acbc920d1e0478fe22cea897 /src | |
parent | a379b32f336f4ec5ff35c9a9acf323e95538eec4 (diff) | |
download | sqlite-60e7068d75acc643cfd045a7cb90d635079f3457.tar.gz sqlite-60e7068d75acc643cfd045a7cb90d635079f3457.zip |
Return an error if a CTE specifies a different number of columns than its SELECT statement returns.
FossilOrigin-Name: 9a514b50e4b01f109fbdb0aabcbfe1ddab129b44
Diffstat (limited to 'src')
-rw-r--r-- | src/select.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/select.c b/src/select.c index 35edcbb03..34a2297c9 100644 --- a/src/select.c +++ b/src/select.c @@ -3556,6 +3556,7 @@ static int withExpand( }else{ ExprList *pEList; Select *pSel; + Select *pLeft; /* Left-most SELECT statement */ int bRecursive; pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table)); @@ -3579,13 +3580,18 @@ static int withExpand( sqlite3WalkSelect(pWalker, pSel); } + for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); + pEList = pLeft->pEList; if( pCte->pCols ){ + if( pEList->nExpr!=pCte->pCols->nExpr ){ + sqlite3ErrorMsg(pParse, "cte \"%s\" returns %d values for %d columns", + pCte->zName, pEList->nExpr, pCte->pCols->nExpr + ); + return WRC_Abort; + } pEList = pCte->pCols; - }else{ - Select *pLeft; - for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); - pEList = pLeft->pEList; } + selectColumnsFromExprList(pParse, pEList, &pTab->nCol, &pTab->aCol); if( bRecursive ){ |