Reputation: 1477
I know if I want to do a SQLite SELECT
by ignoring the spaces of username
column in the DB, I can do:
SELECT * FROM mytable WHERE REPLACE(username, ' ', '') LIKE '%TO_QUERY%'
But the interface of SQLiteDatabase.query()
is:
public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
I am wondering how I can implement the above SQL command using this interface, or it's better to use SQLiteDatabase.rawQuery()
?
Upvotes: 1
Views: 732
Reputation: 1596
You can do this simply using SQLiteOpenHelper
and rawQuery()
method of SQLiteDatabase
Extend SQLiteOpenHelper
in your class
public class DatabaseHelper extends SQLiteOpenHelper
Check this.
private SQLiteDatabase myDataBase;
To Select some columns:
Cursor c = myDataBase.rawQuery(
"SELECT * FROM mytable WHERE REPLACE(username, ' ', '') LIKE '%TO_QUERY%' ;", null);
Then do your operation using cursor c
To update something
myDataBase.execSQL("UPDATE some_table SET some_column='" + value
+ "' WHERE some_column LIKE '" + some_value + "'");
Upvotes: 1