使用rowid删除SQLite行不起作用

huangapple go评论92阅读模式
英文:

SQLite delete row using rowid not working

问题

我创建了一个SQL查询来根据rowid删除一行。当我运行查询时没有错误,但是该行未被删除。

String query = "DELETE FROM " + TABLE_NAME + " WHERE " + " rowid " + " = " + id;
db.execSQL(query);
英文:

I created a sql query to delete a row given the rowid. When I run the query there are no errors, however, the row doesn't get deleted.

String query = "DELETE FROM " + TABLE_NAME + " WHERE " + " rowid " + " = " + id;
db.execSQL(query);

答案1

得分: 0

尝试这个:

String query = "DELETE FROM " + TABLE_NAME + " WHERE rowid = '" + id + "'";
db.execSQL(query);

但我个人更喜欢这种方式:

if (db.delete(TABLE_NAME, "rowid = ?", new String[]{id}) != 0) {
    Log.i("row", "已删除");
} else {
    Log.i("row", "未删除");
}
英文:

Try this:

String query = "DELETE FROM " + TABLE_NAME + " WHERE rowid " + " = '" + id + "'";
db.execSQL(query);

But I personally prefer this way:

if (db.delete(TABLE_NAME, rowid+ " = ?", new String[]{id}) != 0) {
    Log.i("row", "Has been deleted");
} else{
    Log.i("row", "Has not been deleted");
}

答案2

得分: 0

解决方案:我使用了真空功能来重新生成正确的行号。之前我删除了那个行号不存在的行。

英文:

SOLUTION: I used the vacuum function to regenerate the proper rowId. I was previously deleting rows where that rowId didn't exist.

huangapple
  • 本文由 发表于 2020年9月3日 06:43:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/63714432.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定