I am learning to implement databases in android , i came across this query() and rawQuery() , i want to know the difference between them and which one is efficient in android
Asked
Active
Viewed 1.3k times
1 Answers
8
From API Doc:
public void execSQL (String sql)
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
public Cursor rawQuery (String sql, String[] selectionArgs)
Runs the provided SQL and returns a Cursor over the result set.
If you want to e.g. CREATE TABLE
that does not return values you can use execSQL()
, if you want a Cursor
as result use rawQuery()
(=SELECT
statements).
Looking at SQLiteDatabase.java in the android source shows that the query(..) ends up calling the QueryBuilder to build the query as a single string and then it essentially calls rawQuery(). They should be roughly equivalent, assuming that you also did the same work to build your own statement.

Himanshu Agarwal
- 4,623
- 5
- 35
- 49
-
thank you very much , that is the kind of explanation i am waiting for. – Nov 03 '14 at 09:25