Rushabh Patel
Rushabh Patel

Reputation: 3080

Can not clear table from sqlite in android

I am updating the server data talble at every 5 minutes using service and i want to clear the all the data in the table and then update the new data from server so i am using this code before updating the table to clear the data:

public boolean deleteServerData() {
    SQLiteDatabase db = this.getWritableDatabase();
    if (getServerDataCount() > 0) {
        if (db.delete(TABLE_SERVER_CONTACTS, null, null) > 0)
            return true;
        else
            return false;
    } else
        return true;
}

But when is count the rows in the table before deleting it gives me any number say "13" and after deleting it gives me zero but when i see at the table data it still there and updated data is appended in the table so table can not clearing data at all.

please suggest me if any solution is there or any mistake is done by me in the code.

Upvotes: 0

Views: 372

Answers (1)

Yaqub Ahmad
Yaqub Ahmad

Reputation: 27659

Try execSQL:

db.execSQL("DELETE FROM "+ TABLE_SERVER_CONTACTS);

Upvotes: 1

Related Questions