use of android.database.sqlite.SQLiteException in project Anki-Android by Ramblurr.
the class MetaDB method getNotificationStatus.
public static int getNotificationStatus(Context context) {
openDBIfClosed(context);
Cursor cursor = null;
int due = 0;
try {
cursor = mMetaDb.query("smallWidgetStatus", new String[] { "left" }, null, null, null, null, null);
if (cursor.moveToFirst()) {
return cursor.getInt(0);
}
// while (cursor.moveToNext()) {
// due += cursor.getInt(0) + cursor.getInt(1) + cursor.getInt(2);
// }
} catch (SQLiteException e) {
Log.e(AnkiDroidApp.TAG, "Error while querying widgetStatus", e);
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
return due;
}
use of android.database.sqlite.SQLiteException in project Anki-Android by Ramblurr.
the class MetaDB method getWidgetStatus.
/**
* Return the current status of the widget.
*
* @return an array of {@link DeckStatus} objects, each representing the status of one of the known decks
*/
public static DeckStatus[] getWidgetStatus(Context context) {
openDBIfClosed(context);
Cursor cursor = null;
try {
cursor = mMetaDb.query("widgetStatus", new String[] { "deckId", "deckName", "newCards", "lrnCards", "dueCards", "progress", "eta" }, null, null, null, null, "deckName");
int count = cursor.getCount();
DeckStatus[] decks = new DeckStatus[count];
for (int index = 0; index < count; ++index) {
if (!cursor.moveToNext()) {
throw new SQLiteException("cursor count was incorrect");
}
decks[index] = new DeckStatus(cursor.getLong(cursor.getColumnIndexOrThrow("deckId")), cursor.getString(cursor.getColumnIndexOrThrow("deckName")), cursor.getInt(cursor.getColumnIndexOrThrow("newCards")), cursor.getInt(cursor.getColumnIndexOrThrow("lrnCards")), cursor.getInt(cursor.getColumnIndexOrThrow("dueCards")), cursor.getInt(cursor.getColumnIndexOrThrow("progress")), cursor.getInt(cursor.getColumnIndexOrThrow("eta")));
}
return decks;
} catch (SQLiteException e) {
Log.e(AnkiDroidApp.TAG, "Error while querying widgetStatus", e);
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
return new DeckStatus[0];
}
use of android.database.sqlite.SQLiteException in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateWithStaticUpdateButWrongColumn.
public void testUpdateWithStaticUpdateButWrongColumn() {
ContentValues values = new ContentValues();
values.put("TEACHERYEARS", 13);
try {
DataSupport.update(Teacher.class, values, teacher.getId());
fail("no such column: TEACHERYEARS");
} catch (SQLiteException e) {
}
}
use of android.database.sqlite.SQLiteException in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateWithStaticUpdateButWrongClass.
public void testUpdateWithStaticUpdateButWrongClass() {
ContentValues values = new ContentValues();
values.put("TEACHERNAME", "Toy");
try {
DataSupport.update(Object.class, values, teacher.getId());
} catch (SQLiteException e) {
}
}
use of android.database.sqlite.SQLiteException in project sugar by satyan.
the class SugarRecord method sum.
public static <T> long sum(Class<T> type, String field, String whereClause, String... whereArgs) {
long result = -1;
String filter = (!TextUtils.isEmpty(whereClause)) ? " where " + whereClause : "";
SQLiteStatement sqLiteStatement;
try {
sqLiteStatement = getSugarDataBase().compileStatement("SELECT sum(" + field + ") FROM " + NamingHelper.toTableName(type) + filter);
} catch (SQLiteException e) {
e.printStackTrace();
return result;
}
if (whereArgs != null) {
for (int i = whereArgs.length; i != 0; i--) {
sqLiteStatement.bindString(i, whereArgs[i - 1]);
}
}
try {
result = sqLiteStatement.simpleQueryForLong();
} finally {
sqLiteStatement.close();
}
return result;
}
Aggregations