Fix build error in sticker-receiver
[platform/core/uifw/capi-ui-sticker.git] / server / stickerd_db_manager.c
index 3b54fb4..85a778e 100644 (file)
  * | whitelist_id | provider_id | consumer_id |
  * +------------+---------------+-------------+
  *
+ * sticker_recent_history_info
+ * +------------+-----------------+-------+-----------+
+ * | INT        | INT             | INT   | TEXT      |
+ * +------------+-----------------+-------+-----------+
+ * | history_id | sticker_info_id | count | timestamp |
+ * +------------+-----------------+-------+-----------+
+ *
  */
 
 #define STICKER_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db")
 #define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL, display_type INTEGER)"
 #define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
 #define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)"
+#define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
 
 #define STICKER_DB_INSERT_STICKER_INFO "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date, display_type) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'), ?)"
 #define STICKER_DB_INSERT_STICKER_KEYWORD_INFO "INSERT INTO sticker_keyword_info (sticker_info_id, keyword) VALUES (?, ?)"
+#define STICKER_DB_INSERT_RECENT_HISTORY "INSERT INTO sticker_recent_history_info (sticker_info_id, count, timestamp) VALUES (?, 1, DateTime('now','localtime'))"
 
 #define STICKER_DB_DELETE_STICKER_INFO "DELETE FROM sticker_info WHERE sticker_info_id = ?"
 #define STICKER_DB_DELETE_STICKER_KEYWORD_INFO "DELETE FROM sticker_keyword_info WHERE sticker_info_id = ?"
+#define STICKER_DB_DELETE_STICKER_INFO_BY_URI "DELETE FROM sticker_info WHERE uri = ?"
 
 #define STICKER_DB_UPDATE_STICKER_TYPE "UPDATE sticker_info SET type = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?"
 #define STICKER_DB_UPDATE_STICKER_URI "UPDATE sticker_info SET uri = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?"
 #define STICKER_DB_UPDATE_STICKER_DESCRIPTION "UPDATE sticker_info SET description = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?"
 #define STICKER_DB_UPDATE_STICKER_GROUP "UPDATE sticker_info SET group_name = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?"
 #define STICKER_DB_UPDATE_STICKER_DISP_TYPE "UPDATE sticker_info SET display_type = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?"
+#define STICKER_DB_UPDATE_RECENT_HISTORY "UPDATE sticker_recent_history_info SET count = count + 1, timestamp = DateTime('now','localtime') WHERE sticker_info_id = ?"
 
 #define STICKER_DB_GET_LATEST_RECORD_ID "SELECT sticker_info_id FROM sticker_info ORDER BY sticker_info_id DESC LIMIT 1"
 #define STICKER_DB_GET_STICKER_INFO_BY_RECORD_ID "SELECT * FROM sticker_info WHERE sticker_info_id = ?"
 #define STICKER_DB_GET_KEYWORD_INFO_BY_RECORD_ID "SELECT keyword FROM sticker_keyword_info WHERE sticker_info_id = ?"
+#define STICKER_DB_GET_IMAGE_INFO_BY_RECORED_ID "SELECT type, uri, thumbnail FROM sticker_info WHERE sticker_info_id = ?"
+#define STICKER_DB_GET_IMAGE_INFO_BY_URI "SELECT type, thumbnail FROM sticker_info WHERE uri = ?"
 #define STICKER_DB_GET_ALL_GROUP_LIST "SELECT DISTINCT group_name FROM sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?))"
 #define STICKER_DB_GET_ALL_KEYWORD_LIST "SELECT DISTINCT keyword FROM sticker_keyword_info WHERE sticker_info_id IN (SELECT sticker_info_id from sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)))"
 #define STICKER_DB_GET_STICKER_COUNT "SELECT count(*) FROM sticker_info WHERE app_id = ?"
-#define STICKER_DB_GET_ALL_RECORD_ID "SELECT sticker_info_id FROM sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?"
-#define STICKER_DB_GET_RECORD_ID_BY_APP_ID "SELECT sticker_info_id from sticker_info WHERE app_id = ? LIMIT ?, ?"
-#define STICKER_DB_GET_RECORD_ID_BY_TYPE "SELECT sticker_info_id FROM sticker_info WHERE type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?"
-#define STICKER_DB_GET_RECORD_ID_BY_GROUP "SELECT sticker_info_id from sticker_info WHERE group_name = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?"
-#define STICKER_DB_GET_RECORD_ID_BY_KEYWORD "SELECT sticker_info_id FROM sticker_keyword_info WHERE keyword = ? INTERSECT SELECT sticker_info_id from sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?"
-#define STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE "SELECT sticker_info_id FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) LIMIT ?, ?"
+#define STICKER_DB_GET_ALL_RECORD_ID "SELECT sticker_info_id FROM sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) ORDER BY sticker_info_id DESC LIMIT ?, ?"
+#define STICKER_DB_GET_RECORD_ID_BY_APP_ID "SELECT sticker_info_id from sticker_info WHERE app_id = ? ORDER BY sticker_info_id DESC LIMIT ?, ?"
+#define STICKER_DB_GET_RECORD_ID_BY_TYPE "SELECT sticker_info_id FROM sticker_info WHERE type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) ORDER BY sticker_info_id DESC LIMIT ?, ?"
+#define STICKER_DB_GET_RECORD_ID_BY_GROUP "SELECT sticker_info_id from sticker_info WHERE group_name = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) ORDER BY sticker_info_id DESC LIMIT ?, ?"
+#define STICKER_DB_GET_RECORD_ID_BY_KEYWORD "SELECT sticker_info_id FROM sticker_keyword_info WHERE keyword = ? INTERSECT SELECT sticker_info_id from sticker_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) ORDER BY sticker_info_id DESC LIMIT ?, ?"
+#define STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE "SELECT sticker_info_id FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?)) ORDER BY sticker_info_id DESC LIMIT ?, ?"
 #define STICKER_DB_GET_GROUP_LIST_BY_DISP_TYPE "SELECT DISTINCT group_name FROM sticker_info WHERE display_type = ? AND app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?))"
+#define STICKER_DB_CHECK_FILE_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_info WHERE uri = ? LIMIT 1)"
+#define STICKER_DB_CHECK_RECENT_HISTORY_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_recent_history_info WHERE sticker_info_id = ? LIMIT 1)"
+#define STICKER_DB_GET_RECENT_HISTORY "SELECT sticker_info_id FROM sticker_recent_history_info ORDER BY datetime(timestamp) DESC LIMIT ?"
+#define STICKER_DB_GET_STICKER_INFO_BY_URI "SELECT * FROM sticker_info WHERE uri = ?"
 
 typedef enum
 {
@@ -144,6 +161,9 @@ static const char *_db_get_query(sticker_info_db_type sticker_type, command_type
             case STICKER_DB_STICKER_DISP_TYPE:
             query = STICKER_DB_GET_RECORD_ID_BY_DISP_TYPE;
             break;
+            case STICKER_DB_STICKER_RECENT_HISTORY:
+            query = STICKER_DB_GET_RECENT_HISTORY;
+            break;
             default :
             query = "";
             break;
@@ -184,12 +204,21 @@ static int _recover_db(void)
     if (ret != SQLITE_OK) {
         LOGE("Failed to create sticker_keyword_info table : %s", err);
         ret = STICKERD_SERVER_ERROR_DB_FAILED;
+        goto cleanup;
     }
 
     ret = sqlite3_exec(db, STICKER_WHITELIST_INFO_CREATE_TABLE, NULL, NULL, &err);
     if (ret != SQLITE_OK) {
         LOGE("Failed to create sticker_whitelist_info table : %s", err);
         ret = STICKERD_SERVER_ERROR_DB_FAILED;
+        goto cleanup;
+    }
+
+    ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err);
+    if (ret != SQLITE_OK) {
+        LOGE("Failed to create sticker_recent_history_info table : %s", err);
+        ret = STICKERD_SERVER_ERROR_DB_FAILED;
+        goto cleanup;
     }
 
     is_corrupted = FALSE;
@@ -247,6 +276,14 @@ int stickerd_db_init(void)
     if (ret != SQLITE_OK) {
         LOGE("Failed to create sticker_whitelist_info table : %s", err);
         ret = STICKERD_SERVER_ERROR_DB_FAILED;
+        goto cleanup;
+    }
+
+    ret = sqlite3_exec(db, STICKER_RECENT_HISTORY_INFO_CREATE_TABLE, NULL, NULL, &err);
+    if (ret != SQLITE_OK) {
+        LOGE("Failed to create sticker_recent_history_info table : %s", err);
+        ret = STICKERD_SERVER_ERROR_DB_FAILED;
+        goto cleanup;
     }
 
     ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err);
@@ -281,6 +318,9 @@ static sqlite3 *_db_open(void)
     sqlite3 *db = NULL;
     char *err = NULL;
 
+    if (is_corrupted && _recover_db() != SQLITE_OK)
+        return NULL;
+
     ret = sqlite3_open(STICKER_DB_PATH, &db);
     if (ret != SQLITE_OK) {
         LOGE("Failed to open db : %s", sqlite3_errmsg(db));
@@ -396,6 +436,33 @@ int stickerd_db_delete_sticker_info(int record_id)
     if (!db)
         return STICKERD_SERVER_ERROR_DB_FAILED;
 
+    ret = sqlite3_prepare_v2(db, STICKER_DB_GET_IMAGE_INFO_BY_RECORED_ID, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to get image files : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_int(stmt, 1, record_id);
+
+    ret = sqlite3_step(stmt);
+    if (ret == SQLITE_ERROR) {
+        LOGE("sqlite3_step() failed : ret(%d)", ret);
+        goto cleanup;
+    }
+
+    int uri_type = sqlite3_column_int(stmt, 0);
+    const unsigned char *uri = sqlite3_column_text(stmt, 1);
+    const unsigned char *thumbnail = sqlite3_column_text(stmt, 2);
+
+    if (uri_type == 1 && unlink((const char *)uri) == -1)
+        LOGE("fail to delete sticker file");
+
+    if (thumbnail && unlink((const char *)thumbnail) == -1)
+        LOGE("fail to delete thumbnail image");
+
+    sqlite3_finalize(stmt);
+    stmt = NULL;
+
     ret = sqlite3_prepare_v2(db, STICKER_DB_DELETE_STICKER_INFO, -1, &stmt, NULL);
     if (ret != SQLITE_OK) {
         LOGE("fail to delete sticker information : %s", sqlite3_errmsg(db));
@@ -425,6 +492,71 @@ cleanup:
     return STICKERD_SERVER_ERROR_DB_FAILED;
 }
 
+int stickerd_db_delete_sticker_info_by_uri(char *uri)
+{
+    int ret;
+    sqlite3 *db = NULL;
+    sqlite3_stmt *stmt = NULL;
+
+    db = _db_open();
+    if (!db)
+        return STICKERD_SERVER_ERROR_DB_FAILED;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_GET_IMAGE_INFO_BY_URI, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to delete sticker information : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_text(stmt, 1, uri, -1, SQLITE_TRANSIENT);
+
+    ret = sqlite3_step(stmt);
+    if (ret == SQLITE_ERROR) {
+        LOGE("sqlite3_step() failed : ret(%d)", ret);
+        goto cleanup;
+    }
+
+    int uri_type = sqlite3_column_int(stmt, 0);
+    const unsigned char *thumbnail = sqlite3_column_text(stmt, 1);
+
+    if (uri_type == 1 && unlink((const char *)uri) == -1)
+        LOGE("fail to delete sticker file");
+
+    if (thumbnail && unlink((const char *)thumbnail) == -1)
+        LOGE("fail to delete thumbnail image");
+
+    sqlite3_finalize(stmt);
+    stmt = NULL;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_DELETE_STICKER_INFO_BY_URI, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to delete sticker information : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_text(stmt, 1, uri, -1, SQLITE_TRANSIENT);
+
+    ret = sqlite3_step(stmt);
+    if (ret != SQLITE_OK && ret != SQLITE_DONE) {
+        LOGE("sqlite3_step() failed : ret(%d)", ret);
+        goto cleanup;
+    } else if (sqlite3_changes(db) == 0) {
+        LOGE("No changes to DB");
+        goto cleanup;
+    }
+
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_NONE;
+
+cleanup:
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
 int stickerd_db_update_sticker_info(int record_id, sticker_info_db_type type, void *data)
 {
     int ret;
@@ -713,6 +845,8 @@ int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *
         sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT);
         sqlite3_bind_int(stmt, 2, offset);
         sqlite3_bind_int(stmt, 3, count);
+    } else if (type == STICKER_DB_STICKER_RECENT_HISTORY) {
+        sqlite3_bind_int(stmt, 1, count);
     } else {
         if (type == STICKER_DB_STICKER_TYPE || type == STICKER_DB_STICKER_DISP_TYPE)
             sqlite3_bind_int(stmt, 1, *(int *)data);
@@ -777,4 +911,187 @@ cleanup:
     sqlite3_close(db);
 
     return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
+int stickerd_db_check_file_exists(int *result, char *uri)
+{
+    int ret;
+    sqlite3 *db = NULL;
+    sqlite3_stmt *stmt = NULL;
+
+    db = _db_open();
+    if (!db)
+        return STICKERD_SERVER_ERROR_DB_FAILED;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_CHECK_FILE_EXISTS, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to check file exists : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_text(stmt, 1, uri, -1, SQLITE_TRANSIENT);
+
+    ret = sqlite3_step(stmt);
+    if (ret == SQLITE_ERROR) {
+        LOGE("sqlite3_step() failed : ret(%d)", ret);
+        goto cleanup;
+    }
+
+    *result = sqlite3_column_int(stmt, 0);
+
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_NONE;
+
+cleanup:
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
+int stickerd_db_insert_recent_sticker_info(int record_id)
+{
+    int ret;
+    sqlite3 *db = NULL;
+    sqlite3_stmt *stmt = NULL;
+
+    db = _db_open();
+    if (!db)
+        return STICKERD_SERVER_ERROR_DB_FAILED;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_CHECK_RECENT_HISTORY_EXISTS, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to check recent sticker exists : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_int(stmt, 1, record_id);
+
+    ret = sqlite3_step(stmt);
+    if (ret == SQLITE_ERROR) {
+        LOGE("sqlite3_step() failed : ret(%d)", ret);
+        goto cleanup;
+    }
+
+    int result = sqlite3_column_int(stmt, 0);
+
+    sqlite3_finalize(stmt);
+    stmt = NULL;
+
+    if (result)
+        ret = sqlite3_prepare_v2(db, STICKER_DB_UPDATE_RECENT_HISTORY, -1, &stmt, NULL);
+    else
+        ret = sqlite3_prepare_v2(db, STICKER_DB_INSERT_RECENT_HISTORY, -1, &stmt, NULL);
+
+    if (ret != SQLITE_OK) {
+        LOGE("fail to update recent history : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_int(stmt, 1, record_id);
+
+    ret = sqlite3_step(stmt);
+    if (ret != SQLITE_OK && ret != SQLITE_DONE) {
+        LOGE("sqlite3_step() failed : ret(%d)", ret);
+        goto cleanup;
+    } else if (sqlite3_changes(db) == 0) {
+        LOGE("No changes to DB");
+        goto cleanup;
+    }
+
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_NONE;
+
+cleanup:
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
+int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info)
+{
+    int ret;
+    sqlite3 *db = NULL;
+    sqlite3_stmt *stmt = NULL;
+
+    db = _db_open();
+    if (!db)
+        return STICKERD_SERVER_ERROR_DB_FAILED;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_GET_STICKER_INFO_BY_URI, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to get sticker information : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_text(stmt, 1, uri, -1, SQLITE_TRANSIENT);
+
+    ret = sqlite3_step(stmt);
+    if (ret == SQLITE_ERROR) {
+        LOGE("sqlite3_step() failed : ret(%d)", ret);
+        goto cleanup;
+    }
+
+    sticker_info->record_id = sqlite3_column_int(stmt, 0);
+
+    const unsigned char *tmp_app_id = sqlite3_column_text(stmt, 1);
+    if (tmp_app_id)
+        sticker_info->app_id = strdup((const char *)tmp_app_id);
+
+    sticker_info->type = sqlite3_column_int(stmt, 2);
+
+    const unsigned char *tmp_uri = sqlite3_column_text(stmt, 3);
+    if (tmp_uri)
+        sticker_info->uri = strdup((const char *)tmp_uri);
+
+    const unsigned char *tmp_thumbnail = sqlite3_column_text(stmt, 4);
+    if (tmp_thumbnail)
+        sticker_info->thumbnail = strdup((const char *)tmp_thumbnail);
+
+    const unsigned char *tmp_description = sqlite3_column_text(stmt, 5);
+    if (tmp_description)
+        sticker_info->description = strdup((const char *)tmp_description);
+
+    const unsigned char *tmp_group = sqlite3_column_text(stmt, 6);
+    if (tmp_group)
+        sticker_info->group = strdup((const char *)tmp_group);
+
+    const unsigned char *tmp_date = sqlite3_column_text(stmt, 7);
+    if (tmp_date)
+        sticker_info->date = strdup((const char *)tmp_date);
+
+    sticker_info->display_type = sqlite3_column_int(stmt, 8);
+
+    sqlite3_finalize(stmt);
+    stmt = NULL;
+
+    ret = sqlite3_prepare_v2(db, STICKER_DB_GET_KEYWORD_INFO_BY_RECORD_ID, -1, &stmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("fail to get sticker keyword : %s", sqlite3_errmsg(db));
+        goto cleanup;
+    }
+
+    sqlite3_bind_int(stmt, 1, sticker_info->record_id);
+
+    while (sqlite3_step(stmt) == SQLITE_ROW) {
+        const unsigned char *keyword = sqlite3_column_text(stmt, 0);
+        if (keyword)
+            sticker_info->keyword = g_list_append(sticker_info->keyword, strdup((const char *)keyword));
+    }
+
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_NONE;
+
+cleanup:
+    sqlite3_finalize(stmt);
+    sqlite3_close(db);
+
+    return STICKERD_SERVER_ERROR_DB_FAILED;
 }
\ No newline at end of file