Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp @ 5804:25df40a274fd find-refactoring
/changes: allowing filtering on multiple changes
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 23 Sep 2024 15:40:27 +0200 |
parents | e219e272650d |
children | 8a8756b2dd0b |
comparison
equal
deleted
inserted
replaced
5803:e219e272650d | 5804:25df40a274fd |
---|---|
72 std::string joinedTags; | 72 std::string joinedTags; |
73 Orthanc::Toolbox::JoinStrings(joinedTags, tags, " OR "); | 73 Orthanc::Toolbox::JoinStrings(joinedTags, tags, " OR "); |
74 | 74 |
75 sql += joinedTags + ") "; | 75 sql += joinedTags + ") "; |
76 return sql; | 76 return sql; |
77 } | |
78 | |
79 static std::string JoinChanges(const std::set<ChangeType>& changeTypes) | |
80 { | |
81 std::set<std::string> changeTypesString; | |
82 for (std::set<ChangeType>::const_iterator it = changeTypes.begin(); it != changeTypes.end(); ++it) | |
83 { | |
84 changeTypesString.insert(boost::lexical_cast<std::string>(static_cast<uint32_t>(*it))); | |
85 } | |
86 | |
87 std::string joinedChangesTypes; | |
88 Orthanc::Toolbox::JoinStrings(joinedChangesTypes, changeTypesString, ", "); | |
89 | |
90 return joinedChangesTypes; | |
77 } | 91 } |
78 | 92 |
79 class SQLiteDatabaseWrapper::LookupFormatter : public ISqlLookupFormatter | 93 class SQLiteDatabaseWrapper::LookupFormatter : public ISqlLookupFormatter |
80 { | 94 { |
81 private: | 95 private: |
1246 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, | 1260 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, |
1247 bool& done /*out*/, | 1261 bool& done /*out*/, |
1248 int64_t since, | 1262 int64_t since, |
1249 uint32_t limit) ORTHANC_OVERRIDE | 1263 uint32_t limit) ORTHANC_OVERRIDE |
1250 { | 1264 { |
1251 GetChangesExtended(target, done, since, -1, limit, ChangeType_INTERNAL_All); | 1265 std::set<ChangeType> filter; |
1266 GetChangesExtended(target, done, since, -1, limit, filter); | |
1252 } | 1267 } |
1253 | 1268 |
1254 virtual void GetChangesExtended(std::list<ServerIndexChange>& target /*out*/, | 1269 virtual void GetChangesExtended(std::list<ServerIndexChange>& target /*out*/, |
1255 bool& done /*out*/, | 1270 bool& done /*out*/, |
1256 int64_t since, | 1271 int64_t since, |
1257 int64_t to, | 1272 int64_t to, |
1258 uint32_t limit, | 1273 uint32_t limit, |
1259 ChangeType filterType) ORTHANC_OVERRIDE | 1274 const std::set<ChangeType>& filterType) ORTHANC_OVERRIDE |
1260 { | 1275 { |
1261 std::vector<std::string> filters; | 1276 std::vector<std::string> filters; |
1262 bool hasSince = false; | 1277 bool hasSince = false; |
1263 bool hasTo = false; | 1278 bool hasTo = false; |
1264 bool hasFilterType = false; | 1279 // bool hasFilterType = false; |
1265 | 1280 |
1266 if (since > 0) | 1281 if (since > 0) |
1267 { | 1282 { |
1268 hasSince = true; | 1283 hasSince = true; |
1269 filters.push_back("seq>?"); | 1284 filters.push_back("seq>?"); |
1271 if (to != -1) | 1286 if (to != -1) |
1272 { | 1287 { |
1273 hasTo = true; | 1288 hasTo = true; |
1274 filters.push_back("seq<=?"); | 1289 filters.push_back("seq<=?"); |
1275 } | 1290 } |
1276 if (filterType != ChangeType_INTERNAL_All) | 1291 if (filterType.size() != 0) |
1277 { | 1292 { |
1278 hasFilterType = true; | 1293 // hasFilterType = true; |
1279 filters.push_back("changeType=?"); | 1294 filters.push_back("changeType IN ( " + JoinChanges(filterType) + " )"); |
1280 } | 1295 } |
1281 | 1296 |
1282 std::string filtersString; | 1297 std::string filtersString; |
1283 if (filters.size() > 0) | 1298 if (filters.size() > 0) |
1284 { | 1299 { |
1310 } | 1325 } |
1311 if (hasTo) | 1326 if (hasTo) |
1312 { | 1327 { |
1313 s.BindInt64(paramCounter++, to); | 1328 s.BindInt64(paramCounter++, to); |
1314 } | 1329 } |
1315 if (hasFilterType) | 1330 // if (hasFilterType) |
1316 { | 1331 // { |
1317 s.BindInt(paramCounter++, filterType); | 1332 // s.BindInt(paramCounter++, filterType); |
1318 } | 1333 // } |
1319 s.BindInt(paramCounter++, limit + 1); // we take limit+1 because we use the +1 to know if "Done" must be set to true | 1334 s.BindInt(paramCounter++, limit + 1); // we take limit+1 because we use the +1 to know if "Done" must be set to true |
1320 GetChangesInternal(target, done, s, limit, returnFirstResults); | 1335 GetChangesInternal(target, done, s, limit, returnFirstResults); |
1321 } | 1336 } |
1322 | 1337 |
1323 | 1338 |