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,
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<bool>(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<bool>(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<std::string>(i.Get(0));
- if (table_name == "cion")
- return true;
}
- return false;
+ return true;
}
} // namespace
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;
}