Unverified 提交 f2d27a3a authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #683 from perhuss/master

Bugfix for #682: Queries with 'like' expressions may filter rows incorrectly...
......@@ -422,6 +422,11 @@ public class CompareLike extends Condition {
}
patternString = new String(patternChars, 0, patternLength);
// Clear optimizations
shortcutToStartsWith = false;
shortcutToEndsWith = false;
shortcutToContains = false;
// optimizes the common case of LIKE 'foo%'
if (compareMode.getName().equals(CompareMode.OFF) && patternLength > 1) {
int maxMatch = 0;
......
......@@ -58,6 +58,7 @@ public class TestCases extends TestBase {
testSortedSelect();
testMaxMemoryRows();
testDeleteTop();
testLikeExpressions();
testUnicode();
testOuterJoin();
testCommentOnColumnWithSchemaEqualDatabase();
......@@ -1841,4 +1842,15 @@ public class TestCases extends TestBase {
conn.close();
}
/** Tests fix for bug #682: Queries with 'like' expressions may filter rows incorrectly */
private void testLikeExpressions() throws SQLException {
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from (select 'fo%' a union all select '%oo') where 'foo' like a");
assertTrue(rs.next());
assertEquals("fo%", rs.getString(1));
assertTrue(rs.next());
assertEquals("%oo", rs.getString(1));
conn.close();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论