Closed hongsonitptit closed 4 months ago
I tested this myself and your example works fine for me. Is there a chance you might have made a mistake in your code? Here is how I have implemented it:
PersonDao:
@Query('SELECT * FROM persons WHERE name LIKE :key')
Future<List<Person>> findPersonsByName(String key);
main.dart:
persons = widget.personDao.findPersonsByName('%${searchController.text}%');
Could you try this approach and see if it resolves the issue?
@Query('SELECT * FROM persons WHERE name LIKE '%:key%'')
Future<List<Person>> findPersonsByName(String key);
For this approach in SQLite you can't directly include the %
wildcard characters inside the annotation of a query with bound parameters in the manner you've described.
It works. Thanks a lot
Hello, I tried to add like param to the query as below, but it didn't work.
@Query( 'SELECT Person WHERE name LIKE "%:key%"') --> key = "abc" @Query( 'SELECT Person WHERE name LIKE :key') --> key = "%abc%"
It threw an exception that cannot bind the argument key
However, it still work when I hard code by @Query( 'SELECT * Person WHERE name LIKE "%abc"')
Can you pls check it?