-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDatabase.cpp
More file actions
77 lines (62 loc) · 2 KB
/
Database.cpp
File metadata and controls
77 lines (62 loc) · 2 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Copyright 2014 Daniel McInnes
This file is part of OpenMining.
OpenMining is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenMining is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenMining. If not, see <http://www.gnu.org/licenses/>.
*/
// standard libarary includes
#include <iostream>
// boost includes
// Qt includes
#include <QString>
#include <QStringList>
// my includes
#include "Database.h"
#include "utils/utils.h" // FN
#include "utils/Exit.h"
//#include "utils/check_argv.h"
#include "utils/get_mapped_value.h"
using namespace std;
using namespace utils;
Database::Database(const QStringList& args) : m_initialised(false)
{
m_db = QSqlDatabase::addDatabase("QPSQL");
/*check_argv(args,FN, m_requiredArgs);
for (auto str : m_requiredArgs)
{
if (get_mapped_value(args, str.c_str()) == "")
{
Exit(str, -1);
}
}*/
m_db.setHostName (get_mapped_value(args,"-host", FN));
m_db.setDatabaseName (get_mapped_value(args,"-database", FN));
m_db.setUserName (get_mapped_value(args,"-username", FN));
m_db.setPassword (get_mapped_value(args,"-password", FN));
if (m_db.open() == 0) {
std::cout << FN << "failed to open db" << std::endl;
exit (-1);
}
else
{
m_initialised = true;
std::cout << FN << "db opened ok" << std::endl;
QStringList tables = m_db.tables();
for (auto str : tables)
{
//std::cout << FN << "table: " << str.toStdString() << std::endl;
}
}
}
Database::~Database()
{
m_db.close(); // leaks memory if we don't do this. Would never have known if not for valgrind.
}