4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include "cal_internal.h"
23 #include "cal_typedef.h"
25 #include "cal_record.h"
27 #include "cal_db_util.h"
29 #include "cal_db_query.h"
30 #include "cal_utils.h"
32 static int _cal_db_timezone_insert_record(calendar_record_h record, int* id);
33 static int _cal_db_timezone_get_record(int id, calendar_record_h* out_record);
34 static int _cal_db_timezone_update_record(calendar_record_h record);
35 static int _cal_db_timezone_delete_record(int id);
36 static int _cal_db_timezone_get_all_records(int offset, int limit, calendar_list_h* out_list);
37 static int _cal_db_timezone_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
38 static int _cal_db_timezone_delete_records(int ids[], int count);
39 static int _cal_db_timezone_get_count(int *out_count);
40 static int _cal_db_timezone_get_count_with_query(calendar_query_h query, int *out_count);
41 static int _cal_db_timezone_replace_record(calendar_record_h record, int id);
42 static int _cal_db_timezone_replace_records(const calendar_list_h list, int ids[], int count);
47 static void _cal_db_timezone_get_stmt(sqlite3_stmt *stmt, calendar_record_h record);
48 static void _cal_db_timezone_get_property_stmt(sqlite3_stmt *stmt,
49 unsigned int property, int stmt_count, calendar_record_h record);
50 static void _cal_db_timezone_get_projection_stmt(sqlite3_stmt *stmt,
51 const unsigned int *projection, const int projection_count,
52 calendar_record_h record);
53 static void _cal_db_timezone_get_stmt(sqlite3_stmt *stmt, calendar_record_h record);
54 static int _cal_db_timezone_update_projection(calendar_record_h record);
56 cal_db_plugin_cb_s cal_db_timezone_plugin_cb = {
57 .is_query_only = false,
58 .insert_record = _cal_db_timezone_insert_record,
59 .get_record = _cal_db_timezone_get_record,
60 .update_record = _cal_db_timezone_update_record,
61 .delete_record = _cal_db_timezone_delete_record,
62 .get_all_records = _cal_db_timezone_get_all_records,
63 .get_records_with_query = _cal_db_timezone_get_records_with_query,
64 .insert_records = NULL,
65 .update_records = NULL,
66 .delete_records = _cal_db_timezone_delete_records,
67 .get_count = _cal_db_timezone_get_count,
68 .get_count_with_query = _cal_db_timezone_get_count_with_query,
69 .replace_record = _cal_db_timezone_replace_record,
70 .replace_records = _cal_db_timezone_replace_records
73 static int _cal_db_timezone_insert_record(calendar_record_h record, int* id)
75 int ret = CALENDAR_ERROR_NONE;
77 int calendar_book_id = 0;
78 char query[CAL_DB_SQL_MAX_LEN];
80 cal_timezone_s* timezone = (cal_timezone_s*)(record);
81 calendar_record_h record_calendar = NULL;
83 RETV_IF(NULL == timezone, CALENDAR_ERROR_INVALID_PARAMETER);
85 ret = calendar_record_get_int(record,
86 _calendar_timezone.calendar_book_id, &calendar_book_id);
87 DBG("calendar_book_id(%d)", calendar_book_id);
89 ret = cal_db_get_record(_calendar_book._uri, calendar_book_id, &record_calendar);
90 RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "cal_db_get_record() Fail(%d)", ret);
91 calendar_record_destroy(record_calendar, true);
93 if (timezone->standard_name) {
94 snprintf(query, sizeof(query), "SELECT count(*), id FROM %s WHERE standard_name=? ",
96 ret = cal_db_util_query_prepare(query, &stmt);
97 if (CALENDAR_ERROR_NONE != ret) {
99 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
100 SECURE("query[%s]", query);
104 cal_db_util_stmt_bind_text(stmt, 1, timezone->standard_name);
106 ret = cal_db_util_stmt_step(stmt);
107 if (CAL_SQLITE_ROW != ret) {
108 /* LCOV_EXCL_START */
109 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
110 sqlite3_finalize(stmt);
116 int count = sqlite3_column_int(stmt, index++);
117 int timezone_id = sqlite3_column_int(stmt, index++);
118 sqlite3_finalize(stmt);
121 DBG("Already exist which tzid name[%s] id(%d)", timezone->standard_name, timezone_id);
123 return CALENDAR_ERROR_NONE;
125 DBG("Not registered timezone in the table, so insert timezone.");
128 snprintf(query, sizeof(query), "INSERT INTO %s(tz_offset_from_gmt ,standard_name, "
129 "std_start_month ,std_start_position_of_week ,std_start_day, "
130 "std_start_hour ,standard_bias ,day_light_name ,day_light_start_month, "
131 "day_light_start_position_of_week ,day_light_start_day, "
132 "day_light_start_hour ,day_light_bias, calendar_id) "
133 "VALUES(%d,?,%d,%d,%d,%d,%d,?,%d,%d,%d,%d,%d,%d)",
135 timezone->tz_offset_from_gmt,
136 timezone->std_start_month,
137 timezone->std_start_position_of_week,
138 timezone->std_start_day,
139 timezone->std_start_hour,
140 timezone->standard_bias,
141 timezone->day_light_start_month,
142 timezone->day_light_start_position_of_week,
143 timezone->day_light_start_day,
144 timezone->day_light_start_hour,
145 timezone->day_light_bias,
146 timezone->calendar_id);
148 ret = cal_db_util_query_prepare(query, &stmt);
149 if (CALENDAR_ERROR_NONE != ret) {
150 /* LCOV_EXCL_START */
151 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
152 SECURE("query[%s]", query);
157 if (timezone->standard_name)
158 cal_db_util_stmt_bind_text(stmt, 1, timezone->standard_name);
160 if (timezone->day_light_name)
161 cal_db_util_stmt_bind_text(stmt, 2, timezone->day_light_name);
163 ret = cal_db_util_stmt_step(stmt);
164 sqlite3_finalize(stmt);
165 if (CALENDAR_ERROR_NONE != ret) {
166 /* LCOV_EXCL_START */
167 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
171 index = cal_db_util_last_insert_id();
176 return CALENDAR_ERROR_NONE;
179 static int _cal_db_timezone_get_record(int id, calendar_record_h* out_record)
181 char query[CAL_DB_SQL_MAX_LEN];
182 sqlite3_stmt *stmt = NULL;
185 ret = calendar_record_create(_calendar_timezone._uri, out_record);
186 if (CALENDAR_ERROR_NONE != ret) {
187 /* LCOV_EXCL_START */
188 ERR("calendar_record_create() Fail(%d)", ret);
189 return CALENDAR_ERROR_OUT_OF_MEMORY;
193 snprintf(query, sizeof(query), "SELECT * FROM %s WHERE id = %d AND "
194 "calendar_id IN (select id from %s where deleted = 0)",
195 CAL_TABLE_TIMEZONE, id,
197 ret = cal_db_util_query_prepare(query, &stmt);
198 if (CALENDAR_ERROR_NONE != ret) {
199 /* LCOV_EXCL_START */
200 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
201 SECURE("query[%s]", query);
202 calendar_record_destroy(*out_record, true);
208 ret = cal_db_util_stmt_step(stmt);
209 if (CAL_SQLITE_ROW != ret) {
210 /* LCOV_EXCL_START */
211 ERR("cal_db_util_stmt_step() Faile%d)", ret);
212 sqlite3_finalize(stmt);
213 calendar_record_destroy(*out_record, true);
215 if (CALENDAR_ERROR_NONE == ret)
216 return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
221 _cal_db_timezone_get_stmt(stmt, *out_record);
223 sqlite3_finalize(stmt);
226 return CALENDAR_ERROR_NONE;
229 static int _cal_db_timezone_update_record(calendar_record_h record)
231 char query[CAL_DB_SQL_MAX_LEN] = {0};
232 sqlite3_stmt *stmt = NULL;
233 cal_timezone_s* timezone_info = (cal_timezone_s*)(record);
236 RETV_IF(NULL == timezone_info, CALENDAR_ERROR_INVALID_PARAMETER);
238 if (timezone_info->common.properties_flags)
239 return _cal_db_timezone_update_projection(record);
241 snprintf(query, sizeof(query), "UPDATE %s SET "
242 "tz_offset_from_gmt=%d,"
244 "std_start_month=%d,"
245 "std_start_position_of_week=%d,"
250 "day_light_start_month=%d,"
251 "day_light_start_position_of_week=%d,"
252 "day_light_start_day=%d,"
253 "day_light_start_hour=%d,"
254 "day_light_bias=%d, "
258 timezone_info->tz_offset_from_gmt,
259 timezone_info->std_start_month,
260 timezone_info->std_start_position_of_week,
261 timezone_info->std_start_day,
262 timezone_info->std_start_hour,
263 timezone_info->standard_bias,
264 timezone_info->day_light_start_month,
265 timezone_info->day_light_start_position_of_week,
266 timezone_info->day_light_start_day,
267 timezone_info->day_light_start_hour,
268 timezone_info->day_light_bias,
269 timezone_info->calendar_id,
270 timezone_info->index);
272 ret = cal_db_util_query_prepare(query, &stmt);
273 if (CALENDAR_ERROR_NONE != ret) {
274 /* LCOV_EXCL_START */
275 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
276 SECURE("query[%s]", query);
281 if (timezone_info->standard_name)
282 cal_db_util_stmt_bind_text(stmt, 1, timezone_info->standard_name);
284 if (timezone_info->day_light_name)
285 cal_db_util_stmt_bind_text(stmt, 2, timezone_info->day_light_name);
287 ret = cal_db_util_stmt_step(stmt);
288 sqlite3_finalize(stmt);
289 if (CALENDAR_ERROR_NONE != ret) {
290 /* LCOV_EXCL_START */
291 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
296 return CALENDAR_ERROR_NONE;
299 static int _cal_db_timezone_delete_record(int id)
301 char query[CAL_DB_SQL_MAX_LEN] = {0};
304 snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d", CAL_TABLE_TIMEZONE, id);
305 ret = cal_db_util_query_exec(query);
306 if (CALENDAR_ERROR_NONE != ret) {
307 /* LCOV_EXCL_START */
308 ERR("cal_db_util_query_exec() Fail(%d)", ret);
309 SECURE("[%s]", query);
314 return CALENDAR_ERROR_NONE;
317 static int _cal_db_timezone_replace_record(calendar_record_h record, int id)
319 char query[CAL_DB_SQL_MAX_LEN] = {0};
320 sqlite3_stmt *stmt = NULL;
321 cal_timezone_s* timezone_info = (cal_timezone_s*)(record);
324 RETV_IF(NULL == timezone_info, CALENDAR_ERROR_INVALID_PARAMETER);
325 timezone_info->index = id;
327 if (timezone_info->common.properties_flags)
328 return _cal_db_timezone_update_projection(record);
330 snprintf(query, sizeof(query), "UPDATE %s SET "
331 "tz_offset_from_gmt=%d,"
333 "std_start_month=%d,"
334 "std_start_position_of_week=%d,"
339 "day_light_start_month=%d,"
340 "day_light_start_position_of_week=%d,"
341 "day_light_start_day=%d,"
342 "day_light_start_hour=%d,"
343 "day_light_bias=%d, "
347 timezone_info->tz_offset_from_gmt,
348 timezone_info->std_start_month,
349 timezone_info->std_start_position_of_week,
350 timezone_info->std_start_day,
351 timezone_info->std_start_hour,
352 timezone_info->standard_bias,
353 timezone_info->day_light_start_month,
354 timezone_info->day_light_start_position_of_week,
355 timezone_info->day_light_start_day,
356 timezone_info->day_light_start_hour,
357 timezone_info->day_light_bias,
358 timezone_info->calendar_id,
361 ret = cal_db_util_query_prepare(query, &stmt);
362 if (CALENDAR_ERROR_NONE != ret) {
363 /* LCOV_EXCL_START */
364 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
365 SECURE("query[%s]", query);
370 if (timezone_info->standard_name)
371 cal_db_util_stmt_bind_text(stmt, 1, timezone_info->standard_name);
373 if (timezone_info->day_light_name)
374 cal_db_util_stmt_bind_text(stmt, 2, timezone_info->day_light_name);
376 ret = cal_db_util_stmt_step(stmt);
377 sqlite3_finalize(stmt);
378 if (CALENDAR_ERROR_NONE != ret) {
379 /* LCOV_EXCL_START */
380 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
385 return CALENDAR_ERROR_NONE;
388 static int _cal_db_timezone_get_all_records(int offset, int limit, calendar_list_h* out_list)
390 int ret = CALENDAR_ERROR_NONE;
391 char query[CAL_DB_SQL_MAX_LEN] = {0};
392 char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
393 char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
394 sqlite3_stmt *stmt = NULL;
396 RETV_IF(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER);
398 ret = calendar_list_create(out_list);
399 RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "calendar_list_create() Fail(%d)", ret);
402 snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
405 snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
407 snprintf(query, sizeof(query), "SELECT * FROM %s where "
408 "calendar_id IN (select id from %s where deleted = 0) "
415 ret = cal_db_util_query_prepare(query, &stmt);
416 if (CALENDAR_ERROR_NONE != ret) {
417 /* LCOV_EXCL_START */
418 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
419 SECURE("query[%s]", query);
420 calendar_list_destroy(*out_list, true);
426 while (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) {
427 calendar_record_h record;
428 ret = calendar_record_create(_calendar_timezone._uri, &record);
429 if (CALENDAR_ERROR_NONE != ret) {
430 /* LCOV_EXCL_START */
431 calendar_list_destroy(*out_list, true);
433 sqlite3_finalize(stmt);
437 _cal_db_timezone_get_stmt(stmt, record);
439 ret = calendar_list_add(*out_list, record);
440 if (CALENDAR_ERROR_NONE != ret) {
441 /* LCOV_EXCL_START */
442 calendar_list_destroy(*out_list, true);
444 calendar_record_destroy(record, true);
445 sqlite3_finalize(stmt);
451 sqlite3_finalize(stmt);
452 return CALENDAR_ERROR_NONE;
455 static int _cal_db_timezone_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
457 cal_query_s *que = NULL;
458 int ret = CALENDAR_ERROR_NONE;
459 char *condition = NULL;
460 char *projection = NULL;
462 GSList *bind_text = NULL, *cursor = NULL;
463 char *query_str = NULL;
464 sqlite3_stmt *stmt = NULL;
467 que = (cal_query_s *)query;
471 ret = cal_db_query_create_condition(query, &condition, &bind_text);
472 if (CALENDAR_ERROR_NONE != ret) {
473 /* LCOV_EXCL_START */
474 ERR("cal_db_query_create_condition() Fail(%d), ret");
480 /* make: projection */
481 ret = cal_db_query_create_projection(query, &projection);
483 /* query: projection */
485 cal_db_append_string(&query_str, "SELECT");
486 cal_db_append_string(&query_str, projection);
487 cal_db_append_string(&query_str, "FROM");
488 cal_db_append_string(&query_str, CAL_TABLE_TIMEZONE);
489 CAL_FREE(projection);
491 cal_db_append_string(&query_str, "SELECT * FROM");
492 cal_db_append_string(&query_str, CAL_TABLE_TIMEZONE);
495 /* query: condition */
497 cal_db_append_string(&query_str, "WHERE");
498 cal_db_append_string(&query_str, condition);
500 cal_db_append_string(&query_str, "AND calendar_id IN (select id from");
501 cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
502 cal_db_append_string(&query_str, "where deleted = 0)");
504 cal_db_append_string(&query_str, "WHERE calendar_id IN (select id from");
505 cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
506 cal_db_append_string(&query_str, "where deleted = 0)");
510 ret = cal_db_query_create_order(query, condition, &order);
512 cal_db_append_string(&query_str, order);
516 char buf[CAL_STR_SHORT_LEN32] = {0};
518 snprintf(buf, sizeof(buf), "LIMIT %d", limit);
519 cal_db_append_string(&query_str, buf);
521 snprintf(buf, sizeof(buf), "OFFSET %d", offset);
522 cal_db_append_string(&query_str, buf);
527 ret = cal_db_util_query_prepare(query_str, &stmt);
528 if (CALENDAR_ERROR_NONE != ret) {
529 /* LCOV_EXCL_START */
530 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
531 SECURE("query[%s]", query_str);
533 g_slist_free_full(bind_text, free);
543 for (cursor = bind_text, i = 1; cursor; cursor = cursor->next, i++)
544 cal_db_util_stmt_bind_text(stmt, i, cursor->data);
547 ret = calendar_list_create(out_list);
548 if (CALENDAR_ERROR_NONE != ret) {
549 /* LCOV_EXCL_START */
550 ERR("calendar_list_create() Fail");
552 g_slist_free_full(bind_text, free);
556 sqlite3_finalize(stmt);
561 while (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) {
562 calendar_record_h record;
563 ret = calendar_record_create(_calendar_timezone._uri, &record);
564 if (CALENDAR_ERROR_NONE != ret) {
565 /* LCOV_EXCL_START */
566 calendar_list_destroy(*out_list, true);
570 g_slist_free_full(bind_text, free);
574 sqlite3_finalize(stmt);
578 if (0 < que->projection_count) {
579 cal_record_set_projection(record,
580 que->projection, que->projection_count, que->property_count);
582 _cal_db_timezone_get_projection_stmt(stmt,
583 que->projection, que->projection_count,
586 _cal_db_timezone_get_stmt(stmt, record);
589 ret = calendar_list_add(*out_list, record);
590 if (CALENDAR_ERROR_NONE != ret) {
591 /* LCOV_EXCL_START */
592 calendar_list_destroy(*out_list, true);
594 calendar_record_destroy(record, true);
597 g_slist_free_full(bind_text, free);
601 sqlite3_finalize(stmt);
608 g_slist_free_full(bind_text, free);
612 sqlite3_finalize(stmt);
614 return CALENDAR_ERROR_NONE;
617 static int _cal_db_timezone_delete_records(int ids[], int count)
621 for (i = 0; i < count; i++) {
622 ret = _cal_db_timezone_delete_record(ids[i]);
623 if (CALENDAR_ERROR_NONE != ret) {
624 /* LCOV_EXCL_START */
625 ERR("_cal_db_timezone_delete_record() Fail(%d)", ret);
626 return CALENDAR_ERROR_DB_FAILED;
630 return CALENDAR_ERROR_NONE;
633 static int _cal_db_timezone_replace_records(const calendar_list_h list, int ids[], int count)
635 calendar_record_h record;
639 RETV_IF(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
641 ret = calendar_list_first(list);
642 if (CALENDAR_ERROR_NONE != ret) {
643 /* LCOV_EXCL_START */
644 ERR("list first error");
649 for (i = 0; i < count; i++) {
650 if (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(list, &record)) {
651 ret = _cal_db_timezone_replace_record(record, ids[i]);
652 if (CALENDAR_ERROR_NONE != ret) {
653 /* LCOV_EXCL_START */
654 ERR("_cal_db_timezone_replace_record() Fail(%d)", ret);
655 return CALENDAR_ERROR_DB_FAILED;
659 if (CALENDAR_ERROR_NO_DATA != calendar_list_next(list))
663 return CALENDAR_ERROR_NONE;
666 static int _cal_db_timezone_get_count(int *out_count)
668 char query[CAL_DB_SQL_MAX_LEN] = {0};
672 RETV_IF(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER);
674 snprintf(query, sizeof(query), "SELECT count(*) FROM %s where "
675 "calendar_id IN (select id from %s where deleted = 0)",
679 ret = cal_db_util_query_get_first_int_result(query, NULL, &count);
680 if (CALENDAR_ERROR_NONE != ret) {
681 /* LCOV_EXCL_START */
682 ERR("cal_db_util_query_get_first_int_result() Fail");
686 DBG("%s=%d", query, count);
689 return CALENDAR_ERROR_NONE;
692 static int _cal_db_timezone_get_count_with_query(calendar_query_h query, int *out_count)
694 cal_query_s *que = NULL;
695 int ret = CALENDAR_ERROR_NONE;
696 char *condition = NULL;
697 char *query_str = NULL;
700 GSList *bind_text = NULL;
702 que = (cal_query_s *)query;
704 if (CAL_STRING_EQUAL == strcmp(que->view_uri, CALENDAR_VIEW_TIMEZONE)) {
705 table_name = cal_strdup(CAL_TABLE_TIMEZONE);
707 /* LCOV_EXCL_START */
708 ERR("uri(%s) not support get records with query", que->view_uri);
709 return CALENDAR_ERROR_INVALID_PARAMETER;
715 ret = cal_db_query_create_condition(query, &condition, &bind_text);
716 if (CALENDAR_ERROR_NONE != ret) {
717 /* LCOV_EXCL_START */
718 ERR("cal_db_query_create_condition() Fail(%d), ret");
719 CAL_FREE(table_name);
726 cal_db_append_string(&query_str, "SELECT count(*) FROM");
727 cal_db_append_string(&query_str, table_name);
728 CAL_FREE(table_name);
730 /* query: condition */
732 cal_db_append_string(&query_str, "WHERE");
733 cal_db_append_string(&query_str, condition);
734 cal_db_append_string(&query_str, "AND calendar_id IN (select id from");
735 cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
736 cal_db_append_string(&query_str, "where deleted = 0)");
739 cal_db_append_string(&query_str, "WHERE calendar_id IN (select id from");
740 cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
741 cal_db_append_string(&query_str, "where deleted = 0)");
745 ret = cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
746 if (CALENDAR_ERROR_NONE != ret) {
747 /* LCOV_EXCL_START */
748 ERR("cal_db_util_query_get_first_int_result() Fail");
750 g_slist_free_full(bind_text, free);
757 DBG("%s=%d", query_str, count);
762 g_slist_free_full(bind_text, free);
766 return CALENDAR_ERROR_NONE;
769 static void _cal_db_timezone_get_stmt(sqlite3_stmt *stmt, calendar_record_h record)
771 cal_timezone_s* timezone = (cal_timezone_s*)(record);
773 const unsigned char *temp;
775 timezone->index = sqlite3_column_int(stmt, count++);
776 timezone->tz_offset_from_gmt = sqlite3_column_int(stmt, count++);
778 temp = sqlite3_column_text(stmt, count++);
779 timezone->standard_name = cal_strdup((const char *)temp);
781 timezone->std_start_month = sqlite3_column_int(stmt, count++);
782 timezone->std_start_position_of_week = sqlite3_column_int(stmt, count++);
783 timezone->std_start_day = sqlite3_column_int(stmt, count++);
784 timezone->std_start_hour = sqlite3_column_int(stmt, count++);
785 timezone->standard_bias = sqlite3_column_int(stmt, count++);
787 temp = sqlite3_column_text(stmt, count++);
788 timezone->day_light_name = cal_strdup((const char *)temp);
790 timezone->day_light_start_month = sqlite3_column_int(stmt, count++);
791 timezone->day_light_start_position_of_week = sqlite3_column_int(stmt, count++);
792 timezone->day_light_start_day = sqlite3_column_int(stmt, count++);
793 timezone->day_light_start_hour = sqlite3_column_int(stmt, count++);
794 timezone->day_light_bias = sqlite3_column_int(stmt, count++);
796 timezone->calendar_id = sqlite3_column_int(stmt, count++);
799 static void _cal_db_timezone_get_property_stmt(sqlite3_stmt *stmt,
800 unsigned int property, int stmt_count, calendar_record_h record)
802 cal_timezone_s* timezone = (cal_timezone_s*)(record);
803 const unsigned char *temp;
806 case CAL_PROPERTY_TIMEZONE_ID:
807 timezone->index = sqlite3_column_int(stmt, stmt_count);
809 case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
810 timezone->tz_offset_from_gmt = sqlite3_column_int(stmt, stmt_count);
812 case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
813 temp = sqlite3_column_text(stmt, stmt_count);
814 timezone->standard_name = cal_strdup((const char *)temp);
816 case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
817 timezone->std_start_month = sqlite3_column_int(stmt, stmt_count);
819 case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
820 timezone->std_start_position_of_week = sqlite3_column_int(stmt, stmt_count);
822 case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
823 timezone->std_start_day = sqlite3_column_int(stmt, stmt_count);
825 case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
826 timezone->std_start_hour = sqlite3_column_int(stmt, stmt_count);
828 case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
829 timezone->standard_bias = sqlite3_column_int(stmt, stmt_count);
831 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
832 temp = sqlite3_column_text(stmt, stmt_count);
833 timezone->day_light_name = cal_strdup((const char *)temp);
835 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
836 timezone->day_light_start_month = sqlite3_column_int(stmt, stmt_count);
838 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
839 timezone->day_light_start_position_of_week = sqlite3_column_int(stmt, stmt_count);
841 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
842 timezone->day_light_start_day = sqlite3_column_int(stmt, stmt_count);
844 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
845 timezone->day_light_start_hour = sqlite3_column_int(stmt, stmt_count);
847 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
848 timezone->day_light_bias = sqlite3_column_int(stmt, stmt_count);
850 case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
851 timezone->calendar_id = sqlite3_column_int(stmt, stmt_count);
854 /* LCOV_EXCL_START */
855 ERR("Invalid property(0x%x)", property);
863 static void _cal_db_timezone_get_projection_stmt(sqlite3_stmt *stmt,
864 const unsigned int *projection, const int projection_count,
865 calendar_record_h record)
869 for (i = 0; i < projection_count; i++)
870 _cal_db_timezone_get_property_stmt(stmt, projection[i], i, record);
873 static int _cal_db_timezone_update_projection(calendar_record_h record)
875 char query[CAL_DB_SQL_MAX_LEN] = {0};
876 sqlite3_stmt *stmt = NULL;
877 cal_timezone_s* timezone = (cal_timezone_s*)(record);
880 GSList *bind_text = NULL;
881 GSList *cursor = NULL;
883 ret = cal_db_query_create_projection_update_set(record, &set, &bind_text);
884 RETV_IF(CALENDAR_ERROR_NONE != ret, ret);
886 snprintf(query, sizeof(query), "UPDATE %s SET %s WHERE id = %d",
887 CAL_TABLE_TIMEZONE, set, timezone->index);
889 ret = cal_db_util_query_prepare(query, &stmt);
890 if (CALENDAR_ERROR_NONE != ret) {
891 /* LCOV_EXCL_START */
892 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
893 SECURE("query[%s]", query);
896 g_slist_free_full(bind_text, free);
905 for (cursor = bind_text, i = 1; cursor; cursor = cursor->next, i++)
906 cal_db_util_stmt_bind_text(stmt, i, cursor->data);
909 ret = cal_db_util_stmt_step(stmt);
910 sqlite3_finalize(stmt);
913 g_slist_free_full(bind_text, free);
916 if (CALENDAR_ERROR_NONE != ret) {
917 /* LCOV_EXCL_START */
918 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
923 return CALENDAR_ERROR_NONE;