Android SQLite 删除表实际上并没有删除行

标签 android mysql ios sql sqlite

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

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/

相关文章:

java - 将 PFX 静默安装到 Android 系统受信任的 CA 用户 keystore 中

java - 持续更新通知

android - 蓝牙 LE 扫描结果返回 null,但我知道我的外围设备正在广播心率服务 UUID(由第 3 方 BLE 应用程序验证)。为什么?

android - 使用 Arraylist 时 Gridview 上的空白屏幕

php - list() 函数和 mysqli_fetch_array 一起工作吗?

ios - 在 Core Data 中编写原生 SQL

mysql - 在 MySql 中更新连接两个表

mysql - 从非常大的表中导出逗号分隔的数据

ios - 如何获取 Google Maps API iOS 中某个点的坐标?

ios - 更改特定 UIFont.TextStyle 的所有 UILabels