[ 1807657 ] MProduct.afterSave() throws SQL Error in Postgres

This commit is contained in:
Heng Sin Low 2007-10-05 03:56:08 +00:00
parent ea6cce5ebb
commit 370c205e17
2 changed files with 25 additions and 1 deletions

View File

@ -507,12 +507,13 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
String joinFields = null; String joinFields = null;
String joinFromClause = null; String joinFromClause = null;
int joinFromClauseStart = 0; int joinFromClauseStart = 0;
open = -1;
for (int i = 0; i < subQuery.length(); i++) for (int i = 0; i < subQuery.length(); i++)
{ {
char c = subQuery.charAt(i); char c = subQuery.charAt(i);
if (Character.isWhitespace(c)) if (Character.isWhitespace(c))
{ {
if (token.length() > 0) if (token.length() > 0 && open < 0)
{ {
if ("FROM".equalsIgnoreCase(previousToken)) if ("FROM".equalsIgnoreCase(previousToken))
{ {
@ -546,6 +547,10 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
(previousToken != null && previousToken.toUpperCase().endsWith("SELECT")))) (previousToken != null && previousToken.toUpperCase().endsWith("SELECT"))))
joinFieldsBegin = i; joinFieldsBegin = i;
} }
else if (c == '(')
open++;
else if (c == ')')
open--;
token.append(c); token.append(c);
} }
} }

View File

@ -28,6 +28,25 @@ public final class Convert_PostgreSQLTest extends TestCase{
public Convert_PostgreSQLTest() {} public Convert_PostgreSQLTest() {}
public void test1807657() {
sql = "UPDATE A_Asset a "
+ "SET (Name, Description)="
+ "(SELECT SUBSTR((SELECT bp.Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=a.C_BPartner_ID) || ' - ' || p.Name,1,60), p.Description "
+ "FROM M_Product p "
+ "WHERE p.M_Product_ID=a.M_Product_ID) "
+ "WHERE IsActive='Y' "
+ "AND M_Product_ID=0";
sqe = "UPDATE A_Asset "
+ "SET Name=SUBSTR((SELECT bp.Name FROM C_BPartner bp WHERE bp.C_BPartner_ID=A_Asset.C_BPartner_ID) || ' - ' || p.Name,1,60),"
+ "Description=p.Description "
+ "FROM M_Product p "
+ "WHERE p.M_Product_ID=A_Asset.M_Product_ID "
+ "AND A_Asset.IsActive='Y' AND A_Asset.M_Product_ID=0";
r = convert.convert(sql);
assertEquals(sqe, r[0]);
}
public void test1751966() { public void test1751966() {
sql = "UPDATE I_ReportLine i " sql = "UPDATE I_ReportLine i "
+ "SET (Description, SeqNo, IsSummary, IsPrinted, LineType, CalculationType, AmountType, PostingType)=" + "SET (Description, SeqNo, IsSummary, IsPrinted, LineType, CalculationType, AmountType, PostingType)="