-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbmanager.cpp
More file actions
51 lines (39 loc) · 1.33 KB
/
dbmanager.cpp
File metadata and controls
51 lines (39 loc) · 1.33 KB
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"
#include "dbmanager_exceptions.h"
#include <QDir>
#include <QMessageBox>
#include <QtDebug>
#include <QPixmap>
#include <QVariant>
#include <QSqlDatabase>
#include <QSqlQuery>
// Just leave it here for future project modifications
//const std::regex DBManager::db_file_format { R"(^\w*[.](sqlite)$)" };
DBManager & DBManager::instance() {
static DBManager singleton;
return singleton;
}
DBManager::DBManager(const QString & databaseName)
: mDatabase(new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE"))),
patientDao(*mDatabase),
photoDao(*mDatabase)
{
mDatabase->setDatabaseName(qApp->applicationDirPath() + QDir::separator() + databaseName);
if (!mDatabase->open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
patientDao.init();
photoDao.init();
}
DBManager::~DBManager() {
mDatabase->close();
delete mDatabase;
}
bool DBManager::HasTable(const QString & _table) {
return mDatabase->tables().contains(_table);
}