D
D
DivelNick2016-08-07 17:32:38
Android
DivelNick, 2016-08-07 17:32:38

How to completely delete a row from a SQLite android database?

Such problem, there is a DB in which I write down the data. When deleting entries, the entire contents of the line is deleted, but the line itself is not deleted, that is, if the last entry has id = 5, and I delete it, then regardless of this, the next added entry will have id 6. I delete it in the standard way using the delete( ), how can I delete a line entirely?
Here is the method that deletes the data


public void deleteItem(int id) {
sqLiteDatabase = dataBaseHelper.getWritableDatabase();
sqLiteDatabase.delete(dataBaseHelper.DATABASE_TABLE, dataBaseHelper.KEY_ID + "=" + id, null);
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Gamega, 2016-08-07
@DivelNick

this is not a bug, it should be, but if you really want to (make sure you really need it first), then when creating a table, simply do not write _id INTEGER PRIMARY KEY AUTOINCREMENT,
but simply _id INTEGER PRIMARY KEY

V
Vyacheslav, 2016-08-07
@Firik67

The line is deleted completely and so on. The next id is set to a larger one because that's how sqlite works by default, but this behavior can be changed. If you want to know how, then throw the query that created the table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question