2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2016-12-13 18:41:36 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using SQLitePCL.pretty;
|
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.Data
|
|
|
|
{
|
2019-01-13 19:20:16 +00:00
|
|
|
public class ManagedConnection : IDisposable
|
2016-12-13 18:41:36 +00:00
|
|
|
{
|
|
|
|
private SQLiteDatabaseConnection db;
|
|
|
|
private readonly bool _closeOnDispose;
|
|
|
|
|
|
|
|
public ManagedConnection(SQLiteDatabaseConnection db, bool closeOnDispose)
|
|
|
|
{
|
|
|
|
this.db = db;
|
|
|
|
_closeOnDispose = closeOnDispose;
|
|
|
|
}
|
|
|
|
|
|
|
|
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<T>(action, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<IReadOnlyList<IResultSetValue>> Query(string sql)
|
|
|
|
{
|
|
|
|
return db.Query(sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<IReadOnlyList<IResultSetValue>> Query(string sql, params object[] values)
|
|
|
|
{
|
|
|
|
return db.Query(sql, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
{
|
|
|
|
using (db)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
if (_closeOnDispose)
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|