4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngjoo Park <yjoo93.park@samsung.com>,
7 * Seungtaek Chung <seungtaek.chung@samsung.com>, Youngsub Ko <ys4610.ko@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the License);
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an AS IS BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
28 #include "badge_log.h"
29 #include "badge_error.h"
30 #include "badge_internal.h"
33 int badge_db_insert(const char *pkgname, const char *writable_pkg, const char *caller)
35 int err = BADGE_ERROR_NONE;
36 badge_h *badge = NULL;
40 WARN("package name is NULL");
41 return BADGE_ERROR_INVALID_PARAMETER;
44 pkgs = _badge_pkgs_new(&err, writable_pkg, caller, NULL);
46 ERR("fail to _badge_pkgs_new : %d", err);
50 INFO("pkgs : %s", pkgs);
52 badge = _badge_new(pkgname, pkgs, &err);
54 ERR("fail to _badge_new : %d", err);
60 err = _badge_insert(badge);
61 if (err != BADGE_ERROR_NONE) {
62 ERR("fail to _badge_insert : %d", err);
69 return BADGE_ERROR_NONE;
73 int badge_db_delete(const char *pkgname, const char *caller)
75 int result = BADGE_ERROR_NONE;
77 result = _badge_remove(caller, pkgname);
83 int badge_db_set_count(const char *pkgname, const char *caller, int count)
85 int result = BADGE_ERROR_NONE;
87 result = _badget_set_count(caller, pkgname, count);
93 int badge_db_set_display_option(const char *pkgname, const char *caller, int is_display)
95 int result = BADGE_ERROR_NONE;
97 result = _badget_set_display(pkgname, is_display);
103 int badge_db_exec(sqlite3 * db, const char *query, int *num_changes)
106 sqlite3_stmt *stmt = NULL;
109 return BADGE_ERROR_INVALID_PARAMETER;
112 return BADGE_ERROR_INVALID_PARAMETER;
115 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
116 if (ret != SQLITE_OK) {
117 ERR("DB err(%d) : %s", ret,
119 return BADGE_ERROR_FROM_DB;
123 ret = sqlite3_step(stmt);
124 if (ret == SQLITE_OK || ret == SQLITE_DONE) {
125 if (num_changes != NULL) {
126 *num_changes = sqlite3_changes(db);
128 sqlite3_finalize(stmt);
130 ERR("DB err(%d) : %s", ret,
132 sqlite3_finalize(stmt);
133 return BADGE_ERROR_FROM_DB;
136 return BADGE_ERROR_FROM_DB;
139 return BADGE_ERROR_NONE;