I am using provider to delete all data in SQLiteOpenHelper
table suppose i have 5 row and i deleted data in table , if i filled table again with data _ID
column start at 6
SQLite TABLE
final String HISTORY = "CREATE TABLE " + Contract.History.TABLE + " (" +
Contract.History._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
Contract.History.ROW + " INTEGER NOT NULL, " +
Contract.History.HISTORY_NAME + " TEXT NOT NULL " +
" );";
DELETE SNIPPET IN PROVIDER
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
final SQLiteDatabase db = database.getWritableDatabase();
final int match = matcher.match(uri);
int rowsDeleted;
if ( null == selection ) selection = "1";
switch (match) {
case HISTORY:
rowsDeleted = db.delete(
Contract.History.TABLE, selection, selectionArgs);
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
// Because a null deletes all rows
if (rowsDeleted != 0) {
getContext().getContentResolver().notifyChange(uri, null);
}
return rowsDeleted;
}
HOW I DELETE
ContentResolver resolver = getContentResolver();
resolver.delete(Contract.Running.CONTENT_URI,null,null);
}
This is a regular database behavior, and it is not an error in the code or the query, it is just how the SQLite works. SQLite site states:
SQLite keeps track of the largest ROWID that a table has ever held using an internal table named "sqlite_sequence". The sqlite_sequence table is created and initialized automatically whenever a normal table that contains an AUTOINCREMENT column is created. The content of the sqlite_sequence table can be modified using ordinary UPDATE, INSERT, and DELETE statements. But making modifications to this table will likely perturb the AUTOINCREMENT key generation algorithm. Make sure you know what you are doing before you undertake such changes.
I would advise against changing, unless you really know what you are doing. But if you want you can do it like this:
DELETE FROM sqlite_sequence WHERE name = '<YOUR_TABLE>';
You can also update the sequencer, in case you delete only some rows.
UPDATE SQLITE_SEQUENCE SET seq = <n> WHERE name = '<YOUR_TABLE>'
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments