Qx v0.7
Qt Extensions Library
Loading...
Searching...
No Matches
qx-sqlerror.h
1#ifndef QX_SQLERROR_H
2#define QX_SQLERROR_H
3
4// Shared Lib Support
5#include "qx/sql/qx_sql_export.h"
6
7// Extra-component Includes
9
10class QSqlError;
11
12namespace QxSqlPrivate {template<typename T> struct FieldChecker; }
13
14namespace Qx
15{
16
17class SqlQuery;
18class SqlDatabase;
19
20class QX_SQL_EXPORT SqlError final : public AbstractError<"Qx::SqlError", 7>
21{
22 template<typename T>
23 friend struct QxSqlPrivate::FieldChecker;
24//-Class Enums-------------------------------------------------------------
25public:
26 enum Form
27 {
29 MissingDb,
33 InvalidResult
34 };
35
36//-Class Variables-------------------------------------------------------------
37private:
38 static inline const QHash<Form, QString> ERR_STRINGS{
39 {NoError, u"No error occurred."_s},
40 {MissingDb, u"The query could not be executed because it has no associated database."_s},
41 {EngineError, u"Engine error."_s},
42 {TypeMismatch, u"A field value did not match the expected type."_s},
43 {MissingField, u"An expected field is missing."_s},
44 {InvalidResult, u"Data retrieval from an invalid result was attempted."_s}
45 };
46 static inline const QString DATABASE_INFO_TEMPLATE =
47 u"Connected: %1\n"_s
48 u"Database Name: %2\n"_s
49 u"Driver: %3"_s;
50
51//-Instance Variables-------------------------------------------------------------
52private:
53 Form mForm;
54 QString mCause;
55 QString mQuery;
56 QString mDatabase;
57
58//-Constructor---------------------------------------------------------------------
59private:
60 SqlError(const QString& fromType, const QString& toType, const QString& field = {}); // Convenience for TypeMismatch
61
62public:
63 SqlError();
64 SqlError(Form f, const QString& c = {});
65 SqlError(const QSqlError& engineError);
66
67//-Instance Functions-------------------------------------------------------------
68private:
69 quint32 deriveValue() const override;
70 QString derivePrimary() const override;
71 QString deriveSecondary() const override;
72 QString deriveDetails() const override;
73
74public:
75 bool isValid() const;
76 Form form() const;
77 QString cause() const;
78 QString query() const;
79 QString databaseInfo() const;
80
81 SqlError& withQuery(const SqlQuery& q); // Auto-adds database
82 SqlError& withQuery(const QString& q);
83 SqlError& withDatabase(const SqlDatabase& db);
84};
85
86}
87
88#endif // QX_SQLERROR_H
The SqlDatabase class provides straightforward access to an SQL database.
Definition qx-sqldatabase.h:36
Form
Definition qx-sqlerror.h:27
@ NoError
Definition qx-sqlerror.h:28
@ TypeMismatch
Definition qx-sqlerror.h:31
@ EngineError
Definition qx-sqlerror.h:30
@ MissingField
Definition qx-sqlerror.h:32
SqlQuery is a base class from which all query types derive.
Definition qx-sqlquery.h:171
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-abstracterror.cpp:13
The qx-abstracterror.h header file provides access to the base class from which custom error types sh...