static void _cal_db_event_get_property_stmt(sqlite3_stmt *stmt, unsigned int property, int *stmt_count, calendar_record_h record);
static void _cal_db_event_get_projection_stmt(sqlite3_stmt *stmt, const unsigned int *projection, const int projection_count, calendar_record_h record);
static int _cal_db_event_exception_get_records(int original_id, cal_list_s *list);
-static int _cal_db_event_exception_delete_with_id(int original_id);
static int _cal_db_event_exception_get_ids(int original_id, GList **out_list);
static int _cal_db_event_exception_update(cal_list_s *exception_list_s, int original_id, int calendar_id, int is_dirty_in_time, time_t time_diff, int old_type, int new_type);
static int _cal_db_event_get_deleted_data(int id, int* calendar_book_id, int* created_ver, int* original_event_id, char** recurrence_id);
-static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_exdate, const char* exdate, int **exception_id, int *exception_len);
+static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_exdate, const char* exdate, int **exception_id, int *exception_len, bool *needs_update);
static bool _cal_db_event_check_calendar_book_type(calendar_record_h record);
static void __check_list(calendar_list_h l)
{
- DBG("---------------------");
calendar_list_first(l);
int count = 0;
calendar_list_get_count(l, &count);
}
break;
}
- DBG("-------------time diff(%ld)", diff);
+ DBG("time diff(%ld)", diff);
return diff;
}
return CALENDAR_ERROR_NONE;
}
+static void _cal_db_exception_delete_with_id(int original_event_id)
+{
+ int ret = 0;
+ sqlite3_stmt *stmt = NULL;
+ char query[CAL_DB_SQL_MAX_LEN];
+ snprintf(query, sizeof(query), "SELECT id FROM "CAL_TABLE_SCHEDULE" "
+ "WHERE original_event_id = %d ", original_event_id);
+ ret = cal_db_util_query_prepare(query, &stmt);
+ if (CALENDAR_ERROR_NONE != ret) {
+ /* LCOV_EXCL_START */
+ ERR("cal_db_util_query_prepare() Fail(%d)", ret);
+ SECURE("query[%s]", query);
+ return;
+ /* LCOV_EXCL_STOP */
+ }
+
+ while (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) {
+ int num = sqlite3_column_int(stmt, 0);
+ _cal_db_event_delete_record(num);
+ }
+ sqlite3_finalize(stmt);
+}
+
static int __update_record(calendar_record_h record, int is_dirty_in_time)
{
int ret = 0;
cal_db_alarm_delete_with_id(event->index);
cal_db_attendee_delete_with_id(event->index);
+ _cal_db_exception_delete_with_id(event->index);
cal_db_extended_delete_with_id(event->index, CALENDAR_RECORD_TYPE_EVENT);
if (event->alarm_list && 0 < event->alarm_list->count) {
}
if (event->exception_list && 0 < event->exception_list->count) {
- ret = _cal_db_event_exception_update(event->exception_list, event->index, event->calendar_id, is_dirty_in_time, time_diff, ct.type, event->start.type);
+ ret = _cal_db_event_exception_update(event->exception_list, event->index,
+ event->calendar_id, is_dirty_in_time, time_diff, ct.type, event->start.type);
WARN_IF(CALENDAR_ERROR_NONE != ret, "_cal_db_event_exception_update() Fail(%d)", ret);
}
/*
* if parent is deleted first, exception record is failed to be deleted.
- * Becase exception record is deleted first, ret has SQLITE_DONE
+ * Because exception record is deleted first, ret has SQLITE_DONE
* Trigger in schema deletes exception first, before deleting parent.
*/
if (true == is_deleted_exception(id)) {
cal_db_alarm_delete_with_id(id);
cal_db_attendee_delete_with_id(id);
- _cal_db_event_exception_delete_with_id(id);
+ _cal_db_exception_delete_with_id(id);
cal_db_extended_delete_with_id(id, CALENDAR_RECORD_TYPE_EVENT);
if (event->alarm_list && 0 < event->alarm_list->count) {
ret = calendar_record_get_str_p(original_record, property_info[i].property_id, &original_exdate);
if (CALENDAR_ERROR_NONE != ret)
continue;
+
+ bool needs_update = false;
if (sync_event_type == CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN) {
ret = _cal_db_event_exdate_insert_utime(event_id, original_exdate,
- record_exdate, NULL, NULL);
+ record_exdate, NULL, NULL, &needs_update);
WARN_IF(CALENDAR_ERROR_NONE != ret, "%s->%s", original_exdate, record_exdate);
} else {
int *exception_ids = NULL;
int exception_len = 0;
ret = _cal_db_event_exdate_insert_utime(event_id, original_exdate,
- record_exdate, &exception_ids, &exception_len);
+ record_exdate, &exception_ids, &exception_len, &needs_update);
WARN_IF(CALENDAR_ERROR_NONE != ret, "%s->%s", original_exdate, record_exdate);
ret = _cal_db_event_delete_exception(exception_ids, exception_len);
WARN_IF(CALENDAR_ERROR_NONE != ret, "_cal_db_event_delete_record() Fail");
free(exception_ids);
}
- ret = cal_record_set_str(original_record, property_info[i].property_id, record_exdate);
- if (CALENDAR_ERROR_NONE != ret)
- continue;
+ if (needs_update) {
+ ret = cal_record_set_str(original_record, property_info[i].property_id, record_exdate);
+ if (CALENDAR_ERROR_NONE != ret)
+ continue;
+ }
} else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id, CAL_PROPERTY_DATA_TYPE_INT) == true) {
int tmp = 0;
ret = calendar_record_get_int(record, property_info[i].property_id, &tmp);
return CALENDAR_ERROR_NONE;
}
-static int _cal_db_event_exception_delete_with_id(int original_id)
-{
- int ret = 0;
- char query[CAL_DB_SQL_MAX_LEN] = {0};
-
- DBG("delete exception mod with original event id(%d)", original_id);
- snprintf(query, sizeof(query), "DELETE FROM %s WHERE original_event_id=%d ",
- CAL_TABLE_SCHEDULE, original_id);
- ret = cal_db_util_query_exec(query);
- if (CALENDAR_ERROR_NONE != ret) {
- /* LCOV_EXCL_START */
- ERR("cal_db_util_query_exec() Fail(%d)", ret);
- SECURE("[%s]", query);
- return ret;
- /* LCOV_EXCL_STOP */
- }
-
- return CALENDAR_ERROR_NONE;
-}
-
static int _cal_db_event_exception_get_ids(int original_id, GList **out_list)
{
int ret = 0;
}
static int _cal_db_event_exdate_insert_utime(int event_id, const char* original_exdate,
- const char* exdate, int **exception_ids, int *exception_len)
+ const char* inserted_exdate, int **exception_ids, int *exception_len, bool *needs_update)
{
int ret = CALENDAR_ERROR_NONE;
- gchar **patterns1 = NULL;
- gchar **patterns2 = NULL;
- int len1 = 0, len2 = 0, i = 0, j = 0;
+ gchar **t_inserted = NULL;
+ gchar **t_original = NULL;
+ int len_inserted = 0;
+ int len_original = 0;
- int input_ver = cal_db_util_get_next_ver();
- if (exdate != NULL && 0 < strlen(exdate)) {
- patterns1 = g_strsplit_set(exdate, " ,", -1);
- len1 = g_strv_length(patterns1);
+ if (NULL != inserted_exdate && '\0' != *inserted_exdate) {
+ t_inserted = g_strsplit_set(inserted_exdate, " ,", -1);
+ len_inserted = g_strv_length(t_inserted);
}
- if (original_exdate && 0 < strlen(original_exdate)) {
- patterns2 = g_strsplit_set(original_exdate, " ,", -1);
- len2 = g_strv_length(patterns2);
+ if (NULL != original_exdate && '\0' != *original_exdate) {
+ t_original = g_strsplit_set(original_exdate, " ,", -1);
+ len_original = g_strv_length(t_original);
}
- int *ids = calloc(len1, sizeof(int));
- RETVM_IF(NULL == ids, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
+ int *ids = calloc(len_inserted, sizeof(int));
+ if (NULL == ids) {
+ ERR("calloc() Fail");
+ g_strfreev(t_inserted);
+ g_strfreev(t_original);
+ return CALENDAR_ERROR_OUT_OF_MEMORY;
+ }
int exception_count = 0;
- for (i = 0; i < len1; i++) {
- if (NULL == patterns1[i]) {
- WARN("exdate is NULL, so check next");
+ int input_ver = cal_db_util_get_next_ver();
+ int i = 0, j = 0;
+ for (i = 0; i < len_inserted; i++) {
+ if ('\0' == *(t_inserted[i]))
continue;
- }
+
bool bFind = false;
- for (j = 0; j < len2; j++) {
- if (NULL == patterns2[j]) {
- WARN("original exdate is NULL");
+ for (j = 0; j < len_original; j++) {
+ if ('\0' == *(t_original[j]))
continue;
- }
- if (CAL_STRING_EQUAL == strcmp(patterns1[i], patterns2[j])) {
+
+ if (CAL_STRING_EQUAL == strcmp(t_inserted[i], t_original[j])) {
bFind = true;
break;
}
}
+
if (bFind == false) {
char query[CAL_DB_SQL_MAX_LEN] = {0};
long long int start_utime = 0;
char datetime[16] = {0};
- if (strlen("YYYYMMDD") < strlen(patterns1[i])) {
- int y, mon, d, h, min, s;
- sscanf(patterns1[i], CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSSZ,
- &y, &mon, &d, &h, &min, &s);
- start_utime = cal_time_convert_itol(NULL, y, mon, d, h, min, s);
+ if (strlen("YYYYMMDD") < strlen(t_inserted[i])) {
+ int y, m, d, h, n, s;
+ sscanf(t_inserted[i], CAL_DATETIME_FORMAT_YYYYMMDDTHHMMSSZ, &y, &m, &d, &h, &n, &s);
+ start_utime = cal_time_convert_itol(NULL, y, m, d, h, n, s);
} else {
- snprintf(datetime, sizeof(datetime),
- "%s", patterns1[i]);
-
+ snprintf(datetime, sizeof(datetime), "%s", t_inserted[i]);
}
- snprintf(query, sizeof(query),
- "INSERT INTO %s ("
- "type, "
- "created_ver, changed_ver, "
- "calendar_id, "
- "original_event_id, "
- "recurrence_id, "
- "is_deleted, "
- "dtstart_type, "
- "dtstart_utime, "
- "dtstart_datetime, "
- "dtstart_tzid, "
- "dtend_type, "
- "dtend_utime, "
- "dtend_datetime, "
- "dtend_tzid"
- ") SELECT %d,"
- "created_ver, %d, "
- "calendar_id, "
- "%d, "
- "'%s', "
- "1, "
- "dtstart_type, "
- "%lld, "
- "'%s', "
- "dtstart_tzid, "
- "dtend_type, "
- "%lld+(dtend_utime-dtstart_utime), "
- "'%s', "
- "dtend_tzid "
- "FROM %s "
- "WHERE id = %d; ",
- CAL_TABLE_SCHEDULE,
- CAL_SCH_TYPE_EVENT,
- input_ver,
- event_id,
- patterns1[i],
- start_utime,
- datetime,
- start_utime,
- datetime,
- CAL_TABLE_SCHEDULE,
- event_id
- );
+
+ snprintf(query, sizeof(query), "INSERT INTO "CAL_TABLE_SCHEDULE" ("
+ "type, created_ver, changed_ver, calendar_id, original_event_id, "
+ "recurrence_id, is_deleted, dtstart_type, dtstart_utime, "
+ "dtstart_datetime, dtstart_tzid, dtend_type, dtend_utime, "
+ "dtend_datetime, dtend_tzid"
+ ") SELECT %d, created_ver, %d, calendar_id, %d, '%s', 1, dtstart_type, "
+ "%lld, '%s', dtstart_tzid, dtend_type, %lld+(dtend_utime-dtstart_utime), "
+ "'%s', dtend_tzid "
+ "FROM "CAL_TABLE_SCHEDULE" WHERE id = %d ",
+ CAL_SCH_TYPE_EVENT, input_ver, event_id, t_inserted[i], start_utime,
+ datetime, start_utime, datetime, event_id);
ret = cal_db_util_query_exec(query);
if (CALENDAR_ERROR_NONE != ret) {
/* LCOV_EXCL_START */
/* LCOV_EXCL_STOP */
}
int event_id = cal_db_util_last_insert_id();
- DBG("last id(%d)", event_id);
+ SECURE("event id(%d)", event_id);
ids[exception_count] = event_id;
exception_count++;
}
if (exception_len)
*exception_len = exception_count;
- g_strfreev(patterns1);
- g_strfreev(patterns2);
+ if (needs_update)
+ *needs_update = len_inserted > len_original ? true : false;
+
+ g_strfreev(t_inserted);
+ g_strfreev(t_original);
return ret;
}