Search in sources :

Example 81 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 82 with SQLiteException

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];
}
Also used : DeckStatus(com.ichi2.widget.DeckStatus) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 83 with SQLiteException

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) {
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteException(android.database.sqlite.SQLiteException)

Example 84 with SQLiteException

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) {
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteException(android.database.sqlite.SQLiteException)

Example 85 with SQLiteException

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;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLiteException(android.database.sqlite.SQLiteException)

Aggregations

SQLiteException (android.database.sqlite.SQLiteException)122 Cursor (android.database.Cursor)72 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)36 ContentValues (android.content.ContentValues)28 SQLException (android.database.SQLException)17 Intent (android.content.Intent)14 HandlerThread (android.os.HandlerThread)10 File (java.io.File)10 HashMap (java.util.HashMap)8 Account (android.accounts.Account)7 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)7 SyncStatusInfo (android.content.SyncStatusInfo)6 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)6 BufferedWriter (java.io.BufferedWriter)6 FileWriter (java.io.FileWriter)6 Uri (android.net.Uri)5 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 SQLiteStatement (android.database.sqlite.SQLiteStatement)3 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)3