Bug 139394

Summary: Unable to use empty string in smart playlist's match condition
Product: [Applications] amarok Reporter: shattered
Component: Playlists/Saved PlaylistsAssignee: Amarok Developers <amarok-bugs-dist>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 1.4.4   
Target Milestone: ---   
Platform: NetBSD pkgsrc   
OS: NetBSD   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: smart playlist definition

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;
 }