/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
bool Crypto::getDBVersion(int &schemaVersion)
{
- SchemaInfo SchemaInfo(this);
-
- if (SchemaInfo.getVersionInfo(schemaVersion)) {
- LogDebug("Current DB version: " << schemaVersion);
- return true;
- } else {
- LogDebug("No DB version known or DB not present");
+ Transaction transaction(this);
- if (m_connection->CheckTableExist("CKM_TABLE")) {
- // special case: old CKM_TABLE exists
- schemaVersion = DB_VERSION_1;
- return true;
- } else if (m_connection->CheckTableExist("NAME_TABLE")) {
- // special case: new scheme exists, but no SCHEMA_INFO table present
- schemaVersion = DB_VERSION_2;
+ if (m_connection->CheckTableExist("SCHEMA_INFO")) {
+ SchemaInfo SchemaInfo(m_connection);
+ if (SchemaInfo.getVersionInfo(schemaVersion)) {
+ LogDebug("Current DB version: " << schemaVersion);
return true;
}
}
+ LogDebug("No DB version known or DB not present");
+
+ if (m_connection->CheckTableExist("CKM_TABLE")) {
+ // special case: old CKM_TABLE exists
+ schemaVersion = DB_VERSION_1;
+ return true;
+ } else if (m_connection->CheckTableExist("NAME_TABLE")) {
+ // special case: new scheme exists, but no SCHEMA_INFO table present
+ schemaVersion = DB_VERSION_2;
+ return true;
+ }
+
// not recognized - proceed with an empty DBs
return false;
}
}
// update DB version info
- SchemaInfo SchemaInfo(this);
+ SchemaInfo SchemaInfo(m_connection);
SchemaInfo.setVersionInfo();
transaction.commit();
}
"Can not create the database schema: no initialization script");
m_connection->ExecCommand((*script).c_str());
- SchemaInfo SchemaInfo(this);
+ SchemaInfo SchemaInfo(m_connection);
SchemaInfo.setVersionInfo();
transaction.commit();
}
void Crypto::SchemaInfo::setVersionInfo()
{
SqlConnection::DataCommandUniquePtr insertContextCommand =
- m_db->m_connection->PrepareDataCommand(DB_CMD_SCHEMA_SET);
+ m_connection->PrepareDataCommand(DB_CMD_SCHEMA_SET);
insertContextCommand->BindString(101, DB_SCHEMA_VERSION_FIELD);
insertContextCommand->BindString(103,
std::to_string(DB_VERSION_CURRENT).c_str());
insertContextCommand->Step();
}
-bool Crypto::SchemaInfo::getVersionInfo(int &version) const
+bool Crypto::SchemaInfo::getVersionInfo(int &version)
{
- // Try..Catch mandatory here - we don't need to escalate the error
- // if it happens - we just won't return the version, allowing CKM to work
- try {
- SqlConnection::DataCommandUniquePtr selectCommand =
- m_db->m_connection->PrepareDataCommand(DB_CMD_SCHEMA_GET);
- selectCommand->BindString(101, DB_SCHEMA_VERSION_FIELD);
+ SqlConnection::DataCommandUniquePtr selectCommand =
+ m_connection->PrepareDataCommand(DB_CMD_SCHEMA_GET);
+ selectCommand->BindString(101, DB_SCHEMA_VERSION_FIELD);
- if (selectCommand->Step()) {
- version = static_cast<int>(atoi(selectCommand->GetColumnString(1).c_str()));
- return true;
- }
- } catch (const SqlConnection::Exception::InvalidColumn &) {
- LogError("Select statement invalid column error");
- } catch (const SqlConnection::Exception::SyntaxError &) {
- LogError("Couldn't prepare select statement");
- } catch (const SqlConnection::Exception::InternalError &) {
- LogError("Couldn't execute select statement");
+ if (selectCommand->Step()) {
+ version = static_cast<int>(atoi(selectCommand->GetColumnString(1).c_str()));
+ return true;
}
-
return false;
}