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

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