Mercurial > hg > monetdb-java
comparison src/main/java/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.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 | 83bfade6333e |
children | 67fa5c6147d7 |
comparison
equal
deleted
inserted
replaced
369:aa2e5d8c5047 | 370:2ab474af487c |
---|---|
4033 /** | 4033 /** |
4034 * Internal utility method to create a Statement object, execute a query and return the ResulSet object which allows scrolling. | 4034 * Internal utility method to create a Statement object, execute a query and return the ResulSet object which allows scrolling. |
4035 * As the Statement object is created internally (the caller does not see it and thus can not close it), | 4035 * As the Statement object is created internally (the caller does not see it and thus can not close it), |
4036 * we set it to close (and free server resources) when the ResultSet object is closed by the caller. | 4036 * we set it to close (and free server resources) when the ResultSet object is closed by the caller. |
4037 */ | 4037 */ |
4038 private ResultSet executeMetaDataQuery(final String query) throws SQLException { | 4038 private final ResultSet executeMetaDataQuery(final String query) throws SQLException { |
4039 final Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); | 4039 final Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
4040 ResultSet rs = null; | 4040 ResultSet rs = null; |
4041 if (stmt != null) { | 4041 if (stmt != null) { |
4042 // for debug: System.out.println("SQL (len " + query.length() + "): " + query); | 4042 // for debug: System.out.println("SQL (len " + query.length() + "): " + query); |
4043 rs = stmt.executeQuery(query); | 4043 rs = stmt.executeQuery(query); |
4057 * compose an exact match (use =) or match with wildcards (use LIKE) or IS NULL | 4057 * compose an exact match (use =) or match with wildcards (use LIKE) or IS NULL |
4058 * | 4058 * |
4059 * @param in the string to match | 4059 * @param in the string to match |
4060 * @return the SQL match part string | 4060 * @return the SQL match part string |
4061 */ | 4061 */ |
4062 private static final String composeMatchPart(final String in) { | 4062 private final String composeMatchPart(final String in) { |
4063 if (in == null) | 4063 if (in == null) |
4064 return "IS NULL"; | 4064 return "IS NULL"; |
4065 | 4065 |
4066 String cmp = "= '"; | 4066 String cmp = "= '"; |
4067 // check if SQL wildcards are used in the input, if so use LIKE | 4067 // check if SQL wildcards are used in the input, if so use LIKE |
4068 if (in.contains("%") || in.contains("_")) | 4068 if (in.contains("%") || in.contains("_")) |
4069 cmp = "LIKE '"; | 4069 cmp = "LIKE '"; |
4070 | 4070 |
4071 String val = in; | 4071 return cmp + con.escapeSpecialChars(in) + "'"; |
4072 if (in.contains("\\") || in.contains("'")) | |
4073 // all slashes and single quotes in input are escaped with a slash. | |
4074 val = in.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'"); | |
4075 | |
4076 return cmp + val + "'"; | |
4077 } | 4072 } |
4078 | 4073 |
4079 /** | 4074 /** |
4080 * Returns the given string between two double quotes for usage as | 4075 * Returns the given string between two double quotes for usage as |
4081 * exact column or table name in SQL queries. | 4076 * exact column or table name in SQL queries. |