Reputation: 189
I want to add a column to a table in case the column doesn't exist,but SQLite doesn't seem to update the column list in Android
currently i'm using:
DB.execSQL("alter table "+table_name+" add column "+column_name+" text");
DB.rawQuery("select * from "+table_name+" limit 1",null).getColumnNames();
but the string list returned from "getColumnNames" does not contain the column I just created, so when I check again for the same column, it understands the column doesn't exist and tries to create it again, which causes a "duplicated column" exception
Thanks in advance for any help,this is my first question in SO :)
Upvotes: 2
Views: 852
Reputation: 311
Try to discard the result of the first query after the "alter table" command and use the result of a second query. It worked for me.
Upvotes: 0