From 1e80c340bee3f825c7e9f942ae23819d05b7817e Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Sat, 17 May 2008 07:41:23 +0000 Subject: [PATCH] BF [ 1964496 ] AccessSqlParser is not parsing well JOIN CLAUSE * AccessSqlParserTest: don't invoke Adempiere.startup() on setUp() because is not needed * organized imports --- .../org/compiere/model/AccessSqlParser.java | 29 ++++++++++--------- .../compiere/model/AccessSqlParserTest.java | 20 +++++++++---- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/base/src/org/compiere/model/AccessSqlParser.java b/base/src/org/compiere/model/AccessSqlParser.java index 0b86ce2d34..9cad20e458 100644 --- a/base/src/org/compiere/model/AccessSqlParser.java +++ b/base/src/org/compiere/model/AccessSqlParser.java @@ -16,21 +16,22 @@ *****************************************************************************/ package org.compiere.model; -import java.util.*; +import java.util.ArrayList; +import java.util.StringTokenizer; +import java.util.logging.Level; -import java.util.logging.*; -import org.compiere.util.*; +import org.compiere.util.CLogMgt; +import org.compiere.util.CLogger; /** * Parse FROM in SQL WHERE clause - *

- * Change log: - *

* * @author Jorg Janke * @version $Id: AccessSqlParser.java,v 1.3 2006/07/30 00:58:36 jjanke Exp $ + * + * @author Teo Sarca, SC ARHIPAC SERVICE SRL + *
  • BF [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug + *
  • BF [ 1964496 ] AccessSqlParser is not parsing well JOIN CLAUSE */ public class AccessSqlParser { @@ -226,12 +227,12 @@ public class AccessSqlParser int index = from.lastIndexOf(WHERE); // end at where if (index != -1) from = from.substring(0, index); - from = Util.replace(from, " AS ", " "); - from = Util.replace(from, " as ", " "); - from = Util.replace(from, " INNER JOIN ", ", "); - from = Util.replace(from, " LEFT OUTER JOIN ", ", "); - from = Util.replace(from, " RIGHT OUTER JOIN ", ", "); - from = Util.replace(from, " FULL JOIN ", ", "); + from = from.replaceAll("[\r\n\t ]+AS[\r\n\t ]+", " "); + from = from.replaceAll("[\r\n\t ]+as[\r\n\t ]+", " "); + from = from.replaceAll("[\r\n\t ]+INNER[\r\n\t ]+JOIN[\r\n\t ]+", ", "); + from = from.replaceAll("[\r\n\t ]+LEFT[\r\n\t ]+OUTER[\r\n\t ]+JOIN[\r\n\t ]+", ", "); + from = from.replaceAll("[\r\n\t ]+RIGHT[\r\n\t ]+OUTER[\r\n\t ]+JOIN[\r\n\t ]+", ", "); + from = from.replaceAll("[\r\n\t ]+FULL[\r\n\t ]+JOIN[\r\n\t ]+", ", "); // Remove ON clause - assumes that there is no IN () in the clause index = from.indexOf(ON); while (index != -1) diff --git a/base/src/org/compiere/model/AccessSqlParserTest.java b/base/src/org/compiere/model/AccessSqlParserTest.java index 5b743630dc..549dd81c5a 100644 --- a/base/src/org/compiere/model/AccessSqlParserTest.java +++ b/base/src/org/compiere/model/AccessSqlParserTest.java @@ -16,8 +16,7 @@ *****************************************************************************/ package org.compiere.model; -import junit.framework.*; -import org.compiere.*; +import junit.framework.TestCase; /** * AccessSqlParserTest tests the class @@ -58,7 +57,7 @@ public class AccessSqlParserTest extends TestCase protected void setUp() throws Exception { super.setUp(); - Adempiere.startup(true); +// Adempiere.startup(true); } /** @@ -210,10 +209,13 @@ public class AccessSqlParserTest extends TestCase } /** - * teo_sarca - [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug + *
  • teo_sarca - [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug + *
  • teo_sarca - [ 1964496 ] AccessSqlParser is not parsing well JOIN CLAUSE */ public void testTableNameParsing() { + // + // BF [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug String sql = "SELECT SUM(il.QtyInvoiced)\n" + "FROM RV_C_Invoice\n" @@ -221,7 +223,15 @@ public class AccessSqlParserTest extends TestCase + "INNER JOIN RV_C_InvoiceLine il ON (C_Invoice.C_Invoice_ID=il.C_Invoice_ID) WHERE\n" + "C_Invoice.IsSOTrx='Y' AND C_Invoice.Processed='Y' AND C_Invoice.IsPaid='Y'"; AccessSqlParser fixture = new AccessSqlParser(sql); - assertEquals("AccessSqlParser[RV_C_Invoice=C_Invoice|0]", fixture.toString()); + assertEquals("AccessSqlParser[RV_C_Invoice=C_Invoice,RV_C_InvoiceLine=il|0]", fixture.toString()); + // + // BF [ 1964496 ] AccessSqlParser is not parsing well JOIN CLAUSE + sql = + "SELECT C_Invoice.* FROM C_Invoice\n" + +"INNER JOIN C_BPartner bp ON (bp.C_BPartner_ID=C_Invoice.C_BPartner_ID) WHERE 1=0"; + ; + fixture = new AccessSqlParser(sql); + assertEquals("AccessSqlParser[C_Invoice,C_BPartner=bp|0]", fixture.toString()); } }