diff --git a/src/database/SearchFilter.cpp b/src/database/SearchFilter.cpp index e5bcca35..e86c0041 100644 --- a/src/database/SearchFilter.cpp +++ b/src/database/SearchFilter.cpp @@ -22,6 +22,19 @@ namespace Database { +static std::ostream& operator<<(std::ostream& ost, const std::vector< Wt::Dbo::dbo_default_traits::IdType>& ids) +{ + const char *sep = ""; + + for (auto id : ids) + { + ost << sep << std::to_string(id); + sep = ","; + } + + return ost; +} + SqlQuery generatePartialQuery(SearchFilter& filter) { SqlQuery sqlQuery; @@ -70,20 +83,32 @@ SqlQuery generatePartialQuery(SearchFilter& filter) switch (idMatch.first) { case SearchFilter::Field::Artist: - for (auto id : idMatch.second) - idWhereClause.Or( WhereClause("a.id = ?") ).bind( std::to_string(id)); + { + std::ostringstream oss; + oss << "a.id IN (" << idMatch.second << ")"; + idWhereClause.Or(oss.str()); + } break; case SearchFilter::Field::Release: - for (auto id : idMatch.second) - idWhereClause.Or( WhereClause("r.id = ?") ).bind( std::to_string(id)); + { + std::ostringstream oss; + oss << "r.id IN (" << idMatch.second << ")"; + idWhereClause.Or(oss.str()); + } break; case SearchFilter::Field::Genre: - for (auto id : idMatch.second) - idWhereClause.Or( WhereClause("g.id = ?") ).bind( std::to_string(id)); + { + std::ostringstream oss; + oss << "g.id IN (" << idMatch.second << ")"; + idWhereClause.Or(oss.str()); + } break; case SearchFilter::Field::Track: - for (auto id : idMatch.second) - idWhereClause.Or( WhereClause("t.id = ?") ).bind( std::to_string(id)); + { + std::ostringstream oss; + oss << "t.id IN (" << idMatch.second << ")"; + idWhereClause.Or(oss.str()); + } break; } diff --git a/src/database/SearchFilter.hpp b/src/database/SearchFilter.hpp index 50295299..2d0d397c 100644 --- a/src/database/SearchFilter.hpp +++ b/src/database/SearchFilter.hpp @@ -69,7 +69,7 @@ class SearchFilter // ((Field1.name LIKE STR1-1 OR Field1.name LIKE STR1-2 ...) OR (Field2.name LIKE STR2-1 OR Field2.name LIKE STR2-2 ...) ... NameLikeMatchType nameLikeMatch; - // ((Field1.id = ID1-1 OR Field1.id = ID1-2 ... ) AND ((Field2.id = ID2-1 OR Field2.id = ID2-2 ... ) ... + // (Field1.id IN (ID1-1,ID1-2 ... ) AND (Field2.id IN (ID2-1,ID2-2 ... ) ... IdMatchType idMatch; private: diff --git a/src/ui/audio/desktop/TableFilter.cpp b/src/ui/audio/desktop/TableFilter.cpp index 1c59f1f2..34a0c686 100644 --- a/src/ui/audio/desktop/TableFilter.cpp +++ b/src/ui/audio/desktop/TableFilter.cpp @@ -178,7 +178,7 @@ TableFilterArtist::getConstraint(SearchFilter& filter) Artist::id_type id = _queryModel.resultRow( index.row() ).get<0>(); - filter.idMatch[Database::SearchFilter::Field::Artist].push_back(id); + filter.idMatch[SearchFilter::Field::Artist].push_back(id); } }