OpenCoverage

qsqlfield.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/sql/kernel/qsqlfield.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 "qsqlfield.h"-
41#include "qatomic.h"-
42#include "qdebug.h"-
43-
44QT_BEGIN_NAMESPACE-
45-
46class QSqlFieldPrivate-
47{-
48public:-
49 QSqlFieldPrivate(const QString &name,-
50 QVariant::Type type) :-
51 ref(1), nm(name), ro(false), type(type), req(QSqlField::Unknown),-
52 len(-1), prec(-1), tp(-1), gen(true), autoval(false)-
53 {-
54 }
executed 6143 times by 11 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_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
6143
55-
56 QSqlFieldPrivate(const QSqlFieldPrivate &other)-
57 : ref(1),-
58 nm(other.nm),-
59 ro(other.ro),-
60 type(other.type),-
61 req(other.req),-
62 len(other.len),-
63 prec(other.prec),-
64 def(other.def),-
65 tp(other.tp),-
66 gen(other.gen),-
67 autoval(other.autoval)-
68 {}
executed 1071 times by 3 tests: end of block
Executed by:
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1071
69-
70 bool operator==(const QSqlFieldPrivate& other) const-
71 {-
72 return (nm == other.nm
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
73 && ro == other.ro
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
74 && type == other.type
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
75 && req == other.req
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
76 && len == other.len
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
77 && prec == other.prec
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
78 && def == other.def
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
79 && gen == other.gen
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
80 && autoval == other.autoval);
executed 578 times by 6 tests: return (nm == other.nm && ro == other.ro && type == other.type && req == other.req && len == other.len && prec == other.prec && def == other.def && gen == other.gen && autoval == other.autoval);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
578
81 }-
82-
83 QAtomicInt ref;-
84 QString nm;-
85 uint ro: 1;-
86 QVariant::Type type;-
87 QSqlField::RequiredStatus req;-
88 int len;-
89 int prec;-
90 QVariant def;-
91 int tp;-
92 uint gen: 1;-
93 uint autoval: 1;-
94};-
95-
96-
97/*!-
98 \class QSqlField-
99 \brief The QSqlField class manipulates the fields in SQL database tables-
100 and views.-
101-
102 \ingroup database-
103 \ingroup shared-
104 \inmodule QtSql-
105-
106 QSqlField represents the characteristics of a single column in a-
107 database table or view, such as the data type and column name. A-
108 field also contains the value of the database column, which can be-
109 viewed or changed.-
110-
111 Field data values are stored as QVariants. Using an incompatible-
112 type is not permitted. For example:-
113-
114 \snippet sqldatabase/sqldatabase.cpp 2-
115-
116 However, the field will attempt to cast certain data types to the-
117 field data type where possible:-
118-
119 \snippet sqldatabase/sqldatabase.cpp 3-
120-
121 QSqlField objects are rarely created explicitly in application-
122 code. They are usually accessed indirectly through \l{QSqlRecord}s-
123 that already contain a list of fields. For example:-
124-
125 \snippet sqldatabase/sqldatabase.cpp 4-
126 \dots-
127 \snippet sqldatabase/sqldatabase.cpp 5-
128 \snippet sqldatabase/sqldatabase.cpp 6-
129-
130 A QSqlField object can provide some meta-data about the field, for-
131 example, its name(), variant type(), length(), precision(),-
132 defaultValue(), typeID(), and its requiredStatus(),-
133 isGenerated() and isReadOnly(). The field's data can be-
134 checked to see if it isNull(), and its value() retrieved. When-
135 editing the data can be set with setValue() or set to NULL with-
136 clear().-
137-
138 \sa QSqlRecord-
139*/-
140-
141/*!-
142 \enum QSqlField::RequiredStatus-
143-
144 Specifies whether the field is required or optional.-
145-
146 \value Required The field must be specified when inserting records.-
147 \value Optional The fields doesn't have to be specified when inserting records.-
148 \value Unknown The database driver couldn't determine whether the field is required or-
149 optional.-
150-
151 \sa requiredStatus()-
152*/-
153-
154/*!-
155 Constructs an empty field called \a fieldName of variant type \a-
156 type.-
157-
158 \sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(),-
159 setGenerated(), setReadOnly()-
160*/-
161QSqlField::QSqlField(const QString& fieldName, QVariant::Type type)-
162{-
163 d = new QSqlFieldPrivate(fieldName, type);-
164 val = QVariant(type);-
165}
executed 6143 times by 11 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_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
6143
166-
167/*!-
168 Constructs a copy of \a other.-
169*/-
170-
171QSqlField::QSqlField(const QSqlField& other)-
172{-
173 d = other.d;-
174 d->ref.ref();-
175 val = other.val;-
176}
executed 29510 times by 11 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_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
29510
177-
178/*!-
179 Sets the field equal to \a other.-
180*/-
181-
182QSqlField& QSqlField::operator=(const QSqlField& other)-
183{-
184 qAtomicAssign(d, other.d);-
185 val = other.val;-
186 return *this;
executed 233 times by 5 tests: return *this;
Executed by:
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
233
187}-
188-
189-
190/*! \fn bool QSqlField::operator!=(const QSqlField &other) const-
191 Returns \c true if the field is unequal to \a other; otherwise returns-
192 false.-
193*/-
194-
195/*!-
196 Returns \c true if the field is equal to \a other; otherwise returns-
197 false.-
198*/-
199bool QSqlField::operator==(const QSqlField& other) const-
200{-
201 return ((d == other.d || *d == *other.d)
executed 604 times by 6 tests: return ((d == other.d || *d == *other.d) && val == other.val);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
604
202 && val == other.val);
executed 604 times by 6 tests: return ((d == other.d || *d == *other.d) && val == other.val);
Executed by:
  • tst_QItemModel
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
604
203}-
204-
205/*!-
206 Destroys the object and frees any allocated resources.-
207*/-
208-
209QSqlField::~QSqlField()-
210{-
211 if (!d->ref.deref())
!d->ref.deref()Description
TRUEevaluated 7097 times by 11 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
FALSEevaluated 28556 times by 11 tests
Evaluated by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
7097-28556
212 delete d;
executed 7097 times by 11 tests: delete d;
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
7097
213}
executed 35653 times by 11 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_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
35653
214-
215/*!-
216 Sets the required status of this field to \a required.-
217-
218 \sa requiredStatus(), setType(), setLength(), setPrecision(),-
219 setDefaultValue(), setGenerated(), setReadOnly()-
220*/-
221void QSqlField::setRequiredStatus(RequiredStatus required)-
222{-
223 detach();-
224 d->req = required;-
225}
executed 970 times by 7 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
970
226-
227/*! \fn void QSqlField::setRequired(bool required)-
228-
229 Sets the required status of this field to \l Required if \a-
230 required is true; otherwise sets it to \l Optional.-
231-
232 \sa setRequiredStatus(), requiredStatus()-
233*/-
234-
235/*!-
236 Sets the field's length to \a fieldLength. For strings this is the-
237 maximum number of characters the string can hold; the meaning-
238 varies for other types.-
239-
240 \sa length(), setType(), setRequiredStatus(), setPrecision(),-
241 setDefaultValue(), setGenerated(), setReadOnly()-
242*/-
243void QSqlField::setLength(int fieldLength)-
244{-
245 detach();-
246 d->len = fieldLength;-
247}
executed 3 times by 1 test: end of block
Executed by:
  • tst_qsqlfield - unknown status
3
248-
249/*!-
250 Sets the field's \a precision. This only affects numeric fields.-
251-
252 \sa precision(), setType(), setRequiredStatus(), setLength(),-
253 setDefaultValue(), setGenerated(), setReadOnly()-
254*/-
255void QSqlField::setPrecision(int precision)-
256{-
257 detach();-
258 d->prec = precision;-
259}
executed 3 times by 1 test: end of block
Executed by:
  • tst_qsqlfield - unknown status
3
260-
261/*!-
262 Sets the default value used for this field to \a value.-
263-
264 \sa defaultValue(), value(), setType(), setRequiredStatus(),-
265 setLength(), setPrecision(), setGenerated(), setReadOnly()-
266*/-
267void QSqlField::setDefaultValue(const QVariant &value)-
268{-
269 detach();-
270 d->def = value;-
271}
executed 967 times by 6 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
967
272-
273/*!-
274 \internal-
275*/-
276void QSqlField::setSqlType(int type)-
277{-
278 detach();-
279 d->tp = type;-
280}
executed 4556 times by 9 tests: end of block
Executed by:
  • tst_QItemModel
  • tst_QSql
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_QSqlThread
4556
281-
282/*!-
283 Sets the generated state. If \a gen is false, no SQL will-
284 be generated for this field; otherwise, Qt classes such as-
285 QSqlQueryModel and QSqlTableModel will generate SQL for this-
286 field.-
287-
288 \sa isGenerated(), setType(), setRequiredStatus(), setLength(),-
289 setPrecision(), setDefaultValue(), setReadOnly()-
290*/-
291void QSqlField::setGenerated(bool gen)-
292{-
293 detach();-
294 d->gen = gen;-
295}
executed 1702 times by 4 tests: end of block
Executed by:
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
1702
296-
297-
298/*!-
299 Sets the value of the field to \a value. If the field is read-only-
300 (isReadOnly() returns \c true), nothing happens.-
301-
302 If the data type of \a value differs from the field's current-
303 data type, an attempt is made to cast it to the proper type. This-
304 preserves the data type of the field in the case of assignment,-
305 e.g. a QString to an integer data type.-
306-
307 To set the value to NULL, use clear().-
308-
309 \sa value(), isReadOnly(), defaultValue()-
310*/-
311-
312void QSqlField::setValue(const QVariant& value)-
313{-
314 if (isReadOnly())
isReadOnly()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qsqlfield - unknown status
FALSEevaluated 1537 times by 8 tests
Evaluated by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
4-1537
315 return;
executed 4 times by 1 test: return;
Executed by:
  • tst_qsqlfield - unknown status
4
316 val = value;-
317}
executed 1537 times by 8 tests: end of block
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
1537
318-
319/*!-
320 Clears the value of the field and sets it to NULL.-
321 If the field is read-only, nothing happens.-
322-
323 \sa setValue(), isReadOnly(), requiredStatus()-
324*/-
325-
326void QSqlField::clear()-
327{-
328 if (isReadOnly())
isReadOnly()Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • tst_qsqlfield - unknown status
FALSEevaluated 129 times by 3 tests
Evaluated by:
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
14-129
329 return;
executed 14 times by 1 test: return;
Executed by:
  • tst_qsqlfield - unknown status
14
330 val = QVariant(type());-
331}
executed 129 times by 3 tests: end of block
Executed by:
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
129
332-
333/*!-
334 Sets the name of the field to \a name.-
335-
336 \sa name()-
337*/-
338-
339void QSqlField::setName(const QString& name)-
340{-
341 detach();-
342 d->nm = name;-
343}
executed 7 times by 1 test: end of block
Executed by:
  • tst_qsqlfield - unknown status
7
344-
345/*!-
346 Sets the read only flag of the field's value to \a readOnly. A-
347 read-only field cannot have its value set with setValue() and-
348 cannot be cleared to NULL with clear().-
349*/-
350void QSqlField::setReadOnly(bool readOnly)-
351{-
352 detach();-
353 d->ro = readOnly;-
354}
executed 32 times by 3 tests: end of block
Executed by:
  • tst_QSqlQueryModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
32
355-
356/*!-
357 \fn QVariant QSqlField::value() const-
358-
359 Returns the value of the field as a QVariant.-
360-
361 Use isNull() to check if the field's value is NULL.-
362*/-
363-
364/*!-
365 Returns the name of the field.-
366-
367 \sa setName()-
368*/-
369QString QSqlField::name() const-
370{-
371 return d->nm;
executed 4401 times by 9 tests: return d->nm;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
4401
372}-
373-
374/*!-
375 Returns the field's type as stored in the database.-
376 Note that the actual value might have a different type,-
377 Numerical values that are too large to store in a long-
378 int or double are usually stored as strings to prevent-
379 precision loss.-
380-
381 \sa setType()-
382*/-
383QVariant::Type QSqlField::type() const-
384{-
385 return d->type;
executed 312 times by 8 tests: return d->type;
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
312
386}-
387-
388/*!-
389 Set's the field's variant type to \a type.-
390-
391 \sa type(), setRequiredStatus(), setLength(), setPrecision(),-
392 setDefaultValue(), setGenerated(), setReadOnly()-
393*/-
394void QSqlField::setType(QVariant::Type type)-
395{-
396 detach();-
397 d->type = type;-
398 if (!val.isValid())
!val.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
399 val = QVariant(type);
never executed: val = QVariant(type);
0
400}
never executed: end of block
0
401-
402-
403/*!-
404 Returns \c true if the field's value is read-only; otherwise returns-
405 false.-
406-
407 \sa setReadOnly(), type(), requiredStatus(), length(), precision(),-
408 defaultValue(), isGenerated()-
409*/-
410bool QSqlField::isReadOnly() const-
411{
executed 1953 times by 8 tests: return d->ro;
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
return d->ro; }
executed 1953 times by 8 tests: return d->ro;
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlQuery
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
1953
412-
413/*!-
414 Returns \c true if the field's value is NULL; otherwise returns-
415 false.-
416-
417 \sa value()-
418*/-
419bool QSqlField::isNull() const-
420{
executed 678 times by 6 tests: return val.isNull();
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
return val.isNull(); }
executed 678 times by 6 tests: return val.isNull();
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlDriver
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
678
421-
422/*! \internal-
423*/-
424void QSqlField::detach()-
425{-
426 qAtomicDetach(d);-
427}
executed 8261 times by 11 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_qsqlfield - unknown status
  • tst_qsqlrecord - unknown status
8261
428-
429/*!-
430 Returns \c true if this is a required field; otherwise returns \c false.-
431 An \c INSERT will fail if a required field does not have a value.-
432-
433 \sa setRequiredStatus(), type(), length(), precision(), defaultValue(),-
434 isGenerated()-
435*/-
436QSqlField::RequiredStatus QSqlField::requiredStatus() const-
437{-
438 return d->req;
executed 3 times by 1 test: return d->req;
Executed by:
  • tst_qsqlfield - unknown status
3
439}-
440-
441/*!-
442 Returns the field's length.-
443-
444 If the returned value is negative, it means that the information-
445 is not available from the database.-
446-
447 \sa setLength(), type(), requiredStatus(), precision(), defaultValue(),-
448 isGenerated()-
449*/-
450int QSqlField::length() const-
451{-
452 return d->len;
executed 3 times by 1 test: return d->len;
Executed by:
  • tst_qsqlfield - unknown status
3
453}-
454-
455/*!-
456 Returns the field's precision; this is only meaningful for numeric-
457 types.-
458-
459 If the returned value is negative, it means that the information-
460 is not available from the database.-
461-
462 \sa setPrecision(), type(), requiredStatus(), length(), defaultValue(),-
463 isGenerated()-
464*/-
465int QSqlField::precision() const-
466{-
467 return d->prec;
executed 4 times by 2 tests: return d->prec;
Executed by:
  • tst_QSqlQuery
  • tst_qsqlfield - unknown status
4
468}-
469-
470/*!-
471 Returns the field's default value (which may be NULL).-
472-
473 \sa setDefaultValue(), type(), requiredStatus(), length(), precision(),-
474 isGenerated()-
475*/-
476QVariant QSqlField::defaultValue() const-
477{-
478 return d->def;
never executed: return d->def;
0
479}-
480-
481/*!-
482 \internal-
483-
484 Returns the type ID for the field.-
485-
486 If the returned value is negative, it means that the information-
487 is not available from the database.-
488*/-
489int QSqlField::typeID() const-
490{-
491 return d->tp;
never executed: return d->tp;
0
492}-
493-
494/*!-
495 Returns \c true if the field is generated; otherwise returns-
496 false.-
497-
498 \sa setGenerated(), type(), requiredStatus(), length(), precision(),-
499 defaultValue()-
500*/-
501bool QSqlField::isGenerated() const-
502{-
503 return d->gen;
executed 8549 times by 6 tests: return d->gen;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlQueryModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
  • tst_qsqlrecord - unknown status
8549
504}-
505-
506/*!-
507 Returns \c true if the field's variant type is valid; otherwise-
508 returns \c false.-
509*/-
510bool QSqlField::isValid() const-
511{-
512 return d->type != QVariant::Invalid;
executed 373 times by 3 tests: return d->type != QVariant::Invalid;
Executed by:
  • tst_QItemModel
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
373
513}-
514-
515#ifndef QT_NO_DEBUG_STREAM-
516QDebug operator<<(QDebug dbg, const QSqlField &f)-
517{-
518 QDebugStateSaver saver(dbg);-
519 dbg.nospace();-
520 dbg << "QSqlField(" << f.name() << ", " << QMetaType::typeName(f.type());-
521 if (f.length() >= 0)
f.length() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
522 dbg << ", length: " << f.length();
never executed: dbg << ", length: " << f.length();
0
523 if (f.precision() >= 0)
f.precision() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
524 dbg << ", precision: " << f.precision();
never executed: dbg << ", precision: " << f.precision();
0
525 if (f.requiredStatus() != QSqlField::Unknown)
f.requiredStat...Field::UnknownDescription
TRUEnever evaluated
FALSEnever evaluated
0
526 dbg << ", required: "
never executed: dbg << ", required: " << (f.requiredStatus() == QSqlField::Required ? "yes" : "no");
0
527 << (f.requiredStatus() == QSqlField::Required ? "yes" : "no");
never executed: dbg << ", required: " << (f.requiredStatus() == QSqlField::Required ? "yes" : "no");
0
528 dbg << ", generated: " << (f.isGenerated() ? "yes" : "no");-
529 if (f.typeID() >= 0)
f.typeID() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
530 dbg << ", typeID: " << f.typeID();
never executed: dbg << ", typeID: " << f.typeID();
0
531 if (!f.defaultValue().isNull())
!f.defaultValue().isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
532 dbg << ", defaultValue: \"" << f.defaultValue() << '\"';
never executed: dbg << ", defaultValue: \"" << f.defaultValue() << '\"';
0
533 dbg << ", autoValue: " << f.isAutoValue()-
534 << ", readOnly: " << f.isReadOnly() << ')';-
535 return dbg;
never executed: return dbg;
0
536}-
537#endif-
538-
539/*!-
540 Returns \c true if the value is auto-generated by the database,-
541 for example auto-increment primary key values.-
542-
543 \note When using the ODBC driver, due to limitations in the ODBC API,-
544 the \c isAutoValue() field is only populated in a QSqlField resulting from a-
545 QSqlRecord obtained by executing a \c SELECT query. It is \c false in a QSqlField-
546 resulting from a QSqlRecord returned from QSqlDatabase::record() or-
547 QSqlDatabase::primaryIndex().-
548-
549 \sa setAutoValue()-
550*/-
551bool QSqlField::isAutoValue() const-
552{-
553 return d->autoval;
executed 460 times by 4 tests: return d->autoval;
Executed by:
  • tst_QItemModel
  • tst_QSqlDatabase
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
460
554}-
555-
556/*!-
557 Marks the field as an auto-generated value if \a autoVal-
558 is true.-
559-
560 \sa isAutoValue()-
561 */-
562void QSqlField::setAutoValue(bool autoVal)-
563{-
564 detach();-
565 d->autoval = autoVal;-
566}
executed 21 times by 4 tests: end of block
Executed by:
  • tst_QSqlDatabase
  • tst_QSqlQuery
  • tst_QSqlRelationalTableModel
  • tst_QSqlTableModel
21
567-
568QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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