[DB] Replaced OR .. OR ... by IN list
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user