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#ifndef QSQLFIELD_H
5#define QSQLFIELD_H
6
7#include <QtSql/qtsqlglobal.h>
8#include <QtCore/qshareddata.h>
9#include <QtCore/qvariant.h>
10#include <QtCore/qstring.h>
11
12QT_BEGIN_NAMESPACE
13
14
15class QSqlFieldPrivate;
16QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlFieldPrivate, Q_SQL_EXPORT)
17
18class Q_SQL_EXPORT QSqlField
19{
20 Q_GADGET
21 Q_PROPERTY(QVariant value READ value WRITE setValue)
22 Q_PROPERTY(QVariant defaultValue READ defaultValue WRITE setDefaultValue)
23 Q_PROPERTY(QString name READ name WRITE setName)
24 Q_PROPERTY(QString tableName READ tableName WRITE setTableName)
25 Q_PROPERTY(QMetaType metaType READ metaType WRITE setMetaType)
26 Q_PROPERTY(RequiredStatus requiredStatus READ requiredStatus WRITE setRequiredStatus)
27 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
28 Q_PROPERTY(bool generated READ isGenerated WRITE setGenerated)
29 Q_PROPERTY(bool autoValue READ isAutoValue WRITE setAutoValue)
30 Q_PROPERTY(int length READ length WRITE setLength)
31 Q_PROPERTY(int precision READ precision WRITE setPrecision)
32
33public:
34 enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
35
36 explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType(), const QString &tableName = QString());
37
38 QSqlField(const QSqlField& other);
39 QSqlField& operator=(const QSqlField& other);
40 QSqlField(QSqlField &&other) noexcept = default;
41 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlField)
42 ~QSqlField();
43
44 void swap(QSqlField &other) noexcept { val.swap(other&: other.val); d.swap(other&: other.d); }
45
46 bool operator==(const QSqlField& other) const;
47 inline bool operator!=(const QSqlField &other) const { return !operator==(other); }
48
49 void setValue(const QVariant& value);
50 inline QVariant value() const
51 { return val; }
52 void setName(const QString& name);
53 QString name() const;
54 void setTableName(const QString &tableName);
55 QString tableName() const;
56 bool isNull() const;
57 void setReadOnly(bool readOnly);
58 bool isReadOnly() const;
59 void clear();
60 bool isAutoValue() const;
61
62 QMetaType metaType() const;
63 void setMetaType(QMetaType type);
64
65#if QT_DEPRECATED_SINCE(6, 0)
66 QT_WARNING_PUSH
67 QT_WARNING_DISABLE_DEPRECATED
68 QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
69 QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
70 : QSqlField(fieldName, QMetaType(type), tableName)
71 {}
72 QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
73 QVariant::Type type() const { return QVariant::Type(metaType().id()); };
74 QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
75 void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
76 QT_WARNING_POP
77#endif
78
79 void setRequiredStatus(RequiredStatus status);
80 inline void setRequired(bool required)
81 { setRequiredStatus(required ? Required : Optional); }
82 void setLength(int fieldLength);
83 void setPrecision(int precision);
84 void setDefaultValue(const QVariant &value);
85#if QT_DEPRECATED_SINCE(6, 8)
86 QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
87 void setSqlType(int type);
88#endif
89 void setGenerated(bool gen);
90 void setAutoValue(bool autoVal);
91
92 RequiredStatus requiredStatus() const;
93 int length() const;
94 int precision() const;
95 QVariant defaultValue() const;
96#if QT_DEPRECATED_SINCE(6, 8)
97 QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
98 int typeID() const;
99#endif
100 bool isGenerated() const;
101 bool isValid() const;
102
103private:
104 void detach();
105 // ### Qt7: move to private class
106 QVariant val;
107 QExplicitlySharedDataPointer<QSqlFieldPrivate> d;
108};
109
110Q_DECLARE_SHARED(QSqlField)
111
112#ifndef QT_NO_DEBUG_STREAM
113Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &);
114#endif
115
116QT_END_NAMESPACE
117
118#endif // QSQLFIELD_H
119

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtbase/src/sql/kernel/qsqlfield.h