aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordan <Dan Kennedy>2023-09-16 18:18:57 +0000
committerdan <Dan Kennedy>2023-09-16 18:18:57 +0000
commitf99a27fab927a8c8fc8dc3c7d179654fa2b12fcd (patch)
treeef19ab0b6c83995e1a2470238c45849691c5a2d2 /src/expr.c
parent259970510537803c2e92585c1596a849ba12d3bf (diff)
parenta91fe453399ddc836e412a5e8f6473f8a3e68066 (diff)
downloadsqlite-f99a27fab927a8c8fc8dc3c7d179654fa2b12fcd.tar.gz
sqlite-f99a27fab927a8c8fc8dc3c7d179654fa2b12fcd.zip
Fix resolution of "rowid" and similar identifiers in queries that use nested joins.
FossilOrigin-Name: 37ec43d92bde13efc71fa57ff5e59c4a95b9054c298f844aefeb06d4a91ad0d4
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/expr.c b/src/expr.c
index 9f876e610..63c5a8faa 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -2695,6 +2695,27 @@ int sqlite3IsRowid(const char *z){
}
/*
+** Return a pointer to a buffer containing a usable rowid alias for table
+** pTab. An alias is usable if there is not an explicit user-defined column
+** of the same name.
+*/
+const char *sqlite3RowidAlias(Table *pTab){
+ const char *azOpt[] = {"_ROWID_", "ROWID", "OID"};
+ int ii;
+ assert( VisibleRowid(pTab) );
+ for(ii=0; ii<ArraySize(azOpt); ii++){
+ int iCol;
+ for(iCol=0; iCol<pTab->nCol; iCol++){
+ if( sqlite3_stricmp(azOpt[ii], pTab->aCol[iCol].zCnName)==0 ) break;
+ }
+ if( iCol==pTab->nCol ){
+ return azOpt[ii];
+ }
+ }
+ return 0;
+}
+
+/*
** pX is the RHS of an IN operator. If pX is a SELECT statement
** that can be simplified to a direct table access, then return
** a pointer to the SELECT statement. If pX is not a SELECT statement,