smart playlists are incorrectly filtering ratings (fixes issue #1113)

This commit is contained in:
Paweł Bara 2011-01-20 18:35:38 +00:00
parent cc05ce55ca
commit 3b7ae72f82
1 changed files with 24 additions and 4 deletions

View File

@ -35,10 +35,21 @@ SearchTerm::SearchTerm(
} }
QString SearchTerm::ToSql() const { QString SearchTerm::ToSql() const {
const QString col = FieldColumnName(field_); QString col = FieldColumnName(field_);
QString value = value_.toString(); QString value = value_.toString();
value.replace('\'', "''"); value.replace('\'', "''");
// Floating point problems...
// Theoretically 0.0 == 0 stars, 0.1 == 0.5 star, 0.2 == 1 star etc.
// but in reality we need to consider anything from [0.05, 0.15) range
// to be 0.5 star etc.
// To make this simple, I transform the ranges to integeres and then
// operate on ints: [0.0, 0.05) -> 0, [0.05, 0.15) -> 1 etc.
if (TypeOf(field_) == Type_Rating) {
col = "CAST ((" + col + " + 0.05) * 10 AS INTEGER)";
value = "CAST ((" + value + " + 0.05) * 10 AS INTEGER)";
}
switch (operator_) { switch (operator_) {
case Op_Contains: case Op_Contains:
return col + " LIKE '%" + value + "%'"; return col + " LIKE '%" + value + "%'";
@ -51,10 +62,19 @@ QString SearchTerm::ToSql() const {
case Op_Equals: case Op_Equals:
if (TypeOf(field_) == Type_Text) if (TypeOf(field_) == Type_Text)
return col + " LIKE '" + value + "'"; return col + " LIKE '" + value + "'";
else if (TypeOf(field_) == Type_Rating)
return col + " = " + value + "";
else
return col + " = '" + value + "'"; return col + " = '" + value + "'";
case Op_GreaterThan: case Op_GreaterThan:
if (TypeOf(field_) == Type_Rating)
return col + " > " + value + "";
else
return col + " > '" + value + "'"; return col + " > '" + value + "'";
case Op_LessThan: case Op_LessThan:
if (TypeOf(field_) == Type_Rating)
return col + " < " + value + "";
else
return col + " < '" + value + "'"; return col + " < '" + value + "'";
} }