This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push:
new d42b3433 EMPIREDB-398 DBCommand: omit parent tables in FROM clause
d42b3433 is described below
commit d42b3433f772594e7b52d59b715525880936bb3a
Author: Rainer Döbele <[email protected]>
AuthorDate: Mon Dec 12 14:07:30 2022 +0100
EMPIREDB-398 DBCommand: omit parent tables in FROM clause
---
.../main/java/org/apache/empire/db/DBCommand.java | 25 +++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
index 147566b1..7e23997b 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
@@ -78,6 +78,8 @@ public abstract class DBCommand extends DBCommandExpr
protected List<DBCompareExpr> where = null;
protected List<DBCompareExpr> having = null;
protected List<DBColumnExpr> groupBy = null;
+
+ protected Set<DBRowSet> parentTables = null; // omit parent
tables in subqueries
// Parameters for prepared Statements generation
protected boolean autoPrepareStmt = false;
@@ -257,6 +259,22 @@ public abstract class DBCommand extends DBCommandExpr
removeCommandParams(cmp);
}
}
+
+ /**
+ * Set parent tables for subquery command generation.
+ * Parent tables will be omitted to the FROM clause.
+ * @param rowSets
+ */
+ public void setParentTables(DBRowSet... rowSets)
+ {
+ if (rowSets.length>0)
+ { // add all rowsets
+ this.parentTables = new HashSet<DBRowSet>(rowSets.length);
+ for (DBRowSet r : rowSets)
+ this.parentTables.add(r);
+ }
+ else this.parentTables = null;
+ }
/**
* Returns true if the this command has either Select or Set expressions
@@ -1352,6 +1370,7 @@ public abstract class DBCommand extends DBCommandExpr
public void clear()
{
cmdParams.clear(0);
+ parentTables = null;
clearSelectDistinct();
clearSelect();
clearSet();
@@ -1821,8 +1840,12 @@ public abstract class DBCommand extends DBCommandExpr
}
for (int i=0; i<tables.size(); i++)
{
+ DBRowSet t = tables.get(i);
+ // check whether it's a parent table
+ if (this.parentTables!=null && this.parentTables.contains(t))
+ continue; // yes, ignore
+ // append
if (sep) sql.append(", ");
- DBRowSet t = tables.get(i);
t.addSQL(sql, CTX_DEFAULT|CTX_ALIAS);
sep = true;
}