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();
}
}
}
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();
}
}
}
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));
}
}
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));
}
}
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));
}
}
Aggregations