Menu

#26 LIKE does not work properly

open-fixed
nobody
Functions (4)
9
2011-08-19
2011-07-21
No

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)

Discussion

  • pamir sonmez

    pamir sonmez - 2011-07-21
    • priority: 5 --> 9
    • assigned_to: nobody --> barrygently
     
  • pamir sonmez

    pamir sonmez - 2011-07-21

    By the way, I am using josql 2.2

     
  • pamir sonmez

    pamir sonmez - 2011-08-02
    • assigned_to: barrygently --> nobody
     
  • Leandro de Almeida

    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

     
  • Gary Bentley

    Gary Bentley - 2011-08-19

    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

     
  • Gary Bentley

    Gary Bentley - 2011-08-19

    Changes for fixing this issue.

     
  • Gary Bentley

    Gary Bentley - 2011-08-19
    • status: open --> open-fixed
     
  • Anonymous

    Anonymous - 2011-09-21

    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;
    }
    }
    }

     
  • Anonymous

    Anonymous - 2011-09-21

    The patch file attached below fixes my bug - thanks!

     
  • Brauge

    Brauge - 2013-03-28

    The patch file attached below fixes my bug too - thanks!

     

Log in to post a comment.