Q:

Android SQLite delete table not actually deleting the rows

Hi i am trying to delete all the rows in a table by below query
db.beginTransaction(); // db is a SQLiteDatabase object
int deleted = db.delete("user", null, null);
db.endTransaction();

I am getting n number of rows deleted in the table. But still rows exist in the table. Anything wrong in my delete call?

A:

You need to call setTransactionSuccessful to commit all the changes done to the database, before calling endTransaction:
db.beginTransaction();
int deleted = db.delete("user", null, null);
db.setTransactionSuccessful();
db.endTransaction();

Source (Android developer reference):

The changes will be rolled back if any transaction is ended without being marked as clean (by calling setTransactionSuccessful). Otherwise they will be committed.

