Search in sources :

Example 1 with SQLiteFullException

use of android.database.sqlite.SQLiteFullException in project weex-example by KalicyZhou.

the class DefaultWXStorage method performSetItem.

private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) {
    SQLiteDatabase database = mDatabaseSupplier.getDatabase();
    if (database == null) {
        return false;
    }
    WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "set k-v to storage(key:" + key + ",value:" + value + ",isPersistent:" + isPersistent + ",allowRetry:" + allowRetryWhenFull + ")");
    String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);";
    SQLiteStatement statement = null;
    String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date());
    try {
        statement = database.compileStatement(sql);
        statement.clearBindings();
        statement.bindString(1, key);
        statement.bindString(2, value);
        statement.bindString(3, timeStamp);
        statement.bindLong(4, isPersistent ? 1 : 0);
        statement.execute();
        return true;
    } catch (Exception e) {
        WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage());
        if (e instanceof SQLiteFullException) {
            if (allowRetryWhenFull && trimToSize()) {
                //try again
                //setItem/setItemPersistent method only allow try once when occurred a sqliteFullException.
                WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "retry set k-v to storage(key:" + key + ",value:" + value + ")");
                return performSetItem(key, value, isPersistent, false);
            }
        }
        return false;
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLiteFullException(android.database.sqlite.SQLiteFullException) Date(java.util.Date) SQLiteFullException(android.database.sqlite.SQLiteFullException)

Example 2 with SQLiteFullException

use of android.database.sqlite.SQLiteFullException in project incubator-weex by apache.

the class DefaultWXStorage method performSetItem.

private boolean performSetItem(String key, String value, boolean isPersistent, boolean allowRetryWhenFull) {
    SQLiteDatabase database = mDatabaseSupplier.getDatabase();
    if (database == null) {
        return false;
    }
    WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "set k-v to storage(key:" + key + ",value:" + value + ",isPersistent:" + isPersistent + ",allowRetry:" + allowRetryWhenFull + ")");
    String sql = "INSERT OR REPLACE INTO " + WXSQLiteOpenHelper.TABLE_STORAGE + " VALUES (?,?,?,?);";
    SQLiteStatement statement = null;
    String timeStamp = WXSQLiteOpenHelper.sDateFormatter.format(new Date());
    try {
        statement = database.compileStatement(sql);
        statement.clearBindings();
        statement.bindString(1, key);
        statement.bindString(2, value);
        statement.bindString(3, timeStamp);
        statement.bindLong(4, isPersistent ? 1 : 0);
        statement.execute();
        return true;
    } catch (Exception e) {
        WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute setItem :" + e.getMessage());
        if (e instanceof SQLiteFullException) {
            if (allowRetryWhenFull && trimToSize()) {
                // try again
                // setItem/setItemPersistent method only allow try once when occurred a sqliteFullException.
                WXLogUtils.d(WXSQLiteOpenHelper.TAG_STORAGE, "retry set k-v to storage(key:" + key + ",value:" + value + ")");
                return performSetItem(key, value, isPersistent, false);
            }
        }
        return false;
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLiteFullException(android.database.sqlite.SQLiteFullException) Date(java.util.Date) SQLiteFullException(android.database.sqlite.SQLiteFullException)

Example 3 with SQLiteFullException

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

the class Database method updateMangaScrollSensitive.

public static void updateMangaScrollSensitive(Context context, int mid, float nScroll) {
    ContentValues cv = new ContentValues();
    cv.put(COL_SCROLL_SENSITIVE, nScroll);
    try {
        SQLiteDatabase database = getDatabase(context);
        if (!database.isReadOnly())
            database.update(TABLE_MANGA, cv, COL_ID + "=" + mid, null);
        else {
            Log.e("Database", "(updateMangaScrollSensitive) " + 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 4 with SQLiteFullException

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

the class Database method updateChapterPage.

public static void updateChapterPage(Context context, int cid, int pages) {
    ContentValues cv = new ContentValues();
    cv.put(COL_CAP_PAG_READ, pages);
    try {
        SQLiteDatabase database = getDatabase(context);
        if (!database.isReadOnly())
            database.update(TABLE_CHAPTERS, cv, COL_CAP_ID + "=" + Integer.toString(cid), null);
        else {
            Log.e("Database", "(updateChapterPage) " + 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 5 with SQLiteFullException

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

the class Database method updateChapter.

public static void updateChapter(Context context, Chapter chapter) {
    ContentValues cv = new ContentValues();
    cv.put(COL_CAP_NAME, chapter.getTitle());
    cv.put(COL_CAP_PATH, chapter.getPath());
    cv.put(COL_CAP_PAGES, chapter.getPages());
    cv.put(COL_CAP_STATE, chapter.getReadStatus());
    cv.put(COL_CAP_PAG_READ, chapter.getPagesRead());
    cv.put(COL_CAP_EXTRA, chapter.getExtra());
    try {
        SQLiteDatabase database = getDatabase(context);
        if (!database.isReadOnly())
            database.update(TABLE_CHAPTERS, cv, COL_CAP_ID + " = " + chapter.getId(), null);
        else {
            Log.e("Database", "(updateChapter) " + 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);
        outputChapterDebugInformation(chapter);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    } catch (SQLiteDiskIOException sqldioe) {
        Log.e("Database", "SQLiteDiskIOException", sqldioe);
        outputChapterDebugInformation(chapter);
        Util.getInstance().toast(context, context.getString(R.string.error_while_trying_to_update_db));
    } catch (Exception e) {
        Log.e("Database", "Exception", e);
        outputChapterDebugInformation(chapter);
        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