4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungtaek Chung <seungtaek.chung@samsung.com>, Mi-Ju Lee <miju52.lee@samsung.com>, Xi Zhichan <zhichan.xi@samsung.com>, Youngsub Ko <ys4610.ko@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
28 #include <notification.h>
29 #include <notification_db.h>
30 #include <notification_noti.h>
31 #include <notification_debug.h>
32 #include <notification_internal.h>
34 #define NOTI_BURST_DELETE_UNIT 10
36 static int _notification_noti_bind_query_text(sqlite3_stmt * stmt, const char *name,
42 index = sqlite3_bind_parameter_index(stmt, name);
44 NOTIFICATION_ERR("Insert : invalid column name");
45 return NOTIFICATION_ERROR_FROM_DB;
49 sqlite3_bind_text(stmt, index, NOTIFICATION_CHECK_STR(str), -1,
51 if (ret != SQLITE_OK) {
52 NOTIFICATION_ERR("Insert text : %s",
53 NOTIFICATION_CHECK_STR(str));
54 return NOTIFICATION_ERROR_FROM_DB;
57 return NOTIFICATION_ERROR_NONE;
60 static int _notification_noti_bind_query_double(sqlite3_stmt * stmt, const char *name,
66 index = sqlite3_bind_parameter_index(stmt, name);
68 NOTIFICATION_ERR("Insert : invalid column name");
69 return NOTIFICATION_ERROR_FROM_DB;
72 ret = sqlite3_bind_double(stmt, index, val);
73 if (ret != SQLITE_OK) {
74 NOTIFICATION_ERR("Insert double : %f", val);
75 return NOTIFICATION_ERROR_FROM_DB;
78 return NOTIFICATION_ERROR_NONE;
81 static int _notification_noti_check_priv_id(notification_h noti, sqlite3 * db)
83 sqlite3_stmt *stmt = NULL;
84 char query[NOTIFICATION_QUERY_MAX] = { 0, };
85 int ret = NOTIFICATION_ERROR_NONE, result = 0;
87 /* Make query to check priv_id exist */
88 snprintf(query, sizeof(query),
89 "select count(*) from noti_list where caller_pkgname = '%s' and priv_id = %d",
90 noti->caller_pkgname, noti->priv_id);
92 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
93 if (ret != SQLITE_OK) {
94 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
96 return NOTIFICATION_ERROR_FROM_DB;
99 ret = sqlite3_step(stmt);
100 if (ret == SQLITE_ROW) {
101 result = sqlite3_column_int(stmt, 0);
106 sqlite3_finalize(stmt);
108 /* If result > 0, there is priv_id in DB */
110 return NOTIFICATION_ERROR_ALREADY_EXIST_ID;
113 return NOTIFICATION_ERROR_NONE;
116 static int _notification_noti_get_priv_id(notification_h noti, sqlite3 * db)
118 sqlite3_stmt *stmt = NULL;
119 char query[NOTIFICATION_QUERY_MAX] = { 0, };
120 int ret = NOTIFICATION_ERROR_NONE, result = 0;
122 /* Make query to get max priv_id */
123 snprintf(query, sizeof(query),
124 "select max(priv_id) from noti_list where caller_pkgname = '%s'",
125 noti->caller_pkgname);
127 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
128 if (ret != SQLITE_OK) {
129 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
131 return NOTIFICATION_ERROR_FROM_DB;
134 ret = sqlite3_step(stmt);
135 if (ret == SQLITE_ROW) {
136 result = sqlite3_column_int(stmt, 0);
141 sqlite3_finalize(stmt);
144 return NOTIFICATION_ERROR_FROM_DB;
147 /* Increase result(max priv_id value) for next priv_id */
148 noti->priv_id = result + 1;
150 return NOTIFICATION_ERROR_NONE;
153 static int _notification_noti_get_internal_group_id_by_priv_id(const char *pkgname,
157 sqlite3_stmt *stmt = NULL;
158 char query[NOTIFICATION_QUERY_MAX] = { 0, };
159 int ret = NOTIFICATION_ERROR_NONE, result = 0;
161 snprintf(query, sizeof(query),
162 "select internal_group_id from noti_list where caller_pkgname = '%s' and priv_id = %d",
165 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
166 if (ret != SQLITE_OK) {
167 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
169 return NOTIFICATION_ERROR_FROM_DB;
172 ret = sqlite3_step(stmt);
173 if (ret == SQLITE_ROW) {
174 result = sqlite3_column_int(stmt, 0);
179 sqlite3_finalize(stmt);
184 static int _notification_noti_get_max_internal_group_id(notification_h noti,
187 sqlite3_stmt *stmt = NULL;
188 char query[NOTIFICATION_QUERY_MAX] = { 0, };
189 int ret = NOTIFICATION_ERROR_NONE, result = 0;
191 /* Get max internal group id */
192 snprintf(query, sizeof(query),
193 "select max(internal_group_id) from noti_list");
195 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
196 if (ret != SQLITE_OK) {
197 NOTIFICATION_ERR("Get count DB err(%d) : %s", ret,
199 return NOTIFICATION_ERROR_FROM_DB;
202 ret = sqlite3_step(stmt);
203 if (ret == SQLITE_ROW) {
204 result = sqlite3_column_int(stmt, 0);
209 sqlite3_finalize(stmt);
214 static int _notification_noti_get_internal_group_id(notification_h noti,
217 sqlite3_stmt *stmt = NULL;
218 char query[NOTIFICATION_QUERY_MAX] = { 0, };
219 int ret = NOTIFICATION_ERROR_NONE, result = 0;
220 const char *ret_title = NULL;
221 char buf_key[32] = { 0, };
223 if (noti->group_id == NOTIFICATION_GROUP_ID_NONE) {
224 /* If Group ID is NONE Get max internal group ID */
225 result = _notification_noti_get_max_internal_group_id(noti, db);
227 return NOTIFICATION_ERROR_FROM_DB;
230 /* Internal Group ID is max internal group ID + 1 */
231 noti->internal_group_id = result + 1;
233 return NOTIFICATION_ERROR_NONE;
234 } else if (noti->group_id == NOTIFICATION_GROUP_ID_DEFAULT) {
235 /* If Group ID is DEFAULT, Get internal group id if it exist */
236 if (noti->b_key != NULL) {
237 snprintf(buf_key, sizeof(buf_key), "%d",
238 NOTIFICATION_TEXT_TYPE_TITLE);
240 ret_title = bundle_get_val(noti->b_key, buf_key);
243 if (ret_title == NULL && noti->b_text != NULL) {
244 snprintf(buf_key, sizeof(buf_key), "%d",
245 NOTIFICATION_TEXT_TYPE_TITLE);
247 ret_title = bundle_get_val(noti->b_text, buf_key);
250 if (ret_title == NULL) {
251 ret_title = noti->caller_pkgname;
254 snprintf(query, sizeof(query),
255 "select internal_group_id from noti_list where title_key = $title_key and group_id = %d",
256 NOTIFICATION_GROUP_ID_DEFAULT);
258 /* If Group ID is > DEFAULT, Get internal group id if it exit */
259 snprintf(query, sizeof(query),
260 "select internal_group_id from noti_list where caller_pkgname = '%s' and group_id = %d",
261 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
265 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
266 if (ret != SQLITE_OK) {
267 NOTIFICATION_ERR("Select Query : %s", query);
268 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
271 sqlite3_finalize(stmt);
273 return NOTIFICATION_ERROR_FROM_DB;
277 if (ret_title != NULL) {
279 _notification_noti_bind_query_text(stmt, "$title_key",
280 NOTIFICATION_CHECK_STR
282 if (ret != NOTIFICATION_ERROR_NONE) {
283 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
285 sqlite3_finalize(stmt);
291 ret = sqlite3_step(stmt);
292 if (ret == SQLITE_ROW) {
293 result = sqlite3_column_int(stmt, 0);
295 /* If there is not internal_group_id, create new one */
296 result = _notification_noti_get_max_internal_group_id(noti, db);
300 sqlite3_finalize(stmt);
302 noti->internal_group_id = result;
304 return NOTIFICATION_ERROR_NONE;
307 static int _notification_noti_make_query(notification_h noti, char *query,
311 char *group_args = NULL;
312 char *b_image_path = NULL;
313 char *b_execute_option = NULL;
314 char *b_service_responding = NULL;
315 char *b_service_single_launch = NULL;
316 char *b_service_multi_launch = NULL;
319 char *b_format_args = NULL;
320 int flag_simmode = 0;
322 /* Decode bundle to insert DB */
324 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
326 if (noti->group_args) {
327 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
331 if (noti->b_execute_option) {
332 bundle_encode(noti->b_execute_option,
333 (bundle_raw **) & b_execute_option, NULL);
335 if (noti->b_service_responding) {
336 bundle_encode(noti->b_service_responding,
337 (bundle_raw **) & b_service_responding, NULL);
339 if (noti->b_service_single_launch) {
340 bundle_encode(noti->b_service_single_launch,
341 (bundle_raw **) & b_service_single_launch, NULL);
343 if (noti->b_service_multi_launch) {
344 bundle_encode(noti->b_service_multi_launch,
345 (bundle_raw **) & b_service_multi_launch, NULL);
349 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
352 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
354 if (noti->b_format_args) {
355 bundle_encode(noti->b_format_args,
356 (bundle_raw **) & b_format_args, NULL);
359 if (noti->b_image_path) {
360 bundle_encode(noti->b_image_path,
361 (bundle_raw **) & b_image_path, NULL);
364 /* Check only simmode property is enable */
365 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
370 snprintf(query, query_size, "insert into noti_list ("
373 "caller_pkgname, launch_pkgname, "
375 "group_id, internal_group_id, priv_id, "
377 "b_text, b_key, b_format_args, num_format_args, "
378 "text_domain, text_dir, "
379 "time, insert_time, "
382 "b_service_responding, b_service_single_launch, b_service_multi_launch, "
383 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
384 "flags_for_property, flag_simmode, display_applist, "
385 "progress_size, progress_percentage) values ("
392 "'%s', '%s', '%s', %d, "
398 "%d, '%s', %d, '%s', %d, %d, %d, %d,"
400 "$progress_size, $progress_percentage)",
403 NOTIFICATION_CHECK_STR(noti->caller_pkgname),
404 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
405 NOTIFICATION_CHECK_STR(b_image_path), noti->group_id,
406 noti->internal_group_id, noti->priv_id,
407 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
408 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
409 NOTIFICATION_CHECK_STR(noti->domain),
410 NOTIFICATION_CHECK_STR(noti->dir), (int)noti->time,
411 (int)noti->insert_time, NOTIFICATION_CHECK_STR(args),
412 NOTIFICATION_CHECK_STR(group_args),
413 NOTIFICATION_CHECK_STR(b_execute_option),
414 NOTIFICATION_CHECK_STR(b_service_responding),
415 NOTIFICATION_CHECK_STR(b_service_single_launch),
416 NOTIFICATION_CHECK_STR(b_service_multi_launch),
417 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
418 noti->vibration_type,
419 NOTIFICATION_CHECK_STR(noti->vibration_path),
424 noti->flags_for_property, flag_simmode, noti->display_applist);
426 /* Free decoded data */
434 if (b_execute_option) {
435 free(b_execute_option);
437 if (b_service_responding) {
438 free(b_service_responding);
440 if (b_service_single_launch) {
441 free(b_service_single_launch);
443 if (b_service_multi_launch) {
444 free(b_service_multi_launch);
461 return NOTIFICATION_ERROR_NONE;
465 static int _notification_noti_make_update_query(notification_h noti, char *query,
469 char *group_args = NULL;
470 char *b_image_path = NULL;
471 char *b_execute_option = NULL;
472 char *b_service_responding = NULL;
473 char *b_service_single_launch = NULL;
474 char *b_service_multi_launch = NULL;
477 char *b_format_args = NULL;
478 int flag_simmode = 0;
480 /* Decode bundle to update DB */
482 bundle_encode(noti->args, (bundle_raw **) & args, NULL);
484 if (noti->group_args) {
485 bundle_encode(noti->group_args, (bundle_raw **) & group_args,
489 if (noti->b_execute_option) {
490 bundle_encode(noti->b_execute_option,
491 (bundle_raw **) & b_execute_option, NULL);
493 if (noti->b_service_responding) {
494 bundle_encode(noti->b_service_responding,
495 (bundle_raw **) & b_service_responding, NULL);
497 if (noti->b_service_single_launch) {
498 bundle_encode(noti->b_service_single_launch,
499 (bundle_raw **) & b_service_single_launch, NULL);
501 if (noti->b_service_multi_launch) {
502 bundle_encode(noti->b_service_multi_launch,
503 (bundle_raw **) & b_service_multi_launch, NULL);
507 bundle_encode(noti->b_text, (bundle_raw **) & b_text, NULL);
510 bundle_encode(noti->b_key, (bundle_raw **) & b_key, NULL);
512 if (noti->b_format_args) {
513 bundle_encode(noti->b_format_args,
514 (bundle_raw **) & b_format_args, NULL);
517 if (noti->b_image_path) {
518 bundle_encode(noti->b_image_path,
519 (bundle_raw **) & b_image_path, NULL);
522 /* Check only simmode property is enable */
523 if (noti->flags_for_property & NOTIFICATION_PROP_DISPLAY_ONLY_SIMMODE) {
528 snprintf(query, query_size, "update noti_list set "
531 "launch_pkgname = '%s', "
532 "image_path = '%s', "
533 "b_text = '%s', b_key = '%s', "
534 "b_format_args = '%s', num_format_args = %d, "
535 "text_domain = '%s', text_dir = '%s', "
536 "time = %d, insert_time = %d, "
537 "args = '%s', group_args = '%s', "
538 "b_execute_option = '%s', "
539 "b_service_responding = '%s', "
540 "b_service_single_launch = '%s', "
541 "b_service_multi_launch = '%s', "
542 "sound_type = %d, sound_path = '%s', "
543 "vibration_type = %d, vibration_path = '%s', "
544 "led_operation = %d, led_argb = %d, "
545 "led_on_ms = %d, led_off_ms = %d, "
546 "flags_for_property = %d, flag_simmode = %d, "
547 "display_applist = %d, "
548 "progress_size = $progress_size, progress_percentage = $progress_percentage "
549 "where priv_id = %d ",
552 NOTIFICATION_CHECK_STR(noti->launch_pkgname),
553 NOTIFICATION_CHECK_STR(b_image_path),
554 NOTIFICATION_CHECK_STR(b_text), NOTIFICATION_CHECK_STR(b_key),
555 NOTIFICATION_CHECK_STR(b_format_args), noti->num_format_args,
556 NOTIFICATION_CHECK_STR(noti->domain),
557 NOTIFICATION_CHECK_STR(noti->dir),
558 (int)noti->time, (int)noti->insert_time,
559 NOTIFICATION_CHECK_STR(args), NOTIFICATION_CHECK_STR(group_args),
560 NOTIFICATION_CHECK_STR(b_execute_option),
561 NOTIFICATION_CHECK_STR(b_service_responding),
562 NOTIFICATION_CHECK_STR(b_service_single_launch),
563 NOTIFICATION_CHECK_STR(b_service_multi_launch),
564 noti->sound_type, NOTIFICATION_CHECK_STR(noti->sound_path),
565 noti->vibration_type,
566 NOTIFICATION_CHECK_STR(noti->vibration_path),
571 noti->flags_for_property, flag_simmode, noti->display_applist,
574 /* Free decoded data */
582 if (b_execute_option) {
583 free(b_execute_option);
585 if (b_service_responding) {
586 free(b_service_responding);
588 if (b_service_single_launch) {
589 free(b_service_single_launch);
591 if (b_service_multi_launch) {
592 free(b_service_multi_launch);
609 return NOTIFICATION_ERROR_NONE;
612 static void _notification_noti_populate_from_stmt(sqlite3_stmt * stmt, notification_h noti) {
615 if (stmt == NULL || noti == NULL) {
619 noti->type = sqlite3_column_int(stmt, col++);
620 noti->layout = sqlite3_column_int(stmt, col++);
621 noti->caller_pkgname = notification_db_column_text(stmt, col++);
622 noti->launch_pkgname = notification_db_column_text(stmt, col++);
623 noti->b_image_path = notification_db_column_bundle(stmt, col++);
624 noti->group_id = sqlite3_column_int(stmt, col++);
625 noti->internal_group_id = 0;
626 noti->priv_id = sqlite3_column_int(stmt, col++);
628 noti->b_text = notification_db_column_bundle(stmt, col++);
629 noti->b_key = notification_db_column_bundle(stmt, col++);
630 noti->b_format_args = notification_db_column_bundle(stmt, col++);
631 noti->num_format_args = sqlite3_column_int(stmt, col++);
633 noti->domain = notification_db_column_text(stmt, col++);
634 noti->dir = notification_db_column_text(stmt, col++);
635 noti->time = sqlite3_column_int(stmt, col++);
636 noti->insert_time = sqlite3_column_int(stmt, col++);
637 noti->args = notification_db_column_bundle(stmt, col++);
638 noti->group_args = notification_db_column_bundle(stmt, col++);
640 noti->b_execute_option = notification_db_column_bundle(stmt, col++);
641 noti->b_service_responding = notification_db_column_bundle(stmt, col++);
642 noti->b_service_single_launch =
643 notification_db_column_bundle(stmt, col++);
644 noti->b_service_multi_launch =
645 notification_db_column_bundle(stmt, col++);
647 noti->sound_type = sqlite3_column_int(stmt, col++);
648 noti->sound_path = notification_db_column_text(stmt, col++);
649 noti->vibration_type = sqlite3_column_int(stmt, col++);
650 noti->vibration_path = notification_db_column_text(stmt, col++);
651 noti->led_operation = sqlite3_column_int(stmt, col++);
652 noti->led_argb = sqlite3_column_int(stmt, col++);
653 noti->led_on_ms = sqlite3_column_int(stmt, col++);
654 noti->led_off_ms = sqlite3_column_int(stmt, col++);
656 noti->flags_for_property = sqlite3_column_int(stmt, col++);
657 noti->display_applist = sqlite3_column_int(stmt, col++);
658 noti->progress_size = sqlite3_column_double(stmt, col++);
659 noti->progress_percentage = sqlite3_column_double(stmt, col++);
661 noti->app_icon_path = NULL;
662 noti->app_name = NULL;
663 noti->temp_title = NULL;
664 noti->temp_content = NULL;
667 static notification_h _notification_noti_get_item(sqlite3_stmt * stmt)
669 notification_h noti = NULL;
671 noti = malloc(sizeof(struct _notification));
676 _notification_noti_populate_from_stmt(stmt, noti);
681 int notification_noti_set_tag(const char *tag, char *value, char *buf, int buf_len)
685 len_total += (strlen(tag) * 2) + 5 + strlen(value) + 1;
687 if (buf_len <= len_total)
688 return NOTIFICATION_ERROR_INVALID_DATA;
690 snprintf(buf, buf_len, "<%s>%s</%s>", tag, value, tag);
692 return NOTIFICATION_ERROR_NONE;
695 char *notification_noti_strip_tag(const char *tagged_str)
697 if (tagged_str == NULL)
700 int len_total = strlen(tagged_str);
705 char *b_f_e = strstr(tagged_str, ">");
706 char *b_e_s = strstr(tagged_str, "</");
708 if (b_f_e == NULL || b_e_s == NULL || (b_e_s - b_f_e - 1) <= 0)
711 return strndup(b_f_e + 1, b_e_s - b_f_e - 1);
714 int notification_noti_get_tag_type(const char *tagged_str)
716 if (tagged_str == NULL)
717 return TAG_TYPE_INVALID;
719 if (strlen(tagged_str)== 0)
720 return TAG_TYPE_INVALID;
722 char *b_f_s = strstr(tagged_str, "<");
723 char *b_f_e = strstr(tagged_str, ">");
725 if (b_f_s == NULL || b_f_e == NULL || (b_f_e - b_f_s - 1) <= 0)
726 return TAG_TYPE_INVALID;
728 char *start = b_f_s + 1;
729 int len_tag = b_f_e - b_f_s - 1;
731 if (strncmp(start,TAG_TIME,len_tag) == 0) {
732 return TAG_TYPE_TIME;
735 return TAG_TYPE_INVALID;
738 static int _notification_noti_update_priv_id(sqlite3 * db, int rowid)
740 char query[128] = { 0, };
743 return NOTIFICATION_ERROR_INVALID_DATA;
746 snprintf(query, sizeof(query), "update noti_list set "
747 "priv_id = %d, internal_group_id = %d where rowid = %d",
748 rowid, rowid, rowid);
750 return notification_db_exec(db, query, NULL);
753 EXPORT_API int notification_noti_insert(notification_h noti)
756 sqlite3_stmt *stmt = NULL;
757 char query[NOTIFICATION_QUERY_MAX] = { 0, };
759 char buf_key[32] = { 0, };
760 const char *title_key = NULL;
763 db = notification_db_open(DBPATH);
765 return NOTIFICATION_ERROR_FROM_DB;
768 /* Initialize private ID */
769 noti->priv_id = NOTIFICATION_PRIV_ID_NONE;
770 noti->group_id = NOTIFICATION_GROUP_ID_NONE;
771 noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
774 ret = _notification_noti_make_query(noti, query, sizeof(query));
775 if (ret != NOTIFICATION_ERROR_NONE) {
779 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
780 if (ret != SQLITE_OK) {
781 NOTIFICATION_ERR("Insert Query : %s", query);
782 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
784 ret = NOTIFICATION_ERROR_FROM_DB;
789 if (noti->b_key != NULL) {
790 snprintf(buf_key, sizeof(buf_key), "%d",
791 NOTIFICATION_TEXT_TYPE_TITLE);
793 title_key = bundle_get_val(noti->b_key, buf_key);
796 if (title_key == NULL && noti->b_text != NULL) {
797 snprintf(buf_key, sizeof(buf_key), "%d",
798 NOTIFICATION_TEXT_TYPE_TITLE);
800 title_key = bundle_get_val(noti->b_text, buf_key);
803 if (title_key == NULL) {
804 title_key = noti->caller_pkgname;
808 ret = _notification_noti_bind_query_text(stmt, "$title_key", title_key);
809 if (ret != NOTIFICATION_ERROR_NONE) {
810 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
813 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
814 if (ret != NOTIFICATION_ERROR_NONE) {
815 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
817 sqlite3_finalize(stmt);
821 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
822 if (ret != NOTIFICATION_ERROR_NONE) {
823 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
825 sqlite3_finalize(stmt);
830 ret = sqlite3_step(stmt);
831 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
832 noti->priv_id = (int)sqlite3_last_insert_rowid(db);
833 if (_notification_noti_update_priv_id(db, noti->priv_id) == 0) {
834 ret = NOTIFICATION_ERROR_NONE;
836 ret = NOTIFICATION_ERROR_FROM_DB;
839 ret = NOTIFICATION_ERROR_FROM_DB;
843 sqlite3_finalize(stmt);
848 notification_db_close(&db);
854 int notification_noti_get_by_priv_id(notification_h noti, char *pkgname, int priv_id)
857 sqlite3_stmt *stmt = NULL;
858 char query[NOTIFICATION_QUERY_MAX] = { 0, };
861 if (priv_id < 0 || noti == NULL) {
862 ret = NOTIFICATION_ERROR_INVALID_DATA;
867 db = notification_db_open(DBPATH);
869 return NOTIFICATION_ERROR_FROM_DB;
872 char *base_query = "select "
873 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
874 "b_text, b_key, b_format_args, num_format_args, "
875 "text_domain, text_dir, time, insert_time, args, group_args, "
876 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
877 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
878 "flags_for_property, display_applist, progress_size, progress_percentage "
881 if (pkgname != NULL) {
882 snprintf(query, sizeof(query), "%s where caller_pkgname = '%s' and priv_id = %d",
883 base_query ,pkgname, priv_id);
885 snprintf(query, sizeof(query), "%s where priv_id = %d", base_query, priv_id);
888 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
889 if (ret != SQLITE_OK) {
890 NOTIFICATION_ERR("select Query : %s", query);
891 NOTIFICATION_ERR("select DB error(%d) : %s", ret,
893 ret = NOTIFICATION_ERROR_FROM_DB;
897 ret = sqlite3_step(stmt);
898 if (ret == SQLITE_ROW) {
899 _notification_noti_populate_from_stmt(stmt, noti);
900 ret = NOTIFICATION_ERROR_NONE;
902 ret = NOTIFICATION_ERROR_FROM_DB;
906 sqlite3_finalize(stmt);
911 notification_db_close(&db);
917 EXPORT_API int notification_noti_update(notification_h noti)
920 sqlite3_stmt *stmt = NULL;
921 char query[NOTIFICATION_QUERY_MAX] = { 0, };
925 db = notification_db_open(DBPATH);
927 return NOTIFICATION_ERROR_FROM_DB;
930 /* Check private ID is exist */
931 ret = _notification_noti_check_priv_id(noti, db);
932 if (ret != NOTIFICATION_ERROR_ALREADY_EXIST_ID) {
933 ret = NOTIFICATION_ERROR_NOT_EXIST_ID;
937 /* make update query */
938 ret = _notification_noti_make_update_query(noti, query, sizeof(query));
939 if (ret != NOTIFICATION_ERROR_NONE) {
943 ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
944 if (ret != SQLITE_OK) {
945 NOTIFICATION_ERR("Insert Query : %s", query);
946 NOTIFICATION_ERR("Insert DB error(%d) : %s", ret,
948 ret = NOTIFICATION_ERROR_FROM_DB;
952 ret = _notification_noti_bind_query_double(stmt, "$progress_size",noti->progress_size);
953 if (ret != NOTIFICATION_ERROR_NONE) {
954 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
957 ret = _notification_noti_bind_query_double(stmt, "$progress_percentage",noti->progress_percentage);
958 if (ret != NOTIFICATION_ERROR_NONE) {
959 NOTIFICATION_ERR("Bind error : %s", sqlite3_errmsg(db));
963 ret = sqlite3_step(stmt);
964 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
965 ret = NOTIFICATION_ERROR_NONE;
967 ret = NOTIFICATION_ERROR_FROM_DB;
971 sqlite3_finalize(stmt);
976 notification_db_close(&db);
982 EXPORT_API int notification_noti_delete_all(notification_type_e type, const char *pkgname, int *num_deleted, int **list_deleted_rowid)
984 int ret = NOTIFICATION_ERROR_NONE;
985 int ret_tmp = NOTIFICATION_ERROR_NONE;
986 int i = 0, data_cnt = 0;
988 sqlite3_stmt *stmt = NULL;
989 char buf[128] = { 0, };
990 char query[NOTIFICATION_QUERY_MAX] = { 0, };
991 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
992 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
995 db = notification_db_open(DBPATH);
997 return NOTIFICATION_ERROR_FROM_DB;
1000 if (pkgname == NULL) {
1001 if (type != NOTIFICATION_TYPE_NONE) {
1002 snprintf(query_where, sizeof(query_where),
1003 "where type = %d ", type);
1006 if (type == NOTIFICATION_TYPE_NONE) {
1007 snprintf(query_where, sizeof(query_where),
1008 "where caller_pkgname = '%s' ", pkgname);
1010 snprintf(query_where, sizeof(query_where),
1011 "where caller_pkgname = '%s' and type = %d ",
1016 if (num_deleted != NULL) {
1019 if (list_deleted_rowid != NULL) {
1020 *list_deleted_rowid = NULL;
1021 snprintf(query, sizeof(query),
1022 "select priv_id from noti_list %s ", query_where);
1024 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1025 if (ret != SQLITE_OK) {
1026 NOTIFICATION_ERR("Select Query : %s", query);
1027 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1028 sqlite3_errmsg(db));
1030 ret = NOTIFICATION_ERROR_FROM_DB;
1034 while(sqlite3_step(stmt) == SQLITE_ROW) {
1035 if (data_cnt % 8 == 0) {
1038 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1040 *list_deleted_rowid = tmp;
1042 NOTIFICATION_ERR("Heap: %s\n", strerror(errno));
1045 * How can I handle this?
1047 free(*list_deleted_rowid);
1048 *list_deleted_rowid = NULL;
1049 ret = NOTIFICATION_ERROR_NO_MEMORY;
1053 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1058 sqlite3_finalize(stmt);
1063 query_where[0] = '\0';
1064 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1065 for (i = 0; i < data_cnt ; i++) {
1066 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1067 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1068 ret_tmp = notification_db_exec(db, query, NULL);
1069 query_where[0] = '\0';
1070 if (ret == NOTIFICATION_ERROR_NONE) {
1074 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1075 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1077 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1078 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1079 ret_tmp = notification_db_exec(db, query, NULL);
1080 if (ret == NOTIFICATION_ERROR_NONE) {
1085 free(*list_deleted_rowid);
1086 *list_deleted_rowid = NULL;
1089 if (num_deleted != NULL) {
1090 *num_deleted = data_cnt;
1093 /* Make main query */
1094 snprintf(query_base, sizeof(query_base), "delete from noti_list ");
1095 snprintf(query, sizeof(query), "%s %s", query_base, query_where);
1097 ret = notification_db_exec(db, query, NULL);
1099 if (num_deleted != NULL) {
1100 *num_deleted = sqlite3_changes(db);
1106 sqlite3_finalize(stmt);
1110 notification_db_close(&db);
1116 int notification_noti_delete_group_by_group_id(const char *pkgname,
1117 int group_id, int *num_deleted, int **list_deleted_rowid)
1119 int ret = NOTIFICATION_ERROR_NONE;
1120 int ret_tmp = NOTIFICATION_ERROR_NONE;
1122 int i = 0, data_cnt = 0;
1123 sqlite3_stmt *stmt = NULL;
1124 char buf[128] = { 0, };
1125 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1126 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1127 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1129 /* Check pkgname is valid */
1130 if (pkgname == NULL) {
1131 return NOTIFICATION_ERROR_INVALID_DATA;
1134 snprintf(query_where, sizeof(query_where),
1135 "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
1138 db = notification_db_open(DBPATH);
1140 return NOTIFICATION_ERROR_FROM_DB;
1143 if (num_deleted != NULL) {
1146 if (list_deleted_rowid != NULL) {
1147 *list_deleted_rowid = NULL;
1148 snprintf(query, sizeof(query),
1149 "select priv_id from noti_list %s ", query_where);
1151 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1152 if (ret != SQLITE_OK) {
1153 NOTIFICATION_ERR("Select Query : %s", query);
1154 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1155 sqlite3_errmsg(db));
1157 ret = NOTIFICATION_ERROR_FROM_DB;
1161 while(sqlite3_step(stmt) == SQLITE_ROW) {
1162 if (data_cnt % 8 == 0) {
1164 tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
1166 *list_deleted_rowid = tmp;
1168 free(*list_deleted_rowid);
1169 *list_deleted_rowid = NULL;
1170 ret = NOTIFICATION_ERROR_NO_MEMORY;
1174 *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
1179 sqlite3_finalize(stmt);
1184 query_where[0] = '\0';
1185 snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
1186 for (i = 0; i < data_cnt ; i++) {
1187 if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
1188 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1189 ret_tmp = notification_db_exec(db, query, NULL);
1190 query_where[0] = '\0';
1191 if (ret == NOTIFICATION_ERROR_NONE) {
1195 snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
1196 strncat(query_where, buf,sizeof(query_where) - strlen(query_where) - 1);
1198 if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0) ) {
1199 snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
1200 ret_tmp = notification_db_exec(db, query, NULL);
1201 if (ret == NOTIFICATION_ERROR_NONE) {
1206 free(*list_deleted_rowid);
1207 *list_deleted_rowid = NULL;
1210 if (num_deleted != NULL) {
1211 *num_deleted = data_cnt;
1215 snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
1218 ret = notification_db_exec(db, query, NULL);
1223 sqlite3_finalize(stmt);
1227 notification_db_close(&db);
1233 int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
1236 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1237 int internal_group_id = 0;
1240 /* Check pkgname is valid */
1241 if (pkgname == NULL) {
1242 return NOTIFICATION_ERROR_INVALID_DATA;
1246 db = notification_db_open(DBPATH);
1248 return NOTIFICATION_ERROR_FROM_DB;
1251 /* Get internal group id using priv id */
1253 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1257 snprintf(query, sizeof(query), "delete from noti_list "
1258 "where caller_pkgname = '%s' and internal_group_id = %d",
1259 pkgname, internal_group_id);
1262 ret = notification_db_exec(db, query, NULL);
1265 notification_db_close(&db);
1270 EXPORT_API int notification_noti_delete_by_priv_id(const char *pkgname, int priv_id)
1273 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1276 /* Check pkgname is valid */
1277 if (pkgname == NULL) {
1278 return NOTIFICATION_ERROR_INVALID_DATA;
1282 db = notification_db_open(DBPATH);
1284 return NOTIFICATION_ERROR_FROM_DB;
1288 snprintf(query, sizeof(query), "delete from noti_list "
1289 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1293 ret = notification_db_exec(db, query, NULL);
1297 notification_db_close(&db);
1303 EXPORT_API int notification_noti_delete_by_priv_id_get_changes(const char *pkgname, int priv_id, int *num_changes)
1306 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1309 /* Check pkgname is valid */
1310 if (pkgname == NULL) {
1311 return NOTIFICATION_ERROR_INVALID_DATA;
1315 db = notification_db_open(DBPATH);
1317 return NOTIFICATION_ERROR_FROM_DB;
1321 snprintf(query, sizeof(query), "delete from noti_list "
1322 "where caller_pkgname = '%s' and priv_id = %d", pkgname,
1326 ret = notification_db_exec(db, query, num_changes);
1328 if (num_changes != NULL) {
1329 NOTIFICATION_DBG("deleted num:%d", *num_changes);
1334 notification_db_close(&db);
1340 notification_error_e notification_noti_get_count(notification_type_e type,
1341 const char *pkgname,
1342 int group_id, int priv_id,
1346 sqlite3_stmt *stmt = NULL;
1347 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1348 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1349 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1350 char query_where_more[NOTIFICATION_QUERY_MAX] = { 0, };
1352 int ret = 0, get_count = 0, internal_group_id = 0;
1353 int status = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
1355 int flag_where_more = 0;
1359 db = notification_db_open(DBPATH);
1361 return NOTIFICATION_ERROR_FROM_DB;
1364 /* Check current sim status */
1365 ret_vconf = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1368 snprintf(query_base, sizeof(query_base),
1369 "select count(*) from noti_list ");
1371 if (pkgname != NULL) {
1372 if (group_id == NOTIFICATION_GROUP_ID_NONE) {
1373 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1374 snprintf(query_where, sizeof(query_where),
1375 "where caller_pkgname = '%s' ",
1380 _notification_noti_get_internal_group_id_by_priv_id
1381 (pkgname, priv_id, db);
1382 snprintf(query_where, sizeof(query_where),
1383 "where caller_pkgname = '%s' and internal_group_id = %d ",
1384 pkgname, internal_group_id);
1388 if (priv_id == NOTIFICATION_PRIV_ID_NONE) {
1389 snprintf(query_where, sizeof(query_where),
1390 "where caller_pkgname = '%s' and group_id = %d ",
1395 _notification_noti_get_internal_group_id_by_priv_id
1396 (pkgname, priv_id, db);
1397 snprintf(query_where, sizeof(query_where),
1398 "where caller_pkgname = '%s' and internal_group_id = %d ",
1399 pkgname, internal_group_id);
1406 if (ret_vconf == 0 && status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1407 if (type != NOTIFICATION_TYPE_NONE) {
1408 snprintf(query_where_more, sizeof(query_where_more),
1409 "type = %d ", type);
1410 flag_where_more = 1;
1413 if (type != NOTIFICATION_TYPE_NONE) {
1414 snprintf(query_where_more, sizeof(query_where_more),
1415 "type = %d and flag_simmode = 0 ", type);
1416 flag_where_more = 1;
1418 snprintf(query_where_more, sizeof(query_where_more),
1419 "flag_simmode = 0 ");
1420 flag_where_more = 1;
1424 if (flag_where == 1) {
1425 if (flag_where_more == 1) {
1426 snprintf(query, sizeof(query), "%s %s and %s",
1427 query_base, query_where, query_where_more);
1429 snprintf(query, sizeof(query), "%s %s", query_base,
1434 if (flag_where_more == 1) {
1435 snprintf(query, sizeof(query), "%s where %s",
1436 query_base, query_where_more);
1438 snprintf(query, sizeof(query), "%s", query_base);
1442 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1443 if (ret != SQLITE_OK) {
1444 NOTIFICATION_ERR("Select Query : %s", query);
1445 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1446 sqlite3_errmsg(db));
1448 ret = NOTIFICATION_ERROR_FROM_DB;
1452 ret = sqlite3_step(stmt);
1453 if (ret == SQLITE_ROW) {
1454 get_count = sqlite3_column_int(stmt, 0);
1457 ret = NOTIFICATION_ERROR_NONE;
1461 sqlite3_finalize(stmt);
1466 notification_db_close(&db);
1474 notification_error_e notification_noti_get_grouping_list(notification_type_e type,
1476 notification_list_h *
1480 sqlite3_stmt *stmt = NULL;
1481 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1482 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1483 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1486 notification_list_h get_list = NULL;
1487 notification_h noti = NULL;
1488 int internal_count = 0;
1492 db = notification_db_open(DBPATH);
1494 return NOTIFICATION_ERROR_FROM_DB;
1497 /* Check current sim status */
1498 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1501 snprintf(query_base, sizeof(query_base), "select "
1502 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1503 "b_text, b_key, b_format_args, num_format_args, "
1504 "text_domain, text_dir, time, insert_time, args, group_args, "
1505 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1506 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1507 "flags_for_property, display_applist, progress_size, progress_percentage "
1510 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1511 if (type != NOTIFICATION_TYPE_NONE) {
1512 snprintf(query_where, sizeof(query_where),
1513 "where type = %d ", type);
1516 if (type != NOTIFICATION_TYPE_NONE) {
1517 snprintf(query_where, sizeof(query_where),
1518 "where type = %d and flag_simmode = 0 ", type);
1520 snprintf(query_where, sizeof(query_where),
1521 "where flag_simmode = 0 ");
1525 snprintf(query, sizeof(query),
1527 "group by internal_group_id "
1528 "order by rowid desc, time desc", query_base, query_where);
1530 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1531 if (ret != SQLITE_OK) {
1532 NOTIFICATION_ERR("Select Query : %s", query);
1533 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1534 sqlite3_errmsg(db));
1536 ret = NOTIFICATION_ERROR_FROM_DB;
1540 while (sqlite3_step(stmt) == SQLITE_ROW) {
1541 /* Make notification list */
1542 noti = _notification_noti_get_item(stmt);
1546 get_list = notification_list_append(get_list, noti);
1548 if (count != -1 && internal_count >= count) {
1550 ("internal count %d >= count %d",
1551 internal_count, count);
1557 ret = NOTIFICATION_ERROR_NONE;
1561 sqlite3_finalize(stmt);
1566 notification_db_close(&db);
1569 if (get_list != NULL) {
1570 *list = notification_list_get_head(get_list);
1576 notification_error_e notification_noti_get_detail_list(const char *pkgname,
1578 int priv_id, int count,
1579 notification_list_h *list)
1582 sqlite3_stmt *stmt = NULL;
1583 char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
1584 char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
1586 char query[NOTIFICATION_QUERY_MAX] = { 0, };
1588 notification_list_h get_list = NULL;
1589 notification_h noti = NULL;
1590 int internal_count = 0;
1591 int internal_group_id = 0;
1592 int status = 0; /* If the vconf_get_int failed, the status will be the garbage value */
1595 db = notification_db_open(DBPATH);
1597 return NOTIFICATION_ERROR_FROM_DB;
1600 /* Check current sim status */
1601 ret = vconf_get_int(VCONFKEY_TELEPHONY_SIM_SLOT, &status);
1604 snprintf(query_base, sizeof(query_base), "select "
1605 "type, layout, caller_pkgname, launch_pkgname, image_path, group_id, priv_id, "
1606 "b_text, b_key, b_format_args, num_format_args, "
1607 "text_domain, text_dir, time, insert_time, args, group_args, "
1608 "b_execute_option, b_service_responding, b_service_single_launch, b_service_multi_launch, "
1609 "sound_type, sound_path, vibration_type, vibration_path, led_operation, led_argb, led_on_ms, led_off_ms, "
1610 "flags_for_property, display_applist, progress_size, progress_percentage "
1613 if (priv_id == NOTIFICATION_PRIV_ID_NONE && group_id == NOTIFICATION_GROUP_ID_NONE) {
1614 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1615 snprintf(query_where, sizeof(query_where),
1616 "where caller_pkgname = '%s' ",
1617 pkgname, internal_group_id);
1619 snprintf(query_where, sizeof(query_where),
1620 "where caller_pkgname = '%s' and flag_simmode = 0 ",
1621 pkgname, internal_group_id);
1625 _notification_noti_get_internal_group_id_by_priv_id(pkgname,
1628 if (status == VCONFKEY_TELEPHONY_SIM_INSERTED) {
1629 snprintf(query_where, sizeof(query_where),
1630 "where caller_pkgname = '%s' and internal_group_id = %d ",
1631 pkgname, internal_group_id);
1633 snprintf(query_where, sizeof(query_where),
1634 "where caller_pkgname = '%s' and internal_group_id = %d and flag_simmode = 0 ",
1635 pkgname, internal_group_id);
1639 snprintf(query, sizeof(query),
1641 "order by rowid desc, time desc", query_base, query_where);
1643 ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
1644 if (ret != SQLITE_OK) {
1645 NOTIFICATION_ERR("Select Query : %s", query);
1646 NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
1647 sqlite3_errmsg(db));
1649 ret = NOTIFICATION_ERROR_FROM_DB;
1653 while (sqlite3_step(stmt) == SQLITE_ROW) {
1654 /* Make notification list */
1655 noti = _notification_noti_get_item(stmt);
1659 get_list = notification_list_append(get_list, noti);
1661 if (count != -1 && internal_count >= count) {
1663 ("internal count %d >= count %d",
1664 internal_count, count);
1670 ret = NOTIFICATION_ERROR_NONE;
1674 sqlite3_finalize(stmt);
1679 notification_db_close(&db);
1682 if (get_list != NULL) {
1683 *list = notification_list_get_head(get_list);