[ServiceDB] check model in database
authorJaeyun Jung <jy1210.jung@samsung.com>
Tue, 12 Dec 2023 11:29:49 +0000 (20:29 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 12 Dec 2023 13:05:19 +0000 (22:05 +0900)
Add condition to check model is registered in database.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
daemon/service-db.cc

index e7d3846..ebe849d 100644 (file)
@@ -649,6 +649,12 @@ MLServiceDB::get_model (const std::string name, std::string &model, const gint v
   std::string key_with_prefix = DB_KEY_PREFIX + std::string ("_model_");
   key_with_prefix += name;
 
+  /* check the existence of given model */
+  guint ver = (version > 0) ? version : 0U;
+  if (!is_model_registered (key_with_prefix, ver)) {
+    throw std::invalid_argument ("Failed to check the existence of " + name);
+  }
+
   if (version == 0)
     sql = g_strdup_printf (
         "SELECT json_group_array(%s) FROM tblModel WHERE key = ?1", model_info_json);