From 5278ced530541472c622ec4cfdcd238382ea4dfa Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 17 Jan 2007 22:36:56 +0000 Subject: [PATCH] * [ 1638046 ] DB-error shema "j" does not exist when creating GL journal --- .../compiere/dbPort/Convert_PostgreSQL.java | 20 +++++++++++-------- .../dbPort/Convert_PostgreSQLTest.java | 16 ++++++++++++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java index cb24bc0c0e..329ca08a3d 100644 --- a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java +++ b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java @@ -866,7 +866,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 { } } else if (retValue.indexOf("ROWNUM=1") > 1) { int rownum = retValue.indexOf("ROWNUM=1"); - System.out.println("retValue" + retValue); + //System.out.println("retValue" + retValue); if (retValue.substring(0, rownum).contains("WHERE")) { retValue = Util.replace(retValue, "ROWNUM=1 ", " LIMIT 1"); return convert + retValue; @@ -959,7 +959,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 { // sqlStatement = sqlStatement.replaceFirst(",'DY'", ""); return sqlStatement; } - System.out.println("SQL=" + sqlStatement); + //System.out.println("SQL=" + sqlStatement); return sqlStatement; // end vpj-cd e-evolution 09/02/2005 PostgreSQL @@ -1231,7 +1231,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 { if (f < 0) { updateField = updateFields; joinField = joinFields.trim(); - if (joinField.indexOf(".") < 0) { + if (joinField.indexOf(".") < 0 && isIdentifier(joinField)) { joinField = joinAlias + "." + joinField; } @@ -1279,8 +1279,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 { // fieldsjoin.indexOf(','); joinField = joinFields.substring(0, fj).trim(); - if (joinField.indexOf(".") < 0 != joinField - .equals("SysDate")) { + if (joinField.indexOf(".") < 0 && isIdentifier(joinField)) { joinField = joinAlias + "." + joinField; } Update.append(updateField.trim()); @@ -1464,9 +1463,14 @@ public class Convert_PostgreSQL extends Convert_SQL92 { */ private boolean isIdentifier(String token) { - if (isOperator(token)) - return false; - else if (token.startsWith("'") && token.startsWith("'")) + int size = token.length(); + for (int i = 0; i < size; i++) + { + char c = token.charAt(i); + if (isOperator(c)) + return false; + } + if (token.startsWith("'") && token.endsWith("'")) return false; else { diff --git a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java index e101d9f766..b94a1e51ce 100644 --- a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java +++ b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java @@ -180,7 +180,21 @@ public final class Convert_PostgreSQLTest { sql="UPDATE T_InventoryValue SET PricePO = (SELECT currencyConvert (po.PriceList,po.C_Currency_ID,T_InventoryValue.C_Currency_ID,T_InventoryValue.DateValue,null, po.AD_Client_ID,po.AD_Org_ID) FROM M_Product_PO po WHERE po.M_Product_ID=T_InventoryValue.M_Product_ID AND po.IsCurrentVendor='Y' AND RowNum=1), PriceList = (SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,T_InventoryValue.C_Currency_ID,T_InventoryValue.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID) FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp WHERE pp.M_Product_ID=T_InventoryValue.M_Product_ID AND pp.M_PriceList_Version_ID=T_InventoryValue.M_PriceList_Version_ID AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID AND plv.M_PriceList_ID=pl.M_PriceList_ID), PriceStd = (SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,T_InventoryValue.C_Currency_ID,T_InventoryValue.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID) FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp WHERE pp.M_Product_ID=T_InventoryValue.M_Product_ID AND pp.M_PriceList_Version_ID=T_InventoryValue.M_PriceList_Version_ID AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID AND plv.M_PriceList_ID=pl.M_PriceList_ID), PriceLimit = (SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,T_InventoryValue.C_Currency_ID,T_InventoryValue.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID) FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp WHERE pp.M_Product_ID=T_InventoryValue.M_Product_ID AND pp.M_PriceList_Version_ID=T_InventoryValue.M_PriceList_Version_ID AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID AND plv.M_PriceList_ID=pl.M_PriceList_ID)"; r = convert.convert(sql); verify(sql, r, "UPDATE T_InventoryValue SET PricePO = (SELECT currencyConvert (po.PriceList,po.C_Currency_ID,T_InventoryValue.C_Currency_ID,T_InventoryValue.DateValue,null, po.AD_Client_ID,po.AD_Org_ID) FROM M_Product_PO po WHERE po.M_Product_ID=T_InventoryValue.M_Product_ID AND po.IsCurrentVendor='Y' LIMIT 1 ), PriceList = (SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,T_InventoryValue.C_Currency_ID,T_InventoryValue.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID) FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp WHERE pp.M_Product_ID=T_InventoryValue.M_Product_ID AND pp.M_PriceList_Version_ID=T_InventoryValue.M_PriceList_Version_ID AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID AND plv.M_PriceList_ID=pl.M_PriceList_ID), PriceStd = (SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,T_InventoryValue.C_Currency_ID,T_InventoryValue.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID) FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp WHERE pp.M_Product_ID=T_InventoryValue.M_Product_ID AND pp.M_PriceList_Version_ID=T_InventoryValue.M_PriceList_Version_ID AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID AND plv.M_PriceList_ID=pl.M_PriceList_ID), PriceLimit = (SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,T_InventoryValue.C_Currency_ID,T_InventoryValue.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID) FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp WHERE pp.M_Product_ID=T_InventoryValue.M_Product_ID AND pp.M_PriceList_Version_ID=T_InventoryValue.M_PriceList_Version_ID AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID AND plv.M_PriceList_ID=pl.M_PriceList_ID)"); - + + //bug [ 1638046 ] + sql = "UPDATE GL_JournalBatch jb" + + " SET (TotalDr, TotalCr) = (SELECT COALESCE(SUM(TotalDr),0), COALESCE(SUM(TotalCr),0)" + + " FROM GL_Journal j WHERE j.IsActive='Y' AND jb.GL_JournalBatch_ID=j.GL_JournalBatch_ID) " + + "WHERE GL_JournalBatch_ID=0"; + r = convert.convert(sql); + sqe = "UPDATE GL_JournalBatch SET TotalDr=" + + "( SELECT COALESCE(SUM(TotalDr),0) " + + "FROM GL_Journal j WHERE j.IsActive='Y' AND " + + "GL_JournalBatch.GL_JournalBatch_ID=j.GL_JournalBatch_ID ) ," + + "TotalCr=( SELECT COALESCE(SUM(TotalCr),0) FROM GL_Journal j " + + "WHERE j.IsActive='Y' AND GL_JournalBatch.GL_JournalBatch_ID=j.GL_JournalBatch_ID ) " + + " WHERE GL_JournalBatch_ID=0"; + verify(sql, r, sqe); } private void verify(String original, String[] converted, String expected) {