File indexing completed on 2024-05-12 04:58:28
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2014-2018 David Rosca <nowrep@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 #ifndef SQLDATABASE_H 0019 #define SQLDATABASE_H 0020 0021 #include <QSqlQuery> 0022 #include <QSqlError> 0023 #include <QSqlRecord> 0024 0025 #include "qzcommon.h" 0026 0027 class FALKON_EXPORT SqlQueryJob : public QObject 0028 { 0029 Q_OBJECT 0030 0031 public: 0032 explicit SqlQueryJob(QObject *parent = nullptr); 0033 explicit SqlQueryJob(const QString &query, QObject *parent = nullptr); 0034 0035 void setQuery(const QString &query); 0036 void addBindValue(const QVariant &value); 0037 0038 QSqlError error() const; 0039 QVariant lastInsertId() const; 0040 QVector<QSqlRecord> records() const; 0041 0042 void start(); 0043 0044 Q_SIGNALS: 0045 void finished(SqlQueryJob *job); 0046 0047 private: 0048 QString m_query; 0049 QVector<QVariant> m_boundValues; 0050 QSqlError m_error; 0051 QVariant m_lastInsertId; 0052 QVector<QSqlRecord> m_records; 0053 }; 0054 0055 class FALKON_EXPORT SqlDatabase : public QObject 0056 { 0057 Q_OBJECT 0058 0059 public: 0060 explicit SqlDatabase(QObject* parent = nullptr); 0061 ~SqlDatabase(); 0062 0063 // Returns database connection for current thread 0064 QSqlDatabase database(); 0065 0066 // Sets database to be created for other threads 0067 void setDatabase(const QSqlDatabase &database); 0068 0069 static SqlDatabase* instance(); 0070 0071 private: 0072 QString m_databaseName; 0073 QString m_connectOptions; 0074 }; 0075 0076 #endif // SQLDATABASE_H