ae5686f2611361425608ceff75ddba4f8962df29
[platform/core/pim/calendar-service.git] / server / db / cal_db_instance_helper.c
1 /*
2  * Calendar Service
3  *
4  * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include "cal_typedef.h"
21 #include "cal_db.h"
22 #include "cal_db_util.h"
23 #include "cal_internal.h"
24 #include "calendar_errors.h"
25 #include "cal_db_instance_helper.h"
26
27 int cal_db_instance_helper_insert_utime_instance(int event_id, long long int s, long long int e)
28 {
29         int ret = 0;
30         char query[CAL_DB_SQL_MAX_LEN] = {0};
31         snprintf(query, sizeof(query), "INSERT INTO %s (event_id, dtstart_utime, dtend_utime) "
32                         "VALUES (%d, %lld, %lld) ", CAL_TABLE_NORMAL_INSTANCE, event_id, s, e);
33
34         ret = cal_db_util_query_exec(query);
35         if (CALENDAR_ERROR_NONE != ret) {
36                 ERR("cal_db_util_query_exec() Fail(%d)", ret);
37                 SECURE("[%s]", query);
38                 return ret;
39         }
40         return CALENDAR_ERROR_NONE;
41 }
42
43 int cal_db_instance_helper_insert_localtime_instance(int event_id, const char *s, const char *e)
44 {
45         int ret = 0;
46         char query[CAL_DB_SQL_MAX_LEN] = {0};
47         snprintf(query, sizeof(query), "INSERT INTO %s (event_id, dtstart_datetime, dtend_datetime) "
48                         "VALUES (%d, '%s', '%s') ", CAL_TABLE_ALLDAY_INSTANCE, event_id, s, e);
49
50         ret = cal_db_util_query_exec(query);
51         if (CALENDAR_ERROR_NONE != ret) {
52                 ERR("cal_db_util_query_exec() Fail(%d)", ret);
53                 SECURE("[%s]", query);
54                 return ret;
55         }
56         return CALENDAR_ERROR_NONE;
57 }
58