BF [ 1964496 ] AccessSqlParser is not parsing well JOIN CLAUSE

* AccessSqlParserTest: don't invoke Adempiere.startup() on setUp() because is not needed
* organized imports
This commit is contained in:
teo_sarca 2008-05-17 07:41:23 +00:00
parent 452c495ab5
commit 1e80c340be
2 changed files with 30 additions and 19 deletions

View File

@ -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
* <p>
* Change log:
* <ul>
* <li>2007-02-10 - teo_sarca - [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug
* </ul>
*
* @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
* <li>BF [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug
* <li>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)

View File

@ -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
* <li>teo_sarca - [ 1652623 ] AccessSqlParser.getTableInfo(String) - tablename parsing bug
* <li>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());
}
}