diff options
author | AGaliuzov <AGaliuzov@luxoft.com> | 2016-06-23 05:30:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-23 05:30:34 -0700 |
commit | 833cac1b1de464f53d5709904a4ee24634be2936 (patch) | |
tree | eceabb5046166e9b3d3a02fcd76496f88a177390 /src/components/utils/include/utils/sql_qt_wrapper/sql_database_impl.h | |
parent | 405c303a9ef5238c659374785c4bbdc1140ca564 (diff) | |
parent | 48692790e4819261878eed1525d391bdde149ff4 (diff) | |
download | sdl_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/sql_qt_wrapper/sql_database_impl.h')
-rw-r--r-- | src/components/utils/include/utils/sql_qt_wrapper/sql_database_impl.h | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/components/utils/include/utils/sql_qt_wrapper/sql_database_impl.h b/src/components/utils/include/utils/sql_qt_wrapper/sql_database_impl.h new file mode 100644 index 0000000000..92d8bc5425 --- /dev/null +++ b/src/components/utils/include/utils/sql_qt_wrapper/sql_database_impl.h @@ -0,0 +1,109 @@ +#ifndef SRC_COMPONENTS_UTILS_INCLUDE_UTILS_SQL_QT_WRAPPER_SQL_DATABASE_IMPL_H_ +#define SRC_COMPONENTS_UTILS_INCLUDE_UTILS_SQL_QT_WRAPPER_SQL_DATABASE_IMPL_H_ + +#include <string> + +#include <QtSql/QSqlDatabase> + +#include "utils/lock.h" +#include "utils/sql_qt_wrapper/sql_error.h" +#include "utils/sql_database.h" + +namespace utils { +namespace dbms { + +/** + * Represents a connection to a database. + */ +class SQLDatabaseImpl : public SQLDatabase { + public: + SQLDatabaseImpl(); + SQLDatabaseImpl(const std::string& database_path, + const std::string& connection_name); + ~SQLDatabaseImpl(); + + /** + * Opens connection to the temporary in-memory database + * @return true if successfully + */ + bool Open(); + + /** + * Closes connection to the database + */ + void Close(); + + /** + * Begins a transaction on the database + * @return true if successfully + */ + bool BeginTransaction(); + + /** + * Commits a transaction to the database + * @return true if successfully + */ + bool CommitTransaction(); + + /** + * Rolls back a transaction on the database + * @return true if successfully + */ + bool RollbackTransaction(); + + /** + * Gets information about the last error that occurred on the database + * @return last error + */ + SQLError LastError() const; + + /** + * @brief HasErrors Indicate the status of the last executed operation. + * + * @return true in case last operation has any errors, false otherwise. + */ + bool HasErrors() const; + + /** + * @brief get_path databse location path. + * + * @return the path to the database location + */ + std::string get_path() const; + + /** + * Checks if database is read/write + * @return true if database is read/write + */ + bool IsReadWrite(); + + /** + * Call backup for opened DB + */ + bool Backup(); + + operator QSqlDatabase() const; + + private: + QSqlDatabase db_; + + /** + * The filename of database + */ + const QString database_path_; + + /** + * The database connection name + */ + const QString connection_name_; + + /** + * Lock for guarding connection to database + */ + mutable sync_primitives::Lock conn_lock_; +}; + +} // namespace dbms +} // namespace utils + +#endif // SRC_COMPONENTS_UTILS_INCLUDE_UTILS_SQL_QT_WRAPPER_SQL_DATABASE_IMPL_H_ |