[banshee] Services: more reuse of the UriField object
- From: AndrÃs Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] Services: more reuse of the UriField object
- Date: Tue, 27 Dec 2011 23:33:04 +0000 (UTC)
commit e4274c45fd50188036d40a7fa7d147ef529c8881
Author: Andres G. Aragoneses <knocte gmail com>
Date: Tue Dec 27 23:31:05 2011 +0000
Services: more reuse of the UriField object
More reuse of QueryField instances so the
column names are hardcoded in less places.
These seem to be the last cases.
Signed-off-by: Alexander Kojevnikov <alexk gnome org>
.../Banshee.Sources/PrimarySource.cs | 7 +++--
.../Banshee.Bpm/Banshee.Bpm/BpmDetectJob.cs | 6 ++--
.../Banshee.LibraryWatcher/SourceWatcher.cs | 28 +++++++++++++------
.../Banshee.Podcasting/PodcastService.cs | 6 +++-
4 files changed, 30 insertions(+), 17 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
index eb127a7..fd055e0 100644
--- a/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
+++ b/src/Core/Banshee.Services/Banshee.Sources/PrimarySource.cs
@@ -97,10 +97,11 @@ namespace Banshee.Sources
FROM CoreTracks WHERE TrackID IN (SELECT {0});
DELETE FROM CoreTracks WHERE TrackID IN (SELECT {0})";
- protected HyenaSqliteCommand remove_list_command = new HyenaSqliteCommand (@"
- INSERT INTO CoreRemovedTracks (DateRemovedStamp, TrackID, Uri) SELECT ?, TrackID, Uri FROM CoreTracks WHERE TrackID IN (SELECT ItemID FROM CoreCache WHERE ModelID = ?);
+ protected HyenaSqliteCommand remove_list_command = new HyenaSqliteCommand (String.Format (@"
+ INSERT INTO CoreRemovedTracks (DateRemovedStamp, TrackID, Uri)
+ SELECT ?, TrackID, {0} FROM CoreTracks WHERE TrackID IN (SELECT ItemID FROM CoreCache WHERE ModelID = ?);
DELETE FROM CoreTracks WHERE TrackID IN (SELECT ItemID FROM CoreCache WHERE ModelID = ?)
- ");
+ ", BansheeQuery.UriField.Column));
protected HyenaSqliteCommand prune_artists_albums_command = new HyenaSqliteCommand (@"
DELETE FROM CoreArtists WHERE ArtistID NOT IN (SELECT ArtistID FROM CoreTracks);
diff --git a/src/Extensions/Banshee.Bpm/Banshee.Bpm/BpmDetectJob.cs b/src/Extensions/Banshee.Bpm/Banshee.Bpm/BpmDetectJob.cs
index 08621fd..6cb1fbb 100644
--- a/src/Extensions/Banshee.Bpm/Banshee.Bpm/BpmDetectJob.cs
+++ b/src/Extensions/Banshee.Bpm/Banshee.Bpm/BpmDetectJob.cs
@@ -76,10 +76,10 @@ namespace Banshee.Bpm
));
SelectCommand = new HyenaSqliteCommand (String.Format (@"
- SELECT DISTINCT Uri, TrackID
+ SELECT DISTINCT {0}, TrackID
FROM CoreTracks
- WHERE PrimarySourceID IN ({0}) AND (BPM = 0 OR BPM IS NULL) LIMIT 1",
- music_library.DbId
+ WHERE PrimarySourceID IN ({1}) AND (BPM IS NULL OR BPM = 0) LIMIT 1",
+ Banshee.Query.BansheeQuery.UriField.Column, music_library.DbId
));
Register ();
diff --git a/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs b/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
index ceb03db..a95a910 100644
--- a/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
+++ b/src/Extensions/Banshee.LibraryWatcher/Banshee.LibraryWatcher/SourceWatcher.cs
@@ -42,6 +42,7 @@ using Banshee.Collection;
using Banshee.Collection.Database;
using Banshee.Library;
using Banshee.Metadata;
+using Banshee.Query;
using Banshee.ServiceStack;
using Banshee.Sources;
using Banshee.Streaming;
@@ -203,7 +204,7 @@ namespace Banshee.LibraryWatcher
using (var reader = ServiceManager.DbConnection.Query (
DatabaseTrackInfo.Provider.CreateFetchCommand (String.Format (
"CoreTracks.PrimarySourceID = ? AND {0} = ? LIMIT 1",
- Banshee.Query.BansheeQuery.UriField.Column)),
+ BansheeQuery.UriField.Column)),
library.DbId, new SafeUri (track).AbsoluteUri)) {
if (reader.Read ()) {
var track_info = DatabaseTrackInfo.Provider.Load (reader);
@@ -226,17 +227,21 @@ namespace Banshee.LibraryWatcher
// Trigger file rename.
string uri = new SafeUri(track).AbsoluteUri;
- HyenaSqliteCommand command = new HyenaSqliteCommand (@"
+ var command = new HyenaSqliteCommand (String.Format (@"
UPDATE CoreTracks
SET DateUpdatedStamp = LastSyncedStamp + 1
- WHERE Uri = ?", uri);
+ WHERE {0} = ?",
+ BansheeQuery.UriField.Column), uri);
ServiceManager.DbConnection.Execute (command);
}
private void RemoveTrack (string track)
{
string uri = new SafeUri(track).AbsoluteUri;
- const string hash_sql = @"SELECT TrackID, MetadataHash FROM CoreTracks WHERE Uri = ? LIMIT 1";
+ const string hash_sql = String.Format (
+ @"SELECT TrackID, MetadataHash FROM CoreTracks WHERE {0} = ? LIMIT 1",
+ BansheeQuery.UriField.Column
+ );
int track_id = 0;
string hash = null;
using (var reader = new HyenaDataReader (ServiceManager.DbConnection.Query (hash_sql, uri))) {
@@ -260,7 +265,8 @@ namespace Banshee.LibraryWatcher
const string delete_sql = @"
INSERT INTO CoreRemovedTracks (DateRemovedStamp, TrackID, Uri)
- SELECT ?, TrackID, Uri FROM CoreTracks WHERE TrackID IN ({0})
+ SELECT ?, TrackID, " + BansheeQuery.UriField.Column + @"
+ FROM CoreTracks WHERE TrackID IN ({0})
;
DELETE FROM CoreTracks WHERE TrackID IN ({0})";
@@ -272,7 +278,9 @@ namespace Banshee.LibraryWatcher
} else {
string pattern = StringUtil.EscapeLike (uri) + "/_%";
delete_command = new HyenaSqliteCommand (String.Format (delete_sql,
- @"SELECT TrackID FROM CoreTracks WHERE Uri LIKE ? ESCAPE '\'"), DateTime.Now, pattern, pattern);
+ @"SELECT TrackID FROM CoreTracks
+ WHERE " + BansheeQuery.UriField.Column + " LIKE ? ESCAPE '\'"),
+ DateTime.Now, pattern, pattern);
}
ServiceManager.DbConnection.Execute (delete_command);
@@ -287,10 +295,12 @@ namespace Banshee.LibraryWatcher
string old_uri = new SafeUri (oldFullPath).AbsoluteUri;
string new_uri = new SafeUri (fullPath).AbsoluteUri;
string pattern = StringUtil.EscapeLike (old_uri) + "%";
- HyenaSqliteCommand rename_command = new HyenaSqliteCommand (@"
+ var rename_command = new HyenaSqliteCommand (String.Format (@"
UPDATE CoreTracks
- SET Uri = REPLACE(Uri, ?, ?), DateUpdatedStamp = ?
- WHERE Uri LIKE ? ESCAPE '\'",
+ SET Uri = REPLACE ({0}, ?, ?),
+ DateUpdatedStamp = ?
+ WHERE {0} LIKE ? ESCAPE '\'",
+ BansheeQuery.UriField.Column),
old_uri, new_uri, DateTime.Now, pattern);
ServiceManager.DbConnection.Execute (rename_command);
}
diff --git a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs
index ce98568..5131f2b 100644
--- a/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs
+++ b/src/Extensions/Banshee.Podcasting/Banshee.Podcasting/PodcastService.cs
@@ -263,8 +263,10 @@ namespace Banshee.Podcasting
ServiceManager.DbConnection.Execute (String.Format (
"UPDATE {0} SET LocalPath = REPLACE(LocalPath, ?, ?) WHERE LocalPath IS NOT NULL",
FeedEnclosure.Provider.TableName), old_path, new_path);
- ServiceManager.DbConnection.Execute (
- "UPDATE CoreTracks SET Uri = REPLACE(Uri, ?, ?) WHERE Uri LIKE 'file://%' AND PrimarySourceId = ?",
+ ServiceManager.DbConnection.Execute (String.Format (
+ "UPDATE CoreTracks SET Uri = REPLACE ({0}, ?, ?)" +
+ "WHERE {0} LIKE 'file://%' AND PrimarySourceId = ?",
+ Banshee.Query.BansheeQuery.UriField.Column),
old_uri.AbsoluteUri, new_uri.AbsoluteUri, source.DbId);
Hyena.Log.DebugFormat ("Moved Podcasts from {0} to {1}", old_path, new_path);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]