您好,我正在尝试通过以下查询删除表中的所有行
db.beginTransaction(); // db is a SQLiteDatabase object
int deleted = db.delete("user", null, null);
db.endTransaction();
我在表中删除了 n 行。但是表中仍然存在行。我的删除调用有什么问题吗?
最佳答案
在调用 endTransaction
之前,您需要调用 setTransactionSuccessful
来提交对数据库所做的所有更改:
db.beginTransaction();
int deleted = db.delete("user", null, null);
db.setTransactionSuccessful();
db.endTransaction();
来源(Android 开发者引用):
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 删除表实际上并没有删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24778779/