diff --git a/include/include.pri b/include/include.pri index 586aff59a..5abfcdd81 100644 --- a/include/include.pri +++ b/include/include.pri @@ -18,11 +18,15 @@ HEADERS += \ $$PWD/orm/databaseconnection.hpp \ $$PWD/orm/databasemanager.hpp \ $$PWD/orm/db.hpp \ - $$PWD/orm/domainerror.hpp \ - $$PWD/orm/invalidargumenterror.hpp \ - $$PWD/orm/invalidformaterror.hpp \ - $$PWD/orm/invalidtemplateargumenterror.hpp \ - $$PWD/orm/logicerror.hpp \ + $$PWD/orm/exceptions/domainerror.hpp \ + $$PWD/orm/exceptions/invalidargumenterror.hpp \ + $$PWD/orm/exceptions/invalidformaterror.hpp \ + $$PWD/orm/exceptions/invalidtemplateargumenterror.hpp \ + $$PWD/orm/exceptions/logicerror.hpp \ + $$PWD/orm/exceptions/queryerror.hpp \ + $$PWD/orm/exceptions/runtimeerror.hpp \ + $$PWD/orm/exceptions/sqlerror.hpp \ + $$PWD/orm/exceptions/sqltransactionerror.hpp \ $$PWD/orm/logquery.hpp \ $$PWD/orm/macros.hpp \ $$PWD/orm/mysqlconnection.hpp \ @@ -39,8 +43,6 @@ HEADERS += \ $$PWD/orm/query/processors/processor.hpp \ $$PWD/orm/query/processors/sqliteprocessor.hpp \ $$PWD/orm/query/querybuilder.hpp \ - $$PWD/orm/queryerror.hpp \ - $$PWD/orm/runtimeerror.hpp \ $$PWD/orm/schema/grammars/mysqlschemagrammar.hpp \ $$PWD/orm/schema/grammars/postgresschemagrammar.hpp \ $$PWD/orm/schema/grammars/schemagrammar.hpp \ @@ -49,20 +51,18 @@ HEADERS += \ $$PWD/orm/schema/postgresschemabuilder.hpp \ $$PWD/orm/schema/schemabuilder.hpp \ $$PWD/orm/schema/sqliteschemabuilder.hpp \ - $$PWD/orm/sqlerror.hpp \ $$PWD/orm/sqliteconnection.hpp \ - $$PWD/orm/sqltransactionerror.hpp \ $$PWD/orm/support/configurationoptionsparser.hpp \ $$PWD/orm/tiny/concerns/guardsattributes.hpp \ $$PWD/orm/tiny/concerns/hasattributes.hpp \ $$PWD/orm/tiny/concerns/hasrelationstore.hpp \ $$PWD/orm/tiny/concerns/queriesrelationships.hpp \ - $$PWD/orm/tiny/massassignmenterror.hpp \ + $$PWD/orm/tiny/exceptions/massassignmenterror.hpp \ + $$PWD/orm/tiny/exceptions/modelnotfounderror.hpp \ + $$PWD/orm/tiny/exceptions/relationnotfounderror.hpp \ + $$PWD/orm/tiny/exceptions/relationnotloadederror.hpp \ $$PWD/orm/tiny/model.hpp \ - $$PWD/orm/tiny/modelnotfounderror.hpp \ $$PWD/orm/tiny/modelproxies.hpp \ - $$PWD/orm/tiny/relationnotfounderror.hpp \ - $$PWD/orm/tiny/relationnotloadederror.hpp \ $$PWD/orm/tiny/relations/basepivot.hpp \ $$PWD/orm/tiny/relations/belongsto.hpp \ $$PWD/orm/tiny/relations/belongstomany.hpp \ diff --git a/include/orm/concerns/detectslostconnections.hpp b/include/orm/concerns/detectslostconnections.hpp index 3d639b21f..8d8fc94ca 100644 --- a/include/orm/concerns/detectslostconnections.hpp +++ b/include/orm/concerns/detectslostconnections.hpp @@ -7,8 +7,12 @@ namespace TINYORM_COMMON_NAMESPACE { #endif namespace Orm +{ + +namespace Exceptions { class SqlError; +} namespace Concerns { @@ -22,7 +26,7 @@ namespace Concerns DetectsLostConnections() = default; /*! Determine if the given exception was caused by a lost connection. */ - bool causedByLostConnection(const SqlError &e) const; + bool causedByLostConnection(const Exceptions::SqlError &e) const; }; } // namespace Orm::Concerns diff --git a/include/orm/connectors/connector.hpp b/include/orm/connectors/connector.hpp index 849b16b26..7c3cf8378 100644 --- a/include/orm/connectors/connector.hpp +++ b/include/orm/connectors/connector.hpp @@ -47,8 +47,9 @@ namespace Orm::Connectors /*! Handle an exception that occurred during connect execution. */ QSqlDatabase tryAgainIfCausedByLostConnection( - const std::exception_ptr &ePtr, const SqlError &e, const QString &name, - const QVariantHash &config, const QString &options) const; + const std::exception_ptr &ePtr, const Exceptions::SqlError &e, + const QString &name, const QVariantHash &config, + const QString &options) const; /*! Error message used when connection configuration fails. */ static const QString m_configureErrorMessage; diff --git a/include/orm/databaseconnection.hpp b/include/orm/databaseconnection.hpp index 13322dd6f..8df73c924 100644 --- a/include/orm/databaseconnection.hpp +++ b/include/orm/databaseconnection.hpp @@ -11,9 +11,9 @@ #include "orm/concerns/detectslostconnections.hpp" #include "orm/connectioninterface.hpp" #include "orm/connectors/connectorinterface.hpp" +#include "orm/exceptions/queryerror.hpp" #include "orm/query/grammars/grammar.hpp" #include "orm/query/processors/processor.hpp" -#include "orm/queryerror.hpp" #include "orm/schema/schemabuilder.hpp" #include "orm/schema/grammars/schemagrammar.hpp" @@ -348,13 +348,13 @@ namespace Orm /*! Handle a query exception. */ template Return handleQueryException( - const std::exception_ptr &ePtr, const QueryError &e, + const std::exception_ptr &ePtr, const Exceptions::QueryError &e, const QString &queryString, const QVector &bindings, const RunCallback &callback) const; /*! Handle a query exception that occurred during query execution. */ template Return tryAgainIfCausedByLostConnection( - const std::exception_ptr &ePtr, const QueryError &e, + const std::exception_ptr &ePtr, const Exceptions::QueryError &e, const QString &queryString, const QVector &bindings, const RunCallback &callback) const; @@ -487,7 +487,7 @@ namespace Orm try { result = runQueryCallback(queryString, bindings, callback); - } catch (const QueryError &e) { + } catch (const Exceptions::QueryError &e) { result = handleQueryException(std::current_exception(), e, queryString, bindings, callback); } @@ -527,7 +527,7 @@ namespace Orm template Return DatabaseConnection::handleQueryException( - const std::exception_ptr &ePtr, const QueryError &e, + const std::exception_ptr &ePtr, const Exceptions::QueryError &e, const QString &queryString, const QVector &bindings, const RunCallback &callback) const { @@ -542,7 +542,7 @@ namespace Orm template Return DatabaseConnection::tryAgainIfCausedByLostConnection( - const std::exception_ptr &ePtr, const QueryError &e, + const std::exception_ptr &ePtr, const Exceptions::QueryError &e, const QString &queryString, const QVector &bindings, const RunCallback &callback) const { diff --git a/include/orm/domainerror.hpp b/include/orm/exceptions/domainerror.hpp similarity index 86% rename from include/orm/domainerror.hpp rename to include/orm/exceptions/domainerror.hpp index c9e6cf31f..bd2793fae 100644 --- a/include/orm/domainerror.hpp +++ b/include/orm/exceptions/domainerror.hpp @@ -4,14 +4,14 @@ #include -#include "orm/logicerror.hpp" +#include "orm/exceptions/logicerror.hpp" #include "orm/utils/export.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { class SHAREDLIB_EXPORT DomainError : public LogicError diff --git a/include/orm/invalidargumenterror.hpp b/include/orm/exceptions/invalidargumenterror.hpp similarity index 89% rename from include/orm/invalidargumenterror.hpp rename to include/orm/exceptions/invalidargumenterror.hpp index c5ad7eb17..5873824c2 100644 --- a/include/orm/invalidargumenterror.hpp +++ b/include/orm/exceptions/invalidargumenterror.hpp @@ -4,14 +4,14 @@ #include -#include "orm/logicerror.hpp" +#include "orm/exceptions/logicerror.hpp" #include "orm/utils/export.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { // CUR move all exception classes to exceptions folder and own exception NS? silverqx diff --git a/include/orm/invalidformaterror.hpp b/include/orm/exceptions/invalidformaterror.hpp similarity index 86% rename from include/orm/invalidformaterror.hpp rename to include/orm/exceptions/invalidformaterror.hpp index 608de5624..043803a0a 100644 --- a/include/orm/invalidformaterror.hpp +++ b/include/orm/exceptions/invalidformaterror.hpp @@ -2,13 +2,13 @@ #ifndef INVALIDFORMATERROR_H #define INVALIDFORMATERROR_H -#include "orm/logicerror.hpp" +#include "orm/exceptions/logicerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { class SHAREDLIB_EXPORT InvalidFormatError : public LogicError diff --git a/include/orm/invalidtemplateargumenterror.hpp b/include/orm/exceptions/invalidtemplateargumenterror.hpp similarity index 86% rename from include/orm/invalidtemplateargumenterror.hpp rename to include/orm/exceptions/invalidtemplateargumenterror.hpp index 3be2c5e1d..ead56ef5c 100644 --- a/include/orm/invalidtemplateargumenterror.hpp +++ b/include/orm/exceptions/invalidtemplateargumenterror.hpp @@ -2,13 +2,13 @@ #ifndef INVALIDTEMPLATEARGUMENTERROR_HPP #define INVALIDTEMPLATEARGUMENTERROR_HPP -#include "orm/invalidargumenterror.hpp" +#include "orm/exceptions/invalidargumenterror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { class SHAREDLIB_EXPORT InvalidTemplateArgumentError : public InvalidArgumentError diff --git a/include/orm/logicerror.hpp b/include/orm/exceptions/logicerror.hpp similarity index 97% rename from include/orm/logicerror.hpp rename to include/orm/exceptions/logicerror.hpp index 50643318e..a0410057e 100644 --- a/include/orm/logicerror.hpp +++ b/include/orm/exceptions/logicerror.hpp @@ -10,7 +10,7 @@ namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { class SHAREDLIB_EXPORT LogicError : public std::logic_error diff --git a/include/orm/queryerror.hpp b/include/orm/exceptions/queryerror.hpp similarity index 94% rename from include/orm/queryerror.hpp rename to include/orm/exceptions/queryerror.hpp index aebbe3154..9612ac0ce 100644 --- a/include/orm/queryerror.hpp +++ b/include/orm/exceptions/queryerror.hpp @@ -4,7 +4,7 @@ #include -#include "orm/sqlerror.hpp" +#include "orm/exceptions/sqlerror.hpp" class QSqlQuery; @@ -12,7 +12,7 @@ class QSqlQuery; namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { class SHAREDLIB_EXPORT QueryError : public SqlError diff --git a/include/orm/runtimeerror.hpp b/include/orm/exceptions/runtimeerror.hpp similarity index 97% rename from include/orm/runtimeerror.hpp rename to include/orm/exceptions/runtimeerror.hpp index 440e5ed12..d6254279d 100644 --- a/include/orm/runtimeerror.hpp +++ b/include/orm/exceptions/runtimeerror.hpp @@ -12,7 +12,7 @@ namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { class SHAREDLIB_EXPORT RuntimeError : public std::runtime_error diff --git a/include/orm/sqlerror.hpp b/include/orm/exceptions/sqlerror.hpp similarity index 93% rename from include/orm/sqlerror.hpp rename to include/orm/exceptions/sqlerror.hpp index f12c8542c..b6f043cac 100644 --- a/include/orm/sqlerror.hpp +++ b/include/orm/exceptions/sqlerror.hpp @@ -4,13 +4,13 @@ #include -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { class SHAREDLIB_EXPORT SqlError : public RuntimeError diff --git a/include/orm/sqltransactionerror.hpp b/include/orm/exceptions/sqltransactionerror.hpp similarity index 86% rename from include/orm/sqltransactionerror.hpp rename to include/orm/exceptions/sqltransactionerror.hpp index b7103a7d5..a6c2dc0ec 100644 --- a/include/orm/sqltransactionerror.hpp +++ b/include/orm/exceptions/sqltransactionerror.hpp @@ -2,13 +2,13 @@ #ifndef SQLTRANSACTIONERROR_H #define SQLTRANSACTIONERROR_H -#include "orm/sqlerror.hpp" +#include "orm/exceptions/sqlerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { class SHAREDLIB_EXPORT SqlTransactionError : public SqlError diff --git a/include/orm/tiny/concerns/hasrelationstore.hpp b/include/orm/tiny/concerns/hasrelationstore.hpp index 8a4149c18..ffb473651 100644 --- a/include/orm/tiny/concerns/hasrelationstore.hpp +++ b/include/orm/tiny/concerns/hasrelationstore.hpp @@ -5,7 +5,7 @@ #include #include -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" #include "orm/tiny/relations/relation.hpp" #include "orm/tiny/tinytypes.hpp" @@ -373,7 +373,7 @@ namespace Concerns break; default: - throw RuntimeError("Unknown store type."); + throw Orm::Exceptions::RuntimeError("Unknown store type."); } } diff --git a/include/orm/tiny/concerns/queriesrelationships.hpp b/include/orm/tiny/concerns/queriesrelationships.hpp index 1b9ae1178..aa61c0df0 100644 --- a/include/orm/tiny/concerns/queriesrelationships.hpp +++ b/include/orm/tiny/concerns/queriesrelationships.hpp @@ -4,7 +4,7 @@ #include -#include "orm/invalidtemplateargumenterror.hpp" +#include "orm/exceptions/invalidtemplateargumenterror.hpp" #include "orm/query/querybuilder.hpp" #include "orm/tiny/relations/relation.hpp" #include "orm/tiny/tinytypes.hpp" @@ -280,7 +280,7 @@ namespace Private { if (relation.contains(DOT)) { if constexpr (std::is_void_v) - throw InvalidArgumentError( + throw Orm::Exceptions::InvalidArgumentError( "This has() overload doesn't support nested 'has' statements, " "please use has() overload with 'std::function &)> &callback', what means pass " @@ -595,7 +595,7 @@ namespace Private if (relations.size() >= 1) hasQuery->hasInternal(relations.takeFirst(), GE, 1, AND, relations); else - throw RuntimeError( + throw Orm::Exceptions::RuntimeError( QStringLiteral( "wtf, this should never happen :/, 'relations.size() == %1'.") .arg(relations.size())); @@ -684,7 +684,7 @@ namespace Private if (typeid (Related) == Private::HasNestedStore::STORE_TYPEID.top()) return; - throw InvalidTemplateArgumentError( + throw Orm::Exceptions::InvalidTemplateArgumentError( QStringLiteral( "Bad template argument passed to the has() related method with " "nested relations. Actual ' = %1', expected ' " diff --git a/include/orm/tiny/massassignmenterror.hpp b/include/orm/tiny/exceptions/massassignmenterror.hpp similarity index 59% rename from include/orm/tiny/massassignmenterror.hpp rename to include/orm/tiny/exceptions/massassignmenterror.hpp index 05b8a2b0d..c79153be4 100644 --- a/include/orm/tiny/massassignmenterror.hpp +++ b/include/orm/tiny/exceptions/massassignmenterror.hpp @@ -2,19 +2,19 @@ #ifndef MASSASSIGNMENTERROR_H #define MASSASSIGNMENTERROR_H -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm::Tiny +namespace Orm::Tiny::Exceptions { - class SHAREDLIB_EXPORT MassAssignmentError : public RuntimeError + class SHAREDLIB_EXPORT MassAssignmentError : public Orm::Exceptions::RuntimeError { public: - using RuntimeError::RuntimeError; + using Orm::Exceptions::RuntimeError::RuntimeError; }; } // namespace Orm::Tiny diff --git a/include/orm/tiny/modelnotfounderror.hpp b/include/orm/tiny/exceptions/modelnotfounderror.hpp similarity index 89% rename from include/orm/tiny/modelnotfounderror.hpp rename to include/orm/tiny/exceptions/modelnotfounderror.hpp index 4048ed654..1addc1bd1 100644 --- a/include/orm/tiny/modelnotfounderror.hpp +++ b/include/orm/tiny/exceptions/modelnotfounderror.hpp @@ -4,16 +4,16 @@ #include -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm::Tiny +namespace Orm::Tiny::Exceptions { - class SHAREDLIB_EXPORT ModelNotFoundError : public RuntimeError + class SHAREDLIB_EXPORT ModelNotFoundError : public Orm::Exceptions::RuntimeError { public: // FEATURE dilemma primarykey, Model::KeyType vs QVariant silverqx diff --git a/include/orm/tiny/relationnotfounderror.hpp b/include/orm/tiny/exceptions/relationnotfounderror.hpp similarity index 90% rename from include/orm/tiny/relationnotfounderror.hpp rename to include/orm/tiny/exceptions/relationnotfounderror.hpp index aba86fe70..cb3df2b53 100644 --- a/include/orm/tiny/relationnotfounderror.hpp +++ b/include/orm/tiny/exceptions/relationnotfounderror.hpp @@ -2,18 +2,18 @@ #ifndef RELATIONNOTFOUNDERROR_H #define RELATIONNOTFOUNDERROR_H -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm::Tiny +namespace Orm::Tiny::Exceptions { /*! Check whether the relation was defined in the u_relation data member, called from Model::validateUserRelation(). */ - class SHAREDLIB_EXPORT RelationNotFoundError : public RuntimeError + class SHAREDLIB_EXPORT RelationNotFoundError : public Orm::Exceptions::RuntimeError { public: /*! Exception message will be generated on the base of this enum struct. */ diff --git a/include/orm/tiny/relationnotloadederror.hpp b/include/orm/tiny/exceptions/relationnotloadederror.hpp similarity index 86% rename from include/orm/tiny/relationnotloadederror.hpp rename to include/orm/tiny/exceptions/relationnotloadederror.hpp index f00f0340a..af79e2f97 100644 --- a/include/orm/tiny/relationnotloadederror.hpp +++ b/include/orm/tiny/exceptions/relationnotloadederror.hpp @@ -2,17 +2,17 @@ #ifndef RELATIONNOTLOADEDERROR_H #define RELATIONNOTLOADEDERROR_H -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm::Tiny +namespace Orm::Tiny::Exceptions { /*! Called from Model::getRelation(), when the relation was not loaded. */ - class SHAREDLIB_EXPORT RelationNotLoadedError : public RuntimeError + class SHAREDLIB_EXPORT RelationNotLoadedError : public Orm::Exceptions::RuntimeError { public: RelationNotLoadedError(const QString &model, const QString &relation); diff --git a/include/orm/tiny/model.hpp b/include/orm/tiny/model.hpp index ba43d179d..36a6c7102 100644 --- a/include/orm/tiny/model.hpp +++ b/include/orm/tiny/model.hpp @@ -9,13 +9,13 @@ #include "orm/concerns/hasconnectionresolver.hpp" #include "orm/connectionresolverinterface.hpp" -#include "orm/invalidformaterror.hpp" +#include "orm/exceptions/invalidformaterror.hpp" #include "orm/tiny/concerns/guardsattributes.hpp" #include "orm/tiny/concerns/hasrelationstore.hpp" -#include "orm/tiny/massassignmenterror.hpp" +#include "orm/tiny/exceptions/massassignmenterror.hpp" +#include "orm/tiny/exceptions/relationnotfounderror.hpp" +#include "orm/tiny/exceptions/relationnotloadederror.hpp" #include "orm/tiny/modelproxies.hpp" -#include "orm/tiny/relationnotfounderror.hpp" -#include "orm/tiny/relationnotloadederror.hpp" #include "orm/tiny/relations/belongsto.hpp" #include "orm/tiny/relations/belongstomany.hpp" #include "orm/tiny/relations/hasone.hpp" @@ -734,7 +734,7 @@ namespace Relations { private: /*! Alias for the enum struct RelationNotFoundError::From. */ - using RelationFrom = RelationNotFoundError::From; + using RelationFrom = Exceptions::RelationNotFoundError::From; /* Eager load from TinyBuilder */ /*! Invoke Model::eagerVisitor() to define template argument Related @@ -1049,7 +1049,8 @@ namespace Relations { else if (std::holds_alternative>(models)) pushVisited(); else - throw RuntimeError("this->pushStore().models holds unexpected alternative."); + throw Orm::Exceptions::RuntimeError( + "this->pushStore().models holds unexpected alternative."); } template @@ -1126,8 +1127,8 @@ namespace Relations { ) relatedModel->touchOwners(); } else - throw RuntimeError("Bad relation type passed to the " - "Model::touchOwnersVisited()."); + throw Orm::Exceptions::RuntimeError( + "Bad relation type passed to the Model::touchOwnersVisited()."); } template @@ -1169,7 +1170,7 @@ namespace Relations { // mergeAttributesFromClassCasts(); if (getKeyName().isEmpty()) - throw RuntimeError("No primary key defined on model."); + throw Orm::Exceptions::RuntimeError("No primary key defined on model."); /* If the model doesn't exist, there is nothing to delete so we'll just return immediately and not do anything else. Otherwise, we will continue with a @@ -1377,7 +1378,7 @@ namespace Relations { setAttribute(key, std::move(attribute.value)); else if (totallyGuarded) - throw MassAssignmentError( + throw Exceptions::MassAssignmentError( QStringLiteral("Add '%1' to u_fillable data member to allow " "mass assignment on '%2'.") .arg(key, Utils::Type::classPureBasename())); @@ -1401,7 +1402,7 @@ namespace Relations { setAttribute(key, std::move(attribute.value)); else if (totallyGuarded) - throw MassAssignmentError( + throw Exceptions::MassAssignmentError( QStringLiteral("Add '%1' to u_fillable data member to allow " "mass assignment on '%2'.") .arg(key, Utils::Type::classPureBasename())); @@ -1835,7 +1836,7 @@ namespace Relations { ) return date; - throw InvalidFormatError( + throw Orm::Exceptions::InvalidFormatError( QStringLiteral("Could not parse the datetime '%1' using " "the given format '%2'.") .arg(value.value(), format)); @@ -1918,7 +1919,7 @@ namespace Relations { Model::getRelation(const QString &relation) { if (!relationLoaded(relation)) - throw RelationNotLoadedError( + throw Exceptions::RelationNotLoadedError( Orm::Utils::Type::classPureBasename(), relation); return getRelationFromHash(relation); @@ -1931,7 +1932,7 @@ namespace Relations { Model::getRelation(const QString &relation) { if (!relationLoaded(relation)) - throw RelationNotLoadedError( + throw Exceptions::RelationNotLoadedError( Orm::Utils::Type::classPureBasename(), relation); return getRelationFromHash(relation); @@ -2734,7 +2735,7 @@ namespace Relations { value.userType() == QMetaType::QDateTime #endif ) - throw InvalidArgumentError( + throw Orm::Exceptions::InvalidArgumentError( message.arg(Utils::Type::classPureBasename())); } @@ -2761,7 +2762,7 @@ namespace Relations { const QString &name, const RelationFrom from) const { if (!model().u_relations.contains(name)) - throw RelationNotFoundError( + throw Exceptions::RelationNotFoundError( Orm::Utils::Type::classPureBasename(), name, from); } @@ -2773,7 +2774,7 @@ namespace Relations { { if constexpr (std::is_same_v>) { if (!std::holds_alternative(relationVariant)) - throw RuntimeError( + throw Orm::Exceptions::RuntimeError( QStringLiteral( "The relation '%1' is many type relation, use " "%2<%3>() method overload without an 'Orm::One' tag.") @@ -2781,7 +2782,7 @@ namespace Relations { Utils::Type::classPureBasename())); } else if constexpr (std::is_same_v>) { if (!std::holds_alternative(relationVariant)) - throw RuntimeError( + throw Orm::Exceptions::RuntimeError( QStringLiteral( "The relation '%1' is one type relation, use " "%2<%3, Orm::One>() method overload " @@ -2789,7 +2790,8 @@ namespace Relations { .arg(relation, source, Utils::Type::classPureBasename())); } else - throw InvalidArgumentError("Unexpected 'Result' template argument."); + throw Orm::Exceptions::InvalidArgumentError( + "Unexpected 'Result' template argument."); } template diff --git a/include/orm/tiny/relations/belongstomany.hpp b/include/orm/tiny/relations/belongstomany.hpp index 691e5609c..f69d05b99 100644 --- a/include/orm/tiny/relations/belongstomany.hpp +++ b/include/orm/tiny/relations/belongstomany.hpp @@ -10,9 +10,9 @@ #include #include -#include "orm/domainerror.hpp" +#include "orm/exceptions/domainerror.hpp" #include "orm/macros.hpp" -#include "orm/tiny/modelnotfounderror.hpp" +#include "orm/tiny/exceptions/modelnotfounderror.hpp" #include "orm/tiny/relations/relation.hpp" #include "orm/utils/attribute.hpp" #include "orm/utils/type.hpp" @@ -843,7 +843,8 @@ namespace Orm::Tiny::Relations if (model) return *model; - throw ModelNotFoundError(Utils::Type::classPureBasename(), {id}); + throw Exceptions::ModelNotFoundError( + Utils::Type::classPureBasename(), {id}); } template @@ -909,7 +910,8 @@ namespace Orm::Tiny::Relations if (auto model = first(columns); model) return *model; - throw ModelNotFoundError(Utils::Type::classPureBasename()); + throw Exceptions::ModelNotFoundError( + Utils::Type::classPureBasename()); } template @@ -1869,10 +1871,10 @@ namespace Orm::Tiny::Relations QStringLiteral("You can not overwrite '%1' ID key; " "original value : %2, your value : %3."); - throw DomainError(overwriteMessage.arg( - qualifyPivotColumn(key), - QString::number(original.value()), - QString::number(overwrite.value()))); + throw Orm::Exceptions::DomainError( + overwriteMessage.arg(qualifyPivotColumn(key), + QString::number(original.value()), + QString::number(overwrite.value()))); } } // namespace Orm::Tiny::Relations diff --git a/include/orm/tiny/relations/relation.hpp b/include/orm/tiny/relations/relation.hpp index 20a627df9..eead61908 100644 --- a/include/orm/tiny/relations/relation.hpp +++ b/include/orm/tiny/relations/relation.hpp @@ -9,6 +9,7 @@ #include #include +#include "orm/exceptions/runtimeerror.hpp" #include "orm/tiny/relations/relationproxies.hpp" #ifdef TINYORM_COMMON_NAMESPACE @@ -210,9 +211,10 @@ namespace Relations template inline QString Relation::getExistenceCompareKey() const { - throw RuntimeError(QStringLiteral("Method %1() is not implemented for '%2' " - "relation type.") - .arg(__func__, relationTypeName())); + throw Orm::Exceptions::RuntimeError( + QStringLiteral("Method %1() is not implemented for '%2' " + "relation type.") + .arg(__func__, relationTypeName())); } template diff --git a/include/orm/tiny/tinybuilder.hpp b/include/orm/tiny/tinybuilder.hpp index 5c2c993fa..d6e2c50ec 100644 --- a/include/orm/tiny/tinybuilder.hpp +++ b/include/orm/tiny/tinybuilder.hpp @@ -10,7 +10,7 @@ #include "orm/databaseconnection.hpp" #include "orm/tiny/concerns/queriesrelationships.hpp" -#include "orm/tiny/modelnotfounderror.hpp" +#include "orm/tiny/exceptions/modelnotfounderror.hpp" #include "orm/tiny/tinybuilderproxies.hpp" #ifdef TINYORM_COMMON_NAMESPACE @@ -313,7 +313,8 @@ namespace Orm::Tiny if (model) return *model; - throw ModelNotFoundError(Utils::Type::classPureBasename(), {id}); + throw Exceptions::ModelNotFoundError( + Utils::Type::classPureBasename(), {id}); } template @@ -383,7 +384,8 @@ namespace Orm::Tiny if (model) return *model; - throw ModelNotFoundError(Utils::Type::classPureBasename()); + throw Exceptions::ModelNotFoundError( + Utils::Type::classPureBasename()); } template @@ -704,7 +706,7 @@ namespace Orm::Tiny const auto isSelectConstraint = relation.name.contains(COLON); if (isSelectConstraint && relation.constraints) - throw RuntimeError( + throw Orm::Exceptions::RuntimeError( "Passing both 'Select constraint' and 'Lambda expression " "constraint' to the Model::with() method is not allowed, use " "only one of them."); diff --git a/src/orm/basegrammar.cpp b/src/orm/basegrammar.cpp index 2d9b349d8..3ca190d5c 100644 --- a/src/orm/basegrammar.cpp +++ b/src/orm/basegrammar.cpp @@ -1,6 +1,6 @@ #include "orm/basegrammar.hpp" -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE @@ -62,7 +62,7 @@ QString BaseGrammar::wrapTable(const QString &table) const QString BaseGrammar::wrapTable(const FromClause &table) const { if (std::holds_alternative(table)) - throw RuntimeError("std::monostate in wrapTable()."); + throw Exceptions::RuntimeError("std::monostate in wrapTable()."); else if (std::holds_alternative(table)) return getValue(std::get(table)).value(); diff --git a/src/orm/concerns/detectslostconnections.cpp b/src/orm/concerns/detectslostconnections.cpp index d35417858..291968930 100644 --- a/src/orm/concerns/detectslostconnections.cpp +++ b/src/orm/concerns/detectslostconnections.cpp @@ -2,7 +2,7 @@ #include -#include "orm/sqlerror.hpp" +#include "orm/exceptions/sqlerror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE @@ -11,7 +11,7 @@ namespace TINYORM_COMMON_NAMESPACE namespace Orm::Concerns { -bool DetectsLostConnections::causedByLostConnection(const SqlError &e) const +bool DetectsLostConnections::causedByLostConnection(const Exceptions::SqlError &e) const { // TODO verify this will be pain in the ass 😕 silverqx static const QVector lostMessagesCache { diff --git a/src/orm/connectors/connector.cpp b/src/orm/connectors/connector.cpp index c23e897fb..234b6c380 100644 --- a/src/orm/connectors/connector.cpp +++ b/src/orm/connectors/connector.cpp @@ -1,6 +1,6 @@ #include "orm/connectors/connector.hpp" -#include "orm/sqlerror.hpp" +#include "orm/exceptions/sqlerror.hpp" #include "orm/support/configurationoptionsparser.hpp" #include "orm/utils/type.hpp" @@ -22,7 +22,7 @@ Connector::createConnection(const QString &name, const QVariantHash &config, try { return createQSqlDatabaseConnection(name, config, options); - } catch (const SqlError &e) { + } catch (const Exceptions::SqlError &e) { return tryAgainIfCausedByLostConnection(std::current_exception(), e, name, config, options); } @@ -40,9 +40,10 @@ Connector::createQSqlDatabaseConnection(const QString &name, const QVariantHash : addQSqlDatabaseConnection(name, config, options); if (!db.open()) - throw SqlError(QStringLiteral("Open databse connection in %1() failed.") - .arg(__tiny_func__), - db.lastError()); + throw Exceptions::SqlError( + QStringLiteral("Open databse connection in %1() failed.") + .arg(__tiny_func__), + db.lastError()); return db; } @@ -88,8 +89,8 @@ Connector::addQSqlDatabaseConnection(const QString &name, const QVariantHash &co QSqlDatabase Connector::tryAgainIfCausedByLostConnection( - const std::exception_ptr &ePtr, const SqlError &e, const QString &name, - const QVariantHash &config, const QString &options) const + const std::exception_ptr &ePtr, const Exceptions::SqlError &e, + const QString &name, const QVariantHash &config, const QString &options) const { if (causedByLostConnection(e)) return createQSqlDatabaseConnection(name, config, options); diff --git a/src/orm/connectors/mysqlconnector.cpp b/src/orm/connectors/mysqlconnector.cpp index 8386e45ab..c6558aa31 100644 --- a/src/orm/connectors/mysqlconnector.cpp +++ b/src/orm/connectors/mysqlconnector.cpp @@ -4,7 +4,7 @@ #include #include "orm/constants.hpp" -#include "orm/queryerror.hpp" +#include "orm/exceptions/queryerror.hpp" #include "orm/utils/type.hpp" using namespace Orm::Constants; @@ -90,7 +90,7 @@ void MySqlConnector::configureIsolationLevel(const QSqlDatabase &connection, .arg(config["isolation_level"].value()))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } void MySqlConnector::configureEncoding(const QSqlDatabase &connection, @@ -105,7 +105,7 @@ void MySqlConnector::configureEncoding(const QSqlDatabase &connection, .arg(config["charset"].value(), getCollation(config)))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } QString MySqlConnector::getCollation(const QVariantHash &config) const @@ -127,7 +127,7 @@ void MySqlConnector::configureTimezone(const QSqlDatabase &connection, .arg(config["timezone"].value()))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } void MySqlConnector::setModes(const QSqlDatabase &connection, @@ -144,7 +144,8 @@ void MySqlConnector::setModes(const QSqlDatabase &connection, if (query.exec(strictMode(connection, config))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), + query); } else { QSqlQuery query(connection); @@ -152,7 +153,8 @@ void MySqlConnector::setModes(const QSqlDatabase &connection, QStringLiteral("set session sql_mode='NO_ENGINE_SUBSTITUTION'"))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), + query); } } } @@ -188,10 +190,11 @@ QString MySqlConnector::getMySqlVersion(const QSqlDatabase &connection, QSqlQuery query(connection); if (!query.exec(QStringLiteral("select version()"))) - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), + query); if (!query.first()) - throw RuntimeError( + throw Exceptions::RuntimeError( QStringLiteral("Error during connection configuration, can not " "obtain the first record in %1().") .arg(__tiny_func__)); @@ -212,7 +215,7 @@ void MySqlConnector::setCustomModes(const QSqlDatabase &connection, if (query.exec(QStringLiteral("set session sql_mode='%1';").arg(modes))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } } // namespace Orm::Connectors diff --git a/src/orm/connectors/postgresconnector.cpp b/src/orm/connectors/postgresconnector.cpp index e522dd05c..c96cac52d 100644 --- a/src/orm/connectors/postgresconnector.cpp +++ b/src/orm/connectors/postgresconnector.cpp @@ -4,7 +4,7 @@ #include #include "orm/constants.hpp" -#include "orm/queryerror.hpp" +#include "orm/exceptions/queryerror.hpp" #include "orm/utils/type.hpp" using namespace Orm::Constants; @@ -73,7 +73,7 @@ void PostgresConnector::configureEncoding(const QSqlDatabase &connection, .arg(config["charset"].value()))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } void PostgresConnector::configureTimezone(const QSqlDatabase &connection, @@ -95,7 +95,7 @@ void PostgresConnector::configureTimezone(const QSqlDatabase &connection, if (query.exec(QStringLiteral("set time zone '%1'").arg(timezone))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } void PostgresConnector::configureSchema(const QSqlDatabase &connection, @@ -111,7 +111,7 @@ void PostgresConnector::configureSchema(const QSqlDatabase &connection, if (query.exec(QStringLiteral("set search_path to %1").arg(schema))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } QString PostgresConnector::formatSchema(QStringList schema) const @@ -138,7 +138,7 @@ void PostgresConnector::configureApplicationName(const QSqlDatabase &connection, .arg(config["application_name"].value()))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } void PostgresConnector::configureSynchronousCommit(const QSqlDatabase &connection, @@ -153,7 +153,7 @@ void PostgresConnector::configureSynchronousCommit(const QSqlDatabase &connectio .arg(config["synchronous_commit"].value()))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } } // namespace Orm::Connectors diff --git a/src/orm/connectors/sqliteconnector.cpp b/src/orm/connectors/sqliteconnector.cpp index ef34c61df..39beefd15 100644 --- a/src/orm/connectors/sqliteconnector.cpp +++ b/src/orm/connectors/sqliteconnector.cpp @@ -4,8 +4,8 @@ #include #include "orm/constants.hpp" -#include "orm/invalidargumenterror.hpp" -#include "orm/queryerror.hpp" +#include "orm/exceptions/invalidargumenterror.hpp" +#include "orm/exceptions/queryerror.hpp" #include "orm/utils/type.hpp" using namespace Orm::Constants; @@ -76,7 +76,7 @@ void SQLiteConnector::configureForeignKeyConstraints( .arg(foreignKeyConstraints))) return; - throw QueryError(m_configureErrorMessage.arg(__tiny_func__), query); + throw Exceptions::QueryError(m_configureErrorMessage.arg(__tiny_func__), query); } void SQLiteConnector::checkDatabaseExists(const QVariantHash &config) const @@ -91,7 +91,7 @@ void SQLiteConnector::checkDatabaseExists(const QVariantHash &config) const checkDatabaseExists = config["check_database_exists"].value(); if (checkDatabaseExists && !QFile::exists(path)) - throw InvalidArgumentError( + throw Exceptions::InvalidArgumentError( QStringLiteral("SQLite Database file '%1' does not exist.").arg(path)); } diff --git a/src/orm/databaseconnection.cpp b/src/orm/databaseconnection.cpp index 0dab897a1..b6ab229ad 100644 --- a/src/orm/databaseconnection.cpp +++ b/src/orm/databaseconnection.cpp @@ -2,10 +2,10 @@ #include +#include "orm/exceptions/sqltransactionerror.hpp" #include "orm/logquery.hpp" #include "orm/macros.hpp" #include "orm/query/querybuilder.hpp" -#include "orm/sqltransactionerror.hpp" #include "orm/utils/type.hpp" #ifdef TINYORM_COMMON_NAMESPACE @@ -96,7 +96,7 @@ bool DatabaseConnection::beginTransaction() timer.start(); if (!m_pretending && !getQtConnection().transaction()) - throw SqlTransactionError( + throw Exceptions::SqlTransactionError( QStringLiteral("Statement in %1() failed : %2").arg(__tiny_func__, query), getRawQtConnection().lastError()); @@ -132,7 +132,7 @@ bool DatabaseConnection::commit() // TODO rewrite transactions to DatabaseConnection::statement, so I have access to QSqlQuery for logQuery() silverqx if (!m_pretending && !getQtConnection().commit()) - throw SqlTransactionError( + throw Exceptions::SqlTransactionError( QStringLiteral("Statement in %1() failed : %2").arg(__tiny_func__, query), getRawQtConnection().lastError()); @@ -167,7 +167,7 @@ bool DatabaseConnection::rollBack() timer.start(); if (!m_pretending && !getQtConnection().rollback()) - throw SqlTransactionError( + throw Exceptions::SqlTransactionError( QStringLiteral("Statement in %1() failed : %2").arg(__tiny_func__, query), getRawQtConnection().lastError()); @@ -205,7 +205,7 @@ bool DatabaseConnection::savepoint(const QString &id) // Execute a savepoint query if (!m_pretending && !savePoint.exec(query)) - throw SqlTransactionError( + throw Exceptions::SqlTransactionError( QStringLiteral("Statement in %1() failed : %2") .arg(__tiny_func__, query), savePoint.lastError()); @@ -249,7 +249,7 @@ bool DatabaseConnection::rollbackToSavepoint(const QString &id) // Execute a rollback to savepoint query if (!m_pretending && !rollbackToSavepoint.exec(query)) - throw SqlTransactionError( + throw Exceptions::SqlTransactionError( QStringLiteral("Statement in %1() failed : %2") .arg(__tiny_func__, query), rollbackToSavepoint.lastError()); @@ -303,7 +303,7 @@ DatabaseConnection::select(const QString &queryString, to the exception QueryError(), which formats the error message to include the bindings with SQL, which will make this exception a lot more helpful to the developer instead of just the database's errors. */ - throw QueryError( + throw Exceptions::QueryError( QStringLiteral("Select statement in %1() failed.") .arg(__tiny_func__), query, bindings); @@ -380,7 +380,7 @@ QSqlQuery DatabaseConnection::statement(const QString &queryString, to the exception QueryError(), which formats the error message to include the bindings with SQL, which will make this exception a lot more helpful to the developer instead of just the database's errors. */ - throw QueryError( + throw Exceptions::QueryError( // TODO next use __tiny_func__ in similar statements/exceptions silverqx QStringLiteral("Statement in %1() failed.").arg(__tiny_func__), query, bindings); @@ -419,7 +419,7 @@ DatabaseConnection::affectingStatement(const QString &queryString, to the exception QueryError(), which formats the error message to include the bindings with SQL, which will make this exception a lot more helpful to the developer instead of just the database's errors. */ - throw QueryError( + throw Exceptions::QueryError( QStringLiteral("Affecting statement in %1() failed.") .arg(__tiny_func__), query, bindings); @@ -452,7 +452,7 @@ QSqlQuery DatabaseConnection::unprepared(const QString &queryString) to the exception QueryError(), which formats the error message to include the bindings with SQL, which will make this exception a lot more helpful to the developer instead of just the database's errors. */ - throw QueryError( + throw Exceptions::QueryError( QStringLiteral("Statement in %1() failed.").arg(__tiny_func__), query); }); @@ -470,7 +470,8 @@ QSqlDatabase DatabaseConnection::getQtConnection() /* This should never happen 🤔, do this check only when the QSqlDatabase connection was resolved by connection resolver. */ if (!QSqlDatabase::contains(*m_qtConnection)) - throw RuntimeError("Connection '" + *m_qtConnection + "' doesn't exist."); + throw Exceptions::RuntimeError( + "Connection '" + *m_qtConnection + "' doesn't exist."); } // Return the connection from QSqlDatabase connection manager @@ -589,7 +590,7 @@ DatabaseConnection::hitTransactionalCounters(const QElapsedTimer timer, bool DatabaseConnection::pingDatabase() { - throw RuntimeError( + throw Exceptions::RuntimeError( QStringLiteral("The '%1' database driver doesn't support ping command.") .arg(driverName())); } diff --git a/src/orm/databasemanager.cpp b/src/orm/databasemanager.cpp index c77f81d4d..ce45ca852 100644 --- a/src/orm/databasemanager.cpp +++ b/src/orm/databasemanager.cpp @@ -183,7 +183,7 @@ uint DatabaseManager::transactionLevel() DatabaseManager *DatabaseManager::instance() { if (!m_instance) - throw RuntimeError( + throw Exceptions::RuntimeError( "The DatabaseManager instance has not been created yet, create it " "by DB::create() method."); diff --git a/src/orm/queryerror.cpp b/src/orm/exceptions/queryerror.cpp similarity index 87% rename from src/orm/queryerror.cpp rename to src/orm/exceptions/queryerror.cpp index 6b8d6b81a..7bb791038 100644 --- a/src/orm/queryerror.cpp +++ b/src/orm/exceptions/queryerror.cpp @@ -1,4 +1,4 @@ -#include "orm/queryerror.hpp" +#include "orm/exceptions/queryerror.hpp" #include @@ -8,7 +8,7 @@ namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { QueryError::QueryError(const char *message, const QSqlQuery &query, @@ -23,12 +23,12 @@ QueryError::QueryError(const QString &message, const QSqlQuery &query, : QueryError(message.toUtf8().constData(), query, bindings) {} -const QString &Orm::QueryError::getSql() const +const QString &QueryError::getSql() const { return m_sql; } -const QVector &Orm::QueryError::getBindings() const +const QVector &QueryError::getBindings() const { return m_bindings; } diff --git a/src/orm/sqlerror.cpp b/src/orm/exceptions/sqlerror.cpp similarity index 95% rename from src/orm/sqlerror.cpp rename to src/orm/exceptions/sqlerror.cpp index 070e9ae83..5d0b6c2eb 100644 --- a/src/orm/sqlerror.cpp +++ b/src/orm/exceptions/sqlerror.cpp @@ -1,4 +1,4 @@ -#include "orm/sqlerror.hpp" +#include "orm/exceptions/sqlerror.hpp" #include @@ -10,7 +10,7 @@ using namespace Orm::Constants; namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm +namespace Orm::Exceptions { SqlError::SqlError(const char *message, const QSqlError &error) diff --git a/src/orm/query/grammars/grammar.cpp b/src/orm/query/grammars/grammar.cpp index ad6ebec62..40c2dc4d9 100644 --- a/src/orm/query/grammars/grammar.cpp +++ b/src/orm/query/grammars/grammar.cpp @@ -51,8 +51,9 @@ QString Grammar::compileInsert(const QueryBuilder &query, QString Grammar::compileInsertOrIgnore(const QueryBuilder &, const QVector &) const { - throw RuntimeError("This database engine does not support inserting while " - "ignoring errors."); + throw Exceptions::RuntimeError( + "This database engine does not support inserting while ignoring " + "errors."); } QString Grammar::compileUpdate(QueryBuilder &query, @@ -193,7 +194,7 @@ QString Grammar::compileColumns(const QueryBuilder &query) const const auto &distinct = query.getDistinct(); if (!std::holds_alternative(distinct)) - throw RuntimeError( + throw Exceptions::RuntimeError( QStringLiteral("Connection '%1' doesn't support defining more distinct " "columns.") .arg(query.getConnection().getName())); @@ -298,8 +299,8 @@ QString Grammar::compileHaving(const HavingConditionItem &having) const T_UNLIKELY default: - throw RuntimeError(QStringLiteral("Unknown HavingType (%1).") - .arg(static_cast(having.type))); + throw Exceptions::RuntimeError(QStringLiteral("Unknown HavingType (%1).") + .arg(static_cast(having.type))); } } diff --git a/src/orm/query/processors/processor.cpp b/src/orm/query/processors/processor.cpp index ef1588166..264e8f970 100644 --- a/src/orm/query/processors/processor.cpp +++ b/src/orm/query/processors/processor.cpp @@ -1,6 +1,6 @@ #include "orm/query/processors/processor.hpp" -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" #include "orm/utils/type.hpp" #ifdef TINYORM_COMMON_NAMESPACE @@ -12,8 +12,8 @@ namespace Orm::Query::Processors QStringList Processor::processColumnListing(QSqlQuery &) const { - throw RuntimeError(QStringLiteral("Method %1() is not implemented.") - .arg(__tiny_func__)); + throw Exceptions::RuntimeError(QStringLiteral("Method %1() is not implemented.") + .arg(__tiny_func__)); } } // namespace Orm::Query::Processors diff --git a/src/orm/query/querybuilder.cpp b/src/orm/query/querybuilder.cpp index e4077fdea..33246b9cc 100644 --- a/src/orm/query/querybuilder.cpp +++ b/src/orm/query/querybuilder.cpp @@ -1,7 +1,7 @@ #include "orm/query/querybuilder.hpp" #include "orm/databaseconnection.hpp" -#include "orm/invalidargumenterror.hpp" +#include "orm/exceptions/invalidargumenterror.hpp" #include "orm/query/joinclause.hpp" #ifdef TINYORM_COMMON_NAMESPACE @@ -520,8 +520,8 @@ Builder &Builder::orderBy(const Column &column, const QString &direction) const auto &directionLower = direction.toLower(); if (directionLower != ASC && directionLower != DESC) - throw RuntimeError("Order direction must be \"asc\" or \"desc\", " - "case is not important."); + throw Exceptions::RuntimeError( + "Order direction must be \"asc\" or \"desc\", case is not important."); m_orders.append({column, directionLower}); @@ -1079,8 +1079,9 @@ void Builder::checkBindingType(const BindingType type) const return; // TODO add hash which maps BindingType to the QString silverqx - throw InvalidArgumentError(QStringLiteral("Invalid binding type: %1") - .arg(static_cast(type))); + throw Exceptions::InvalidArgumentError( + QStringLiteral("Invalid binding type: %1") + .arg(static_cast(type))); } } // namespace Orm diff --git a/src/orm/tiny/modelnotfounderror.cpp b/src/orm/tiny/exceptions/modelnotfounderror.cpp similarity index 93% rename from src/orm/tiny/modelnotfounderror.cpp rename to src/orm/tiny/exceptions/modelnotfounderror.cpp index b2f776bd6..db67744ed 100644 --- a/src/orm/tiny/modelnotfounderror.cpp +++ b/src/orm/tiny/exceptions/modelnotfounderror.cpp @@ -1,4 +1,4 @@ -#include "orm/tiny/modelnotfounderror.hpp" +#include "orm/tiny/exceptions/modelnotfounderror.hpp" #include "orm/constants.hpp" @@ -8,7 +8,7 @@ using namespace Orm::Constants; namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm::Tiny +namespace Orm::Tiny::Exceptions { ModelNotFoundError::ModelNotFoundError(const char *model, diff --git a/src/orm/tiny/relationnotfounderror.cpp b/src/orm/tiny/exceptions/relationnotfounderror.cpp similarity index 95% rename from src/orm/tiny/relationnotfounderror.cpp rename to src/orm/tiny/exceptions/relationnotfounderror.cpp index b96736ee0..16c52eca6 100644 --- a/src/orm/tiny/relationnotfounderror.cpp +++ b/src/orm/tiny/exceptions/relationnotfounderror.cpp @@ -1,10 +1,10 @@ -#include "orm/tiny/relationnotfounderror.hpp" +#include "orm/tiny/exceptions/relationnotfounderror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm::Tiny +namespace Orm::Tiny::Exceptions { RelationNotFoundError::RelationNotFoundError(const QString &model, diff --git a/src/orm/tiny/relationnotloadederror.cpp b/src/orm/tiny/exceptions/relationnotloadederror.cpp similarity index 89% rename from src/orm/tiny/relationnotloadederror.cpp rename to src/orm/tiny/exceptions/relationnotloadederror.cpp index aee9801e3..e562ef2fb 100644 --- a/src/orm/tiny/relationnotloadederror.cpp +++ b/src/orm/tiny/exceptions/relationnotloadederror.cpp @@ -1,10 +1,10 @@ -#include "orm/tiny/relationnotloadederror.hpp" +#include "orm/tiny/exceptions/relationnotloadederror.hpp" #ifdef TINYORM_COMMON_NAMESPACE namespace TINYORM_COMMON_NAMESPACE { #endif -namespace Orm::Tiny +namespace Orm::Tiny::Exceptions { RelationNotLoadedError::RelationNotLoadedError(const QString &model, diff --git a/src/orm/utils/type.cpp b/src/orm/utils/type.cpp index 299f1e932..767d1808b 100644 --- a/src/orm/utils/type.cpp +++ b/src/orm/utils/type.cpp @@ -3,7 +3,7 @@ #include #include "orm/constants.hpp" -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" using namespace Orm::Constants; @@ -31,7 +31,8 @@ QString Type::prettyFunction(const QString &function) QRegularExpression re(QStringLiteral( "(?:.*::)?(\\w+)(?:<.*>)?::(\\w+)(?:$|:: using TinyBuilder = Orm::Tiny::Builder; diff --git a/tests/auto/unit/orm/tiny/mysql_tinybuilder/tst_mysql_tinybuilder.cpp b/tests/auto/unit/orm/tiny/mysql_tinybuilder/tst_mysql_tinybuilder.cpp index b918654a1..962f32563 100644 --- a/tests/auto/unit/orm/tiny/mysql_tinybuilder/tst_mysql_tinybuilder.cpp +++ b/tests/auto/unit/orm/tiny/mysql_tinybuilder/tst_mysql_tinybuilder.cpp @@ -9,7 +9,7 @@ using namespace Orm::Constants; -using Orm::InvalidArgumentError; +using Orm::Exceptions::InvalidArgumentError; using Orm::QueryBuilder; using Orm::Tiny::TinyBuilder; diff --git a/tests/auto/utils/src/databases.cpp b/tests/auto/utils/src/databases.cpp index 4a064b9d3..45335cee9 100644 --- a/tests/auto/utils/src/databases.cpp +++ b/tests/auto/utils/src/databases.cpp @@ -1,11 +1,11 @@ #include "databases.hpp" #include "orm/db.hpp" -#include "orm/logicerror.hpp" -#include "orm/runtimeerror.hpp" +#include "orm/exceptions/logicerror.hpp" +#include "orm/exceptions/runtimeerror.hpp" -using Orm::LogicError; -using Orm::RuntimeError; +using Orm::Exceptions::LogicError; +using Orm::Exceptions::RuntimeError; namespace TestUtils {