Changeset c790268 for src/orm/ormrecord.h
- Timestamp:
- 01/17/10 17:22:03 (13 years ago)
- Branches:
- master, qt5
- Children:
- 6f39595
- Parents:
- 680a4da
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/orm/ormrecord.h
r680a4da rc790268 10 10 #include <QDebug> 11 11 12 // INFO: 13 // all record items/columns may be defined in one table (1.), or 14 // they can be splitted in two separate tables (2.) (eg. for FTS support) 15 // 1.) you have to define "static QString const sTableName" 16 // 2.) you have to define two table names: 17 // "static QString const sTable1Name" 18 // "static QString const sTable2Name" 19 // and since all record items/columns are handled by one QSqlRecord, 20 // you have to also define number of columns that belongs to table 1 (1.), and table 2 (2.) 21 // 1.) "static int const sTable1ColCount" 22 // 2.) "static int const sTable2ColCount" 23 // there are also defined auxiliary methods for 1-Table/2-Tables approach, see bellow 24 12 25 class OrmException 13 26 { … … 44 57 45 58 // auxiliary methods 59 static QSqlRecord toRecord(const QList<QSqlField> & columnList); 60 // all record items/columns are in one table 46 61 static QString columnsForSelect(const QString& prefix = QString()); 47 62 static QString selectQuery(); 48 63 static QString updateQuery(); 49 static QSqlRecord toRecord(const QList<QSqlField> & columnList); 64 // record items/columns are stored in two tables 65 static QString columnsForSelectJoin2T(); // for joining two tables 66 static QString selectQueryJoin2T(const QString &key); // for joining two tables 50 67 51 68 static QVariant convertToC(QVariant value, QVariant::Type colType); … … 150 167 151 168 template <typename T> 169 QString OrmRecord<T>::columnsForSelectJoin2T() 170 { 171 Q_ASSERT((T::sTable1ColCount+T::sTable2ColCount) == T::sColumns.count()); 172 173 QStringList prefixedColumns; 174 for (int i=0; i<T::sTable1ColCount; i++) 175 { 176 prefixedColumns.append(QString("%1.%2").arg(T::sTable1Name, T::sColumns.field(i).name())); 177 } 178 for (int j=0; j<T::sTable2ColCount; j++) 179 { 180 prefixedColumns.append(QString("%1.%2").arg(T::sTable2Name, T::sColumns.field(T::sTable1ColCount+j).name())); 181 } 182 return prefixedColumns.join(","); 183 } 184 185 template <typename T> 152 186 QString OrmRecord<T>::selectQuery() 153 187 { … … 156 190 157 191 template <typename T> 192 QString OrmRecord<T>::selectQueryJoin2T(const QString &key) 193 { 194 return QString("SELECT %1 FROM %2 INNER JOIN %3 ON %4.%5 = %6.%7 ").arg( 195 columnsForSelectJoin2T(), 196 T::sTable1Name, 197 T::sTable2Name, 198 T::sTable1Name, 199 key, 200 T::sTable2Name, 201 key); 202 } 203 204 template <typename T> 158 205 QString OrmRecord<T>::updateQuery() 159 206 { 160 return QString("UPDATE %1 ").arg(T::sTable Name);207 return QString("UPDATE %1 ").arg(T::sTable1Name); 161 208 } 162 209 … … 198 245 199 246 #endif // ORMRECORD_H 247
Note: See TracChangeset
for help on using the changeset viewer.