Skip to content Skip to sidebar Skip to footer

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.endTransacti

Solution 1:

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.

Solution 2:

Just try this

publicintdelete(String tableName) {
    SQLiteDatabasedb=this.getWritableDatabase();
    intx= db.delete(tableName, null, null);
    db.close();
    return x;
}

Solution 3:

Try it :

db.execSQL("DROP TABLE IF EXISTS table_name");

Where db is a reference to a SqliteDatabase object.

Solution 4:

When we install the app the database file is recreated in the /data folder. The problem may occour due to recreation of database even after deleting the files.

Check if this is the case.

Solution 5:

String query="delete from "+tablename;

SQLiteDatabase db=getWritableDatabase();

db.execSQL(query);

Log.d("msg","deleted");

Post a Comment for "Android Sqlite Delete Table Not Actually Deleting The Rows"