Search in sources :

Example 66 with SQLiteStatement

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

Example 67 with SQLiteStatement

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

Example 68 with SQLiteStatement

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

Example 69 with SQLiteStatement

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

Example 70 with SQLiteStatement

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

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