Code example for SQLiteDatabase

Methods: insertOrThrowrawQuery

0
        String stringColumnValue = "column_value";
        byte[] byteColumnValue = new byte[]{1, 2, 3};
        ContentValues values = new ContentValues();
        values.put("first_column", stringColumnValue);
        values.put("second_column", byteColumnValue);
        database.insertOrThrow("table_name", null, values);
         
        Cursor cursor = database.rawQuery("select second_column, first_column from table_name", null);
        assertThat(cursor.moveToFirst()).isTrue();
        byte[] byteValueFromDatabase = cursor.getBlob(0);
        String stringValueFromDatabase = cursor.getString(1);
        assertThat(stringValueFromDatabase).isEqualTo(stringColumnValue);
        assertThat(byteValueFromDatabase).isEqualTo(byteColumnValue);
    } 
 
    @Test(expected = IllegalArgumentException.class) 
    public void testRawQueryThrowsIndex0NullException() throws Exception { 
        database.rawQuery("select second_column, first_column from rawtable WHERE `id` = ?", new String[]{null});
    } 
 
Stop searching for code, let great code find you!  Add Codota to your java IDE