Android Sqlite Transaction and Content Provider
I'm Parsing a JSON WebService and creating a array with data to INSERT and
DELETE entries in a database.
I found the solution bulkInsert to insert multiple rows using database
transactions inside a content provider, however, I am trying to do the
same procedure to delete multiple lines.
The INSERT solution:
@Override
public int bulkInsert(Uri uri, ContentValues[] allValues) {
SQLiteDatabase sqlDB = mCustomerDB.getWritableDatabase();
int numInserted = 0;
String table = MyDatabase.TABLE;
sqlDB.beginTransaction();
try {
for (ContentValues cv : allValues) {
//long newID = sqlDB.insertOrThrow(table, null, cv);
long newID = sqlDB.insertWithOnConflict(table, null, cv,
SQLiteDatabase.CONFLICT_REPLACE);
if (newID <= 0) {
throw new SQLException("Error to add: " + uri);
}
}
sqlDB.setTransactionSuccessful();
getContext().getContentResolver().notifyChange(uri, null);
numInserted = allValues.length;
} finally {
sqlDB.endTransaction();
}
return numInserted;
}
Using this call:
mContext.getContentResolver().bulkInsert(ProviderMyDatabase.CONTENT_URI,
valuesToInsertArray);
Is there any way to delete multiple rows (with this array ID's) of
database using content provider.
Thanks in advance
No comments:
Post a Comment