* [ 1662983 ] Convert cutting backslash from string

This commit is contained in:
Heng Sin Low 2007-02-20 14:42:33 +00:00
parent d198daba59
commit 646a4d07c8
3 changed files with 13 additions and 2 deletions

View File

@ -237,6 +237,7 @@ public abstract class Convert
protected String[] convertIt (String sqlStatements)
{
// Need to mask / in SQL Strings !
final char MASK = '\u001F'; // Unit Separator
StringBuffer masked = new StringBuffer(sqlStatements.length());
Matcher m = Pattern.compile("'[^']+'", Pattern.DOTALL).matcher(sqlStatements);
@ -247,7 +248,8 @@ public abstract class Convert
group = group.replace('/', MASK);
if (group.indexOf('$') != -1) // Group character needs to be escaped
group = Util.replace(group, "$", "\\$");
m.appendReplacement(masked, group);
//hengsin, [ 1662983 ] Convert cutting backslash from string
m.appendReplacement(masked, Matcher.quoteReplacement(group));
}
m.appendTail(masked);
String tempResult = masked.toString();
@ -261,8 +263,9 @@ public abstract class Convert
for (int i = 0; i < sql.length; i++)
{
String statement = sql[i];
/*
if (statement.indexOf(MASK) != -1)
statement = statement.replace(MASK, '/');
statement = statement.replace(MASK, '/');*/
result.addAll(convertStatement(statement)); // may return more than one target statement
}
// convert to array

View File

@ -193,6 +193,8 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
//hengsin, special character in replacement can cause exception
String replacement = (String) retVars.get(cont);
retValue = m.replaceFirst(Matcher.quoteReplacement(replacement));
if (retValue.indexOf(replacement) < 0)
System.err.println("Failed to recover: " + replacement);
m = p.matcher(retValue);
}
return retValue;

View File

@ -28,6 +28,12 @@ public final class Convert_PostgreSQLTest {
String sqe;
String[] r;
//[ 1662983 ] Convert cutting backslash from string
sql = "SELECT 'C:\\Documentos\\Test' FROM DUAL";
sqe = "SELECT 'C:\\Documentos\\Test'";
r = convert.convert(sql);
verify(sql, r, sqe);
// Line 407 of ImportProduct.java
sql = "ALTER TABLE LPI_Publication MODIFY AD_Client_ID NUMERIC(10) DEFAULT NULL";