Quark  0.1
SqlValueBinder.h++
Go to the documentation of this file.
1 #ifndef __libquark_util_SqlValueBinder_hxx
2 #define __libquark_util_SqlValueBinder_hxx
3 
4 #include <QSqlQuery>
5 #include <QVariant>
6 
7 namespace quark {
8 namespace util {
9 
17 {
18  public:
19 
21  SqlValueBinder(QSqlQuery &query)
22  : _query(query)
23  , _index(0)
24  { }
25 
28  { }
29 
33  template<typename T> SqlValueBinder& operator<<(const T &value)
34  {
35  _query.bindValue(_index, value);
36  ++_index;
37  return(*this);
38  }
39 
43  template<typename T> SqlValueBinder& operator>>(T &value)
44  {
45  QVariant variant = _query.value(_index);
46  value = variant.value<T>();
47  ++_index;
48  return(*this);
49  }
50 
55  void reset()
56  { _index = 0; }
57 
58  private:
59 
60  QSqlQuery &_query;
61  int _index;
62 };
63 
64 } // namespace util
65 } // namespace quark
66 
67 #endif // __libquark_util_SqlValueBinder_hxx
SqlValueBinder & operator>>(T &value)
Extracts a value from the next field in the results.
Definition: SqlValueBinder.h++:43
SqlValueBinder(QSqlQuery &query)
Constructs a new SqlValueBinder for the given query.
Definition: SqlValueBinder.h++:21
~SqlValueBinder()
Destructor.
Definition: SqlValueBinder.h++:27
SqlValueBinder & operator<<(const T &value)
Binds a value to the next query parameter.
Definition: SqlValueBinder.h++:33
Definition: BarChartView.h++:6
void reset()
Reset the SqlValueBinder.
Definition: SqlValueBinder.h++:55
#define LIBQUARK_API
Definition: Quark.h++:18
A value binder for a QSqlQuery object.
Definition: SqlValueBinder.h++:16