what is the best way to flush or empty an android sqlite table and delete every thing in it...??? and if i upgrade the database VERSION will it flush the table
this is how i delete one item but i want to delete all rows (i dont know ho开发者_开发百科w many rows i have) to empty the table
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DBAdapter db = new DBAdapter(this);
//---delete a title---
db.open();
if (db.deleteTitle(1))
Toast.makeText(this, "Delete successful.",
Toast.LENGTH_LONG).show();
else
Toast.makeText(this, "Delete failed.",
Toast.LENGTH_LONG).show();
db.close();
}
db.delete(TABLE_NAME, null, null);
or
db.delete(TABLE_NAME, "1", null);
From the documentation of SQLiteDatabase delete method:
To remove all rows and get a count pass "1" as the whereClause.
It's an sql database, just do DELETE * FROM yourtable
, which nukes all rows.
You can just execute the SQL query: db.execSQL("DELETE FROM <table-name>;");
If you want to delete all of the app's data, you can use the 'Clear Data' button found in Settings -> Applications -> Manage Applications -> 'your app'.
精彩评论