FIX: correct behavior of "startsWith, "contains" etc (#1031)

* FIX: correct behavior of "startsWith" if string contains "like"-wildcards

* Removed likeClasues with disabled escaping in database platforms as bind values are properly escaped now.
This commit is contained in:
Roland Praml authored and Rob Bygrave committed 2017-06-19 22:21:26 +12:00
1 parent a1f95bf25e
commit bc74d35651
13 files changed
+162 -15

No files matched your search

@@ -65,4 +65,9 @@ public interface SpiExpressionRequest {
* Append a DB Like clause.
*/
void appendLike();
/**
* Escapes a string to use it as exact match in Like clause.
*/
String escapeLikeString(String value);
}
@@ -96,6 +96,14 @@ public final class OrmQueryRequest<T> extends BeanRequest implements BeanQueryRe
public String getDBLikeClause() {
return ebeanServer.getDatabasePlatform().getLikeClause();
}
/**
* Return the database platform escaped like string.
*/
@Override
public String escapeLikeString(String value) {
return ebeanServer.getDatabasePlatform().escapeLikeString(value);
}
@Override
public void executeSecondaryQueries(boolean forEach) {
@@ -123,6 +123,11 @@ public interface SpiOrmQueryRequest<T> extends DocQueryRequest<T> {
* Return the Database platform like clause.
*/
String getDBLikeClause();
/**
* Escapes a string to use it as exact match in Like clause.
*/
String escapeLikeString(String value);
/**
* Mark the underlying transaction as not being query only.
@@ -93,6 +93,11 @@ public class DefaultExpressionRequest implements SpiExpressionRequest {
sql.append(" ");
}
@Override
public String escapeLikeString(String value) {
return queryRequest.escapeLikeString(value);
}
/**
* Increments the parameter index and returns that value.
*/
@@ -34,8 +34,7 @@ class LikeExpression extends AbstractValueExpression {
String encryptKey = prop.getBeanProperty().getEncryptKey().getStringValue();
request.addBindEncryptKey(encryptKey);
}
String bindValue = getValue(strValue(), caseInsensitive, type);
String bindValue = getValue(strValue(), caseInsensitive, type, request);
request.addBindValue(bindValue);
}
@@ -92,13 +91,15 @@ class LikeExpression extends AbstractValueExpression {
return strValue().equals(that.strValue());
}
private static String getValue(String value, boolean caseInsensitive, LikeType type) {
private static String getValue(String value, boolean caseInsensitive, LikeType type, SpiExpressionRequest request) {
if (caseInsensitive) {
value = value.toLowerCase();
}
if (type == LikeType.RAW) {
return value;
}
value = request.escapeLikeString(value);
switch (type) {
case RAW:
return value;
case STARTS_WITH:
return value + "%";
case ENDS_WITH: