0

I need to reset the row number count to 1. How can I do that?

An example for an update query in my code:

public boolean update (long rowId, String title, String body, String reminderDateTime, String loca, String type, String settime, String lat, String llong) {
    ContentValues args = new ContentValues();
    args.put(KEY_TITLE, title);
    args.put(KEY_BODY, body);
    args.put(KEY_DATE_TIME, reminderDateTime);
    args.put(KEY_LOCATION, loca);
    args.put(KEY_TYPE, type);
    args.put(KEY_SETTIME, settime);
    args.put(KEY_LAT, lat);
    args.put(KEY_LONG, llong);


    return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;

I tried to do that but the eclipse showing me an error:"sqlite_sequence cannot be resolved to a variable"

public void resetAutoNumbering ()
{

     mDb.update(sqlite_sequence, args, KEY_ROWID + "=" + rowId, null);

}

What can I do and how?

ofeking109
  • 71
  • 1
  • 11
  • Well, that's because `sqlite_sequence` is not a valid name of variable. Think about it, what is so special in `sqlite_sequence` name that it should be resolved without you having any kind of variables with such name in code. – inazaruk Dec 22 '11 at 08:03
  • can u post in the creation of your db – Abhinava Dec 22 '11 at 08:17
  • `SQLiteDatabase mDb = mDbHelper.getWritableDatabase();` – ofeking109 Dec 22 '11 at 11:43

2 Answers2

2

Found this as answer for a similar question SQLite Reset Primary Key Field:

delete from your_table;
delete from sqlite_sequence where name='your_table';

SQLite Autoincrement

SQLite keeps track of the largest ROWID that a table has ever held using the special SQLITE_SEQUENCE table. 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.

-axel

Community
  • 1
  • 1
AxelTheGerman
  • 986
  • 13
  • 26
  • I tried to do that but the eclipse showing me an error:"sqlite_sequence cannot be resolved to a variable" – ofeking109 Dec 22 '11 at 10:06
  • do you get an error from eclipse so you cannot build and run your code or do you get an exception with that error message? could you post the complete error message/exception stacktrace. what sql statement did you use to create your table? the sqlite_sequence table is created automatically when a table with an INTEGER_PRIMARY_KEY column is created. you can use an sqlite viewer (e.g. http://sqlitebrowser.sourceforge.net/ ) to browse your sqlite database (to check whether this table exists or not) – AxelTheGerman Dec 22 '11 at 22:56
  • @axel's advice worked for me: __database.delete( "sqlite_sequence", "name = '" + TABLE_NAME + "'", null ); – Jon Jun 13 '12 at 01:11
0

You use sqlite_sequence in your procedure but before this you used DATABASE_TABLE instead of sqlite_sequence. Change your sqlite_sequence to DATABASE_TABLE.

Yury
  • 20,618
  • 7
  • 58
  • 86