File indexing completed on 2026-05-21 08:32:30
0001
0002
0003
0004
0005 #ifndef QSQLFIELD_H
0006 #define QSQLFIELD_H
0007
0008 #include <QtSql/qtsqlglobal.h>
0009 #include <QtCore/qshareddata.h>
0010 #include <QtCore/qvariant.h>
0011 #include <QtCore/qstring.h>
0012
0013 QT_BEGIN_NAMESPACE
0014
0015
0016 class QSqlFieldPrivate;
0017 QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlFieldPrivate, Q_SQL_EXPORT)
0018
0019 class Q_SQL_EXPORT QSqlField
0020 {
0021 Q_GADGET
0022 Q_PROPERTY(QVariant value READ value WRITE setValue)
0023 Q_PROPERTY(QVariant defaultValue READ defaultValue WRITE setDefaultValue)
0024 Q_PROPERTY(QString name READ name WRITE setName)
0025 Q_PROPERTY(QString tableName READ tableName WRITE setTableName)
0026 Q_PROPERTY(QMetaType metaType READ metaType WRITE setMetaType)
0027 Q_PROPERTY(RequiredStatus requiredStatus READ requiredStatus WRITE setRequiredStatus)
0028 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
0029 Q_PROPERTY(bool generated READ isGenerated WRITE setGenerated)
0030 Q_PROPERTY(bool autoValue READ isAutoValue WRITE setAutoValue)
0031 Q_PROPERTY(int length READ length WRITE setLength)
0032 Q_PROPERTY(int precision READ precision WRITE setPrecision)
0033
0034 public:
0035 enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
0036
0037 explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType(), const QString &tableName = QString());
0038
0039 QSqlField(const QSqlField& other);
0040 QSqlField& operator=(const QSqlField& other);
0041 QSqlField(QSqlField &&other) noexcept = default;
0042 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlField)
0043 ~QSqlField();
0044
0045 void swap(QSqlField &other) noexcept { val.swap(other.val); d.swap(other.d); }
0046
0047 bool operator==(const QSqlField& other) const;
0048 inline bool operator!=(const QSqlField &other) const { return !operator==(other); }
0049
0050 void setValue(const QVariant& value);
0051 inline QVariant value() const
0052 { return val; }
0053 void setName(const QString& name);
0054 QString name() const;
0055 void setTableName(const QString &tableName);
0056 QString tableName() const;
0057 bool isNull() const;
0058 void setReadOnly(bool readOnly);
0059 bool isReadOnly() const;
0060 void clear();
0061 bool isAutoValue() const;
0062
0063 QMetaType metaType() const;
0064 void setMetaType(QMetaType type);
0065
0066 #if QT_DEPRECATED_SINCE(6, 0)
0067 QT_WARNING_PUSH
0068 QT_WARNING_DISABLE_DEPRECATED
0069 QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
0070 QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
0071 : QSqlField(fieldName, QMetaType(type), tableName)
0072 {}
0073 QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
0074 QVariant::Type type() const { return QVariant::Type(metaType().id()); }
0075 QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
0076 void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
0077 QT_WARNING_POP
0078 #endif
0079
0080 void setRequiredStatus(RequiredStatus status);
0081 inline void setRequired(bool required)
0082 { setRequiredStatus(required ? Required : Optional); }
0083 void setLength(int fieldLength);
0084 void setPrecision(int precision);
0085 void setDefaultValue(const QVariant &value);
0086 #if QT_DEPRECATED_SINCE(6, 8)
0087 QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
0088 void setSqlType(int type);
0089 #endif
0090 void setGenerated(bool gen);
0091 void setAutoValue(bool autoVal);
0092
0093 RequiredStatus requiredStatus() const;
0094 int length() const;
0095 int precision() const;
0096 QVariant defaultValue() const;
0097 #if QT_DEPRECATED_SINCE(6, 8)
0098 QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
0099 int typeID() const;
0100 #endif
0101 bool isGenerated() const;
0102 bool isValid() const;
0103
0104 private:
0105 void detach();
0106
0107 QVariant val;
0108 QExplicitlySharedDataPointer<QSqlFieldPrivate> d;
0109 };
0110
0111 Q_DECLARE_SHARED(QSqlField)
0112
0113 #ifndef QT_NO_DEBUG_STREAM
0114 Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &);
0115 #endif
0116
0117 QT_END_NAMESPACE
0118
0119 #endif