use of android.database.sqlite.SQLiteStatement in project squidb by yahoo.
the class SQLiteDatabaseAdapter method simpleQueryForLong.
@Override
public long simpleQueryForLong(String sql, Object[] bindArgs) {
SQLiteStatement statement = null;
try {
statement = db.compileStatement(sql);
SquidCursorFactory.bindArgumentsToProgram(statement, bindArgs);
return statement.simpleQueryForLong();
} finally {
if (statement != null) {
statement.close();
}
}
}
use of android.database.sqlite.SQLiteStatement in project XobotOS by xamarin.
the class WebViewDatabase method trimCache.
List<String> trimCache(long amount) {
ArrayList<String> pathList = new ArrayList<String>(100);
Cursor cursor = null;
final String query = "SELECT contentlength, filepath FROM cache ORDER BY expires ASC";
try {
cursor = mCacheDatabase.rawQuery(query, null);
if (cursor.moveToFirst()) {
int batchSize = 100;
StringBuilder pathStr = new StringBuilder(20 + 16 * batchSize);
pathStr.append("DELETE FROM cache WHERE filepath IN (?");
for (int i = 1; i < batchSize; i++) {
pathStr.append(", ?");
}
pathStr.append(")");
SQLiteStatement statement = null;
try {
statement = mCacheDatabase.compileStatement(pathStr.toString());
// as bindString() uses 1-based index, initialize index to 1
int index = 1;
do {
long length = cursor.getLong(0);
if (length == 0) {
continue;
}
amount -= length;
String filePath = cursor.getString(1);
statement.bindString(index, filePath);
pathList.add(filePath);
if (index++ == batchSize) {
statement.execute();
statement.clearBindings();
index = 1;
}
} while (cursor.moveToNext() && amount > 0);
if (index > 1) {
// there may be old bindings from the previous statement
// if index is less than batchSize, which is Ok.
statement.execute();
}
} catch (IllegalStateException e) {
Log.e(LOGTAG, "trimCache SQLiteStatement", e);
} finally {
if (statement != null)
statement.close();
}
}
} catch (IllegalStateException e) {
Log.e(LOGTAG, "trimCache Cursor", e);
} finally {
if (cursor != null)
cursor.close();
}
return pathList;
}
use of android.database.sqlite.SQLiteStatement in project xUtils3 by wyouflf.
the class DbManagerImpl method execNonQuery.
@Override
public void execNonQuery(SqlInfo sqlInfo) throws DbException {
SQLiteStatement statement = null;
try {
statement = sqlInfo.buildStatement(database);
statement.execute();
} catch (Throwable e) {
throw new DbException(e);
} finally {
if (statement != null) {
try {
statement.releaseReference();
} catch (Throwable ex) {
LogUtil.e(ex.getMessage(), ex);
}
}
}
}
use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by crdroidandroid.
the class DatabaseHelper method loadSystemSettings.
private void loadSystemSettings(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" + " VALUES(?,?);");
loadBooleanSetting(stmt, Settings.System.DIM_SCREEN, R.bool.def_dim_screen);
loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, R.integer.def_screen_off_timeout);
// Set default cdma DTMF type
loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
// Set default hearing aid
loadSetting(stmt, Settings.System.HEARING_AID, 0);
// Set default tty mode
loadSetting(stmt, Settings.System.TTY_MODE, 0);
loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS, R.integer.def_screen_brightness);
loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE, R.bool.def_screen_brightness_automatic_mode);
loadDefaultAnimationSettings(stmt);
loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION, R.bool.def_accelerometer_rotation);
loadDefaultHapticSettings(stmt);
loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE, R.bool.def_notification_pulse);
final boolean isShowPassword = mContext.getResources().getBoolean(R.bool.config_show_password_on);
if (isShowPassword) {
loadBooleanSetting(stmt, Settings.System.TEXT_SHOW_PASSWORD, R.bool.def_show_password_on);
}
loadUISoundEffectsSettings(stmt);
loadIntegerSetting(stmt, Settings.System.POINTER_SPEED, R.integer.def_pointer_speed);
/*
* IMPORTANT: Do not add any more upgrade steps here as the global,
* secure, and system settings are no longer stored in a database
* but are kept in memory and persisted to XML.
*
* See: SettingsProvider.UpgradeController#onUpgradeLocked
*/
} finally {
if (stmt != null)
stmt.close();
}
}
use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by crdroidandroid.
the class DatabaseHelper method movePrefixedSettingsToNewTable.
/**
* Move any settings with the given prefixes from the source table to the
* destination table.
*/
private void movePrefixedSettingsToNewTable(SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
SQLiteStatement insertStmt = null;
SQLiteStatement deleteStmt = null;
db.beginTransaction();
try {
insertStmt = db.compileStatement("INSERT INTO " + destTable + " (name,value) SELECT name,value FROM " + sourceTable + " WHERE substr(name,0,?)=?");
deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?");
for (String prefix : prefixesToMove) {
insertStmt.bindLong(1, prefix.length() + 1);
insertStmt.bindString(2, prefix);
insertStmt.execute();
deleteStmt.bindLong(1, prefix.length() + 1);
deleteStmt.bindString(2, prefix);
deleteStmt.execute();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (insertStmt != null) {
insertStmt.close();
}
if (deleteStmt != null) {
deleteStmt.close();
}
}
}
Aggregations