update extension

This commit is contained in:
Luke Pulverenti 2016-11-20 01:13:35 -05:00
parent 64d15be839
commit a385ab5142
2 changed files with 88 additions and 36 deletions

View File

@ -173,6 +173,15 @@ namespace Emby.Server.Implementations.Data
return result[index].ReadGuid();
}
public static void TryBind(this IReadOnlyDictionary<string, IBindParameter> bindParameters, string name, double value)
{
IBindParameter bindParam;
if (bindParameters.TryGetValue(name, out bindParam))
{
bindParam.Bind(value);
}
}
public static void TryBind(this IReadOnlyDictionary<string, IBindParameter> bindParameters, string name, string value)
{
IBindParameter bindParam;
@ -191,6 +200,24 @@ namespace Emby.Server.Implementations.Data
}
}
public static void TryBind(this IReadOnlyDictionary<string, IBindParameter> bindParameters, string name, int value)
{
IBindParameter bindParam;
if (bindParameters.TryGetValue(name, out bindParam))
{
bindParam.Bind(value);
}
}
public static void TryBind(this IReadOnlyDictionary<string, IBindParameter> bindParameters, string name, long 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;

View File

@ -150,29 +150,54 @@
// private void SaveUserData(IDatabaseConnection db, Guid userId, string key, UserItemData userData)
// {
// var paramList = new List<object>();
// var commandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (?, ?, ?,?,?,?,?,?,?,?)";
// paramList.Add(key);
// paramList.Add(userId.ToGuidParamValue());
// paramList.Add(userData.Rating);
// paramList.Add(userData.Played);
// paramList.Add(userData.PlayCount);
// paramList.Add(userData.IsFavorite);
// paramList.Add(userData.PlaybackPositionTicks);
// if (userData.LastPlayedDate.HasValue)
// 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)"))
// {
// paramList.Add(userData.LastPlayedDate.Value.ToDateTimeParamValue());
// }
// else
// {
// paramList.Add(null);
// }
// paramList.Add(userData.AudioStreamIndex);
// paramList.Add(userData.SubtitleStreamIndex);
// statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue());
// statement.BindParameters.TryBind("@Key", key);
// db.Execute(commandText, paramList.ToArray());
// if (userData.Rating.HasValue)
// {
// statement.BindParameters.TryBind("@rating", userData.Rating.Value);
// }
// else
// {
// statement.BindParameters.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);
// if (userData.LastPlayedDate.HasValue)
// {
// statement.BindParameters.TryBind("@lastPlayedDate", userData.LastPlayedDate.Value.ToDateTimeParamValue());
// }
// else
// {
// statement.BindParameters.TryBindNull("@lastPlayedDate");
// }
// if (userData.AudioStreamIndex.HasValue)
// {
// statement.BindParameters.TryBind("@AudioStreamIndex", userData.AudioStreamIndex.Value);
// }
// else
// {
// statement.BindParameters.TryBindNull("@AudioStreamIndex");
// }
// if (userData.SubtitleStreamIndex.HasValue)
// {
// statement.BindParameters.TryBind("@SubtitleStreamIndex", userData.SubtitleStreamIndex.Value);
// }
// else
// {
// statement.BindParameters.TryBindNull("@SubtitleStreamIndex");
// }
// statement.MoveNext();
// }
// }
// /// <summary>
@ -216,15 +241,15 @@
// throw new ArgumentNullException("key");
// }
// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = ? and userId=?";
// var paramList = new List<object>();
// paramList.Add(key);
// paramList.Add(userId.ToGuidParamValue());
// foreach (var row in _connection.Query(commandText, paramList.ToArray()))
// using (var statement = _connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
// {
// return ReadRow(row);
// statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue());
// statement.BindParameters.TryBind("@Key", key);
// foreach (var row in statement.ExecuteQuery())
// {
// return ReadRow(row);
// }
// }
// return null;
@ -265,14 +290,14 @@
// using (WriteLock.Read())
// {
// var commandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata 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 key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@UserId"))
// {
// list.Add(ReadRow(row));
// statement.BindParameters.TryBind("@UserId", userId.ToGuidParamValue());
// foreach (var row in statement.ExecuteQuery())
// {
// list.Add(ReadRow(row));
// }
// }
// }