From: Hwankyu Jhun Date: Tue, 13 Dec 2022 05:33:03 +0000 (+0000) Subject: Enable foreign_keys X-Git-Tag: accepted/tizen/unified/20221214.053551~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=600f9b1f37a53d28562cccc736fd535545ef036e;p=platform%2Fcore%2Fappfw%2Fevent-system.git Enable foreign_keys This patch is for foreign_keys setting for cion db. Change-Id: Id3e101f78ed12330eb5eb0fa01f756e6376a3530 Signed-off-by: Hwankyu Jhun --- diff --git a/src/modules/cion/cion_module.cc b/src/modules/cion/cion_module.cc index 86fa6fa..758ea7f 100644 --- a/src/modules/cion/cion_module.cc +++ b/src/modules/cion/cion_module.cc @@ -35,6 +35,7 @@ namespace { constexpr const char CREATE_CION_TABLE[] = R"__cion( PRAGMA user_version = 50; PRAGMA journal_mode = PERSIST; +PRAGMA foreign_keys = ON; CREATE TABLE IF NOT EXISTS cion_uuid ( appid TEXT NOT NULL, uuid TEXT NOT NULL, @@ -50,6 +51,8 @@ CREATE TABLE IF NOT EXISTS cion_display_name ( ); )__cion"; +constexpr const char PRAGMA_FOREIGN_KEYS[] = "PRAGMA foreign_keys;"; + bool CreateTable(const tizen_base::Database& db) { try { auto q = tizen_base::Database::Sql(CREATE_CION_TABLE); @@ -62,6 +65,19 @@ bool CreateTable(const tizen_base::Database& db) { return true; } +bool IsEnabledForeignKeys(const tizen_base::Database& db) { + try { + auto sql = tizen_base::Database::Sql(PRAGMA_FOREIGN_KEYS); + auto result = db.Exec(sql); + for (const auto& i : result) + return static_cast(i.Get(0)) ? true : false; + } catch (const tizen_base::DbException& e) { + _E("Exception(%s) occurs", e.msg()); + } + + return false; +} + } // namespace bool CionModule::Startup(api::ToolBox* tools) { @@ -172,6 +188,8 @@ bool CionModule::DbInit() { _E("Fail to create table"); return false; } + + _W("foreign_keys: %s", IsEnabledForeignKeys(db) ? "ON" : "OFF"); } catch (const tizen_base::DbException& e) { _E("runtime error(%s) occurs", e.msg()); unlink(DBPATH); @@ -182,6 +200,8 @@ bool CionModule::DbInit() { _E("Fail to create table"); return false; } + + _W("foreign_keys: %s", IsEnabledForeignKeys(db) ? "ON" : "OFF"); } catch (const tizen_base::DbException& e) { _E("runtime error(%s) occurs", e.msg()); unlink(DBPATH);