What is the exact difference between using rawquery and execSQL ?? While writing a query in android activity, when to use rawquery and when to use execSQL ?
From API documentation:
void execSQL (String sql)
Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
void execSQL (String sql, Object[] bindArgs)
Execute a single SQL statement that is NOT a SELECT/INSERT/UPDATE/DELETE.
The documentation is inconsistent but they behave both the same. Documentation of the latter is more in depth.
Cursor rawQuery (String sql, String[] selectionArgs)
Runs the provided SQL and returns a Cursor over the result set.
Uses for rawQuery are:
rawQuery
SELECT
rawQuery("SELECT ...
Cursor
DatabaseUtils.longForQuery(SQLiteDatabase, String, String[])
DatabaseUtils.stringForQuery(...)
SELECT count(*) FROM table
DatabaseUtils.queryNumEntries(...)
PRAGMA table_info
INSERT
UPDATE
DELETE
Uses for execSQL are:
execSQL
CREATE TABLE
CREATE
CREATE INDEX
DROP
PRAGMA
update()
insert()
delete()
DatabaseUtils.longForQuery
SELECT last_insert_rowid()
SELECT changes()
2.1m questions
2.1m answers
60 comments
57.0k users