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 8931278c EMPIREDB-452 DBCombinedCmd: fix command params in union 
statements
8931278c is described below

commit 8931278c4333ca7d08df062a7b69b56778066f8d
Author: Rainer Döbele <[email protected]>
AuthorDate: Thu Jan 2 21:14:36 2025 +0100

    EMPIREDB-452
    DBCombinedCmd: fix command params in union statements
---
 .../main/java/org/apache/empire/db/DBCmdParam.java  | 11 +++++++++++
 .../java/org/apache/empire/db/DBCombinedCmd.java    | 21 ++++++++++++++++-----
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java 
b/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java
index f3221939..96c71db2 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCmdParam.java
@@ -23,6 +23,7 @@ import java.util.Set;
 import org.apache.empire.commons.DateUtils;
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.data.DataType;
+import org.apache.empire.db.expr.column.DBValueExpr;
 import org.apache.empire.exceptions.InvalidOperationException;
 
 /**
@@ -50,6 +51,16 @@ public class DBCmdParam extends DBExpr
         this.value = getCmdParamValue(value);
     }
 
+    /**
+     * Returns a value expression for this param
+     * @param db the database
+     * @return the value expression 
+     */
+    public DBValueExpr getValueExpr(DBDatabase db)
+    {
+        return db.getValueExpr(this, type);
+    }
+
     /**
      * Returns the internal parameter value for a given "real" value.  
      * Depending on the data type this might involve wrapping the real value 
with another class.
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java 
b/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
index 2729fcf8..21b32e40 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
@@ -37,10 +37,19 @@ public class DBCombinedCmd extends DBCommandExpr
 {
     // *Deprecated* private static final long serialVersionUID = 1L;
 
+    @Override
+    protected DBSQLBuilder createSQLBuilder(String initalSQL)
+    {
+        DBSQLBuilder sql = super.createSQLBuilder(initalSQL);
+        sql.setCmdParams(this.cmdParams);
+        return sql;
+    }
+
     // Members
-    protected DBCommandExpr left;
-    protected DBCommandExpr right;
-    protected String        keyWord;
+    protected DBCommandExpr  left;
+    protected DBCommandExpr  right;
+    protected String         keyWord;
+    protected DBCmdParamList cmdParams;
 
     /**
      * Constructs a new DBFuncExpr object and
@@ -56,6 +65,7 @@ public class DBCombinedCmd extends DBCommandExpr
         this.left = left;
         this.right = right;
         this.keyWord = keyWord;
+        this.cmdParams = new DBCmdParamList();
     }
 
     @Override
@@ -206,12 +216,13 @@ public class DBCombinedCmd extends DBCommandExpr
     @Override
     public void getSelect(DBSQLBuilder sql)
     {
+        cmdParams.clear(0);
         // the left part
         left.clearOrderBy();
         if (!(left instanceof DBCombinedCmd))
         {
             sql.append("(");
-            left.getSelect(sql);
+            sql.append(left);
             sql.append(")");
         }
         else
@@ -225,7 +236,7 @@ public class DBCombinedCmd extends DBCommandExpr
         if (!(right instanceof DBCombinedCmd))
         {
             sql.append("(");
-            right.getSelect(sql);
+            sql.append(right);
             sql.append(")");
         }
         else

Reply via email to