[ 1742835 ] Problem in Doc_MatchInv DECODE Function

This commit is contained in:
Heng Sin Low 2007-06-25 13:22:46 +00:00
parent 6ceff048ba
commit 4e12c0ec76
3 changed files with 63 additions and 48 deletions

View File

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

View File

@ -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]);
}
}

View File

@ -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;
}
}