SQL query in Android - search for whole or part of a string

后端 未结 2 453
梦谈多话
梦谈多话 2021-01-24 09:36

I\'m not experienced with SQL queries too much so I\'m having some trouble in finding the solution to my problem.

I have a list of Bookmarks, for example: Facebook, Deve

相关标签:
2条回答
  • 2021-01-24 09:57

    You can use the SQL-keyword LIKE for this. Encapsulate it with the wildward (%) and you're way to go.

    sqlite> select * from testtable where name like '%face%';
    facebook|42
    
    0 讨论(0)
  • 2021-01-24 10:10

    You can try this:

    String where = Browser.BookmarkColumns.TITLE + " LIKE '%" + x +"%' OR "
                + Browser.BookmarkColumns.URL + " LIKE '%" + x +"%'";
                where = "(" + where + ") AND " + Browser.BookmarkColumns.BOOKMARK + " == 1";
    

    where x is the text that user has inserted, i.e. face.

    Hope this helps!

    0 讨论(0)
提交回复
热议问题