resolve error saving sync jobs

pull/1154/head
Luke Pulverenti 8 years ago
parent a1ca5e3ecc
commit d350dc0edb

@ -346,6 +346,18 @@ namespace Emby.Server.Implementations.Data
} }
} }
public static void TryBind(this IStatement statement, string name, double? value)
{
if (value.HasValue)
{
TryBind(statement, name, value.Value);
}
else
{
TryBindNull(statement, name);
}
}
public static void TryBind(this IStatement statement, string name, int? value) public static void TryBind(this IStatement statement, string name, int? value)
{ {
if (value.HasValue) if (value.HasValue)

@ -221,48 +221,77 @@ namespace Emby.Server.Implementations.Sync
using (var connection = CreateConnection()) using (var connection = CreateConnection())
{ {
string commandText; string commandText;
var paramList = new List<object>();
if (insert) if (insert)
{ {
commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Profile, @Quality, @Bitrate, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)";
} }
else else
{ {
commandText = "update SyncJobs set TargetId=?,Name=?,Profile=?,Quality=?,Bitrate=?,Status=?,Progress=?,UserId=?,ItemIds=?,Category=?,ParentId=?,UnwatchedOnly=?,ItemLimit=?,SyncNewContent=?,DateCreated=?,DateLastModified=?,ItemCount=? where Id=?"; commandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Profile=@Profile,Quality=@Quality,Bitrate=@Bitrate,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@Id";
} }
paramList.Add(job.TargetId); connection.RunInTransaction(conn =>
paramList.Add(job.Name); {
paramList.Add(job.Profile); using (var statement = PrepareStatementSafe(connection, commandText))
paramList.Add(job.Quality); {
paramList.Add(job.Bitrate); statement.TryBind("@TargetId", job.TargetId);
paramList.Add(job.Status.ToString()); statement.TryBind("@Name", job.Name);
paramList.Add(job.Progress); statement.TryBind("@Profile", job.Profile);
paramList.Add(job.UserId); statement.TryBind("@Quality", job.Quality);
statement.TryBind("@Bitrate", job.Bitrate);
statement.TryBind("@Status", job.Status.ToString());
statement.TryBind("@Progress", job.Progress);
statement.TryBind("@UserId", job.UserId);
if (job.RequestedItemIds.Count > 0)
{
statement.TryBind("@ItemIds", string.Join(",", job.RequestedItemIds.ToArray()));
}
else
{
statement.TryBindNull("@ItemIds");
}
paramList.Add(string.Join(",", job.RequestedItemIds.ToArray())); if (job.Category.HasValue)
paramList.Add(job.Category); {
paramList.Add(job.ParentId); statement.TryBind("@Category", job.Category.Value.ToString());
paramList.Add(job.UnwatchedOnly); }
paramList.Add(job.ItemLimit); else
paramList.Add(job.SyncNewContent); {
paramList.Add(job.DateCreated.ToDateTimeParamValue()); statement.TryBindNull("@Category");
paramList.Add(job.DateLastModified.ToDateTimeParamValue()); }
paramList.Add(job.ItemCount);
if (insert) if (!string.IsNullOrWhiteSpace(job.ParentId))
{ {
paramList.Insert(0, job.Id.ToGuidParamValue()); statement.TryBind("@ParentId", job.ParentId);
} }
else else
{ {
paramList.Add(job.Id.ToGuidParamValue()); statement.TryBindNull("@ParentId");
} }
connection.RunInTransaction(conn => statement.TryBind("@UnwatchedOnly", job.UnwatchedOnly);
{
conn.Execute(commandText, paramList.ToArray()); if (job.ItemLimit.HasValue)
{
statement.TryBind("@ItemLimit", job.ItemLimit);
}
else
{
statement.TryBindNull("@ItemLimit");
}
statement.TryBind("@SyncNewContent", job.SyncNewContent);
statement.TryBind("@DateCreated", job.DateCreated.ToDateTimeParamValue());
statement.TryBind("@DateLastModified", job.DateLastModified.ToDateTimeParamValue());
statement.TryBind("@ItemCount", job.ItemCount);
statement.TryBind("@Id", job.Id.ToGuidParamValue());
statement.MoveNext();
}
}, TransactionMode); }, TransactionMode);
} }
} }

@ -55,11 +55,15 @@ namespace MediaBrowser.Providers.TV
return result; return result;
} }
if (OmdbProvider.IsValidSeries(info.SeriesProviderIds) && info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue) string seriesImdbId;
if (info.SeriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out seriesImdbId) && !string.IsNullOrEmpty(seriesImdbId))
{ {
var seriesImdbId = info.GetProviderId(MetadataProviders.Imdb); if (info.IndexNumber.HasValue &&
info.ParentIndexNumber.HasValue)
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false); {
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager)
.FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
}
} }
return result; return result;

Loading…
Cancel
Save