Code example for DatabaseUtils.InsertHelper

Methods: getColumnIndex

0
 
	@Override 
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if(oldVersion < 2) {
			// Add a few new consoles. 
			InsertHelper ih = new InsertHelper(db, "consoles");
			final int id = ih.getColumnIndex(_ID);
	        final int name = ih.getColumnIndex("console_name");
	        final int abbv = ih.getColumnIndex("console_abbv");	 
	         
	        ih.prepareForInsert(); ih.bind(id, 190); ih.bind(name, "Sord M5"); ih.bind(abbv, "Sord"); ih.execute();
	        ih.prepareForInsert(); ih.bind(id, 191); ih.bind(name, "Oric-1 / Atmos"); ih.bind(abbv, "Oric"); ih.execute();
	        ih.prepareForInsert(); ih.bind(id, 192); ih.bind(name, "Acorn Archimedes"); ih.bind(abbv, "Arch"); ih.execute();
	        ih.prepareForInsert(); ih.bind(id, 193); ih.bind(name, "Panasonic JR"); ih.bind(abbv, "JR"); ih.execute();
	        ih.prepareForInsert(); ih.bind(id, 194); ih.bind(name, "Steam"); ih.bind(abbv, "Steam"); ih.execute();
		} 
	} 
	 
	private void insertConsoles(SQLiteDatabase db) {
		// Create a single InsertHelper to handle this set of insertions. 
		InsertHelper ih = new InsertHelper(db, "consoles");