TreeFrogFramework: src/tsqlqueryormapper.h Source File

1#pragma once

2#include <QList>

3#include <QtSql>

4#include <TCriteriaConverter>

5#include <TSqlQuery>

6#include <TSystemGlobal>

7

17template <class T>

19public:

21

23 bool load(const QString &filename);

27 bool exec(const QString &query);

29 T execFirst(const QString &query);

32 int size() const;

35 QString fieldName(int index) const;

36

40

45 public:

48

53 {

54 m = o.m;

56 return *this;

57 }

59 {

60 if (it == 0)

61 m->first();

62 return m->value();

63 }

67 {

68 it = qMin(it + 1, m->size());

69 m->next();

70 return *this;

71 }

72

73 private:

75 m(mapper), it(i) { }

77 };

78};

79

80

81template <class T>

86

87

88template <class T>

94

95

96template <class T>

101

102

103template <class T>

105{

107 return *this;

108}

109

110

111template <class T>

113{

115 return *this;

116}

117

118

119template <class T>

121{

123 return *this;

124}

125

126

127template <class T>

132

133

134template <class T>

139

140

141template <class T>

146

147

148template <class T>

153

154

155template <class T>

160

161

162template <class T>

167

168

169template <class T>

174

175

176template <class T>

178{

179 T rec;

180 QSqlRecord r = record();

182 return rec;

183}

184

185

186template <class T>

188{

189 return TCriteriaConverter<T>::getPropertyName(index, driver());

190}

191

Const iterator.

Definition tsqlqueryormapper.h:44

TSqlQueryORMapper< T > * m

Definition tsqlqueryormapper.h:46

const T operator*() const

Definition tsqlqueryormapper.h:58

bool operator!=(const ConstIterator &o) const

Definition tsqlqueryormapper.h:65

bool operator==(const ConstIterator &o) const

Definition tsqlqueryormapper.h:64

ConstIterator & operator=(const ConstIterator &o)

Definition tsqlqueryormapper.h:52

ConstIterator & operator++()

Definition tsqlqueryormapper.h:66

int it

Definition tsqlqueryormapper.h:47

ConstIterator(const ConstIterator &o)

Definition tsqlqueryormapper.h:50

ConstIterator()

Definition tsqlqueryormapper.h:49

The TSqlQueryORMapper class is a template class that creates ORM objects by executing and manipulatin...

Definition tsqlqueryormapper.h:18

TSqlQueryORMapper(int databaseId=0)

Constructs a TSqlQueryORMapper object using the SQL query and the database databaseId.

Definition tsqlqueryormapper.h:82

TSqlQueryORMapper< T > & prepare(const QString &query)

Prepares the SQL query query to retrieve the ORM objects specified by the class T.

Definition tsqlqueryormapper.h:89

QString fieldName(int index) const

Returns the name of the field at position index in the class T.

Definition tsqlqueryormapper.h:187

bool next()

Definition tsqlqueryormapper.h:170

bool exec()

Definition tsqlqueryormapper.h:135

ConstIterator end()

Definition tsqlqueryormapper.h:39

int numRowsAffected() const

Definition tsqlqueryormapper.h:156

T value() const

Returns the current ORM object in the results retrieved by the query.

Definition tsqlqueryormapper.h:177

ConstIterator begin()

Definition tsqlqueryormapper.h:38

TSqlQueryORMapper< T > & addBind(const QVariant &val)

Definition tsqlqueryormapper.h:120

TSqlQueryORMapper< T > & bind(const QString &placeholder, const QVariant &val)

Definition tsqlqueryormapper.h:104

T execFirst()

Definition tsqlqueryormapper.h:149

int size() const

Definition tsqlqueryormapper.h:163

bool load(const QString &filename)

Definition tsqlqueryormapper.h:97

The TSqlQuery class provides a means of executing and manipulating SQL statements.

Definition tsqlquery.h:6

bool exec()

Executes a previously prepared SQL query.

Definition tsqlquery.cpp:213

TSqlQuery & addBind(const QVariant &val)

Adds the value val to the list of values when using positional value binding and returns the query ob...

Definition tsqlquery.cpp:298

int numRowsAffected() const

Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined.

Definition tsqlquery.h:50

TSqlQuery & prepare(const QString &query)

Prepares the SQL query query for execution.

Definition tsqlquery.cpp:174

TSqlQuery & bind(const QString &placeholder, const QVariant &val)

Set the placeholder placeholder to be bound to value val in the prepared statement.

Definition tsqlquery.cpp:252

bool load(const QString &filename)

Loads a query from the given file filename.

Definition tsqlquery.cpp:50

int size() const

Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or i...

Definition tsqlquery.h:56

bool next()

Retrieves the next record in the result, if available, and positions the query on the retrieved recor...

Definition tsqlquery.h:62

QSqlError lastError()

Returns the VariantMap object of the error status of the last operation.

Definition tcachesqlitestore.cpp:26