Mercurial > hg > orthanc-databases
comparison Framework/Plugins/IndexBackend.cpp @ 567:22bbce1f88ff find-refactoring
changes extended: support multiple filters
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Mon, 23 Sep 2024 16:03:24 +0200 |
parents | 3a83c434b284 |
children | 77c8544bbd7d |
comparison
equal
deleted
inserted
replaced
564:3a83c434b284 | 567:22bbce1f88ff |
---|---|
58 // TODO Escape underscores and percents | 58 // TODO Escape underscores and percents |
59 | 59 |
60 return s; | 60 return s; |
61 } | 61 } |
62 | 62 |
63 static std::string JoinChanges(const std::set<uint32_t>& changeTypes) | |
64 { | |
65 std::set<std::string> changeTypesString; | |
66 for (std::set<uint32_t>::const_iterator it = changeTypes.begin(); it != changeTypes.end(); ++it) | |
67 { | |
68 changeTypesString.insert(boost::lexical_cast<std::string>(*it)); | |
69 } | |
70 | |
71 std::string joinedChangesTypes; | |
72 Orthanc::Toolbox::JoinStrings(joinedChangesTypes, changeTypesString, ", "); | |
73 | |
74 return joinedChangesTypes; | |
75 } | |
63 | 76 |
64 template <typename T> | 77 template <typename T> |
65 static void ReadListOfIntegers(std::list<T>& target, | 78 static void ReadListOfIntegers(std::list<T>& target, |
66 DatabaseManager::CachedStatement& statement, | 79 DatabaseManager::CachedStatement& statement, |
67 const Dictionary& args) | 80 const Dictionary& args) |
595 bool& done /*out*/, | 608 bool& done /*out*/, |
596 DatabaseManager& manager, | 609 DatabaseManager& manager, |
597 int64_t since, | 610 int64_t since, |
598 uint32_t limit) | 611 uint32_t limit) |
599 { | 612 { |
600 #if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5) | 613 std::set<uint32_t> changeTypes; |
601 GetChangesExtended(output, done, manager, since, -1, _OrthancPluginChangeType_All, limit); | 614 GetChangesExtended(output, done, manager, since, -1, changeTypes, limit); |
602 #else | |
603 GetChangesExtended(output, done, manager, since, -1, 65535, limit); | |
604 #endif | |
605 } | 615 } |
606 | 616 |
607 /* Use GetOutput().AnswerChange() */ | 617 /* Use GetOutput().AnswerChange() */ |
608 void IndexBackend::GetChangesExtended(IDatabaseBackendOutput& output, | 618 void IndexBackend::GetChangesExtended(IDatabaseBackendOutput& output, |
609 bool& done /*out*/, | 619 bool& done /*out*/, |
610 DatabaseManager& manager, | 620 DatabaseManager& manager, |
611 int64_t since, | 621 int64_t since, |
612 int64_t to, | 622 int64_t to, |
613 int32_t changeType, | 623 const std::set<uint32_t>& changeTypes, |
614 uint32_t limit) | 624 uint32_t limit) |
615 { | 625 { |
616 std::string limitSuffix; | 626 std::string limitSuffix; |
617 if (manager.GetDialect() == Dialect_MSSQL) | 627 if (manager.GetDialect() == Dialect_MSSQL) |
618 { | 628 { |
624 } | 634 } |
625 | 635 |
626 std::vector<std::string> filters; | 636 std::vector<std::string> filters; |
627 bool hasSince = false; | 637 bool hasSince = false; |
628 bool hasTo = false; | 638 bool hasTo = false; |
629 bool hasFilterType = false; | |
630 | 639 |
631 if (since > 0) | 640 if (since > 0) |
632 { | 641 { |
633 hasSince = true; | 642 hasSince = true; |
634 filters.push_back("seq>${since}"); | 643 filters.push_back("seq>${since}"); |
636 if (to != -1) | 645 if (to != -1) |
637 { | 646 { |
638 hasTo = true; | 647 hasTo = true; |
639 filters.push_back("seq<=${to}"); | 648 filters.push_back("seq<=${to}"); |
640 } | 649 } |
641 if (changeType != _OrthancPluginChangeType_All) | 650 if (changeTypes.size() > 0) |
642 { | 651 { |
643 hasFilterType = true; | 652 filters.push_back("changeType IN (" + JoinChanges(changeTypes) + ") "); |
644 filters.push_back("changeType=${changeType}"); | |
645 } | 653 } |
646 | 654 |
647 std::string filtersString; | 655 std::string filtersString; |
648 if (filters.size() > 0) | 656 if (filters.size() > 0) |
649 { | 657 { |
687 | 695 |
688 if (hasTo) | 696 if (hasTo) |
689 { | 697 { |
690 statement.SetParameterType("to", ValueType_Integer64); | 698 statement.SetParameterType("to", ValueType_Integer64); |
691 args.SetIntegerValue("to", to); | 699 args.SetIntegerValue("to", to); |
692 } | |
693 | |
694 if (hasFilterType) | |
695 { | |
696 statement.SetParameterType("changeType", ValueType_Integer64); | |
697 args.SetIntegerValue("changeType", changeType); | |
698 } | 700 } |
699 | 701 |
700 ReadChangesInternal(output, done, manager, statement, args, limit, returnFirstResults); | 702 ReadChangesInternal(output, done, manager, statement, args, limit, returnFirstResults); |
701 } | 703 } |
702 | 704 |