-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkerexample.cpp
More file actions
48 lines (45 loc) · 1.69 KB
/
workerexample.cpp
File metadata and controls
48 lines (45 loc) · 1.69 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
#include "workerexample.h"
#include "src/qcustomqsqlquery.h"
#include "src/LoggerDef.h"
QString WorkerExample::loggerId=QLatin1String(LOGGER_SQL);
WorkerExample::WorkerExample(QString query,int workFrequencyMs,QObject *parent) :
QObject(parent),
m_query(query)
{
m_internalTimer.setInterval(workFrequencyMs);
QObject::connect(&m_internalTimer,SIGNAL(timeout()),this,SLOT(work()));
m_internalTimer.start();;
}
void WorkerExample::work()
{
QCustomQsqlQuery customquery(loggerId);
bool res = customquery.exec(m_query);
if(res==true)
{
if(customquery.lastError().type()==QSqlError::NoError)
{
QList<QVariant> result;
while(customquery.next(result))
{
LOG_INFO(loggerId,QString("NEXT : %1")
.arg(result.at(0).toString()));
}
LOG_INFO(loggerId,QString("FINISHED Browsing results"));
}
else
{
LOG_ERROR(loggerId,QString("Error SQL query=[%1] -- err_type=[%2] -- err_numer=[%3] -- err_text=[%4]")
.arg(m_query)
.arg(qsql_error_as_string(customquery.lastError().type()))
.arg(customquery.lastError().number())
.arg(customquery.lastError().databaseText())); }
}
else
{
LOG_ERROR(loggerId,QString("Error while trying to run the query=[%1] -- err_type=[%2] -- err_numer=[%3] -- err_text=[%4]")
.arg(m_query)
.arg(qsql_error_as_string(customquery.lastError().type()))
.arg(customquery.lastError().number())
.arg(customquery.lastError().databaseText()));
}
}