diff --git a/cmake/Modules/TinySources.cmake b/cmake/Modules/TinySources.cmake index 0bbb28d74..d632403ce 100644 --- a/cmake/Modules/TinySources.cmake +++ b/cmake/Modules/TinySources.cmake @@ -54,6 +54,7 @@ function(tinyorm_sources out_headers out_sources) exceptions/recordsnotfounderror.hpp exceptions/runtimeerror.hpp exceptions/sqlerror.hpp + exceptions/sqlitedatabasedoesnotexisterror.hpp exceptions/sqltransactionerror.hpp libraryinfo.hpp macros/archdetect.hpp diff --git a/include/include.pri b/include/include.pri index 4e309b3c9..3b5dd7f7d 100644 --- a/include/include.pri +++ b/include/include.pri @@ -46,6 +46,7 @@ headersList += \ $$PWD/orm/exceptions/recordsnotfounderror.hpp \ $$PWD/orm/exceptions/runtimeerror.hpp \ $$PWD/orm/exceptions/sqlerror.hpp \ + $$PWD/orm/exceptions/sqlitedatabasedoesnotexisterror.hpp \ $$PWD/orm/exceptions/sqltransactionerror.hpp \ $$PWD/orm/libraryinfo.hpp \ $$PWD/orm/macros/archdetect.hpp \ diff --git a/include/orm/exceptions/sqlitedatabasedoesnotexisterror.hpp b/include/orm/exceptions/sqlitedatabasedoesnotexisterror.hpp new file mode 100644 index 000000000..be6536ce8 --- /dev/null +++ b/include/orm/exceptions/sqlitedatabasedoesnotexisterror.hpp @@ -0,0 +1,49 @@ +#pragma once +#ifndef ORM_EXCEPTIONS_SQLITEDATABASEDOESNOTEXISTERROR_HPP +#define ORM_EXCEPTIONS_SQLITEDATABASEDOESNOTEXISTERROR_HPP + +#include "orm/macros/systemheader.hpp" +TINY_SYSTEM_HEADER + +#include "orm/exceptions/invalidargumenterror.hpp" + +TINYORM_BEGIN_COMMON_NAMESPACE + +namespace Orm::Exceptions +{ + + /*! TinyORM SQLite database doesn't exist exception. */ + class SQLiteDatabaseDoesNotExistError : public InvalidArgumentError // clazy:exclude=copyable-polymorphic + { + public: + /*! Path constructor (QString). */ + inline explicit SQLiteDatabaseDoesNotExistError(const QString &path); + + /*! Get the path to the database. */ + inline const QString &getPath() const noexcept; + + protected: + /*! The path to the database. */ + QString m_path; + }; + + /* public */ + + SQLiteDatabaseDoesNotExistError::SQLiteDatabaseDoesNotExistError(const QString &path) + : InvalidArgumentError(QStringLiteral( + "SQLite Database file '%1' does not exist, please " + " insert an absolute path to the database.") + .arg(path).toUtf8().constData()) + , m_path(path) + {} + + const QString &SQLiteDatabaseDoesNotExistError::getPath() const noexcept + { + return m_path; + } + +} // namespace Orm::Exceptions + +TINYORM_END_COMMON_NAMESPACE + +#endif // ORM_EXCEPTIONS_SQLITEDATABASEDOESNOTEXISTERROR_HPP diff --git a/src/orm/connectors/sqliteconnector.cpp b/src/orm/connectors/sqliteconnector.cpp index 3b6560a34..c44f50590 100644 --- a/src/orm/connectors/sqliteconnector.cpp +++ b/src/orm/connectors/sqliteconnector.cpp @@ -5,6 +5,7 @@ #include "orm/constants.hpp" #include "orm/exceptions/queryerror.hpp" +#include "orm/exceptions/sqlitedatabasedoesnotexisterror.hpp" #include "orm/utils/type.hpp" TINYORM_BEGIN_COMMON_NAMESPACE @@ -95,8 +96,7 @@ void SQLiteConnector::checkDatabaseExists(const QVariantHash &config) checkDatabaseExists = config[check_database_exists].value(); if (checkDatabaseExists && !QFile::exists(path)) - throw Exceptions::RuntimeError( - QStringLiteral("SQLite Database file '%1' does not exist.").arg(path)); + throw Exceptions::SQLiteDatabaseDoesNotExistError(path); } } // namespace Orm::Connectors