aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Data
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/Data')
-rw-r--r--Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs51
-rw-r--r--Emby.Server.Implementations/Data/SqliteExtensions.cs48
-rw-r--r--Emby.Server.Implementations/Data/SqliteUserRepository.cs20
3 files changed, 82 insertions, 37 deletions
diff --git a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
index 1fbf9b0a9..1c592048e 100644
--- a/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteDisplayPreferencesRepository.cs
@@ -100,14 +100,17 @@ namespace Emby.Server.Implementations.Data
private void SaveDisplayPreferences(DisplayPreferences displayPreferences, Guid userId, string client, IDatabaseConnection connection)
{
- var commandText = "replace into userdisplaypreferences (id, userid, client, data) values (?, ?, ?, ?)";
- var serialized = _jsonSerializer.SerializeToBytes(displayPreferences, _memoryStreamProvider);
-
- connection.Execute(commandText,
- displayPreferences.Id.ToGuidParamValue(),
- userId.ToGuidParamValue(),
- client,
- serialized);
+ using (var statement = connection.PrepareStatement("replace into userdisplaypreferences (id, userid, client, data) values (@id, @userid, @client, @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.MoveNext();
+ }
}
/// <summary>
@@ -163,16 +166,16 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- var commandText = "select data from userdisplaypreferences where id = ? and userId=? and client=?";
-
- var paramList = new List<object>();
- paramList.Add(guidId.ToGuidParamValue());
- paramList.Add(userId.ToGuidParamValue());
- paramList.Add(client);
-
- foreach (var row in connection.Query(commandText, paramList.ToArray()))
+ using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where id = @id and userId=@userId and client=@client"))
{
- return Get(row);
+ statement.BindParameters.TryBind("@id", guidId.ToGuidParamValue());
+ statement.BindParameters.TryBind("@userId", userId.ToGuidParamValue());
+ statement.BindParameters.TryBind("@client", client);
+
+ foreach (var row in statement.ExecuteQuery())
+ {
+ return Get(row);
+ }
}
return new DisplayPreferences
@@ -197,14 +200,14 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
- var commandText = "select data from userdisplaypreferences where userId=?";
-
- var paramList = new List<object>();
- paramList.Add(userId.ToGuidParamValue());
-
- foreach (var row in connection.Query(commandText, paramList.ToArray()))
+ using (var statement = connection.PrepareStatement("select data from userdisplaypreferences where userId=@userId"))
{
- list.Add(Get(row));
+ statement.BindParameters.TryBind("@userId", userId.ToGuidParamValue());
+
+ foreach (var row in statement.ExecuteQuery())
+ {
+ list.Add(Get(row));
+ }
}
}
}
diff --git a/Emby.Server.Implementations/Data/SqliteExtensions.cs b/Emby.Server.Implementations/Data/SqliteExtensions.cs
index 014211924..1cc8a8a93 100644
--- a/Emby.Server.Implementations/Data/SqliteExtensions.cs
+++ b/Emby.Server.Implementations/Data/SqliteExtensions.cs
@@ -168,14 +168,54 @@ namespace Emby.Server.Implementations.Data
return result[index].ToFloat();
}
- public static DateTime GetDateTime(this IReadOnlyList<IResultSetValue> result, int index)
+ public static Guid GetGuid(this IReadOnlyList<IResultSetValue> result, int index)
{
- return result[index].ReadDateTime();
+ return result[index].ReadGuid();
}
- public static Guid GetGuid(this IReadOnlyList<IResultSetValue> result, int index)
+ public static void TryBind(this IReadOnlyDictionary<string, IBindParameter> bindParameters, string name, string value)
{
- return result[index].ReadGuid();
+ IBindParameter bindParam;
+ if (bindParameters.TryGetValue(name, out bindParam))
+ {
+ bindParam.Bind(value);
+ }
+ }
+
+ public static void TryBind(this IReadOnlyDictionary<string, IBindParameter> bindParameters, string name, bool value)
+ {
+ IBindParameter bindParam;
+ if (bindParameters.TryGetValue(name, out bindParam))
+ {
+ bindParam.Bind(value);
+ }
+ }
+
+ public static void TryBind(this IReadOnlyDictionary<string, IBindParameter> bindParameters, string name, byte[] value)
+ {
+ IBindParameter bindParam;
+ if (bindParameters.TryGetValue(name, out bindParam))
+ {
+ bindParam.Bind(value);
+ }
+ }
+
+ public static void TryBindNull(this IReadOnlyDictionary<string, IBindParameter> bindParameters, string name)
+ {
+ IBindParameter bindParam;
+ if (bindParameters.TryGetValue(name, out bindParam))
+ {
+ bindParam.BindNull();
+ }
+ }
+
+ public static IEnumerable<IReadOnlyList<IResultSetValue>> ExecuteQuery(
+ this IStatement This)
+ {
+ while (This.MoveNext())
+ {
+ yield return This.Current;
+ }
}
}
}
diff --git a/Emby.Server.Implementations/Data/SqliteUserRepository.cs b/Emby.Server.Implementations/Data/SqliteUserRepository.cs
index f0e38f8c0..ee496b669 100644
--- a/Emby.Server.Implementations/Data/SqliteUserRepository.cs
+++ b/Emby.Server.Implementations/Data/SqliteUserRepository.cs
@@ -89,11 +89,12 @@ namespace Emby.Server.Implementations.Data
{
connection.RunInTransaction(db =>
{
- var commandText = "replace into users (guid, data) values (?, ?)";
-
- db.Execute(commandText,
- user.Id.ToGuidParamValue(),
- serialized);
+ 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.MoveNext();
+ }
});
}
}
@@ -151,10 +152,11 @@ namespace Emby.Server.Implementations.Data
{
connection.RunInTransaction(db =>
{
- var commandText = "delete from users where guid=?";
-
- db.Execute(commandText,
- user.Id.ToGuidParamValue());
+ using (var statement = db.PrepareStatement("delete from users where guid=@id"))
+ {
+ statement.BindParameters.TryBind("@id", user.Id.ToGuidParamValue());
+ statement.MoveNext();
+ }
});
}
}