| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/sql/models/qsqlrelationaltablemodel.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | class QSqlRelationalTableModelSql: public QSqlTableModelSql | - | ||||||||||||||||||
| 8 | { | - | ||||||||||||||||||
| 9 | public: | - | ||||||||||||||||||
| 10 | inline const static QString relTablePrefix(int i) { return executed 107 times by 1 test: QString::number(i).prepend(QLatin1String("relTblAl_"));return QString::number(i).prepend(QLatin1String("relTblAl_"));Executed by:
executed 107 times by 1 test: }return QString::number(i).prepend(QLatin1String("relTblAl_"));Executed by:
| 107 | ||||||||||||||||||
| 11 | }; | - | ||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | typedef QSqlRelationalTableModelSql Sql; | - | ||||||||||||||||||
| 14 | class QRelatedTableModel; | - | ||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | struct QRelation | - | ||||||||||||||||||
| 17 | { | - | ||||||||||||||||||
| 18 | public: | - | ||||||||||||||||||
| 19 | QRelation(): model(0), m_parent(0), m_dictInitialized(false) {} executed 266 times by 1 test: end of blockExecuted by:
| 266 | ||||||||||||||||||
| 20 | void init(QSqlRelationalTableModel *parent, const QSqlRelation &relation); | - | ||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | void populateModel(); | - | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | bool isDictionaryInitialized(); | - | ||||||||||||||||||
| 25 | void populateDictionary(); | - | ||||||||||||||||||
| 26 | void clearDictionary(); | - | ||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | void clear(); | - | ||||||||||||||||||
| 29 | bool isValid(); | - | ||||||||||||||||||
| 30 | - | |||||||||||||||||||
| 31 | QSqlRelation rel; | - | ||||||||||||||||||
| 32 | QRelatedTableModel *model; | - | ||||||||||||||||||
| 33 | QHash<QString, QVariant> dictionary; | - | ||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | private: | - | ||||||||||||||||||
| 36 | QSqlRelationalTableModel *m_parent; | - | ||||||||||||||||||
| 37 | bool m_dictInitialized; | - | ||||||||||||||||||
| 38 | }; | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | class QRelatedTableModel : public QSqlTableModel | - | ||||||||||||||||||
| 41 | { | - | ||||||||||||||||||
| 42 | public: | - | ||||||||||||||||||
| 43 | QRelatedTableModel(QRelation *rel, QObject *parent = 0, QSqlDatabase db = QSqlDatabase()); | - | ||||||||||||||||||
| 44 | bool select() override; | - | ||||||||||||||||||
| 45 | private: | - | ||||||||||||||||||
| 46 | bool firstSelect; | - | ||||||||||||||||||
| 47 | QRelation *relation; | - | ||||||||||||||||||
| 48 | }; | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | void QRelation::init(QSqlRelationalTableModel *parent, const QSqlRelation &relation) | - | ||||||||||||||||||
| 55 | { | - | ||||||||||||||||||
| 56 | ((!(parent != __null)) ? qt_assert("parent != NULL",__FILE__,171) : qt_noop()); | - | ||||||||||||||||||
| 57 | m_parent = parent; | - | ||||||||||||||||||
| 58 | rel = relation; | - | ||||||||||||||||||
| 59 | } executed 44 times by 1 test: end of blockExecuted by:
| 44 | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | void QRelation::populateModel() | - | ||||||||||||||||||
| 62 | { | - | ||||||||||||||||||
| 63 | if (!isValid()
| 0-40 | ||||||||||||||||||
| 64 | return; never executed: return; | 0 | ||||||||||||||||||
| 65 | ((!(m_parent != __null)) ? qt_assert("m_parent != NULL",__FILE__,180) : qt_noop()); | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | if (!model
| 0-40 | ||||||||||||||||||
| 68 | model = new QRelatedTableModel(this, m_parent, m_parent->database()); | - | ||||||||||||||||||
| 69 | model->setTable(rel.tableName()); | - | ||||||||||||||||||
| 70 | model->select(); | - | ||||||||||||||||||
| 71 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 72 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | bool QRelation::isDictionaryInitialized() | - | ||||||||||||||||||
| 75 | { | - | ||||||||||||||||||
| 76 | return executed 191 times by 1 test: m_dictInitialized;return m_dictInitialized;Executed by:
executed 191 times by 1 test: return m_dictInitialized;Executed by:
| 191 | ||||||||||||||||||
| 77 | } | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | void QRelation::populateDictionary() | - | ||||||||||||||||||
| 80 | { | - | ||||||||||||||||||
| 81 | if (!isValid()
| 0-66 | ||||||||||||||||||
| 82 | return; never executed: return; | 0 | ||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | if (model == __null
| 29-37 | ||||||||||||||||||
| 85 | populateModel(); executed 37 times by 1 test: populateModel();Executed by:
| 37 | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | QSqlRecord record; | - | ||||||||||||||||||
| 88 | QString indexColumn; | - | ||||||||||||||||||
| 89 | QString displayColumn; | - | ||||||||||||||||||
| 90 | for (int i=0; i < model->rowCount()
| 66-136 | ||||||||||||||||||
| 91 | record = model->record(i); | - | ||||||||||||||||||
| 92 | - | |||||||||||||||||||
| 93 | indexColumn = rel.indexColumn(); | - | ||||||||||||||||||
| 94 | if (m_parent->database().driver()->isIdentifierEscaped(indexColumn, QSqlDriver::FieldName)
| 14-122 | ||||||||||||||||||
| 95 | indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName); executed 14 times by 1 test: indexColumn = m_parent->database().driver()->stripDelimiters(indexColumn, QSqlDriver::FieldName);Executed by:
| 14 | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | displayColumn = rel.displayColumn(); | - | ||||||||||||||||||
| 98 | if (m_parent->database().driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName)
| 18-118 | ||||||||||||||||||
| 99 | displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); executed 18 times by 1 test: displayColumn = m_parent->database().driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName);Executed by:
| 18 | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | dictionary[record.field(indexColumn).value().toString()] = | - | ||||||||||||||||||
| 102 | record.field(displayColumn).value(); | - | ||||||||||||||||||
| 103 | } executed 136 times by 1 test: end of blockExecuted by:
| 136 | ||||||||||||||||||
| 104 | m_dictInitialized = true; | - | ||||||||||||||||||
| 105 | } executed 66 times by 1 test: end of blockExecuted by:
| 66 | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | void QRelation::clearDictionary() | - | ||||||||||||||||||
| 108 | { | - | ||||||||||||||||||
| 109 | dictionary.clear(); | - | ||||||||||||||||||
| 110 | m_dictInitialized = false; | - | ||||||||||||||||||
| 111 | } executed 216 times by 1 test: end of blockExecuted by:
| 216 | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | void QRelation::clear() | - | ||||||||||||||||||
| 114 | { | - | ||||||||||||||||||
| 115 | delete model; | - | ||||||||||||||||||
| 116 | model = 0; | - | ||||||||||||||||||
| 117 | clearDictionary(); | - | ||||||||||||||||||
| 118 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | bool QRelation::isValid() | - | ||||||||||||||||||
| 121 | { | - | ||||||||||||||||||
| 122 | return executed 497 times by 1 test: (rel.isValid() && m_parent != __null);return (rel.isValid() && m_parent != __null);Executed by:
executed 497 times by 1 test: return (rel.isValid() && m_parent != __null);Executed by:
| 497 | ||||||||||||||||||
| 123 | } | - | ||||||||||||||||||
| 124 | - | |||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | QRelatedTableModel::QRelatedTableModel(QRelation *rel, QObject *parent, QSqlDatabase db) : | - | ||||||||||||||||||
| 128 | QSqlTableModel(parent, db), firstSelect(true), relation(rel) | - | ||||||||||||||||||
| 129 | { | - | ||||||||||||||||||
| 130 | } executed 40 times by 1 test: end of blockExecuted by:
| 40 | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | bool QRelatedTableModel::select() | - | ||||||||||||||||||
| 133 | { | - | ||||||||||||||||||
| 134 | if (firstSelect
| 1-40 | ||||||||||||||||||
| 135 | firstSelect = false; | - | ||||||||||||||||||
| 136 | return executed 40 times by 1 test: QSqlTableModel::select();return QSqlTableModel::select();Executed by:
executed 40 times by 1 test: return QSqlTableModel::select();Executed by:
| 40 | ||||||||||||||||||
| 137 | } | - | ||||||||||||||||||
| 138 | relation->clearDictionary(); | - | ||||||||||||||||||
| 139 | bool res = QSqlTableModel::select(); | - | ||||||||||||||||||
| 140 | if (res
| 0-1 | ||||||||||||||||||
| 141 | relation->populateDictionary(); executed 1 time by 1 test: relation->populateDictionary();Executed by:
| 1 | ||||||||||||||||||
| 142 | return executed 1 time by 1 test: res;return res;Executed by:
executed 1 time by 1 test: return res;Executed by:
| 1 | ||||||||||||||||||
| 143 | } | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | class QSqlRelationalTableModelPrivate: public QSqlTableModelPrivate | - | ||||||||||||||||||
| 147 | { | - | ||||||||||||||||||
| 148 | inline QSqlRelationalTableModel* q_func() { return static_cast<QSqlRelationalTableModel *>(q_ptr); } inline const QSqlRelationalTableModel* q_func() const { return static_cast<const QSqlRelationalTableModel *>(q_ptr); } friend class QSqlRelationalTableModel; | - | ||||||||||||||||||
| 149 | public: | - | ||||||||||||||||||
| 150 | QSqlRelationalTableModelPrivate() | - | ||||||||||||||||||
| 151 | : QSqlTableModelPrivate(), | - | ||||||||||||||||||
| 152 | joinMode( QSqlRelationalTableModel::InnerJoin ) | - | ||||||||||||||||||
| 153 | {} executed 31 times by 1 test: end of blockExecuted by:
| 31 | ||||||||||||||||||
| 154 | QString fullyQualifiedFieldName(const QString &tableName, const QString &fieldName) const; | - | ||||||||||||||||||
| 155 | - | |||||||||||||||||||
| 156 | int nameToIndex(const QString &name) const override; | - | ||||||||||||||||||
| 157 | mutable QVector<QRelation> relations; | - | ||||||||||||||||||
| 158 | QSqlRecord baseRec; | - | ||||||||||||||||||
| 159 | void clearChanges(); | - | ||||||||||||||||||
| 160 | void clearCache() override; | - | ||||||||||||||||||
| 161 | void revertCachedRow(int row) override; | - | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | void translateFieldNames(QSqlRecord &values) const; | - | ||||||||||||||||||
| 164 | QSqlRelationalTableModel::JoinMode joinMode; | - | ||||||||||||||||||
| 165 | }; | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | void QSqlRelationalTableModelPrivate::clearChanges() | - | ||||||||||||||||||
| 168 | { | - | ||||||||||||||||||
| 169 | for (int i = 0; i < relations.count()
| 4-32 | ||||||||||||||||||
| 170 | QRelation &rel = relations[i]; | - | ||||||||||||||||||
| 171 | rel.clear(); | - | ||||||||||||||||||
| 172 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 173 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | void QSqlRelationalTableModelPrivate::revertCachedRow(int row) | - | ||||||||||||||||||
| 176 | { | - | ||||||||||||||||||
| 177 | QSqlTableModelPrivate::revertCachedRow(row); | - | ||||||||||||||||||
| 178 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const | - | ||||||||||||||||||
| 181 | { | - | ||||||||||||||||||
| 182 | const QString fieldname = strippedFieldName(name); | - | ||||||||||||||||||
| 183 | int idx = baseRec.indexOf(fieldname); | - | ||||||||||||||||||
| 184 | if (idx == -1
| 1-16 | ||||||||||||||||||
| 185 | - | |||||||||||||||||||
| 186 | idx = QSqlTableModelPrivate::nameToIndex(name); | - | ||||||||||||||||||
| 187 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 188 | return executed 17 times by 1 test: idx;return idx;Executed by:
executed 17 times by 1 test: return idx;Executed by:
| 17 | ||||||||||||||||||
| 189 | } | - | ||||||||||||||||||
| 190 | - | |||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | void QSqlRelationalTableModelPrivate::clearCache() | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | for (int i = 0; i < relations.count()
| 74-211 | ||||||||||||||||||
| 197 | relations[i].clearDictionary(); executed 211 times by 1 test: relations[i].clearDictionary();Executed by:
| 211 | ||||||||||||||||||
| 198 | - | |||||||||||||||||||
| 199 | QSqlTableModelPrivate::clearCache(); | - | ||||||||||||||||||
| 200 | } executed 74 times by 1 test: end of blockExecuted by:
| 74 | ||||||||||||||||||
| 201 | QSqlRelationalTableModel::QSqlRelationalTableModel(QObject *parent, QSqlDatabase db) | - | ||||||||||||||||||
| 202 | : QSqlTableModel(*new QSqlRelationalTableModelPrivate, parent, db) | - | ||||||||||||||||||
| 203 | { | - | ||||||||||||||||||
| 204 | } executed 31 times by 1 test: end of blockExecuted by:
| 31 | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | QSqlRelationalTableModel::~QSqlRelationalTableModel() | - | ||||||||||||||||||
| 210 | { | - | ||||||||||||||||||
| 211 | } | - | ||||||||||||||||||
| 212 | - | |||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | QVariant QSqlRelationalTableModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||
| 217 | { | - | ||||||||||||||||||
| 218 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | if (role == Qt::DisplayRole
| 5-248 | ||||||||||||||||||
| 221 | d->relations.value(index.column()).isValid()
| 76-147 | ||||||||||||||||||
| 222 | QRelation &relation = d->relations[index.column()]; | - | ||||||||||||||||||
| 223 | if (!relation.isDictionaryInitialized()
| 54-93 | ||||||||||||||||||
| 224 | relation.populateDictionary(); executed 54 times by 1 test: relation.populateDictionary();Executed by:
| 54 | ||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | if (d->strategy != OnFieldChange
| 1-146 | ||||||||||||||||||
| 231 | const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); | - | ||||||||||||||||||
| 232 | if (row.op() != QSqlTableModelPrivate::None
| 29-86 | ||||||||||||||||||
| 233 | if (d->strategy == OnManualSubmit
| 0-16 | ||||||||||||||||||
| 234 | QVariant v = row.rec().value(index.column()); | - | ||||||||||||||||||
| 235 | if (v.isValid()
| 0-29 | ||||||||||||||||||
| 236 | return executed 29 times by 1 test: relation.dictionary[v.toString()];return relation.dictionary[v.toString()];Executed by:
executed 29 times by 1 test: return relation.dictionary[v.toString()];Executed by:
| 29 | ||||||||||||||||||
| 237 | } never executed: end of block | 0 | ||||||||||||||||||
| 238 | } never executed: end of block | 0 | ||||||||||||||||||
| 239 | } executed 117 times by 1 test: end of blockExecuted by:
| 117 | ||||||||||||||||||
| 240 | } executed 118 times by 1 test: end of blockExecuted by:
| 118 | ||||||||||||||||||
| 241 | return executed 307 times by 1 test: QSqlTableModel::data(index, role);return QSqlTableModel::data(index, role);Executed by:
executed 307 times by 1 test: return QSqlTableModel::data(index, role);Executed by:
| 307 | ||||||||||||||||||
| 242 | } | - | ||||||||||||||||||
| 243 | bool QSqlRelationalTableModel::setData(const QModelIndex &index, const QVariant &value, | - | ||||||||||||||||||
| 244 | int role) | - | ||||||||||||||||||
| 245 | { | - | ||||||||||||||||||
| 246 | QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 247 | if ( role == Qt::EditRole
| 0-85 | ||||||||||||||||||
| 248 | && d->relations.value(index.column()).isValid()
| 15-44 | ||||||||||||||||||
| 249 | QRelation &relation = d->relations[index.column()]; | - | ||||||||||||||||||
| 250 | if (!relation.isDictionaryInitialized()
| 11-33 | ||||||||||||||||||
| 251 | relation.populateDictionary(); executed 11 times by 1 test: relation.populateDictionary();Executed by:
| 11 | ||||||||||||||||||
| 252 | if (!relation.dictionary.contains(value.toString())
| 2-42 | ||||||||||||||||||
| 253 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 254 | } executed 42 times by 1 test: end of blockExecuted by:
| 42 | ||||||||||||||||||
| 255 | return executed 83 times by 1 test: QSqlTableModel::setData(index, value, role);return QSqlTableModel::setData(index, value, role);Executed by:
executed 83 times by 1 test: return QSqlTableModel::setData(index, value, role);Executed by:
| 83 | ||||||||||||||||||
| 256 | } | - | ||||||||||||||||||
| 257 | void QSqlRelationalTableModel::setRelation(int column, const QSqlRelation &relation) | - | ||||||||||||||||||
| 258 | { | - | ||||||||||||||||||
| 259 | QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 260 | if (column < 0
| 0-44 | ||||||||||||||||||
| 261 | return; never executed: return; | 0 | ||||||||||||||||||
| 262 | if (d->relations.size() <= column
| 3-41 | ||||||||||||||||||
| 263 | d->relations.resize(column + 1); executed 41 times by 1 test: d->relations.resize(column + 1);Executed by:
| 41 | ||||||||||||||||||
| 264 | d->relations[column].init(this, relation); | - | ||||||||||||||||||
| 265 | } executed 44 times by 1 test: end of blockExecuted by:
| 44 | ||||||||||||||||||
| 266 | - | |||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | QSqlRelation QSqlRelationalTableModel::relation(int column) const | - | ||||||||||||||||||
| 274 | { | - | ||||||||||||||||||
| 275 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 276 | return never executed: d->relations.value(column).rel;return d->relations.value(column).rel;never executed: return d->relations.value(column).rel; | 0 | ||||||||||||||||||
| 277 | } | - | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | QString QSqlRelationalTableModelPrivate::fullyQualifiedFieldName(const QString &tableName, | - | ||||||||||||||||||
| 280 | const QString &fieldName) const | - | ||||||||||||||||||
| 281 | { | - | ||||||||||||||||||
| 282 | QString ret; | - | ||||||||||||||||||
| 283 | ret.reserve(tableName.size() + fieldName.size() + 1); | - | ||||||||||||||||||
| 284 | ret.append(tableName).append(QLatin1Char('.')).append(fieldName); | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | return executed 512 times by 1 test: ret;return ret;Executed by:
executed 512 times by 1 test: return ret;Executed by:
| 512 | ||||||||||||||||||
| 287 | } | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | - | |||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | - | |||||||||||||||||||
| 292 | QString QSqlRelationalTableModel::selectStatement() const | - | ||||||||||||||||||
| 293 | { | - | ||||||||||||||||||
| 294 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 295 | - | |||||||||||||||||||
| 296 | if (tableName().isEmpty()
| 0-89 | ||||||||||||||||||
| 297 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 298 | if (d->relations.isEmpty()
| 5-84 | ||||||||||||||||||
| 299 | return executed 5 times by 1 test: QSqlTableModel::selectStatement();return QSqlTableModel::selectStatement();Executed by:
executed 5 times by 1 test: return QSqlTableModel::selectStatement();Executed by:
| 5 | ||||||||||||||||||
| 300 | - | |||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | QHash<QString, int> fieldNames; | - | ||||||||||||||||||
| 303 | QStringList fieldList; | - | ||||||||||||||||||
| 304 | for (int i = 0; i < d->baseRec.count()
| 84-302 | ||||||||||||||||||
| 305 | QSqlRelation relation = d->relations.value(i).rel; | - | ||||||||||||||||||
| 306 | QString name; | - | ||||||||||||||||||
| 307 | if (relation.isValid()
| 103-199 | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | name = relation.displayColumn(); | - | ||||||||||||||||||
| 310 | if (d->db.driver()->isIdentifierEscaped(name, QSqlDriver::FieldName)
| 10-93 | ||||||||||||||||||
| 311 | name = d->db.driver()->stripDelimiters(name, QSqlDriver::FieldName); executed 10 times by 1 test: name = d->db.driver()->stripDelimiters(name, QSqlDriver::FieldName);Executed by:
| 10 | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | const QSqlRecord rec = database().record(relation.tableName()); | - | ||||||||||||||||||
| 314 | for (int i = 0; i < rec.count()
| 0-206 | ||||||||||||||||||
| 315 | if (name.compare(rec.fieldName(i), Qt::CaseInsensitive) == 0
| 103 | ||||||||||||||||||
| 316 | name = rec.fieldName(i); | - | ||||||||||||||||||
| 317 | break; executed 103 times by 1 test: break;Executed by:
| 103 | ||||||||||||||||||
| 318 | } | - | ||||||||||||||||||
| 319 | } executed 103 times by 1 test: end of blockExecuted by:
| 103 | ||||||||||||||||||
| 320 | } executed 103 times by 1 test: end of blockExecuted by:
| 103 | ||||||||||||||||||
| 321 | else { | - | ||||||||||||||||||
| 322 | name = d->baseRec.fieldName(i); | - | ||||||||||||||||||
| 323 | } executed 199 times by 1 test: end of blockExecuted by:
| 199 | ||||||||||||||||||
| 324 | fieldNames[name] = fieldNames.value(name, 0) + 1; | - | ||||||||||||||||||
| 325 | fieldList.append(name); | - | ||||||||||||||||||
| 326 | } executed 302 times by 1 test: end of blockExecuted by:
| 302 | ||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | QString fList; | - | ||||||||||||||||||
| 329 | QString conditions; | - | ||||||||||||||||||
| 330 | QString from = Sql::from(tableName()); | - | ||||||||||||||||||
| 331 | for (int i = 0; i < d->baseRec.count()
| 84-302 | ||||||||||||||||||
| 332 | QSqlRelation relation = d->relations.value(i).rel; | - | ||||||||||||||||||
| 333 | const QString tableField = d->fullyQualifiedFieldName(tableName(), d->db.driver()->escapeIdentifier(d->baseRec.fieldName(i), QSqlDriver::FieldName)); | - | ||||||||||||||||||
| 334 | if (relation.isValid()
| 103-199 | ||||||||||||||||||
| 335 | const QString relTableAlias = Sql::relTablePrefix(i); | - | ||||||||||||||||||
| 336 | QString displayTableField = d->fullyQualifiedFieldName(relTableAlias, relation.displayColumn()); | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | - | |||||||||||||||||||
| 339 | if (fieldNames.value(fieldList[i]) > 1
| 23-80 | ||||||||||||||||||
| 340 | QString relTableName = relation.tableName().section(QChar::fromLatin1('.'), -1, -1); | - | ||||||||||||||||||
| 341 | if (d->db.driver()->isIdentifierEscaped(relTableName, QSqlDriver::TableName)
| 0-23 | ||||||||||||||||||
| 342 | relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName); never executed: relTableName = d->db.driver()->stripDelimiters(relTableName, QSqlDriver::TableName); | 0 | ||||||||||||||||||
| 343 | QString displayColumn = relation.displayColumn(); | - | ||||||||||||||||||
| 344 | if (d->db.driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName)
| 0-23 | ||||||||||||||||||
| 345 | displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); never executed: displayColumn = d->db.driver()->stripDelimiters(displayColumn, QSqlDriver::FieldName); | 0 | ||||||||||||||||||
| 346 | const QString alias = QString::fromLatin1("%1_%2_%3").arg(relTableName).arg(displayColumn).arg(fieldNames.value(fieldList[i])); | - | ||||||||||||||||||
| 347 | displayTableField = Sql::as(displayTableField, alias); | - | ||||||||||||||||||
| 348 | --fieldNames[fieldList[i]]; | - | ||||||||||||||||||
| 349 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 350 | - | |||||||||||||||||||
| 351 | fList = Sql::comma(fList, displayTableField); | - | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | const QString tblexpr = Sql::concat(relation.tableName(), relTableAlias); | - | ||||||||||||||||||
| 355 | const QString relTableField = d->fullyQualifiedFieldName(relTableAlias, relation.indexColumn()); | - | ||||||||||||||||||
| 356 | const QString cond = Sql::eq(tableField, relTableField); | - | ||||||||||||||||||
| 357 | if (d->joinMode == QSqlRelationalTableModel::InnerJoin
| 30-73 | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | from = Sql::comma(from, tblexpr); | - | ||||||||||||||||||
| 361 | conditions = Sql::et(conditions, cond); | - | ||||||||||||||||||
| 362 | } executed 73 times by 1 test: else {end of blockExecuted by:
| 73 | ||||||||||||||||||
| 363 | from = Sql::concat(from, Sql::leftJoin(tblexpr)); | - | ||||||||||||||||||
| 364 | from = Sql::concat(from, Sql::on(cond)); | - | ||||||||||||||||||
| 365 | } executed 30 times by 1 test: end of blockExecuted by:
| 30 | ||||||||||||||||||
| 366 | } else { | - | ||||||||||||||||||
| 367 | fList = Sql::comma(fList, tableField); | - | ||||||||||||||||||
| 368 | } executed 199 times by 1 test: end of blockExecuted by:
| 199 | ||||||||||||||||||
| 369 | } | - | ||||||||||||||||||
| 370 | - | |||||||||||||||||||
| 371 | if (fList.isEmpty()
| 0-84 | ||||||||||||||||||
| 372 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | const QString stmt = Sql::concat(Sql::select(fList), from); | - | ||||||||||||||||||
| 375 | const QString where = Sql::where(Sql::et(Sql::paren(conditions), Sql::paren(filter()))); | - | ||||||||||||||||||
| 376 | return executed 84 times by 1 test: Sql::concat(Sql::concat(stmt, where), orderByClause());return Sql::concat(Sql::concat(stmt, where), orderByClause());Executed by:
executed 84 times by 1 test: return Sql::concat(Sql::concat(stmt, where), orderByClause());Executed by:
| 84 | ||||||||||||||||||
| 377 | } | - | ||||||||||||||||||
| 378 | QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const | - | ||||||||||||||||||
| 379 | { | - | ||||||||||||||||||
| 380 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 381 | if ( column < 0
| 0-20 | ||||||||||||||||||
| 382 | return executed 4 times by 1 test: 0;return 0;Executed by:
executed 4 times by 1 test: return 0;Executed by:
| 4 | ||||||||||||||||||
| 383 | - | |||||||||||||||||||
| 384 | QRelation &relation = const_cast<QSqlRelationalTableModelPrivate *>(d)->relations[column]; | - | ||||||||||||||||||
| 385 | if (!relation.isValid()
| 6-10 | ||||||||||||||||||
| 386 | return executed 6 times by 1 test: 0;return 0;Executed by:
executed 6 times by 1 test: return 0;Executed by:
| 6 | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | if (!relation.model
| 3-7 | ||||||||||||||||||
| 389 | relation.populateModel(); executed 3 times by 1 test: relation.populateModel();Executed by:
| 3 | ||||||||||||||||||
| 390 | return executed 10 times by 1 test: relation.model;return relation.model;Executed by:
executed 10 times by 1 test: return relation.model;Executed by:
| 10 | ||||||||||||||||||
| 391 | } | - | ||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | void QSqlRelationalTableModel::revertRow(int row) | - | ||||||||||||||||||
| 397 | { | - | ||||||||||||||||||
| 398 | QSqlTableModel::revertRow(row); | - | ||||||||||||||||||
| 399 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | - | |||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | void QSqlRelationalTableModel::clear() | - | ||||||||||||||||||
| 405 | { | - | ||||||||||||||||||
| 406 | QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 407 | beginResetModel(); | - | ||||||||||||||||||
| 408 | d->clearChanges(); | - | ||||||||||||||||||
| 409 | d->relations.clear(); | - | ||||||||||||||||||
| 410 | QSqlTableModel::clear(); | - | ||||||||||||||||||
| 411 | endResetModel(); | - | ||||||||||||||||||
| 412 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 413 | void QSqlRelationalTableModel::setJoinMode( QSqlRelationalTableModel::JoinMode joinMode ) | - | ||||||||||||||||||
| 414 | { | - | ||||||||||||||||||
| 415 | QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 416 | d->joinMode = joinMode; | - | ||||||||||||||||||
| 417 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | - | |||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | bool QSqlRelationalTableModel::select() | - | ||||||||||||||||||
| 422 | { | - | ||||||||||||||||||
| 423 | return executed 74 times by 1 test: QSqlTableModel::select();return QSqlTableModel::select();Executed by:
executed 74 times by 1 test: return QSqlTableModel::select();Executed by:
| 74 | ||||||||||||||||||
| 424 | } | - | ||||||||||||||||||
| 425 | - | |||||||||||||||||||
| 426 | - | |||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | - | |||||||||||||||||||
| 429 | void QSqlRelationalTableModel::setTable(const QString &table) | - | ||||||||||||||||||
| 430 | { | - | ||||||||||||||||||
| 431 | QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | - | |||||||||||||||||||
| 434 | d->baseRec = d->db.record(table); | - | ||||||||||||||||||
| 435 | - | |||||||||||||||||||
| 436 | QSqlTableModel::setTable(table); | - | ||||||||||||||||||
| 437 | } executed 32 times by 1 test: end of blockExecuted by:
| 32 | ||||||||||||||||||
| 438 | - | |||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | - | |||||||||||||||||||
| 441 | void QSqlRelationalTableModelPrivate::translateFieldNames(QSqlRecord &values) const | - | ||||||||||||||||||
| 442 | { | - | ||||||||||||||||||
| 443 | for (int i = 0; i < values.count()
| 26-93 | ||||||||||||||||||
| 444 | if (relations.value(i).isValid()
| 34-59 | ||||||||||||||||||
| 445 | QVariant v = values.value(i); | - | ||||||||||||||||||
| 446 | bool gen = values.isGenerated(i); | - | ||||||||||||||||||
| 447 | values.replace(i, baseRec.field(i)); | - | ||||||||||||||||||
| 448 | values.setValue(i, v); | - | ||||||||||||||||||
| 449 | values.setGenerated(i, gen); | - | ||||||||||||||||||
| 450 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 451 | } executed 93 times by 1 test: end of blockExecuted by:
| 93 | ||||||||||||||||||
| 452 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 453 | - | |||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | - | |||||||||||||||||||
| 456 | - | |||||||||||||||||||
| 457 | bool QSqlRelationalTableModel::updateRowInTable(int row, const QSqlRecord &values) | - | ||||||||||||||||||
| 458 | { | - | ||||||||||||||||||
| 459 | QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | QSqlRecord rec = values; | - | ||||||||||||||||||
| 462 | d->translateFieldNames(rec); | - | ||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | return executed 19 times by 1 test: QSqlTableModel::updateRowInTable(row, rec);return QSqlTableModel::updateRowInTable(row, rec);Executed by:
executed 19 times by 1 test: return QSqlTableModel::updateRowInTable(row, rec);Executed by:
| 19 | ||||||||||||||||||
| 465 | } | - | ||||||||||||||||||
| 466 | - | |||||||||||||||||||
| 467 | - | |||||||||||||||||||
| 468 | - | |||||||||||||||||||
| 469 | - | |||||||||||||||||||
| 470 | bool QSqlRelationalTableModel::insertRowIntoTable(const QSqlRecord &values) | - | ||||||||||||||||||
| 471 | { | - | ||||||||||||||||||
| 472 | QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 473 | - | |||||||||||||||||||
| 474 | QSqlRecord rec = values; | - | ||||||||||||||||||
| 475 | d->translateFieldNames(rec); | - | ||||||||||||||||||
| 476 | - | |||||||||||||||||||
| 477 | return executed 7 times by 1 test: QSqlTableModel::insertRowIntoTable(rec);return QSqlTableModel::insertRowIntoTable(rec);Executed by:
executed 7 times by 1 test: return QSqlTableModel::insertRowIntoTable(rec);Executed by:
| 7 | ||||||||||||||||||
| 478 | } | - | ||||||||||||||||||
| 479 | - | |||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | - | |||||||||||||||||||
| 483 | QString QSqlRelationalTableModel::orderByClause() const | - | ||||||||||||||||||
| 484 | { | - | ||||||||||||||||||
| 485 | const QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 486 | - | |||||||||||||||||||
| 487 | const QSqlRelation rel = d->relations.value(d->sortColumn).rel; | - | ||||||||||||||||||
| 488 | if (!rel.isValid()
| 4-85 | ||||||||||||||||||
| 489 | return executed 85 times by 1 test: QSqlTableModel::orderByClause();return QSqlTableModel::orderByClause();Executed by:
executed 85 times by 1 test: return QSqlTableModel::orderByClause();Executed by:
| 85 | ||||||||||||||||||
| 490 | - | |||||||||||||||||||
| 491 | QString f = d->fullyQualifiedFieldName(Sql::relTablePrefix(d->sortColumn), rel.displayColumn()); | - | ||||||||||||||||||
| 492 | f = d->sortOrder == Qt::AscendingOrder
| 2 | ||||||||||||||||||
| 493 | return executed 4 times by 1 test: Sql::orderBy(f);return Sql::orderBy(f);Executed by:
executed 4 times by 1 test: return Sql::orderBy(f);Executed by:
| 4 | ||||||||||||||||||
| 494 | } | - | ||||||||||||||||||
| 495 | - | |||||||||||||||||||
| 496 | - | |||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | - | |||||||||||||||||||
| 499 | bool QSqlRelationalTableModel::removeColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||
| 500 | { | - | ||||||||||||||||||
| 501 | QSqlRelationalTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||
| 502 | - | |||||||||||||||||||
| 503 | if (parent.isValid()
| 0-4 | ||||||||||||||||||
| 504 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||
| 505 | - | |||||||||||||||||||
| 506 | for (int i = 0; i < count
| 4-6 | ||||||||||||||||||
| 507 | d->baseRec.remove(column); | - | ||||||||||||||||||
| 508 | if (d->relations.count() > column
| 2-4 | ||||||||||||||||||
| 509 | d->relations.remove(column); executed 4 times by 1 test: d->relations.remove(column);Executed by:
| 4 | ||||||||||||||||||
| 510 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 511 | return executed 4 times by 1 test: QSqlTableModel::removeColumns(column, count, parent);return QSqlTableModel::removeColumns(column, count, parent);Executed by:
executed 4 times by 1 test: return QSqlTableModel::removeColumns(column, count, parent);Executed by:
| 4 | ||||||||||||||||||
| 512 | } | - | ||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |