Stack Exchange
SQLite Adding Column With Default Value
I'm working in an Android SQLite DB. I'm upgrading it from version 1 to version 2.
The onUpgrade method is getting called as expected.
My code:
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");

I keep getting the same error:
Caused by: android.database.sqlite.SQLiteException: near "group": syntax error (code 1): , while compiling: ALTER TABLE DateActivities ADD group INTEGER DEFAULT 0

What am I doing wrong?
Other variations I have tried:
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD COLUMN " + Contracts.DateActivities.C_GROUP + " int DEFAULT 0;");
sqLiteDatabase.execSQL("ALTER TABLE " + Contracts.DateActivities.TABLE_NAME + " ADD " + Contracts.DateActivities.C_GROUP + " INTEGER DEFAULT 0;");


I suspect that Contracts.DateActivities.C_GROUP is "GROUP" (or "group" or "Group" or ... casing doesn't matter), which is a reserved keyword for SQLite... and can't be used for a column name

Oooh wow. I didn't realize that. I'll try a variation

That did it. If you write an answer with what you said in the comment I'll mark it as an answer

Sometimes you just have it under your nose, and you can't see it. It happens.

I suspect that Contracts.DateActivities.C_GROUP is "GROUP" (or "group" or "Group" or ... casing doesn't matter), which is a reserved keyword for SQLite... and can't be used for a column name

group can’t, but "group" can.

Why better? This says "A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility".

@SimonWright "Better" means "compatible", here. I started with VB6, VB#, so Access and SQL Server were my dayly bread. I still use square brackets because, for me, they are more readable.
