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 e3cde97  EMPIREDB-359 Allow multiple occurrences of column placeholder
e3cde97 is described below

commit e3cde9700a13a5079504cb7dc4cbd43de54fe802
Author: Rainer Döbele <[email protected]>
AuthorDate: Fri Sep 3 14:22:45 2021 +0200

    EMPIREDB-359
    Allow multiple occurrences of column placeholder
---
 .../empire/db/expr/column/DBAbstractFuncExpr.java  | 32 +++++++++++++---------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git 
a/empire-db/src/main/java/org/apache/empire/db/expr/column/DBAbstractFuncExpr.java
 
b/empire-db/src/main/java/org/apache/empire/db/expr/column/DBAbstractFuncExpr.java
index 1a2e7f8..100ecd0 100644
--- 
a/empire-db/src/main/java/org/apache/empire/db/expr/column/DBAbstractFuncExpr.java
+++ 
b/empire-db/src/main/java/org/apache/empire/db/expr/column/DBAbstractFuncExpr.java
@@ -209,20 +209,26 @@ public abstract class DBAbstractFuncExpr extends 
DBColumnExpr
                 // template = template.replaceAll("\\{" + String.valueOf(i) + 
"\\}", value);
                 template = StringUtils.replaceAll(template, ph, paramAsString);
             }
-        }
-        // Get Prefix and Postfix
-        String prefix  = template;
-        String postfix = "";
-        int sep = template.indexOf("?");
-        if (sep >= 0)
+        }        
+        // Assemble SQL
+        int beg = 0;
+        while (true)
         {
-            prefix  = template.substring(0, sep);
-            postfix = template.substring(sep + 1);
-        } 
-        // append
-        sql.append(prefix);
-        expr.addSQL(sql, (context & ~CTX_ALIAS));
-        sql.append(postfix);
+            int end = template.indexOf("?", beg);
+            if (end < 0)
+                break;
+            // part
+            sql.append(template.substring(beg, end));
+            expr.addSQL(sql, (context & ~CTX_ALIAS));
+            beg = end + 1;
+        }
+        if (beg < template.length())
+        {   // add the rest
+            sql.append(template.substring(beg));
+            // special case: Nothing added yet
+            if (beg==0)
+                log.warn("No Placeholder for Column found in function 
template.");
+        }
     }
 
     @Override

Reply via email to