Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Character start with query in room persistent android

Tags:

android-room

I have tried the following query but it does not give any result.

SELECT * FROM details WHERE name LIKE :name

I have used AutoCompleteTextview for searching purpose. is there any query to find with a substring?

like image 503
Ashish Patil Avatar asked Jun 01 '17 05:06

Ashish Patil


2 Answers

Like MoinKhan suggested, adding the wildcard to the string before sending to Room worked for me.

query = "%"+query+"%";
like image 131
Jeff Avatar answered Sep 30 '22 06:09

Jeff


I recently ran into this issue and found the nicest solution is to use Sql string concatenation || in combination with % which represents zero, one, or multiple numbers or characters.

@Query("SELECT * FROM details WHERE name LIKE '%' || :name || '%'")
fun getDetails(name: String): details

This will get the details where the name contains the one we are looking for

Similarly the below will find matches that start with the name

LIKE :name || '%'
like image 32
Matt Smith Avatar answered Sep 30 '22 07:09

Matt Smith