Search in sources :

Example 76 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project sqlbrite by square.

the class BriteDatabaseTest method executeUpdateDeleteAndTrigger.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteAndTrigger() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.NAME + " = 'Zach'");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
    o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
    db.executeUpdateDelete(TABLE_EMPLOYEE, statement);
    o.assertCursor().hasRow("alice", "Zach").hasRow("bob", "Zach").hasRow("eve", "Zach").isExhausted();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 77 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project sqlbrite by square.

the class BriteDatabaseTest method executeUpdateDeleteWithArgsAndTrigger.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteWithArgsAndTrigger() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.NAME + " = ?");
    statement.bindString(1, "Zach");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
    o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
    db.executeUpdateDelete(TABLE_EMPLOYEE, statement);
    o.assertCursor().hasRow("alice", "Zach").hasRow("bob", "Zach").hasRow("eve", "Zach").isExhausted();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 78 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project xUtils3 by wyouflf.

the class SqlInfo method buildStatement.

public SQLiteStatement buildStatement(SQLiteDatabase database) {
    SQLiteStatement result = database.compileStatement(sql);
    if (bindArgs != null) {
        for (int i = 1; i < bindArgs.size() + 1; i++) {
            KeyValue kv = bindArgs.get(i - 1);
            Object value = ColumnUtils.convert2DbValueIfNeeded(kv.value);
            if (value == null) {
                result.bindNull(i);
            } else {
                ColumnConverter converter = ColumnConverterFactory.getColumnConverter(value.getClass());
                ColumnDbType type = converter.getColumnDbType();
                switch(type) {
                    case INTEGER:
                        result.bindLong(i, ((Number) value).longValue());
                        break;
                    case REAL:
                        result.bindDouble(i, ((Number) value).doubleValue());
                        break;
                    case TEXT:
                        result.bindString(i, value.toString());
                        break;
                    case BLOB:
                        result.bindBlob(i, (byte[]) value);
                        break;
                    default:
                        result.bindNull(i);
                        break;
                }
            // end switch
            }
        }
    }
    return result;
}
Also used : KeyValue(org.xutils.common.util.KeyValue) SQLiteStatement(android.database.sqlite.SQLiteStatement) ColumnConverter(org.xutils.db.converter.ColumnConverter)

Example 79 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project squidb by yahoo.

the class SQLiteDatabaseAdapter method executeInsert.

@Override
public long executeInsert(String sql, Object[] bindArgs) {
    SQLiteStatement statement = null;
    try {
        statement = db.compileStatement(sql);
        SquidCursorFactory.bindArgumentsToProgram(statement, bindArgs);
        return statement.executeInsert();
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 80 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project squidb by yahoo.

the class SQLiteDatabaseAdapter method executeUpdateDelete.

@Override
public int executeUpdateDelete(String sql, Object[] bindArgs) {
    SQLiteStatement statement = null;
    try {
        statement = db.compileStatement(sql);
        SquidCursorFactory.bindArgumentsToProgram(statement, bindArgs);
        return statement.executeUpdateDelete();
    } finally {
        if (statement != null) {
            statement.close();
        }
    }
}
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