Code example for DatabaseUtils.InsertHelper

Methods: getColumnIndex

0
		onCreate(db);
	} 
 
	private void insertConsoles(SQLiteDatabase db) {
		// Create a single InsertHelper to handle this set of insertions. 
        InsertHelper ih = new InsertHelper(db, "consoles");
         
        // Get the numeric indexes for each of the columns that we're updating. 
        final int nameColumn = ih.getColumnIndex("console_name");
        final int aliasColumn = ih.getColumnIndex("console_alias");
        final int categoryColumn = ih.getColumnIndex("category");
         
        // Insert Nintendo consoles. 
        ih.prepareForInsert();
        ih.bind(nameColumn, "Nintendo NES"); ih.bind(aliasColumn, "nes"); ih.bind(categoryColumn, 1);
         
        ih.execute(); ih.prepareForInsert();
        ih.bind(nameColumn, "Super Nintendo"); ih.bind(aliasColumn, "super-nintendo"); ih.bind(categoryColumn, 1);
         
        ih.execute(); ih.prepareForInsert();
        ih.bind(nameColumn, "Nintendo 64"); ih.bind(aliasColumn, "nintendo-64"); ih.bind(categoryColumn, 1);