| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtSql module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 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 https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://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 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QSQLFIELD_H |
| 41 | #define QSQLFIELD_H |
| 42 | |
| 43 | #include <QtSql/qtsqlglobal.h> |
| 44 | #include <QtCore/qvariant.h> |
| 45 | #include <QtCore/qstring.h> |
| 46 | |
| 47 | QT_BEGIN_NAMESPACE |
| 48 | |
| 49 | |
| 50 | class QSqlFieldPrivate; |
| 51 | |
| 52 | class Q_SQL_EXPORT QSqlField |
| 53 | { |
| 54 | public: |
| 55 | enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 }; |
| 56 | |
| 57 | explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType(), const QString &tableName = QString()); |
| 58 | |
| 59 | QSqlField(const QSqlField& other); |
| 60 | QSqlField& operator=(const QSqlField& other); |
| 61 | bool operator==(const QSqlField& other) const; |
| 62 | inline bool operator!=(const QSqlField &other) const { return !operator==(other); } |
| 63 | ~QSqlField(); |
| 64 | |
| 65 | void setValue(const QVariant& value); |
| 66 | inline QVariant value() const |
| 67 | { return val; } |
| 68 | void setName(const QString& name); |
| 69 | QString name() const; |
| 70 | void setTableName(const QString &tableName); |
| 71 | QString tableName() const; |
| 72 | bool isNull() const; |
| 73 | void setReadOnly(bool readOnly); |
| 74 | bool isReadOnly() const; |
| 75 | void clear(); |
| 76 | bool isAutoValue() const; |
| 77 | |
| 78 | QMetaType metaType() const; |
| 79 | void setMetaType(QMetaType type); |
| 80 | |
| 81 | #if QT_DEPRECATED_SINCE(6, 0) |
| 82 | QT_WARNING_PUSH |
| 83 | QT_WARNING_DISABLE_DEPRECATED |
| 84 | QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead" ) |
| 85 | QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString()) |
| 86 | : QSqlField(fieldName, QMetaType(type), tableName) |
| 87 | {} |
| 88 | QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead" ) |
| 89 | QVariant::Type type() const { return QVariant::Type(metaType().id()); }; |
| 90 | QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead" ) |
| 91 | void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); } |
| 92 | QT_WARNING_POP |
| 93 | #endif |
| 94 | |
| 95 | void setRequiredStatus(RequiredStatus status); |
| 96 | inline void setRequired(bool required) |
| 97 | { setRequiredStatus(required ? Required : Optional); } |
| 98 | void setLength(int fieldLength); |
| 99 | void setPrecision(int precision); |
| 100 | void setDefaultValue(const QVariant &value); |
| 101 | void setSqlType(int type); |
| 102 | void setGenerated(bool gen); |
| 103 | void setAutoValue(bool autoVal); |
| 104 | |
| 105 | RequiredStatus requiredStatus() const; |
| 106 | int length() const; |
| 107 | int precision() const; |
| 108 | QVariant defaultValue() const; |
| 109 | int typeID() const; |
| 110 | bool isGenerated() const; |
| 111 | bool isValid() const; |
| 112 | |
| 113 | private: |
| 114 | void detach(); |
| 115 | QVariant val; |
| 116 | QSqlFieldPrivate* d; |
| 117 | }; |
| 118 | |
| 119 | #ifndef QT_NO_DEBUG_STREAM |
| 120 | Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &); |
| 121 | #endif |
| 122 | |
| 123 | QT_END_NAMESPACE |
| 124 | |
| 125 | #endif // QSQLFIELD_H |
| 126 | |