summaryrefslogtreecommitdiff
path: root/src/components/utils/include/utils/sqlite_wrapper/sql_database_impl.h
diff options
context:
space:
mode:
authorAGaliuzov <AGaliuzov@luxoft.com>2016-06-23 05:30:34 -0700
committerGitHub <noreply@github.com>2016-06-23 05:30:34 -0700
commit833cac1b1de464f53d5709904a4ee24634be2936 (patch)
treeeceabb5046166e9b3d3a02fcd76496f88a177390 /src/components/utils/include/utils/sqlite_wrapper/sql_database_impl.h
parent405c303a9ef5238c659374785c4bbdc1140ca564 (diff)
parent48692790e4819261878eed1525d391bdde149ff4 (diff)
downloadsdl_core-833cac1b1de464f53d5709904a4ee24634be2936.tar.gz
Merge pull request #618 from Kozoriz/feature/Cover_resumption_with_unit_tests
Cover resumption with unit tests
Diffstat (limited to 'src/components/utils/include/utils/sqlite_wrapper/sql_database_impl.h')
-rw-r--r--src/components/utils/include/utils/sqlite_wrapper/sql_database_impl.h156
1 files changed, 156 insertions, 0 deletions
diff --git a/src/components/utils/include/utils/sqlite_wrapper/sql_database_impl.h b/src/components/utils/include/utils/sqlite_wrapper/sql_database_impl.h
new file mode 100644
index 0000000000..d9984604a9
--- /dev/null
+++ b/src/components/utils/include/utils/sqlite_wrapper/sql_database_impl.h
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2016, Ford Motor Company
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of the Ford Motor Company nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_UTILS_INCLUDE_UTILS_SQLITE_WRAPPER_SQL_DATABASE_IMPL_H_
+#define SRC_COMPONENTS_UTILS_INCLUDE_UTILS_SQLITE_WRAPPER_SQL_DATABASE_IMPL_H_
+
+#include <string>
+
+#include "utils/sql_database.h"
+#include "utils/sqlite_wrapper/sql_error.h"
+#include "utils/lock.h"
+
+namespace utils {
+namespace dbms {
+/**
+ * Represents a connection to a database.
+ */
+class SQLDatabaseImpl : public SQLDatabase {
+ public:
+ SQLDatabaseImpl();
+ explicit SQLDatabaseImpl(const std::string& filename);
+ ~SQLDatabaseImpl();
+
+ /**
+ * Opens connection to the temporary in-memory database
+ * @return true if successfully
+ */
+ bool Open() OVERRIDE;
+
+ /**
+ * Closes connection to the database
+ */
+ void Close() OVERRIDE;
+
+ /**
+ * Begins a transaction on the database
+ * @return true if successfully
+ */
+ bool BeginTransaction() OVERRIDE;
+
+ /**
+ * Commits a transaction to the database
+ * @return true if successfully
+ */
+ bool CommitTransaction() OVERRIDE;
+
+ /**
+ * Rolls back a transaction on the database
+ * @return true if successfully
+ */
+ bool RollbackTransaction() OVERRIDE;
+
+ /**
+ * Gets information about the last error that occurred on the database
+ * @return last error
+ */
+ SQLError LastError() const OVERRIDE;
+
+ /**
+ * @brief HasErrors Indicate the status of the last executed operation.
+ *
+ * @return true in case last operation has any errors, false otherwise.
+ */
+ bool HasErrors() const OVERRIDE;
+
+ void set_path(const std::string& path) OVERRIDE;
+
+ /**
+ * @brief get_path databse location path.
+ *
+ * @return the path to the database location
+ */
+ std::string get_path() const OVERRIDE;
+
+ /**
+ * Checks if database is read/write
+ * @return true if database is read/write
+ */
+ bool IsReadWrite() OVERRIDE;
+
+ /**
+ * Call backup for opened DB
+ */
+ bool Backup() OVERRIDE;
+
+#ifndef QT_PORT
+ /**
+ * Gets connection to the SQLite database
+ * @return pointer to connection
+ */
+ sqlite3* conn() const OVERRIDE;
+#endif // QT_PORT
+
+ private:
+#ifndef QT_PORT
+ /**
+ * The connection to the SQLite database
+ */
+ sqlite3* conn_;
+#endif // QT_PORT
+
+ /**
+ * Lock for guarding connection to database
+ */
+ sync_primitives::Lock conn_lock_;
+
+ /**
+ * The filename of database
+ */
+ std::string database_name_;
+
+ int error_;
+
+ /**
+ * Execs query for internal using in this class
+ * @param query sql query without return results
+ * @return true if query was executed successfully
+ */
+ inline bool Exec(const std::string& query);
+
+ friend class SQLQuery;
+};
+
+} // namespace dbms
+} // namespace utils
+
+#endif // SRC_COMPONENTS_UTILS_INCLUDE_UTILS_SQLITE_WRAPPER_SQL_DATABASE_IMPL_H_