2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "rua_internal.h"
21 #include "db-schema.h"
24 static int __exec(sqlite3 *db, char *query)
32 r = sqlite3_exec(db, query, NULL, NULL, &errmsg);
42 static int __create_table(sqlite3 *db)
46 r = __exec(db, CREATE_RUA_HISTORY_TABLE);
53 static sqlite3 *__db_init(uid_t uid)
58 r = _rua_util_open_db(&db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE,
63 r = __create_table(db);
72 int rua_db_delete_history(bundle *b)
74 return rua_usr_db_delete_history(b, getuid());
77 int rua_usr_db_delete_history(bundle *b, uid_t uid)
81 char query[QUERY_MAXLEN];
82 char *pkg_name = NULL;
83 char *app_path = NULL;
89 LOGE("Error db null");
94 bundle_get_str(b, AUL_K_RUA_PKGNAME, &pkg_name);
95 bundle_get_str(b, AUL_K_RUA_APPPATH, &app_path);
99 snprintf(query, QUERY_MAXLEN, "delete from rua_history where pkg_name = '%s';", pkg_name);
100 else if (app_path != NULL)
101 snprintf(query, QUERY_MAXLEN, "delete from rua_history where app_path = '%s';", app_path);
103 snprintf(query, QUERY_MAXLEN, "delete from rua_history;");
105 LOGI("rua_delete_history_from_db : %s", query);
106 r = sqlite3_exec(db, query, NULL, NULL, &errmsg);
108 if (r != SQLITE_OK) {
109 LOGE("fail to exec delete query %s : %s", query, errmsg);
110 sqlite3_free(errmsg);
120 int rua_db_add_history(struct rua_rec *rec)
122 return rua_usr_db_add_history(rec, getuid());
125 int rua_usr_db_add_history(struct rua_rec *rec, uid_t uid)
128 char query[QUERY_MAXLEN];
133 LOGE("Error db null");
138 LOGE("Error rec null");
143 snprintf(query, QUERY_MAXLEN,
144 "insert or replace into %s ( pkg_name, app_path, arg, launch_time) "
145 " values ( \"%s\", \"%s\", \"%s\", %d) ",
147 rec->pkg_name ? rec->pkg_name : "",
148 rec->app_path ? rec->app_path : "",
149 rec->arg ? rec->arg : "", (int)rec->launch_time);
151 r = __exec(db, query);
153 LOGE("[RUA ADD HISTORY ERROR] %s\n", query);