mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Synchronise DB upgrades with other DB actions. (#591)
This commit is contained in:
parent
32cdc1b512
commit
1462d53cb0
4 changed files with 11 additions and 8 deletions
|
@ -30,7 +30,7 @@ public class BlurDatabase extends SQLiteOpenHelper {
|
|||
db.execSQL(DatabaseConstants.ACTION_SQL);
|
||||
}
|
||||
|
||||
public void dropAndRecreateTables() {
|
||||
void dropAndRecreateTables() {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
String drop = "DROP TABLE IF EXISTS ";
|
||||
db.execSQL(drop + DatabaseConstants.FEED_TABLE);
|
||||
|
@ -48,8 +48,6 @@ public class BlurDatabase extends SQLiteOpenHelper {
|
|||
db.execSQL(drop + DatabaseConstants.ACTION_TABLE);
|
||||
|
||||
onCreate(db);
|
||||
|
||||
db.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -72,6 +72,10 @@ public class BlurDatabaseHelper {
|
|||
return dbRW.isOpen();
|
||||
}
|
||||
|
||||
public void dropAndRecreateTables() {
|
||||
synchronized (RW_MUTEX) {dbWrapper.dropAndRecreateTables();}
|
||||
}
|
||||
|
||||
private List<String> getAllFeeds() {
|
||||
String q1 = "SELECT " + DatabaseConstants.FEED_ID +
|
||||
" FROM " + DatabaseConstants.FEED_TABLE;
|
||||
|
|
|
@ -50,6 +50,10 @@ public class FeedUtils {
|
|||
c.startService(i);
|
||||
}
|
||||
|
||||
public static void dropAndRecreateTables() {
|
||||
dbHelper.dropAndRecreateTables();
|
||||
}
|
||||
|
||||
public static void setStorySaved(final Story story, final boolean saved, final Context context) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.util.Log;
|
|||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.activity.Login;
|
||||
import com.newsblur.database.BlurDatabase;
|
||||
import com.newsblur.domain.UserDetails;
|
||||
import com.newsblur.service.NBSyncService;
|
||||
|
||||
|
@ -58,8 +57,7 @@ public class PrefsUtils {
|
|||
if ( (oldVersion == null) || (!oldVersion.equals(version)) ) {
|
||||
Log.i(PrefsUtils.class.getName(), "detected new version of app, clearing local data");
|
||||
// wipe the local DB
|
||||
BlurDatabase databaseHelper = new BlurDatabase(context.getApplicationContext());
|
||||
databaseHelper.dropAndRecreateTables();
|
||||
FeedUtils.dropAndRecreateTables();
|
||||
// in case this is the first time we have run since moving the cache to the new location,
|
||||
// blow away the old version entirely. This line can be removed some time well after
|
||||
// v61+ is widely deployed
|
||||
|
@ -99,8 +97,7 @@ public class PrefsUtils {
|
|||
context.getSharedPreferences(PrefConstants.PREFERENCES, 0).edit().clear().commit();
|
||||
|
||||
// wipe the local DB
|
||||
BlurDatabase databaseHelper = new BlurDatabase(context.getApplicationContext());
|
||||
databaseHelper.dropAndRecreateTables();
|
||||
FeedUtils.dropAndRecreateTables();
|
||||
|
||||
// prompt for a new login
|
||||
Intent i = new Intent(context, Login.class);
|
||||
|
|
Loading…
Add table
Reference in a new issue