use of android.database.sqlite.SQLiteStatement in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
the class DatabaseHelper method upgradeVibrateSettingFromNone.
private void upgradeVibrateSettingFromNone(SQLiteDatabase db) {
int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, 0);
// If the ringer vibrate value is invalid, set it to the default
if ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_OFF) {
vibrateSetting = AudioSystem.getValueForVibrateSetting(0, AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
}
// Apply the same setting to the notification vibrate value
vibrateSetting = AudioSystem.getValueForVibrateSetting(vibrateSetting, AudioManager.VIBRATE_TYPE_NOTIFICATION, vibrateSetting);
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" + " VALUES(?,?);");
loadSetting(stmt, Settings.System.VIBRATE_ON, vibrateSetting);
} finally {
if (stmt != null)
stmt.close();
}
}
use of android.database.sqlite.SQLiteStatement in project greenDAO by greenrobot.
the class AbstractDao method insertInsideTx.
private long insertInsideTx(T entity, DatabaseStatement stmt) {
synchronized (stmt) {
if (isStandardSQLite) {
SQLiteStatement rawStmt = (SQLiteStatement) stmt.getRawStatement();
bindValues(rawStmt, entity);
return rawStmt.executeInsert();
} else {
bindValues(stmt, entity);
return stmt.executeInsert();
}
}
}
use of android.database.sqlite.SQLiteStatement in project greenDAO by greenrobot.
the class AbstractDao method executeInsertInTx.
private void executeInsertInTx(DatabaseStatement stmt, Iterable<T> entities, boolean setPrimaryKey) {
db.beginTransaction();
try {
synchronized (stmt) {
if (identityScope != null) {
identityScope.lock();
}
try {
if (isStandardSQLite) {
SQLiteStatement rawStmt = (SQLiteStatement) stmt.getRawStatement();
for (T entity : entities) {
bindValues(rawStmt, entity);
if (setPrimaryKey) {
long rowId = rawStmt.executeInsert();
updateKeyAfterInsertAndAttach(entity, rowId, false);
} else {
rawStmt.execute();
}
}
} else {
for (T entity : entities) {
bindValues(stmt, entity);
if (setPrimaryKey) {
long rowId = stmt.executeInsert();
updateKeyAfterInsertAndAttach(entity, rowId, false);
} else {
stmt.execute();
}
}
}
} finally {
if (identityScope != null) {
identityScope.unlock();
}
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
use of android.database.sqlite.SQLiteStatement in project newsrob by marianokamp.
the class DB method populateTempIds.
public void populateTempIds(TempTable tempTableType, long[] articleIds) {
SQLiteDatabase dbase = getDb();
final String createTableDDL = expandTempTableName(CREATE_TABLE_TEMP_IDS_SQL, tempTableType);
PL.log("Executing sql=" + createTableDDL, context);
dbase.execSQL(createTableDDL);
clearTempTable(tempTableType);
Timing t = new Timing("DB.populateTempIds " + tempTableType + " count=" + articleIds.length, context);
PL.log("DB.populateTempIds(" + tempTableType + "): number of article ids=" + articleIds.length, context);
// offset points at the current element, 0 meaning the first element
int offset = 0;
while (offset < articleIds.length) {
int nextPackSize = Math.min(articleIds.length - offset, 30);
// if (nextPackSize == 0)
// break;
SQLiteStatement stmt = null;
try {
dbase.beginTransaction();
stmt = dbase.compileStatement(expandTempTableName("INSERT INTO temp_ids values(?);", tempTableType));
for (int j = offset; j < offset + nextPackSize && j < articleIds.length; j++) {
long l = articleIds[j];
// "tag:google.com,2005:reader/item/"
String id = EntriesRetriever.TAG_GR_ITEM + U.longToHex(l);
stmt.bindString(1, id);
stmt.execute();
}
offset += nextPackSize;
} finally {
if (stmt != null)
stmt.close();
dbase.setTransactionSuccessful();
dbase.endTransaction();
}
Thread.yield();
}
t.stop();
}
Aggregations