1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 Jerzy Kozera
4 ** Contact: https://go.zealdocs.org/l/contact
5 **
6 ** This file is part of Zeal.
7 **
8 ** Zeal is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation, either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Zeal is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
20 **
21 ****************************************************************************/
22 
23 #ifndef ZEAL_UTIL_SQLITEDATABASE_H
24 #define ZEAL_UTIL_SQLITEDATABASE_H
25 
26 #include <QStringList>
27 #include <QVariant>
28 
29 struct sqlite3;
30 struct sqlite3_stmt;
31 
32 namespace Zeal {
33 namespace Util {
34 
35 class SQLiteDatabase
36 {
37 public:
38     explicit SQLiteDatabase(const QString &path);
39     virtual ~SQLiteDatabase();
40 
41     bool isOpen() const;
42 
43     QStringList tables();
44     QStringList views();
45 
46     bool prepare(const QString &sql);
47     bool next();
48 
49     bool execute(const QString &sql);
50 
51     QVariant value(int index) const;
52 
53     QString lastError() const;
54 
55     sqlite3 *handle() const;
56 
57 private:
58     void close();
59     void finalize();
60     void updateLastError();
61 
62     sqlite3 *m_db = nullptr;
63     sqlite3_stmt *m_stmt = nullptr;
64     QString m_lastError;
65 };
66 
67 } // namespace Util
68 } // namespace Zeal
69 
70 #endif // ZEAL_UTIL_SQLITEDATABASE_H
71