I’m having some trouble searching a SQLite database in my Android app. I use the Search interface to pass the search variable (searchActivity.query) to this:
//searchActivity.query obtained from:
//String query = searchActivity.getStringExtra(SearchManager.QUERY);
String searchString = "'" + searchActivity.query + "%'";
//sqlitedb is called via: private SQLiteDatabase sqlitedb;
Cursor cursor = sqlitedb.query(DATABASE_TABLE, new String[]
{"id", "FirstName","LastName"},
"FirstName LIKE " + searchString, null, null, null, null);
int index_CONTENT = cursor.getColumnIndex(FirstName);
for(cursor.moveToFirst(); !(cursor.isAfterLast()); cursor.moveToNext()){
result = result + cursor.getString(index_CONTENT) + "\n";
}
The problem is that using the “LIKE” statement outputs everything in the database – defeating the purpose of using the Search interface. I’m not too sure where I’m going wrong.
I tried replacing LIKE with “=” except that displayed nothing, even when I was 100% sure the record existed.
Any help would be greatly appreciated!
Thanks in advance,
Joe
UPDATE:
Sorry about the misleading title. I wasn’t passing the search query properly.
Try this,
and let me know what happen..