* Implemented trunc in pl/pgsql

This commit is contained in:
Heng Sin Low 2007-01-26 10:15:19 +00:00
parent 1f49f0e571
commit 73cffd61c0
2 changed files with 13 additions and 5 deletions

View File

@ -730,13 +730,16 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
// Truncate Handling -------------------------------------------------
// begin vpj-cd e-evolution 16/07/2005
// while (retValue.indexOf("TRUNC") != -1)
//Hengsin, replace by trunc implementation in pl/pgsql
/*
if (retValue.indexOf("TRUNC(((TRUNC(") != -1)
retValue = Util.replace(retValue, "TRUNC(((TRUNC(", "(((TRUNC(");
// end vpj-cd e-evolution 16/07/2005
while (retValue.indexOf("TRUNC") != -1)
retValue = convertTrunc(retValue);
*/
// Outer Join Handling -----------------------------------------------
int index = retValue.indexOf("SELECT ");
if (index != -1 && retValue.indexOf("(+)", index) != -1)
@ -888,12 +891,15 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
} // convertRowNum
/**
* Hengsin, Replace by trunc implementation in pl/pgsql
* Convert TRUNC. Assumed that it is used for date only!
*
* @param sqlStatement
* @return converted statement
*/
/*
private String convertTrunc(String sqlStatement) {
*/
/**
* <pre>
* TRUNC(myDate)
@ -912,9 +918,11 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
*
* //begin vpj-cd e-evolution 07/12/2005
*/
/*
// index = sqlStatement.indexOf("TRUNC(");
// beforeStatement = sqlStatement.substring(0, index);
// beforeStatement = sqlStatement.replaceFirst("TRUNC" , "DATE_Trunc");
int find = -1;
find = sqlStatement.indexOf(",'Q'");
if (find != -1)
@ -967,7 +975,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
// end vpj-cd e-evolution 09/02/2005 PostgreSQL
} // convertTrunc
*/
// begin vpj-cd e-evolution 02/24/2005 PostgreSQL
/***************************************************************************

View File

@ -94,14 +94,14 @@ public final class Convert_PostgreSQLTest {
+ " C_Project_ID, AD_OrgTrx_ID, C_SalesRegion_ID,C_Activity_ID,"
+ " C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID, User1_ID, User2_ID, GL_Budget_ID,"
+ " AmtAcctDr, AmtAcctCr, Qty) "
+ "SELECT AD_Client_ID, AD_Org_ID, C_AcctSchema_ID, DATE_Trunc('day',DateAcct),"
+ "SELECT AD_Client_ID, AD_Org_ID, C_AcctSchema_ID, TRUNC(DateAcct),"
+ " Account_ID, PostingType, M_Product_ID, C_BPartner_ID,"
+ " C_Project_ID, AD_OrgTrx_ID, C_SalesRegion_ID,C_Activity_ID,"
+ " C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID, User1_ID, User2_ID, GL_Budget_ID,"
+ " COALESCE(SUM(AmtAcctDr),0), COALESCE(SUM(AmtAcctCr),0), COALESCE(SUM(Qty),0) "
+ "FROM Fact_Acct a "
+ "WHERE C_AcctSchema_ID=0"
+ " GROUP BY AD_Client_ID,AD_Org_ID, C_AcctSchema_ID, DATE_Trunc('day',DateAcct),"
+ " GROUP BY AD_Client_ID,AD_Org_ID, C_AcctSchema_ID, TRUNC(DateAcct),"
+ " Account_ID, PostingType, M_Product_ID, C_BPartner_ID,"
+ " C_Project_ID, AD_OrgTrx_ID, C_SalesRegion_ID, C_Activity_ID,"
+ " C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID, User1_ID, User2_ID, GL_Budget_ID";
@ -127,7 +127,7 @@ public final class Convert_PostgreSQLTest {
//From bug [ 1576358 ] and [ 1577055 ]
sql = "SELECT TRUNC(TO_DATE('2006-10-13','YYYY-MM-DD'),'Q') FROM DUAL";
r = convert.convert(sql);
verify(sql, r, "SELECT DATE_Trunc('quarter',TO_TIMESTAMP('2006-10-13','YYYY-MM-DD'))");
verify(sql, r, "SELECT TRUNC(TO_TIMESTAMP('2006-10-13','YYYY-MM-DD'),'Q')");
//FinReport, test inner join in subquery
sql = "UPDATE T_Report r SET (Name,Description)=("