mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Add some database checks
This commit is contained in:
@@ -130,6 +130,8 @@ public abstract class CheckmarkList
|
|||||||
*/
|
*/
|
||||||
public final int[] getValues(long from, long to)
|
public final int[] getValues(long from, long to)
|
||||||
{
|
{
|
||||||
|
if(from > to) return new int[0];
|
||||||
|
|
||||||
List<Checkmark> checkmarks = getByInterval(from, to);
|
List<Checkmark> checkmarks = getByInterval(from, to);
|
||||||
int values[] = new int[checkmarks.size()];
|
int values[] = new int[checkmarks.size()];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.models.sqlite;
|
||||||
|
|
||||||
|
public class InconsistentDatabaseException extends RuntimeException
|
||||||
|
{
|
||||||
|
public InconsistentDatabaseException(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import com.activeandroid.query.*;
|
|||||||
|
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.models.sqlite.records.*;
|
import org.isoron.uhabits.models.sqlite.records.*;
|
||||||
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.jetbrains.annotations.*;
|
import org.jetbrains.annotations.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -99,6 +100,15 @@ public class SQLiteCheckmarkList extends CheckmarkList
|
|||||||
|
|
||||||
List<CheckmarkRecord> records = sqlite.query(query, params);
|
List<CheckmarkRecord> records = sqlite.query(query, params);
|
||||||
for (CheckmarkRecord record : records) record.habit = habitRecord;
|
for (CheckmarkRecord record : records) record.habit = habitRecord;
|
||||||
|
|
||||||
|
int nDays = DateUtils.getDaysBetween(fromTimestamp, toTimestamp) + 1;
|
||||||
|
if (records.size() != nDays)
|
||||||
|
{
|
||||||
|
throw new InconsistentDatabaseException(
|
||||||
|
String.format("habit=%s, %d expected, %d found",
|
||||||
|
habit.getName(), nDays, records.size()));
|
||||||
|
}
|
||||||
|
|
||||||
return toCheckmarks(records);
|
return toCheckmarks(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user