-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdbmanager.cpp
More file actions
51 lines (40 loc) · 1008 Bytes
/
Copy pathdbmanager.cpp
File metadata and controls
51 lines (40 loc) · 1008 Bytes
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
#include "dbmanager.h"
// initialisation de l'instance a null
DBManager* DBManager::instance = nullptr;
DBManager::DBManager()
{
db = QSqlDatabase::addDatabase("QSQLITE");
QString dbFullPath = "C:\\Qt-workspace\\banking-system\\db\\banking_system.db";
db.setDatabaseName(dbFullPath);
qDebug("Connection opened successfully with database.");
qDebug("Singleton DBManager initialized.");
qDebug() << db.databaseName();
}
bool DBManager::open()
{
if (db.isOpen()) return true;
if (db.open()) return true;
else
{
qDebug("Failed to open connection.");
return false;
}
}
void DBManager::close()
{
if (db.isOpen()) db.close();
}
DBManager* DBManager::getInstance()
{
if (instance == nullptr) instance = new DBManager();
return instance;
}
void DBManager::release()
{
if (instance != nullptr)
{
delete instance;
qDebug("Suppression du Singleton DBManager effectuéé.");
}
}
DBManager::~DBManager() {}