英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论