Address comments

This commit is contained in:
Bond_009 2019-04-03 13:46:07 +02:00 committed by Bond_009
parent 02b864e41b
commit d00ad28efd
5 changed files with 21 additions and 20 deletions

View File

@ -215,7 +215,7 @@ namespace Emby.Server.Implementations.Activity
var list = new List<ActivityLogEntry>();
var result = new QueryResult<ActivityLogEntry>();
var statements = PrepareAllSafe(db, statementTexts).ToList();
var statements = PrepareAll(db, statementTexts).ToList();
using (var statement = statements[0])
{

View File

@ -69,7 +69,7 @@ namespace Emby.Server.Implementations.Data
public IStatement PrepareStatement(IDatabaseConnection connection, string sql)
=> connection.PrepareStatement(sql);
public IEnumerable<IStatement> PrepareAllSafe(IDatabaseConnection connection, IEnumerable<string> sql)
public IEnumerable<IStatement> PrepareAll(IDatabaseConnection connection, IEnumerable<string> sql)
=> sql.Select(connection.PrepareStatement);
protected bool TableExists(ManagedConnection connection, string name)

View File

@ -518,10 +518,11 @@ namespace Emby.Server.Implementations.Data
{
saveItemCommandCommandText += ",";
}
saveItemCommandCommandText += "@" + saveColumns[i];
}
saveItemCommandCommandText += ")";
return saveItemCommandCommandText;
return saveItemCommandCommandText + ")";
}
/// <summary>
@ -551,16 +552,16 @@ namespace Emby.Server.Implementations.Data
using (var connection = GetConnection())
{
connection.RunInTransaction((Action<IDatabaseConnection>)(db =>
connection.RunInTransaction(db =>
{
using (var saveImagesStatement = base.PrepareStatement((IDatabaseConnection)db, (string)"Update TypedBaseItems set Images=@Images where guid=@Id"))
using (var saveImagesStatement = base.PrepareStatement(db, "Update TypedBaseItems set Images=@Images where guid=@Id"))
{
saveImagesStatement.TryBind("@Id", item.Id.ToGuidBlob());
saveImagesStatement.TryBind("@Images", SerializeImages(item));
saveImagesStatement.MoveNext();
}
}), TransactionMode);
}, TransactionMode);
}
}
@ -611,7 +612,7 @@ namespace Emby.Server.Implementations.Data
private void SaveItemsInTranscation(IDatabaseConnection db, IEnumerable<(BaseItem, List<Guid>, BaseItem, string, List<string>)> tuples)
{
var statements = PrepareAllSafe(db, new string[]
var statements = PrepareAll(db, new string[]
{
GetSaveItemCommandText(),
"delete from AncestorIds where ItemId=@ItemId"
@ -990,6 +991,7 @@ namespace Emby.Server.Implementations.Data
{
albumArtists = string.Join("|", hasAlbumArtists.AlbumArtists);
}
saveItemStatement.TryBind("@AlbumArtists", albumArtists);
saveItemStatement.TryBind("@ExternalId", item.ExternalId);
@ -1026,6 +1028,7 @@ namespace Emby.Server.Implementations.Data
{
continue;
}
str.Append($"{i.Key}={i.Value}|");
}
@ -1033,6 +1036,7 @@ namespace Emby.Server.Implementations.Data
{
return null;
}
str.Length -= 1; // Remove last |
return str.ToString();
}
@ -1070,6 +1074,7 @@ namespace Emby.Server.Implementations.Data
{
return null;
}
StringBuilder str = new StringBuilder();
foreach (var i in images)
{
@ -1079,6 +1084,7 @@ namespace Emby.Server.Implementations.Data
}
str.Append(ToValueString(i) + "|");
}
str.Length -= 1; // Remove last |
return str.ToString();
}
@ -2823,7 +2829,7 @@ namespace Emby.Server.Implementations.Data
return connection.RunInTransaction(db =>
{
var result = new QueryResult<BaseItem>();
var statements = PrepareAllSafe(db, statementTexts).ToList();
var statements = PrepareAll(db, statementTexts).ToList();
if (!isReturningZeroItems)
{
@ -3235,7 +3241,7 @@ namespace Emby.Server.Implementations.Data
{
var result = new QueryResult<Guid>();
var statements = PrepareAllSafe(db, statementTexts).ToList();
var statements = PrepareAll(db, statementTexts).ToList();
if (!isReturningZeroItems)
{
@ -5436,7 +5442,7 @@ where AncestorIdText not null and ItemValues.Value not null and ItemValues.Type
var list = new List<(BaseItem, ItemCounts)>();
var result = new QueryResult<(BaseItem, ItemCounts)>();
var statements = PrepareAllSafe(db, statementTexts).ToList();
var statements = PrepareAll(db, statementTexts).ToList();
if (!isReturningZeroItems)
{

View File

@ -380,10 +380,5 @@ namespace Emby.Server.Implementations.Data
return userData;
}
protected override void Dispose(bool dispose)
{
// handled by library database
}
}
}

View File

@ -258,7 +258,7 @@ namespace Emby.Server.Implementations.Security
statementTexts.Add(commandText);
statementTexts.Add("select count (Id) from Tokens" + whereTextWithoutPaging);
var statements = PrepareAllSafe(db, statementTexts)
var statements = PrepareAll(db, statementTexts)
.ToList();
using (var statement = statements[0])
@ -348,9 +348,9 @@ namespace Emby.Server.Implementations.Security
{
using (var connection = GetConnection(true))
{
return connection.RunInTransaction((Func<IDatabaseConnection, DeviceOptions>)(db =>
return connection.RunInTransaction(db =>
{
using (var statement = base.PrepareStatement((IDatabaseConnection)db, (string)"select CustomName from Devices where Id=@DeviceId"))
using (var statement = base.PrepareStatement(db, "select CustomName from Devices where Id=@DeviceId"))
{
statement.TryBind("@DeviceId", deviceId);
@ -367,7 +367,7 @@ namespace Emby.Server.Implementations.Security
return result;
}
}), ReadTransactionMode);
}, ReadTransactionMode);
}
}