Search in sources :

Example 6 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ParanoidAndroid.

the class DatabaseStatementTest method testExecuteStatement.

@MediumTest
public void testExecuteStatement() throws Exception {
    populateDefaultTable();
    SQLiteStatement statement = mDatabase.compileStatement("DELETE FROM test");
    statement.execute();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    assertEquals(0, c.getCount());
    c.deactivate();
    statement.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 7 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ParanoidAndroid.

the class DatabaseStatementTest method testStatementMultiThreaded.

@MediumTest
public void testStatementMultiThreaded() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER, str TEXT);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num, str) VALUES (?, ?)");
    StatementTestThread thread = new StatementTestThread(mDatabase, statement);
    thread.start();
    try {
        thread.join();
    } finally {
        statement.close();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 8 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ParanoidAndroid.

the class DatabaseStatementTest method testStatementClearBindings.

@MediumTest
public void testStatementClearBindings() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
    for (long i = 0; i < 10; i++) {
        statement.bindLong(1, i);
        statement.clearBindings();
        statement.execute();
    }
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, "ROWID");
    int numCol = c.getColumnIndexOrThrow("num");
    assertTrue(c.moveToFirst());
    for (long i = 0; i < 10; i++) {
        assertTrue(c.isNull(numCol));
        c.moveToNext();
    }
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 9 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ParanoidAndroid.

the class DatabaseHelper method upgradeScreenTimeoutFromNever.

private void upgradeScreenTimeoutFromNever(SQLiteDatabase db) {
    // See if the timeout is -1 (for "Never").
    Cursor c = db.query(TABLE_SYSTEM, new String[] { "_id", "value" }, "name=? AND value=?", new String[] { Settings.System.SCREEN_OFF_TIMEOUT, "-1" }, null, null, null);
    SQLiteStatement stmt = null;
    if (c.getCount() > 0) {
        c.close();
        try {
            stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" + " VALUES(?,?);");
            // Set the timeout to 30 minutes in milliseconds
            loadSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, Integer.toString(30 * 60 * 1000));
        } finally {
            if (stmt != null)
                stmt.close();
        }
    } else {
        c.close();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor)

Example 10 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ParanoidAndroid.

the class DatabaseHelper method loadSecureSettings.

private void loadSecureSettings(SQLiteDatabase db) {
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" + " VALUES(?,?);");
        loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED, R.string.def_location_providers_allowed);
        String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
        if (!TextUtils.isEmpty(wifiWatchList)) {
            loadSetting(stmt, Settings.Secure.WIFI_WATCHDOG_WATCH_LIST, wifiWatchList);
        }
        // Don't do this.  The SystemServer will initialize ADB_ENABLED from a
        // persistent system property instead.
        //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
        // Allow mock locations default, based on build
        loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION, "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
        loadSecure35Settings(stmt);
        loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND, R.bool.def_mount_play_notification_snd);
        loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART, R.bool.def_mount_ums_autostart);
        loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT, R.bool.def_mount_ums_prompt);
        loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED, R.bool.def_mount_ums_notify_enabled);
        loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SCRIPT_INJECTION, R.bool.def_accessibility_script_injection);
        loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS, R.string.def_accessibility_web_content_key_bindings);
        loadIntegerSetting(stmt, Settings.Secure.LONG_PRESS_TIMEOUT, R.integer.def_long_press_timeout_millis);
        loadBooleanSetting(stmt, Settings.Secure.TOUCH_EXPLORATION_ENABLED, R.bool.def_touch_exploration_enabled);
        loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_SPEAK_PASSWORD, R.bool.def_accessibility_speak_password);
        loadStringSetting(stmt, Settings.Secure.ACCESSIBILITY_SCREEN_READER_URL, R.string.def_accessibility_screen_reader_url);
        if (SystemProperties.getBoolean("ro.lockscreen.disable.default", false) == true) {
            loadSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, "1");
        } else {
            loadBooleanSetting(stmt, Settings.System.LOCKSCREEN_DISABLED, R.bool.def_lockscreen_disabled);
        }
        loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ENABLED, com.android.internal.R.bool.config_dreamsEnabledByDefault);
        loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_DOCK, com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault);
        loadBooleanSetting(stmt, Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault);
        loadStringSetting(stmt, Settings.Secure.SCREENSAVER_COMPONENTS, com.android.internal.R.string.config_dreamsDefaultComponent);
        loadStringSetting(stmt, Settings.Secure.SCREENSAVER_DEFAULT_COMPONENT, com.android.internal.R.string.config_dreamsDefaultComponent);
        loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, R.bool.def_accessibility_display_magnification_enabled);
        loadFractionSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, R.fraction.def_accessibility_display_magnification_scale, 1);
        loadBooleanSetting(stmt, Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_AUTO_UPDATE, R.bool.def_accessibility_display_magnification_auto_update);
        loadBooleanSetting(stmt, Settings.Secure.USER_SETUP_COMPLETE, R.bool.def_user_setup_complete);
        loadIntegerSetting(stmt, Settings.Secure.DIALPAD_AUTOCOMPLETE, R.integer.def_dialpad_autocomplete);
    } finally {
        if (stmt != null)
            stmt.close();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Aggregations

SQLiteStatement (android.database.sqlite.SQLiteStatement)249 Cursor (android.database.Cursor)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)49 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 SQLException (android.database.SQLException)21 Test (org.junit.Test)20 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 Timing (com.newsrob.util.Timing)3 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)3 IOException (java.io.IOException)3 ContentValues (android.content.ContentValues)2 VisibleForTesting (android.support.annotation.VisibleForTesting)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2