diff options
Diffstat (limited to 'Emby.Server.Implementations/Data')
4 files changed, 129 insertions, 42 deletions
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<string, IBindParameter> 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<string, IBindParameter> 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<string, IBindParameter> 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<string, IBindParameter> 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<string, IBindParameter> 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<string, IBindParameter> 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<string, IBindParameter> 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<IReadOnlyList<IResultSetValue>> 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(); } }); |
