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) {
98 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
99 SECURE("query[%s]", query);
102 cal_db_util_stmt_bind_text(stmt, 1, timezone->standard_name);
104 ret = cal_db_util_stmt_step(stmt);
105 if (CAL_SQLITE_ROW != ret) {
106 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
107 sqlite3_finalize(stmt);
112 int count = sqlite3_column_int(stmt, index++);
113 int timezone_id = sqlite3_column_int(stmt, index++);
114 sqlite3_finalize(stmt);
117 DBG("Already exist which tzid name[%s] id(%d)", timezone->standard_name, timezone_id);
119 return CALENDAR_ERROR_NONE;
121 DBG("Not registered timezone in the table, so insert timezone.");
124 snprintf(query, sizeof(query), "INSERT INTO %s(tz_offset_from_gmt ,standard_name, "
125 "std_start_month ,std_start_position_of_week ,std_start_day, "
126 "std_start_hour ,standard_bias ,day_light_name ,day_light_start_month, "
127 "day_light_start_position_of_week ,day_light_start_day, "
128 "day_light_start_hour ,day_light_bias, calendar_id) "
129 "VALUES(%d,?,%d,%d,%d,%d,%d,?,%d,%d,%d,%d,%d,%d)",
131 timezone->tz_offset_from_gmt,
132 timezone->std_start_month,
133 timezone->std_start_position_of_week,
134 timezone->std_start_day,
135 timezone->std_start_hour,
136 timezone->standard_bias,
137 timezone->day_light_start_month,
138 timezone->day_light_start_position_of_week,
139 timezone->day_light_start_day,
140 timezone->day_light_start_hour,
141 timezone->day_light_bias,
142 timezone->calendar_id);
144 ret = cal_db_util_query_prepare(query, &stmt);
145 if (CALENDAR_ERROR_NONE != ret) {
146 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
147 SECURE("query[%s]", query);
151 if (timezone->standard_name)
152 cal_db_util_stmt_bind_text(stmt, 1, timezone->standard_name);
154 if (timezone->day_light_name)
155 cal_db_util_stmt_bind_text(stmt, 2, timezone->day_light_name);
157 ret = cal_db_util_stmt_step(stmt);
158 sqlite3_finalize(stmt);
159 if (CALENDAR_ERROR_NONE != ret) {
160 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
163 index = cal_db_util_last_insert_id();
168 return CALENDAR_ERROR_NONE;
171 static int _cal_db_timezone_get_record(int id, calendar_record_h* out_record)
173 char query[CAL_DB_SQL_MAX_LEN];
174 sqlite3_stmt *stmt = NULL;
177 ret = calendar_record_create(_calendar_timezone._uri, out_record);
178 if (CALENDAR_ERROR_NONE != ret) {
179 ERR("calendar_record_create() Fail(%d)", ret);
180 return CALENDAR_ERROR_OUT_OF_MEMORY;
183 snprintf(query, sizeof(query), "SELECT * FROM %s WHERE id = %d AND "
184 "calendar_id IN (select id from %s where deleted = 0)",
185 CAL_TABLE_TIMEZONE, id,
187 ret = cal_db_util_query_prepare(query, &stmt);
188 if (CALENDAR_ERROR_NONE != ret) {
189 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
190 SECURE("query[%s]", query);
191 calendar_record_destroy(*out_record, true);
196 ret = cal_db_util_stmt_step(stmt);
197 if (CAL_SQLITE_ROW != ret) {
198 ERR("cal_db_util_stmt_step() Faile%d)", ret);
199 sqlite3_finalize(stmt);
200 calendar_record_destroy(*out_record, true);
202 if (CALENDAR_ERROR_NONE == ret)
203 return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
207 _cal_db_timezone_get_stmt(stmt, *out_record);
209 sqlite3_finalize(stmt);
212 return CALENDAR_ERROR_NONE;
215 static int _cal_db_timezone_update_record(calendar_record_h record)
217 char query[CAL_DB_SQL_MAX_LEN] = {0};
218 sqlite3_stmt *stmt = NULL;
219 cal_timezone_s* timezone_info = (cal_timezone_s*)(record);
222 RETV_IF(NULL == timezone_info, CALENDAR_ERROR_INVALID_PARAMETER);
224 if (timezone_info->common.properties_flags)
225 return _cal_db_timezone_update_projection(record);
227 snprintf(query, sizeof(query), "UPDATE %s SET "
228 "tz_offset_from_gmt=%d,"
230 "std_start_month=%d,"
231 "std_start_position_of_week=%d,"
236 "day_light_start_month=%d,"
237 "day_light_start_position_of_week=%d,"
238 "day_light_start_day=%d,"
239 "day_light_start_hour=%d,"
240 "day_light_bias=%d, "
244 timezone_info->tz_offset_from_gmt,
245 timezone_info->std_start_month,
246 timezone_info->std_start_position_of_week,
247 timezone_info->std_start_day,
248 timezone_info->std_start_hour,
249 timezone_info->standard_bias,
250 timezone_info->day_light_start_month,
251 timezone_info->day_light_start_position_of_week,
252 timezone_info->day_light_start_day,
253 timezone_info->day_light_start_hour,
254 timezone_info->day_light_bias,
255 timezone_info->calendar_id,
256 timezone_info->index);
258 ret = cal_db_util_query_prepare(query, &stmt);
259 if (CALENDAR_ERROR_NONE != ret) {
260 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
261 SECURE("query[%s]", query);
265 if (timezone_info->standard_name)
266 cal_db_util_stmt_bind_text(stmt, 1, timezone_info->standard_name);
268 if (timezone_info->day_light_name)
269 cal_db_util_stmt_bind_text(stmt, 2, timezone_info->day_light_name);
271 ret = cal_db_util_stmt_step(stmt);
272 sqlite3_finalize(stmt);
273 if (CALENDAR_ERROR_NONE != ret) {
274 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
278 return CALENDAR_ERROR_NONE;
281 static int _cal_db_timezone_delete_record(int id)
283 char query[CAL_DB_SQL_MAX_LEN] = {0};
286 snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d", CAL_TABLE_TIMEZONE, id);
287 ret = cal_db_util_query_exec(query);
288 if (CALENDAR_ERROR_NONE != ret) {
289 ERR("cal_db_util_query_exec() Fail(%d)", ret);
290 SECURE("[%s]", query);
294 return CALENDAR_ERROR_NONE;
297 static int _cal_db_timezone_replace_record(calendar_record_h record, int id)
299 char query[CAL_DB_SQL_MAX_LEN] = {0};
300 sqlite3_stmt *stmt = NULL;
301 cal_timezone_s* timezone_info = (cal_timezone_s*)(record);
304 RETV_IF(NULL == timezone_info, CALENDAR_ERROR_INVALID_PARAMETER);
305 timezone_info->index = id;
307 if (timezone_info->common.properties_flags)
308 return _cal_db_timezone_update_projection(record);
310 snprintf(query, sizeof(query), "UPDATE %s SET "
311 "tz_offset_from_gmt=%d,"
313 "std_start_month=%d,"
314 "std_start_position_of_week=%d,"
319 "day_light_start_month=%d,"
320 "day_light_start_position_of_week=%d,"
321 "day_light_start_day=%d,"
322 "day_light_start_hour=%d,"
323 "day_light_bias=%d, "
327 timezone_info->tz_offset_from_gmt,
328 timezone_info->std_start_month,
329 timezone_info->std_start_position_of_week,
330 timezone_info->std_start_day,
331 timezone_info->std_start_hour,
332 timezone_info->standard_bias,
333 timezone_info->day_light_start_month,
334 timezone_info->day_light_start_position_of_week,
335 timezone_info->day_light_start_day,
336 timezone_info->day_light_start_hour,
337 timezone_info->day_light_bias,
338 timezone_info->calendar_id,
341 ret = cal_db_util_query_prepare(query, &stmt);
342 if (CALENDAR_ERROR_NONE != ret) {
343 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
344 SECURE("query[%s]", query);
348 if (timezone_info->standard_name)
349 cal_db_util_stmt_bind_text(stmt, 1, timezone_info->standard_name);
351 if (timezone_info->day_light_name)
352 cal_db_util_stmt_bind_text(stmt, 2, timezone_info->day_light_name);
354 ret = cal_db_util_stmt_step(stmt);
355 sqlite3_finalize(stmt);
356 if (CALENDAR_ERROR_NONE != ret) {
357 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
361 return CALENDAR_ERROR_NONE;
364 static int _cal_db_timezone_get_all_records(int offset, int limit, calendar_list_h* out_list)
366 int ret = CALENDAR_ERROR_NONE;
367 char query[CAL_DB_SQL_MAX_LEN] = {0};
368 char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
369 char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
370 sqlite3_stmt *stmt = NULL;
372 RETV_IF(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER);
374 ret = calendar_list_create(out_list);
375 RETVM_IF(CALENDAR_ERROR_NONE != ret, ret, "calendar_list_create() Fail(%d)", ret);
378 snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
381 snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
383 snprintf(query, sizeof(query), "SELECT * FROM %s where "
384 "calendar_id IN (select id from %s where deleted = 0) "
391 ret = cal_db_util_query_prepare(query, &stmt);
392 if (CALENDAR_ERROR_NONE != ret) {
393 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
394 SECURE("query[%s]", query);
395 calendar_list_destroy(*out_list, true);
400 while (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) {
401 calendar_record_h record;
402 ret = calendar_record_create(_calendar_timezone._uri, &record);
403 if (CALENDAR_ERROR_NONE != ret) {
404 calendar_list_destroy(*out_list, true);
406 sqlite3_finalize(stmt);
409 _cal_db_timezone_get_stmt(stmt, record);
411 ret = calendar_list_add(*out_list, record);
412 if (CALENDAR_ERROR_NONE != ret) {
413 calendar_list_destroy(*out_list, true);
415 calendar_record_destroy(record, true);
416 sqlite3_finalize(stmt);
421 sqlite3_finalize(stmt);
422 return CALENDAR_ERROR_NONE;
425 static int _cal_db_timezone_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
427 cal_query_s *que = NULL;
428 int ret = CALENDAR_ERROR_NONE;
429 char *condition = NULL;
430 char *projection = NULL;
432 GSList *bind_text = NULL, *cursor = NULL;
433 char *query_str = NULL;
434 sqlite3_stmt *stmt = NULL;
437 que = (cal_query_s *)query;
441 ret = cal_db_query_create_condition(query, &condition, &bind_text);
442 if (CALENDAR_ERROR_NONE != ret) {
443 ERR("cal_db_query_create_condition() Fail(%d), ret");
448 /* make: projection */
449 ret = cal_db_query_create_projection(query, &projection);
451 /* query: projection */
453 cal_db_append_string(&query_str, "SELECT");
454 cal_db_append_string(&query_str, projection);
455 cal_db_append_string(&query_str, "FROM");
456 cal_db_append_string(&query_str, CAL_TABLE_TIMEZONE);
457 CAL_FREE(projection);
459 cal_db_append_string(&query_str, "SELECT * FROM");
460 cal_db_append_string(&query_str, CAL_TABLE_TIMEZONE);
463 /* query: condition */
465 cal_db_append_string(&query_str, "WHERE");
466 cal_db_append_string(&query_str, condition);
468 cal_db_append_string(&query_str, "AND calendar_id IN (select id from");
469 cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
470 cal_db_append_string(&query_str, "where deleted = 0)");
472 cal_db_append_string(&query_str, "WHERE calendar_id IN (select id from");
473 cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
474 cal_db_append_string(&query_str, "where deleted = 0)");
478 ret = cal_db_query_create_order(query, condition, &order);
480 cal_db_append_string(&query_str, order);
484 char buf[CAL_STR_SHORT_LEN32] = {0};
486 snprintf(buf, sizeof(buf), "LIMIT %d", limit);
487 cal_db_append_string(&query_str, buf);
489 snprintf(buf, sizeof(buf), "OFFSET %d", offset);
490 cal_db_append_string(&query_str, buf);
495 ret = cal_db_util_query_prepare(query_str, &stmt);
496 if (CALENDAR_ERROR_NONE != ret) {
497 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
498 SECURE("query[%s]", query_str);
500 g_slist_free_full(bind_text, free);
509 for (cursor = bind_text, i = 1; cursor; cursor = cursor->next, i++)
510 cal_db_util_stmt_bind_text(stmt, i, cursor->data);
513 ret = calendar_list_create(out_list);
514 if (CALENDAR_ERROR_NONE != ret) {
516 g_slist_free_full(bind_text, free);
520 ERR("calendar_list_create() Fail");
521 sqlite3_finalize(stmt);
525 while (CAL_SQLITE_ROW == cal_db_util_stmt_step(stmt)) {
526 calendar_record_h record;
527 ret = calendar_record_create(_calendar_timezone._uri, &record);
528 if (CALENDAR_ERROR_NONE != ret) {
529 calendar_list_destroy(*out_list, true);
533 g_slist_free_full(bind_text, free);
537 sqlite3_finalize(stmt);
540 if (0 < que->projection_count) {
541 cal_record_set_projection(record,
542 que->projection, que->projection_count, que->property_count);
544 _cal_db_timezone_get_projection_stmt(stmt,
545 que->projection, que->projection_count,
548 _cal_db_timezone_get_stmt(stmt, record);
551 ret = calendar_list_add(*out_list, record);
552 if (CALENDAR_ERROR_NONE != ret) {
553 calendar_list_destroy(*out_list, true);
555 calendar_record_destroy(record, true);
558 g_slist_free_full(bind_text, free);
562 sqlite3_finalize(stmt);
568 g_slist_free_full(bind_text, free);
572 sqlite3_finalize(stmt);
574 return CALENDAR_ERROR_NONE;
577 static int _cal_db_timezone_delete_records(int ids[], int count)
581 for (i = 0; i < count; i++) {
582 ret = _cal_db_timezone_delete_record(ids[i]);
583 if (CALENDAR_ERROR_NONE != ret) {
584 ERR("_cal_db_timezone_delete_record() Fail(%d)", ret);
585 return CALENDAR_ERROR_DB_FAILED;
588 return CALENDAR_ERROR_NONE;
591 static int _cal_db_timezone_replace_records(const calendar_list_h list, int ids[], int count)
593 calendar_record_h record;
597 RETV_IF(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
599 ret = calendar_list_first(list);
600 if (CALENDAR_ERROR_NONE != ret) {
601 ERR("list first error");
605 for (i = 0; i < count; i++) {
606 if (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(list, &record)) {
607 ret = _cal_db_timezone_replace_record(record, ids[i]);
608 if (CALENDAR_ERROR_NONE != ret) {
609 ERR("_cal_db_timezone_replace_record() Fail(%d)", ret);
610 return CALENDAR_ERROR_DB_FAILED;
613 if (CALENDAR_ERROR_NO_DATA != calendar_list_next(list))
617 return CALENDAR_ERROR_NONE;
620 static int _cal_db_timezone_get_count(int *out_count)
622 char query[CAL_DB_SQL_MAX_LEN] = {0};
626 RETV_IF(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER);
628 snprintf(query, sizeof(query), "SELECT count(*) FROM %s where "
629 "calendar_id IN (select id from %s where deleted = 0)",
633 ret = cal_db_util_query_get_first_int_result(query, NULL, &count);
634 if (CALENDAR_ERROR_NONE != ret) {
635 ERR("cal_db_util_query_get_first_int_result() Fail");
638 DBG("%s=%d", query, count);
641 return CALENDAR_ERROR_NONE;
644 static int _cal_db_timezone_get_count_with_query(calendar_query_h query, int *out_count)
646 cal_query_s *que = NULL;
647 int ret = CALENDAR_ERROR_NONE;
648 char *condition = NULL;
649 char *query_str = NULL;
652 GSList *bind_text = NULL;
654 que = (cal_query_s *)query;
656 if (CAL_STRING_EQUAL == strcmp(que->view_uri, CALENDAR_VIEW_TIMEZONE)) {
657 table_name = cal_strdup(CAL_TABLE_TIMEZONE);
659 ERR("uri(%s) not support get records with query", que->view_uri);
660 return CALENDAR_ERROR_INVALID_PARAMETER;
665 ret = cal_db_query_create_condition(query, &condition, &bind_text);
666 if (CALENDAR_ERROR_NONE != ret) {
667 CAL_FREE(table_name);
668 ERR("cal_db_query_create_condition() Fail(%d), ret");
674 cal_db_append_string(&query_str, "SELECT count(*) FROM");
675 cal_db_append_string(&query_str, table_name);
676 CAL_FREE(table_name);
678 /* query: condition */
680 cal_db_append_string(&query_str, "WHERE");
681 cal_db_append_string(&query_str, condition);
682 cal_db_append_string(&query_str, "AND calendar_id IN (select id from");
683 cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
684 cal_db_append_string(&query_str, "where deleted = 0)");
687 cal_db_append_string(&query_str, "WHERE calendar_id IN (select id from");
688 cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
689 cal_db_append_string(&query_str, "where deleted = 0)");
693 ret = cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
694 if (CALENDAR_ERROR_NONE != ret) {
695 ERR("cal_db_util_query_get_first_int_result() Fail");
697 g_slist_free_full(bind_text, free);
703 DBG("%s=%d", query_str, count);
708 g_slist_free_full(bind_text, free);
712 return CALENDAR_ERROR_NONE;
715 static void _cal_db_timezone_get_stmt(sqlite3_stmt *stmt, calendar_record_h record)
717 cal_timezone_s* timezone = (cal_timezone_s*)(record);
719 const unsigned char *temp;
721 timezone->index = sqlite3_column_int(stmt, count++);
722 timezone->tz_offset_from_gmt = sqlite3_column_int(stmt, count++);
724 temp = sqlite3_column_text(stmt, count++);
725 timezone->standard_name = cal_strdup((const char *)temp);
727 timezone->std_start_month = sqlite3_column_int(stmt, count++);
728 timezone->std_start_position_of_week = sqlite3_column_int(stmt, count++);
729 timezone->std_start_day = sqlite3_column_int(stmt, count++);
730 timezone->std_start_hour = sqlite3_column_int(stmt, count++);
731 timezone->standard_bias = sqlite3_column_int(stmt, count++);
733 temp = sqlite3_column_text(stmt, count++);
734 timezone->day_light_name = cal_strdup((const char *)temp);
736 timezone->day_light_start_month = sqlite3_column_int(stmt, count++);
737 timezone->day_light_start_position_of_week = sqlite3_column_int(stmt, count++);
738 timezone->day_light_start_day = sqlite3_column_int(stmt, count++);
739 timezone->day_light_start_hour = sqlite3_column_int(stmt, count++);
740 timezone->day_light_bias = sqlite3_column_int(stmt, count++);
742 timezone->calendar_id = sqlite3_column_int(stmt, count++);
745 static void _cal_db_timezone_get_property_stmt(sqlite3_stmt *stmt,
746 unsigned int property, int stmt_count, calendar_record_h record)
748 cal_timezone_s* timezone = (cal_timezone_s*)(record);
749 const unsigned char *temp;
752 case CAL_PROPERTY_TIMEZONE_ID:
753 timezone->index = sqlite3_column_int(stmt, stmt_count);
755 case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
756 timezone->tz_offset_from_gmt = sqlite3_column_int(stmt, stmt_count);
758 case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
759 temp = sqlite3_column_text(stmt, stmt_count);
760 timezone->standard_name = cal_strdup((const char *)temp);
762 case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
763 timezone->std_start_month = sqlite3_column_int(stmt, stmt_count);
765 case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
766 timezone->std_start_position_of_week = sqlite3_column_int(stmt, stmt_count);
768 case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
769 timezone->std_start_day = sqlite3_column_int(stmt, stmt_count);
771 case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
772 timezone->std_start_hour = sqlite3_column_int(stmt, stmt_count);
774 case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
775 timezone->standard_bias = sqlite3_column_int(stmt, stmt_count);
777 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
778 temp = sqlite3_column_text(stmt, stmt_count);
779 timezone->day_light_name = cal_strdup((const char *)temp);
781 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
782 timezone->day_light_start_month = sqlite3_column_int(stmt, stmt_count);
784 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
785 timezone->day_light_start_position_of_week = sqlite3_column_int(stmt, stmt_count);
787 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
788 timezone->day_light_start_day = sqlite3_column_int(stmt, stmt_count);
790 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
791 timezone->day_light_start_hour = sqlite3_column_int(stmt, stmt_count);
793 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
794 timezone->day_light_bias = sqlite3_column_int(stmt, stmt_count);
796 case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
797 timezone->calendar_id = sqlite3_column_int(stmt, stmt_count);
800 ERR("Invalid property(0x%x)", property);
807 static void _cal_db_timezone_get_projection_stmt(sqlite3_stmt *stmt,
808 const unsigned int *projection, const int projection_count,
809 calendar_record_h record)
813 for (i = 0; i < projection_count; i++)
814 _cal_db_timezone_get_property_stmt(stmt, projection[i], i, record);
817 static int _cal_db_timezone_update_projection(calendar_record_h record)
819 char query[CAL_DB_SQL_MAX_LEN] = {0};
820 sqlite3_stmt *stmt = NULL;
821 cal_timezone_s* timezone = (cal_timezone_s*)(record);
824 GSList *bind_text = NULL;
825 GSList *cursor = NULL;
827 ret = cal_db_query_create_projection_update_set(record, &set, &bind_text);
828 RETV_IF(CALENDAR_ERROR_NONE != ret, ret);
830 snprintf(query, sizeof(query), "UPDATE %s SET %s WHERE id = %d",
831 CAL_TABLE_TIMEZONE, set, timezone->index);
833 ret = cal_db_util_query_prepare(query, &stmt);
834 if (CALENDAR_ERROR_NONE != ret) {
835 ERR("cal_db_util_query_prepare() Fail(%d)", ret);
836 SECURE("query[%s]", query);
839 g_slist_free_full(bind_text, free);
847 for (cursor = bind_text, i = 1; cursor; cursor = cursor->next, i++)
848 cal_db_util_stmt_bind_text(stmt, i, cursor->data);
851 ret = cal_db_util_stmt_step(stmt);
852 sqlite3_finalize(stmt);
855 g_slist_free_full(bind_text, free);
858 if (CALENDAR_ERROR_NONE != ret) {
859 ERR("cal_db_util_stmt_step() Fail(%d)", ret);
863 return CALENDAR_ERROR_NONE;