From 6beb43bdde14fa3ed0775a7c853b4d6ba3b34f40 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 26 Feb 2007 14:21:36 +0000 Subject: [PATCH] * [ 1662983 ] Convert cutting backslash from string - Fixed escape issue. --- .../compiere/dbPort/Convert_PostgreSQL.java | 25 +++++++++++++++++++ .../dbPort/Convert_PostgreSQLTest.java | 7 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java index dca105ba49..1072aaba2a 100644 --- a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java +++ b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQL.java @@ -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); @@ -199,6 +200,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 diff --git a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java index c8d5941aef..7851c86fd6 100644 --- a/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java +++ b/dbPort/src/org/compiere/dbPort/Convert_PostgreSQLTest.java @@ -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);