From c6259b40c11867078a1d3f260227d3c09dd53ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20D=C3=ADaz?= Date: Thu, 2 Mar 2017 12:46:40 +0100 Subject: [PATCH] Exception handling for db.insert in bulkInsert. If we throw an Exception when the date is not normalized I think we should handle the case where db.insert fails with the same severity. Currently it would mark the transaction as complete, meaning that if some items fails to be inserted, and are then read from the database, our recycler view will show the stored items and our user will see we are missing data. --- .../com/example/android/sunshine/data/WeatherProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/S09.02-Solution-ContentProviderBulkInsert/app/src/main/java/com/example/android/sunshine/data/WeatherProvider.java b/S09.02-Solution-ContentProviderBulkInsert/app/src/main/java/com/example/android/sunshine/data/WeatherProvider.java index f6702d0c57..6a564baf95 100644 --- a/S09.02-Solution-ContentProviderBulkInsert/app/src/main/java/com/example/android/sunshine/data/WeatherProvider.java +++ b/S09.02-Solution-ContentProviderBulkInsert/app/src/main/java/com/example/android/sunshine/data/WeatherProvider.java @@ -160,6 +160,8 @@ public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) { long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value); if (_id != -1) { rowsInserted++; + } else { + throw new SQLException("Failed to insert item: " + value + " into uri: " + uri); } } db.setTransactionSuccessful(); @@ -358,4 +360,4 @@ public void shutdown() { mOpenHelper.close(); super.shutdown(); } -} \ No newline at end of file +}