| 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 |
| 13 | QT_BEGIN_NAMESPACE |
| 14 | |
| 15 | |
| 16 | class QSqlDriver; |
| 17 | class QSqlError; |
| 18 | class QSqlResult; |
| 19 | class QSqlRecord; |
| 20 | class QSqlQueryPrivate; |
| 21 | |
| 22 | |
| 23 | class 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 | |
| 30 | public: |
| 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_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(obj&: other.d, new_val: 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(lhs&: d, rhs&: 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 | private: |
| 115 | QSqlQueryPrivate* d; |
| 116 | }; |
| 117 | |
| 118 | QT_END_NAMESPACE |
| 119 | |
| 120 | #endif // QSQLQUERY_H |
| 121 | |