* [ 1638046 ] DB-error shema "j" does not exist when creating GL journal

This commit is contained in:
Heng Sin Low 2007-01-17 22:36:56 +00:00
parent a18373e5a9
commit 5278ced530
2 changed files with 27 additions and 9 deletions

View File

@ -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
{

View File

@ -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) {