Search in sources :

Example 66 with SQLiteException

use of android.database.sqlite.SQLiteException in project DevRing by LJYcoder.

the class NativeTableManager method count.

@Override
public long count() {
    int count = 0;
    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    String sql = "select count(*) from " + mTableName;
    Cursor cursor = null;
    try {
        cursor = db.rawQuery(sql, null);
        if (cursor != null && cursor.moveToFirst()) {
            count = cursor.getInt(0);
        }
    } catch (SQLiteException e) {
        RingLog.e(e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        mOpenHelper.close();
    }
    return count;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 67 with SQLiteException

use of android.database.sqlite.SQLiteException in project DevRing by LJYcoder.

the class NativeTableManager method loadAll.

@Override
public List<M> loadAll() {
    List<M> list = null;
    String sql = "select * from " + mTableName;
    SQLiteDatabase db = mOpenHelper.getReadableDatabase();
    Cursor cursor = null;
    try {
        cursor = db.rawQuery(sql, null);
        list = cursor != null ? readCursors(cursor) : null;
    } catch (SQLiteException e) {
        RingLog.e(e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        mOpenHelper.close();
    }
    return list;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 68 with SQLiteException

use of android.database.sqlite.SQLiteException in project k-9 by k9mail.

the class MigrationTo41 method db41UpdateFolderMetadata.

public static void db41UpdateFolderMetadata(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT id, name FROM folders", null);
        while (cursor.moveToNext()) {
            try {
                int id = cursor.getInt(0);
                String name = cursor.getString(1);
                update41Metadata(db, migrationsHelper, id, name);
            } catch (Exception e) {
                Timber.e(e, " error trying to ugpgrade a folder class");
            }
        }
    } catch (SQLiteException e) {
        Timber.e(e, "Exception while upgrading database to v41. folder classes may have vanished");
    } finally {
        Utility.closeQuietly(cursor);
    }
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) SQLiteException(android.database.sqlite.SQLiteException)

Example 69 with SQLiteException

use of android.database.sqlite.SQLiteException in project k-9 by k9mail.

the class MigrationTo50 method foldersAddNotifyClassColumn.

public static void foldersAddNotifyClassColumn(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
    try {
        db.execSQL("ALTER TABLE folders ADD notify_class TEXT default '" + Folder.FolderClass.INHERITED.name() + "'");
    } catch (SQLiteException e) {
        if (!e.getMessage().startsWith("duplicate column name:")) {
            throw e;
        }
    }
    ContentValues cv = new ContentValues();
    cv.put("notify_class", Folder.FolderClass.FIRST_CLASS.name());
    Account account = migrationsHelper.getAccount();
    db.update("folders", cv, "name = ?", new String[] { account.getInboxFolderName() });
}
Also used : ContentValues(android.content.ContentValues) Account(com.fsck.k9.Account) SQLiteException(android.database.sqlite.SQLiteException)

Example 70 with SQLiteException

use of android.database.sqlite.SQLiteException in project android-sqlite-asset-helper by jgilfelt.

the class SQLiteAssetHelper method returnDatabase.

private SQLiteDatabase returnDatabase() {
    try {
        SQLiteDatabase db = SQLiteDatabase.openDatabase(mDatabasePath + "/" + mName, mFactory, SQLiteDatabase.OPEN_READWRITE);
        Log.i(TAG, "successfully opened database " + mName);
        return db;
    } catch (SQLiteException e) {
        Log.w(TAG, "could not open database " + mName + " - " + e.getMessage());
        return null;
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) 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