-int notification_noti_delete_group_by_group_id(const char *pkgname,
- int group_id, int *num_deleted, int **list_deleted_rowid)
-{
- int ret = NOTIFICATION_ERROR_NONE;
- int ret_tmp = NOTIFICATION_ERROR_NONE;
- sqlite3 *db = NULL;
- int i = 0, data_cnt = 0;
- sqlite3_stmt *stmt = NULL;
- char buf[128] = { 0, };
- char query[NOTIFICATION_QUERY_MAX] = { 0, };
- char query_base[NOTIFICATION_QUERY_MAX] = { 0, };
- char query_where[NOTIFICATION_QUERY_MAX] = { 0, };
-
- /* Check pkgname is valid */
- if (pkgname == NULL)
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
- snprintf(query_where, sizeof(query_where),
- "where caller_pkgname = '%s' and group_id = %d", pkgname, group_id);
-
- /* Open DB */
- db = notification_db_open(DBPATH);
- if (!db)
- return get_last_result();
-
- if (num_deleted != NULL)
- *num_deleted = 0;
-
- if (list_deleted_rowid != NULL) {
- *list_deleted_rowid = NULL;
- snprintf(query, sizeof(query),
- "select priv_id from noti_list %s ", query_where);
-
- ret = sqlite3_prepare(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- NOTIFICATION_ERR("Select Query : %s", query);
- NOTIFICATION_ERR("Select DB error(%d) : %s", ret,
- sqlite3_errmsg(db));
-
- ret = NOTIFICATION_ERROR_FROM_DB;
- goto err;
- }
-
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- if (data_cnt % 8 == 0) {
- int *tmp;
- tmp = (int *)realloc(*list_deleted_rowid, sizeof(int) * (data_cnt + 8 + 1));
- if (tmp) {
- *list_deleted_rowid = tmp;
- } else {
- free(*list_deleted_rowid);
- *list_deleted_rowid = NULL;
- ret = NOTIFICATION_ERROR_OUT_OF_MEMORY;
- goto err;
- }
- }
- *((*list_deleted_rowid) + data_cnt) = sqlite3_column_int(stmt, 0);
- data_cnt++;
- }
-
- if (stmt) {
- sqlite3_finalize(stmt);
- stmt = NULL;
- }
-
- if (data_cnt > 0) {
- query_where[0] = '\0';
- snprintf(query_base, sizeof(query_base) - 1, "delete from noti_list");
- for (i = 0; i < data_cnt ; i++) {
- if (i % NOTI_BURST_DELETE_UNIT == 0 && i != 0) {
- snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
- ret_tmp = notification_db_exec(db, query, NULL);
- query_where[0] = '\0';
- if (ret == NOTIFICATION_ERROR_NONE)
- ret = ret_tmp;
- }
- snprintf(buf, sizeof(buf) - 1, "%s%d", (i % NOTI_BURST_DELETE_UNIT == 0) ? "" : ",", *((*list_deleted_rowid) + i));
- strncat(query_where, buf, sizeof(query_where) - strlen(query_where) - 1);
- }
- if ((i <= NOTI_BURST_DELETE_UNIT) || ((i % NOTI_BURST_DELETE_UNIT) > 0)) {
- snprintf(query, sizeof(query) - 1, "%s where priv_id in (%s)", query_base, query_where);
- ret_tmp = notification_db_exec(db, query, NULL);
- if (ret == NOTIFICATION_ERROR_NONE)
- ret = ret_tmp;
- }
- } else {
- free(*list_deleted_rowid);
- *list_deleted_rowid = NULL;
- }
-
- if (num_deleted != NULL)
- *num_deleted = data_cnt;
-
- } else {
- /* Make query */
- snprintf(query, sizeof(query), "delete from noti_list %s", query_where);
-
- /* execute DB */
- ret = notification_db_exec(db, query, NULL);
- }
-
-err:
- if (stmt)
- sqlite3_finalize(stmt);
-
- /* Close DB */
- if (db)
- notification_db_close(&db);
-
- return ret;
-}
-
-int notification_noti_delete_group_by_priv_id(const char *pkgname, int priv_id)
-{
- sqlite3 *db = NULL;
- char query[NOTIFICATION_QUERY_MAX] = { 0, };
- int internal_group_id = 0;
- int ret;
-
- /* Check pkgname is valid */
- if (pkgname == NULL)
- return NOTIFICATION_ERROR_INVALID_PARAMETER;
-
- /* Open DB */
- db = notification_db_open(DBPATH);
- if (!db)
- return get_last_result();
-
- /* Get internal group id using priv id */
- internal_group_id =
- _notification_noti_get_internal_group_id_by_priv_id(pkgname,
- priv_id, db);
-
- /* Make query */
- snprintf(query, sizeof(query), "delete from noti_list "
- "where caller_pkgname = '%s' and internal_group_id = %d",
- pkgname, internal_group_id);
-
- /* execute DB */
- ret = notification_db_exec(db, query, NULL);
-
- /* Close DB */
- notification_db_close(&db);
-
- return ret;
-}
-