2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jan Olszak <j.olszak@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
21 * @author Jan Olszak (j.olszak@samsung.com)
22 * @brief Definition of the class managing a sqlite3 database connection
26 #include "config/sqlite3/connection.hpp"
27 #include "config/exception.hpp"
32 Connection::Connection(const std::string& path)
34 if (::sqlite3_open_v2(path.c_str(),
36 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
38 throw ConfigException("Error opening the database: " + getErrorMessage());
42 throw ConfigException("Error opening the database: Unable to allocate memory.");
46 Connection::~Connection()
48 if (::sqlite3_close(mDbPtr) != SQLITE_OK) {
49 throw ConfigException("Error during closing the database. Error: " + getErrorMessage());
53 void Connection::exec(const std::string& query)
56 if (::sqlite3_exec(mDbPtr, query.c_str(), 0, 0, &mess) != SQLITE_OK) {
57 throw ConfigException("Error during executing statement " + std::string(mess));
61 ::sqlite3* Connection::get()
66 std::string Connection::getErrorMessage()
68 return std::string(sqlite3_errmsg(mDbPtr));
71 } // namespace sqlite3