diff --git a/base/src/org/compiere/dbPort/Convert_PostgreSQL.java b/base/src/org/compiere/dbPort/Convert_PostgreSQL.java index 01257985cb..6d428a670a 100644 --- a/base/src/org/compiere/dbPort/Convert_PostgreSQL.java +++ b/base/src/org/compiere/dbPort/Convert_PostgreSQL.java @@ -15,11 +15,9 @@ package org.compiere.dbPort; import java.math.BigDecimal; import java.util.ArrayList; -import java.util.Iterator; import java.util.Map; import java.util.TreeMap; import java.util.Vector; -import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.StringTokenizer; import org.compiere.util.CLogger; @@ -791,51 +789,6 @@ public class Convert_PostgreSQL extends Convert_SQL92 { return result; } - private boolean isOperator(char c) - { - if ('=' == c) - return true; - else if ('<' == c) - return true; - else if ('>' == c) - return true; - else if ('|' == c) - return true; - else if ('(' == c) - return true; - else if (')' == c) - return true; - else if ('+' == c) - return true; - else if ('-' == c) - return true; - else if ('*' == c) - return true; - else if ('/' == c) - return true; - else if ('!' == c) - return true; - else if (',' == c) - return true; - else if ('?' == c) - return true; - else if ('#' == c) - return true; - else if ('@' == c) - return true; - else if ('~' == c) - return true; - else if ('&' == c) - return true; - else if ('^' == c) - return true; - else if ('!' == c) - return true; - else - return false; - } - - /** * Check if token is a valid sql identifier * @param token diff --git a/base/src/org/compiere/dbPort/Convert_PostgreSQLTest.java b/base/src/org/compiere/dbPort/Convert_PostgreSQLTest.java index 19b4cfff53..1c86efc02a 100644 --- a/base/src/org/compiere/dbPort/Convert_PostgreSQLTest.java +++ b/base/src/org/compiere/dbPort/Convert_PostgreSQLTest.java @@ -336,5 +336,17 @@ public final class Convert_PostgreSQLTest extends TestCase{ sqe = "SELECT supplier_name, CASE WHEN supplier_id=10000 THEN 'IBM' WHEN supplier_id=10001 THEN 'Microsoft' WHEN supplier_id=10002 THEN 'Hewlett Packard' ELSE 'Gateway' END FROM suppliers"; r = convert.convert(sql); assertEquals(sqe, r[0]); + + //doc_matchinv update average cost, bug [ 1742835 ] + sql = "UPDATE M_Product_Costing " + + "SET CostAverage = CostAverageCumAmt/DECODE(CostAverageCumQty, 0,1, CostAverageCumQty) " + + "WHERE C_AcctSchema_ID=0" + + " AND M_Product_ID=0"; + sqe = "UPDATE M_Product_Costing " + + "SET CostAverage = CostAverageCumAmt/CASE WHEN CostAverageCumQty=0 THEN 1 ELSE CostAverageCumQty END " + + "WHERE C_AcctSchema_ID=0" + + " AND M_Product_ID=0"; + r = convert.convert(sql); + assertEquals(sqe, r[0]); } } \ No newline at end of file diff --git a/base/src/org/compiere/dbPort/Convert_SQL92.java b/base/src/org/compiere/dbPort/Convert_SQL92.java index 0b3ccb7dbd..49794bd371 100644 --- a/base/src/org/compiere/dbPort/Convert_SQL92.java +++ b/base/src/org/compiere/dbPort/Convert_SQL92.java @@ -339,7 +339,8 @@ public abstract class Convert_SQL92 extends Convert { int index = statement.toUpperCase().indexOf("DECODE", fromIndex); if (index <= 0) return sqlStatement; - if (Character.isWhitespace(statement.charAt(index - 1)) == false) + char previousChar = statement.charAt(index - 1); + if (!(Character.isWhitespace(previousChar) || isOperator(previousChar))) return sqlStatement; String firstPart = statement.substring(0,index); @@ -434,5 +435,54 @@ public abstract class Convert_SQL92 extends Convert { return sqlStatement; } // convertDelete + + /** + * Is character a valid sql operator + * @param c + * @return boolean + */ + protected boolean isOperator(char c) + { + if ('=' == c) + return true; + else if ('<' == c) + return true; + else if ('>' == c) + return true; + else if ('|' == c) + return true; + else if ('(' == c) + return true; + else if (')' == c) + return true; + else if ('+' == c) + return true; + else if ('-' == c) + return true; + else if ('*' == c) + return true; + else if ('/' == c) + return true; + else if ('!' == c) + return true; + else if (',' == c) + return true; + else if ('?' == c) + return true; + else if ('#' == c) + return true; + else if ('@' == c) + return true; + else if ('~' == c) + return true; + else if ('&' == c) + return true; + else if ('^' == c) + return true; + else if ('!' == c) + return true; + else + return false; + } }