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 "Utils/Pimpl.h"
25 #include <QObject>
26 
27 class QSqlDatabase;
28 
29 namespace DB
30 {
31  class Base : public QObject
32  {
33  PIMPL(Base)
34 
35  public:
36  explicit Base(DbId db_id, const QString& db_dir, const QString& db_name, QObject *parent=nullptr);
37  virtual ~Base();
38 
39  virtual bool close_db();
40  virtual bool is_initialized();
41 
42  virtual void transaction();
43  virtual void commit();
44  virtual void rollback();
45 
46  DbId db_id() const;
47 
48 
49  protected:
50  virtual bool exists();
51  virtual bool create_db();
52  virtual QSqlDatabase open_db();
53  virtual bool apply_fixes()=0;
54 
55  virtual bool check_and_insert_column(const QString& tablename, const QString& column, const QString& sqltype, const QString& default_value=QString());
56  virtual bool check_and_create_table(const QString& tablename, const QString& sql_create_str);
57  virtual bool check_and_drop_table(const QString& tablename);
58 
59 
60  QSqlDatabase db() const;
61  };
62 }
63 
64 #endif // ABSTRACTDATABASE_H
Definition: AbstractDatabase.h:31
Definition: AbstractDatabase.h:29