Added code to catch SQLiteException errors like missing columns and recommend a reinstall

pull/14/head
Sam Bosley 13 years ago
parent ad4d99bcf6
commit cce6f2c0e7

@ -11,6 +11,7 @@ import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.v4.app.Fragment;
@ -38,6 +39,7 @@ import android.widget.TextView.OnEditorActionListener;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query;
@ -60,6 +62,7 @@ import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.helper.ImageDiskCache;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.sync.SyncResultCallback;
@ -125,7 +128,11 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene
}
public void loadViewForTaskID(long t){
task = PluginServices.getTaskService().fetchById(t, Task.NOTES, Task.ID, Task.REMOTE_ID, Task.TITLE);
try {
task = PluginServices.getTaskService().fetchById(t, Task.NOTES, Task.ID, Task.REMOTE_ID, Task.TITLE);
} catch (SQLiteException e) {
StartupService.handleSQLiteColumnMissing(ContextManager.getContext(), e);
}
if(task == null) {
return;
}

@ -645,5 +645,12 @@ Astrid is the much loved open-source todo list / task manager designed to help
you get stuff done. It features reminders, tags, sync, Locale plug-in, a widget and more.
</string>
<string name="DB_corrupted_title">Corrupted Database</string>
<string name="DB_corrupted_body">
Uh oh! It looks like you may have a corrupted database.
If you see this error regularly, we suggest you uninstall,
reinstall, and restore your tasks from a backup by
clicking Menu->Backup->Import Tasks in Astrid.</string>
</resources>

@ -18,6 +18,7 @@ import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
@ -81,6 +82,7 @@ import com.todoroo.astrid.reminders.ReminderDebugContextActions;
import com.todoroo.astrid.service.AddOnService;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.TagDataService;
@ -814,8 +816,14 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
filter.sqlQuery, sortFlags, sortSort));
// perform query
TodorooCursor<Task> currentCursor = taskService.fetchFiltered(
TodorooCursor<Task> currentCursor;
try {
currentCursor = taskService.fetchFiltered(
sqlQueryTemplate.get(), null, taskProperties());
} catch (SQLiteException e) {
StartupService.handleSQLiteColumnMissing(getActivity(), e);
return;
}
// set up list adapters
taskAdapter = createTaskAdapter(currentCursor);

@ -16,6 +16,7 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.sqlite.SQLiteException;
import android.media.AudioManager;
import android.util.Log;
import android.widget.Toast;
@ -112,7 +113,12 @@ public class StartupService {
Crittercism.setShouldUseAmazonMarket(Constants.MARKET_DISABLED);
}
database.openForWriting();
try {
database.openForWriting();
} catch (SQLiteException e) {
handleSQLiteColumnMissing(context, e);
return;
}
// show notification if reminders are silenced
if(context instanceof Activity) {
@ -211,6 +217,18 @@ public class StartupService {
hasStartedUp = true;
}
public static void handleSQLiteColumnMissing(Context context, final SQLiteException e) {
new AlertDialog.Builder(context)
.setTitle(R.string.DB_corrupted_title)
.setMessage(R.string.DB_corrupted_body)
.setPositiveButton(R.string.DLG_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
throw e;
}
}).create().show();
}
/**
* If database exists, no tasks but metadata, and a backup file exists, restore it
*/

Loading…
Cancel
Save