[DB] Replaced OR .. OR ... by IN list

This commit is contained in:
epoupon
2015-10-16 18:40:41 +02:00
parent 511696fcc0
commit 0d967f035a
3 changed files with 35 additions and 10 deletions
+33 -8
View File
@@ -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;
}