qsqlrelationaltablemodel.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/sql/models/qsqlrelationaltablemodel.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7class QSqlRelationalTableModelSql: public QSqlTableModelSql-
8{-
9public:-
10 inline const static QString relTablePrefix(int i) { return
executed 107 times by 1 test: return QString::number(i).prepend(QLatin1String("relTblAl_"));
Executed by:
  • tst_QSqlRelationalTableModel
QString::number(i).prepend(QLatin1String("relTblAl_"));
executed 107 times by 1 test: return QString::number(i).prepend(QLatin1String("relTblAl_"));
Executed by:
  • tst_QSqlRelationalTableModel
}
107
11};-
12-
13typedef QSqlRelationalTableModelSql Sql;-
14class QRelatedTableModel;-
15-
16struct QRelation-
17{-
18 public:-
19 QRelation(): model(0), m_parent(0), m_dictInitialized(false) {}
executed 266 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
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-
40class QRelatedTableModel : public QSqlTableModel-
41{-
42public:-
43 QRelatedTableModel(QRelation *rel, QObject *parent = 0, QSqlDatabase db = QSqlDatabase());-
44 bool select() override;-
45private:-
46 bool firstSelect;-
47 QRelation *relation;-
48};-
49-
50-
51-
52-
53-
54void 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 block
Executed by:
  • tst_QSqlRelationalTableModel
44
60-
61void QRelation::populateModel()-
62{-
63 if (!isValid()
!isValid()Description
TRUEnever evaluated
FALSEevaluated 40 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
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
!modelDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEnever evaluated
) {
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 block
Executed by:
  • tst_QSqlRelationalTableModel
40
72}
executed 40 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
40
73-
74bool QRelation::isDictionaryInitialized()-
75{-
76 return
executed 191 times by 1 test: return m_dictInitialized;
Executed by:
  • tst_QSqlRelationalTableModel
m_dictInitialized;
executed 191 times by 1 test: return m_dictInitialized;
Executed by:
  • tst_QSqlRelationalTableModel
191
77}-
78-
79void QRelation::populateDictionary()-
80{-
81 if (!isValid()
!isValid()Description
TRUEnever evaluated
FALSEevaluated 66 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
0-66
82 return;
never executed: return;
0
83-
84 if (model == __null
model == __nullDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 29 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
29-37
85 populateModel();
executed 37 times by 1 test: populateModel();
Executed by:
  • tst_QSqlRelationalTableModel
37
86-
87 QSqlRecord record;-
88 QString indexColumn;-
89 QString displayColumn;-
90 for (int i=0; i < model->rowCount()
i < model->rowCount()Description
TRUEevaluated 136 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 66 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
; ++i) {
66-136
91 record = model->record(i);-
92-
93 indexColumn = rel.indexColumn();-
94 if (m_parent->database().driver()->isIdentifierEscaped(indexColumn, QSqlDriver::FieldName)
m_parent->data...er::FieldName)Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 122 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
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:
  • tst_QSqlRelationalTableModel
14
96-
97 displayColumn = rel.displayColumn();-
98 if (m_parent->database().driver()->isIdentifierEscaped(displayColumn, QSqlDriver::FieldName)
m_parent->data...er::FieldName)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 118 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
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:
  • tst_QSqlRelationalTableModel
18
100-
101 dictionary[record.field(indexColumn).value().toString()] =-
102 record.field(displayColumn).value();-
103 }
executed 136 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
136
104 m_dictInitialized = true;-
105}
executed 66 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
66
106-
107void QRelation::clearDictionary()-
108{-
109 dictionary.clear();-
110 m_dictInitialized = false;-
111}
executed 216 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
216
112-
113void QRelation::clear()-
114{-
115 delete model;-
116 model = 0;-
117 clearDictionary();-
118}
executed 4 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
4
119-
120bool QRelation::isValid()-
121{-
122 return
executed 497 times by 1 test: return (rel.isValid() && m_parent != __null);
Executed by:
  • tst_QSqlRelationalTableModel
(rel.isValid() && m_parent != __null);
executed 497 times by 1 test: return (rel.isValid() && m_parent != __null);
Executed by:
  • tst_QSqlRelationalTableModel
497
123}-
124-
125-
126-
127QRelatedTableModel::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 block
Executed by:
  • tst_QSqlRelationalTableModel
40
131-
132bool QRelatedTableModel::select()-
133{-
134 if (firstSelect
firstSelectDescription
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
1-40
135 firstSelect = false;-
136 return
executed 40 times by 1 test: return QSqlTableModel::select();
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::select();
executed 40 times by 1 test: return QSqlTableModel::select();
Executed by:
  • tst_QSqlRelationalTableModel
40
137 }-
138 relation->clearDictionary();-
139 bool res = QSqlTableModel::select();-
140 if (res
resDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEnever evaluated
)
0-1
141 relation->populateDictionary();
executed 1 time by 1 test: relation->populateDictionary();
Executed by:
  • tst_QSqlRelationalTableModel
1
142 return
executed 1 time by 1 test: return res;
Executed by:
  • tst_QSqlRelationalTableModel
res;
executed 1 time by 1 test: return res;
Executed by:
  • tst_QSqlRelationalTableModel
1
143}-
144-
145-
146class 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;-
149public:-
150 QSqlRelationalTableModelPrivate()-
151 : QSqlTableModelPrivate(),-
152 joinMode( QSqlRelationalTableModel::InnerJoin )-
153 {}
executed 31 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
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-
167void QSqlRelationalTableModelPrivate::clearChanges()-
168{-
169 for (int i = 0; i < relations.count()
i < relations.count()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 32 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
; ++i) {
4-32
170 QRelation &rel = relations[i];-
171 rel.clear();-
172 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
4
173}
executed 32 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
32
174-
175void QSqlRelationalTableModelPrivate::revertCachedRow(int row)-
176{-
177 QSqlTableModelPrivate::revertCachedRow(row);-
178}
executed 19 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
19
179-
180int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const-
181{-
182 const QString fieldname = strippedFieldName(name);-
183 int idx = baseRec.indexOf(fieldname);-
184 if (idx == -1
idx == -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
1-16
185-
186 idx = QSqlTableModelPrivate::nameToIndex(name);-
187 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
1
188 return
executed 17 times by 1 test: return idx;
Executed by:
  • tst_QSqlRelationalTableModel
idx;
executed 17 times by 1 test: return idx;
Executed by:
  • tst_QSqlRelationalTableModel
17
189}-
190-
191-
192-
193-
194void QSqlRelationalTableModelPrivate::clearCache()-
195{-
196 for (int i = 0; i < relations.count()
i < relations.count()Description
TRUEevaluated 211 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 74 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
; ++i)
74-211
197 relations[i].clearDictionary();
executed 211 times by 1 test: relations[i].clearDictionary();
Executed by:
  • tst_QSqlRelationalTableModel
211
198-
199 QSqlTableModelPrivate::clearCache();-
200}
executed 74 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
74
201QSqlRelationalTableModel::QSqlRelationalTableModel(QObject *parent, QSqlDatabase db)-
202 : QSqlTableModel(*new QSqlRelationalTableModelPrivate, parent, db)-
203{-
204}
executed 31 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
31
205-
206-
207-
208-
209QSqlRelationalTableModel::~QSqlRelationalTableModel()-
210{-
211}-
212-
213-
214-
215-
216QVariant QSqlRelationalTableModel::data(const QModelIndex &index, int role) const-
217{-
218 const QSqlRelationalTableModelPrivate * const d = d_func();-
219-
220 if (role == Qt::DisplayRole
role == Qt::DisplayRoleDescription
TRUEevaluated 248 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 88 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
&& index.column() >= 0
index.column() >= 0Description
TRUEevaluated 243 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 5 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
&& index.column() < d->relations.count()
index.column()...ations.count()Description
TRUEevaluated 223 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 20 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
&&
5-248
221 d->relations.value(index.column()).isValid()
d->relations.v...n()).isValid()Description
TRUEevaluated 147 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 76 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
76-147
222 QRelation &relation = d->relations[index.column()];-
223 if (!relation.isDictionaryInitialized()
!relation.isDi...yInitialized()Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 93 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
54-93
224 relation.populateDictionary();
executed 54 times by 1 test: relation.populateDictionary();
Executed by:
  • tst_QSqlRelationalTableModel
54
225-
226-
227-
228-
229-
230 if (d->strategy != OnFieldChange
d->strategy != OnFieldChangeDescription
TRUEevaluated 146 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
1-146
231 const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row());-
232 if (row.op() != QSqlTableModelPrivate::None
row.op() != QS...lPrivate::NoneDescription
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 86 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
&& row.rec().isGenerated(index.column())
row.rec().isGe...ndex.column())Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 31 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
29-86
233 if (d->strategy == OnManualSubmit
d->strategy == OnManualSubmitDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 13 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
|| row.op() != QSqlTableModelPrivate::Delete
row.op() != QS...rivate::DeleteDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEnever evaluated
) {
0-16
234 QVariant v = row.rec().value(index.column());-
235 if (v.isValid()
v.isValid()Description
TRUEevaluated 29 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEnever evaluated
)
0-29
236 return
executed 29 times by 1 test: return relation.dictionary[v.toString()];
Executed by:
  • tst_QSqlRelationalTableModel
relation.dictionary[v.toString()];
executed 29 times by 1 test: return relation.dictionary[v.toString()];
Executed by:
  • tst_QSqlRelationalTableModel
29
237 }
never executed: end of block
0
238 }
never executed: end of block
0
239 }
executed 117 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
117
240 }
executed 118 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
118
241 return
executed 307 times by 1 test: return QSqlTableModel::data(index, role);
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::data(index, role);
executed 307 times by 1 test: return QSqlTableModel::data(index, role);
Executed by:
  • tst_QSqlRelationalTableModel
307
242}-
243bool QSqlRelationalTableModel::setData(const QModelIndex &index, const QVariant &value,-
244 int role)-
245{-
246 QSqlRelationalTableModelPrivate * const d = d_func();-
247 if ( role == Qt::EditRole
role == Qt::EditRoleDescription
TRUEevaluated 85 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEnever evaluated
&& index.column() > 0
index.column() > 0Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 22 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
&& index.column() < d->relations.count()
index.column()...ations.count()Description
TRUEevaluated 59 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
0-85
248 && d->relations.value(index.column()).isValid()
d->relations.v...n()).isValid()Description
TRUEevaluated 44 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 15 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
15-44
249 QRelation &relation = d->relations[index.column()];-
250 if (!relation.isDictionaryInitialized()
!relation.isDi...yInitialized()Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 33 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
11-33
251 relation.populateDictionary();
executed 11 times by 1 test: relation.populateDictionary();
Executed by:
  • tst_QSqlRelationalTableModel
11
252 if (!relation.dictionary.contains(value.toString())
!relation.dict...ue.toString())Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 42 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
2-42
253 return
executed 2 times by 1 test: return false;
Executed by:
  • tst_QSqlRelationalTableModel
false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QSqlRelationalTableModel
2
254 }
executed 42 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
42
255 return
executed 83 times by 1 test: return QSqlTableModel::setData(index, value, role);
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::setData(index, value, role);
executed 83 times by 1 test: return QSqlTableModel::setData(index, value, role);
Executed by:
  • tst_QSqlRelationalTableModel
83
256}-
257void QSqlRelationalTableModel::setRelation(int column, const QSqlRelation &relation)-
258{-
259 QSqlRelationalTableModelPrivate * const d = d_func();-
260 if (column < 0
column < 0Description
TRUEnever evaluated
FALSEevaluated 44 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
0-44
261 return;
never executed: return;
0
262 if (d->relations.size() <= column
d->relations.size() <= columnDescription
TRUEevaluated 41 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
3-41
263 d->relations.resize(column + 1);
executed 41 times by 1 test: d->relations.resize(column + 1);
Executed by:
  • tst_QSqlRelationalTableModel
41
264 d->relations[column].init(this, relation);-
265}
executed 44 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
44
266-
267-
268-
269-
270-
271-
272-
273QSqlRelation QSqlRelationalTableModel::relation(int column) const-
274{-
275 const QSqlRelationalTableModelPrivate * const d = d_func();-
276 return
never executed: return d->relations.value(column).rel;
d->relations.value(column).rel;
never executed: return d->relations.value(column).rel;
0
277}-
278-
279QString 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: return ret;
Executed by:
  • tst_QSqlRelationalTableModel
ret;
executed 512 times by 1 test: return ret;
Executed by:
  • tst_QSqlRelationalTableModel
512
287}-
288-
289-
290-
291-
292QString QSqlRelationalTableModel::selectStatement() const-
293{-
294 const QSqlRelationalTableModelPrivate * const d = d_func();-
295-
296 if (tableName().isEmpty()
tableName().isEmpty()Description
TRUEnever evaluated
FALSEevaluated 89 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
0-89
297 return
never executed: return QString();
QString();
never executed: return QString();
0
298 if (d->relations.isEmpty()
d->relations.isEmpty()Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 84 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
5-84
299 return
executed 5 times by 1 test: return QSqlTableModel::selectStatement();
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::selectStatement();
executed 5 times by 1 test: return QSqlTableModel::selectStatement();
Executed by:
  • tst_QSqlRelationalTableModel
5
300-
301-
302 QHash<QString, int> fieldNames;-
303 QStringList fieldList;-
304 for (int i = 0; i < d->baseRec.count()
i < d->baseRec.count()Description
TRUEevaluated 302 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 84 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
; ++i) {
84-302
305 QSqlRelation relation = d->relations.value(i).rel;-
306 QString name;-
307 if (relation.isValid()
relation.isValid()Description
TRUEevaluated 103 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 199 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
103-199
308-
309 name = relation.displayColumn();-
310 if (d->db.driver()->isIdentifierEscaped(name, QSqlDriver::FieldName)
d->db.driver()...er::FieldName)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 93 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
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:
  • tst_QSqlRelationalTableModel
10
312-
313 const QSqlRecord rec = database().record(relation.tableName());-
314 for (int i = 0; i < rec.count()
i < rec.count()Description
TRUEevaluated 206 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEnever evaluated
; ++i) {
0-206
315 if (name.compare(rec.fieldName(i), Qt::CaseInsensitive) == 0
name.compare(r...ensitive) == 0Description
TRUEevaluated 103 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 103 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
103
316 name = rec.fieldName(i);-
317 break;
executed 103 times by 1 test: break;
Executed by:
  • tst_QSqlRelationalTableModel
103
318 }-
319 }
executed 103 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
103
320 }
executed 103 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
103
321 else {-
322 name = d->baseRec.fieldName(i);-
323 }
executed 199 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
199
324 fieldNames[name] = fieldNames.value(name, 0) + 1;-
325 fieldList.append(name);-
326 }
executed 302 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
302
327-
328 QString fList;-
329 QString conditions;-
330 QString from = Sql::from(tableName());-
331 for (int i = 0; i < d->baseRec.count()
i < d->baseRec.count()Description
TRUEevaluated 302 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 84 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
; ++i) {
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()
relation.isValid()Description
TRUEevaluated 103 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 199 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
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
fieldNames.val...ldList[i]) > 1Description
TRUEevaluated 23 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 80 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
23-80
340 QString relTableName = relation.tableName().section(QChar::fromLatin1('.'), -1, -1);-
341 if (d->db.driver()->isIdentifierEscaped(relTableName, QSqlDriver::TableName)
d->db.driver()...er::TableName)Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
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)
d->db.driver()...er::FieldName)Description
TRUEnever evaluated
FALSEevaluated 23 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
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 block
Executed by:
  • tst_QSqlRelationalTableModel
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
d->joinMode ==...del::InnerJoinDescription
TRUEevaluated 73 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 30 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
30-73
358-
359-
360 from = Sql::comma(from, tblexpr);-
361 conditions = Sql::et(conditions, cond);-
362 }
executed 73 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
else {
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 block
Executed by:
  • tst_QSqlRelationalTableModel
30
366 } else {-
367 fList = Sql::comma(fList, tableField);-
368 }
executed 199 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
199
369 }-
370-
371 if (fList.isEmpty()
fList.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 84 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
0-84
372 return
never executed: return QString();
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: return Sql::concat(Sql::concat(stmt, where), orderByClause());
Executed by:
  • tst_QSqlRelationalTableModel
Sql::concat(Sql::concat(stmt, where), orderByClause());
executed 84 times by 1 test: return Sql::concat(Sql::concat(stmt, where), orderByClause());
Executed by:
  • tst_QSqlRelationalTableModel
84
377}-
378QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const-
379{-
380 const QSqlRelationalTableModelPrivate * const d = d_func();-
381 if ( column < 0
column < 0Description
TRUEnever evaluated
FALSEevaluated 20 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
|| column >= d->relations.count()
column >= d->relations.count()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
0-20
382 return
executed 4 times by 1 test: return 0;
Executed by:
  • tst_QSqlRelationalTableModel
0;
executed 4 times by 1 test: return 0;
Executed by:
  • tst_QSqlRelationalTableModel
4
383-
384 QRelation &relation = const_cast<QSqlRelationalTableModelPrivate *>(d)->relations[column];-
385 if (!relation.isValid()
!relation.isValid()Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
6-10
386 return
executed 6 times by 1 test: return 0;
Executed by:
  • tst_QSqlRelationalTableModel
0;
executed 6 times by 1 test: return 0;
Executed by:
  • tst_QSqlRelationalTableModel
6
387-
388 if (!relation.model
!relation.modelDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
3-7
389 relation.populateModel();
executed 3 times by 1 test: relation.populateModel();
Executed by:
  • tst_QSqlRelationalTableModel
3
390 return
executed 10 times by 1 test: return relation.model;
Executed by:
  • tst_QSqlRelationalTableModel
relation.model;
executed 10 times by 1 test: return relation.model;
Executed by:
  • tst_QSqlRelationalTableModel
10
391}-
392-
393-
394-
395-
396void QSqlRelationalTableModel::revertRow(int row)-
397{-
398 QSqlTableModel::revertRow(row);-
399}
executed 19 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
19
400-
401-
402-
403-
404void 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 block
Executed by:
  • tst_QSqlRelationalTableModel
32
413void 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 block
Executed by:
  • tst_QSqlRelationalTableModel
23
418-
419-
420-
421bool QSqlRelationalTableModel::select()-
422{-
423 return
executed 74 times by 1 test: return QSqlTableModel::select();
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::select();
executed 74 times by 1 test: return QSqlTableModel::select();
Executed by:
  • tst_QSqlRelationalTableModel
74
424}-
425-
426-
427-
428-
429void 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 block
Executed by:
  • tst_QSqlRelationalTableModel
32
438-
439-
440-
441void QSqlRelationalTableModelPrivate::translateFieldNames(QSqlRecord &values) const-
442{-
443 for (int i = 0; i < values.count()
i < values.count()Description
TRUEevaluated 93 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 26 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
; ++i) {
26-93
444 if (relations.value(i).isValid()
relations.value(i).isValid()Description
TRUEevaluated 34 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 59 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
) {
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 block
Executed by:
  • tst_QSqlRelationalTableModel
34
451 }
executed 93 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
93
452}
executed 26 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
26
453-
454-
455-
456-
457bool 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: return QSqlTableModel::updateRowInTable(row, rec);
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::updateRowInTable(row, rec);
executed 19 times by 1 test: return QSqlTableModel::updateRowInTable(row, rec);
Executed by:
  • tst_QSqlRelationalTableModel
19
465}-
466-
467-
468-
469-
470bool 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: return QSqlTableModel::insertRowIntoTable(rec);
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::insertRowIntoTable(rec);
executed 7 times by 1 test: return QSqlTableModel::insertRowIntoTable(rec);
Executed by:
  • tst_QSqlRelationalTableModel
7
478}-
479-
480-
481-
482-
483QString 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()
!rel.isValid()Description
TRUEevaluated 85 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
4-85
489 return
executed 85 times by 1 test: return QSqlTableModel::orderByClause();
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::orderByClause();
executed 85 times by 1 test: return QSqlTableModel::orderByClause();
Executed by:
  • tst_QSqlRelationalTableModel
85
490-
491 QString f = d->fullyQualifiedFieldName(Sql::relTablePrefix(d->sortColumn), rel.displayColumn());-
492 f = d->sortOrder == Qt::AscendingOrder
d->sortOrder =...AscendingOrderDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
? Sql::asc(f) : Sql::desc(f);
2
493 return
executed 4 times by 1 test: return Sql::orderBy(f);
Executed by:
  • tst_QSqlRelationalTableModel
Sql::orderBy(f);
executed 4 times by 1 test: return Sql::orderBy(f);
Executed by:
  • tst_QSqlRelationalTableModel
4
494}-
495-
496-
497-
498-
499bool QSqlRelationalTableModel::removeColumns(int column, int count, const QModelIndex &parent)-
500{-
501 QSqlRelationalTableModelPrivate * const d = d_func();-
502-
503 if (parent.isValid()
parent.isValid()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
|| column < 0
column < 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
|| column + count > d->rec.count()
column + count...d->rec.count()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
0-4
504 return
never executed: return false;
false;
never executed: return false;
0
505-
506 for (int i = 0; i < count
i < countDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
; ++i) {
4-6
507 d->baseRec.remove(column);-
508 if (d->relations.count() > column
d->relations.count() > columnDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
)
2-4
509 d->relations.remove(column);
executed 4 times by 1 test: d->relations.remove(column);
Executed by:
  • tst_QSqlRelationalTableModel
4
510 }
executed 6 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
6
511 return
executed 4 times by 1 test: return QSqlTableModel::removeColumns(column, count, parent);
Executed by:
  • tst_QSqlRelationalTableModel
QSqlTableModel::removeColumns(column, count, parent);
executed 4 times by 1 test: return QSqlTableModel::removeColumns(column, count, parent);
Executed by:
  • tst_QSqlRelationalTableModel
4
512}-
513-
514-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9