ISQLiteIndex.cpp (3796B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "Microsoft/Schema/ISQLiteIndex.h" 5 6 #include "Microsoft/Schema/1_0/Interface.h" 7 #include "Microsoft/Schema/1_1/Interface.h" 8 #include "Microsoft/Schema/1_2/Interface.h" 9 #include "Microsoft/Schema/1_3/Interface.h" 10 #include "Microsoft/Schema/1_4/Interface.h" 11 #include "Microsoft/Schema/1_5/Interface.h" 12 #include "Microsoft/Schema/1_6/Interface.h" 13 #include "Microsoft/Schema/1_7/Interface.h" 14 #include "Microsoft/Schema/2_0/Interface.h" 15 16 namespace AppInstaller::Repository::Microsoft::Schema 17 { 18 void ISQLiteIndex::PrepareForPackaging(const SQLiteIndexContext& context) 19 { 20 PrepareForPackaging(context.Connection); 21 } 22 23 void ISQLiteIndex::SetProperty(SQLite::Connection&, Property, const std::string&) 24 { 25 THROW_WIN32(ERROR_NOT_SUPPORTED); 26 } 27 28 std::unique_ptr<ISQLiteIndex> CreateISQLiteIndex(const SQLite::Version& version) 29 { 30 if (version.MajorVersion == 1 || 31 version.IsLatest()) 32 { 33 constexpr std::array<std::unique_ptr<ISQLiteIndex>(*)(), 8> versionCreatorMap = 34 { 35 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V1_0::Interface>()); }, 36 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V1_1::Interface>()); }, 37 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V1_2::Interface>()); }, 38 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V1_3::Interface>()); }, 39 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V1_4::Interface>()); }, 40 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V1_5::Interface>()); }, 41 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V1_6::Interface>()); }, 42 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V1_7::Interface>()); }, 43 }; 44 45 return versionCreatorMap[std::min(static_cast<size_t>(version.MinorVersion), versionCreatorMap.size() - 1)](); 46 } 47 48 // Version 2.0 is designed solely for minimizing the size of the index for transport. 49 // Unless it is prepared for packaging, it will be identical to a 1.N index. 50 if (version.MajorVersion == 2) 51 { 52 constexpr std::array<std::unique_ptr<ISQLiteIndex>(*)(), 1> versionCreatorMap = 53 { 54 []() { return std::unique_ptr<ISQLiteIndex>(std::make_unique<V2_0::Interface>()); }, 55 }; 56 57 return versionCreatorMap[std::min(static_cast<size_t>(version.MinorVersion), versionCreatorMap.size() - 1)](); 58 } 59 60 // We do not have the capacity to operate on this schema version 61 THROW_WIN32(ERROR_NOT_SUPPORTED); 62 } 63 64 std::vector<MatchType> GetDefaultMatchTypeOrder(MatchType type) 65 { 66 switch (type) 67 { 68 case MatchType::Exact: 69 return { MatchType::Exact }; 70 case MatchType::CaseInsensitive: 71 return { MatchType::CaseInsensitive }; 72 case MatchType::StartsWith: 73 return { MatchType::CaseInsensitive, MatchType::StartsWith }; 74 case MatchType::Substring: 75 return { MatchType::CaseInsensitive, MatchType::Substring }; 76 case MatchType::Wildcard: 77 return { MatchType::Wildcard }; 78 case MatchType::Fuzzy: 79 return { MatchType::CaseInsensitive, MatchType::Fuzzy }; 80 case MatchType::FuzzySubstring: 81 return { MatchType::CaseInsensitive, MatchType::Fuzzy, MatchType::Substring, MatchType::FuzzySubstring }; 82 default: 83 THROW_HR(E_UNEXPECTED); 84 } 85 } 86 }