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

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