If I do this query, I search on a field that contains :
[Water, coke, 7up]
[Coke, water, 7up]
So, then I want also to return these items even if the parameter is written with capital letter, for this I'm using this @Query
@Query("SELECT * from drinksList WHERE list LIKE '%'||:name||'%'")
What am I missing?
EDIT
Now I'm using LIKE %param%
but the problem is that if the table is like this :
[Water, coke, 7up]
[Coke, waterera, 7up]
[Waterg3d, coke, 7up]
[Coke, water23, 7up]
And I want to find the "water" one it will show all of these records, and I just want to find the word "water" doesn't matter if it's lowercase or uppercase.
The following should work :-
@Query("SELECT * from drinksList WHERE list||',' LIKE '%'||:name||',%' OR list||',' LIKE :name||',%'")
This based upon/ was tested using :-
DROP TABLE IF EXISTS DrinksList;
CREATE TABLE IF NOT EXISTS DrinksList (list TEXT UNIQUE NOT NULL);
INSERT INTO DrinksList VALUES
('Water, spicy, coke'), -- Should be found when searching for water
('Coke'), -- will not be found when seraching for water
('Spicy, water, coke'), -- Should be found
('Coke, spicy, water'), -- Should be found
('wateria, spicyer, cokeer'), -- should not be found
('Water, coke, 7up'), -- should be found
('Coke, waterera, 7up'), -- should not be found
('Waterg3d, coke, 7up'), -- should not be found
('Coke, water23, 7up') -- should not be found
;
SELECT * from drinkslist WHERE list||',' LIKE '%'||'water'||',%' OR list||',' LIKE 'water'||',%';
Resulting in :-
The above has been tested and it does work in room as per :-
All lists displays :-
Entering wAtER in the edit text and clicking the Selective button results in :-
Entering 7Up :-
and so on.
The query being :-
@Query("SELECT * FROM DrinkList WHERE list||',' LIKE '%'||:name||',%' OR list||',' LIKE :name||',%'")
List<DrinkList> getSelectiveDrinks(String name);