Commit ccd58ac9 authored by Craig Earley's avatar Craig Earley
Browse files

adds a check for null or zero-size cursor before cleaning tables

parent 8e8ccec0
......@@ -323,7 +323,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
if (button == findViewById(R.id.wipeDatabase)) {
if(db.copyDatabase("archive")){
db.cleanDatabase("all");
makeToast("Erased local database");
makeToast("Local database content is now erased");
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
......@@ -333,7 +333,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
else if (button == findViewById(R.id.wipeReadingsTable)) {
if(db.copyDatabase("archive")){
db.cleanDatabase("reading");
makeToast("Cleaned readings table");
makeToast("Readings table is now clean");
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
......@@ -343,7 +343,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
else if (button == findViewById(R.id.wipeStreamingTable)) {
if(db.copyDatabase("archive")){
db.cleanDatabase("streaming");
makeToast("Cleaned streaming table");
makeToast("Streaming table is now clean");
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
......@@ -353,7 +353,7 @@ public class DatabaseActionsActivity extends AppCompatActivity {
else if (button == findViewById(R.id.wipeFieldData)) {
if(db.copyDatabase("archive")){
db.cleanDatabase("field");
makeToast("Cleaned field data");
makeToast("Both streaming and reading tables are now clean");
editor.putString("lastClean", getTimestamp());
cleanTV.setText(String.format(res.getString(R.string.lastClean), getTimestamp()));
displayDatabaseStatus(db.getStatus());
......
......@@ -402,6 +402,10 @@ public class ReadingsDatabase extends SQLiteOpenHelper {
Log.d("TABLECLEAN","table to clean: "+tableToClean);
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery("select endtime from fieldday_upload order by endtime desc",null);
if(c==null || c.getCount()==0){
Log.d("TABLECLEAN","Nothing to clean here");
return;
}
String mostRecentUploadTS;
c.moveToFirst();
mostRecentUploadTS = "'" + c.getString(c.getColumnIndex("endtime")) + "'";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment