Sayonara Player
AbstractDatabase.h
1 /* AbstractDatabase.h */
2 
3 /* Copyright (C) 2011-2017 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef ABSTRACTDATABASE_H
22 #define ABSTRACTDATABASE_H
23 
24 #include <QObject>
25 #include <QSqlDatabase>
26 
27 class AbstractDatabase : public QObject
28 {
29 public:
30  explicit AbstractDatabase(quint8 db_id, const QString& db_dir, const QString& db_name, QObject *parent=nullptr);
31  virtual ~AbstractDatabase();
32 
33  virtual void close_db();
34  virtual bool is_initialized();
35 
36  virtual void transaction();
37  virtual void commit();
38  virtual void rollback();
39 
40  quint8 get_id();
41 
42 
43 protected:
44  QSqlDatabase _database;
45  QString _db_path;
46  QString _db_name;
47  QString _db_dir;
48  quint8 _db_id;
49 
55 
56  virtual bool exists();
57  virtual bool create_db();
58  virtual bool open_db();
59  virtual bool apply_fixes()=0;
60 
61  virtual bool check_and_insert_column(const QString& tablename, const QString& column, const QString& sqltype, const QString& default_value=QString());
62  virtual bool check_and_create_table(const QString& tablename, const QString& sql_create_str);
63  virtual bool check_and_drop_table(const QString& tablename);
64 };
65 
66 #endif // ABSTRACTDATABASE_H
Definition: AbstractDatabase.h:27
bool _initialized
Definition: AbstractDatabase.h:54