Add a new table into DB for checking recent history 39/230039/6
authorInHong Han <inhong1.han@samsung.com>
Tue, 7 Apr 2020 09:21:24 +0000 (18:21 +0900)
committerInHong Han <inhong1.han@samsung.com>
Thu, 9 Apr 2020 10:54:12 +0000 (19:54 +0900)
Change-Id: I78725d047ab6b5e1c24a4c49b63ab69bde6d17d7

server/stickerd_db_manager.c
sticker-parser/sticker-parser.c

index 3adda1b..7e6c8e1 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 (?, ?)"
@@ -197,6 +205,12 @@ static int _recover_db(void)
         ret = STICKERD_SERVER_ERROR_DB_FAILED;
     }
 
+    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;
+    }
+
     is_corrupted = FALSE;
 
 cleanup:
@@ -255,6 +269,13 @@ int stickerd_db_init(void)
         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);
     if (ret != SQLITE_OK) {
         LOGE("Failed to set journal_mode : %s", err);
index 86ebd3e..a3f96b5 100644 (file)
@@ -44,6 +44,7 @@
 #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 UIFW_ID           502
 #define APPFW_ID          301
 #define MAX_ERROR_BUFFER  256
@@ -130,6 +131,12 @@ static void __recover_db()
         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);
+        goto cleanup;
+    }
+
     is_corrupted = FALSE;
 
 cleanup:
@@ -186,6 +193,12 @@ static void __db_init()
         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);
+        goto cleanup;
+    }
+
     ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err);
     if (ret != SQLITE_OK) {
         LOGE("Failed to set journal_mode : %s", err);