How To Use Glob With Sqlite In Android
I have a database of 23,000 words. I want to have the query return all words that start with a certain search string. After reading sqlite LIKE problem in android I was able to get
Solution 1:
It is very similar to what you have already.
SQLiteDatabasedb= getReadableDatabase();
SQLiteQueryBuilderqb=newSQLiteQueryBuilder();
String [] sqlSelect = { KEY_WORD };
StringsqlTables= TABLE_WORDS;
Stringselection= KEY_FUZZYWORD + " GLOB ?";
String[] selectionArgs = { searchString + "*" };
Stringlimit= Integer.toString(WORD_QUERY_LIMIT);
qb.setTables(sqlTables);
Cursorcursor= qb.query(db, sqlSelect, selection, selectionArgs, null, null, null, limit);
the key lines being
String selection = KEY_FUZZYWORD + " GLOB ?";
String[] selectionArgs = { searchString + "*" };
Further reading:
- SQLite - GLOB Clause
- SQL As Understood By SQLite (scroll down to "The LIKE and GLOB operators")
Post a Comment for "How To Use Glob With Sqlite In Android"