提交 435e2435 authored 作者: phuss's avatar phuss

Bugfix for #682: Queries with 'like' expressions may filter rows incorrectly.

上级 67aa05ba
...@@ -422,6 +422,11 @@ public class CompareLike extends Condition { ...@@ -422,6 +422,11 @@ public class CompareLike extends Condition {
} }
patternString = new String(patternChars, 0, patternLength); patternString = new String(patternChars, 0, patternLength);
// Clear optimizations
shortcutToStartsWith = false;
shortcutToEndsWith = false;
shortcutToContains = false;
// optimizes the common case of LIKE 'foo%' // optimizes the common case of LIKE 'foo%'
if (compareMode.getName().equals(CompareMode.OFF) && patternLength > 1) { if (compareMode.getName().equals(CompareMode.OFF) && patternLength > 1) {
int maxMatch = 0; int maxMatch = 0;
......
...@@ -58,6 +58,7 @@ public class TestCases extends TestBase { ...@@ -58,6 +58,7 @@ public class TestCases extends TestBase {
testSortedSelect(); testSortedSelect();
testMaxMemoryRows(); testMaxMemoryRows();
testDeleteTop(); testDeleteTop();
testLikeExpressions();
testUnicode(); testUnicode();
testOuterJoin(); testOuterJoin();
testCommentOnColumnWithSchemaEqualDatabase(); testCommentOnColumnWithSchemaEqualDatabase();
...@@ -1841,4 +1842,15 @@ public class TestCases extends TestBase { ...@@ -1841,4 +1842,15 @@ public class TestCases extends TestBase {
conn.close(); 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论