From 64d15be8390c6174eb7ded067715c226038b38fc Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Nov 2016 00:59:36 -0500 Subject: update queries --- .../Activity/ActivityRepository.cs | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'Emby.Server.Implementations/Activity/ActivityRepository.cs') diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs index 8f64f04db..aaa0b2f5d 100644 --- a/Emby.Server.Implementations/Activity/ActivityRepository.cs +++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs @@ -57,18 +57,21 @@ namespace Emby.Server.Implementations.Activity { connection.RunInTransaction(db => { - var commandText = "replace into ActivityLogEntries (Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"; - - db.Execute(commandText, - entry.Id.ToGuidParamValue(), - entry.Name, - entry.Overview, - entry.ShortOverview, - entry.Type, - entry.ItemId, - entry.UserId, - entry.Date.ToDateTimeParamValue(), - entry.Severity.ToString()); + using (var statement = db.PrepareStatement("replace into ActivityLogEntries (Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Id, @Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)")) + { + statement.BindParameters.TryBind("@Id", entry.Id.ToGuidParamValue()); + statement.BindParameters.TryBind("@Name", entry.Name); + + statement.BindParameters.TryBind("@Overview", entry.Overview); + statement.BindParameters.TryBind("@ShortOverview", entry.ShortOverview); + statement.BindParameters.TryBind("@Type", entry.Type); + statement.BindParameters.TryBind("@ItemId", entry.ItemId); + statement.BindParameters.TryBind("@UserId", entry.UserId); + statement.BindParameters.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue()); + statement.BindParameters.TryBind("@LogSeverity", entry.Severity.ToString()); + + statement.MoveNext(); + } }); } } -- cgit v1.2.3 From 7f62a99ab508551b83568051a874703ddd50b563 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Nov 2016 02:10:07 -0500 Subject: update extensions --- .../Activity/ActivityRepository.cs | 20 ++-- .../Data/SqliteDisplayPreferencesRepository.cs | 16 +-- .../Data/SqliteExtensions.cs | 115 ++++++++++++++++++--- .../Data/SqliteUserDataRepository.cs | 34 +++--- .../Data/SqliteUserRepository.cs | 6 +- .../Notifications/SqliteNotificationsRepository.cs | 34 +++--- .../Security/AuthenticationRepository.cs | 30 +++--- Emby.Server.Implementations/Sync/SyncRepository.cs | 4 +- 8 files changed, 173 insertions(+), 86 deletions(-) (limited to 'Emby.Server.Implementations/Activity/ActivityRepository.cs') diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs index aaa0b2f5d..ebf93fa33 100644 --- a/Emby.Server.Implementations/Activity/ActivityRepository.cs +++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs @@ -59,16 +59,16 @@ namespace Emby.Server.Implementations.Activity { using (var statement = db.PrepareStatement("replace into ActivityLogEntries (Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Id, @Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)")) { - statement.BindParameters.TryBind("@Id", entry.Id.ToGuidParamValue()); - statement.BindParameters.TryBind("@Name", entry.Name); - - statement.BindParameters.TryBind("@Overview", entry.Overview); - statement.BindParameters.TryBind("@ShortOverview", entry.ShortOverview); - statement.BindParameters.TryBind("@Type", entry.Type); - statement.BindParameters.TryBind("@ItemId", entry.ItemId); - statement.BindParameters.TryBind("@UserId", entry.UserId); - statement.BindParameters.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue()); - statement.BindParameters.TryBind("@LogSeverity", entry.Severity.ToString()); + statement.TryBind("@Id", entry.Id.ToGuidParamValue()); + statement.TryBind("@Name", entry.Name); + + statement.TryBind("@Overview", entry.Overview); + statement.TryBind("@ShortOverview", entry.ShortOverview); + statement.TryBind("@Type", entry.Type); + statement.TryBind("@ItemId", entry.ItemId); + statement.TryBind("@UserId", entry.UserId); + statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue()); + statement.TryBind("@LogSeverity", entry.Severity.ToString()); statement.MoveNext(); } diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs index 1c592048e..184caa4d4 100644 --- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs @@ -104,10 +104,10 @@ namespace Emby.Server.Implementations.Data { var serialized = _jsonSerializer.SerializeToBytes(displayPreferences, _memoryStreamProvider); - statement.BindParameters.TryBind("@id", displayPreferences.Id.ToGuidParamValue()); - statement.BindParameters.TryBind("@userId", userId.ToGuidParamValue()); - statement.BindParameters.TryBind("@client", client); - statement.BindParameters.TryBind("@data", serialized); + statement.TryBind("@id", displayPreferences.Id.ToGuidParamValue()); + statement.TryBind("@userId", userId.ToGuidParamValue()); + statement.TryBind("@client", client); + statement.TryBind("@data", serialized); statement.MoveNext(); } @@ -168,9 +168,9 @@ namespace Emby.Server.Implementations.Data { using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where id = @id and userId=@userId and client=@client")) { - statement.BindParameters.TryBind("@id", guidId.ToGuidParamValue()); - statement.BindParameters.TryBind("@userId", userId.ToGuidParamValue()); - statement.BindParameters.TryBind("@client", client); + statement.TryBind("@id", guidId.ToGuidParamValue()); + statement.TryBind("@userId", userId.ToGuidParamValue()); + statement.TryBind("@client", client); foreach (var row in statement.ExecuteQuery()) { @@ -202,7 +202,7 @@ namespace Emby.Server.Implementations.Data { using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where userId=@userId")) { - statement.BindParameters.TryBind("@userId", userId.ToGuidParamValue()); + statement.TryBind("@userId", userId.ToGuidParamValue()); foreach (var row in statement.ExecuteQuery()) { diff --git a/Emby.Server.Implementations/Data/SqliteExtensions.cs b/Emby.Server.Implementations/Data/SqliteExtensions.cs index 0f4f703a0..657dadfe5 100644 --- a/Emby.Server.Implementations/Data/SqliteExtensions.cs +++ b/Emby.Server.Implementations/Data/SqliteExtensions.cs @@ -173,69 +173,156 @@ namespace Emby.Server.Implementations.Data return result[index].ReadGuid(); } - public static void TryBind(this IReadOnlyDictionary bindParameters, string name, double value) + public static void TryBind(this IStatement statement, string name, double value) { IBindParameter bindParam; - if (bindParameters.TryGetValue(name, out bindParam)) + if (statement.BindParameters.TryGetValue(name, out bindParam)) { bindParam.Bind(value); } } - public static void TryBind(this IReadOnlyDictionary bindParameters, string name, string value) + public static void TryBind(this IStatement statement, string name, string value) { IBindParameter bindParam; - if (bindParameters.TryGetValue(name, out bindParam)) + if (statement.BindParameters.TryGetValue(name, out bindParam)) { bindParam.Bind(value); } } - public static void TryBind(this IReadOnlyDictionary bindParameters, string name, bool value) + public static void TryBind(this IStatement statement, string name, bool value) { IBindParameter bindParam; - if (bindParameters.TryGetValue(name, out bindParam)) + if (statement.BindParameters.TryGetValue(name, out bindParam)) { bindParam.Bind(value); } } - public static void TryBind(this IReadOnlyDictionary bindParameters, string name, int value) + public static void TryBind(this IStatement statement, string name, float value) { IBindParameter bindParam; - if (bindParameters.TryGetValue(name, out bindParam)) + if (statement.BindParameters.TryGetValue(name, out bindParam)) { bindParam.Bind(value); } } - public static void TryBind(this IReadOnlyDictionary bindParameters, string name, long value) + public static void TryBind(this IStatement statement, string name, int value) { IBindParameter bindParam; - if (bindParameters.TryGetValue(name, out bindParam)) + if (statement.BindParameters.TryGetValue(name, out bindParam)) { bindParam.Bind(value); } } - public static void TryBind(this IReadOnlyDictionary bindParameters, string name, byte[] value) + public static void TryBind(this IStatement statement, string name, Guid value) { IBindParameter bindParam; - if (bindParameters.TryGetValue(name, out bindParam)) + if (statement.BindParameters.TryGetValue(name, out bindParam)) + { + bindParam.Bind(value.ToGuidParamValue()); + } + } + + public static void TryBind(this IStatement statement, string name, DateTime value) + { + IBindParameter bindParam; + if (statement.BindParameters.TryGetValue(name, out bindParam)) + { + bindParam.Bind(value.ToDateTimeParamValue()); + } + } + + public static void TryBind(this IStatement statement, string name, long value) + { + IBindParameter bindParam; + if (statement.BindParameters.TryGetValue(name, out bindParam)) { bindParam.Bind(value); } } - public static void TryBindNull(this IReadOnlyDictionary bindParameters, string name) + public static void TryBind(this IStatement statement, string name, byte[] value) { IBindParameter bindParam; - if (bindParameters.TryGetValue(name, out bindParam)) + if (statement.BindParameters.TryGetValue(name, out bindParam)) + { + bindParam.Bind(value); + } + } + + public static void TryBindNull(this IStatement statement, string name) + { + IBindParameter bindParam; + if (statement.BindParameters.TryGetValue(name, out bindParam)) { bindParam.BindNull(); } } + public static void TryBind(this IStatement statement, string name, DateTime? value) + { + if (value.HasValue) + { + TryBind(statement, name, value.Value); + } + else + { + TryBindNull(statement, name); + } + } + + public static void TryBind(this IStatement statement, string name, Guid? value) + { + if (value.HasValue) + { + TryBind(statement, name, value.Value); + } + else + { + TryBindNull(statement, name); + } + } + + public static void TryBind(this IStatement statement, string name, int? value) + { + if (value.HasValue) + { + TryBind(statement, name, value.Value); + } + else + { + TryBindNull(statement, name); + } + } + + public static void TryBind(this IStatement statement, string name, float? value) + { + if (value.HasValue) + { + TryBind(statement, name, value.Value); + } + else + { + TryBindNull(statement, name); + } + } + + public static void TryBind(this IStatement statement, string name, bool? value) + { + if (value.HasValue) + { + TryBind(statement, name, value.Value); + } + else + { + TryBindNull(statement, name); + } + } + public static IEnumerable> ExecuteQuery( this IStatement This) { diff --git a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs index 8aa3698b8..c6b08c4b3 100644 --- a/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserDataRepository.cs @@ -152,48 +152,48 @@ // { // using (var statement = _connection.PrepareStatement("replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)")) // { -// statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue()); -// statement.BindParameters.TryBind("@Key", key); +// statement.TryBind("@UserId", userId.ToGuidParamValue()); +// statement.TryBind("@Key", key); // if (userData.Rating.HasValue) // { -// statement.BindParameters.TryBind("@rating", userData.Rating.Value); +// statement.TryBind("@rating", userData.Rating.Value); // } // else // { -// statement.BindParameters.TryBindNull("@rating"); +// statement.TryBindNull("@rating"); // } -// statement.BindParameters.TryBind("@played", userData.Played); -// statement.BindParameters.TryBind("@playCount", userData.PlayCount); -// statement.BindParameters.TryBind("@isFavorite", userData.IsFavorite); -// statement.BindParameters.TryBind("@playbackPositionTicks", userData.PlaybackPositionTicks); +// statement.TryBind("@played", userData.Played); +// statement.TryBind("@playCount", userData.PlayCount); +// statement.TryBind("@isFavorite", userData.IsFavorite); +// statement.TryBind("@playbackPositionTicks", userData.PlaybackPositionTicks); // if (userData.LastPlayedDate.HasValue) // { -// statement.BindParameters.TryBind("@lastPlayedDate", userData.LastPlayedDate.Value.ToDateTimeParamValue()); +// statement.TryBind("@lastPlayedDate", userData.LastPlayedDate.Value.ToDateTimeParamValue()); // } // else // { -// statement.BindParameters.TryBindNull("@lastPlayedDate"); +// statement.TryBindNull("@lastPlayedDate"); // } // if (userData.AudioStreamIndex.HasValue) // { -// statement.BindParameters.TryBind("@AudioStreamIndex", userData.AudioStreamIndex.Value); +// statement.TryBind("@AudioStreamIndex", userData.AudioStreamIndex.Value); // } // else // { -// statement.BindParameters.TryBindNull("@AudioStreamIndex"); +// statement.TryBindNull("@AudioStreamIndex"); // } // if (userData.SubtitleStreamIndex.HasValue) // { -// statement.BindParameters.TryBind("@SubtitleStreamIndex", userData.SubtitleStreamIndex.Value); +// statement.TryBind("@SubtitleStreamIndex", userData.SubtitleStreamIndex.Value); // } // else // { -// statement.BindParameters.TryBindNull("@SubtitleStreamIndex"); +// statement.TryBindNull("@SubtitleStreamIndex"); // } // statement.MoveNext(); @@ -243,8 +243,8 @@ // using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId")) // { -// statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue()); -// statement.BindParameters.TryBind("@Key", key); +// statement.TryBind("@UserId", userId.ToGuidParamValue()); +// statement.TryBind("@Key", key); // foreach (var row in statement.ExecuteQuery()) // { @@ -292,7 +292,7 @@ // { // using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId")) // { -// statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue()); +// statement.TryBind("@UserId", userId.ToGuidParamValue()); // foreach (var row in statement.ExecuteQuery()) // { diff --git a/Emby.Server.Implementations/Data/SqliteUserRepository.cs b/Emby.Server.Implementations/Data/SqliteUserRepository.cs index ee496b669..5e148d95a 100644 --- a/Emby.Server.Implementations/Data/SqliteUserRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteUserRepository.cs @@ -91,8 +91,8 @@ namespace Emby.Server.Implementations.Data { using (var statement = db.PrepareStatement("replace into users (guid, data) values (@guid, @data)")) { - statement.BindParameters.TryBind("@guid", user.Id.ToGuidParamValue()); - statement.BindParameters.TryBind("@data", serialized); + statement.TryBind("@guid", user.Id.ToGuidParamValue()); + statement.TryBind("@data", serialized); statement.MoveNext(); } }); @@ -154,7 +154,7 @@ namespace Emby.Server.Implementations.Data { using (var statement = db.PrepareStatement("delete from users where guid=@id")) { - statement.BindParameters.TryBind("@id", user.Id.ToGuidParamValue()); + statement.TryBind("@id", user.Id.ToGuidParamValue()); statement.MoveNext(); } }); diff --git a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs index 15322dcd3..5a3b64dbb 100644 --- a/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs +++ b/Emby.Server.Implementations/Notifications/SqliteNotificationsRepository.cs @@ -109,8 +109,8 @@ namespace Emby.Server.Implementations.Notifications { using (var statement = connection.PrepareStatement("select Level from Notifications where UserId=@UserId and IsRead=@IsRead")) { - statement.BindParameters.TryBind("@IsRead", false); - statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue()); + statement.TryBind("@IsRead", false); + statement.TryBind("@UserId", userId.ToGuidParamValue()); foreach (var row in statement.ExecuteQuery()) { @@ -228,16 +228,16 @@ namespace Emby.Server.Implementations.Notifications { using (var statement = conn.PrepareStatement("replace into Notifications (Id, UserId, Date, Name, Description, Url, Level, IsRead, Category, RelatedId) values (@Id, @UserId, @Date, @Name, @Description, @Url, @Level, @IsRead, @Category, @RelatedId)")) { - statement.BindParameters.TryBind("@Id", notification.Id.ToGuidParamValue()); - statement.BindParameters.TryBind("@UserId", notification.UserId.ToGuidParamValue()); - statement.BindParameters.TryBind("@Date", notification.Date.ToDateTimeParamValue()); - statement.BindParameters.TryBind("@Name", notification.Name); - statement.BindParameters.TryBind("@Description", notification.Description); - statement.BindParameters.TryBind("@Url", notification.Url); - statement.BindParameters.TryBind("@Level", notification.Level.ToString()); - statement.BindParameters.TryBind("@IsRead", notification.IsRead); - statement.BindParameters.TryBind("@Category", string.Empty); - statement.BindParameters.TryBind("@RelatedId", string.Empty); + statement.TryBind("@Id", notification.Id.ToGuidParamValue()); + statement.TryBind("@UserId", notification.UserId.ToGuidParamValue()); + statement.TryBind("@Date", notification.Date.ToDateTimeParamValue()); + statement.TryBind("@Name", notification.Name); + statement.TryBind("@Description", notification.Description); + statement.TryBind("@Url", notification.Url); + statement.TryBind("@Level", notification.Level.ToString()); + statement.TryBind("@IsRead", notification.IsRead); + statement.TryBind("@Category", string.Empty); + statement.TryBind("@RelatedId", string.Empty); statement.MoveNext(); } @@ -291,8 +291,8 @@ namespace Emby.Server.Implementations.Notifications { using (var statement = conn.PrepareStatement("update Notifications set IsRead=@IsRead where UserId=@UserId")) { - statement.BindParameters.TryBind("@IsRead", isRead); - statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue()); + statement.TryBind("@IsRead", isRead); + statement.TryBind("@UserId", userId.ToGuidParamValue()); statement.MoveNext(); } @@ -313,14 +313,14 @@ namespace Emby.Server.Implementations.Notifications { using (var statement = conn.PrepareStatement("update Notifications set IsRead=@IsRead where UserId=@UserId and Id=@Id")) { - statement.BindParameters.TryBind("@IsRead", isRead); - statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue()); + statement.TryBind("@IsRead", isRead); + statement.TryBind("@UserId", userId.ToGuidParamValue()); foreach (var id in notificationIdList) { statement.Reset(); - statement.BindParameters.TryBind("@Id", id.ToGuidParamValue()); + statement.TryBind("@Id", id.ToGuidParamValue()); statement.MoveNext(); } diff --git a/Emby.Server.Implementations/Security/AuthenticationRepository.cs b/Emby.Server.Implementations/Security/AuthenticationRepository.cs index 160e0f5d2..a9141f153 100644 --- a/Emby.Server.Implementations/Security/AuthenticationRepository.cs +++ b/Emby.Server.Implementations/Security/AuthenticationRepository.cs @@ -71,24 +71,24 @@ namespace Emby.Server.Implementations.Security { using (var statement = db.PrepareStatement("replace into AccessTokens (Id, AccessToken, DeviceId, AppName, AppVersion, DeviceName, UserId, IsActive, DateCreated, DateRevoked) values (@Id, @AccessToken, @DeviceId, @AppName, @AppVersion, @DeviceName, @UserId, @IsActive, @DateCreated, @DateRevoked)")) { - statement.BindParameters.TryBind("@Id", info.Id.ToGuidParamValue()); - statement.BindParameters.TryBind("@AccessToken", info.AccessToken); + statement.TryBind("@Id", info.Id.ToGuidParamValue()); + statement.TryBind("@AccessToken", info.AccessToken); - statement.BindParameters.TryBind("@DeviceId", info.DeviceId); - statement.BindParameters.TryBind("@AppName", info.AppName); - statement.BindParameters.TryBind("@AppVersion", info.AppVersion); - statement.BindParameters.TryBind("@DeviceName", info.DeviceName); - statement.BindParameters.TryBind("@UserId", info.UserId); - statement.BindParameters.TryBind("@IsActive", info.IsActive); - statement.BindParameters.TryBind("@DateCreated", info.DateCreated.ToDateTimeParamValue()); + statement.TryBind("@DeviceId", info.DeviceId); + statement.TryBind("@AppName", info.AppName); + statement.TryBind("@AppVersion", info.AppVersion); + statement.TryBind("@DeviceName", info.DeviceName); + statement.TryBind("@UserId", info.UserId); + statement.TryBind("@IsActive", info.IsActive); + statement.TryBind("@DateCreated", info.DateCreated.ToDateTimeParamValue()); if (info.DateRevoked.HasValue) { - statement.BindParameters.TryBind("@DateRevoked", info.DateRevoked.Value.ToDateTimeParamValue()); + statement.TryBind("@DateRevoked", info.DateRevoked.Value.ToDateTimeParamValue()); } else { - statement.BindParameters.TryBindNull("@DateRevoked"); + statement.TryBindNull("@DateRevoked"); } statement.MoveNext(); @@ -104,22 +104,22 @@ namespace Emby.Server.Implementations.Security { if (!string.IsNullOrWhiteSpace(query.AccessToken)) { - statement.BindParameters.TryBind("@AccessToken", query.AccessToken); + statement.TryBind("@AccessToken", query.AccessToken); } if (!string.IsNullOrWhiteSpace(query.UserId)) { - statement.BindParameters.TryBind("@UserId", query.UserId); + statement.TryBind("@UserId", query.UserId); } if (!string.IsNullOrWhiteSpace(query.DeviceId)) { - statement.BindParameters.TryBind("@DeviceId", query.DeviceId); + statement.TryBind("@DeviceId", query.DeviceId); } if (query.IsActive.HasValue) { - statement.BindParameters.TryBind("@IsActive", query.IsActive.Value); + statement.TryBind("@IsActive", query.IsActive.Value); } } diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index bbd23831c..6fb918f15 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -515,7 +515,7 @@ namespace Emby.Server.Implementations.Sync { if (!string.IsNullOrWhiteSpace(query.TargetId)) { - statement.BindParameters.TryBind("@TargetId", query.TargetId); + statement.TryBind("@TargetId", query.TargetId); } foreach (var row in statement.ExecuteQuery()) @@ -535,7 +535,7 @@ namespace Emby.Server.Implementations.Sync { if (!string.IsNullOrWhiteSpace(query.TargetId)) { - statement.BindParameters.TryBind("@TargetId", query.TargetId); + statement.TryBind("@TargetId", query.TargetId); } foreach (var row in statement.ExecuteQuery()) -- cgit v1.2.3 From 24dc91160d33e9b1ea8edd1f4262b8ecb14db930 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Nov 2016 15:31:55 -0500 Subject: update activity log --- .../Activity/ActivityRepository.cs | 35 +++++++++++++++------- .../Data/SqliteItemRepository.cs | 4 +-- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'Emby.Server.Implementations/Activity/ActivityRepository.cs') diff --git a/Emby.Server.Implementations/Activity/ActivityRepository.cs b/Emby.Server.Implementations/Activity/ActivityRepository.cs index ebf93fa33..d730e420a 100644 --- a/Emby.Server.Implementations/Activity/ActivityRepository.cs +++ b/Emby.Server.Implementations/Activity/ActivityRepository.cs @@ -84,19 +84,16 @@ namespace Emby.Server.Implementations.Activity using (var connection = CreateConnection(true)) { var commandText = BaseActivitySelectText; - var whereClauses = new List(); - var paramList = new List(); if (minDate.HasValue) { - whereClauses.Add("DateCreated>=?"); - paramList.Add(minDate.Value.ToDateTimeParamValue()); + whereClauses.Add("DateCreated>=@DateCreated"); } var whereTextWithoutPaging = whereClauses.Count == 0 ? - string.Empty : - " where " + string.Join(" AND ", whereClauses.ToArray()); + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); if (startIndex.HasValue && startIndex.Value > 0) { @@ -122,13 +119,31 @@ namespace Emby.Server.Implementations.Activity commandText += " LIMIT " + limit.Value.ToString(_usCulture); } - var totalRecordCount = connection.Query("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging, paramList.ToArray()).SelectScalarInt().First(); - var list = new List(); - foreach (var row in connection.Query(commandText, paramList.ToArray())) + using (var statement = connection.PrepareStatement(commandText)) + { + if (minDate.HasValue) + { + statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue()); + } + + foreach (var row in statement.ExecuteQuery()) + { + list.Add(GetEntry(row)); + } + } + + int totalRecordCount; + + using (var statement = connection.PrepareStatement("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging)) { - list.Add(GetEntry(row)); + if (minDate.HasValue) + { + statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue()); + } + + totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First(); } return new QueryResult() diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index e4ceca267..255235cc7 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -3860,7 +3860,7 @@ namespace Emby.Server.Implementations.Data whereClauses.Add("LocationType=@LocationType"); if (statement != null) { - statement.TryBind("LocationType", query.LocationTypes[0].ToString()); + statement.TryBind("@LocationType", query.LocationTypes[0].ToString()); } } } @@ -3881,7 +3881,7 @@ namespace Emby.Server.Implementations.Data whereClauses.Add("LocationType<>@ExcludeLocationTypes"); if (statement != null) { - statement.TryBind("ExcludeLocationTypes", query.ExcludeLocationTypes[0].ToString()); + statement.TryBind("@ExcludeLocationTypes", query.ExcludeLocationTypes[0].ToString()); } } } -- cgit v1.2.3