mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Do not allow table-valued function syntax on ordinary tables and views as those
objects are not table-valued functions. Fix for ticket [73eba7ba5c7c0fc]. FossilOrigin-Name: ff5716b89f99d9c4568a39f1f52524528a631623
This commit is contained in:
24
src/select.c
24
src/select.c
@@ -3623,6 +3623,7 @@ static int flattenSubquery(
|
||||
*/
|
||||
for(i=0; i<nSubSrc; i++){
|
||||
sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
|
||||
assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
|
||||
pSrc->a[i+iFrom] = pSubSrc->a[i];
|
||||
memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
|
||||
}
|
||||
@@ -3957,6 +3958,19 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){
|
||||
return WRC_Continue;
|
||||
}
|
||||
|
||||
/*
|
||||
** Check to see if the FROM clause term pFrom has table-valued function
|
||||
** arguments. If it does, leave an error message in pParse and return
|
||||
** non-zero, since pFrom is not allowed to be a table-valued function.
|
||||
*/
|
||||
static int cannotBeFunction(Parse *pParse, struct SrcList_item *pFrom){
|
||||
if( pFrom->fg.isTabFunc ){
|
||||
sqlite3ErrorMsg(pParse, "'%s' is not a function", pFrom->zName);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_CTE
|
||||
/*
|
||||
** Argument pWith (which may be NULL) points to a linked list of nested
|
||||
@@ -4052,6 +4066,7 @@ static int withExpand(
|
||||
sqlite3ErrorMsg(pParse, pCte->zCteErr, pCte->zName);
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
if( cannotBeFunction(pParse, pFrom) ) return SQLITE_ERROR;
|
||||
|
||||
assert( pFrom->pTab==0 );
|
||||
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
|
||||
@@ -4245,15 +4260,14 @@ static int selectExpander(Walker *pWalker, Select *p){
|
||||
return WRC_Abort;
|
||||
}
|
||||
pTab->nRef++;
|
||||
if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
|
||||
return WRC_Abort;
|
||||
}
|
||||
#if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
|
||||
if( pTab->pSelect || IsVirtual(pTab) ){
|
||||
if( IsVirtual(pTab) || pTab->pSelect ){
|
||||
i16 nCol;
|
||||
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
|
||||
assert( pFrom->pSelect==0 );
|
||||
if( pFrom->fg.isTabFunc && !IsVirtual(pTab) ){
|
||||
sqlite3ErrorMsg(pParse, "'%s' is not a function", pTab->zName);
|
||||
return WRC_Abort;
|
||||
}
|
||||
pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0);
|
||||
sqlite3SelectSetName(pFrom->pSelect, pTab->zName);
|
||||
nCol = pTab->nCol;
|
||||
|
||||
Reference in New Issue
Block a user