2019-11-01 17:38:54 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-02-26 17:30:13 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading;
|
|
|
|
using SQLitePCL.pretty;
|
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.Data
|
|
|
|
{
|
|
|
|
public class ManagedConnection : IDisposable
|
|
|
|
{
|
2019-03-11 21:33:27 +00:00
|
|
|
private readonly SemaphoreSlim _writeLock;
|
2021-10-02 17:03:04 +00:00
|
|
|
|
|
|
|
private SQLiteDatabaseConnection? _db;
|
|
|
|
|
2019-02-26 17:30:13 +00:00
|
|
|
private bool _disposed = false;
|
|
|
|
|
|
|
|
public ManagedConnection(SQLiteDatabaseConnection db, SemaphoreSlim writeLock)
|
|
|
|
{
|
|
|
|
_db = db;
|
|
|
|
_writeLock = writeLock;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IStatement PrepareStatement(string sql)
|
|
|
|
{
|
|
|
|
return _db.PrepareStatement(sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<IStatement> PrepareAll(string sql)
|
|
|
|
{
|
|
|
|
return _db.PrepareAll(sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ExecuteAll(string sql)
|
|
|
|
{
|
|
|
|
_db.ExecuteAll(sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Execute(string sql, params object[] values)
|
|
|
|
{
|
|
|
|
_db.Execute(sql, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RunQueries(string[] sql)
|
|
|
|
{
|
|
|
|
_db.RunQueries(sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RunInTransaction(Action<IDatabaseConnection> action, TransactionMode mode)
|
|
|
|
{
|
|
|
|
_db.RunInTransaction(action, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public T RunInTransaction<T>(Func<IDatabaseConnection, T> action, TransactionMode mode)
|
|
|
|
{
|
|
|
|
return _db.RunInTransaction(action, mode);
|
|
|
|
}
|
|
|
|
|
2021-05-21 17:35:00 +00:00
|
|
|
public IEnumerable<IReadOnlyList<ResultSetValue>> Query(string sql)
|
2019-02-26 17:30:13 +00:00
|
|
|
{
|
|
|
|
return _db.Query(sql);
|
|
|
|
}
|
|
|
|
|
2021-05-21 17:35:00 +00:00
|
|
|
public IEnumerable<IReadOnlyList<ResultSetValue>> Query(string sql, params object[] values)
|
2019-02-26 17:30:13 +00:00
|
|
|
{
|
|
|
|
return _db.Query(sql, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
if (_disposed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-11 21:33:27 +00:00
|
|
|
_writeLock.Release();
|
2019-02-26 17:30:13 +00:00
|
|
|
|
|
|
|
_db = null; // Don't dispose it
|
|
|
|
_disposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|