Code example for SQLiteDatabase

Methods: beginTransactionendTransactionexecSQLsetTransactionSuccessful

0
    } 
 
    @Test 
    public void testFailureNestedTransaction() throws Exception { 
        assertThat(shDatabase.isTransactionSuccess()).isFalse();
        database.beginTransaction();
        assertThat(shDatabase.isTransactionSuccess()).isFalse();
        database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');");
        database.beginTransaction();
        assertThat(shDatabase.isTransactionSuccess()).isFalse();
        database.execSQL("INSERT INTO table_name (id, name) VALUES(12345, 'Julie');");
        database.endTransaction();
        assertThat(shDatabase.isTransactionSuccess()).isFalse();
        database.setTransactionSuccessful();
        assertThat(shDatabase.isTransactionSuccess()).isFalse();
        database.endTransaction();
        assertThat(shDatabase.isTransactionSuccess()).isFalse();
        Statement statement = shadowOf(database).getConnection().createStatement();
        ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM table_name");
        assertThat(resultSet.next()).isTrue();
        assertThat(resultSet.getInt(1)).isEqualTo(0);