Mercurial > hg > monetdb-java
changeset 680:238d6a3a6469
Improve composeMatchPart(final String in). Prevent parsing pattern when length is 0. Optimise patterns: % or %%.
author | Martin van Dinther <martin.van.dinther@monetdbsolutions.com> |
---|---|
date | Thu, 03 Nov 2022 19:45:52 +0100 (2022-11-03) |
parents | a2dfec33dbcb |
children | 32e7ac7b979e |
files | src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java tests/JDBC_API_Tester.java |
diffstat | 2 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java +++ b/src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @@ -4240,11 +4240,17 @@ public final class MonetDatabaseMetaData if (in == null) return "IS NULL"; + final int len = in.length(); + if (len == 0) + return "= ''"; + + if (in.equals("%") || in.equals("%%")) + return "LIKE '%'"; + // Scan input string for SQL wildcard characters: % and _ // When they are all prefixed by a backslash then the backslash is removed (to allow usage of = comparator) // else it needs to be interpreted as a wildcard and we need to use LIKE instead of = comparator. // A backslash can be escaped by using two backslashes. - final int len = in.length(); final StringBuilder sb = new StringBuilder(len); boolean removed_bs = false; boolean use_like = false; @@ -4296,7 +4302,7 @@ public final class MonetDatabaseMetaData if (removed_bs) { // for debug: System.out.println("input: " + in + " changed into: " + "= " + MonetWrapper.sq(sb.toString())); // we found only escaped wildcard character(s), - // use the edited string without the ecapes before the wildcard character(s) so an equals match can be done (its is faster than LIKE) + // use the edited string without the ecapes before the wildcard character(s) so an equals match can be done (which is faster than LIKE) return "= " + MonetWrapper.sq(sb.toString()); } // for debug: System.out.println("input: " + in + " changed into: " + "= " + MonetWrapper.sq(in));
--- a/tests/JDBC_API_Tester.java +++ b/tests/JDBC_API_Tester.java @@ -1115,6 +1115,16 @@ final public class JDBC_API_Tester { "varchar(1024) char(1)\n" + "jdbctst null\n"); + compareResultSet(dbmd.getSchemas(null, ""), "getSchemas(null, emptystring)", + "Resultset with 2 columns\n" + + "TABLE_SCHEM TABLE_CATALOG\n" + + "varchar(1024) char(1)\n"); + + compareResultSet(dbmd.getSchemas("%", "%%"), "getSchemas(%, %%)", + "Resultset with 2 columns\n" + + "TABLE_SCHEM TABLE_CATALOG\n" + + "varchar(1024) char(1)\n"); + compareResultSet(dbmd.getTables(null, "jdbctst", null, null), "getTables(null, jdbctst, null, null)", "Resultset with 10 columns\n" + "TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS TYPE_CAT TYPE_SCHEM TYPE_NAME SELF_REFERENCING_COL_NAME REF_GENERATION\n" +