update db connections

This commit is contained in:
Luke Pulverenti
2016-12-13 10:44:34 -05:00
parent 71854c1a09
commit 81d685b882
7 changed files with 161 additions and 154 deletions

View File

@@ -42,8 +42,10 @@ namespace Emby.Server.Implementations.Data
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
public void Initialize(ReaderWriterLockSlim writeLock)
public void Initialize(ReaderWriterLockSlim writeLock, ManagedConnection managedConnection)
{
_connection = managedConnection;
WriteLock.Dispose();
WriteLock = writeLock;
@@ -90,7 +92,7 @@ namespace Emby.Server.Implementations.Data
}
}
private void ImportUserDataIfNeeded(IDatabaseConnection connection)
private void ImportUserDataIfNeeded(ManagedConnection connection)
{
if (!_fileSystem.FileExists(_importFile))
{
@@ -117,7 +119,7 @@ namespace Emby.Server.Implementations.Data
}, TransactionMode);
}
private void ImportUserData(IDatabaseConnection connection, string file)
private void ImportUserData(ManagedConnection connection, string file)
{
SqliteExtensions.Attach(connection, file, "UserDataBackup");
@@ -300,22 +302,18 @@ namespace Emby.Server.Implementations.Data
{
using (var connection = CreateConnection(true))
{
return connection.RunInTransaction(db =>
using (var statement = connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
{
using (var statement = db.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
statement.TryBind("@UserId", userId.ToGuidParamValue());
statement.TryBind("@Key", key);
foreach (var row in statement.ExecuteQuery())
{
statement.TryBind("@UserId", userId.ToGuidParamValue());
statement.TryBind("@Key", key);
foreach (var row in statement.ExecuteQuery())
{
return ReadRow(row);
}
return ReadRow(row);
}
}
return null;
}, ReadTransactionMode);
return null;
}
}
}