"sqllite" does not have the order of "TRUNCATE", like mysql, then we should get a different path ... this function (reset_table) frist deletes all the data in the table, and then reset the AUTOINCREMENT key in the table .... now you can use this function every time you want ...
example:
private SQLiteDatabase mydb; private final String dbPath = "data/data/your_project_name/databases/"; private final String dbName = "your_db_name"; public void reset_table(String table_name){ open_db(); mydb.execSQL("Delete from "+table_name); mydb.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE name='"+table_name+"';"); close_db(); } public void open_db(){ mydb = SQLiteDatabase.openDatabase(dbPath + dbName + ".db", null, SQLiteDatabase.OPEN_READWRITE); } public void close_db(){ mydb.close(); }
Ferhad Konar Oct 18 '15 at 18:26 2015-10-18 18:26
source share