Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

android sqlite add column if not exists

Cursor cursor = database.rawQuery("SELECT * FROM MY_TABLE", null); // grab cursor for all data
int deleteStateColumnIndex = cursor.getColumnIndex("MISSING_COLUMN");  // see if the column is there
if (deleteStateColumnIndex < 0) { 
    // missing_column not there - add it
    database.execSQL("ALTER TABLE MY_TABLE ADD COLUMN MISSING_COLUMN int null;");
}
 
PREVIOUS NEXT
Tagged: #android #sqlite #add #column #exists
ADD COMMENT
Topic
Name
7+9 =