-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.cpp
More file actions
executable file
·68 lines (51 loc) · 1.08 KB
/
Copy pathdb.cpp
File metadata and controls
executable file
·68 lines (51 loc) · 1.08 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
#include "db.h"
DB::DB()
{
}
bool DB::open()
{
this->db = QSqlDatabase::addDatabase(DRIVER);
this->db.setHostName(HOST);
this->db.setDatabaseName(DATABASE);
this->db.setUserName(USER);
this->db.setPassword(PASSWORD);
bool ok = this->db.open();
qDebug() << this->db.driverName();
if(!ok)
this->error = this->db.lastError().text();
return ok;
}
QString DB::getResult()
{
return this->result;
}
void DB::doQuery(QString sql)
{
if(this->db.isOpen())
{
QSqlDatabase::database().transaction();
QSqlQuery query;
if(query.exec(sql))
{
while (query.next())
{
QString name = query.value(0).toString();
this->result = this->result + name + "\n";
//qDebug() << name << salary;
}
}
else
{
this->result = "";
}
QSqlDatabase::database().commit();
}
else
{
qDebug() << "Not open ....";
}
}
QString DB::getError()
{
return this->error;
}