[banshee] BansheeQuery: stop hardcoding field columns



commit dd56eba36785744a45ec60cf4ea3ec7ec432426c
Author: AndrÃs G. Aragoneses <knocte gmail com>
Date:   Thu Nov 3 00:00:37 2011 +0000

    BansheeQuery: stop hardcoding field columns
    
    After some recent refactorings to start using QueryField
    objects instead of strings, it makes sense to improve
    further and stop using in general column names that are
    already specified in these field objects. Leads to cleaner
    code, less duplication, and less error-prone to typos as
    it is checked at compile time now.
    
    There is no change of behaviour in this commit.

 .../DatabaseTrackListModel.cs                      |    6 ++-
 .../Banshee.Collection.Database/RandomByAlbum.cs   |   15 ++++++---
 .../Banshee.Collection.Database/RandomByArtist.cs  |   17 +++++++----
 .../Banshee.Collection.Database/RandomByRating.cs  |    5 ++-
 .../Banshee.Collection.Database/RandomByScore.cs   |    6 ++-
 .../Banshee.Collection.Database/RandomByTrack.cs   |    2 +-
 .../Banshee.Collection/RescanPipeline.cs           |    5 ++-
 .../Banshee.Services/Banshee.Query/BansheeQuery.cs |   32 +++++++++++--------
 .../AmazonMp3GroupSource.cs                        |    2 +-
 .../Banshee.Dap.MassStorage/WebOSDevice.cs         |    2 +-
 .../Banshee.CoverArt/CoverArtJob.cs                |    5 ++-
 .../Banshee.LibraryWatcher/SourceWatcher.cs        |    6 ++-
 .../Banshee.OpticalDisc.AudioCd/AudioCdSource.cs   |    5 ++-
 .../Banshee.Podcasting.Data/PodcastSource.cs       |    4 ++-
 .../PodcastTrackListModel.cs                       |    4 ++-
 15 files changed, 72 insertions(+), 44 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs
index f8d2a50..bae5889 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackListModel.cs
@@ -78,7 +78,8 @@ namespace Banshee.Collection.Database
             this.provider = provider;
             this.source = source;
 
-            SelectAggregates = "SUM(CoreTracks.Duration), SUM(CoreTracks.FileSize)";
+            SelectAggregates = String.Format ("SUM({0}), SUM({1})",
+                                              BansheeQuery.DurationField.Column, BansheeQuery.FileSizeField.Column);
 
             Selection.Changed += delegate {
                 if (SelectionAggregatesHandler != null) {
@@ -240,7 +241,8 @@ namespace Banshee.Collection.Database
         public virtual void UpdateUnfilteredAggregates ()
         {
             HyenaSqliteCommand count_command = new HyenaSqliteCommand (String.Format (
-                "SELECT COUNT(*), SUM(CoreTracks.FileSize), SUM(CoreTracks.Duration) {0}", UnfilteredQuery
+                "SELECT COUNT(*), SUM({0}), SUM({1}) {2}",
+                BansheeQuery.FileSizeField.Column, BansheeQuery.DurationField.Column, UnfilteredQuery
             ));
 
             using (HyenaDataReader reader = new HyenaDataReader (connection.Query (count_command))) {
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByAlbum.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByAlbum.cs
index 56055e9..4d93928 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByAlbum.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByAlbum.cs
@@ -33,6 +33,7 @@ using Hyena;
 using Hyena.Data;
 using Hyena.Data.Sqlite;
 
+using Banshee.Query;
 using Banshee.ServiceStack;
 using Banshee.PlaybackController;
 using Mono.Unix;
@@ -101,28 +102,32 @@ namespace Banshee.Collection.Database
                             SELECT
                                 CoreAlbums.AlbumID,
                                 CoreAlbums.Title,
-                                MAX(CoreTracks.LastPlayedStamp) as LastPlayed,
-                                MAX(CoreTracks.LastSkippedStamp) as LastSkipped
+                                MAX({4}) as LastPlayed,
+                                MAX({5}) as LastSkipped
                             FROM
                                 CoreTracks, CoreAlbums, CoreCache {0}
                             WHERE
                                 {1}
                                 CoreCache.ModelID = {2} AND
                                 CoreTracks.AlbumID = CoreAlbums.AlbumID AND
-                                CoreTracks.LastStreamError = 0
+                                {6} = 0
                                 {3}
                             GROUP BY CoreTracks.AlbumID
                             HAVING
                                 (LastPlayed < ? OR LastPlayed IS NULL) AND
                                 (LastSkipped < ? OR LastSkipped IS NULL)
-                            ORDER BY RANDOM()
+                            ORDER BY {7}
                             LIMIT 1",
                         Model.JoinFragment,
                         Model.CachesJoinTableEntries
                             ? String.Format ("CoreCache.ItemID = {0}.{1} AND", Model.JoinTable, Model.JoinPrimaryKey)
                             : "CoreCache.ItemId = CoreTracks.TrackID AND",
                         Model.CacheId,
-                        Model.ConditionFragment
+                        Model.ConditionFragment,
+                        BansheeQuery.LastPlayedField.Column,
+                        BansheeQuery.LastSkippedField.Column,
+                        BansheeQuery.PlaybackErrorField.Column,
+                        BansheeQuery.GetRandomSort ()
                     ));
                 }
                 return album_query;
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByArtist.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByArtist.cs
index 154a3e2..4b553ee 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByArtist.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByArtist.cs
@@ -33,6 +33,7 @@ using Hyena;
 using Hyena.Data;
 using Hyena.Data.Sqlite;
 
+using Banshee.Query;
 using Banshee.ServiceStack;
 using Banshee.PlaybackController;
 using Mono.Unix;
@@ -51,7 +52,7 @@ namespace Banshee.Collection.Database
             Description = Catalog.GetString ("Play all songs by an artist, then randomly choose another artist");
 
             Condition = "CoreAlbums.ArtistID = ?";
-            OrderBy = "CoreTracks.Year, CoreTracks.AlbumID ASC, Disc ASC, TrackNumber ASC";
+            OrderBy = String.Format ("{0}, CoreTracks.AlbumID ASC, Disc ASC, TrackNumber ASC", Banshee.Query.BansheeQuery.YearField.Column);
         }
 
         protected override void OnModelAndCacheUpdated ()
@@ -102,28 +103,32 @@ namespace Banshee.Collection.Database
                             SELECT
                                 CoreAlbums.ArtistID,
                                 CoreAlbums.ArtistName,
-                                MAX(CoreTracks.LastPlayedStamp) as LastPlayed,
-                                MAX(CoreTracks.LastSkippedStamp) as LastSkipped
+                                MAX({4}) as LastPlayed,
+                                MAX({5}) as LastSkipped
                             FROM
                                 CoreTracks, CoreAlbums, CoreCache {0}
                             WHERE
                                 {1}
                                 CoreCache.ModelID = {2} AND
                                 CoreTracks.AlbumID = CoreAlbums.AlbumID AND
-                                CoreTracks.LastStreamError = 0
+                                {6} = 0
                                 {3}
                             GROUP BY CoreTracks.AlbumID
                             HAVING
                                 (LastPlayed < ? OR LastPlayed IS NULL) AND
                                 (LastSkipped < ? OR LastSkipped IS NULL)
-                            ORDER BY RANDOM()
+                            ORDER BY {7}
                             LIMIT 1",
                         Model.JoinFragment,
                         Model.CachesJoinTableEntries
                             ? String.Format ("CoreCache.ItemID = {0}.{1} AND", Model.JoinTable, Model.JoinPrimaryKey)
                             : "CoreCache.ItemId = CoreTracks.TrackID AND",
                         Model.CacheId,
-                        Model.ConditionFragment
+                        Model.ConditionFragment,
+                        BansheeQuery.LastPlayedField.Column,
+                        BansheeQuery.LastSkippedField.Column,
+                        BansheeQuery.PlaybackErrorField.Column,
+                        BansheeQuery.GetRandomSort ()
                     ));
                 }
                 return query;
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByRating.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByRating.cs
index 6d2c882..76e2fae 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByRating.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByRating.cs
@@ -33,6 +33,7 @@
 using System;
 using System.Collections.Generic;
 
+using Banshee.Query;
 using Banshee.PlaybackController;
 using Mono.Unix;
 
@@ -46,8 +47,8 @@ namespace Banshee.Collection.Database
             Adverb = Catalog.GetString ("by rating");
             Description = Catalog.GetString ("Play songs randomly, prefer higher rated songs");
 
-            Condition = "(CoreTracks.Rating = ? OR (? = 3 AND CoreTracks.Rating = 0))";
-            OrderBy = "RANDOM()";
+            Condition = String.Format ("({0} = ? OR (? = 3 AND {0} = 0))", BansheeQuery.RatingField.Column);
+            OrderBy = BansheeQuery.GetRandomSort ();
         }
 
         protected override IEnumerable<object> GetConditionParameters (DateTime after)
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByScore.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByScore.cs
index 28fda52..e27317b 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByScore.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByScore.cs
@@ -31,6 +31,7 @@ using System.Collections.Generic;
 
 using Mono.Unix;
 
+using Banshee.Query;
 using Banshee.PlaybackController;
 
 namespace Banshee.Collection.Database
@@ -43,8 +44,9 @@ namespace Banshee.Collection.Database
             Adverb = Catalog.GetString ("by score");
             Description = Catalog.GetString ("Play songs randomly, prefer higher scored songs");
 
-            Condition = "(CoreTracks.Score BETWEEN ? AND ? OR (? = 50 AND CoreTracks.Score = 0))";
-            OrderBy = "RANDOM()";
+            Condition = String.Format ("({0} BETWEEN ? AND ? OR (? = 50 AND {0} = 0))",
+                                       BansheeQuery.ScoreField.Column);
+            OrderBy = BansheeQuery.GetRandomSort ();
         }
 
         protected override IEnumerable<object> GetConditionParameters (DateTime after)
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByTrack.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByTrack.cs
index 6e7b4f5..f85ddd7 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByTrack.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/RandomByTrack.cs
@@ -48,7 +48,7 @@ namespace Banshee.Collection.Database
             Description = Catalog.GetString ("Play songs randomly from the playlist");
 
             Condition = "1=1";
-            OrderBy = "RANDOM()";
+            OrderBy = Banshee.Query.BansheeQuery.GetRandomSort ();
         }
 
         public override bool Next (DateTime after)
diff --git a/src/Core/Banshee.Services/Banshee.Collection/RescanPipeline.cs b/src/Core/Banshee.Services/Banshee.Collection/RescanPipeline.cs
index 572f830..82441e2 100644
--- a/src/Core/Banshee.Services/Banshee.Collection/RescanPipeline.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection/RescanPipeline.cs
@@ -137,8 +137,9 @@ namespace Banshee.Collection
             this.psource = psource;
             this.scan_started = scan_started;
 
-            fetch_command = DatabaseTrackInfo.Provider.CreateFetchCommand (
-                "CoreTracks.PrimarySourceID = ? AND CoreTracks.Uri = ? LIMIT 1");
+            fetch_command = DatabaseTrackInfo.Provider.CreateFetchCommand (String.Format (
+                "CoreTracks.PrimarySourceID = ? AND {0} = ? LIMIT 1",
+                Banshee.Query.BansheeQuery.UriField.Column));
 
             fetch_similar_command = DatabaseTrackInfo.Provider.CreateFetchCommand (
                 "CoreTracks.PrimarySourceID = ? AND CoreTracks.LastSyncedStamp < ? AND CoreTracks.MetadataHash = ?");
diff --git a/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs b/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
index 783faa3..c7b21bf 100644
--- a/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
+++ b/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
@@ -353,7 +353,7 @@ namespace Banshee.Query
             PlayCountField.ShortLabel   = Catalog.GetString ("Plays");
 
             default_sort = String.Format (default_sort_template, "");
-            default_sort_by_year = String.Format (default_sort_template, "CoreTracks.Year ASC, ");
+            default_sort_by_year = String.Format (default_sort_template, YearField.Column + " ASC, ");
 
             RandomOrder = CreateRandomQueryOrder ();
 
@@ -403,7 +403,7 @@ namespace Banshee.Query
             }
 
             bool sort_by_year = Banshee.Configuration.Schema.LibrarySchema.SortByAlbumYear.Get ();
-            string sort_by_year_part = sort_by_year ? "CoreTracks.Year ASC," : "";
+            string sort_by_year_part = sort_by_year ? YearField.Column + " ASC," : "";
             string sort = sort_by_year ? default_sort_by_year : default_sort;
 
             string ascDesc = asc ? "ASC" : "DESC";
@@ -415,9 +415,9 @@ namespace Banshee.Query
                     CoreAlbums.ArtistNameSortKey ASC,
                     {0}
                     CoreAlbums.TitleSortKey ASC,
-                    CoreTracks.Disc ASC,
-                    {1} {2}",
-                    sort_by_year_part, TrackNumberField.Column, ascDesc);
+                    {1} ASC,
+                    {2} {3}",
+                    sort_by_year_part, DiscNumberField.Column, TrackNumberField.Column, ascDesc);
             }
 
             else if (field.Equals (AlbumArtistField)) {
@@ -426,8 +426,9 @@ namespace Banshee.Query
                     CoreAlbums.ArtistNameSortKey {0},
                     {1}
                     CoreAlbums.TitleSortKey ASC,
-                    CoreTracks.Disc ASC,
-                    CoreTracks.TrackNumber ASC", ascDesc, sort_by_year_part);
+                    {2} ASC,
+                    {3} ASC",
+                    ascDesc, sort_by_year_part, DiscNumberField.Column, TrackNumberField.Column);
             }
 
             else if (field.Equals (ArtistField)) {
@@ -436,16 +437,18 @@ namespace Banshee.Query
                     CoreArtists.NameSortKey {0},
                     {1}
                     CoreAlbums.TitleSortKey ASC,
-                    CoreTracks.Disc ASC,
-                    CoreTracks.TrackNumber ASC", ascDesc, sort_by_year_part);
+                    {2} ASC,
+                    {3} ASC",
+                    ascDesc, sort_by_year_part, DiscNumberField.Column, TrackNumberField.Column);
             }
 
             else if (field.Equals (AlbumField)) {
                 sort_query = String.Format (@"
                     CoreAlbums.TitleSortKey {0},
                     {1}
-                    CoreTracks.Disc ASC,
-                    CoreTracks.TrackNumber ASC", ascDesc, sort_by_year_part);
+                    {2} ASC,
+                    {3} ASC",
+                    ascDesc, sort_by_year_part, DiscNumberField.Column, TrackNumberField.Column);
             }
 
             else if (field.Equals (TitleField)) {
@@ -459,10 +462,11 @@ namespace Banshee.Query
             else if (field.Equals (DiscNumberField)) {
                 sort_query = String.Format (@"
                     CoreAlbums.ArtistNameSortKey ASC,
-                    {1}
+                    {0}
                     CoreAlbums.TitleSortKey ASC,
-                    CoreTracks.Disc {0},
-                    CoreTracks.TrackNumber ASC", ascDesc, sort_by_year_part);
+                    {1} {2},
+                    {3} ASC",
+                    sort_by_year_part, DiscNumberField.Column, ascDesc, TrackNumberField.Column);
             }
 
             else if (field.Equals (ScoreField)) {
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AmazonMp3GroupSource.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AmazonMp3GroupSource.cs
index 1041187..b03a0f9 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AmazonMp3GroupSource.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/AmazonMp3GroupSource.cs
@@ -45,7 +45,7 @@ namespace Banshee.Dap.MassStorage
             this.amazon_base_dir = amazon_base_dir;
 
             Properties.SetString ("Icon.Name", "amazon-mp3-source");
-            ConditionSql = String.Format ("(CoreTracks.Uri LIKE \"%{0}%\")", amazon_dir);
+            ConditionSql = String.Format ("({0} LIKE \"%{1}%\")", Banshee.Query.BansheeQuery.UriField.Column, amazon_dir);
         }
 
         public override void Activate ()
diff --git a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs
index 52d697e..ffbecb2 100644
--- a/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs
+++ b/src/Dap/Banshee.Dap.MassStorage/Banshee.Dap.MassStorage/WebOSDevice.cs
@@ -194,7 +194,7 @@ namespace Banshee.Dap.MassStorage
         public RingtonesGroupSource (DapSource parent)
             : base (parent, Catalog.GetString ("Ringtones"))
         {
-            ConditionSql = "(CoreTracks.Uri LIKE \"%ringtones/%\")";
+            ConditionSql = String.Format ("({0} LIKE \"%ringtones/%\")", Banshee.Query.BansheeQuery.UriField.Column);
         }
     }
 
diff --git a/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs b/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs
index cee72d4..f42f1f2 100644
--- a/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs
+++ b/src/Extensions/Banshee.CoverArt/Banshee.CoverArt/CoverArtJob.cs
@@ -79,8 +79,8 @@ namespace Banshee.CoverArt
                 ServiceManager.SourceManager.MusicLibrary.DbId, last_scan, last_scan - retry_every
             );
 
-            SelectCommand = new HyenaSqliteCommand (@"
-                SELECT DISTINCT CoreAlbums.AlbumID, CoreAlbums.Title, CoreArtists.Name, CoreTracks.Uri, CoreTracks.TrackID
+            SelectCommand = new HyenaSqliteCommand (String.Format (@"
+                SELECT DISTINCT CoreAlbums.AlbumID, CoreAlbums.Title, CoreArtists.Name, {0}, CoreTracks.TrackID
                     FROM CoreTracks, CoreArtists, CoreAlbums
                     WHERE
                         CoreTracks.PrimarySourceID = ? AND
@@ -91,6 +91,7 @@ namespace Banshee.CoverArt
                             SELECT AlbumID FROM CoverArtDownloads WHERE
                                 LastAttempt > ? OR Downloaded = 1)
                     GROUP BY CoreTracks.AlbumID ORDER BY CoreTracks.DateUpdatedStamp DESC LIMIT ?",
+                Banshee.Query.BansheeQuery.UriField.Column),
                 ServiceManager.SourceManager.MusicLibrary.DbId, last_scan, last_scan - retry_every, 1
             );
 
diff --git a/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs b/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
index bb146cc..77fa20a 100644
--- a/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
+++ b/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
@@ -200,8 +200,10 @@ namespace Banshee.LibraryWatcher
         private void UpdateTrack (string track)
         {
             using (var reader = ServiceManager.DbConnection.Query (
-                DatabaseTrackInfo.Provider.CreateFetchCommand (
-                "CoreTracks.PrimarySourceID = ? AND CoreTracks.Uri = ? LIMIT 1"), library.DbId, new SafeUri (track).AbsoluteUri)) {
+                DatabaseTrackInfo.Provider.CreateFetchCommand (String.Format (
+                "CoreTracks.PrimarySourceID = ? AND {0} = ? LIMIT 1",
+                Banshee.Query.BansheeQuery.UriField.Column)),
+                library.DbId, new SafeUri (track).AbsoluteUri)) {
                 if (reader.Read ()) {
                     var track_info = DatabaseTrackInfo.Provider.Load (reader);
                     if (Banshee.IO.File.GetModifiedTime (track_info.Uri) > track_info.FileModifiedStamp) {
diff --git a/src/Extensions/Banshee.OpticalDisc/Banshee.OpticalDisc.AudioCd/AudioCdSource.cs b/src/Extensions/Banshee.OpticalDisc/Banshee.OpticalDisc.AudioCd/AudioCdSource.cs
index 62a6edb..5c6b52f 100644
--- a/src/Extensions/Banshee.OpticalDisc/Banshee.OpticalDisc.AudioCd/AudioCdSource.cs
+++ b/src/Extensions/Banshee.OpticalDisc/Banshee.OpticalDisc.AudioCd/AudioCdSource.cs
@@ -160,12 +160,13 @@ namespace Banshee.OpticalDisc.AudioCd
         {
             // Make sure the album isn't already in the Library
             TrackInfo track = Model[0];
-            int count = ServiceManager.DbConnection.Query<int> (
+            int count = ServiceManager.DbConnection.Query<int> (String.Format (
                 @"SELECT Count(*) FROM CoreTracks, CoreArtists, CoreAlbums WHERE
                     CoreTracks.PrimarySourceID = ? AND
                     CoreTracks.ArtistID = CoreArtists.ArtistID AND
                     CoreTracks.AlbumID = CoreAlbums.AlbumID AND
-                    CoreArtists.Name = ? AND CoreAlbums.Title = ? AND (CoreTracks.Disc = ? OR CoreTracks.Disc = 0)",
+                    CoreArtists.Name = ? AND CoreAlbums.Title = ? AND ({0} = ? OR {0} = 0)",
+                    Banshee.Query.BansheeQuery.DiscNumberField.Column),
                     ServiceManager.SourceManager.MusicLibrary.DbId,
                     track.ArtistName, track.AlbumTitle, track.DiscNumber
             );
diff --git a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs
index b9591ef..e10f2ae 100644
--- a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs
+++ b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastSource.cs
@@ -42,6 +42,7 @@ using Hyena.Data.Sqlite;
 
 using Banshee.Gui;
 using Banshee.Base;
+using Banshee.Query;
 using Banshee.Database;
 using Banshee.Collection;
 using Banshee.ServiceStack;
@@ -213,7 +214,8 @@ namespace Banshee.Podcasting.Gui
             TrackArtworkIdHandler = GetTrackArtworkId;
             MediaTypes = TrackMediaAttributes.Podcast;
             NotMediaTypes = TrackMediaAttributes.AudioBook;
-            SyncCondition = "(substr(CoreTracks.Uri, 0, 4) != 'http' AND CoreTracks.PlayCount = 0)";
+            SyncCondition = String.Format ("(substr({0}, 0, 4) != 'http' AND {1} = 0)",
+                                           BansheeQuery.UriField.Column, BansheeQuery.PlayCountField.Column);
             TrackModel.Reloaded += OnReloaded;
 
             Properties.SetString ("Icon.Name", "podcast");
diff --git a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs
index d4acbcc..50e0b6e 100644
--- a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs
+++ b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackListModel.cs
@@ -40,6 +40,7 @@ using Hyena.Data.Sqlite;
 
 using Banshee.Gui;
 using Banshee.Base;
+using Banshee.Query;
 using Banshee.Database;
 using Banshee.Collection;
 using Banshee.ServiceStack;
@@ -66,7 +67,8 @@ namespace Banshee.Podcasting.Gui
                 Feed.Provider.TableName, FeedItem.Provider.TableName, FeedEnclosure.Provider.TableName, podcast_library_dbid
             ));
 
-            SelectAggregates += ",COUNT(NULLIF(CoreTracks.Uri LIKE 'file:%', 0)), COUNT(NULLIF(CoreTracks.PlayCount = 0, 0)), COUNT(DISTINCT(CoreTracks.AlbumID))";
+            SelectAggregates += String.Format (",COUNT(NULLIF({0} LIKE 'file:%', 0)), COUNT(NULLIF({1} = 0, 0)), COUNT(DISTINCT(CoreTracks.AlbumID))",
+                                               BansheeQuery.UriField.Column, BansheeQuery.PlayCountField.Column);
             SelectionAggregatesHandler = (reader) => {
                 SelectionDownloadedCount = Convert.ToInt32 (reader[3]);
                 SelectionUnheardCount = Convert.ToInt32 (reader[4]);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]