OpenCoverage

qsqlrecord.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqlrecord.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtSql module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qsqlrecord.h"-
41-
42#include "qdebug.h"-
43#include "qstringlist.h"-
44#include "qatomic.h"-
45#include "qsqlfield.h"-
46#include "qstring.h"-
47#include "qvector.h"-
48-
49QT_BEGIN_NAMESPACE-
50-
51class QSqlRecordPrivate-
52{-
53public:-
54 QSqlRecordPrivate();-
55 QSqlRecordPrivate(const QSqlRecordPrivate &other);-
56-
57 inline bool contains(int index) { return index >= 0 && index < fields.count(); }
executed 3290 times by 7 tests: return index >= 0 && index < fields.count();
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
3290
58 QString createField(int index, const QString &prefix) const;-
59-
60 QVector<QSqlField> fields;-
61 QAtomicInt ref;-
62};-
63-
64QSqlRecordPrivate::QSqlRecordPrivate() : ref(1)-
65{-
66}
executed 15179 times by 10 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
15179
67-
68QSqlRecordPrivate::QSqlRecordPrivate(const QSqlRecordPrivate &other): fields(other.fields), ref(1)-
69{-
70}
executed 1024 times by 8 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1024
71-
72/*! \internal-
73 Just for compat-
74*/-
75QString QSqlRecordPrivate::createField(int index, const QString &prefix) const-
76{-
77 QString f;-
78 if (!prefix.isEmpty())
!prefix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
79 f = prefix + QLatin1Char('.');
never executed: f = prefix + QLatin1Char('.');
0
80 f += fields.at(index).name();-
81 return f;
never executed: return f;
0
82}-
83-
84/*!-
85 \class QSqlRecord-
86 \brief The QSqlRecord class encapsulates a database record.-
87-
88 \ingroup database-
89 \ingroup shared-
90 \inmodule QtSql-
91-
92 The QSqlRecord class encapsulates the functionality and-
93 characteristics of a database record (usually a row in a table or-
94 view within the database). QSqlRecord supports adding and-
95 removing fields as well as setting and retrieving field values.-
96-
97 The values of a record's fields can be set by name or position-
98 with setValue(); if you want to set a field to null use-
99 setNull(). To find the position of a field by name use indexOf(),-
100 and to find the name of a field at a particular position use-
101 fieldName(). Use field() to retrieve a QSqlField object for a-
102 given field. Use contains() to see if the record contains a-
103 particular field name.-
104-
105 When queries are generated to be executed on the database only-
106 those fields for which isGenerated() is true are included in the-
107 generated SQL.-
108-
109 A record can have fields added with append() or insert(), replaced-
110 with replace(), and removed with remove(). All the fields can be-
111 removed with clear(). The number of fields is given by count();-
112 all their values can be cleared (to null) using clearValues().-
113-
114 \sa QSqlField, QSqlQuery::record()-
115*/-
116-
117-
118/*!-
119 Constructs an empty record.-
120-
121 \sa isEmpty(), append(), insert()-
122*/-
123-
124QSqlRecord::QSqlRecord()-
125{-
126 d = new QSqlRecordPrivate();-
127}
executed 15179 times by 10 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
15179
128-
129/*!-
130 Constructs a copy of \a other.-
131-
132 QSqlRecord is \l{implicitly shared}. This means you can make copies-
133 of a record in \l{constant time}.-
134*/-
135-
136QSqlRecord::QSqlRecord(const QSqlRecord& other)-
137{-
138 d = other.d;-
139 d->ref.ref();-
140}
executed 20192 times by 8 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
20192
141-
142/*!-
143 Sets the record equal to \a other.-
144-
145 QSqlRecord is \l{implicitly shared}. This means you can make copies-
146 of a record in \l{constant time}.-
147*/-
148-
149QSqlRecord& QSqlRecord::operator=(const QSqlRecord& other)-
150{-
151 qAtomicAssign(d, other.d);-
152 return *this;
executed 1738 times by 8 tests: return *this;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1738
153}-
154-
155/*!-
156 Destroys the object and frees any allocated resources.-
157*/-
158-
159QSqlRecord::~QSqlRecord()-
160{-
161 if (!d->ref.deref())
!d->ref.deref()Description
TRUEevaluated 14532 times by 10 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
FALSEevaluated 20839 times by 8 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
14532-20839
162 delete d;
executed 14532 times by 10 tests: delete d;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
14532
163}
executed 35371 times by 10 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
35371
164-
165/*!-
166 \fn bool QSqlRecord::operator!=(const QSqlRecord &other) const-
167-
168 Returns \c true if this object is not identical to \a other;-
169 otherwise returns \c false.-
170-
171 \sa operator==()-
172*/-
173-
174/*!-
175 Returns \c true if this object is identical to \a other (i.e., has-
176 the same fields in the same order); otherwise returns \c false.-
177-
178 \sa operator!=()-
179*/-
180bool QSqlRecord::operator==(const QSqlRecord &other) const-
181{-
182 return d->fields == other.d->fields;
executed 382 times by 4 tests: return d->fields == other.d->fields;
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
382
183}-
184-
185/*!-
186 Returns the value of the field located at position \a index in-
187 the record. If \a index is out of bounds, an invalid QVariant-
188 is returned.-
189-
190 \sa fieldName(), isNull()-
191*/-
192-
193QVariant QSqlRecord::value(int index) const-
194{-
195 return d->fields.value(index).value();
executed 1320 times by 5 tests: return d->fields.value(index).value();
Executed by:
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1320
196}-
197-
198/*!-
199 \overload-
200-
201 Returns the value of the field called \a name in the record. If-
202 field \a name does not exist an invalid variant is returned.-
203-
204 \sa indexOf()-
205*/-
206-
207QVariant QSqlRecord::value(const QString& name) const-
208{-
209 return value(indexOf(name));
executed 280 times by 3 tests: return value(indexOf(name));
Executed by:
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
280
210}-
211-
212/*!-
213 Returns the name of the field at position \a index. If the field-
214 does not exist, an empty string is returned.-
215-
216 \sa indexOf()-
217*/-
218-
219QString QSqlRecord::fieldName(int index) const-
220{-
221 return d->fields.value(index).name();
executed 2572 times by 8 tests: return d->fields.value(index).name();
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
2572
222}-
223-
224/*!-
225 Returns the position of the field called \a name within the-
226 record, or -1 if it cannot be found. Field names are not-
227 case-sensitive. If more than one field matches, the first one is-
228 returned.-
229-
230 \sa fieldName()-
231*/-
232-
233int QSqlRecord::indexOf(const QString& name) const-
234{-
235 QString nm = name.toUpper();-
236 for (int i = 0; i < count(); ++i) {
i < count()Description
TRUEevaluated 1543 times by 5 tests
Evaluated by:
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
FALSEevaluated 28 times by 4 tests
Evaluated by:
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
28-1543
237 if (d->fields.at(i).name().toUpper() == nm) // TODO: case-insensitive comparison
d->fields.at(i...oUpper() == nmDescription
TRUEevaluated 814 times by 5 tests
Evaluated by:
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
FALSEevaluated 729 times by 5 tests
Evaluated by:
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
729-814
238 return i;
executed 814 times by 5 tests: return i;
Executed by:
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
814
239 }
executed 729 times by 5 tests: end of block
Executed by:
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
729
240 return -1;
executed 28 times by 4 tests: return -1;
Executed by:
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
28
241}-
242-
243/*!-
244 Returns the field at position \a index. If the \a index-
245 is out of range, function returns-
246 a \l{default-constructed value}.-
247 */-
248QSqlField QSqlRecord::field(int index) const-
249{-
250 return d->fields.value(index);
executed 1674 times by 8 tests: return d->fields.value(index);
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1674
251}-
252-
253/*! \overload-
254 Returns the field called \a name.-
255 */-
256QSqlField QSqlRecord::field(const QString &name) const-
257{-
258 return field(indexOf(name));
executed 284 times by 4 tests: return field(indexOf(name));
Executed by:
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_qsqlrecord - unknown status
284
259}-
260-
261-
262/*!-
263 Append a copy of field \a field to the end of the record.-
264-
265 \sa insert(), replace(), remove()-
266*/-
267-
268void QSqlRecord::append(const QSqlField& field)-
269{-
270 detach();-
271 d->fields.append(field);-
272}
executed 5623 times by 10 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
5623
273-
274/*!-
275 Inserts the field \a field at position \a pos in the record.-
276-
277 \sa append(), replace(), remove()-
278 */-
279void QSqlRecord::insert(int pos, const QSqlField& field)-
280{-
281 detach();-
282 d->fields.insert(pos, field);-
283}
executed 117 times by 3 tests: end of block
Executed by:
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
117
284-
285/*!-
286 Replaces the field at position \a pos with the given \a field. If-
287 \a pos is out of range, nothing happens.-
288-
289 \sa append(), insert(), remove()-
290*/-
291-
292void QSqlRecord::replace(int pos, const QSqlField& field)-
293{-
294 if (!d->contains(pos))
!d->contains(pos)Description
TRUEnever evaluated
FALSEevaluated 34 times by 1 test
Evaluated by:
  • tst_QSqlRelationalTableModel
0-34
295 return;
never executed: return;
0
296-
297 detach();-
298 d->fields[pos] = field;-
299}
executed 34 times by 1 test: end of block
Executed by:
  • tst_QSqlRelationalTableModel
34
300-
301/*!-
302 Removes the field at position \a pos. If \a pos is out of range,-
303 nothing happens.-
304-
305 \sa append(), insert(), replace()-
306*/-
307-
308void QSqlRecord::remove(int pos)-
309{-
310 if (!d->contains(pos))
!d->contains(pos)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_qsqlrecord - unknown status
FALSEevaluated 24 times by 4 tests
Evaluated by:
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1-24
311 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_qsqlrecord - unknown status
1
312-
313 detach();-
314 d->fields.remove(pos);-
315}
executed 24 times by 4 tests: end of block
Executed by:
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
24
316-
317/*!-
318 Removes all the record's fields.-
319-
320 \sa clearValues(), isEmpty()-
321*/-
322-
323void QSqlRecord::clear()-
324{-
325 detach();-
326 d->fields.clear();-
327}
executed 124421 times by 10 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
124421
328-
329/*!-
330 Returns \c true if there are no fields in the record; otherwise-
331 returns \c false.-
332-
333 \sa append(), insert(), clear()-
334*/-
335-
336bool QSqlRecord::isEmpty() const-
337{-
338 return d->fields.isEmpty();
executed 89869 times by 10 tests: return d->fields.isEmpty();
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
89869
339}-
340-
341-
342/*!-
343 Returns \c true if there is a field in the record called \a name;-
344 otherwise returns \c false.-
345*/-
346-
347bool QSqlRecord::contains(const QString& name) const-
348{-
349 return indexOf(name) >= 0;
executed 6 times by 1 test: return indexOf(name) >= 0;
Executed by:
  • tst_qsqlrecord - unknown status
6
350}-
351-
352/*!-
353 Clears the value of all fields in the record and sets each field-
354 to null.-
355-
356 \sa setValue()-
357*/-
358-
359void QSqlRecord::clearValues()-
360{-
361 detach();-
362 int count = d->fields.count();-
363 for (int i = 0; i < count; ++i)
i < countDescription
TRUEevaluated 72 times by 2 tests
Evaluated by:
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
FALSEevaluated 24 times by 2 tests
Evaluated by:
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
24-72
364 d->fields[i].clear();
executed 72 times by 2 tests: d->fields[i].clear();
Executed by:
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
72
365}
executed 24 times by 2 tests: end of block
Executed by:
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
24
366-
367/*!-
368 Sets the generated flag for the field called \a name to \a-
369 generated. If the field does not exist, nothing happens. Only-
370 fields that have \a generated set to true are included in the SQL-
371 that is generated by QSqlQueryModel for example.-
372-
373 \sa isGenerated()-
374*/-
375-
376void QSqlRecord::setGenerated(const QString& name, bool generated)-
377{-
378 setGenerated(indexOf(name), generated);-
379}
executed 2 times by 1 test: end of block
Executed by:
  • tst_qsqlrecord - unknown status
2
380-
381/*!-
382 \overload-
383-
384 Sets the generated flag for the field \a index to \a generated.-
385-
386 \sa isGenerated()-
387*/-
388-
389void QSqlRecord::setGenerated(int index, bool generated)-
390{-
391 if (!d->contains(index))
!d->contains(index)Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_qsqlrecord - unknown status
FALSEevaluated 1678 times by 3 tests
Evaluated by:
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
6-1678
392 return;
executed 6 times by 1 test: return;
Executed by:
  • tst_qsqlrecord - unknown status
6
393 detach();-
394 d->fields[index].setGenerated(generated);-
395}
executed 1678 times by 3 tests: end of block
Executed by:
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1678
396-
397/*!-
398 \overload-
399-
400 Returns \c true if the field \a index is null or if there is no field at-
401 position \a index; otherwise returns \c false.-
402*/-
403bool QSqlRecord::isNull(int index) const-
404{-
405 return d->fields.value(index).isNull();
executed 532 times by 4 tests: return d->fields.value(index).isNull();
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
532
406}-
407-
408/*!-
409 Returns \c true if the field called \a name is null or if there is no-
410 field called \a name; otherwise returns \c false.-
411-
412 \sa setNull()-
413*/-
414bool QSqlRecord::isNull(const QString& name) const-
415{-
416 return isNull(indexOf(name));
executed 20 times by 1 test: return isNull(indexOf(name));
Executed by:
  • tst_qsqlrecord - unknown status
20
417}-
418-
419/*!-
420 Sets the value of field \a index to null. If the field does not exist,-
421 nothing happens.-
422-
423 \sa setValue()-
424*/-
425void QSqlRecord::setNull(int index)-
426{-
427 if (!d->contains(index))
!d->contains(index)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qsqlrecord - unknown status
FALSEevaluated 48 times by 1 test
Evaluated by:
  • tst_qsqlrecord - unknown status
4-48
428 return;
executed 4 times by 1 test: return;
Executed by:
  • tst_qsqlrecord - unknown status
4
429 detach();-
430 d->fields[index].clear();-
431}
executed 48 times by 1 test: end of block
Executed by:
  • tst_qsqlrecord - unknown status
48
432-
433/*!-
434 \overload-
435-
436 Sets the value of the field called \a name to null. If the field-
437 does not exist, nothing happens.-
438*/-
439void QSqlRecord::setNull(const QString& name)-
440{-
441 setNull(indexOf(name));-
442}
executed 10 times by 1 test: end of block
Executed by:
  • tst_qsqlrecord - unknown status
10
443-
444-
445/*!-
446 Returns \c true if the record has a field called \a name and this-
447 field is to be generated (the default); otherwise returns \c false.-
448-
449 \sa setGenerated()-
450*/-
451bool QSqlRecord::isGenerated(const QString& name) const-
452{-
453 return isGenerated(indexOf(name));
executed 16 times by 1 test: return isGenerated(indexOf(name));
Executed by:
  • tst_qsqlrecord - unknown status
16
454}-
455-
456/*! \overload-
457-
458 Returns \c true if the record has a field at position \a index and this-
459 field is to be generated (the default); otherwise returns \c false.-
460-
461 \sa setGenerated()-
462*/-
463bool QSqlRecord::isGenerated(int index) const-
464{-
465 return d->fields.value(index).isGenerated();
executed 8549 times by 6 tests: return d->fields.value(index).isGenerated();
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
8549
466}-
467-
468/*!-
469 Returns the number of fields in the record.-
470-
471 \sa isEmpty()-
472*/-
473-
474int QSqlRecord::count() const-
475{-
476 return d->fields.count();
executed 146486 times by 9 tests: return d->fields.count();
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
146486
477}-
478-
479/*!-
480 Sets the value of the field at position \a index to \a val. If the-
481 field does not exist, nothing happens.-
482-
483 \sa setNull()-
484*/-
485-
486void QSqlRecord::setValue(int index, const QVariant& val)-
487{-
488 if (!d->contains(index))
!d->contains(index)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QSqlTableModel
FALSEevaluated 1493 times by 7 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
2-1493
489 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QSqlTableModel
2
490 detach();-
491 d->fields[index].setValue(val);-
492}
executed 1493 times by 7 tests: end of block
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1493
493-
494-
495/*!-
496 \overload-
497-
498 Sets the value of the field called \a name to \a val. If the field-
499 does not exist, nothing happens.-
500*/-
501-
502void QSqlRecord::setValue(const QString& name, const QVariant& val)-
503{-
504 setValue(indexOf(name), val);-
505}
executed 15 times by 2 tests: end of block
Executed by:
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
15
506-
507-
508/*! \internal-
509*/-
510void QSqlRecord::detach()-
511{-
512 qAtomicDetach(d);-
513}
executed 133462 times by 10 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlrecord - unknown status
133462
514-
515#ifndef QT_NO_DEBUG_STREAM-
516QDebug operator<<(QDebug dbg, const QSqlRecord &r)-
517{-
518 QDebugStateSaver saver(dbg);-
519 dbg.nospace();-
520 const int count = r.count();-
521 dbg << "QSqlRecord(" << count << ')';-
522 for (int i = 0; i < count; ++i) {
i < countDescription
TRUEnever evaluated
FALSEnever evaluated
0
523 dbg.nospace();-
524 dbg << '\n' << qSetFieldWidth(2) << right << i << left << qSetFieldWidth(0) << ':';-
525 dbg.space();-
526 dbg << r.field(i) << r.value(i).toString();-
527 }
never executed: end of block
0
528 return dbg;
never executed: return dbg;
0
529}-
530#endif-
531-
532/*!-
533 \since 5.1-
534 Returns a record containing the fields represented in \a keyFields set to values-
535 that match by field name.-
536*/-
537QSqlRecord QSqlRecord::keyValues(const QSqlRecord &keyFields) const-
538{-
539 QSqlRecord retValues(keyFields);-
540-
541 for (int i = retValues.count() - 1; i >= 0; --i)
i >= 0Description
TRUEevaluated 278 times by 2 tests
Evaluated by:
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
FALSEevaluated 133 times by 2 tests
Evaluated by:
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
133-278
542 retValues.setValue(i, value(retValues.fieldName(i)));
executed 278 times by 2 tests: retValues.setValue(i, value(retValues.fieldName(i)));
Executed by:
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
278
543-
544 return retValues;
executed 133 times by 2 tests: return retValues;
Executed by:
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
133
545}-
546-
547QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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