Why does a delete rawQuery need a moveToFirst in order to actually delete the rows?

I cannot answer the why, but another solution is to use .execSQL(String) as posted here


A rawQuery returns a Cursor of a result set, which is just a reference to the query results. You should just be using a straight delete() call. Take a look at the documentation:

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

or an SQLiteStatement:

http://developer.android.com/reference/android/database/sqlite/SQLiteStatement.html


In my case also, the same thing has happened for DELETE, It ran successfully after calling "cursor.moveToFirst()". Same is the case with INSERT and UPDATE queries also. I have also observed that calling any method on the cursor for the above mentioned queries I have got the results correctly. Without calling any method of the cursor the desired effect is taking place. So, I think the answer to your question is : Query gets executed only when we call some method on the cursor.

Tags:

Sqlite

Android