2019-11-01 13:38:54 -04:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-02-26 12:30:13 -05:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using SQLitePCL.pretty;
|
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.Data
|
|
|
|
{
|
2021-11-15 09:57:07 -05:00
|
|
|
public sealed class ManagedConnection : IDisposable
|
2019-02-26 12:30:13 -05:00
|
|
|
{
|
2023-04-14 07:43:56 -04:00
|
|
|
private readonly ConnectionPool _pool;
|
2021-10-02 13:03:04 -04:00
|
|
|
|
2023-04-14 07:43:56 -04:00
|
|
|
private SQLiteDatabaseConnection _db;
|
2021-10-02 13:03:04 -04:00
|
|
|
|
2022-03-06 11:30:47 -05:00
|
|
|
private bool _disposed = false;
|
2022-01-22 16:52:30 -05:00
|
|
|
|
2023-04-14 07:43:56 -04:00
|
|
|
public ManagedConnection(SQLiteDatabaseConnection db, ConnectionPool pool)
|
2019-02-26 12:30:13 -05:00
|
|
|
{
|
|
|
|
_db = db;
|
2023-04-14 07:43:56 -04:00
|
|
|
_pool = pool;
|
2019-02-26 12:30:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 13:35:00 -04:00
|
|
|
public IEnumerable<IReadOnlyList<ResultSetValue>> Query(string sql)
|
2019-02-26 12:30:13 -05:00
|
|
|
{
|
|
|
|
return _db.Query(sql);
|
|
|
|
}
|
|
|
|
|
2021-05-21 13:35:00 -04:00
|
|
|
public IEnumerable<IReadOnlyList<ResultSetValue>> Query(string sql, params object[] values)
|
2019-02-26 12:30:13 -05:00
|
|
|
{
|
|
|
|
return _db.Query(sql, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
if (_disposed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-14 07:43:56 -04:00
|
|
|
_pool.Return(_db);
|
2019-02-26 12:30:13 -05:00
|
|
|
|
2023-04-14 07:43:56 -04:00
|
|
|
_db = null!; // Don't dispose it
|
2019-02-26 12:30:13 -05:00
|
|
|
_disposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|