Hello,
my app was released a year ago or so, but now one year later, I get the
following error message:
android.database.sqlite.SQLiteException: no such table: tracking: ,
while compiling: SELECT _id, ...
How can it happen that the table does not exist? In one installation of
thousands?
The app accesses the db via an SQLiteOpenHelper.
This is my implementation, a little bit shortened:
public class DatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 22;
private static final String DATABASE_NAME = "de.sportscheck.db";
private static DatabaseHelper dh;
public static synchronized DatabaseHelper singleton(final Context
context) {
if (dh == null) {
dh = new DatabaseHelper(context);
}
return dh;
}
private DatabaseHelper(final Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
createTrainingTable(db);
createTrainingStepTable(db);
createTrackingTable(db);
createBreadcrumbTable(db);
createKmTable(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
if (oldVersion == 12) {
db.execSQL("ALTER TABLE " ...
db.execSQL("ALTER TABLE " ...
}
if (oldVersion == 21) {
createKmTable(db);
}
}
private void createTrainingTable(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS
".concat(TrainingProvider.TABLE_NAME) + ";");
String sql = "CREATE TABLE ".concat(TrainingProvider.TABLE_NAME) ...
.concat(TrainingItem.TYP).concat(" TEXT);");
db.execSQL(sql);
}
private void createTrainingStepTable(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS
".concat(TrainingStepProvider.TABLE_NAME) + ";");
String sql = "CREATE TABLE
".concat(TrainingStepProvider.TABLE_NAME) ...
db.execSQL(sql);
}
private void createTrackingTable(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS
".concat(TrackingProvider.TABLE_NAME) + ";");
String sql = "CREATE TABLE ".concat(TrackingProvider.TABLE_NAME) ...
db.execSQL(sql);
}
private void createBreadcrumbTable(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS
".concat(BreadcrumbProvider.TABLE_NAME) + ";");
String sql = "CREATE TABLE ".concat(BreadcrumbProvider.TABLE_NAME) ...
db.execSQL(sql);
}
private void createKmTable(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS ".concat(KmProvider.TABLE_NAME) +
";");
String sql = "CREATE TABLE ".concat(KmProvider.TABLE_NAME) ...
db.execSQL(sql);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en