* Fixed a convertAlias bug

This commit is contained in:
Heng Sin Low 2006-12-30 08:13:14 +00:00
parent 8476ae058f
commit 61258fafaf
2 changed files with 21 additions and 2 deletions

View File

@ -102,7 +102,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
} else if (cmpString.indexOf("DELETE FROM") != -1) {
result.add(converSimpleStatement(convertAlias(statement)));
} else if (cmpString.indexOf("UPDATE") != -1) {
} else if (cmpString.indexOf("UPDATE ") != -1) {
result
.add(converSimpleStatement(convertUpdate(convertAlias(statement))));
} else {
@ -1401,7 +1401,10 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
if ("VALUES".equalsIgnoreCase(tokens[3]) ||
"SELECT".equalsIgnoreCase(tokens[3]))
return sqlStatement;
if (!tokens[3].startsWith("(")) {
if (tokens[2].indexOf("(") > 0)
return sqlStatement;
else if ((tokens[3].indexOf("(") < 0) ||
tokens[3].indexOf("(") > 0) {
table = tokens[2];
alias = tokens[3];
} else {
@ -1414,6 +1417,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
alias = tokens[3];
}
if (table != null && alias != null ) {
if (alias.indexOf("(") > 0) alias = alias.substring(0, alias.indexOf("("));
String converted = sqlStatement.replaceFirst("\\s"+alias+"\\s", " ");
converted = converted.replaceAll("\\s"+alias+"\\.", " " + table+".");
converted = converted.replaceAll(","+alias+"\\.", "," + table+".");

View File

@ -124,6 +124,21 @@ public final class Convert_PostgreSQLTest {
+ " AND M_InOut_ID=0)";
r = convert.convert(sql);
verify(sql, r, "DELETE FROM M_InOutLineMA WHERE EXISTS (SELECT * FROM M_InOutLine l WHERE l.M_InOutLine_ID=M_InOutLineMA.M_InOutLine_ID AND M_InOut_ID=0)");
//MLanguage.addTable
sql = "INSERT INTO " + "AD_Column_Trl"
+ "(AD_Language,IsTranslated, AD_Client_ID,AD_Org_ID, "
+ "Createdby,UpdatedBy, "
+ "AD_Column_ID,Name) "
+ "SELECT '" + "es_MX" + "','N', AD_Client_ID,AD_Org_ID, "
+ 100 + "," + 100 + ", "
+ "AD_Column_ID,Name"
+ " FROM " + "AD_Column"
+ " WHERE " + "AD_Column_ID" + " NOT IN (SELECT " + "AD_Column_ID"
+ " FROM " + "AD_Column_Trl"
+ " WHERE AD_Language='" + "es_MX" + "')";
r = convert.convert(sql);
verify(sql, r, "INSERT INTO AD_Column_Trl(AD_Language,IsTranslated, AD_Client_ID,AD_Org_ID, Createdby,UpdatedBy, AD_Column_ID,Name) SELECT 'es_MX','N', AD_Client_ID,AD_Org_ID, 100,100, AD_Column_ID,Name FROM AD_Column WHERE AD_Column_ID NOT IN (SELECT AD_Column_ID FROM AD_Column_Trl WHERE AD_Language='es_MX')");
}
private void verify(String original, String[] converted, String expected) {