Bug 139394 - Unable to use empty string in smart playlist's match condition
Summary: Unable to use empty string in smart playlist's match condition
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: Playlists/Saved Playlists (show other bugs)
Version: 1.4.4
Platform: NetBSD pkgsrc NetBSD
: NOR normal
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-30 14:40 UTC by shattered
Modified: 2006-12-31 15:39 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
smart playlist definition (28.59 KB, image/gif)
2006-12-30 14:41 UTC, shattered
Details

Note You need to log in before you can comment on or make changes to this bug.
Description shattered 2006-12-30 14:40:50 UTC
Version:           1.4.4 (using KDE KDE 3.5.4)
Installed from:    NetBSD pkgsrc
Compiler:          gcc version 3.3.3 (NetBSD nb3 20040520) 
OS:                NetBSD

I use a smart playlist that matches on empty artist and/or track name to find untagged or badly tagged tracks.  It worked just fine earlier (in 1.3.x and early 1.4.x); in 1.4.4, an empty playlist is generated instead.
Comment 1 shattered 2006-12-30 14:41:45 UTC
Created attachment 19070 [details]
smart playlist definition
Comment 2 Alexandre Oliveira 2006-12-31 14:32:00 UTC
SVN commit 618171 by aoliveira:

filtering for empty string wouldn't work on smart playlists
BUG: 139394


 M  +27 -30    collectiondb.cpp  


--- trunk/extragear/multimedia/amarok/src/collectiondb.cpp #618170:618171
@@ -6999,43 +6999,40 @@
 void
 QueryBuilder::addFilter( int tables, Q_INT64 value, const QString& filter, int mode, bool exact )
 {
-    if ( !filter.isEmpty() )
-    {
-        //true for INTEGER fields (see comment of coalesceField(int, Q_INT64)
-        bool useCoalesce = coalesceField( tables, value );
-        m_where += ANDslashOR() + " ( ";
+    //true for INTEGER fields (see comment of coalesceField(int, Q_INT64)
+    bool useCoalesce = coalesceField( tables, value );
+    m_where += ANDslashOR() + " ( ";
 
-        QString m, s;
-        if (mode == modeLess || mode == modeGreater)
-        {
-            QString escapedFilter;
+    QString m, s;
+    if (mode == modeLess || mode == modeGreater)
+    {
+        QString escapedFilter;
+        if (useCoalesce && DbConnection::sqlite == CollectionDB::instance()->getDbConnectionType())
+            escapedFilter = CollectionDB::instance()->escapeString( filter );
+        else
+            escapedFilter = "'" + CollectionDB::instance()->escapeString( filter ) + "' ";
+        s = ( mode == modeLess ? "< " : "> " ) + escapedFilter;
+    }
+    else
+    {
+        if (exact)
             if (useCoalesce && DbConnection::sqlite == CollectionDB::instance()->getDbConnectionType())
-                escapedFilter = CollectionDB::instance()->escapeString( filter );
+                s = " = " +CollectionDB::instance()->escapeString( filter ) + ' ';
             else
-                escapedFilter = "'" + CollectionDB::instance()->escapeString( filter ) + "' ";
-            s = ( mode == modeLess ? "< " : "> " ) + escapedFilter;
-        }
+                s = " = '" + CollectionDB::instance()->escapeString( filter ) + "' ";
         else
-        {
-            if (exact)
-                if (useCoalesce && DbConnection::sqlite == CollectionDB::instance()->getDbConnectionType())
-                    s = " = " +CollectionDB::instance()->escapeString( filter ) + ' ';
-                else
-                    s = " = '" + CollectionDB::instance()->escapeString( filter ) + "' ";
-            else
-                s = CollectionDB::likeCondition( filter, mode != modeBeginMatch, mode != modeEndMatch );
-        }
+            s = CollectionDB::likeCondition( filter, mode != modeBeginMatch, mode != modeEndMatch );
+    }
 
-        if( coalesceField( tables, value ) )
-            m_where += QString( "COALESCE(%1.%2,0) " ).arg( tableName( tables ) ).arg( valueName( value ) ) + s;
-        else
-            m_where += QString( "%1.%2 " ).arg( tableName( tables ) ).arg( valueName( value ) ) + s;
+    if( coalesceField( tables, value ) )
+        m_where += QString( "COALESCE(%1.%2,0) " ).arg( tableName( tables ) ).arg( valueName( value ) ) + s;
+    else
+        m_where += QString( "%1.%2 " ).arg( tableName( tables ) ).arg( valueName( value ) ) + s;
 
-        if ( !exact && (value & valName) && mode == modeNormal && i18n( "Unknown").contains( filter, false ) )
-            m_where += QString( "OR %1.%2 = '' " ).arg( tableName( tables ) ).arg( valueName( value ) );
+    if ( !exact && (value & valName) && mode == modeNormal && i18n( "Unknown").contains( filter, false ) )
+        m_where += QString( "OR %1.%2 = '' " ).arg( tableName( tables ) ).arg( valueName( value ) );
 
-        m_where += " ) ";
-    }
+    m_where += " ) ";
 
     m_linkTables |= tables;
 }
Comment 3 Maximilian Kossick 2006-12-31 15:39:05 UTC
SVN commit 618193 by mkossick:

filtering for empty strings works for "is not" too
CCBUG: 139394

 M  +17 -20    collectiondb.cpp  


--- trunk/extragear/multimedia/amarok/src/collectiondb.cpp #618192:618193
@@ -7141,31 +7141,28 @@
 void
 QueryBuilder::excludeFilter( int tables, Q_INT64 value, const QString& filter, int mode, bool exact )
 {
-    if ( !filter.isEmpty() )
-    {
-        m_where += ANDslashOR() + " ( ";
+    m_where += ANDslashOR() + " ( ";
 
-        QString m, s;
-        if (mode == modeLess || mode == modeGreater)
-            s = ( mode == modeLess ? ">= '" : "<= '" ) + CollectionDB::instance()->escapeString( filter ) + "' ";
+    QString m, s;
+    if (mode == modeLess || mode == modeGreater)
+        s = ( mode == modeLess ? ">= '" : "<= '" ) + CollectionDB::instance()->escapeString( filter ) + "' ";
+    else
+    {
+        if (exact)
+            s = " <> '" + CollectionDB::instance()->escapeString( filter ) + "' ";
         else
-        {
-            if (exact)
-                s = " <> '" + CollectionDB::instance()->escapeString( filter ) + "' ";
-            else
-                s = "NOT " + CollectionDB::instance()->likeCondition( filter, mode != modeBeginMatch, mode != modeEndMatch ) + ' ';
-        }
+            s = "NOT " + CollectionDB::instance()->likeCondition( filter, mode != modeBeginMatch, mode != modeEndMatch ) + ' ';
+    }
 
-        if( coalesceField( tables, value ) )
-            m_where += QString( "COALESCE(%1.%2,0) " ).arg( tableName( tables ) ).arg( valueName( value ) ) + s;
-        else
-            m_where += QString( "%1.%2 " ).arg( tableName( tables ) ).arg( valueName( value ) ) + s;
+    if( coalesceField( tables, value ) )
+        m_where += QString( "COALESCE(%1.%2,0) " ).arg( tableName( tables ) ).arg( valueName( value ) ) + s;
+    else
+        m_where += QString( "%1.%2 " ).arg( tableName( tables ) ).arg( valueName( value ) ) + s;
 
-        if ( !exact && (value & valName) && mode == modeNormal && i18n( "Unknown").contains( filter, false ) )
-            m_where += QString( "AND %1.%2 <> '' " ).arg( tableName( tables ) ).arg( valueName( value ) );
+    if ( !exact && (value & valName) && mode == modeNormal && i18n( "Unknown").contains( filter, false ) )
+        m_where += QString( "AND %1.%2 <> '' " ).arg( tableName( tables ) ).arg( valueName( value ) );
 
-        m_where += " ) ";
-    }
+    m_where += " ) ";
 
     m_linkTables |= tables;
 }