-
Notifications
You must be signed in to change notification settings - Fork 0
/
searcher.cpp
175 lines (162 loc) · 6.08 KB
/
searcher.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "searcher.h"
Searcher::Searcher(const QString &name,
QObject *parent) :
QObject(parent)
, _numberRowsForProcessing(0)
, _sheet(name)
, _canceled(false)
, _isFinished(false)
{
qDebug() << " Searcher()" << _sheet;
}
Searcher::~Searcher()
{
qDebug() << " ~Searcher()" << _sheet;
}
void Searcher::cancel()
{
// qDebug() << " Searcher::cancel()" << _sheet;
_canceled=true;
emit finished(_sheet);
_isFinished=true;
}
bool Searcher::isCanceled()
{
return _canceled;
}
//static function:
SearchStruct Searcher::concSelectAddress(SearchStruct s)
{
// qDebug() << "Searcher::concSelectAddress <" << s.row << QThread::currentThreadId();
if(!s.findIt)
return s;
Address &a=s.a;
QString str = QString("SELECT STREET_ID, BUILD_ID, RAW "
"FROM %1 "
"WHERE TYPE_OF_FSUBJ = '%2' "
" AND FSUBJ = '%3' "
" AND DISTRICT = '%4' "
" AND TYPE_OF_CITY1 = '%5' "
" AND CITY1 = '%6' "
" AND TYPE_OF_CITY2 = '%7' "
" AND CITY2 = '%8'"
" AND TYPE_OF_STREET = '%9' "
" AND STREET = '%10' "
" AND BUILD = '%11' "
" AND KORP = '%12' "
" AND LITERA = '%13' "
" AND CORRECT = '1'; "
)
.arg(TableName)
.arg(a.getTypeOfFSubjInString())
.arg(a.getFsubj())
.arg(a.getDistrict())
.arg(a.getTypeOfCity1())
.arg(a.getCity1())
.arg(a.getTypeOfCity2())
.arg(a.getCity2())
.arg(a.getTypeOfStreet())
.arg(a.getStreet())
.arg(a.getBuild())
.arg(a.getKorp())
.arg(a.getLitera());
// qDebug() << "Searcher::selectAddress" << str;
QSqlQuery query;
// qDebug() << "Searcher::selectAddress BEGIN" << query.isActive() << s.row;
if (!query.exec(str))
return s;
// qDebug() << "Searcher::selectAddress END" << query.isActive() << s.row;
//Reading of the data
// qDebug() << "Searcher::Reading record BEGIN" << QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
QSqlRecord rec = query.record();
// qDebug() << "Searcher::Reading record END" << QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
// qDebug() << "Searcher::Reading record count" << rec.count();
bool isExists=false;
while (query.next()) {
isExists=true;
// qDebug() << "Searcher::Reading query isValid" << query.isValid();
a.setRawAddress( query.value(rec.indexOf("RAW")).toString() );
a.setBuildId( query.value(rec.indexOf("BUILD_ID")).toULongLong() );
a.setStreetId( query.value(rec.indexOf("STREET_ID")).toULongLong() );
}
// qDebug() << "Searcher::Reading next END" << QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
s.found=isExists;
// qDebug() << "Searcher::concSelectAddress >" << s.row << QThread::currentThreadId();
return s;
}
void Searcher::selectAddress(QString sheet, int nRow, Address a, bool findIt)
{
if(!findIt)
return;
if(_canceled)
{
if(_isFinished)
return;
emit finished(_sheet);
_isFinished=true;
}
QString str = QString("SELECT STREET_ID, BUILD_ID, RAW "
"FROM %1 "
"WHERE TYPE_OF_FSUBJ = '%2' "
" AND FSUBJ = '%3' "
" AND DISTRICT = '%4' "
" AND TYPE_OF_CITY1 = '%5' "
" AND CITY1 = '%6' "
" AND TYPE_OF_CITY2 = '%7' "
" AND CITY2 = '%8'"
" AND TYPE_OF_STREET = '%9' "
" AND STREET = '%10' "
" AND BUILD = '%11' "
" AND KORP = '%12' "
" AND LITERA = '%13' "
" AND CORRECT = '1'; "
)
.arg(TableName)
.arg(a.getTypeOfFSubjInString())
.arg(a.getFsubj())
.arg(a.getDistrict())
.arg(a.getTypeOfCity1())
.arg(a.getCity1())
.arg(a.getTypeOfCity2())
.arg(a.getCity2())
.arg(a.getTypeOfStreet())
.arg(a.getStreet())
.arg(a.getBuild())
.arg(a.getKorp())
.arg(a.getLitera());
// qDebug() << "Searcher::selectAddress" << str;
QSqlQuery query;
// qDebug() << "Searcher::selectAddress BEGIN" << nRow;
if (!query.exec(str))
{
emit toDebug(objectName(),
QString("Невозможно выполнить запрос '%1'. Ошибка: '%2'")
.arg(str).arg(query.lastError().text()));
return;
}
// qDebug() << "Searcher::selectAddress END" << nRow;
//Reading of the data
QSqlRecord rec = query.record();
bool isExists=false;
while (query.next()) {
isExists=true;
a.setRawAddress( query.value(rec.indexOf("RAW")).toString() );
a.setBuildId( query.value(rec.indexOf("BUILD_ID")).toULongLong() );
a.setStreetId( query.value(rec.indexOf("STREET_ID")).toULongLong() );
emit addressFounded(sheet, nRow, a);
}
if(!isExists)
emit addressNotFounded(sheet, nRow, a);
if(nRow+1>=_numberRowsForProcessing)
{
if(_isFinished)
return;
emit finished(_sheet);
_isFinished=true;
}
}
void Searcher::setCountRows(int rows)
{
_numberRowsForProcessing=rows;
_canceled=false;
}