Falkon Develop
Cross-platform Qt-based web browser
sqldatabase.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2014-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#ifndef SQLDATABASE_H
19#define SQLDATABASE_H
20
21#include <QSqlQuery>
22#include <QSqlError>
23#include <QSqlRecord>
24
25#include "qzcommon.h"
26
27class FALKON_EXPORT SqlQueryJob : public QObject
28{
29 Q_OBJECT
30
31public:
32 explicit SqlQueryJob(QObject *parent = nullptr);
33 explicit SqlQueryJob(const QString &query, QObject *parent = nullptr);
34
35 void setQuery(const QString &query);
36 void addBindValue(const QVariant &value);
37
38 QSqlError error() const;
39 QVariant lastInsertId() const;
40 int numRowsAffected() const;
41 QVector<QSqlRecord> records() const;
42
43 void start();
44
45Q_SIGNALS:
47
48private:
49 QString m_query;
50 QVector<QVariant> m_boundValues;
51 QSqlError m_error;
52 QVariant m_lastInsertId;
53 int m_numRowsAffected;
54 QVector<QSqlRecord> m_records;
55};
56
57class FALKON_EXPORT SqlDatabase : public QObject
58{
59 Q_OBJECT
60
61public:
62 explicit SqlDatabase(QObject* parent = nullptr);
64
65 // Returns database connection for current thread
66 QSqlDatabase database();
67
68 // Sets database to be created for other threads
69 void setDatabase(const QSqlDatabase &database);
70
71 static SqlDatabase* instance();
72
73private:
74 QString m_databaseName;
75 QString m_connectOptions;
76};
77
78#endif // SQLDATABASE_H
void finished(SqlQueryJob *job)
int value(const QColor &c)
Definition: colors.cpp:238
#define FALKON_EXPORT
Definition: qzcommon.h:28