Android SQLite删除表实际上没有删除行 [英] Android SQLite delete table not actually deleting the rows

查看:123
本文介绍了Android SQLite删除表实际上没有删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试通过以下查询删除表格中的所有行

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();

我在表中删除了n行。但是表中仍然存在行。我的删除电话有什么问题吗?

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

推荐答案

你需要拨打 setTransactionSuccessful 在调用 endTransaction 之前提交对数据库所做的所有更改:

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();

来源(Android开发者参考):

Source (Android developer reference):


如果任何事务结束而没有标记为干净(通过调用setTransactionSuccessful),则将回滚更改。否则他们将被提交。

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

这篇关于Android SQLite删除表实际上没有删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆