Mercurial > hg > monetdb-java
diff src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @ 370:2ab474af487c
Add utility method to replace calls to x.replaceAll().replaceAll() in several places.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 17 Sep 2020 17:33:49 +0200 (2020-09-17) |
parents | 54137aeb1f92 |
children | ffdc7b0e102d |
line wrap: on
line diff
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java @@ -1640,6 +1640,8 @@ public class MonetConnection //== end methods of interface java.sql.Connection + //== internal helper methods which do not belong to the JDBC interface + /** * @return whether the JDBC BLOB type should be mapped to VARBINARY type. * This allows generic JDBC programs to fetch Blob data via getBytes() @@ -1683,6 +1685,23 @@ public class MonetConnection return sb.toString(); } + /** + * Utility method to escape all ocurrences of special characters + * (double slashes and single quotes) in a string literal + * It is called from: MonetDatabaseMetaData and MonetPreparedStatement + */ + final String escapeSpecialChars(final String in) { + String ret = in; + if (ret.contains("\\\\")) + // all double slashes in input need to be escaped. + ret = ret.replaceAll("\\\\", "\\\\\\\\"); + if (ret.contains("'")) + // all single quotes in input need to be escaped. + ret = ret.replaceAll("'", "\\\\'"); + return ret; + } + + // Internal cache for 3 static mserver environment values, so they aren't queried from mserver again and again private String env_current_user = null; private String env_monet_version = null;