New UI: first step
This commit is contained in:
@@ -24,98 +24,15 @@
|
||||
namespace Database
|
||||
{
|
||||
|
||||
static std::ostream& operator<<(std::ostream& ost, const std::vector< Wt::Dbo::dbo_default_traits::IdType>& ids)
|
||||
void
|
||||
SearchFilter::operator+=(const SearchFilter& filter)
|
||||
{
|
||||
const char *sep = "";
|
||||
|
||||
for (auto id : ids)
|
||||
{
|
||||
ost << sep << std::to_string(id);
|
||||
sep = ",";
|
||||
}
|
||||
|
||||
return ost;
|
||||
}
|
||||
|
||||
SqlQuery generatePartialQuery(SearchFilter& filter)
|
||||
SqlQuery
|
||||
SearchFilter::generatePartialQuery()
|
||||
{
|
||||
SqlQuery sqlQuery;
|
||||
|
||||
// Process name like parameters
|
||||
for (auto nameLikeMatches : filter.nameLikeMatch)
|
||||
{
|
||||
WhereClause likeWhereClause;
|
||||
|
||||
for (auto nameLikeMatch : nameLikeMatches)
|
||||
{
|
||||
switch (nameLikeMatch.first)
|
||||
{
|
||||
case SearchFilter::Field::Artist:
|
||||
for (const std::string& name : nameLikeMatch.second)
|
||||
likeWhereClause.Or( WhereClause("a.name LIKE ?") ).bind("%%" + name + "%%");
|
||||
break;
|
||||
|
||||
case SearchFilter::Field::Release:
|
||||
for (const std::string& name : nameLikeMatch.second)
|
||||
likeWhereClause.Or( WhereClause("r.name LIKE ?") ).bind("%%" + name + "%%");
|
||||
break;
|
||||
|
||||
case SearchFilter::Field::Cluster:
|
||||
for (const std::string& name : nameLikeMatch.second)
|
||||
likeWhereClause.Or( WhereClause("c.name LIKE ?") ).bind("%%" + name + "%%");
|
||||
break;
|
||||
|
||||
case SearchFilter::Field::Track:
|
||||
for (const std::string& name : nameLikeMatch.second)
|
||||
likeWhereClause.Or( WhereClause("t.name LIKE ?") ).bind("%%" + name + "%%");
|
||||
break;
|
||||
}
|
||||
}
|
||||
sqlQuery.where().And( likeWhereClause );
|
||||
}
|
||||
|
||||
// Process id exact match parameters
|
||||
// Id list may be long, we do not bind the parameters
|
||||
// Safe since we already known these are just ints
|
||||
for (auto idMatch : filter.idMatch)
|
||||
{
|
||||
WhereClause idWhereClause;
|
||||
|
||||
switch (idMatch.first)
|
||||
{
|
||||
case SearchFilter::Field::Artist:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "a.id IN (" << idMatch.second << ")";
|
||||
idWhereClause.Or(oss.str());
|
||||
}
|
||||
break;
|
||||
case SearchFilter::Field::Release:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "r.id IN (" << idMatch.second << ")";
|
||||
idWhereClause.Or(oss.str());
|
||||
}
|
||||
break;
|
||||
case SearchFilter::Field::Cluster:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "c.id IN (" << idMatch.second << ")";
|
||||
idWhereClause.Or(oss.str());
|
||||
}
|
||||
break;
|
||||
case SearchFilter::Field::Track:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "t.id IN (" << idMatch.second << ")";
|
||||
idWhereClause.Or(oss.str());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
sqlQuery.where().And( idWhereClause );
|
||||
}
|
||||
|
||||
return sqlQuery;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user