Query using LIKE does not work using GreenDAO

I have a table in which a column is a row with three characters, each character has a value of 0 or 1. I would like to select these rows according to the case.

I would like to execute a query like this:

SELECT * FROM Item WHERE group_type LIKE ? 

? can be 100 or 101 or 011 or 111 or 001. Combination with 0 and 1 in three characters.

I am trying to execute a query using LIKE

 WhereCondition where = null; switch (condition) { case case1: where = ItemDao.Properties.GroupType.like("1%"); break; case case2: where = ItemDao.Properties.GroupType.like("%1%"); break; case case3: where = ItemDao.Properties.GroupType.like("%1"); break; } List<Item> items = itemDao.queryBuilder().where(where).list(); 

case1 returns everything that starts with 1, as expected. case3 returns everything that ends with 1, as expected. case2 returns everything! This does not affect the value at the beginning, middle or end. He returns everything.

case1 and case3 are working fine. However, case2 does not work. Are there any problems with this?

+5
source share
2 answers

No. "% 1%" should return everything where "1". It can be "100", "010" or "101", but not "000".

0
source

On sqlite like clause page:

The percent sign represents zero, one, or more numbers or characters. The underlined character is a single number or character. These characters can be used in combinations.

Speaking %1% , you are looking for elements that have at least one number 1, no matter where it may be. This is mainly because% means zero, one or more occurrences. This is explained in this link by the following example:

WHERE TO DISPLAY AS "% 200%"

Finds any values ​​that have 200 in any position

So we can see what you really expect.

0
source

All Articles