Skip to content

Commit

Permalink
CSmartPlaylistRule: add OPERATOR_BETWEEN for range filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Oct 8, 2012
1 parent 86a8f57 commit 3b33950
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
18 changes: 17 additions & 1 deletion xbmc/playlists/SmartPlayList.cpp
Expand Up @@ -132,7 +132,8 @@ static const operatorField operators[] = { { "contains", CSmartPlaylistRule::OPE
{ "inthelast", CSmartPlaylistRule::OPERATOR_IN_THE_LAST, 21410 },
{ "notinthelast", CSmartPlaylistRule::OPERATOR_NOT_IN_THE_LAST, 21411 },
{ "true", CSmartPlaylistRule::OPERATOR_TRUE, 20122 },
{ "false", CSmartPlaylistRule::OPERATOR_FALSE, 20424 }
{ "false", CSmartPlaylistRule::OPERATOR_FALSE, 20424 },
{ "between", CSmartPlaylistRule::OPERATOR_BETWEEN, 21456 }
};

#define NUM_OPERATORS sizeof(operators) / sizeof(operatorField)
Expand Down Expand Up @@ -747,6 +748,21 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
}
}

// The BETWEEN operator is handled special
if (op == OPERATOR_BETWEEN)
{
if (m_parameter.size() != 2)
return "";

FIELD_TYPE fieldType = GetFieldType(m_field);
if (fieldType == NUMERIC_FIELD || m_field == FieldYear)
return db.PrepareSQL("CAST(%s as DECIMAL(5,1)) BETWEEN %s AND %s", GetField(m_field, strType).c_str(), m_parameter[0].c_str(), m_parameter[1].c_str());
else if (fieldType == SECONDS_FIELD)
return db.PrepareSQL("CAST(%s as INTEGER) BETWEEN %s AND %s", GetField(m_field, strType).c_str(), m_parameter[0].c_str(), m_parameter[1].c_str());
else
return db.PrepareSQL("%s BETWEEN '%s' AND '%s'", GetField(m_field, strType).c_str(), m_parameter[0].c_str(), m_parameter[1].c_str());
}

// now the query parameter
CStdString wholeQuery;
for (vector<CStdString>::const_iterator it = m_parameter.begin(); it != m_parameter.end(); /* it++ is done further down */)
Expand Down
1 change: 1 addition & 0 deletions xbmc/playlists/SmartPlayList.h
Expand Up @@ -60,6 +60,7 @@ class CSmartPlaylistRule : public ISmartPlaylistRule
OPERATOR_NOT_IN_THE_LAST,
OPERATOR_TRUE,
OPERATOR_FALSE,
OPERATOR_BETWEEN,
OPERATOR_END
};

Expand Down

0 comments on commit 3b33950

Please sign in to comment.