Fix database creation and updates #246
The creation script *must* always do the full creation so that fresh installs get the correct database (no upgrade scripts will run for them)
This commit is contained in:
parent
459f6baf08
commit
619ea04a63
|
@ -34,7 +34,7 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActivityDatabaseHandler.class);
|
||||
|
||||
private static final int DATABASE_VERSION = 6;
|
||||
private static final int DATABASE_VERSION = 7;
|
||||
|
||||
public ActivityDatabaseHandler(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
|
|
|
@ -73,9 +73,18 @@ public class DBHelper {
|
|||
|
||||
public static boolean existsColumn(String tableName, String columnName, SQLiteDatabase db) {
|
||||
try (Cursor res = db.rawQuery("PRAGMA table_info('" + tableName + "')", null)) {
|
||||
int result = res.getColumnIndex(columnName);
|
||||
return result != -1;
|
||||
int index = res.getColumnIndex("name");
|
||||
if (index < 1) {
|
||||
return false; // something's really wrong
|
||||
}
|
||||
while (res.moveToNext()) {
|
||||
String cn = res.getString(index);
|
||||
if (columnName.equals(cn)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package nodomain.freeyourgadget.gadgetbridge.database.schema;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES;
|
||||
|
||||
/**
|
||||
* Bugfix for users who installed 0.8.1 cleanly, i.e. without any previous
|
||||
* database. Perform Update script 6 again.
|
||||
*/
|
||||
public class ActivityDBUpdate_7 extends ActivityDBUpdate_6 {
|
||||
}
|
Loading…
Reference in New Issue