Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsqlfield.h
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// Qt-Security score:significant reason:default
4
5#ifndef QSQLFIELD_H
6#define QSQLFIELD_H
7
8#include <QtSql/qtsqlglobal.h>
9#include <QtCore/qshareddata.h>
10#include <QtCore/qvariant.h>
11#include <QtCore/qstring.h>
12
14
15
17QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlFieldPrivate, Q_SQL_EXPORT)
18
19class Q_SQL_EXPORT QSqlField
20{
21 Q_GADGET
22 Q_PROPERTY(QVariant value READ value WRITE setValue)
23 Q_PROPERTY(QVariant defaultValue READ defaultValue WRITE setDefaultValue)
24 Q_PROPERTY(QString name READ name WRITE setName)
25 Q_PROPERTY(QString tableName READ tableName WRITE setTableName)
26 Q_PROPERTY(QMetaType metaType READ metaType WRITE setMetaType)
27 Q_PROPERTY(RequiredStatus requiredStatus READ requiredStatus WRITE setRequiredStatus)
28 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
29 Q_PROPERTY(bool generated READ isGenerated WRITE setGenerated)
30 Q_PROPERTY(bool autoValue READ isAutoValue WRITE setAutoValue)
31 Q_PROPERTY(int length READ length WRITE setLength)
32 Q_PROPERTY(int precision READ precision WRITE setPrecision)
33
34public:
35 enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
36
37 explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType(), const QString &tableName = QString());
38
39 QSqlField(const QSqlField& other);
40 QSqlField& operator=(const QSqlField& other);
41 QSqlField(QSqlField &&other) noexcept = default;
42 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlField)
43 ~QSqlField();
44
45 void swap(QSqlField &other) noexcept { val.swap(other.val); d.swap(other.d); }
46
47 bool operator==(const QSqlField& other) const;
48 inline bool operator!=(const QSqlField &other) const { return !operator==(other); }
49
50 void setValue(const QVariant& value);
51 inline QVariant value() const
52 { return val; }
53 void setName(const QString& name);
54 QString name() const;
55 void setTableName(const QString &tableName);
56 QString tableName() const;
57 bool isNull() const;
58 void setReadOnly(bool readOnly);
59 bool isReadOnly() const;
60 void clear();
61 bool isAutoValue() const;
62
63 QMetaType metaType() const;
64 void setMetaType(QMetaType type);
65
66#if QT_DEPRECATED_SINCE(6, 0)
67 QT_WARNING_PUSH
68 QT_WARNING_DISABLE_DEPRECATED
69 QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
70 QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
71 : QSqlField(fieldName, QMetaType(type), tableName)
72 {}
73 QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
74 QVariant::Type type() const { return QVariant::Type(metaType().id()); }
75 QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
76 void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
77 QT_WARNING_POP
78#endif
79
80 void setRequiredStatus(RequiredStatus status);
81 inline void setRequired(bool required)
82 { setRequiredStatus(required ? Required : Optional); }
83 void setLength(int fieldLength);
84 void setPrecision(int precision);
85 void setDefaultValue(const QVariant &value);
86#if QT_DEPRECATED_SINCE(6, 8)
87 QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
88 void setSqlType(int type);
89#endif
90 void setGenerated(bool gen);
91 void setAutoValue(bool autoVal);
92
93 RequiredStatus requiredStatus() const;
94 int length() const;
95 int precision() const;
96 QVariant defaultValue() const;
97#if QT_DEPRECATED_SINCE(6, 8)
98 QT_DEPRECATED_VERSION_X_6_8("This internal value is no longer used.")
99 int typeID() const;
100#endif
101 bool isGenerated() const;
102 bool isValid() const;
103
104private:
105 void detach();
106 // ### Qt7: move to private class
107 QVariant val;
108 QExplicitlySharedDataPointer<QSqlFieldPrivate> d;
109};
110
112
113#ifndef QT_NO_DEBUG_STREAM
114Q_SQL_EXPORT QDebug operator<<(QDebug, const QSqlField &);
115#endif
116
117QT_END_NAMESPACE
118
119#endif // QSQLFIELD_H
void qSplitTableQualifier(const QString &qualifier, QString &catalog, QString &schema, QString &table) const
Definition qsql_db2.cpp:443
QList< QVariant * > valueCache
Definition qsql_db2.cpp:115
QSqlRecord recInf
Definition qsql_db2.cpp:114
bool fetchLast() override
Positions the result to the last record (last row) in the result.
Definition qsql_db2.cpp:940
QVariant handle() const override
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVarian...
Definition qsql_db2.cpp:528
void detachFromResultSet() override
void virtual_hook(int id, void *data) override
int numRowsAffected() override
Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or i...
bool fetch(int i) override
Positions the result to an arbitrary (zero-based) row index.
Definition qsql_db2.cpp:865
bool isNull(int i) override
Returns true if the field at position index in the current row is null; otherwise returns false.
bool exec() override
Executes the query, returning true if successful; otherwise returns false.
Definition qsql_db2.cpp:613
bool fetchFirst() override
Positions the result to the first record (row 0) in the result.
Definition qsql_db2.cpp:918
int size() override
Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELE...
bool prepare(const QString &query) override
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...
Definition qsql_db2.cpp:588
QSqlRecord record() const override
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
bool fetchNext() override
Positions the result to the next available record (row) in the result.
Definition qsql_db2.cpp:900
bool reset(const QString &query) override
Sets the result to use the SQL statement query for subsequent data retrieval.
Definition qsql_db2.cpp:551
bool nextResult() override
QVariant data(int field) override
Returns the data for field index in the current row as a QVariant.
Definition qsql_db2.cpp:972
\inmodule QtCore \reentrant
Definition qdatetime.h:29
Definition qlist.h:80
The QSqlError class provides SQL database error information.
Definition qsqlerror.h:18
The QSqlField class manipulates the fields in SQL database tables and views.
Definition qsqlfield.h:20
\inmodule QtCore \reentrant
Definition qdatetime.h:250
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568
static QSqlField qMakeFieldInfo(const QDB2ResultPrivate *d, int i)
Definition qsql_db2.cpp:252
static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt)
Definition qsql_db2.cpp:469
static bool qMakeStatement(QDB2ResultPrivate *d, bool forwardOnly, bool setForwardOnly=true)
Definition qsql_db2.cpp:486
static QByteArray qGetBinaryData(SQLHANDLE hStmt, int column, SQLLEN &lengthIndicator, bool &isNull)
Definition qsql_db2.cpp:387
static void qSqlWarning(const QString &message, const T *d)
Definition qsql_db2.cpp:182
static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool &isNull)
Definition qsql_db2.cpp:347
static SQLBIGINT qGetBigIntData(SQLHANDLE hStmt, int column, bool &isNull)
Definition qsql_db2.cpp:330
static int qGetIntData(SQLHANDLE hStmt, int column, bool &isNull)
Definition qsql_db2.cpp:293
static SQLTCHAR * qToTChar(const QString &str)
Definition qsql_db2.cpp:125
static const SQLSMALLINT TABLENAMESIZE
Definition qsql_db2.cpp:40
static const SQLSMALLINT qParamType[4]
Definition qsql_db2.cpp:41
static QString qFromTChar(SQLTCHAR *str)
Definition qsql_db2.cpp:118
static const int COLNAMESIZE
Definition qsql_db2.cpp:36
static QSqlError qMakeError(const QString &err, QSqlError::ErrorType type, const T *p)
Definition qsql_db2.cpp:189
static QMetaType qDecodeDB2Type(SQLSMALLINT sqltype)
Definition qsql_db2.cpp:197
static QString qDB2Warn(const QDB2DriverPrivate *d, QStringList *errorCodes=nullptr)
Definition qsql_db2.cpp:153
static QString qWarnDB2Handle(int handleType, SQLHANDLE handle, int *errorCode)
Definition qsql_db2.cpp:130
static QString qDB2Warn(const QDB2ResultPrivate *d, QStringList *errorCodes=nullptr)
Definition qsql_db2.cpp:169
static double qGetDoubleData(SQLHANDLE hStmt, int column, bool &isNull)
Definition qsql_db2.cpp:311