android sqlite add column if not exists

Solutions on MaxInterview for android sqlite add column if not exists by the best coders in the world

showing results for - "android sqlite add column if not exists"
Estelle
06 Mar 2017
1Cursor cursor = database.rawQuery("SELECT * FROM MY_TABLE", null); // grab cursor for all data
2int deleteStateColumnIndex = cursor.getColumnIndex("MISSING_COLUMN");  // see if the column is there
3if (deleteStateColumnIndex < 0) { 
4    // missing_column not there - add it
5    database.execSQL("ALTER TABLE MY_TABLE ADD COLUMN MISSING_COLUMN int null;");
6}