diff --git a/include/orm/exceptions/multiplerecordsfounderror.hpp b/include/orm/exceptions/multiplerecordsfounderror.hpp index 6230f3b98..aa731b53c 100644 --- a/include/orm/exceptions/multiplerecordsfounderror.hpp +++ b/include/orm/exceptions/multiplerecordsfounderror.hpp @@ -17,22 +17,29 @@ namespace Orm::Exceptions { public: /*! Constructor. */ - inline explicit MultipleRecordsFoundError(int count); + inline explicit MultipleRecordsFoundError(int count, QString &&functionName); /*! Get the number of records found. */ inline int count() const noexcept; + /*! Get a function name where the exception occured. */ + inline const QString &functionName() const noexcept; protected: /*! The number of records found. */ int m_count; + /*! Function name where the exception occured. */ + QString m_functionName; }; /* public */ - MultipleRecordsFoundError::MultipleRecordsFoundError(const int count) - : RuntimeError(QStringLiteral("%1 records were found.").arg(count) + MultipleRecordsFoundError::MultipleRecordsFoundError(const int count, + QString &&functionName) + : RuntimeError(QStringLiteral("%1 records were found in %2().") + .arg(count).arg(functionName) .toUtf8().constData()) , m_count(count) + , m_functionName(std::move(functionName)) {} int MultipleRecordsFoundError::count() const noexcept @@ -40,6 +47,11 @@ namespace Orm::Exceptions return m_count; } + const QString &MultipleRecordsFoundError::functionName() const noexcept + { + return m_functionName; + } + } // namespace Orm::Exceptions TINYORM_END_COMMON_NAMESPACE diff --git a/include/orm/tiny/concerns/buildsqueries.hpp b/include/orm/tiny/concerns/buildsqueries.hpp index d9357179c..2d069e6a5 100644 --- a/include/orm/tiny/concerns/buildsqueries.hpp +++ b/include/orm/tiny/concerns/buildsqueries.hpp @@ -287,7 +287,7 @@ namespace Concerns QStringLiteral("No records found in %1().").arg(__tiny_func__)); if (count > 1) - throw Orm::Exceptions::MultipleRecordsFoundError(count); + throw Orm::Exceptions::MultipleRecordsFoundError(count, __tiny_func__); return std::move(models.first()); } diff --git a/src/orm/query/concerns/buildsqueries.cpp b/src/orm/query/concerns/buildsqueries.cpp index af5a02415..a330d7913 100644 --- a/src/orm/query/concerns/buildsqueries.cpp +++ b/src/orm/query/concerns/buildsqueries.cpp @@ -185,7 +185,7 @@ SqlQuery BuildsQueries::sole(const QVector &columns) QStringLiteral("No records found in %1().").arg(__tiny_func__)); if (count > 1) - throw Exceptions::MultipleRecordsFoundError(count); + throw Exceptions::MultipleRecordsFoundError(count, __tiny_func__); query.first();