From 5c48526057a9a8c37df269f03dc2a7783d4ccdfd Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 7 Dec 2011 11:31:43 +0300 Subject: [PATCH] check for db validity in has/pending offlinedata functions --- src/org/fox/ttrss/MainActivity.java | 38 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index b60609d2..81187fa0 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -123,14 +123,18 @@ public class MainActivity extends FragmentActivity implements OnlineServices { } private boolean hasPendingOfflineData() { - Cursor c = getReadableDb().query("articles", - new String[] { "COUNT(*)" }, "modified = 1", null, null, null, - null); - if (c.moveToFirst()) { - int modified = c.getInt(0); - c.close(); - - return modified > 0; + try { + Cursor c = getReadableDb().query("articles", + new String[] { "COUNT(*)" }, "modified = 1", null, null, null, + null); + if (c.moveToFirst()) { + int modified = c.getInt(0); + c.close(); + + return modified > 0; + } + } catch (IllegalStateException e) { + // db is closed? ugh } return false; @@ -141,13 +145,17 @@ public class MainActivity extends FragmentActivity implements OnlineServices { } private boolean hasOfflineData() { - Cursor c = getReadableDb().query("articles", - new String[] { "COUNT(*)" }, null, null, null, null, null); - if (c.moveToFirst()) { - int modified = c.getInt(0); - c.close(); - - return modified > 0; + try { + Cursor c = getReadableDb().query("articles", + new String[] { "COUNT(*)" }, null, null, null, null, null); + if (c.moveToFirst()) { + int modified = c.getInt(0); + c.close(); + + return modified > 0; + } + } catch (IllegalStateException e) { + // db is closed? } return false;