banshee r3066 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Library src/Core/Banshee.Services/Banshee.Playlist src/Core/Hyena/Hyena.Data.Sqlite



Author: gburt
Date: Mon Jan 28 21:12:15 2008
New Revision: 3066
URL: http://svn.gnome.org/viewvc/banshee?rev=3066&view=rev

Log:
2008-01-28  Gabriel Burt  <gabriel burt gmail com>

	* src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs: Change API.
	Used to have ctor(command, int) where int was the number of paramters.
	This was used primarily for stored, reused commands.  But, this ctor was
	ambiguous with the ctor(command, params object [] values), used to create
	a command and immediately apply values to it.  So, instead of passing the
	int, you can now just pass the command, and it will be scanned for '?'.

	* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs:
	* src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs:
	* src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs:
	* src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs:
	* src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs:
	* src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs: Use new
	HyenaSqliteCommand API.


Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs
   trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryAlbumInfo.cs	Mon Jan 28 21:12:15 2008
@@ -49,7 +49,7 @@
         }
 
         private static HyenaSqliteCommand select_command = new HyenaSqliteCommand (
-            "SELECT AlbumID, Title FROM CoreAlbums WHERE ArtistID = ? AND Title = ?", 2
+            "SELECT AlbumID, Title FROM CoreAlbums WHERE ArtistID = ? AND Title = ?"
         );
 
         private enum Column : int {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryArtistInfo.cs	Mon Jan 28 21:12:15 2008
@@ -49,7 +49,7 @@
         }
 
         private static HyenaSqliteCommand select_command = new HyenaSqliteCommand (
-            "SELECT ArtistID, Name FROM CoreArtists WHERE Name = ?", 1
+            "SELECT ArtistID, Name FROM CoreArtists WHERE Name = ?"
         );
 
         private enum Column : int {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/LibraryTrackInfo.cs	Mon Jan 28 21:12:15 2008
@@ -234,7 +234,8 @@
         }
 
         private static HyenaSqliteCommand check_command = new HyenaSqliteCommand (
-            "SELECT COUNT(*) FROM CoreTracks WHERE Uri = ? OR Uri = ?", 2);
+            "SELECT COUNT(*) FROM CoreTracks WHERE Uri = ? OR Uri = ?"
+        );
         
         public static bool ContainsUri (SafeUri uri)
         {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Library/LibrarySource.cs	Mon Jan 28 21:12:15 2008
@@ -56,13 +56,13 @@
                     WHERE ModelID = ? LIMIT ?, ?);
             DELETE FROM CoreSmartPlaylistEntries WHERE TrackID IN
                 (SELECT ItemID FROM CoreCache
-                    WHERE ModelID = ? LIMIT ?, ?)", 9
+                    WHERE ModelID = ? LIMIT ?, ?)"
         );
 
         private HyenaSqliteCommand remove_track_command = new HyenaSqliteCommand (@"
             DELETE FROM CoreTracks WHERE TrackID = ?;
             DELETE FROM CorePlaylistEntries WHERE TrackID = ?;
-            DELETE FROM CoreSmartPlaylistEntries WHERE TrackID = ?", 3
+            DELETE FROM CoreSmartPlaylistEntries WHERE TrackID = ?"
         );
     
         public LibrarySource () : base (Catalog.GetString("Library"), Catalog.GetString ("Library"), "Library", 1)

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistFileUtil.cs	Mon Jan 28 21:12:15 2008
@@ -176,7 +176,7 @@
 
             HyenaSqliteCommand command = new HyenaSqliteCommand (
                 @"INSERT INTO CorePlaylistEntries (PlaylistID, TrackID)
-                    VALUES (?, (SELECT TrackID FROM CoreTracks WHERE Uri = ?))", 2
+                    VALUES (?, (SELECT TrackID FROM CoreTracks WHERE Uri = ?))"
             );
 
             foreach (string uri in uris) {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Playlist/PlaylistSource.cs	Mon Jan 28 21:12:15 2008
@@ -72,24 +72,24 @@
         static PlaylistSource () 
         {
             add_track_command = new HyenaSqliteCommand (
-                "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)", 2
+                "INSERT INTO CorePlaylistEntries (PlaylistID, TrackID) VALUES (?, ?)"
             );
 
             remove_track_command = new HyenaSqliteCommand (
-                "DELETE FROM CorePlaylistEntries WHERE PlaylistID = ? AND TrackID = ?", 2
+                "DELETE FROM CorePlaylistEntries WHERE PlaylistID = ? AND TrackID = ?"
             );
 
             add_track_range_command = new HyenaSqliteCommand (@"
                 INSERT INTO CorePlaylistEntries
                     SELECT null, ?, ItemID, 0
                         FROM CoreCache WHERE ModelID = ?
-                        LIMIT ?, ?", 4
+                        LIMIT ?, ?"
             );
 
             remove_track_range_command = new HyenaSqliteCommand (@"
                 DELETE FROM CorePlaylistEntries WHERE PlaylistID = ? AND
                     TrackID IN (SELECT ItemID FROM CoreCache
-                        WHERE ModelID = ? LIMIT ?, ?)", 4
+                        WHERE ModelID = ? LIMIT ?, ?)"
             );
         }
 

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/HyenaSqliteCommand.cs	Mon Jan 28 21:12:15 2008
@@ -57,20 +57,31 @@
         public HyenaSqliteCommand (string command)
         {
             this.command = new SqliteCommand (command);
-        }
 
-        public HyenaSqliteCommand (string command, int num_params) : this (command)
-        {
-            for (int i = 0; i < num_params; i++) {
-                Parameters.Add (new SqliteParameter ());
+            int num_params = 0;
+            foreach (char c in command) {
+                if (c == '?') {
+                    num_params++;
+                }
             }
+
+            CreateParameters (num_params);
         }
 
-        public HyenaSqliteCommand (string command, params object [] param_values) : this (command, param_values.Length)
+        public HyenaSqliteCommand (string command, params object [] param_values)
         {
+            this.command = new SqliteCommand (command);
+            CreateParameters (param_values.Length);
             ApplyValues (param_values);
         }
 
+        protected void CreateParameters (int num_params)
+        {
+            for (int i = 0; i < num_params; i++) {
+                Parameters.Add (new SqliteParameter ());
+            }
+        }
+
         public HyenaSqliteCommand ApplyValues (params object [] param_values)
         {
             if (param_values.Length != Parameters.Count) {

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelCache.cs	Mon Jan 28 21:12:15 2008
@@ -63,7 +63,7 @@
             count_command = new HyenaSqliteCommand (
                 String.Format (
                     "SELECT COUNT(*) FROM {0} WHERE ModelID = ?", CacheTableName
-                ), 1
+                )
             );
 
             FindOrCreateCacheModelId (String.Format ("{0}-{1}", uuid, typeof(T).Name));
@@ -81,7 +81,7 @@
                     provider.PrimaryKey, uid,
                     String.IsNullOrEmpty (provider.Where) ? String.Empty : "AND",
                     provider.Where
-                ), 2
+                )
             );
             
             select_single_command = new HyenaSqliteCommand (
@@ -91,7 +91,7 @@
                             ModelID = {1} AND
                             ItemID = ?",
                     CacheTableName, uid
-                ), 1
+                )
             );
             
             select_first_command = new HyenaSqliteCommand (

Modified: trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs
==============================================================================
--- trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs	(original)
+++ trunk/banshee/src/Core/Hyena/Hyena.Data.Sqlite/SqliteModelProvider.cs	Mon Jan 28 21:12:15 2008
@@ -371,7 +371,6 @@
                 if (insert_command == null) {
                     StringBuilder cols = new StringBuilder ();
                     StringBuilder vals = new StringBuilder ();
-                    int count = 0;
                     bool first = true;
                     foreach (DatabaseColumn column in columns) {
                         if (first) {
@@ -382,12 +381,11 @@
                         }
                         cols.Append (column.Name);
                         vals.Append ('?');
-                        count++;
                     }
 
                     insert_command = new HyenaSqliteCommand (String.Format (
                         "INSERT INTO {0} ({1}) VALUES ({2})",
-                        TableName, cols.ToString (), vals.ToString ()), count
+                        TableName, cols.ToString (), vals.ToString ())
                     );
                 }
                 return insert_command;
@@ -401,7 +399,6 @@
                     builder.Append ("UPDATE ");
                     builder.Append (TableName);
                     builder.Append (" SET ");
-                    int count = 0;
                     bool first = true;
                     foreach (DatabaseColumn column in columns) {
                         if (first) {
@@ -411,13 +408,11 @@
                         }
                         builder.Append (column.Name);
                         builder.Append (" = ?");
-                        count++;
                     }
                     builder.Append (" WHERE ");
                     builder.Append (key.Name);
                     builder.Append (" = ?");
-                    count++;
-                    update_command = new HyenaSqliteCommand (builder.ToString (), count);
+                    update_command = new HyenaSqliteCommand (builder.ToString ());
                 }
                 return update_command;
             }
@@ -448,7 +443,7 @@
                             Select, From,
                             (String.IsNullOrEmpty (Where) ? String.Empty : " WHERE "),
                             Where
-                        ), 2
+                        )
                     );
                 }
                 return select_range_command;
@@ -464,7 +459,7 @@
                             Select, From, Where,
                             (String.IsNullOrEmpty (Where) ? String.Empty : " AND "),
                             PrimaryKey
-                        ), 1
+                        )
                     );
                 }
                 return select_single_command;



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