0

I have a code which called when new database version will be installed on device.

    if (oldVersion < 8) {
        try {
            sqLiteDatabase.execSQL("ALTER TABLE `" + Category.controllerName + "` ADD COLUMN " + Category.TYPE + " TEXT");
        } catch (SQLiteException e) {

        }
    }

I suppose this will be created a new Column with name type.
How i can fill this column with default value -1 for example?
And also... how i need support database update correctly? Any links will be appericated.

Sergey Shustikov
  • 15,377
  • 12
  • 67
  • 119
  • possible duplicate of [Add a column, with a default value, to an existing table in SQL Server](http://stackoverflow.com/questions/92082/add-a-column-with-a-default-value-to-an-existing-table-in-sql-server) – tachyonflux Jul 13 '15 at 20:17
  • http://www.sqlite.org/lang_altertable.html – Sam Cohen-Devries Jul 13 '15 at 20:20

1 Answers1

0

You need to add a default value like this:

        sqLiteDatabase.execSQL("ALTER TABLE `" + Category.controllerName + "` ADD COLUMN " + Category.TYPE + " TEXT DEFAULT -1");

More on Alter table :https://www.sqlite.org/lang_altertable.html

isma3l
  • 3,833
  • 1
  • 22
  • 28