Search in sources :

Example 96 with SQLiteStatement

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();
        }
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 97 with SQLiteStatement

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();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 98 with SQLiteStatement

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();
        }
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLiteFullException(android.database.sqlite.SQLiteFullException)

Example 99 with SQLiteStatement

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();
        }
    }
}
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 100 with SQLiteStatement

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);
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Aggregations

SQLiteStatement (android.database.sqlite.SQLiteStatement)252 Cursor (android.database.Cursor)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)49 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 Test (org.junit.Test)22 SQLException (android.database.SQLException)21 Date (java.util.Date)12 TargetApi (android.annotation.TargetApi)8 SQLiteDoneException (android.database.sqlite.SQLiteDoneException)8 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)7 SdkSuppress (android.support.test.filters.SdkSuppress)7 ArrayList (java.util.ArrayList)5 SQLiteException (android.database.sqlite.SQLiteException)4 SQLiteFullException (android.database.sqlite.SQLiteFullException)4 SQLException (java.sql.SQLException)4 Timing (com.newsrob.util.Timing)3 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)3 IOException (java.io.IOException)3 Savepoint (java.sql.Savepoint)3 ContentValues (android.content.ContentValues)2