File indexing completed on 2025-01-18 10:09:18
0001
0002
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 QT_BEGIN_NAMESPACE
0013
0014
0015 class QSqlDriver;
0016 class QSqlError;
0017 class QSqlResult;
0018 class QSqlRecord;
0019 class QSqlQueryPrivate;
0020
0021
0022 class Q_SQL_EXPORT QSqlQuery
0023 {
0024 public:
0025 explicit QSqlQuery(QSqlResult *r);
0026 explicit QSqlQuery(const QString& query = QString(), const QSqlDatabase &db = QSqlDatabase());
0027 explicit QSqlQuery(const QSqlDatabase &db);
0028
0029 #if QT_DEPRECATED_SINCE(6, 2)
0030 QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move construction instead.")
0031 QSqlQuery(const QSqlQuery &other);
0032 QT_DEPRECATED_VERSION_X_6_2("QSqlQuery is not meant to be copied. Use move assignment instead.")
0033 QSqlQuery& operator=(const QSqlQuery &other);
0034 #else
0035 QSqlQuery(const QSqlQuery &other) = delete;
0036 QSqlQuery& operator=(const QSqlQuery &other) = delete;
0037 #endif
0038
0039 QSqlQuery(QSqlQuery &&other) noexcept
0040 : d(std::exchange(other.d, nullptr))
0041 {}
0042 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlQuery)
0043
0044 ~QSqlQuery();
0045
0046 void swap(QSqlQuery &other) noexcept
0047 { qt_ptr_swap(d, other.d); }
0048
0049 bool isValid() const;
0050 bool isActive() const;
0051 bool isNull(int field) const;
0052 bool isNull(const QString &name) const;
0053 int at() const;
0054 QString lastQuery() const;
0055 int numRowsAffected() const;
0056 QSqlError lastError() const;
0057 bool isSelect() const;
0058 int size() const;
0059 const QSqlDriver* driver() const;
0060 const QSqlResult* result() const;
0061 bool isForwardOnly() const;
0062 QSqlRecord record() const;
0063
0064 void setForwardOnly(bool forward);
0065 bool exec(const QString& query);
0066 QVariant value(int i) const;
0067 QVariant value(const QString& name) const;
0068
0069 void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy);
0070 QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const;
0071
0072 void setPositionalBindingEnabled(bool enable);
0073 bool isPositionalBindingEnabled() const;
0074
0075 bool seek(int i, bool relative = false);
0076 bool next();
0077 bool previous();
0078 bool first();
0079 bool last();
0080
0081 void clear();
0082
0083
0084 bool exec();
0085 enum BatchExecutionMode { ValuesAsRows, ValuesAsColumns };
0086 bool execBatch(BatchExecutionMode mode = ValuesAsRows);
0087 bool prepare(const QString& query);
0088 void bindValue(const QString& placeholder, const QVariant& val,
0089 QSql::ParamType type = QSql::In);
0090 void bindValue(int pos, const QVariant& val, QSql::ParamType type = QSql::In);
0091 void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In);
0092 QVariant boundValue(const QString& placeholder) const;
0093 QVariant boundValue(int pos) const;
0094 QVariantList boundValues() const;
0095 QStringList boundValueNames() const;
0096 QString boundValueName(int pos) const;
0097 QString executedQuery() const;
0098 QVariant lastInsertId() const;
0099 void finish();
0100 bool nextResult();
0101
0102 private:
0103 QSqlQueryPrivate* d;
0104 };
0105
0106 QT_END_NAMESPACE
0107
0108 #endif