/* * Copyright (c) 2014-2017 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. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * @file db-crypto-ext.cpp * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com) * @version 1.0 * @brief Limited implementation of encrypted db access layer */ #include #include namespace CKM { namespace DB { const char *DB_CMD_OBJECT_SELECT = "SELECT * FROM [join_name_object_tables];"; SqlConnection::Output CryptoExt::Execute(const std::string &cmd) { SqlConnection::Output out; if (!m_connection) { ThrowMsg(SqlConnection::Exception::ConnectionBroken, "Not connected to database"); } m_connection->ExecCommand(&out, "%s", cmd.c_str()); return out; } RowVector CryptoExt::getRows() { try { RowVector output; SqlConnection::DataCommandUniquePtr selectCommand = m_connection->PrepareDataCommand(DB_CMD_OBJECT_SELECT); while (selectCommand->Step()) { // extract data output.push_back(getRow(selectCommand)); } return output; } 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"); } ThrowErr(Exc::DatabaseFailed, "Couldn't get row from database"); } } // namespace DB } // namespace CKM