Skip to content
Browse files

CSmartPlaylistRule: add OPERATOR_BETWEEN for range filters

  • Loading branch information...
1 parent 86a8f57 commit 3b339501970244f5e76bbfafef557dcfc0cf2094 @Montellese committed Jun 23, 2012
Showing with 18 additions and 1 deletion.
  1. +17 −1 xbmc/playlists/SmartPlayList.cpp
  2. +1 −0 xbmc/playlists/SmartPlayList.h
View
18 xbmc/playlists/SmartPlayList.cpp
@@ -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)
@@ -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 */)
View
1 xbmc/playlists/SmartPlayList.h
@@ -60,6 +60,7 @@ class CSmartPlaylistRule : public ISmartPlaylistRule
OPERATOR_NOT_IN_THE_LAST,
OPERATOR_TRUE,
OPERATOR_FALSE,
+ OPERATOR_BETWEEN,
OPERATOR_END
};

0 comments on commit 3b33950

Please sign in to comment.
Something went wrong with that request. Please try again.