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{
20public:
21 enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
22
23 explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType(), const QString &tableName = QString());
24
25 QSqlField(const QSqlField& other);
26 QSqlField& operator=(const QSqlField& other);
27 QSqlField(QSqlField &&other) noexcept = default;
28 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlField)
29 ~QSqlField();
30
31 void swap(QSqlField &other) noexcept { val.swap(other&: other.val); d.swap(other&: other.d); }
32
33 bool operator==(const QSqlField& other) const;
34 inline bool operator!=(const QSqlField &other) const { return !operator==(other); }
35
36 void setValue(const QVariant& value);
37 inline QVariant value() const
38 { return val; }
39 void setName(const QString& name);
40 QString name() const;
41 void setTableName(const QString &tableName);
42 QString tableName() const;
43 bool isNull() const;
44 void setReadOnly(bool readOnly);
45 bool isReadOnly() const;
46 void clear();
47 bool isAutoValue() const;
48
49 QMetaType metaType() const;
50 void setMetaType(QMetaType type);
51
52#if QT_DEPRECATED_SINCE(6, 0)
53 QT_WARNING_PUSH
54 QT_WARNING_DISABLE_DEPRECATED
55 QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
56 QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
57 : QSqlField(fieldName, QMetaType(type), tableName)
58 {}
59 QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
60 QVariant::Type type() const { return QVariant::Type(metaType().id()); };
61 QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
62 void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
63 QT_WARNING_POP
64#endif
65
66 void setRequiredStatus(RequiredStatus status);
67 inline void setRequired(bool required)
68 { setRequiredStatus(required ? Required : Optional); }
69 void setLength(int fieldLength);
70 void setPrecision(int precision);
71 void setDefaultValue(const QVariant &value);
72 void setSqlType(int type);
73 void setGenerated(bool gen);
74 void setAutoValue(bool autoVal);
75
76 RequiredStatus requiredStatus() const;
77 int length() const;
78 int precision() const;
79 QVariant defaultValue() const;
80 int typeID() const;
81 bool isGenerated() const;
82 bool isValid() const;
83
84private:
85 void detach();
86 // ### Qt7: move to private class
87 QVariant val;
88 QExplicitlySharedDataPointer<QSqlFieldPrivate> d;
89};
90
91Q_DECLARE_SHARED(QSqlField)
92
93#ifndef QT_NO_DEBUG_STREAM
94Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &);
95#endif
96
97QT_END_NAMESPACE
98
99#endif // QSQLFIELD_H
100

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