/
database.h
73 lines (55 loc) · 1.75 KB
/
database.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// This file is part of Piqs.
//
// Piqs is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Piqs is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Piqs. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef DATABASE_H
#define DATABASE_H
#include <QSqlDatabase>
#include <QHash>
class QDir;
class Picture;
class Tags;
//! Database access
class Database : public QObject
{
Q_OBJECT
public:
explicit Database(const QDir& metadir, QObject *parent = 0);
~Database();
//! Is the database opened succesfully?
bool isOpen() const { return m_db.isOpen(); }
//! Get the database connection
QSqlDatabase get() const { return m_db; }
//! Get the name of the database connection
const QString& name() const { return m_dbname; }
//! Escape text for use in SQL queries
QString esc(const QString& text) const;
Tags *tags() { return m_tags; }
const Tags *tags() const { return m_tags; }
//! Save a configuration value
void saveSetting(const QString& key, const QVariant& value) const;
//! Get a configuration value
QVariant getSetting(const QString& key) const;
//! Alert the user of database errors
static void showError(const QString& message, const QSqlQuery &query);
signals:
public slots:
private:
static int dbindex;
QString m_dbname;
QSqlDatabase m_db;
Tags *m_tags;
};
#endif // DATABASE_H