File indexing completed on 2025-01-05 04:26:49
0001 /* 0002 * Replacement fot QT Bindings that were removed from QT5 0003 * Copyright (C) 2020 Pedro de Carvalho Gomes <pedrogomes81@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #ifndef SQLSQLQUERY_H 0020 #define SQLSQLQUERY_H 0021 0022 #include "QtBinding.h" 0023 0024 #include <QObject> 0025 #include <QSqlError> 0026 #include <QSqlQuery> 0027 #include <QSqlRecord> 0028 0029 namespace QtBindings 0030 { 0031 namespace Sql 0032 { 0033 class SqlQuery : public QObject, public QSqlQuery, public QtBindings::Base<SqlQuery> 0034 { 0035 Q_OBJECT 0036 public: 0037 Q_INVOKABLE SqlQuery(QSqlResult *r); 0038 Q_INVOKABLE SqlQuery(const QString& query = QString(), QSqlDatabase db = QSqlDatabase()); 0039 Q_INVOKABLE SqlQuery(QSqlDatabase db); 0040 Q_INVOKABLE explicit SqlQuery(const QSqlQuery& other); 0041 Q_INVOKABLE SqlQuery(const SqlQuery& other); 0042 SqlQuery &operator=(const SqlQuery& other); 0043 public slots: 0044 void addBindValue(const QVariant& val, QSql::ParamType type = QSql::In); 0045 int at() const; 0046 void bindValue(const QString& placeholder, const QVariant& val, QSql::ParamType type = QSql::In); 0047 void bindValue(int pos, const QVariant& val, QSql::ParamType type = QSql::In); 0048 QVariant boundValue(const QString& placeholder) const; 0049 QVariant boundValue(int pos) const; 0050 void clear(); 0051 const QSqlDriver* driver() const; 0052 bool exec(); 0053 bool execBatch(BatchExecutionMode mode = ValuesAsRows); 0054 bool exec(const QString& query); 0055 QString executedQuery() const; 0056 void finish(); 0057 bool first(); 0058 bool isActive() const; 0059 bool isForwardOnly() const; 0060 bool isNull(const QString &name) const; 0061 bool isNull(int field) const; 0062 bool isSelect() const; 0063 bool isValid() const; 0064 bool last(); 0065 QSqlError lastError() const; 0066 QVariant lastInsertId() const; 0067 QString lastQuery() const; 0068 bool next(); 0069 bool nextResult(); 0070 QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const; 0071 int numRowsAffected() const; 0072 bool prepare(const QString& query); 0073 bool previous(); 0074 QMap<QString, QVariant> boundValues() const; 0075 QSqlRecord record() const; 0076 const QSqlResult* result() const; 0077 bool seek(int i, bool relative = false); 0078 void setForwardOnly(bool forward); 0079 void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy); 0080 int size() const; 0081 QVariant value(const QString& name) const; 0082 QVariant value(int i) const; 0083 }; 0084 } 0085 } 0086 Q_DECLARE_METATYPE(QtBindings::Sql::SqlQuery) 0087 #endif //SQLSQLQUERY_H