Search in sources :

Example 71 with SQLiteStatement

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

the class BriteDatabaseTest method executeUpdateDeleteAndTriggerWithMultipleTables.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteAndTriggerWithMultipleTables() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.NAME + " = 'Zach'");
    final RecordingObserver managerObserver = new RecordingObserver();
    db.createQuery(TABLE_MANAGER, SELECT_MANAGER_LIST).subscribe(managerObserver);
    managerObserver.assertCursor().hasRow("Eve Evenson", "Alice Allison").isExhausted();
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
    o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
    final Set<String> employeeAndManagerTables = Collections.unmodifiableSet(new HashSet<>(BOTH_TABLES));
    db.executeUpdateDelete(employeeAndManagerTables, statement);
    o.assertCursor().hasRow("alice", "Zach").hasRow("bob", "Zach").hasRow("eve", "Zach").isExhausted();
    managerObserver.assertCursor().hasRow("Zach", "Zach").isExhausted();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 72 with SQLiteStatement

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

the class BriteDatabaseTest method executeInsertAndDontTrigger.

@Test
public void executeInsertAndDontTrigger() {
    SQLiteStatement statement = real.compileStatement("INSERT OR IGNORE INTO " + TABLE_EMPLOYEE + " (" + TestDb.EmployeeTable.NAME + ", " + TestDb.EmployeeTable.USERNAME + ") " + "VALUES ('Alice Allison', 'alice')");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
    o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
    db.executeInsert(TABLE_EMPLOYEE, statement);
    o.assertNoMoreEvents();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Test(org.junit.Test)

Example 73 with SQLiteStatement

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

the class BriteDatabaseTest method executeInsertThrowsAndDoesNotTrigger.

@Test
public void executeInsertThrowsAndDoesNotTrigger() {
    SQLiteStatement statement = real.compileStatement("INSERT INTO " + TABLE_EMPLOYEE + " (" + TestDb.EmployeeTable.NAME + ", " + TestDb.EmployeeTable.USERNAME + ") " + "VALUES ('Alice Allison', 'alice')");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).skip(// Skip initial
    1).subscribe(o);
    try {
        db.executeInsert(TABLE_EMPLOYEE, statement);
        fail();
    } catch (SQLException ignored) {
    }
    o.assertNoMoreEvents();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException) Test(org.junit.Test)

Example 74 with SQLiteStatement

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

the class BriteDatabaseTest method executeUpdateDeleteThrowsAndDoesNotTrigger.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteThrowsAndDoesNotTrigger() {
    SQLiteStatement statement = real.compileStatement("UPDATE " + TABLE_EMPLOYEE + " SET " + TestDb.EmployeeTable.USERNAME + " = 'alice'");
    db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).skip(// Skip initial
    1).subscribe(o);
    try {
        db.executeUpdateDelete(TABLE_EMPLOYEE, statement);
        fail();
    } catch (SQLException ignored) {
    }
    o.assertNoMoreEvents();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

Example 75 with SQLiteStatement

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

the class BriteDatabaseTest method executeUpdateDeleteAndTriggerWithNoTables.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void executeUpdateDeleteAndTriggerWithNoTables() {
    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(Collections.<String>emptySet(), statement);
    o.assertNoMoreEvents();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Test(org.junit.Test) SdkSuppress(android.support.test.filters.SdkSuppress) TargetApi(android.annotation.TargetApi)

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