I’m trying to make an android app that searches my database for any combination of characters I put in an edittext control.
For example, I have the word RAW and HOW and HEAD (among a lot of other words and numbers) in my database and if I put in the characters “HOWRADE” I want to get a hit on both RAW, HOW and HEAD since W O H A R E D exists in the string I put in the edittext.
Anyone know if this can be done with an sql query? I could do it the hard way and make a query for each char in the string but that seems too complicated. Would really appreciate some help with this one since I can’t think straight anymore 🙂
I’m trying to make an android app that searches my database for any combination
Share
Sure, you have the WHERE clause and you can use LIKE and wild cards such as % to define that you are looking for the Letters in context.
Build the base SQL as a string and finish it with “WHERE ”
then iterate through the letters and add text LIKE ‘%” + char + “%’
Make sure you get the OR(s) put in at the right places in the SQL and then execute the statement.
As you are building it you may want to Log the finished string to see what you need to change to make it work.
Reference:
LIKE clause