qt5
Last change
on this file since 5a73d27 was
5a73d27,
checked in by komarma <komarma@…>, 13 years ago
|
Adding orm module
|
-
Property mode set to
100644
|
File size:
844 bytes
|
Line | |
---|
1 | #include <QSqlRecord> |
---|
2 | #include <QSqlField> |
---|
3 | |
---|
4 | template <typename T> |
---|
5 | class OrmRecord : protected QSqlRecord |
---|
6 | { |
---|
7 | public: |
---|
8 | static QString colName(int col); |
---|
9 | |
---|
10 | protected: |
---|
11 | QVariant value(int col) const; |
---|
12 | void setValue(int col, QVariant value); |
---|
13 | }; |
---|
14 | |
---|
15 | template <typename T> |
---|
16 | QString OrmRecord<T>::colName(int col) |
---|
17 | { |
---|
18 | return T::sColNames.at(col); |
---|
19 | } |
---|
20 | |
---|
21 | template <typename T> |
---|
22 | QVariant 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 | |
---|
29 | template <typename T> |
---|
30 | void 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.