use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by AOSPA.
the class DatabaseHelper method moveSettingsToNewTable.
private void moveSettingsToNewTable(SQLiteDatabase db, String sourceTable, String destTable, String[] settingsToMove, boolean doIgnore) {
// Copy settings values from the source table to the dest, and remove from the source
SQLiteStatement insertStmt = null;
SQLiteStatement deleteStmt = null;
db.beginTransaction();
try {
insertStmt = db.compileStatement("INSERT " + (doIgnore ? " OR IGNORE " : "") + " INTO " + destTable + " (name,value) SELECT name,value FROM " + sourceTable + " WHERE name=?");
deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?");
for (String setting : settingsToMove) {
insertStmt.bindString(1, setting);
insertStmt.execute();
deleteStmt.bindString(1, setting);
deleteStmt.execute();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (insertStmt != null) {
insertStmt.close();
}
if (deleteStmt != null) {
deleteStmt.close();
}
}
}
use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by AOSPA.
the class DatabaseHelper method loadVibrateWhenRingingSetting.
private void loadVibrateWhenRingingSetting(SQLiteDatabase db) {
// The default should be off. VIBRATE_SETTING_ONLY_SILENT should also be ignored here.
// Phone app should separately check whether AudioManager#getRingerMode() returns
// RINGER_MODE_VIBRATE, with which the device should vibrate anyway.
int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, AudioManager.VIBRATE_SETTING_OFF);
boolean vibrateWhenRinging = ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_ON);
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" + " VALUES(?,?);");
loadSetting(stmt, Settings.System.VIBRATE_WHEN_RINGING, vibrateWhenRinging ? 1 : 0);
} finally {
if (stmt != null)
stmt.close();
}
}
use of android.database.sqlite.SQLiteStatement in project weex-example by KalicyZhou.
the class DefaultWXStorage method performGetLength.
private long performGetLength() {
SQLiteDatabase database = mDatabaseSupplier.getDatabase();
if (database == null) {
return 0;
}
String sql = "SELECT count(" + WXSQLiteOpenHelper.COLUMN_KEY + ") FROM " + WXSQLiteOpenHelper.TABLE_STORAGE;
SQLiteStatement statement = null;
try {
statement = database.compileStatement(sql);
return statement.simpleQueryForLong();
} catch (Exception e) {
WXLogUtils.e(WXSQLiteOpenHelper.TAG_STORAGE, "DefaultWXStorage occurred an exception when execute getLength:" + e.getMessage());
return 0;
} finally {
if (statement != null) {
statement.close();
}
}
}
use of android.database.sqlite.SQLiteStatement 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.SQLiteStatement in project 360-Engine-for-Android by 360.
the class DatabaseHelper method fetchContactByServerId.
/**
* Fetches a contact, given a server Id.
*
* @param contactServerId The server ID of the contact to fetch
* @param contact An empty Contact object which will be filled with the data
* @return SUCCESS or a suitable error code
* @see #modifyContactServerId(long, Long, Long)
* @see #fetchServerId(long)
*/
public ServiceStatus fetchContactByServerId(Long contactServerId, Contact contact) {
final SQLiteStatement statement = ContactsTable.fetchLocalFromServerIdStatement(getReadableDatabase());
Long localId = ContactsTable.fetchLocalFromServerId(contactServerId, statement);
if (localId == null) {
return ServiceStatus.ERROR_NOT_FOUND;
}
if (statement != null) {
statement.close();
}
return fetchContact(localId, contact);
}
Aggregations