From be5eb7a9fbb48cfef065a3e4dda649618fc97732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bara?= Date: Thu, 20 Jan 2011 18:55:28 +0000 Subject: [PATCH] smart playlists: 'on date' (equals for dates) operator was too precise (fixes issue #1174) --- src/smartplaylists/searchterm.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/smartplaylists/searchterm.cpp b/src/smartplaylists/searchterm.cpp index bc96f3752..5210f0ac6 100644 --- a/src/smartplaylists/searchterm.cpp +++ b/src/smartplaylists/searchterm.cpp @@ -48,6 +48,12 @@ QString SearchTerm::ToSql() const { if (TypeOf(field_) == Type_Rating) { col = "CAST ((" + col + " + 0.05) * 10 AS INTEGER)"; value = "CAST ((" + value + " + 0.05) * 10 AS INTEGER)"; + + // The calendar widget specifies no time so ditch the possible time part + // from integers representing the dates. + } else if (TypeOf(field_) == Type_Date) { + col = "DATE(" + col + ", 'unixepoch', 'localtime')"; + value = "DATE(" + value + ", 'unixepoch', 'localtime')"; } switch (operator_) { @@ -62,17 +68,20 @@ QString SearchTerm::ToSql() const { case Op_Equals: if (TypeOf(field_) == Type_Text) return col + " LIKE '" + value + "'"; - else if (TypeOf(field_) == Type_Rating) + else if (TypeOf(field_) == Type_Rating || + TypeOf(field_) == Type_Date) return col + " = " + value + ""; else return col + " = '" + value + "'"; case Op_GreaterThan: - if (TypeOf(field_) == Type_Rating) + if (TypeOf(field_) == Type_Rating || + TypeOf(field_) == Type_Date) return col + " > " + value + ""; else return col + " > '" + value + "'"; case Op_LessThan: - if (TypeOf(field_) == Type_Rating) + if (TypeOf(field_) == Type_Rating || + TypeOf(field_) == Type_Date) return col + " < " + value + ""; else return col + " < '" + value + "'";