Search in sources :

Example 91 with SQLiteStatement

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

the class DatabaseStatementTest method testSimpleQuery.

@MediumTest
public void testSimpleQuery() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER NOT NULL, str TEXT NOT NULL);");
    mDatabase.execSQL("INSERT INTO test VALUES (1234, 'hello');");
    SQLiteStatement statement1 = mDatabase.compileStatement("SELECT num FROM test WHERE str = ?");
    SQLiteStatement statement2 = mDatabase.compileStatement("SELECT str FROM test WHERE num = ?");
    try {
        statement1.bindString(1, "hello");
        long value = statement1.simpleQueryForLong();
        assertEquals(1234, value);
        statement1.bindString(1, "world");
        statement1.simpleQueryForLong();
        fail("shouldn't get here");
    } catch (SQLiteDoneException e) {
    // expected
    }
    try {
        statement2.bindLong(1, 1234);
        String value = statement1.simpleQueryForString();
        assertEquals("hello", value);
        statement2.bindLong(1, 5678);
        statement1.simpleQueryForString();
        fail("shouldn't get here");
    } catch (SQLiteDoneException e) {
    // expected
    }
    statement1.close();
    statement2.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLiteDoneException(android.database.sqlite.SQLiteDoneException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 92 with SQLiteStatement

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

the class DatabaseStatementTest method testStatementLongBinding.

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

Example 93 with SQLiteStatement

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

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 94 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android-priority-jobqueue by path.

the class SqliteJobQueue method insert.

/**
 * {@inheritDoc}
 */
@Override
public long insert(JobHolder jobHolder) {
    SQLiteStatement stmt = sqlHelper.getInsertStatement();
    long id;
    synchronized (stmt) {
        stmt.clearBindings();
        bindValues(stmt, jobHolder);
        id = stmt.executeInsert();
    }
    jobHolder.setId(id);
    return id;
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 95 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android-priority-jobqueue by path.

the class SqliteJobQueue method count.

/**
 * {@inheritDoc}
 */
@Override
public int count() {
    SQLiteStatement stmt = sqlHelper.getCountStatement();
    synchronized (stmt) {
        stmt.clearBindings();
        stmt.bindLong(1, sessionId);
        return (int) stmt.simpleQueryForLong();
    }
}
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