Skip to content

Commit

Permalink
Improve ElSqlConfig for SQL Server 2008+.
Browse files Browse the repository at this point in the history
- Match [ as wildcard character to support character range matching.
  (See: https://msdn.microsoft.com/en-us/library/ms179859.aspx)

- Specify backslash as escape character to allow escaping of wildcard
  characters in variables used with LIKE matching.
  • Loading branch information
evpaassen committed Apr 18, 2016
1 parent 4618fc3 commit 31332ec
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/opengamma/elsql/ElSqlConfig.java
Expand Up @@ -257,9 +257,30 @@ public String addPaging(String selectToPage, int offset, int fetchLimit) {
return "SELECT * FROM (" + inner + ") AS ROW_TABLE WHERE ROW_NUM >= " + start + " AND ROW_NUM <= " + end;
}
@Override
public String getLikeSuffix() {
return "ESCAPE '\\' ";
}
@Override
public String getPaging(int offset, int fetchLimit) {
throw new UnsupportedOperationException();
}
@Override
public boolean isLikeWildcard(String value) {
boolean escape = false;
for (int i = 0; i < value.length(); i++) {
char ch = value.charAt(i);
if (escape) {
escape = false;
} else {
if (ch == '\\') {
escape = true;
} else if (ch == '%' || ch == '_' || ch == '[') {
return true;
}
}
}
return false;
}
}

//-------------------------------------------------------------------------
Expand Down

0 comments on commit 31332ec

Please sign in to comment.