* [ 1662983 ] Convert cutting backslash from string

- Fixed escape issue.
This commit is contained in:
Heng Sin Low 2007-02-26 14:21:36 +00:00
parent 19ee138849
commit 6beb43bdde
2 changed files with 31 additions and 1 deletions

View File

@ -192,6 +192,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
for (int cont = 0; cont < retVars.size(); cont++) {
//hengsin, special character in replacement can cause exception
String replacement = (String) retVars.get(cont);
replacement = escapeBackSlash(replacement);
retValue = m.replaceFirst(Matcher.quoteReplacement(replacement));
if (retValue.indexOf(replacement) < 0)
System.err.println("Failed to recover: " + replacement);
@ -200,6 +201,30 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
return retValue;
}
private String escapeBackSlash(String in)
{
StringBuffer out = new StringBuffer();
boolean escape = false;
int size = in.length();
for(int i = 0; i < size; i++) {
char c = in.charAt(i);
out.append(c);
if (c == '\\')
{
escape = true;
out.append(c);
}
}
if (escape)
{
return "E" + out.toString();
}
else
{
return out.toString();
}
}
/**
* Clean up Statement. Remove all comments and while spaces Database
* specific functionality can me tagged as follows:

View File

@ -30,7 +30,12 @@ public final class Convert_PostgreSQLTest {
//[ 1662983 ] Convert cutting backslash from string
sql = "SELECT 'C:\\Documentos\\Test' FROM DUAL";
sqe = "SELECT 'C:\\Documentos\\Test'";
sqe = "SELECT E'C:\\\\Documentos\\\\Test'";
r = convert.convert(sql);
verify(sql, r, sqe);
sql = "SELECT 'C:Document' FROM DUAL";
sqe = "SELECT 'C:Document'";
r = convert.convert(sql);
verify(sql, r, sqe);