Sayonara Player
DatabaseModule.h
1 /* DatabaseModule.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 DATABASEMODULE_H
22 #define DATABASEMODULE_H
23 
24 #include <QSqlDatabase>
25 
26 
27 #define DB_TRY_OPEN(db) if (!this -> db.isOpen()) \
28  this -> db.open()
29 
30 #define DB_RETURN_NOT_OPEN_VOID(db) DB_TRY_OPEN(db); \
31  if (!this -> db.isOpen()) \
32  return
33 
34 #define DB_RETURN_NOT_OPEN_INT(db) DB_TRY_OPEN(db); \
35  if (!this -> db.isOpen()) \
36  return -1
37 
38 #define DB_RETURN_NOT_OPEN_BOOL(db) DB_TRY_OPEN(db); \
39  if (!this -> db.isOpen()) \
40  return false
41 
42 #define DB_RETURN_NOT_OPEN_STRING(db) DB_TRY_OPEN(db); \
43  if(!this->db.isOpen()) \
44  return ""
45 
46 class SayonaraQuery;
48 {
49 protected:
50 
51  QSqlDatabase _db;
52  quint8 _module_db_id;
53 
54 public:
55  DatabaseModule(const QSqlDatabase& db, quint8 db_id);
56 };
57 
58 #endif // DATABASEMODULE_H
Definition: SayonaraQuery.h:30
Definition: DatabaseModule.h:47