Add rua history update APIs 33/244033/1
authorhyunho <hhstark.kang@samsung.com>
Mon, 14 Sep 2020 07:52:27 +0000 (16:52 +0900)
committerhyunho <hhstark.kang@samsung.com>
Mon, 14 Sep 2020 07:52:27 +0000 (16:52 +0900)
Change-Id: If0ce1c2c7d5a28d93bce413dc5d732552f7769fa
Signed-off-by: hyunho <hhstark.kang@samsung.com>
include/rua_internal.h
src/rua_internal.c

index a9c7c22..e1cf72c 100644 (file)
@@ -65,6 +65,10 @@ int rua_db_update_image(const char *pkg_name, const char *comp_id,
                const char *instance_id, const char *image);
 int rua_usr_db_update_image(const char *pkg_name, const char *comp_id,
                const char *instance_id, const char *image, uid_t uid);
+int rua_usr_db_update_history(const char *pkg_name,
+               const char *comp_id, int launch_time, uid_t uid);
+int rua_db_update_history(const char *pkg_name,
+               const char *comp_id, int launch_time);
 
 #ifdef __cplusplus
 }
index 0bb4305..287b7fa 100644 (file)
@@ -286,6 +286,54 @@ static int __update_history(sqlite3 *db, struct rua_rec *rec)
        return 0;
 }
 
+API int rua_usr_db_update_history(const char *pkg_name,
+               const char *comp_id, int launch_time, uid_t uid)
+{
+       static const char query[] =
+               "UPDATE rua_history SET launch_time=? "
+               "WHERE pkg_name=? AND comp_id=?";
+       int r;
+       sqlite3_stmt *stmt;
+       int idx = 1;
+       sqlite3 *db;
+
+       db = __db_init(uid);
+       if (db == NULL) {
+               LOGE("Error db null");
+               return -1;
+       }
+
+       r = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (r != SQLITE_OK) {
+               LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               sqlite3_close_v2(db);
+               return -1;
+       }
+
+       __BIND_INT(db, stmt, idx++, launch_time);
+       __BIND_TEXT(db, stmt, idx++, pkg_name);
+       __BIND_TEXT(db, stmt, idx++, comp_id ? comp_id : "");
+
+       r = sqlite3_step(stmt);
+       if (r != SQLITE_DONE) {
+               LOGE("step failed: %s", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               sqlite3_close_v2(db);
+               return -1;
+       }
+
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(db);
+       return r;
+}
+
+API int rua_db_update_history(const char *pkg_name,
+               const char *comp_id, int launch_time)
+{
+       return rua_usr_db_update_history(
+               pkg_name, comp_id, launch_time, getuid());
+}
+
 API int rua_usr_db_add_history(struct rua_rec *rec, uid_t uid)
 {
        int r;