I want to add one column in existing table so i wrote the below query in onUpgrade
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String addMeasureJsonQuery = "ALTER TABLE " + SqlCard.TOOTEET_TABLE + " ADD COLUMN " + Columns.Tooteet.MEASURE_JSON + " TEXT";
if (oldVersion == 1 && newVersion == 2){
db.execSQL(addMeasureJsonQuery);
}
Also updated database version as 2. But my app get crashed with the below error
FATAL EXCEPTION: Thread-1516 Process: MyPackageName, PID: 2117
android.database.sqlite.SQLiteException: near "CREATE": syntax error (code 1): , while compiling: ALTER TABLE CREATE TABLE IF NOT EXISTS tooteets (id TEXT, text TEXT, file_url_1 TEXT, file_url_2 TEXT, thumb_url_1 TEXT, thumb_url_2 TEXT, color TEXT, local_parent_folder TEXT, unique_file_name TEXT, unique_thumbnail_name TEXT, keywords TEXT, created_user_name TEXT, updated_user_name TEXT, is_favorite INTEGER DEFAULT 0, is_tooti_author INTEGER DEFAULT 1, tweet_type INTEGER, rating INTEGER DEFAULT 0, weather_type INTEGER DEFAULT 0, latitude DOUBLE DEFAULT 0.0, longitude DOUBLE DEFAULT 0.0, group_key TEXT, tweet_date INTEGER, group_sort_order INTEGER, no_of_unread_tooteets INTEGER DEFAULT 0, no_of_comments INTEGER DEFAULT 0, no_of_unread_comments INTEGER DEFAULT 0, lane_id TEXT, lane_name TEXT, expense_json TEXT, is_synced INTEGER DEFAULT 0, is_update INTEGER DEFAULT 0, is_deleted INTEGER DEFAULT 0) ADD COLUMN measure_json TEXT
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:690)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1806)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1737)
at MyPackageName.database.DBSQLite.onUpgrade(DBSQLite.java:80)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:257)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at MyPackageName.database.DBSQLite.getDatabase(DBSQLite.java:56)
at MyPackageName.MyApplicationClass$1.run(MyApplicationClass.java:68)
at java.lang.Thread.run(Thread.java:841)
Could you please suggest me an idea to solve this problem? Thanks in Advance...
Aucun commentaire:
Enregistrer un commentaire