Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform an SQLite query within an Android application?

I am trying to use this query upon my Android database, but it does not return any data. Am I missing something?

SQLiteDatabase db = mDbHelper.getReadableDatabase();     String select = "Select _id, title, title_raw from search Where(title_raw like " + "'%Smith%'" +     ")";             Cursor cursor = db.query(TABLE_NAME, FROM,              select, null, null, null, null);     startManagingCursor(cursor);     return cursor; 
like image 711
Dennie Avatar asked Aug 07 '09 06:08

Dennie


People also ask

Which method is used to run select query in SQLite of Android?

You may try something like: SQLiteDatabase db = this. getWritableDatabase(); String selectQuery = "select sum(odometer) as odometer from tripmileagetable where date like '2012-07%'"; Cursor cursor = db. rawQuery(selectQuery, null);

What is SQLite open helper in Android?

android.database.sqlite.SQLiteOpenHelper. A helper class to manage database creation and version management.


1 Answers

This will return you the required cursor

Cursor cursor = db.query(TABLE_NAME, new String[] {"_id", "title", "title_raw"},                  "title_raw like " + "'%Smith%'", null, null, null, null); 
like image 69
Prashast Avatar answered Sep 19 '22 06:09

Prashast