Search in sources :

Example 6 with SQLiteFullException

use of android.database.sqlite.SQLiteFullException in project MiMangaNu by raulhaag.

the class Database method markChapter.

static void markChapter(Context context, int capId, boolean read) {
    ContentValues cv = new ContentValues();
    cv.put(COL_CAP_STATE, read ? Chapter.READ : Chapter.UNREAD);
    try {
        SQLiteDatabase database = getDatabase(context);
        if (!database.isReadOnly()) {
            database.update(TABLE_CHAPTERS, cv, COL_CAP_ID + " = " + capId, null);
        } else {
            Log.e("Database", "(markChapter) " + context.getResources().getString(R.string.error_database_is_read_only));
            Util.getInstance().toast(context, context.getResources().getString(R.string.error_database_is_read_only));
        }
    } catch (SQLiteFullException sqlfe) {
        Log.e("Database", "SQLiteFullException", sqlfe);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    } catch (SQLiteDiskIOException sqldioe) {
        Log.e("Database", "SQLiteDiskIOException", sqldioe);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    } catch (Exception e) {
        Log.e("Database", "Exception", e);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteFullException(android.database.sqlite.SQLiteFullException) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteFullException(android.database.sqlite.SQLiteFullException) SQLiteDatabaseCorruptException(android.database.sqlite.SQLiteDatabaseCorruptException) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteCantOpenDatabaseException(android.database.sqlite.SQLiteCantOpenDatabaseException) IOException(java.io.IOException) SQLException(android.database.SQLException) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException)

Example 7 with SQLiteFullException

use of android.database.sqlite.SQLiteFullException in project MiMangaNu by raulhaag.

the class Database method updateReadOrder.

public static void updateReadOrder(Context context, int ordinal, int mid) {
    ContentValues cv = new ContentValues();
    cv.put(COL_READ_ORDER, ordinal);
    try {
        SQLiteDatabase database = getDatabase(context);
        if (!database.isReadOnly()) {
            database.update(TABLE_MANGA, cv, COL_ID + "=" + mid, null);
        } else {
            Log.e("Database", "(updateReadOrder) " + context.getResources().getString(R.string.error_database_is_read_only));
            Util.getInstance().toast(context, context.getResources().getString(R.string.error_database_is_read_only));
        }
    } catch (SQLiteFullException sqlfe) {
        Log.e("Database", "SQLiteFullException", sqlfe);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    } catch (SQLiteDiskIOException sqldioe) {
        Log.e("Database", "SQLiteDiskIOException", sqldioe);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    } catch (Exception e) {
        Log.e("Database", "Exception", e);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteFullException(android.database.sqlite.SQLiteFullException) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteFullException(android.database.sqlite.SQLiteFullException) SQLiteDatabaseCorruptException(android.database.sqlite.SQLiteDatabaseCorruptException) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteCantOpenDatabaseException(android.database.sqlite.SQLiteCantOpenDatabaseException) IOException(java.io.IOException) SQLException(android.database.SQLException) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException)

Example 8 with SQLiteFullException

use of android.database.sqlite.SQLiteFullException in project Zom-Android by zom.

the class ImPluginHelper method loadAvailablePlugins.

public void loadAvailablePlugins() {
    if (mLoaded) {
        return;
    }
    List<ResolveInfo> plugins = getPlugins();
    for (ResolveInfo info : plugins) {
        Log.d(TAG, "Found plugin " + info);
        ServiceInfo serviceInfo = info.serviceInfo;
        if (serviceInfo == null) {
            Log.e(TAG, "Ignore bad IM plugin: " + info);
            continue;
        }
        String providerName = null;
        String providerFullName = null;
        String signUpUrl = null;
        Bundle metaData = serviceInfo.metaData;
        if (metaData != null) {
            providerName = metaData.getString(ImPluginConstants.METADATA_PROVIDER_NAME);
            providerFullName = metaData.getString(ImPluginConstants.METADATA_PROVIDER_FULL_NAME);
            signUpUrl = metaData.getString(ImPluginConstants.METADATA_SIGN_UP_URL);
        }
        if (TextUtils.isEmpty(providerName) || TextUtils.isEmpty(providerFullName)) {
            Log.e(TAG, "Ignore bad IM plugin: " + info + ". Lack of required meta data");
            continue;
        }
        if (isPluginDuplicated(providerName)) {
            Log.e(TAG, "Ignore duplicated IM plugin: " + info);
            continue;
        }
        if (!serviceInfo.packageName.equals(mContext.getPackageName())) {
            Log.e(TAG, "Ignore plugin in package: " + serviceInfo.packageName);
            continue;
        }
        ImPluginInfo pluginInfo = new ImPluginInfo(providerName, serviceInfo.packageName, serviceInfo.name, serviceInfo.applicationInfo.sourceDir);
        ImPlugin plugin = loadPlugin(pluginInfo);
        if (plugin == null) {
            Log.e(TAG, "Ignore bad IM plugin");
            continue;
        }
        try {
            updateProviderDb(plugin, pluginInfo, providerFullName, signUpUrl);
        } catch (SQLiteFullException e) {
            Log.e(TAG, "Storage full", e);
            return;
        }
        mPluginsInfo.add(pluginInfo);
        mPluginObjects.add(plugin);
    }
    mLoaded = true;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) Bundle(android.os.Bundle) ImPluginInfo(org.awesomeapp.messenger.plugin.ImPluginInfo) SQLiteFullException(android.database.sqlite.SQLiteFullException) ImPlugin(org.awesomeapp.messenger.plugin.ImPlugin)

Example 9 with SQLiteFullException

use of android.database.sqlite.SQLiteFullException in project mobile-center-sdk-android by Microsoft.

the class DatabaseManagerTest method cursorFailsToCloseAfterPut.

@Test
public void cursorFailsToCloseAfterPut() {
    /* Mocking instances. */
    Context contextMock = mock(Context.class);
    SQLiteOpenHelper helperMock = mock(SQLiteOpenHelper.class);
    SQLiteDatabase sqLiteDatabase = mock(SQLiteDatabase.class);
    when(helperMock.getWritableDatabase()).thenReturn(sqLiteDatabase);
    /* Mock the select cursor we are using to find logs to evict to fail. */
    mockStatic(SQLiteUtils.class);
    Cursor cursor = mock(Cursor.class);
    SQLiteDiskIOException exception = new SQLiteDiskIOException();
    doThrow(exception).when(cursor).close();
    when(cursor.moveToNext()).thenReturn(true).thenReturn(false);
    SQLiteQueryBuilder sqLiteQueryBuilder = mock(SQLiteQueryBuilder.class, new Returns(cursor));
    when(SQLiteUtils.newSQLiteQueryBuilder()).thenReturn(sqLiteQueryBuilder);
    /* Simulate that database is full only once (will work after purging 1 log). */
    when(sqLiteDatabase.insertOrThrow(anyString(), anyString(), any(ContentValues.class))).thenThrow(new SQLiteFullException()).thenReturn(1L);
    /* Instantiate real instance for DatabaseManager. */
    DatabaseManager databaseManager = new DatabaseManager(contextMock, "database", "table", 1, null, null, null);
    databaseManager.setSQLiteOpenHelper(helperMock);
    /* When we put a log, it succeeds even if a problem occurred while closing purge cursor. */
    long id = databaseManager.put(mock(ContentValues.class), "priority");
    assertEquals(1, id);
}
Also used : Context(android.content.Context) SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) ContentValues(android.content.ContentValues) Returns(org.mockito.internal.stubbing.answers.Returns) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteFullException(android.database.sqlite.SQLiteFullException) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with SQLiteFullException

use of android.database.sqlite.SQLiteFullException in project MiMangaNu by raulhaag.

the class Database method updateMangaRead.

public static void updateMangaRead(Context context, int mid) {
    ContentValues cv = new ContentValues();
    cv.put(COL_LAST_READ, System.currentTimeMillis());
    cv.put(COL_NEW, 0);
    try {
        SQLiteDatabase database = getDatabase(context);
        if (!database.isReadOnly())
            database.update(TABLE_MANGA, cv, COL_ID + "=" + mid, null);
        else {
            Log.e("Database", "(updateMangaRead) " + context.getResources().getString(R.string.error_database_is_read_only));
            Util.getInstance().toast(context, context.getResources().getString(R.string.error_database_is_read_only));
        }
    } catch (SQLiteFullException sqlfe) {
        Log.e("Database", "SQLiteFullException", sqlfe);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    } catch (SQLiteDiskIOException sqldioe) {
        Log.e("Database", "SQLiteDiskIOException", sqldioe);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    } catch (Exception e) {
        Log.e("Database", "Exception", e);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteFullException(android.database.sqlite.SQLiteFullException) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteFullException(android.database.sqlite.SQLiteFullException) SQLiteDatabaseCorruptException(android.database.sqlite.SQLiteDatabaseCorruptException) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteCantOpenDatabaseException(android.database.sqlite.SQLiteCantOpenDatabaseException) IOException(java.io.IOException) SQLException(android.database.SQLException) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException)

Aggregations

SQLiteFullException (android.database.sqlite.SQLiteFullException)23 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)16 ContentValues (android.content.ContentValues)15 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)14 IOException (java.io.IOException)13 SQLException (android.database.SQLException)12 SQLiteCantOpenDatabaseException (android.database.sqlite.SQLiteCantOpenDatabaseException)12 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)12 SQLiteDatabaseCorruptException (android.database.sqlite.SQLiteDatabaseCorruptException)12 Context (android.content.Context)3 Cursor (android.database.Cursor)3 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)3 Uri (android.net.Uri)3 ResolveInfo (android.content.pm.ResolveInfo)2 ServiceInfo (android.content.pm.ServiceInfo)2 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)2 SQLiteStatement (android.database.sqlite.SQLiteStatement)2 Bundle (android.os.Bundle)2 Date (java.util.Date)2 ImPlugin (org.awesomeapp.messenger.plugin.ImPlugin)2