diff options
author | drh <> | 2023-02-02 15:28:40 +0000 |
---|---|---|
committer | drh <> | 2023-02-02 15:28:40 +0000 |
commit | 6f31eac7d857ab8215707433e5f4196be73c5ba8 (patch) | |
tree | 928c10f817b9eeaa1dad98a7e9797cdaf2bc543e /src/resolve.c | |
parent | 7667eedf953e42c7a8e6371a59357eeffe6630db (diff) | |
download | sqlite-6f31eac7d857ab8215707433e5f4196be73c5ba8.tar.gz sqlite-6f31eac7d857ab8215707433e5f4196be73c5ba8.zip |
Resolve all possible aliases and variations of the schema table names.
FossilOrigin-Name: e7a0112b235d97cb68c92b967bf2218b90258c243ec2b638aaac142392873126
Diffstat (limited to 'src/resolve.c')
-rw-r--r-- | src/resolve.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/resolve.c b/src/resolve.c index 0d196ac37..d5e639abc 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -203,6 +203,33 @@ static void extendFJMatch( } /* +** Return TRUE (non-zero) if zTab is a valid name for the schema table pTab. +*/ +static SQLITE_NOINLINE int isValidSchemaTableName( + const char *zTab, /* Name as it appears in the SQL */ + Table *pTab, /* The schema table we are trying to match */ + Schema *pSchema /* non-NULL if a database qualifier is present */ +){ + const char *zLegacy; + const char *zPreferred; + assert( pTab!=0 ); + assert( pTab->tnum==1 ); + if( sqlite3StrNICmp(zTab, "sqlite_", 7)!=0 ) return 0; + zLegacy = pTab->zName; + zPreferred = sqlite3PreferredTableName(zLegacy); + if( sqlite3StrICmp(zTab, zPreferred)==0 ) return 1; + if( pSchema && strcmp(zLegacy+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0){ + if( sqlite3StrICmp(zTab+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 + || sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 + || sqlite3StrICmp(zTab+7, &LEGACY_SCHEMA_TABLE[7])==0 + ){ + return 1; + } + } + return 0; +} + +/* ** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up ** that name in the set of source tables in pSrcList and make the pExpr ** expression node refer back to that source column. The following changes @@ -355,15 +382,17 @@ static int lookupName( } assert( zDb==0 || zTab!=0 ); if( zTab ){ - const char *zTabName; if( zDb ){ if( pTab->pSchema!=pSchema ) continue; if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue; } - zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName; - assert( zTabName!=0 ); - if( sqlite3StrICmp(zTabName, zTab)!=0 ){ - continue; + if( pItem->zAlias!=0 ){ + if( sqlite3StrICmp(zTab, pItem->zAlias)!=0 ){ + continue; + } + }else if( sqlite3StrICmp(zTab, pTab->zName)!=0 ){ + if( pTab->tnum!=1 ) continue; + if( !isValidSchemaTableName(zTab, pTab, pSchema) ) continue; } assert( ExprUseYTab(pExpr) ); if( IN_RENAME_OBJECT && pItem->zAlias ){ |