mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 22:57:29 +00:00
db migration debug
This commit is contained in:
parent
e141b17701
commit
9c0eddeff2
@ -12,7 +12,7 @@ android {
|
|||||||
// REMEMBER TO CHANGE versionCode AS WELL
|
// REMEMBER TO CHANGE versionCode AS WELL
|
||||||
// 16.7 is 32, 16.9 is 35 (34 is public beta)
|
// 16.7 is 32, 16.9 is 35 (34 is public beta)
|
||||||
|
|
||||||
versionCode 35
|
versionCode 36
|
||||||
versionName '16.9'
|
versionName '16.9'
|
||||||
|
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
|
@ -142,7 +142,7 @@ public final class Main extends BaseLanguageActivity {
|
|||||||
if (mainHelper != null && !Utils.isEmpty(result)) {
|
if (mainHelper != null && !Utils.isEmpty(result)) {
|
||||||
closeAnyOpenDrawer();
|
closeAnyOpenDrawer();
|
||||||
addToStack();
|
addToStack();
|
||||||
userQuery = (result.contains("/") || result.startsWith("#")) ? result : ("@"+result);
|
userQuery = (result.contains("/") || result.startsWith("#") || result.startsWith("@")) ? result : ("@"+result);
|
||||||
mainHelper.onRefresh();
|
mainHelper.onRefresh();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -41,6 +41,7 @@ public final class DataBox extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@NonNull final SQLiteDatabase db) {
|
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||||
|
settingsHelper.putBoolean(Constants.DB_TO_MIGRATE, false);
|
||||||
db.execSQL("CREATE TABLE cookies (id INTEGER PRIMARY KEY, uid TEXT, username TEXT, cookie TEXT)");
|
db.execSQL("CREATE TABLE cookies (id INTEGER PRIMARY KEY, uid TEXT, username TEXT, cookie TEXT)");
|
||||||
db.execSQL("CREATE TABLE favorites (id INTEGER PRIMARY KEY, query_text TEXT, date_added INTEGER, query_display TEXT)");
|
db.execSQL("CREATE TABLE favorites (id INTEGER PRIMARY KEY, query_text TEXT, date_added INTEGER, query_display TEXT)");
|
||||||
}
|
}
|
||||||
@ -107,14 +108,14 @@ public final class DataBox extends SQLiteOpenHelper {
|
|||||||
ArrayList<FavoriteModel> favorites = null;
|
ArrayList<FavoriteModel> favorites = null;
|
||||||
FavoriteModel tempFav;
|
FavoriteModel tempFav;
|
||||||
|
|
||||||
if (Utils.settingsHelper.getBoolean(Constants.DB_TO_MIGRATE)) {
|
if (Utils.settingsHelper.getBoolean(Constants.DB_TO_MIGRATE) == true) {
|
||||||
try (final SQLiteDatabase db = getWritableDatabase()) {
|
try (final SQLiteDatabase db = getWritableDatabase()) {
|
||||||
db.execSQL("ALTER TABLE favorites ADD query_display TEXT");
|
|
||||||
try {
|
try {
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
db.execSQL("ALTER TABLE favorites ADD query_display TEXT");
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
if (logCollector != null)
|
if (logCollector != null)
|
||||||
logCollector.appendException(e, LogCollector.LogFile.DATA_BOX_FAVORITES, "delFavorite");
|
logCollector.appendException(e, LogCollector.LogFile.DATA_BOX_FAVORITES, "migrate");
|
||||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
@ -126,6 +127,7 @@ public final class DataBox extends SQLiteOpenHelper {
|
|||||||
try (final SQLiteDatabase db = getWritableDatabase();
|
try (final SQLiteDatabase db = getWritableDatabase();
|
||||||
final Cursor cursor = db.rawQuery("SELECT query_text, date_added, query_display FROM favorites ORDER BY date_added DESC", null)) {
|
final Cursor cursor = db.rawQuery("SELECT query_text, date_added, query_display FROM favorites ORDER BY date_added DESC", null)) {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
db.beginTransaction();
|
||||||
favorites = new ArrayList<>();
|
favorites = new ArrayList<>();
|
||||||
do {
|
do {
|
||||||
tempFav = new FavoriteModel(
|
tempFav = new FavoriteModel(
|
||||||
@ -135,21 +137,24 @@ public final class DataBox extends SQLiteOpenHelper {
|
|||||||
);
|
);
|
||||||
if (cursor.getString(2) == null) {
|
if (cursor.getString(2) == null) {
|
||||||
try {
|
try {
|
||||||
db.beginTransaction();
|
final ContentValues values = new ContentValues();
|
||||||
final int rowsDeleted = db.delete(TABLE_FAVORITES, KEY_QUERY_TEXT + "=? AND " + KEY_DATE_ADDED + "=? AND " + KEY_QUERY_DISPLAY + " IS NULL",
|
values.put(KEY_DATE_ADDED, tempFav.getDate());
|
||||||
new String[]{cursor.getString(0), Long.toString(cursor.getLong(1))});
|
values.put(KEY_QUERY_TEXT, tempFav.getQuery());
|
||||||
if (rowsDeleted > 0) db.setTransactionSuccessful();
|
values.put(KEY_QUERY_DISPLAY, tempFav.getDisplayName());
|
||||||
|
|
||||||
|
final int rows = db.update(TABLE_FAVORITES, values, KEY_QUERY_TEXT + "=?", new String[]{tempFav.getQuery()});
|
||||||
|
|
||||||
|
if (rows != 1)
|
||||||
|
db.insertOrThrow(TABLE_FAVORITES, null, values);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
if (logCollector != null)
|
if (logCollector != null)
|
||||||
logCollector.appendException(e, LogCollector.LogFile.DATA_BOX_FAVORITES, "delFavorite");
|
logCollector.appendException(e, LogCollector.LogFile.DATA_BOX_FAVORITES, "delFavorite");
|
||||||
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
}
|
||||||
addFavorite(tempFav);
|
|
||||||
}
|
}
|
||||||
favorites.add(tempFav);
|
favorites.add(tempFav);
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public final class FlavorTown {
|
|||||||
|
|
||||||
public static void changelogCheck(@NonNull final Context context) {
|
public static void changelogCheck(@NonNull final Context context) {
|
||||||
if (settingsHelper.getInteger(Constants.PREV_INSTALL_VERSION) < BuildConfig.VERSION_CODE) {
|
if (settingsHelper.getInteger(Constants.PREV_INSTALL_VERSION) < BuildConfig.VERSION_CODE) {
|
||||||
if (settingsHelper.getInteger(Constants.PREV_INSTALL_VERSION) < 35)
|
if (settingsHelper.getInteger(Constants.PREV_INSTALL_VERSION) < 36)
|
||||||
settingsHelper.putBoolean(Constants.DB_TO_MIGRATE, true);
|
settingsHelper.putBoolean(Constants.DB_TO_MIGRATE, true);
|
||||||
Toast.makeText(context, R.string.updated, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.updated, Toast.LENGTH_SHORT).show();
|
||||||
settingsHelper.putInteger(Constants.PREV_INSTALL_VERSION, BuildConfig.VERSION_CODE);
|
settingsHelper.putInteger(Constants.PREV_INSTALL_VERSION, BuildConfig.VERSION_CODE);
|
||||||
|
Loading…
Reference in New Issue
Block a user