1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-15 11:41:13 +03:00

Name resolution and "*" wildcard expansion for parenthesized FROM clauses

seems to work the same as PG.  The code is chaos, however, and needs some
cleanup.

FossilOrigin-Name: 6f9c0b07aadc5189c65c3ee4e6938aac10fc0d98f1cb06980f5e5d7b0308f237
This commit is contained in:
drh
2022-05-02 19:59:03 +00:00
parent 85f93850f7
commit 72d620bdb1
6 changed files with 27 additions and 11 deletions

View File

@@ -1635,6 +1635,7 @@ ExprList *sqlite3ExprListDup(sqlite3 *db, const ExprList *p, int flags){
pItem->bUsed = pOldItem->bUsed;
pItem->bUsingTerm = pOldItem->bUsingTerm;
pItem->bSorterRef = pOldItem->bSorterRef;
pItem->bNoExpand = pOldItem->bNoExpand;
pItem->u = pOldItem->u;
}
return pNew;

View File

@@ -2231,6 +2231,9 @@ int sqlite3ColumnsFromExprList(
}
pCol->zCnName = zName;
pCol->hName = sqlite3StrIHash(zName);
if( pX->bNoExpand ){
pCol->colFlags |= COLFLAG_NOEXPAND;
}
sqlite3ColumnPropertiesFromName(0, pCol);
if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
sqlite3OomFault(db);
@@ -5822,6 +5825,7 @@ static int selectExpander(Walker *pWalker, Select *p){
char *zTabName; /* AS name for this data source */
const char *zSchemaName = 0; /* Schema name for this data source */
int iDb; /* Schema index for this data src */
IdList *pUsing; /* USING clause for this join */
if( (zTabName = pFrom->zAlias)==0 ){
zTabName = pTab->zName;
@@ -5846,7 +5850,7 @@ static int selectExpander(Walker *pWalker, Select *p){
&& (selFlags & SF_NestedFrom)!=0
){
int ii;
IdList *pUsing = pFrom[1].u3.pUsing;
pUsing = pFrom[1].u3.pUsing;
for(ii=0; ii<pUsing->nId; ii++){
const char *zUName = pUsing->a[ii].zName;
pRight = sqlite3Expr(db, TK_ID, zUName);
@@ -5859,6 +5863,8 @@ static int selectExpander(Walker *pWalker, Select *p){
pX->bUsingTerm = 1;
}
}
}else{
pUsing = 0;
}
for(j=0; j<pTab->nCol; j++){
char *zName = pTab->aCol[j].zCnName;
@@ -5938,6 +5944,13 @@ static int selectExpander(Walker *pWalker, Select *p){
testcase( pX->zEName==0 );
}
pX->eEName = ENAME_TAB;
if( (pFrom->fg.isUsing
&& sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0)
|| (pUsing && sqlite3IdListIndex(pUsing, zName)>=0)
|| (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
){
pX->bNoExpand = 1;
}
}else if( longNames ){
pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
pX->eEName = ENAME_NAME;

View File

@@ -3008,6 +3008,7 @@ struct ExprList {
unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */
unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */
unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */
unsigned bNoExpand: 1;
union {
struct { /* Used by any ExprList other than Parse.pConsExpr */
u16 iOrderByCol; /* For ORDER BY, column number in result set */

View File

@@ -882,6 +882,7 @@ void sqlite3TreeViewBareExprList(
fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
if( pList->a[i].bUsed ) fprintf(stdout, "(used) ");
if( pList->a[i].bUsingTerm ) fprintf(stdout, "(USING-term) ");
if( pList->a[i].bNoExpand ) fprintf(stdout, "(NoExpand) ");
break;
case ENAME_SPAN:
fprintf(stdout, "SPAN(\"%s\") ", zName);