Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qsqlfield.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qsqlfield.h"
5#include "qdebug.h"
6
8
10{
11public:
13 QMetaType type, const QString &tableName) :
14 nm(name), table(tableName), def(QVariant()), type(type),
15 req(QSqlField::Unknown), len(-1), prec(-1), tp(-1),
16 ro(false), gen(true), autoval(false)
17 {}
18
20 {
21 return (nm == other.nm
22 && table == other.table
23 && def == other.def
24 && type == other.type
25 && req == other.req
26 && len == other.len
27 && prec == other.prec
28 && ro == other.ro
29 && gen == other.gen
30 && autoval == other.autoval);
31 }
32
38 int len;
39 int prec;
40 int tp;
41 bool ro: 1;
42 bool gen: 1;
43 bool autoval: 1;
44};
46
47
48
130 : val(QVariant(type, nullptr)),
131 d(new QSqlFieldPrivate(fieldName, type, table))
132{
133}
134
140 = default;
141
147 = default;
148
159{
160 return ((d == other.d || *d == *other.d)
161 && val == other.val);
162}
163
169 = default;
170
175{
176 detach();
177 d->req = required;
178}
179
191void QSqlField::setLength(int fieldLength)
192{
193 detach();
194 d->len = fieldLength;
195}
196
201{
202 detach();
203 d->prec = precision;
204}
205
219{
220 detach();
221 d->def = value;
222}
223
224#if QT_DEPRECATED_SINCE(6, 8)
229void QSqlField::setSqlType(int type)
230{
231 detach();
232 d->tp = type;
233}
234#endif
235
240{
241 detach();
242 d->gen = gen;
243}
244
245
270{
271 if (isReadOnly())
272 return;
273 val = value;
274}
275
282{
283 if (isReadOnly())
284 return;
285 val = QVariant(d->type, nullptr);
286}
287
288
293{
294 detach();
295 d->nm = name;
296}
297
301void QSqlField::setReadOnly(bool readOnly)
302{
303 detach();
304 d->ro = readOnly;
305}
306
318{
319 return d->nm;
320}
321
339{
340 return d->type;
341}
342
347{
348 detach();
349 d->type = type;
350 if (!val.isValid())
351 val = QVariant(type, nullptr);
352}
353
389{
390 return d->ro;
391}
392
400{
401 return val.isNull();
402}
403
406void QSqlField::detach()
407{
408 d.detach();
409}
410
428
445{
446 return d->len;
447}
448
463{
464 return d->prec;
465}
466
471{
472 return d->def;
473}
474
475#if QT_DEPRECATED_SINCE(6, 8)
485int QSqlField::typeID() const
486{
487 return d->tp;
488}
489#endif
490
504{
505 return d->gen;
506}
507
513{
514 return d->type.isValid();
515}
516
517#ifndef QT_NO_DEBUG_STREAM
519{
520 QDebugStateSaver saver(dbg);
521 dbg.nospace();
522 dbg << "QSqlField(" << f.name() << ", " << f.metaType().name();
523 dbg << ", tableName: " << (f.tableName().isEmpty() ? QStringLiteral("(not specified)") : f.tableName());
524 if (f.length() >= 0)
525 dbg << ", length: " << f.length();
526 if (f.precision() >= 0)
527 dbg << ", precision: " << f.precision();
528 if (f.requiredStatus() != QSqlField::Unknown)
529 dbg << ", required: "
530 << (f.requiredStatus() == QSqlField::Required ? "yes" : "no");
531 dbg << ", generated: " << (f.isGenerated() ? "yes" : "no");
532 if (!f.defaultValue().isNull())
533 dbg << ", defaultValue: \"" << f.defaultValue() << '\"';
534 dbg << ", autoValue: " << f.isAutoValue()
535 << ", readOnly: " << f.isReadOnly() << ')';
536 return dbg;
537}
538#endif
539
558{
559 return d->autoval;
560}
561
565void QSqlField::setAutoValue(bool autoVal)
566{
567 detach();
568 d->autoval = autoVal;
569}
570
574void QSqlField::setTableName(const QString &tableName)
575{
576 detach();
577 d->table = tableName;
578}
579
594{
595 return d->table;
596}
597
599
600#include "moc_qsqlfield.cpp"
\inmodule QtCore
\inmodule QtCore
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
\inmodule QtCore
Definition qmetatype.h:341
bool isValid() const
\inmodule QtCore
Definition qshareddata.h:19
QSqlField::RequiredStatus req
Definition qsqlfield.cpp:37
bool operator==(const QSqlFieldPrivate &other) const
Definition qsqlfield.cpp:19
QSqlFieldPrivate(const QString &name, QMetaType type, const QString &tableName)
Definition qsqlfield.cpp:12
The QSqlField class manipulates the fields in SQL database tables and views.
Definition qsqlfield.h:19
QSqlField(const QString &fieldName=QString(), QMetaType type=QMetaType(), const QString &tableName=QString())
RequiredStatus
Specifies whether the field is required or optional.
Definition qsqlfield.h:22
void setAutoValue(bool autoVal)
Sets \l autoValue to autoVal.
bool isGenerated() const
Returns the value of \l generated.
void setRequiredStatus(RequiredStatus status)
Sets \l requiredStatus to required.
bool isValid() const
Returns true if the field's variant type is valid; otherwise returns false.
bool operator==(const QSqlField &other) const
Returns true if the field is equal to other; otherwise returns false.
void setValue(const QVariant &value)
Sets \l value to value.
void setLength(int fieldLength)
Sets \l length to fieldLength.
void setDefaultValue(const QVariant &value)
Sets \l defaultValue to value.
void setName(const QString &name)
Sets \l name to name.
QMetaType metaType
Definition qsqlfield.h:28
RequiredStatus requiredStatus
Definition qsqlfield.h:29
void setMetaType(QMetaType type)
Sets \l metaType to type.
void setReadOnly(bool readOnly)
Sets \l readOnly to readOnly.
QString tableName
Definition qsqlfield.h:27
QString name
This property holds the name of the field.
Definition qsqlfield.h:26
QVariant defaultValue
Definition qsqlfield.h:25
void clear()
Clears the value of the field and sets it to NULL.
~QSqlField()
Destroys the object and frees any allocated resources.
bool readOnly
Definition qsqlfield.h:30
bool isNull() const
Returns true if the field's value is NULL; otherwise returns false.
int precision
Definition qsqlfield.h:34
bool isAutoValue() const
Returns the value of \l autoValue.
bool isReadOnly() const
Returns the value of \l readOnly.
void setPrecision(int precision)
Sets \l precision to precision.
void setTableName(const QString &tableName)
Sets \l tableName to tableName.
void setGenerated(bool gen)
Sets \l generated to gen.
QVariant value
Definition qsqlfield.h:24
int length
Definition qsqlfield.h:33
QSqlField & operator=(const QSqlField &other)
Sets the field equal to other.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLfloat GLfloat f
GLenum type
GLuint name
GLuint GLfloat * val
GLenum GLsizei len
GLenum GLenum GLsizei void * table
GLenum GLint GLint * precision
#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
QDebug operator<<(QDebug dbg, const QSqlField &f)
#define QStringLiteral(str)
QSharedPointer< T > other(t)
[5]