From 73cffd61c0086005a126b6ed8beab95e0088bc2d Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 26 Jan 2007 10:15:19 +0000 Subject: [PATCH] * Implemented trunc in pl/pgsql --- .../src/org/compiere/dbPort/Convert_PostgreSQL.java | 12 ++++++++++-- .../org/compiere/dbPort/Convert_PostgreSQLTest.java | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java index b2db7ed28e..3cb96a4808 100644 --- a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java +++ b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java @@ -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) { + */ /** *
 		 *        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
 
 	/***************************************************************************
diff --git a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java
index 821e5cd0ae..f9bc4a3588 100644
--- a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java
+++ b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java
@@ -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)=("