Mercurial > hg > monetdb-java
comparison src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 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 | 3034312c1eda |
children | 78253fdb3c3f |
comparison
equal
deleted
inserted
replaced
679:a2dfec33dbcb | 680:238d6a3a6469 |
---|---|
4238 */ | 4238 */ |
4239 private final String composeMatchPart(final String in) { | 4239 private final String composeMatchPart(final String in) { |
4240 if (in == null) | 4240 if (in == null) |
4241 return "IS NULL"; | 4241 return "IS NULL"; |
4242 | 4242 |
4243 final int len = in.length(); | |
4244 if (len == 0) | |
4245 return "= ''"; | |
4246 | |
4247 if (in.equals("%") || in.equals("%%")) | |
4248 return "LIKE '%'"; | |
4249 | |
4243 // Scan input string for SQL wildcard characters: % and _ | 4250 // Scan input string for SQL wildcard characters: % and _ |
4244 // When they are all prefixed by a backslash then the backslash is removed (to allow usage of = comparator) | 4251 // When they are all prefixed by a backslash then the backslash is removed (to allow usage of = comparator) |
4245 // else it needs to be interpreted as a wildcard and we need to use LIKE instead of = comparator. | 4252 // else it needs to be interpreted as a wildcard and we need to use LIKE instead of = comparator. |
4246 // A backslash can be escaped by using two backslashes. | 4253 // A backslash can be escaped by using two backslashes. |
4247 final int len = in.length(); | |
4248 final StringBuilder sb = new StringBuilder(len); | 4254 final StringBuilder sb = new StringBuilder(len); |
4249 boolean removed_bs = false; | 4255 boolean removed_bs = false; |
4250 boolean use_like = false; | 4256 boolean use_like = false; |
4251 boolean escaped = false; | 4257 boolean escaped = false; |
4252 try { | 4258 try { |
4294 return "LIKE " + MonetWrapper.sq(in); | 4300 return "LIKE " + MonetWrapper.sq(in); |
4295 } | 4301 } |
4296 if (removed_bs) { | 4302 if (removed_bs) { |
4297 // for debug: System.out.println("input: " + in + " changed into: " + "= " + MonetWrapper.sq(sb.toString())); | 4303 // for debug: System.out.println("input: " + in + " changed into: " + "= " + MonetWrapper.sq(sb.toString())); |
4298 // we found only escaped wildcard character(s), | 4304 // we found only escaped wildcard character(s), |
4299 // use the edited string without the ecapes before the wildcard character(s) so an equals match can be done (its is faster than LIKE) | 4305 // use the edited string without the ecapes before the wildcard character(s) so an equals match can be done (which is faster than LIKE) |
4300 return "= " + MonetWrapper.sq(sb.toString()); | 4306 return "= " + MonetWrapper.sq(sb.toString()); |
4301 } | 4307 } |
4302 // for debug: System.out.println("input: " + in + " changed into: " + "= " + MonetWrapper.sq(in)); | 4308 // for debug: System.out.println("input: " + in + " changed into: " + "= " + MonetWrapper.sq(in)); |
4303 return "= " + MonetWrapper.sq(in); | 4309 return "= " + MonetWrapper.sq(in); |
4304 } | 4310 } |