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 | QT_BEGIN_NAMESPACE |
13 | |
14 | |
15 | class QSqlDriver; |
16 | class QSqlError; |
17 | class QSqlResult; |
18 | class QSqlRecord; |
19 | class QSqlQueryPrivate; |
20 | |
21 | |
22 | class Q_SQL_EXPORT QSqlQuery |
23 | { |
24 | public: |
25 | explicit QSqlQuery(QSqlResult *r); |
26 | explicit QSqlQuery(const QString& query = QString(), const QSqlDatabase &db = QSqlDatabase()); |
27 | explicit QSqlQuery(const QSqlDatabase &db); |
28 | |
29 | #if QT_DEPRECATED_SINCE(6, 2) |
30 | QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move construction instead." ) |
31 | QSqlQuery(const QSqlQuery &other); |
32 | QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move assignment instead." ) |
33 | QSqlQuery& operator=(const QSqlQuery &other); |
34 | #else |
35 | QSqlQuery(const QSqlQuery &other) = delete; |
36 | QSqlQuery& operator=(const QSqlQuery &other) = delete; |
37 | #endif |
38 | |
39 | QSqlQuery(QSqlQuery &&other) noexcept |
40 | : d(std::exchange(obj&: other.d, new_val: nullptr)) |
41 | {} |
42 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlQuery) |
43 | |
44 | ~QSqlQuery(); |
45 | |
46 | void swap(QSqlQuery &other) noexcept |
47 | { qt_ptr_swap(lhs&: d, rhs&: other.d); } |
48 | |
49 | bool isValid() const; |
50 | bool isActive() const; |
51 | bool isNull(int field) const; |
52 | bool isNull(const QString &name) const; |
53 | int at() const; |
54 | QString lastQuery() const; |
55 | int numRowsAffected() const; |
56 | QSqlError lastError() const; |
57 | bool isSelect() const; |
58 | int size() const; |
59 | const QSqlDriver* driver() const; |
60 | const QSqlResult* result() const; |
61 | bool isForwardOnly() const; |
62 | QSqlRecord record() const; |
63 | |
64 | void setForwardOnly(bool forward); |
65 | bool exec(const QString& query); |
66 | QVariant value(int i) const; |
67 | QVariant value(const QString& name) const; |
68 | |
69 | void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); |
70 | QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; |
71 | |
72 | bool seek(int i, bool relative = false); |
73 | bool next(); |
74 | bool previous(); |
75 | bool first(); |
76 | bool last(); |
77 | |
78 | void clear(); |
79 | |
80 | // prepared query support |
81 | bool exec(); |
82 | enum BatchExecutionMode { ValuesAsRows, ValuesAsColumns }; |
83 | bool execBatch(BatchExecutionMode mode = ValuesAsRows); |
84 | bool prepare(const QString& query); |
85 | void bindValue(const QString& placeholder, const QVariant& val, |
86 | QSql::ParamType type = QSql::In); |
87 | void bindValue(int pos, const QVariant& val, QSql::ParamType type = QSql::In); |
88 | void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In); |
89 | QVariant boundValue(const QString& placeholder) const; |
90 | QVariant boundValue(int pos) const; |
91 | QVariantList boundValues() const; |
92 | QStringList boundValueNames() const; |
93 | QString boundValueName(int pos) const; |
94 | QString executedQuery() const; |
95 | QVariant lastInsertId() const; |
96 | void finish(); |
97 | bool nextResult(); |
98 | |
99 | private: |
100 | QSqlQueryPrivate* d; |
101 | }; |
102 | |
103 | QT_END_NAMESPACE |
104 | |
105 | #endif // QSQLQUERY_H |
106 | |