Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-05 08:49:00

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QSQLQUERY_H
0006 #define QSQLQUERY_H
0007 
0008 #include <QtSql/qtsqlglobal.h>
0009 #include <QtSql/qsqldatabase.h>
0010 #include <QtCore/qstring.h>
0011 #include <QtCore/qvariant.h>
0012 
0013 // clazy:excludeall=qproperty-without-notify
0014 QT_BEGIN_NAMESPACE
0015 
0016 
0017 class QSqlDriver;
0018 class QSqlError;
0019 class QSqlResult;
0020 class QSqlRecord;
0021 class QSqlQueryPrivate;
0022 
0023 
0024 class Q_SQL_EXPORT QSqlQuery
0025 {
0026     Q_GADGET
0027     Q_PROPERTY(bool forwardOnly READ isForwardOnly WRITE setForwardOnly)
0028     Q_PROPERTY(bool positionalBindingEnabled READ isPositionalBindingEnabled WRITE setPositionalBindingEnabled)
0029     Q_PROPERTY(QSql::NumericalPrecisionPolicy numericalPrecisionPolicy READ numericalPrecisionPolicy WRITE setNumericalPrecisionPolicy)
0030 
0031 public:
0032     explicit QSqlQuery(QSqlResult *r);
0033     explicit QSqlQuery(const QString& query = QString(), const QSqlDatabase &db = QSqlDatabase());
0034     explicit QSqlQuery(const QSqlDatabase &db);
0035 
0036 #if QT_REMOVAL_QT7_DEPRECATED_SINCE(6, 2)
0037     QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move construction instead.")
0038     QSqlQuery(const QSqlQuery &other);
0039     QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move assignment instead.")
0040     QSqlQuery& operator=(const QSqlQuery &other);
0041 #else
0042     QSqlQuery(const QSqlQuery &other) = delete;
0043     QSqlQuery& operator=(const QSqlQuery &other) = delete;
0044 #endif
0045 
0046     QSqlQuery(QSqlQuery &&other) noexcept
0047         : d(std::exchange(other.d, nullptr))
0048     {}
0049     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlQuery)
0050 
0051     ~QSqlQuery();
0052 
0053     void swap(QSqlQuery &other) noexcept
0054     { qt_ptr_swap(d, other.d); }
0055 
0056     bool isValid() const;
0057     bool isActive() const;
0058     bool isNull(int field) const;
0059 #if QT_SQL_REMOVED_SINCE(6, 8)
0060     bool isNull(const QString &name) const;
0061 #endif
0062     bool isNull(QAnyStringView name) const;
0063     int at() const;
0064     QString lastQuery() const;
0065     int numRowsAffected() const;
0066     QSqlError lastError() const;
0067     bool isSelect() const;
0068     int size() const;
0069     const QSqlDriver* driver() const;
0070     const QSqlResult* result() const;
0071     bool isForwardOnly() const;
0072     QSqlRecord record() const;
0073 
0074     void setForwardOnly(bool forward);
0075     bool exec(const QString& query);
0076     QVariant value(int i) const;
0077 #if QT_SQL_REMOVED_SINCE(6, 8)
0078     QVariant value(const QString &name) const;
0079 #endif
0080     QVariant value(QAnyStringView name) const;
0081 
0082     void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
0083     QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
0084 
0085     void setPositionalBindingEnabled(bool enable);
0086     bool isPositionalBindingEnabled() const;
0087 
0088     bool seek(int i, bool relative = false);
0089     bool next();
0090     bool previous();
0091     bool first();
0092     bool last();
0093 
0094     void clear();
0095 
0096     // prepared query support
0097     bool exec();
0098     enum BatchExecutionMode { ValuesAsRows, ValuesAsColumns };
0099     bool execBatch(BatchExecutionMode mode = ValuesAsRows);
0100     bool prepare(const QString& query);
0101     void bindValue(const QString& placeholder, const QVariant& val,
0102                    QSql::ParamType type = QSql::In);
0103     void bindValue(int pos, const QVariant& val, QSql::ParamType type = QSql::In);
0104     void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In);
0105     QVariant boundValue(const QString& placeholder) const;
0106     QVariant boundValue(int pos) const;
0107     QVariantList boundValues() const;
0108     QStringList boundValueNames() const;
0109     QString boundValueName(int pos) const;
0110     QString executedQuery() const;
0111     QVariant lastInsertId() const;
0112     void finish();
0113     bool nextResult();
0114 
0115 #if QT_REMOVAL_QT7_DEPRECATED_SINCE(6, 2)
0116     // Avoid raising warnings in QMetaType, cf. QTBUG-132752
0117     using _q_hasDeprecatedCopyConstructor = void;
0118 #endif
0119 private:
0120     QSqlQueryPrivate* d;
0121 };
0122 
0123 QT_END_NAMESPACE
0124 
0125 #endif // QSQLQUERY_H