4

I'm using a fairly simple command to try to delete rows in a SQLite database. However, after successfully running the command, the rows remain in the DB!?

SQLiteDatabase dbinst = mydb.getWritableDatabase();

try
{
  dbinst.beginTransaction();
  int del = dbinst.delete("sms", "wassent = ? or waserror = ? or wasaborted = ?", new String[] {"1", "1", "1"} );   
  clog.debug("Rows deleted: " + del);
  dbinst.setTransactionSuccessful();
}
catch(Exception e)
{
  clog.error(e.toString(),e);
}

dbinst.close();

The logger says "rows deleted: 3", and no exception arises. However, when doing a query immediately afterwards, the rows are still there?

Any obvious thing I'm doing wrong here?

1
  • Have you solved this ? Commented Apr 8, 2013 at 12:48

1 Answer 1

2

You have to call endTransaction to actually commit the changes. More info can be found here: beginTransaction() documentation

Sign up to request clarification or add additional context in comments.

6 Comments

Say, does it help in any way to actually use a transaction for a simple deletion? And how about a single deletion that has multiple rows to delete from? Any better in performance or in thread-safety?
@androiddeveloper Transactions are useful if you want to update several tables atomically (either all of the updates work or they all fail, no mixed results). Also, if your application can't handle the user pulling the battery in the middle of a table update then use transactions.
makes sense. but is it useful in case I know a deletion operation would be only for a single row? what about multiple rows? Would using deletion without transaction be dangerous in terms of thread-safety ? I mean, is this "db.delete(...)" thread safe ?
@androiddeveloper All db interactions are thread safe by default. The usefulness of transactions to your application depends on the factors I've laid out in my previous comment. If you're just updating a single row, then transactions don't give you any added benefit. If you're worried about performance, then you're probably overthinking it.
So no matter how complex the db operation is, it's thread safe ? OK, thank you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.