From: Inkyun Kil Date: Tue, 13 Dec 2022 01:21:15 +0000 (+0900) Subject: Fix issue for cion initialization X-Git-Tag: accepted/tizen/unified/20221213.123156~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d2f542fc3021bff1c81c595b4c0bad093883f7c;p=platform%2Fcore%2Fappfw%2Fevent-system.git Fix issue for cion initialization - Fix issue for checking if table is exist Requires: - https://review.tizen.org/gerrit/#/c/platform/core/base/bundle/+/285443/ Change-Id: I02461a8caf3986699bebf327d8b20a359e3ed345 Signed-off-by: Inkyun Kil --- diff --git a/src/modules/cion/cion_module.cc b/src/modules/cion/cion_module.cc index ec945f0..86fa6fa 100644 --- a/src/modules/cion/cion_module.cc +++ b/src/modules/cion/cion_module.cc @@ -35,8 +35,6 @@ namespace { constexpr const char CREATE_CION_TABLE[] = R"__cion( PRAGMA user_version = 50; PRAGMA journal_mode = PERSIST; -PRAGMA foreign_keys = ON; -BEGIN EXCLUSIVE TRANSACTION; CREATE TABLE IF NOT EXISTS cion_uuid ( appid TEXT NOT NULL, uuid TEXT NOT NULL, @@ -50,33 +48,18 @@ CREATE TABLE IF NOT EXISTS cion_display_name ( PRIMARY KEY(service_name, appid) , FOREIGN KEY(appid) REFERENCES cion_uuid (appid) ON DELETE CASCADE ); -COMMIT TRANSACTION; )__cion"; bool CreateTable(const tizen_base::Database& db) { - auto q = tizen_base::Database::Sql(CREATE_CION_TABLE); - auto r = db.Exec(q); - if (!static_cast(r)) - return false; - - return true; -} - -bool IsTableExist(const tizen_base::Database& db) { - auto q = tizen_base::Database::Sql( - "SELECT name FROM sqlite_master WHERE type='table'" - " ORDER BY name ASC"); - auto r = db.Exec(q); - if (!static_cast(r)) + try { + auto q = tizen_base::Database::Sql(CREATE_CION_TABLE); + db.OneStepExec(q); + } catch (const tizen_base::DbException& e) { + _E("Exception(%s) occurs", e.msg()); return false; - - for (const auto& i : r) { - auto table_name = static_cast(i.Get(0)); - if (table_name == "cion") - return true; } - return false; + return true; } } // namespace @@ -185,24 +168,22 @@ void CionModule::RemoveEnabledApp(const std::string& service_name, bool CionModule::DbInit() { try { tizen_base::Database db(DBPATH, SQLITE_OPEN_READWRITE); - if (IsTableExist(db)) { - if (!CreateTable(db)) { - _E("Fail to create table"); - return false; - } + if (!CreateTable(db)) { + _E("Fail to create table"); + return false; } - } catch(const std::runtime_error&) { + } catch (const tizen_base::DbException& e) { + _E("runtime error(%s) occurs", e.msg()); unlink(DBPATH); try { tizen_base::Database db(DBPATH, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE); - if (IsTableExist(db)) { - if (!CreateTable(db)) { - _E("Fail to create table"); - return false; - } + if (!CreateTable(db)) { + _E("Fail to create table"); + return false; } - } catch(const std::runtime_error&) { + } catch (const tizen_base::DbException& e) { + _E("runtime error(%s) occurs", e.msg()); unlink(DBPATH); return false; }