[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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user