source: src/orm/ormrecord.h @ 5a73d27

qt5
Last change on this file since 5a73d27 was 5a73d27, checked in by komarma <komarma@…>, 12 years ago

Adding orm module

  • Property mode set to 100644
File size: 844 bytes
Line 
1#include <QSqlRecord>
2#include <QSqlField>
3
4template <typename T>
5class OrmRecord : protected QSqlRecord
6{
7public:
8    static QString colName(int col);
9
10protected:
11    QVariant value(int col) const;
12    void setValue(int col, QVariant value);
13};
14
15template <typename T>
16QString OrmRecord<T>::colName(int col)
17{
18    return T::sColNames.at(col);
19}
20
21template <typename T>
22QVariant OrmRecord<T>::value(int col) const
23{
24    Q_ASSERT(col >= 0 && col < T::sColNames.count());
25
26    return QSqlRecord::value(T::sColNames.at(col));
27}
28
29template <typename T>
30void OrmRecord<T>::setValue(int col, QVariant value)
31{
32    Q_ASSERT(col >= 0 && col < T::sColNames.count());
33
34    QString fieldName = T::sColNames.at(col);
35
36    if (!contains(fieldName))
37    {
38        append(QSqlField(fieldName, value.type()));
39    }
40
41    QSqlRecord::setValue(fieldName, value);
42}
Note: See TracBrowser for help on using the repository browser.