aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordan <Dan Kennedy>2023-09-15 18:36:51 +0000
committerdan <Dan Kennedy>2023-09-15 18:36:51 +0000
commit81b70d97eb3ccf25d8fec5544009e6ebe9225b4a (patch)
treefce9a903cbc8d9ac0d341dd697e20af9f7931da3 /src/expr.c
parent581b22936297aa4cc19f2ee1920804ce96d5459d (diff)
downloadsqlite-81b70d97eb3ccf25d8fec5544009e6ebe9225b4a.tar.gz
sqlite-81b70d97eb3ccf25d8fec5544009e6ebe9225b4a.zip
Allow expressions like "<tbl>.rowid" to refer to implicit rowid columns of tables in nested FROM clauses.
FossilOrigin-Name: 59a1bbc69f5dbb33418fa4b383393fb13a46bc1e531577da8ad54ae2fad5a10e
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,