Qx v0.7
Qt Extensions Library
Loading...
Searching...
No Matches
qx-sqlresult.h
1#ifndef QX_SQLRESULT_H
2#define QX_SQLRESULT_H
3
4// Qt Includes
5#include <QSqlQuery>
6
7// Intra-component Includes
8#include "qx/sql/__private/qx-sqlquery_p.h"
10
11namespace QxSql
12{
13
14//-Namespace Enums----------------------------------------------------------------------------------------------------
20
21}
22
23namespace Qx
24{
25
26// TODO: Allow going backwards
27template<QxSql::sql_struct T>
28class SqlResult
29{
30 friend class SqlDqlQuery;
31//-Instance Variables-----------------------------------------------------------------------------------------------
32private:
33 QSqlQuery mResult;
34 int mSize;
35
36//-Constructor-------------------------------------------------------------------------------------------------
37private:
38 SqlResult(QSqlQuery&& validQuery, int size) :
39 mResult(std::move(validQuery)),
40 mSize(size)
41 {
42 Q_ASSERT(mResult.isActive());
43 }
44
45public:
46 SqlResult() : mSize(-1) {}
47
48//-Instance Functions------------------------------------------------------------------------------------------------------
49public:
50 int at() const { return mResult.at(); }
51 int size() const { return mSize; }
52 bool isValid() const { return mResult.isValid(); }
53 bool isEmpty() const { return mSize < 1; }
54
56 {
57 if(isValid())
58 return QxSqlPrivate::RowConverter<T>::fromSql(value, mResult);
59 else
60 return SqlError(SqlError::InvalidResult).withQuery(mResult.lastQuery());
61 }
62
63 bool next() { return mResult.next(); }
64};
65
66}
67
68#endif // QX_SQLRESULT_H
The SqlError class is used to report errors related to database configuration and SQL queries.
Definition qx-sqlerror.h:21
SqlError & withQuery(const SqlQuery &q)
Definition qx-sqlerror.cpp:112
bool next()
Definition qx-sqlresult.h:63
SqlResult()
Definition qx-sqlresult.h:46
bool isEmpty() const
Definition qx-sqlresult.h:53
bool isValid() const
Definition qx-sqlresult.h:52
int size() const
Definition qx-sqlresult.h:51
SqlError value(T &value) const
Definition qx-sqlresult.h:55
int at() const
Definition qx-sqlresult.h:50
The QxSql namespace contains several utilities that are specific to the SQL module and grouped togeth...
Definition qx-sqlconcepts.dox:10
Location
Definition qx-sqlresult.h:16
@ BeforeFirstRow
Definition qx-sqlresult.h:17
@ AfterLastRow
Definition qx-sqlresult.h:18
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-sqlconcepts header file provides a set of concepts that are specific to the Qx SQL module.