/* * Copyright (C) 2015 Emeric Poupon * * This file is part of LMS. * * LMS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LMS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LMS. If not, see . */ #ifndef _DB_SEARCH_FILTER_HPP_ #define _DB_SEARCH_FILTER_HPP_ #include #include #include #include #include "SqlQuery.hpp" namespace Database { class SearchFilter { public: enum class Field { Artist, // artist Release, // release Genre, // genre Track, // track }; typedef std::map > NameLikeMatchMap; typedef std::map > IdMatchMap; SearchFilter() {} static SearchFilter IdMatch( const IdMatchMap& _idMatch ) { return SearchFilter(_idMatch); } static SearchFilter NameLikeMatch( const NameLikeMatchMap& _nameLikeMatch ) { return SearchFilter(_nameLikeMatch); } // The filter is a AND of the following conditions: // ((Field1.name LIKE STR1-1 OR Field1.name LIKE STR1-2 ...) OR (Field2.name LIKE STR2-1 OR Field2.name LIKE STR2-2 ...) ... NameLikeMatchMap nameLikeMatch; // ((Field1.id = ID1-1 OR Field1.id = ID1-2 ... ) AND ((Field2.id = ID2-1 OR Field2.id = ID2-2 ... ) ... IdMatchMap idMatch; private: SearchFilter(const NameLikeMatchMap& _nameLikeMatch) : nameLikeMatch(_nameLikeMatch) {} SearchFilter(const IdMatchMap& _idMatch) : idMatch(_idMatch) {} }; SqlQuery generatePartialQuery(SearchFilter& filter); } // namespace Database #endif // _DB_SEARCH_FILTER_HPP_