I have a WCF witch provides some JSON data and then I save it into the local database. Works fine I have a Activity witch fills the data from a local database to a listview witch works fine.
public void fillData() {
// Fields from the database (projection)
// Must include the _id column for the adapter to work
String[] from = new String[] { TodoTable.COLUMN_SUMMARY };
// Fields on the UI to which we map
int[] to = new int[] { R.id.label };
getLoaderManager().initLoader(0, null, this);
adapter = new SimpleCursorAdapter(this, R.layout.todo_row, null, from,
to, 0);
lw.setAdapter(adapter);
}
What I can't figure out is what would be the best way to delete all rows prior to a sync action from a WCF.
I could do this by getting all Id's from the database then find the row URI and then use:
getContentResolver().delete(uri, null, null)
I just think that there has to be a better way I saw many examples on the net that uses the DbHelper class but I can't figure out how to access the dbHelper class from the Activity or over the ContentProvider
Hope that makes any sense
We can also use the TRUNCATE command to delete all the records from a table.
Tip: You can delete the contents of a row or column without deleting the table structure. To do this, select the row or column and then press the Delete key.
SQLite does not have an explicit TRUNCATE TABLE command like other databases. Instead, it has added a TRUNCATE optimizer to the DELETE statement. To truncate a table in SQLite, you just need to execute a DELETE statement without a WHERE clause. The TRUNCATE optimizer handles the rest.
Using DatabaseHelper
you can do like this:
dbHelper = new DatabaseHelper(context);
database = dbHelper.getWritableDatabase();
public void clearTable() {
database.delete(TABLE, null,null);
}
Try
<your-SQLite-instance>.execSQL("DELETE FROM <table_name>");
That will drop all the rows from <table_name>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With