[banshee] DatabaseTrackInfo: reuse another SQL query
- From: AndrÃs Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] DatabaseTrackInfo: reuse another SQL query
- Date: Thu, 22 Dec 2011 01:01:19 +0000 (UTC)
commit 2625a34f50cdae2f6d61c2ab39d4985e5b1d5962
Author: Andres G. Aragoneses <knocte gmail com>
Date: Thu Dec 22 01:01:18 2011 +0000
DatabaseTrackInfo: reuse another SQL query
Reuse another SQL instruction for querying
the TrackID filtering by Uri. The UriField is
now also used, which prevents hardcoding the
Uri column name.
This also prevents that someone could misuse
the GetTrackIdForUri method by passing null
or an empty array, as the primary_sources param
was not validated before.
Signed-off-by: Alexander Kojevnikov <alexk gnome org>
.../DatabaseTrackInfo.cs | 24 ++++++++++++++-----
1 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
index ee7d0e6..8502b5b 100644
--- a/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
+++ b/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
@@ -770,15 +770,21 @@ namespace Banshee.Collection.Database
return copy_success;
}
- private static HyenaSqliteCommand get_uri_id_cmd = new HyenaSqliteCommand ("SELECT TrackID FROM CoreTracks WHERE Uri = ? LIMIT 1");
public static int GetTrackIdForUri (string uri)
{
- return ServiceManager.DbConnection.Query<int> (get_uri_id_cmd, new SafeUri (uri).AbsoluteUri);
+ return GetTrackIdForUri (new SafeUri (uri));
}
- private static HyenaSqliteCommand get_track_id_by_uri = new HyenaSqliteCommand (
- "SELECT TrackID FROM CoreTracks WHERE PrimarySourceId IN (?) AND Uri = ? LIMIT 1"
- );
+ private static string get_track_id_by_uri =
+ "SELECT TrackID FROM CoreTracks WHERE {0} {1} = ? LIMIT 1";
+
+ private static HyenaSqliteCommand get_track_id_by_uri_primarysources = new HyenaSqliteCommand (String.Format (
+ get_track_id_by_uri, "PrimarySourceId IN (?) AND", BansheeQuery.UriField.Column
+ ));
+
+ private static HyenaSqliteCommand get_track_id_by_uri_plain = new HyenaSqliteCommand (String.Format (
+ get_track_id_by_uri, string.Empty, BansheeQuery.UriField.Column
+ ));
private static string get_track_by_metadata_hash =
"SELECT {0} FROM {1} WHERE {2} AND PrimarySourceId IN (?) AND MetadataHash = ? LIMIT 1";
@@ -789,8 +795,12 @@ namespace Banshee.Collection.Database
public static int GetTrackIdForUri (SafeUri uri, params int [] primary_sources)
{
- return ServiceManager.DbConnection.Query<int> (get_track_id_by_uri,
- primary_sources, uri.AbsoluteUri);
+ if (primary_sources == null || primary_sources.Length == 0) {
+ return ServiceManager.DbConnection.Query<int> (get_track_id_by_uri_plain, uri.AbsoluteUri);
+ }
+ return ServiceManager.DbConnection.Query<int> (
+ get_track_id_by_uri_primarysources, primary_sources, uri.AbsoluteUri
+ );
}
public static int GetTrackIdForUri (string absoluteUri, int [] primary_sources)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]