| Chunk |
|---|
| Conflicting content |
|---|
// Note: if you update the version number, you must also update the code
// in upgradeDatabase() to modify the database (gracefully, if possible).
<<<<<<< HEAD
// Versions under 100 cover through Froyo, 1xx version are for Gingerbread,
// 2xx for Honeycomb, and 3xx for ICS. For future versions bump this to the
// next hundred at each major release.
static final int DATABASE_VERSION = 307;
=======
static final int DATABASE_VERSION = 206;
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
private static final int PRE_FROYO_SYNC_STATE_VERSION = 3;
|
| Solution content |
|---|
// Note: if you update the version number, you must also update the code
// in upgradeDatabase() to modify the database (gracefully, if possible).
// Versions under 100 cover through Froyo, 1xx version are for Gingerbread,
// 2xx for Honeycomb, and 3xx for ICS. For future versions bump this to the
// next hundred at each major release.
static final int DATABASE_VERSION = 307;
private static final int PRE_FROYO_SYNC_STATE_VERSION = 3;
|
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Attribute |
| Comment |
| Chunk |
|---|
| Conflicting content |
|---|
AFTER_EVENT_INSERT_SQL +
"END");
createCalendarsTable(db);
<<<<<<< HEAD
createEventsTable(db);
=======
// TODO: do we need both dtend and duration?
db.execSQL("CREATE TABLE " + Tables.EVENTS + " (" +
Calendar.Events._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
Calendar.Events._SYNC_ACCOUNT + " TEXT," +
Calendar.Events._SYNC_ACCOUNT_TYPE + " TEXT," +
Calendar.Events._SYNC_ID + " TEXT," +
Calendar.Events._SYNC_VERSION + " TEXT," +
// sync time in UTC
Calendar.Events._SYNC_TIME + " TEXT," +
Calendar.Events._SYNC_DATA + " INTEGER," +
Calendar.Events._SYNC_DIRTY + " INTEGER," +
// sync mark to filter out new rows
Calendar.Events._SYNC_MARK + " INTEGER," +
Calendar.Events.CALENDAR_ID + " INTEGER NOT NULL," +
Calendar.Events.HTML_URI + " TEXT," +
Calendar.Events.TITLE + " TEXT," +
Calendar.Events.EVENT_LOCATION + " TEXT," +
Calendar.Events.DESCRIPTION + " TEXT," +
Calendar.Events.STATUS + " INTEGER," +
Calendar.Events.SELF_ATTENDEE_STATUS + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.COMMENTS_URI + " TEXT," +
// dtstart in millis since epoch
Calendar.Events.DTSTART + " INTEGER," +
// dtend in millis since epoch
Calendar.Events.DTEND + " INTEGER," +
// timezone for event
Calendar.Events.EVENT_TIMEZONE + " TEXT," +
Calendar.Events.DURATION + " TEXT," +
Calendar.Events.ALL_DAY + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.VISIBILITY + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.TRANSPARENCY + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.HAS_ALARM + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.HAS_EXTENDED_PROPERTIES + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.RRULE + " TEXT," +
Calendar.Events.RDATE + " TEXT," +
Calendar.Events.EXRULE + " TEXT," +
Calendar.Events.EXDATE + " TEXT," +
// originalEvent is the _sync_id of recurring event
Calendar.Events.ORIGINAL_EVENT + " TEXT," +
// originalInstanceTime is in millis since epoch
Calendar.Events.ORIGINAL_INSTANCE_TIME + " INTEGER," +
Calendar.Events.ORIGINAL_ALL_DAY + " INTEGER," +
// lastDate is in millis since epoch
Calendar.Events.LAST_DATE + " INTEGER," +
Calendar.Events.HAS_ATTENDEE_DATA + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.GUESTS_CAN_MODIFY + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.GUESTS_CAN_INVITE_OTHERS + " INTEGER NOT NULL DEFAULT 1," +
Calendar.Events.GUESTS_CAN_SEE_GUESTS + " INTEGER NOT NULL DEFAULT 1," +
Calendar.Events.ORGANIZER + " STRING," +
Calendar.Events.DELETED + " INTEGER NOT NULL DEFAULT 0," +
// dstart2 is in millis since epoch, allDay events are in local timezone
Calendar.Events.DTSTART2 + " INTEGER," +
// dtend2 is in millis since epoch, allDay events are in local timezone
Calendar.Events.DTEND2 + " INTEGER," +
// timezone for event with allDay events are in local timezone
Calendar.Events.EVENT_TIMEZONE2 + " TEXT," +
// syncAdapterData is available for use by sync adapters
Calendar.Events.SYNC_ADAPTER_DATA + " TEXT" +
");");
// Trigger to set event's sync_account
db.execSQL("CREATE TRIGGER events_insert AFTER INSERT ON " + Tables.EVENTS + " " +
"BEGIN " +
db.execSQL("CREATE INDEX eventSyncAccountAndIdIndex ON " + Tables.EVENTS + " (" +
Calendar.Events._SYNC_ACCOUNT_TYPE + ", " +
Calendar.Events._SYNC_ACCOUNT + ", " +
Calendar.Events._SYNC_ID +
");");
db.execSQL("CREATE INDEX eventsCalendarIdIndex ON " + Tables.EVENTS + " (" +
Calendar.Events.CALENDAR_ID +
");");
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
db.execSQL("CREATE TABLE " + Tables.EVENTS_RAW_TIMES + " (" +
CalendarContract.EventsRawTimes._ID + " INTEGER PRIMARY KEY," + |
| Solution content |
|---|
createCalendarsTable(db);
createEventsTable(db);
db.execSQL("CREATE TABLE " + Tables.EVENTS_RAW_TIMES + " (" +
CalendarContract.EventsRawTimes._ID + " INTEGER PRIMARY KEY," + |
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Method invocation |
| Chunk |
|---|
| Conflicting content |
|---|
");");
}
<<<<<<< HEAD
private void initCalendarCacheTable203(SQLiteDatabase db, String oldTimezoneDbVersion) {
String timezoneDbVersion = (oldTimezoneDbVersion != null) ?
oldTimezoneDbVersion : "2009s";
// Set the default timezone database version
db.execSQL("INSERT OR REPLACE INTO CalendarCache" +
" (_id, " +
"key, " +
"value) VALUES (" +
"timezoneDatabaseVersion".hashCode() + "," +
"'timezoneDatabaseVersion'," +
"'" + timezoneDbVersion + "'" +
");");
}
private void updateCalendarCacheTableTo203(SQLiteDatabase db) {
// Define the default timezone type for Instances timezone management
db.execSQL("INSERT INTO CalendarCache" +
" (_id, key, value) VALUES (" +
"timezoneType".hashCode() + "," +
"'timezoneType'," +
"'auto'" +
");");
String defaultTimezone = TimeZone.getDefault().getID();
// Define the default timezone for Instances
db.execSQL("INSERT INTO CalendarCache" +
" (_id, key, value) VALUES (" +
"timezoneInstances".hashCode() + "," +
"'timezoneInstances'," +
"'" + defaultTimezone + "'" +
");");
// Define the default previous timezone for Instances
db.execSQL("INSERT INTO CalendarCache" +
" (_id, key, value) VALUES (" +
"timezoneInstancesPrevious".hashCode() + "," +
"'timezoneInstancesPrevious'," +
"'" + defaultTimezone + "'" +
");");
}
=======
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
/**
* Removes orphaned data from the database. Specifically:
* |
| Solution content |
|---|
");");
}
private void initCalendarCacheTable203(SQLiteDatabase db, String oldTimezoneDbVersion) {
String timezoneDbVersion = (oldTimezoneDbVersion != null) ?
oldTimezoneDbVersion : "2009s";
// Set the default timezone database version
db.execSQL("INSERT OR REPLACE INTO CalendarCache" +
" (_id, " +
"key, " +
"value) VALUES (" +
"timezoneDatabaseVersion".hashCode() + "," +
"'timezoneDatabaseVersion'," +
"'" + timezoneDbVersion + "'" +
");");
}
private void updateCalendarCacheTableTo203(SQLiteDatabase db) {
// Define the default timezone type for Instances timezone management
db.execSQL("INSERT INTO CalendarCache" +
" (_id, key, value) VALUES (" +
"timezoneType".hashCode() + "," +
"'timezoneType'," +
"'auto'" +
");");
String defaultTimezone = TimeZone.getDefault().getID();
// Define the default timezone for Instances
db.execSQL("INSERT INTO CalendarCache" +
" (_id, key, value) VALUES (" +
"timezoneInstances".hashCode() + "," +
"'timezoneInstances'," +
"'" + defaultTimezone + "'" +
");");
// Define the default previous timezone for Instances
db.execSQL("INSERT INTO CalendarCache" +
" (_id, key, value) VALUES (" +
"timezoneInstancesPrevious".hashCode() + "," +
"'timezoneInstancesPrevious'," +
"'" + defaultTimezone + "'" +
");");
}
/**
* Removes orphaned data from the database. Specifically:
* |
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Method declaration |
| Chunk |
|---|
| Conflicting content |
|---|
if (cursor != null) {
*
*/
static void removeOrphans(SQLiteDatabase db) {
<<<<<<< HEAD
if (false) { // debug mode
String SELECT_ATTENDEES_ORPHANS = "SELECT " +
Attendees._ID + ", " + Attendees.EVENT_ID + " FROM " + Tables.ATTENDEES +
" WHERE " + WHERE_ATTENDEES_ORPHANS;
Cursor cursor = null;
try {
Log.i(TAG, "Attendees orphans:");
cursor = db.rawQuery(SELECT_ATTENDEES_ORPHANS, null);
DatabaseUtils.dumpCursor(cursor);
} finally {
if (cursor != null) {
cursor.close();
}
}
String SELECT_REMINDERS_ORPHANS = "SELECT " +
Attendees._ID + ", " + Reminders.EVENT_ID + " FROM " + Tables.REMINDERS +
" WHERE " + WHERE_REMINDERS_ORPHANS;
cursor = null;
try {
Log.i(TAG, "Reminders orphans:");
cursor = db.rawQuery(SELECT_REMINDERS_ORPHANS, null);
DatabaseUtils.dumpCursor(cursor);
} finally {
cursor.close();
}
}
return;
}
Log.d(TAG, "Checking for orphaned entries");
int count;
count = db.delete(Tables.ATTENDEES, WHERE_ATTENDEES_ORPHANS, null);
=======
Log.d(TAG, "Checking for orphaned entries");
int count;
count = db.delete("Attendees", WHERE_ATTENDEES_ORPHANS, null);
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
if (count != 0) {
Log.i(TAG, "Deleted " + count + " orphaned Attendees");
} |
| Solution content |
|---|
Cursor cursor = null;
try {
*
*/
static void removeOrphans(SQLiteDatabase db) {
if (false) { // debug mode
String SELECT_ATTENDEES_ORPHANS = "SELECT " +
Attendees._ID + ", " + Attendees.EVENT_ID + " FROM " + Tables.ATTENDEES +
" WHERE " + WHERE_ATTENDEES_ORPHANS;
Log.i(TAG, "Attendees orphans:");
cursor = db.rawQuery(SELECT_ATTENDEES_ORPHANS, null);
DatabaseUtils.dumpCursor(cursor);
} finally {
if (cursor != null) {
cursor.close();
}
}
String SELECT_REMINDERS_ORPHANS = "SELECT " +
Attendees._ID + ", " + Reminders.EVENT_ID + " FROM " + Tables.REMINDERS +
" WHERE " + WHERE_REMINDERS_ORPHANS;
cursor = null;
try {
Log.i(TAG, "Reminders orphans:");
cursor = db.rawQuery(SELECT_REMINDERS_ORPHANS, null);
DatabaseUtils.dumpCursor(cursor);
} finally {
if (cursor != null) {
cursor.close();
}
}
return;
}
Log.d(TAG, "Checking for orphaned entries");
int count;
count = db.delete(Tables.ATTENDEES, WHERE_ATTENDEES_ORPHANS, null);
if (count != 0) {
Log.i(TAG, "Deleted " + count + " orphaned Attendees");
} |
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| If statement |
| Method invocation |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
Log.i(TAG, "Deleted " + count + " orphaned Attendees");
}
<<<<<<< HEAD
count = db.delete(Tables.REMINDERS, WHERE_REMINDERS_ORPHANS, null);
=======
count = db.delete("Reminders", WHERE_REMINDERS_ORPHANS, null);
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
if (count != 0) {
Log.i(TAG, "Deleted " + count + " orphaned Reminders");
} |
| Solution content |
|---|
Log.i(TAG, "Deleted " + count + " orphaned Attendees");
}
count = db.delete(Tables.REMINDERS, WHERE_REMINDERS_ORPHANS, null);
if (count != 0) {
Log.i(TAG, "Deleted " + count + " orphaned Reminders");
} |
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Method invocation |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
}
}
<<<<<<< HEAD
=======
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.i(TAG, "Upgrading DB from version " + oldVersion + " to " + newVersion); |
| Solution content |
|---|
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.i(TAG, "Upgrading DB from version " + oldVersion + " to " + newVersion); |
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Blank |
| Chunk |
|---|
| Conflicting content |
|---|
createEventsView = true;
oldVersion += 1;
}
<<<<<<< HEAD
if (oldVersion == 206) {
// v206 exists only in HC (change Event._id to autoincrement). Otherwise
// identical to v204, so back it up and let the upgrade path continue.
oldVersion -= 2;
}
if (oldVersion == 204) {
// This is an ICS update, all following use 300+ versions.
upgradeToVersion205(db);
createEventsView = true;
oldVersion += 1;
}
if (oldVersion == 205) {
// Move ICS updates to 300 range
upgradeToVersion300(db);
createEventsView = true;
oldVersion = 300;
}
if (oldVersion == 300) {
upgradeToVersion301(db);
createEventsView = true;
oldVersion++;
}
if (oldVersion == 301) {
upgradeToVersion302(db);
oldVersion++;
}
if (oldVersion == 302) {
upgradeToVersion303(db);
oldVersion++;
createEventsView = true;
}
if (oldVersion == 303) {
upgradeToVersion304(db);
oldVersion++;
createEventsView = true;
}
if (oldVersion == 304) {
upgradeToVersion305(db);
oldVersion++;
createEventsView = true;
}
if (oldVersion == 305) {
upgradeToVersion306(db);
// force a sync to update edit url and etag
scheduleSync(null /* all accounts */, false, null);
oldVersion++;
}
if (oldVersion == 306) {
upgradeToVersion307(db);
oldVersion++;
}
if (createEventsView) {
createEventsView(db);
=======
if (oldVersion == 204) {
// version 205 exists in ICS, skip over it
upgradeToVersion206(db);
oldVersion += 2;
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
}
if (oldVersion != DATABASE_VERSION) {
Log.e(TAG, "Need to recreate Calendar schema because of " |
| Solution content |
|---|
createEventsView = true;
oldVersion += 1;
}
if (oldVersion == 206) {
// v206 exists only in HC (change Event._id to autoincrement). Otherwise
// identical to v204, so back it up and let the upgrade path continue.
oldVersion -= 2;
}
if (oldVersion == 204) {
// This is an ICS update, all following use 300+ versions.
upgradeToVersion205(db);
createEventsView = true;
oldVersion += 1;
}
if (oldVersion == 205) {
// Move ICS updates to 300 range
upgradeToVersion300(db);
createEventsView = true;
oldVersion = 300;
}
if (oldVersion == 300) {
upgradeToVersion301(db);
createEventsView = true;
oldVersion++;
}
if (oldVersion == 301) {
upgradeToVersion302(db);
oldVersion++;
}
if (oldVersion == 302) {
upgradeToVersion303(db);
oldVersion++;
createEventsView = true;
}
if (oldVersion == 303) {
upgradeToVersion304(db);
oldVersion++;
createEventsView = true;
}
if (oldVersion == 304) {
upgradeToVersion305(db);
oldVersion++;
createEventsView = true;
}
if (oldVersion == 305) {
upgradeToVersion306(db);
// force a sync to update edit url and etag
scheduleSync(null /* all accounts */, false, null);
oldVersion++;
}
if (oldVersion == 306) {
upgradeToVersion307(db);
oldVersion++;
}
if (createEventsView) {
createEventsView(db);
}
if (oldVersion != DATABASE_VERSION) {
Log.e(TAG, "Need to recreate Calendar schema because of " |
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| If statement |
| Method invocation |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
}
@VisibleForTesting
<<<<<<< HEAD
void upgradeToVersion307(SQLiteDatabase db) {
/*
* Changes from version 306 to 307:
* - Changed _id field to AUTOINCREMENT
*/
db.execSQL("ALTER TABLE Events RENAME TO Events_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS events_cleanup_delete");
db.execSQL("DROP TRIGGER IF EXISTS original_sync_update");
db.execSQL("DROP INDEX IF EXISTS eventsCalendarIdIndex");
createEventsTable(db);
String FIELD_LIST =
"_id, " +
"_sync_id, " +
"dirty, " +
"lastSynced," +
"calendar_id, " +
"title, " +
"eventLocation, " +
"description, " +
"eventColor, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"duration, " +
"allDay, " +
"accessLevel, " +
"availability, " +
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"original_id," +
"original_sync_id, " +
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"eventEndTimezone, " +
"sync_data1," +
"sync_data2," +
"sync_data3," +
"sync_data4," +
"sync_data5," +
"sync_data6," +
"sync_data7," +
"sync_data8," +
"sync_data9," +
"sync_data10 ";
// copy fields from old to new
db.execSQL("INSERT INTO Events (" + FIELD_LIST + ") SELECT " + FIELD_LIST +
"FROM Events_Backup;");
db.execSQL("DROP TABLE Events_Backup;");
// Trigger to remove data tied to an event when we delete that event.
db.execSQL("CREATE TRIGGER events_cleanup_delete DELETE ON " + Tables.EVENTS + " " +
"BEGIN " + EVENTS_CLEANUP_TRIGGER_SQL + "END");
// Trigger to update exceptions when an original event updates its
// _sync_id
db.execSQL(CREATE_SYNC_ID_UPDATE_TRIGGER);
}
@VisibleForTesting
void upgradeToVersion306(SQLiteDatabase db) {
/*
* The following changes are for google.com accounts only.
*
* Change event id's from ".../private/full/... to .../events/...
* Set Calendars.canPartiallyUpdate to 1 to support partial updates
* Nuke sync state so we re-sync with a fresh etag and edit url
*/
db.execSQL("UPDATE Events SET "
+ "_sync_id = REPLACE(_sync_id, '/private/full/', '/events/'), "
+ "original_sync_id = REPLACE(original_sync_id, '/private/full/', '/events/') "
"cal_sync6 " +
+ "WHERE _id IN (SELECT Events._id FROM Events "
+ "JOIN Calendars ON Events.calendar_id = Calendars._id "
+ "WHERE account_type = 'com.google')"
);
db.execSQL("UPDATE Calendars SET canPartiallyUpdate = 1 WHERE account_type = 'com.google'");
db.execSQL("DELETE FROM _sync_state WHERE account_type = 'com.google'");
}
@VisibleForTesting
void upgradeToVersion305(SQLiteDatabase db) {
/*
* Changes from version 304 to 305:
* -Add CAL_SYNC columns up to 10
* -Rename Calendars.access_level to calendar_access_level
* -Rename calendars _sync_version to cal_sync7
* -Rename calendars _sync_time to cal_sync8
* -Rename displayName to calendar_displayName
* -Rename _sync_local_id to sync_data2
* -Rename htmlUri to sync_data3
* -Rename events _sync_version to sync_data4
* -Rename events _sync_time to sync_data5
* -Rename commentsUri to sync_data6
* -Migrate Events _sync_mark to sync_data8
* -Change sync_data2 from INTEGER to TEXT
* -Change sync_data8 from INTEGER to TEXT
* -Add SYNC_DATA columns up to 10
* -Add EVENT_COLOR to Events table
*/
// rename old table, create new table with updated layout
db.execSQL("ALTER TABLE Calendars RENAME TO Calendars_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS calendar_cleanup");
createCalendarsTable(db);
// copy fields from old to new
db.execSQL("INSERT INTO Calendars (" +
"_id, " +
"account_name, " +
"account_type, " +
"_sync_id, " +
"cal_sync7, " + // rename from _sync_version
"cal_sync8, " + // rename from _sync_time
"dirty, " +
"name, " +
"calendar_displayName, " + // rename from displayName
"calendar_color, " +
"calendar_access_level, " + // rename from access_level
"visible, " +
"sync_events, " +
"calendar_location, " +
"calendar_timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders, " +
"deleted, " +
"canPartiallyUpdate," +
"cal_sync1, " +
"cal_sync2, " +
"cal_sync3, " +
"cal_sync4, " +
"cal_sync5, " +
"cal_sync6) " +
"SELECT " +
"_id, " +
"account_name, " +
"account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"dirty, " +
"name, " +
"displayName, " +
"calendar_color, " +
"access_level, " +
"visible, " +
"sync_events, " +
"calendar_location, " +
"calendar_timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders, " +
"deleted, " +
"canPartiallyUpdate," +
"cal_sync1, " +
"cal_sync2, " +
"cal_sync3, " +
"cal_sync4, " +
"cal_sync5, " +
"FROM Calendars_Backup;");
// drop the old table
db.execSQL("DROP TABLE Calendars_Backup;");
db.execSQL("ALTER TABLE Events RENAME TO Events_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS events_cleanup_delete");
db.execSQL("DROP INDEX IF EXISTS eventsCalendarIdIndex");
// 305 and 307 can share the same createEventsTable implementation, because the
// addition of "autoincrement" to _ID doesn't affect the upgrade path. (Note that
// much older databases may also already have autoincrement set because the change
// was back-ported.)
createEventsTable(db);
// copy fields from old to new
db.execSQL("INSERT INTO Events (" +
"_id, " +
"_sync_id, " +
"sync_data4, " + // renamed from _sync_version
"sync_data5, " + // renamed from _sync_time
"sync_data2, " + // renamed from _sync_local_id
"dirty, " +
"sync_data8, " + // renamed from _sync_mark
"calendar_id, " +
"sync_data3, " + // renamed from htmlUri
"title, " +
"eventLocation, " +
"description, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"sync_data6, " + // renamed from commentsUri
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"eventEndTimezone, " +
"duration, " +
"allDay, " +
"accessLevel, " +
"availability, " +
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"original_id," +
"original_sync_id, " +
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"sync_data7," +
"lastSynced," +
"sync_data1) " +
"SELECT " +
"_id, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_local_id, " +
"dirty, " +
"_sync_mark, " +
"calendar_id, " +
"htmlUri, " +
"title, " +
"eventLocation, " +
"description, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"commentsUri, " +
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"eventEndTimezone, " +
"duration, " +
"allDay, " +
"accessLevel, " +
"availability, " +
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"original_id," +
"original_sync_id, " +
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"sync_data7," +
"lastSynced," +
"sync_data1 " +
"FROM Events_Backup;"
);
db.execSQL("DROP TABLE Events_Backup;");
// Trigger to remove data tied to an event when we delete that event.
db.execSQL("CREATE TRIGGER events_cleanup_delete DELETE ON " + Tables.EVENTS + " " +
"BEGIN " +
EVENTS_CLEANUP_TRIGGER_SQL +
"END");
// Trigger to update exceptions when an original event updates its
// _sync_id
db.execSQL(CREATE_SYNC_ID_UPDATE_TRIGGER);
}
@VisibleForTesting
void upgradeToVersion304(SQLiteDatabase db) {
/*
* Changes from version 303 to 304:
* - add canPartiallyUpdate to Calendars table
* - add sync_data7 to Calendars to Events table
* - add lastSynced to Calendars to Events table
*/
db.execSQL("ALTER TABLE Calendars ADD COLUMN canPartiallyUpdate INTEGER DEFAULT 0;");
db.execSQL("ALTER TABLE Events ADD COLUMN sync_data7 TEXT;");
db.execSQL("ALTER TABLE Events ADD COLUMN lastSynced INTEGER DEFAULT 0;");
}
@VisibleForTesting
void upgradeToVersion303(SQLiteDatabase db) {
/*
* Changes from version 302 to 303:
* - change SYNCx columns to CAL_SYNCx
*/
// rename old table, create new table with updated layout
db.execSQL("ALTER TABLE Calendars RENAME TO Calendars_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS calendar_cleanup");
createCalendarsTable303(db);
// copy fields from old to new
db.execSQL("INSERT INTO Calendars (" +
"_id, " +
"account_name, " +
"account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"dirty, " +
"name, " +
"displayName, " +
"calendar_color, " +
"access_level, " +
"visible, " +
"sync_events, " +
"calendar_location, " +
"calendar_timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders, " +
"deleted, " +
"cal_sync1, " + // rename from sync1
"cal_sync2, " + // rename from sync2
"cal_sync3, " + // rename from sync3
"cal_sync4, " + // rename from sync4
"cal_sync5, " + // rename from sync5
"cal_sync6) " + // rename from sync6
"SELECT " +
"_id, " +
"account_name, " +
"account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"dirty, " +
"name, " +
"displayName, " +
"calendar_color, " +
"access_level, " +
"visible, " +
"sync_events, " +
"calendar_location, " +
"calendar_timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders," +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4," +
"sync5," +
"sync6 " +
"FROM Calendars_Backup;"
);
// drop the old table
db.execSQL("DROP TABLE Calendars_Backup;");
}
@VisibleForTesting
void upgradeToVersion302(SQLiteDatabase db) {
/*
* Changes from version 301 to 302
* - Move Exchange eventEndTimezone values to SYNC_DATA1
*/
db.execSQL("UPDATE Events SET sync_data1=eventEndTimezone WHERE calendar_id IN "
+ "(SELECT _id FROM Calendars WHERE account_type='com.android.exchange');");
db.execSQL("UPDATE Events SET eventEndTimezone=NULL WHERE calendar_id IN "
+ "(SELECT _id FROM Calendars WHERE account_type='com.android.exchange');");
}
@VisibleForTesting
void upgradeToVersion301(SQLiteDatabase db) {
/*
* Changes from version 300 to 301
* - Added original_id column to Events table
* - Added triggers to keep original_id and original_sync_id in sync
*/
db.execSQL("DROP TRIGGER IF EXISTS " + SYNC_ID_UPDATE_TRIGGER_NAME + ";");
db.execSQL("ALTER TABLE Events ADD COLUMN original_id INTEGER;");
// Fill in the original_id for all events that have an original_sync_id
db.execSQL("UPDATE Events set original_id=" +
"(SELECT Events2._id FROM Events AS Events2 " +
"WHERE Events2._sync_id=Events.original_sync_id) " +
"WHERE Events.original_sync_id NOT NULL");
// Trigger to update exceptions when an original event updates its
// _sync_id
db.execSQL(CREATE_SYNC_ID_UPDATE_TRIGGER);
}
@VisibleForTesting
void upgradeToVersion300(SQLiteDatabase db) {
/*
* Changes from version 205 to 300:
* - rename _sync_account to account_name in Calendars table
* - remove _sync_account from Events table
* - rename _sync_account_type to account_type in Calendars table
* - remove _sync_account_type from Events table
* - rename _sync_dirty to dirty in Calendars/Events table
* - rename color to calendar_color in Calendars table
* - rename location to calendar_location in Calendars table
* - rename timezone to calendar_timezone in Calendars table
* - add allowedReminders in Calendars table
* - rename visibility to accessLevel in Events table
* - rename transparency to availability in Events table
* - rename originalEvent to original_sync_id in Events table
* - remove dtstart2 and dtend2 from Events table
* - rename syncAdapterData to sync_data1 in Events table
*/
// rename old table, create new table with updated layout
db.execSQL("ALTER TABLE Calendars RENAME TO Calendars_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS calendar_cleanup;");
createCalendarsTable300(db);
// copy fields from old to new
db.execSQL("INSERT INTO Calendars (" +
"_id, " +
"account_name, " + // rename from _sync_account
"account_type, " + // rename from _sync_account_type
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"dirty, " + // rename from _sync_dirty
"name, " +
"displayName, " +
"calendar_color, " + // rename from color
"access_level, " +
"visible, " +
"sync_events, " +
"calendar_location, " + // rename from location
"calendar_timezone, " + // rename from timezone
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders," +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4," +
"sync5," +
"sync6) " +
"SELECT " +
"_id, " +
"_sync_account, " +
"_sync_account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_dirty, " +
"name, " +
"displayName, " +
"color, " +
"access_level, " +
"visible, " +
"sync_events, " +
"location, " +
"timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"'0,1,2,3'," +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4, " +
"sync5, " +
"sync6 " +
"FROM Calendars_Backup;"
);
// drop the old table
db.execSQL("DROP TABLE Calendars_Backup;");
db.execSQL("ALTER TABLE Events RENAME TO Events_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS events_insert");
db.execSQL("DROP TRIGGER IF EXISTS events_cleanup_delete");
db.execSQL("DROP INDEX IF EXISTS eventSyncAccountAndIdIndex");
db.execSQL("DROP INDEX IF EXISTS eventsCalendarIdIndex");
createEventsTable300(db);
// copy fields from old to new
db.execSQL("INSERT INTO Events (" +
"_id, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_local_id, " +
"dirty, " + // renamed from _sync_dirty
"_sync_mark, " +
"calendar_id, " +
"htmlUri, " +
"title, " +
"eventLocation, " +
"description, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"commentsUri, " +
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"eventEndTimezone, " + // renamed from eventTimezone2
"duration, " +
"allDay, " +
"accessLevel, " + // renamed from visibility
"availability, " + // renamed from transparency
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"original_sync_id, " + // renamed from originalEvent
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"sync_data1) " + // renamed from syncAdapterData
"SELECT " +
"_id, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_local_id, " +
"_sync_dirty, " +
"_sync_mark, " +
"calendar_id, " +
"htmlUri, " +
"title, " +
"eventLocation, " +
"description, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"commentsUri, " +
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"eventTimezone2, " +
"duration, " +
"allDay, " +
"visibility, " +
"transparency, " +
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"originalEvent, " +
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"syncAdapterData " +
"FROM Events_Backup;"
);
db.execSQL("DROP TABLE Events_Backup;");
=======
void upgradeToVersion206(SQLiteDatabase db) {
/*
* Changes from version 204 to 205:
* - Changed _id field to AUTOINCREMENT
*/
db.execSQL("ALTER TABLE Events RENAME TO Events_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS events_insert");
db.execSQL("DROP TRIGGER IF EXISTS events_cleanup_delete");
db.execSQL("DROP INDEX IF EXISTS eventSyncAccountAndIdIndex");
db.execSQL("DROP INDEX IF EXISTS eventsCalendarIdIndex");
// copy & pasted from bootstrapDB
db.execSQL("CREATE TABLE " + Tables.EVENTS + " (" +
Calendar.Events._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
Calendar.Events._SYNC_ACCOUNT + " TEXT," +
Calendar.Events._SYNC_ACCOUNT_TYPE + " TEXT," +
Calendar.Events._SYNC_ID + " TEXT," +
Calendar.Events._SYNC_VERSION + " TEXT," +
// sync time in UTC
Calendar.Events._SYNC_TIME + " TEXT," +
Calendar.Events._SYNC_DATA + " INTEGER," +
Calendar.Events._SYNC_DIRTY + " INTEGER," +
// sync mark to filter out new rows
Calendar.Events._SYNC_MARK + " INTEGER," +
Calendar.Events.CALENDAR_ID + " INTEGER NOT NULL," +
Calendar.Events.HTML_URI + " TEXT," +
Calendar.Events.TITLE + " TEXT," +
Calendar.Events.EVENT_LOCATION + " TEXT," +
Calendar.Events.DESCRIPTION + " TEXT," +
Calendar.Events.STATUS + " INTEGER," +
Calendar.Events.SELF_ATTENDEE_STATUS + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.COMMENTS_URI + " TEXT," +
// dtstart in millis since epoch
Calendar.Events.DTSTART + " INTEGER," +
// dtend in millis since epoch
Calendar.Events.DTEND + " INTEGER," +
// timezone for event
Calendar.Events.EVENT_TIMEZONE + " TEXT," +
Calendar.Events.DURATION + " TEXT," +
Calendar.Events.ALL_DAY + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.VISIBILITY + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.TRANSPARENCY + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.HAS_ALARM + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.HAS_EXTENDED_PROPERTIES + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.RRULE + " TEXT," +
Calendar.Events.RDATE + " TEXT," +
Calendar.Events.EXRULE + " TEXT," +
Calendar.Events.EXDATE + " TEXT," +
// originalEvent is the _sync_id of recurring event
Calendar.Events.ORIGINAL_EVENT + " TEXT," +
// originalInstanceTime is in millis since epoch
Calendar.Events.ORIGINAL_INSTANCE_TIME + " INTEGER," +
Calendar.Events.ORIGINAL_ALL_DAY + " INTEGER," +
// lastDate is in millis since epoch
Calendar.Events.LAST_DATE + " INTEGER," +
Calendar.Events.HAS_ATTENDEE_DATA + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.GUESTS_CAN_MODIFY + " INTEGER NOT NULL DEFAULT 0," +
Calendar.Events.GUESTS_CAN_INVITE_OTHERS + " INTEGER NOT NULL DEFAULT 1," +
Calendar.Events.GUESTS_CAN_SEE_GUESTS + " INTEGER NOT NULL DEFAULT 1," +
Calendar.Events.ORGANIZER + " STRING," +
Calendar.Events.DELETED + " INTEGER NOT NULL DEFAULT 0," +
// dstart2 is in millis since epoch, allDay events are in local timezone
Calendar.Events.DTSTART2 + " INTEGER," +
// dtend2 is in millis since epoch, allDay events are in local timezone
Calendar.Events.DTEND2 + " INTEGER," +
// timezone for event with allDay events are in local timezone
Calendar.Events.EVENT_TIMEZONE2 + " TEXT," +
// syncAdapterData is available for use by sync adapters
Calendar.Events.SYNC_ADAPTER_DATA + " TEXT" +
");");
db.execSQL("CREATE INDEX eventSyncAccountAndIdIndex ON " + Tables.EVENTS + " (" +
Calendar.Events._SYNC_ACCOUNT_TYPE + ", " +
Calendar.Events._SYNC_ACCOUNT + ", " +
Calendar.Events._SYNC_ID +
");");
db.execSQL("CREATE INDEX eventsCalendarIdIndex ON " + Tables.EVENTS + " (" +
Calendar.Events.CALENDAR_ID +
");");
String FIELD_LIST =
Calendar.Events._ID + ", " +
Calendar.Events._SYNC_ACCOUNT + ", " +
Calendar.Events._SYNC_ACCOUNT_TYPE + ", " +
Calendar.Events._SYNC_ID + ", " +
Calendar.Events._SYNC_VERSION + ", " +
Calendar.Events._SYNC_TIME + ", " +
Calendar.Events._SYNC_DATA + ", " +
Calendar.Events._SYNC_DIRTY + ", " +
Calendar.Events._SYNC_MARK + ", " +
Calendar.Events.CALENDAR_ID + ", " +
Calendar.Events.HTML_URI + ", " +
Calendar.Events.TITLE + ", " +
Calendar.Events.EVENT_LOCATION + ", " +
Calendar.Events.DESCRIPTION + ", " +
Calendar.Events.STATUS + ", " +
Calendar.Events.SELF_ATTENDEE_STATUS + ", " +
Calendar.Events.COMMENTS_URI + ", " +
Calendar.Events.DTSTART + ", " +
Calendar.Events.DTEND + ", " +
Calendar.Events.EVENT_TIMEZONE + ", " +
Calendar.Events.DURATION + ", " +
Calendar.Events.ALL_DAY + ", " +
Calendar.Events.VISIBILITY + ", " +
Calendar.Events.TRANSPARENCY + ", " +
Calendar.Events.HAS_ALARM + ", " +
Calendar.Events.HAS_EXTENDED_PROPERTIES + ", " +
Calendar.Events.RRULE + ", " +
Calendar.Events.RDATE + ", " +
Calendar.Events.EXRULE + ", " +
Calendar.Events.EXDATE + ", " +
Calendar.Events.ORIGINAL_EVENT + ", " +
Calendar.Events.ORIGINAL_INSTANCE_TIME + ", " +
Calendar.Events.ORIGINAL_ALL_DAY + ", " +
Calendar.Events.LAST_DATE + ", " +
Calendar.Events.HAS_ATTENDEE_DATA + ", " +
Calendar.Events.GUESTS_CAN_MODIFY + ", " +
Calendar.Events.GUESTS_CAN_INVITE_OTHERS + ", " +
Calendar.Events.GUESTS_CAN_SEE_GUESTS + ", " +
Calendar.Events.ORGANIZER + ", " +
Calendar.Events.DELETED + ", " +
Calendar.Events.DTSTART2 + ", " +
Calendar.Events.DTEND2 + ", " +
Calendar.Events.EVENT_TIMEZONE2 + ", " +
Calendar.Events.SYNC_ADAPTER_DATA;
// copy fields from old to new
db.execSQL("INSERT INTO Events (" + FIELD_LIST + ") SELECT " + FIELD_LIST +
" FROM Events_Backup;");
db.execSQL("DROP TABLE Events_Backup;");
// Trigger to set event's sync_account
db.execSQL("CREATE TRIGGER events_insert AFTER INSERT ON " + Tables.EVENTS + " " +
"BEGIN " +
AFTER_EVENT_INSERT_SQL +
"END");
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
// Trigger to remove data tied to an event when we delete that event.
db.execSQL("CREATE TRIGGER events_cleanup_delete DELETE ON " + Tables.EVENTS + " " +
"BEGIN " + |
| Solution content |
|---|
}
@VisibleForTesting
void upgradeToVersion307(SQLiteDatabase db) {
/*
* Changes from version 306 to 307:
* - Changed _id field to AUTOINCREMENT
*/
db.execSQL("ALTER TABLE Events RENAME TO Events_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS events_cleanup_delete");
db.execSQL("DROP TRIGGER IF EXISTS original_sync_update");
db.execSQL("DROP INDEX IF EXISTS eventsCalendarIdIndex");
createEventsTable(db);
String FIELD_LIST =
"_id, " +
"_sync_id, " +
"dirty, " +
"lastSynced," +
"calendar_id, " +
"title, " +
"eventLocation, " +
"description, " +
"eventColor, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"duration, " +
"allDay, " +
"accessLevel, " +
"availability, " +
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"original_id," +
"original_sync_id, " +
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"eventEndTimezone, " +
"sync_data1," +
"sync_data2," +
"sync_data3," +
"sync_data4," +
"sync_data5," +
"sync_data6," +
"sync_data7," +
"sync_data8," +
"sync_data9," +
"sync_data10 ";
// copy fields from old to new
db.execSQL("INSERT INTO Events (" + FIELD_LIST + ") SELECT " + FIELD_LIST +
"FROM Events_Backup;");
db.execSQL("DROP TABLE Events_Backup;");
// Trigger to remove data tied to an event when we delete that event.
db.execSQL("CREATE TRIGGER events_cleanup_delete DELETE ON " + Tables.EVENTS + " " +
"BEGIN " + EVENTS_CLEANUP_TRIGGER_SQL + "END");
// Trigger to update exceptions when an original event updates its
// _sync_id
db.execSQL(CREATE_SYNC_ID_UPDATE_TRIGGER);
}
@VisibleForTesting
void upgradeToVersion306(SQLiteDatabase db) {
/*
* The following changes are for google.com accounts only.
*
* Change event id's from ".../private/full/... to .../events/...
* Set Calendars.canPartiallyUpdate to 1 to support partial updates
* Nuke sync state so we re-sync with a fresh etag and edit url
*/
db.execSQL("UPDATE Events SET "
+ "_sync_id = REPLACE(_sync_id, '/private/full/', '/events/'), "
+ "original_sync_id = REPLACE(original_sync_id, '/private/full/', '/events/') "
+ "WHERE _id IN (SELECT Events._id FROM Events "
+ "JOIN Calendars ON Events.calendar_id = Calendars._id "
+ "WHERE account_type = 'com.google')"
);
db.execSQL("UPDATE Calendars SET canPartiallyUpdate = 1 WHERE account_type = 'com.google'");
db.execSQL("DELETE FROM _sync_state WHERE account_type = 'com.google'");
}
@VisibleForTesting
void upgradeToVersion305(SQLiteDatabase db) {
/*
* Changes from version 304 to 305:
* -Add CAL_SYNC columns up to 10
* -Rename Calendars.access_level to calendar_access_level
* -Rename calendars _sync_version to cal_sync7
* -Rename calendars _sync_time to cal_sync8
* -Rename displayName to calendar_displayName
* -Rename _sync_local_id to sync_data2
* -Rename htmlUri to sync_data3
* -Rename events _sync_version to sync_data4
* -Rename events _sync_time to sync_data5
* -Rename commentsUri to sync_data6
* -Migrate Events _sync_mark to sync_data8
* -Change sync_data2 from INTEGER to TEXT
* -Change sync_data8 from INTEGER to TEXT
* -Add SYNC_DATA columns up to 10
* -Add EVENT_COLOR to Events table
*/
// rename old table, create new table with updated layout
db.execSQL("ALTER TABLE Calendars RENAME TO Calendars_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS calendar_cleanup");
createCalendarsTable(db);
// copy fields from old to new
db.execSQL("INSERT INTO Calendars (" +
"_id, " +
"account_name, " +
"account_type, " +
"_sync_id, " +
"cal_sync7, " + // rename from _sync_version
"cal_sync8, " + // rename from _sync_time
"dirty, " +
"name, " +
"calendar_displayName, " + // rename from displayName
"calendar_color, " +
"calendar_access_level, " + // rename from access_level
"visible, " +
"sync_events, " +
"calendar_location, " +
"calendar_timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders, " +
"deleted, " +
"canPartiallyUpdate," +
"cal_sync1, " +
"cal_sync2, " +
"cal_sync3, " +
"cal_sync4, " +
"cal_sync5, " +
"cal_sync6) " +
"SELECT " +
"_id, " +
"account_name, " +
"account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"dirty, " +
"name, " +
"displayName, " +
"calendar_color, " +
"access_level, " +
"visible, " +
"sync_events, " +
"calendar_location, " +
"calendar_timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders, " +
"deleted, " +
"canPartiallyUpdate," +
"cal_sync1, " +
"cal_sync2, " +
"cal_sync3, " +
"cal_sync4, " +
"cal_sync5, " +
"cal_sync6 " +
"FROM Calendars_Backup;");
// drop the old table
db.execSQL("DROP TABLE Calendars_Backup;");
db.execSQL("ALTER TABLE Events RENAME TO Events_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS events_cleanup_delete");
db.execSQL("DROP INDEX IF EXISTS eventsCalendarIdIndex");
// 305 and 307 can share the same createEventsTable implementation, because the
// addition of "autoincrement" to _ID doesn't affect the upgrade path. (Note that
// much older databases may also already have autoincrement set because the change
// was back-ported.)
createEventsTable(db);
// copy fields from old to new
db.execSQL("INSERT INTO Events (" +
"_id, " +
"_sync_id, " +
"sync_data4, " + // renamed from _sync_version
"sync_data5, " + // renamed from _sync_time
"sync_data2, " + // renamed from _sync_local_id
"dirty, " +
"sync_data8, " + // renamed from _sync_mark
"calendar_id, " +
"sync_data3, " + // renamed from htmlUri
"title, " +
"eventLocation, " +
"description, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"sync_data6, " + // renamed from commentsUri
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"eventEndTimezone, " +
"duration, " +
"allDay, " +
"accessLevel, " +
"availability, " +
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"original_id," +
"original_sync_id, " +
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"sync_data7," +
"lastSynced," +
"sync_data1) " +
"SELECT " +
"_id, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_local_id, " +
"dirty, " +
"_sync_mark, " +
"calendar_id, " +
"htmlUri, " +
"title, " +
"eventLocation, " +
"description, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"commentsUri, " +
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"eventEndTimezone, " +
"duration, " +
"allDay, " +
"accessLevel, " +
"availability, " +
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"original_id," +
"original_sync_id, " +
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"sync_data7," +
"lastSynced," +
"sync_data1 " +
"FROM Events_Backup;"
);
db.execSQL("DROP TABLE Events_Backup;");
// Trigger to remove data tied to an event when we delete that event.
db.execSQL("CREATE TRIGGER events_cleanup_delete DELETE ON " + Tables.EVENTS + " " +
"BEGIN " +
EVENTS_CLEANUP_TRIGGER_SQL +
"END");
// Trigger to update exceptions when an original event updates its
// _sync_id
db.execSQL(CREATE_SYNC_ID_UPDATE_TRIGGER);
}
@VisibleForTesting
void upgradeToVersion304(SQLiteDatabase db) {
/*
* Changes from version 303 to 304:
* - add canPartiallyUpdate to Calendars table
* - add sync_data7 to Calendars to Events table
* - add lastSynced to Calendars to Events table
*/
db.execSQL("ALTER TABLE Calendars ADD COLUMN canPartiallyUpdate INTEGER DEFAULT 0;");
db.execSQL("ALTER TABLE Events ADD COLUMN sync_data7 TEXT;");
db.execSQL("ALTER TABLE Events ADD COLUMN lastSynced INTEGER DEFAULT 0;");
}
@VisibleForTesting
void upgradeToVersion303(SQLiteDatabase db) {
/*
* Changes from version 302 to 303:
* - change SYNCx columns to CAL_SYNCx
*/
// rename old table, create new table with updated layout
db.execSQL("ALTER TABLE Calendars RENAME TO Calendars_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS calendar_cleanup");
createCalendarsTable303(db);
// copy fields from old to new
db.execSQL("INSERT INTO Calendars (" +
"_id, " +
"account_name, " +
"account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"dirty, " +
"name, " +
"displayName, " +
"calendar_color, " +
"access_level, " +
"visible, " +
"sync_events, " +
"calendar_location, " +
"calendar_timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders, " +
"deleted, " +
"cal_sync1, " + // rename from sync1
"cal_sync2, " + // rename from sync2
"cal_sync3, " + // rename from sync3
"cal_sync4, " + // rename from sync4
"cal_sync5, " + // rename from sync5
"cal_sync6) " + // rename from sync6
"SELECT " +
"_id, " +
"account_name, " +
"account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"dirty, " +
"name, " +
"displayName, " +
"calendar_color, " +
"access_level, " +
"visible, " +
"sync_events, " +
"calendar_location, " +
"calendar_timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders," +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4," +
"sync5," +
"sync6 " +
"FROM Calendars_Backup;"
);
// drop the old table
db.execSQL("DROP TABLE Calendars_Backup;");
}
@VisibleForTesting
void upgradeToVersion302(SQLiteDatabase db) {
/*
* Changes from version 301 to 302
* - Move Exchange eventEndTimezone values to SYNC_DATA1
*/
db.execSQL("UPDATE Events SET sync_data1=eventEndTimezone WHERE calendar_id IN "
+ "(SELECT _id FROM Calendars WHERE account_type='com.android.exchange');");
db.execSQL("UPDATE Events SET eventEndTimezone=NULL WHERE calendar_id IN "
+ "(SELECT _id FROM Calendars WHERE account_type='com.android.exchange');");
}
@VisibleForTesting
void upgradeToVersion301(SQLiteDatabase db) {
/*
* Changes from version 300 to 301
* - Added original_id column to Events table
* - Added triggers to keep original_id and original_sync_id in sync
*/
db.execSQL("DROP TRIGGER IF EXISTS " + SYNC_ID_UPDATE_TRIGGER_NAME + ";");
db.execSQL("ALTER TABLE Events ADD COLUMN original_id INTEGER;");
// Fill in the original_id for all events that have an original_sync_id
db.execSQL("UPDATE Events set original_id=" +
"(SELECT Events2._id FROM Events AS Events2 " +
"WHERE Events2._sync_id=Events.original_sync_id) " +
"WHERE Events.original_sync_id NOT NULL");
// Trigger to update exceptions when an original event updates its
// _sync_id
db.execSQL(CREATE_SYNC_ID_UPDATE_TRIGGER);
}
@VisibleForTesting
void upgradeToVersion300(SQLiteDatabase db) {
/*
* Changes from version 205 to 300:
* - rename _sync_account to account_name in Calendars table
* - remove _sync_account from Events table
* - rename _sync_account_type to account_type in Calendars table
* - remove _sync_account_type from Events table
* - rename _sync_dirty to dirty in Calendars/Events table
* - rename color to calendar_color in Calendars table
* - rename location to calendar_location in Calendars table
* - rename timezone to calendar_timezone in Calendars table
* - add allowedReminders in Calendars table
* - rename visibility to accessLevel in Events table
* - rename transparency to availability in Events table
* - rename originalEvent to original_sync_id in Events table
* - remove dtstart2 and dtend2 from Events table
* - rename syncAdapterData to sync_data1 in Events table
*/
// rename old table, create new table with updated layout
db.execSQL("ALTER TABLE Calendars RENAME TO Calendars_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS calendar_cleanup;");
createCalendarsTable300(db);
// copy fields from old to new
db.execSQL("INSERT INTO Calendars (" +
"_id, " +
"account_name, " + // rename from _sync_account
"account_type, " + // rename from _sync_account_type
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"dirty, " + // rename from _sync_dirty
"name, " +
"displayName, " +
"calendar_color, " + // rename from color
"access_level, " +
"visible, " +
"sync_events, " +
"calendar_location, " + // rename from location
"calendar_timezone, " + // rename from timezone
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"allowedReminders," +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4," +
"sync5," +
"sync6) " +
"SELECT " +
"_id, " +
"_sync_account, " +
"_sync_account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_dirty, " +
"name, " +
"displayName, " +
"color, " +
"access_level, " +
"visible, " +
"sync_events, " +
"location, " +
"timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " +
"canModifyTimeZone, " +
"maxReminders, " +
"'0,1,2,3'," +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4, " +
"sync5, " +
"sync6 " +
"FROM Calendars_Backup;"
);
// drop the old table
db.execSQL("DROP TABLE Calendars_Backup;");
db.execSQL("ALTER TABLE Events RENAME TO Events_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS events_insert");
db.execSQL("DROP TRIGGER IF EXISTS events_cleanup_delete");
db.execSQL("DROP INDEX IF EXISTS eventSyncAccountAndIdIndex");
db.execSQL("DROP INDEX IF EXISTS eventsCalendarIdIndex");
createEventsTable300(db);
// copy fields from old to new
db.execSQL("INSERT INTO Events (" +
"_id, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_local_id, " +
"dirty, " + // renamed from _sync_dirty
"_sync_mark, " +
"calendar_id, " +
"htmlUri, " +
"title, " +
"eventLocation, " +
"description, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"commentsUri, " +
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"eventEndTimezone, " + // renamed from eventTimezone2
"duration, " +
"allDay, " +
"accessLevel, " + // renamed from visibility
"availability, " + // renamed from transparency
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"original_sync_id, " + // renamed from originalEvent
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"sync_data1) " + // renamed from syncAdapterData
"SELECT " +
"_id, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_local_id, " +
"_sync_dirty, " +
"_sync_mark, " +
"calendar_id, " +
"htmlUri, " +
"title, " +
"eventLocation, " +
"description, " +
"eventStatus, " +
"selfAttendeeStatus, " +
"commentsUri, " +
"dtstart, " +
"dtend, " +
"eventTimezone, " +
"eventTimezone2, " +
"duration, " +
"allDay, " +
"visibility, " +
"transparency, " +
"hasAlarm, " +
"hasExtendedProperties, " +
"rrule, " +
"rdate, " +
"exrule, " +
"exdate, " +
"originalEvent, " +
"originalInstanceTime, " +
"originalAllDay, " +
"lastDate, " +
"hasAttendeeData, " +
"guestsCanModify, " +
"guestsCanInviteOthers, " +
"guestsCanSeeGuests, " +
"organizer, " +
"deleted, " +
"syncAdapterData " +
"FROM Events_Backup;"
);
db.execSQL("DROP TABLE Events_Backup;");
// Trigger to remove data tied to an event when we delete that event.
db.execSQL("CREATE TRIGGER events_cleanup_delete DELETE ON " + Tables.EVENTS + " " +
"BEGIN " + |
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Method declaration |
| Method invocation |
| Method signature |
| Variable |
| Chunk |
|---|
| Conflicting content |
|---|
"BEGIN " +
EVENTS_CLEANUP_TRIGGER_SQL +
"END");
<<<<<<< HEAD
}
@VisibleForTesting
void upgradeToVersion205(SQLiteDatabase db) {
/*
* Changes from version 204 to 205:
* - rename+reorder "_sync_mark" to "sync6" (and change type from INTEGER to TEXT)
* - rename "selected" to "visible"
* - rename "organizerCanRespond" to "canOrganizerRespond"
* - add "canModifyTimeZone"
* - add "maxReminders"
* - remove "_sync_local_id" (a/k/a _SYNC_DATA)
*/
// rename old table, create new table with updated layout
db.execSQL("ALTER TABLE Calendars RENAME TO Calendars_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS calendar_cleanup");
createCalendarsTable205(db);
// copy fields from old to new
db.execSQL("INSERT INTO Calendars (" +
"_id, " +
"_sync_account, " +
"_sync_account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_dirty, " +
"name, " +
"displayName, " +
"color, " +
"access_level, " +
"visible, " + // rename from "selected"
"sync_events, " +
"location, " +
"timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " + // rename from "organizerCanRespond"
"canModifyTimeZone, " +
"maxReminders, " +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4," +
"sync5," +
"sync6) " + // rename/reorder from _sync_mark
"SELECT " +
"_id, " +
"_sync_account, " +
"_sync_account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_dirty, " +
"name, " +
"displayName, " +
"color, " +
"access_level, " +
"selected, " +
"sync_events, " +
"location, " +
"timezone, " +
"ownerAccount, " +
"organizerCanRespond, " +
"1, " +
"5, " +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4, " +
"sync5, " +
"_sync_mark " +
"FROM Calendars_Backup;"
);
// set these fields appropriately for Exchange events
db.execSQL("UPDATE Calendars SET canModifyTimeZone=0, maxReminders=1 " +
"WHERE _sync_account_type='com.android.exchange'");
// drop the old table
db.execSQL("DROP TABLE Calendars_Backup;");
=======
}
@VisibleForTesting
void upgradeToVersion204(SQLiteDatabase db) {
// Recreate the Events Views as the new SYNC_ADAPTER_DATA column needs to be added
createEventsView(db);
>>>>>>> 989d50bd95b45755adc09facdf53e4218cf10077
}
@VisibleForTesting |
| Solution content |
|---|
"BEGIN " +
EVENTS_CLEANUP_TRIGGER_SQL +
"END");
}
@VisibleForTesting
void upgradeToVersion205(SQLiteDatabase db) {
/*
* Changes from version 204 to 205:
* - rename+reorder "_sync_mark" to "sync6" (and change type from INTEGER to TEXT)
* - rename "selected" to "visible"
* - rename "organizerCanRespond" to "canOrganizerRespond"
* - add "canModifyTimeZone"
* - add "maxReminders"
* - remove "_sync_local_id" (a/k/a _SYNC_DATA)
*/
// rename old table, create new table with updated layout
db.execSQL("ALTER TABLE Calendars RENAME TO Calendars_Backup;");
db.execSQL("DROP TRIGGER IF EXISTS calendar_cleanup");
createCalendarsTable205(db);
// copy fields from old to new
db.execSQL("INSERT INTO Calendars (" +
"_id, " +
"_sync_account, " +
"_sync_account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_dirty, " +
"name, " +
"displayName, " +
"color, " +
"access_level, " +
"visible, " + // rename from "selected"
"sync_events, " +
"location, " +
"timezone, " +
"ownerAccount, " +
"canOrganizerRespond, " + // rename from "organizerCanRespond"
"canModifyTimeZone, " +
"maxReminders, " +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4," +
"sync5," +
"sync6) " + // rename/reorder from _sync_mark
"SELECT " +
"_id, " +
"_sync_account, " +
"_sync_account_type, " +
"_sync_id, " +
"_sync_version, " +
"_sync_time, " +
"_sync_dirty, " +
"name, " +
"displayName, " +
"color, " +
"access_level, " +
"selected, " +
"sync_events, " +
"location, " +
"timezone, " +
"ownerAccount, " +
"organizerCanRespond, " +
"1, " +
"5, " +
"deleted, " +
"sync1, " +
"sync2, " +
"sync3, " +
"sync4, " +
"sync5, " +
"_sync_mark " +
"FROM Calendars_Backup;"
);
// set these fields appropriately for Exchange events
db.execSQL("UPDATE Calendars SET canModifyTimeZone=0, maxReminders=1 " +
"WHERE _sync_account_type='com.android.exchange'");
// drop the old table
db.execSQL("DROP TABLE Calendars_Backup;");
}
@VisibleForTesting |
| File |
|---|
| CalendarDatabaseHelper.java |
| Developer's decision |
|---|
| Version 1 |
| Kind of conflict |
|---|
| Comment |
| Method invocation |
| Method signature |