1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Return an error if a CTE specifies a different number of columns than its SELECT statement returns.

FossilOrigin-Name: 9a514b50e4b01f109fbdb0aabcbfe1ddab129b44
This commit is contained in:
dan
2014-01-15 15:27:51 +00:00
parent a379b32f33
commit 60e7068d75
4 changed files with 55 additions and 13 deletions

View File

@@ -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 ){