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
qsqlquery.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
4#ifndef QSQLQUERY_H
5#define QSQLQUERY_H
6
7#include <QtSql/qtsqlglobal.h>
8#include <QtSql/qsqldatabase.h>
9#include <QtCore/qstring.h>
10#include <QtCore/qvariant.h>
11
12// clazy:excludeall=qproperty-without-notify
14
15
16class QSqlDriver;
17class QSqlError;
18class QSqlResult;
19class QSqlRecord;
21
22
23class Q_SQL_EXPORT QSqlQuery
24{
25 Q_GADGET
26 Q_PROPERTY(bool forwardOnly READ isForwardOnly WRITE setForwardOnly)
27 Q_PROPERTY(bool positionalBindingEnabled READ isPositionalBindingEnabled WRITE setPositionalBindingEnabled)
28 Q_PROPERTY(QSql::NumericalPrecisionPolicy numericalPrecisionPolicy READ numericalPrecisionPolicy WRITE setNumericalPrecisionPolicy)
29
30public:
31 explicit QSqlQuery(QSqlResult *r);
32 explicit QSqlQuery(const QString& query = QString(), const QSqlDatabase &db = QSqlDatabase());
33 explicit QSqlQuery(const QSqlDatabase &db);
34
35#if QT_REMOVAL_QT7_DEPRECATED_SINCE(6, 2)
36 QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move construction instead.")
37 QSqlQuery(const QSqlQuery &other);
38 QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move assignment instead.")
39 QSqlQuery& operator=(const QSqlQuery &other);
40#else
41 QSqlQuery(const QSqlQuery &other) = delete;
42 QSqlQuery& operator=(const QSqlQuery &other) = delete;
43#endif
44
45 QSqlQuery(QSqlQuery &&other) noexcept
46 : d(std::exchange(other.d, nullptr))
47 {}
48 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlQuery)
49
50 ~QSqlQuery();
51
52 void swap(QSqlQuery &other) noexcept
53 { qt_ptr_swap(d, other.d); }
54
55 bool isValid() const;
56 bool isActive() const;
57 bool isNull(int field) const;
58#if QT_SQL_REMOVED_SINCE(6, 8)
59 bool isNull(const QString &name) const;
60#endif
61 bool isNull(QAnyStringView name) const;
62 int at() const;
63 QString lastQuery() const;
64 int numRowsAffected() const;
65 QSqlError lastError() const;
66 bool isSelect() const;
67 int size() const;
68 const QSqlDriver* driver() const;
69 const QSqlResult* result() const;
70 bool isForwardOnly() const;
71 QSqlRecord record() const;
72
73 void setForwardOnly(bool forward);
74 bool exec(const QString& query);
75 QVariant value(int i) const;
76#if QT_SQL_REMOVED_SINCE(6, 8)
77 QVariant value(const QString &name) const;
78#endif
79 QVariant value(QAnyStringView name) const;
80
81 void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
82 QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
83
84 void setPositionalBindingEnabled(bool enable);
85 bool isPositionalBindingEnabled() const;
86
87 bool seek(int i, bool relative = false);
88 bool next();
89 bool previous();
90 bool first();
91 bool last();
92
93 void clear();
94
95 // prepared query support
96 bool exec();
97 enum BatchExecutionMode { ValuesAsRows, ValuesAsColumns };
98 bool execBatch(BatchExecutionMode mode = ValuesAsRows);
99 bool prepare(const QString& query);
100 void bindValue(const QString& placeholder, const QVariant& val,
101 QSql::ParamType type = QSql::In);
102 void bindValue(int pos, const QVariant& val, QSql::ParamType type = QSql::In);
103 void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In);
104 QVariant boundValue(const QString& placeholder) const;
105 QVariant boundValue(int pos) const;
106 QVariantList boundValues() const;
107 QStringList boundValueNames() const;
108 QString boundValueName(int pos) const;
109 QString executedQuery() const;
110 QVariant lastInsertId() const;
111 void finish();
112 bool nextResult();
113
114#if QT_REMOVAL_QT7_DEPRECATED_SINCE(6, 2)
115 // Avoid raising warnings in QMetaType, cf. QTBUG-132752
116 using _q_hasDeprecatedCopyConstructor = void;
117#endif
118private:
119 QSqlQueryPrivate* d;
120};
121
122QT_END_NAMESPACE
123
124#endif // QSQLQUERY_H
MimerSession sessionhandle
void splitTableQualifier(const QString &qualifier, QString *schema, QString *table) const
QVector< QVariant > batch_vector
static constexpr int maxStackStringSize
static constexpr int lobChunkMaxSizeSet
bool fetchNext() override
Positions the result to the next available record (row) in the result.
bool reset(const QString &query) override
Sets the result to use the SQL statement query for subsequent data retrieval.
bool prepare(const QString &query) override
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...
QVariant data(int i) override
Returns the data for field index in the current row as a QVariant.
static constexpr int maxDateStringSize
QSqlRecord record() const override
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
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...
QVariant handle() const override
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVarian...
static constexpr int maxTimeStringSize
static constexpr int genericError
bool fetchLast() override
Positions the result to the last record (last row) in the result.
static constexpr int lobChunkMaxSizeFetch
bool fetch(int i) override
Positions the result to an arbitrary (zero-based) row index.
bool execBatch(bool arrayBind=false) override
bool isNull(int index) override
Returns true if the field at position index in the current row is null; otherwise returns false.
bool fetchFirst() override
Positions the result to the first record (row 0) in the result.
int numRowsAffected() override
Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or i...
QMimerSQLResult(const QMimerSQLDriver *db)
static constexpr int maxTimestampStringSize
virtual ~QMimerSQLResult() override
bool exec() override
Executes the query, returning true if successful; otherwise returns false.
QVariant lastInsertId() const override
Returns the object ID of the most recent inserted row if the database supports it.
The QSqlField class manipulates the fields in SQL database tables and views.
Definition qsqlfield.h:19
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition qsqlquery.h:24
Combined button and popup list for selecting options.
#define qCWarning(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
#define Q_DECLARE_OPAQUE_POINTER(POINTER)
Definition qmetatype.h:1500
#define Q_DECLARE_METATYPE(TYPE)
Definition qmetatype.h:1508
static QSqlError qMakeError(const QString &err, const int errCode, QSqlError::ErrorType type, const QMimerSQLDriverPrivate *p)
static MimerColumnTypes mimerMapColumnTypes(int32_t t)
static QString msgCouldNotGet(const char *type, int column)
static QMetaType::Type qDecodeMSQLType(int32_t t)
static QString msgCouldNotSet(const char *type, int column)
static int32_t qLookupMimDataType(QStringView s)
MimerColumnTypes
#define MIMER_DEFAULT_DATATYPE