LIKE does not work properly
Brought to you by:
barrygently
In where clause, I write a condition like { where field LIKE '11%' }
this query finds the object if the field is equal to "1123456" however
it returns false if the field is equal to "112110"
I think there is a bug because of the "11" in the middle of the field.
(ps. the field is stored as varchar, it is not integer)
By the way, I am using josql 2.2
I'm facing this same problem...
SELECT * FROM com.pkg WHERE getData('FIELD', :_currobj) LIKE '2%'
21 - Match
22 - Not Match
SELECT * FROM com.pkg WHERE getData('FIELD', :_currobj) LIKE '5%'
51 - Match
50 - Not Match
I've now had chance to have a look at this one and there will be a fix in version 2.3 (not sure when that will be released yet).
Alternatively you can use the attached source file which has the changes and recompile yourself.
Another option is to contact me directly on barrygently @ sourceforge.net and I can send you the updated jar file.
The change is basically to replace the use of a built-in matching mechanism with a regular expression instead (this happens internally), there is a small performance hit for this but it prevents these types of problems.
Gary
Changes for fixing this issue.
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
I have a similiar problem. This test fails "shouldMatchLeastRestrictively" returning 1 match only, not 3 (the match is for the "bill" instance of X).
public class JoSQLLikeTest {
private List<X> items;
@Before
public void setUp() {
items = asList(new X("bob"), new X("bbobert"), new X("bill"));
}
@Test
public void shouldMatchMostRestrictively()
throws QueryParseException, QueryExecutionException {
assertMatches("name like 'bb%'", 1);
}
@Test
public void shouldMatchLeastRestrictively()
throws QueryParseException, QueryExecutionException {
assertMatches("name like 'b%'", 3);
}
private void assertMatches(final String query, final int count)
throws QueryParseException, QueryExecutionException {
assertThat(parseAndExec("select * from " + X.class.getName() + " where " + query, items)
.getResults().size(), is(equalTo(count)));
}
public static final class X {
private final String name;
public X(final String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
The patch file attached below fixes my bug - thanks!
The patch file attached below fixes my bug too - thanks!