Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Commit

Permalink
Fixed crash in database
Browse files Browse the repository at this point in the history
Auditors: @bbondy
  • Loading branch information
SergeyZhukovsky committed Dec 8, 2015
1 parent 3566adb commit bf681ac
Showing 1 changed file with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,50 +186,62 @@ public int getRecentHistoryRecordId(String url){
public List<HistoryRecord> getAllHistoryRecords() {
List<HistoryRecord> records = new ArrayList<HistoryRecord>();

String query = "SELECT * FROM " + TABLE_LINK_HISTORY + " ORDER BY " + KEY_TIME + " DESC;";
try {
String query = "SELECT * FROM " + TABLE_LINK_HISTORY + " ORDER BY " + KEY_TIME + " DESC;";

SQLiteDatabase db = getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);

if (cursor.moveToFirst()) {
do {
HistoryRecord historyRecord = new HistoryRecord();
historyRecord.setId(Integer.parseInt(cursor.getString(0)));
historyRecord.setTitle(cursor.getString(1));
historyRecord.setUrl(cursor.getString(2));
historyRecord.setHost(cursor.getString(3));
historyRecord.setTime(cursor.getLong(4));

records.add(historyRecord);
} while (cursor.moveToNext());
}

SQLiteDatabase db = getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);

if (cursor.moveToFirst()) {
do {
HistoryRecord historyRecord = new HistoryRecord();
historyRecord.setId(Integer.parseInt(cursor.getString(0)));
historyRecord.setTitle(cursor.getString(1));
historyRecord.setUrl(cursor.getString(2));
historyRecord.setHost(cursor.getString(3));
historyRecord.setTime(cursor.getLong(4));

records.add(historyRecord);
} while (cursor.moveToNext());
db.close();
}
catch (IllegalStateException exc) {
// TODO: just skip it for now, we will need to refactor db code in future
}

db.close();
return records;
}

public List<HistoryRecord> getRecentNHistoryRecords(int countToGet) {
List<HistoryRecord> records = new ArrayList<HistoryRecord>();

String query = "SELECT * FROM " + TABLE_LINK_HISTORY + " ORDER BY " + KEY_TIME + " DESC LIMIT " + String.valueOf(countToGet) + ";";
try {
String query = "SELECT * FROM " + TABLE_LINK_HISTORY + " ORDER BY " + KEY_TIME + " DESC LIMIT " + String.valueOf(countToGet) + ";";

SQLiteDatabase db = getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);

if (cursor.moveToFirst()) {
do {
HistoryRecord historyRecord = new HistoryRecord();
historyRecord.setId(Integer.parseInt(cursor.getString(0)));
historyRecord.setTitle(cursor.getString(1));
historyRecord.setUrl(cursor.getString(2));
historyRecord.setHost(cursor.getString(3));
historyRecord.setTime(cursor.getLong(4));

records.add(historyRecord);
} while (cursor.moveToNext());
}

SQLiteDatabase db = getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);

if (cursor.moveToFirst()) {
do {
HistoryRecord historyRecord = new HistoryRecord();
historyRecord.setId(Integer.parseInt(cursor.getString(0)));
historyRecord.setTitle(cursor.getString(1));
historyRecord.setUrl(cursor.getString(2));
historyRecord.setHost(cursor.getString(3));
historyRecord.setTime(cursor.getLong(4));

records.add(historyRecord);
} while (cursor.moveToNext());
db.close();
}
catch (IllegalStateException exc) {
// TODO: just skip it for now, we will need to refactor db code in future
}

db.close();
return records;
}

Expand Down

0 comments on commit bf681ac

Please sign in to comment.