Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:11:28

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