delete row id using Contentprovider

Error

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

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Delete a row javascript using row id

From Dev

Laravel delete row with no 'id'

From Dev

Delete multiple rows while using the id from the row before

From Dev

jqGrid Delete Row with ID passed

From Dev

MySQL delete row if id is found in another row

From Dev

How do I delete a row from Sqlite using ID where my ID is binary data (GUID)

From Dev

Using ContentProvider from an IntentService

From Dev

delete row using delete button in ListView

From Dev

Delete blank row using For Next

From Dev

Delete Table row using javascript

From Dev

Delete row using where clause

From Dev

delete row in googlesheet using googlesheetapi

From Dev

Using case to delete data row

From Dev

How to delete row using php?

From Dev

Delete row of the table using javascript

From Dev

AJAX Delete row in table with PHP id selected

From Dev

jQuery delete table row by dynamic id

From Dev

Delete Row By id from SQLdatabase in Android

From Dev

Android - Using ORMLite DAO as a ContentProvider

From Dev

How to change table row ID dynamically based on the row delete?

From Dev

How to change table row ID dynamically based on the row delete?

From Dev

Edit specific row of a table using id of that row

From Dev

How to delete a row in dojo EnhancedGrid using row index not by using selection

From Dev

Update row on datatable using ID

From Dev

Unable to delete pages when using FragmentStatePagerAdapter - What is the usual behavior of row ID's when integer primary key is used?

From Dev

unable to delete row from table using jquery?

From Dev

delete a specific row of a table using php

From Dev

How to delete single row using a trigger

From Dev

Delete data row from database using href

Related Related

HotTag

Archive