Code example for SQLiteDatabase

Methods: execSQLinsert

0
    protected ShadowSQLiteDatabase shDatabase;
 
    @Before 
    public void setUp() throws Exception { 
        database = SQLiteDatabase.openDatabase("path", null, 0);
        shDatabase = Robolectric.shadowOf(database);
        database.execSQL("CREATE TABLE table_name (\n" +
                "  id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + 
                "  first_column VARCHAR(255),\n" + 
                "  second_column BINARY,\n" + 
                "  name VARCHAR(255),\n" + 
                "  big_int INTEGER\n" + 
                ");"); 
 
        database.execSQL("CREATE TABLE rawtable (\n" +
                "  id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + 
                "  first_column VARCHAR(255),\n" + 
                "  second_column BINARY,\n" + 
                "  name VARCHAR(255),\n" + 
                "  big_int INTEGER\n" + 
                ");"); 
 
        database.execSQL("CREATE TABLE exectable (\n" +
                "  id INTEGER PRIMARY KEY AUTOINCREMENT,\n" + 
                "  first_column VARCHAR(255),\n" + 
                "  second_column BINARY,\n" + 
                "  name VARCHAR(255),\n" + 
                "  big_int INTEGER\n" + 
                ");"); 
 
        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.insert("rawtable", null, values);
        //////////////////////////////////////////////// 
        String stringColumnValue2 = "column_value2";
        byte[] byteColumnValue2 = new byte[]{4, 5, 6};
        ContentValues values2 = new ContentValues();
 
        values2.put("first_column", stringColumnValue2);
        values2.put("second_column", byteColumnValue2);
 
        database.insert("rawtable", null, values2);
    } 
 
 
    @After 
    public void tearDown() throws Exception {