-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTypeThread.cpp
65 lines (60 loc) · 2.22 KB
/
TypeThread.cpp
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
//
// Created by Mac on 27/04/2019.
//
#include <string>
#include <mysql/mysql.h>
#include <cstring>
#include <cstdlib>
#include "TypeThread.h"
#include "dbase.h"
#include "errors.h"
uint32_t TypeThread::getAllThreads(TypeThread **dstPtr) {
DBase dBase;
static MYSQL_RES *res;
static MYSQL_ROW row;
static char query[500];
struct tm tms = {0};
if (dBase.openConnection() == OK) {
sprintf(query, "SELECT * FROM threads");
res = dBase.sqlexec(query);
if (res) {
u_long nRow = mysql_num_rows(res);
auto *tThread = new TypeThread[nRow];
*dstPtr = tThread;
for (u_long r = 0; r < nRow; r++) {
row = mysql_fetch_row(res);
unsigned long *lengths;
int32_t flen;
lengths = mysql_fetch_lengths(res);
if (row) {
tThread[r].id = strtol(row[0], nullptr, 10);
flen = lengths[3];
memset(tThread[r].port, 0, 15);
strncpy(tThread[r].port, row[3], flen);
flen = lengths[5];
memset(tThread[r].title, 0, 100);
strncpy(tThread[r].title, row[5], flen);
memset(tThread[r].device_uuid, 0, 37);
strncpy(tThread[r].device_uuid, row[2], 36);
tThread[r].speed = static_cast<uint16_t>(strtol(row[4], nullptr, 10));
tThread[r].status = strtol(row[6], nullptr, 10);
tThread[r].work = strtol(row[7], nullptr, 10);
// tThread[r].deviceType = strtol(row[6], nullptr, 10);
flen = lengths[8];
memset(tThread[r].deviceType, 0, 37);
strncpy(tThread[r].deviceType, row[8], flen);
if (row[9]) {
strptime(row[9], "%Y-%m-%d %H:%M:%S", &tms);
tThread[r].lastDate = mktime(&tms);
} else
tThread[r].lastDate = mktime(nullptr);
}
}
mysql_free_result(res);
dBase.disconnect();
return nRow;
}
}
dBase.disconnect();
return 0;
}