开发者

android flush sqlite table

开发者 https://www.devze.com 2023-03-26 18:22 出处:网络
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

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'.

0

精彩评论

暂无评论...
验证码 换一张
取 消