简体   繁体   中英

SQLite delete row using rowid not working

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

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");
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM