cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [cayenne] 03/04: Do not use TRIM() in JOIN clauses and inside other function calls
Date Sat, 04 May 2019 15:01:05 GMT
This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit 9ef777667da5bb33e308b80a2d27443e574e2788
Author: Nikita Timofeev <stariy95@gmail.com>
AuthorDate: Sat May 4 17:15:28 2019 +0300

    Do not use TRIM() in JOIN clauses and inside other function calls
---
 .../access/sqlbuilder/sqltree/TrimmingColumnNode.java       | 13 ++++++++++++-
 .../apache/cayenne/exp/parser/ASTFunctionCallStringIT.java  |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/sqlbuilder/sqltree/TrimmingColumnNode.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/sqlbuilder/sqltree/TrimmingColumnNode.java
index c4c252b..b57e536 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/sqlbuilder/sqltree/TrimmingColumnNode.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/sqlbuilder/sqltree/TrimmingColumnNode.java
@@ -38,7 +38,7 @@ public class TrimmingColumnNode extends Node {
     public QuotingAppendable append(QuotingAppendable buffer) {
         boolean isResult = isResultNode();
         if(columnNode.getAlias() == null || isResult) {
-            if(isCharType()) {
+            if(isCharType() && isAllowedForTrimming()) {
                 appendRtrim(buffer);
                 appendAlias(buffer, isResult);
             } else if(isComparisionWithClob()) {
@@ -72,6 +72,17 @@ public class TrimmingColumnNode extends Node {
                 && columnNode.getAttribute().getType() == Types.CHAR;
     }
 
+    protected boolean isAllowedForTrimming() {
+        Node parent = getParent();
+        while(parent != null) {
+            if(parent.getType() == NodeType.JOIN || parent.getType() == NodeType.FUNCTION)
{
+                return false;
+            }
+            parent = parent.getParent();
+        }
+        return true;
+    }
+
     protected boolean isResultNode() {
         Node parent = getParent();
         while(parent != null) {
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTFunctionCallStringIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTFunctionCallStringIT.java
index 3a8742d..361c5b6 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTFunctionCallStringIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTFunctionCallStringIT.java
@@ -88,7 +88,7 @@ public class ASTFunctionCallStringIT extends ServerCase {
     public void testASTConcat() throws Exception {
         Artist a1 = createArtist("Pablo");
         Artist a2 = ObjectSelect.query(Artist.class)
-                .where(Artist.ARTIST_NAME.concat(" ", "Picasso").eq("Pablo Picasso")).selectOne(context);
+                .where(Artist.ARTIST_NAME.trim().concat(" ", "Picasso").eq("Pablo Picasso")).selectOne(context);
         assertEquals(a1, a2);
     }
 


Mime
View raw message