|
|
@ -282,7 +282,7 @@ namespace PetaPoco
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_sharedConnection = connection;
|
|
|
|
_sharedConnection = connection;
|
|
|
|
_connectionString = connection.ConnectionString;
|
|
|
|
_connectionString = connection.ConnectionString;
|
|
|
|
_sharedConnectionDepth = 2; // Prevent closing external connection
|
|
|
|
|
|
|
|
_dbType = dbType;
|
|
|
|
_dbType = dbType;
|
|
|
|
CommonConstruct();
|
|
|
|
CommonConstruct();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -294,10 +294,11 @@ namespace PetaPoco
|
|
|
|
CommonConstruct();
|
|
|
|
CommonConstruct();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Database(string connectionString, DbProviderFactory provider)
|
|
|
|
public Database(string connectionString, DbProviderFactory provider, DBType dbType)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_connectionString = connectionString;
|
|
|
|
_connectionString = connectionString;
|
|
|
|
_factory = provider;
|
|
|
|
_factory = provider;
|
|
|
|
|
|
|
|
_dbType = dbType;
|
|
|
|
CommonConstruct();
|
|
|
|
CommonConstruct();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -375,6 +376,7 @@ namespace PetaPoco
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Automatically close one open connection reference
|
|
|
|
// Automatically close one open connection reference
|
|
|
|
// (Works with KeepConnectionAlive and manually opening a shared connection)
|
|
|
|
// (Works with KeepConnectionAlive and manually opening a shared connection)
|
|
|
|
|
|
|
|
KeepConnectionAlive = false;
|
|
|
|
CloseSharedConnection();
|
|
|
|
CloseSharedConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -384,18 +386,14 @@ namespace PetaPoco
|
|
|
|
// Open a connection (can be nested)
|
|
|
|
// Open a connection (can be nested)
|
|
|
|
public void OpenSharedConnection()
|
|
|
|
public void OpenSharedConnection()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_sharedConnectionDepth == 0)
|
|
|
|
if (_sharedConnection == null || _sharedConnection.State == ConnectionState.Closed || _sharedConnection.State == ConnectionState.Broken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_sharedConnection = _factory.CreateConnection();
|
|
|
|
_sharedConnection = _factory.CreateConnection();
|
|
|
|
_sharedConnection.ConnectionString = _connectionString;
|
|
|
|
_sharedConnection.ConnectionString = _connectionString;
|
|
|
|
_sharedConnection.Open();
|
|
|
|
_sharedConnection.Open();
|
|
|
|
|
|
|
|
|
|
|
|
_sharedConnection = OnConnectionOpened(_sharedConnection);
|
|
|
|
_sharedConnection = OnConnectionOpened(_sharedConnection);
|
|
|
|
|
|
|
|
|
|
|
|
if (KeepConnectionAlive)
|
|
|
|
|
|
|
|
_sharedConnectionDepth++; // Make sure you call Dispose
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_sharedConnectionDepth++;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -404,15 +402,11 @@ namespace PetaPoco
|
|
|
|
// Close a previously opened connection
|
|
|
|
// Close a previously opened connection
|
|
|
|
public void CloseSharedConnection()
|
|
|
|
public void CloseSharedConnection()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_sharedConnectionDepth > 0)
|
|
|
|
if (!KeepConnectionAlive && _sharedConnection != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_sharedConnectionDepth--;
|
|
|
|
OnConnectionClosing(_sharedConnection);
|
|
|
|
if (_sharedConnectionDepth == 0)
|
|
|
|
_sharedConnection.Dispose();
|
|
|
|
{
|
|
|
|
_sharedConnection = null;
|
|
|
|
OnConnectionClosing(_sharedConnection);
|
|
|
|
|
|
|
|
_sharedConnection.Dispose();
|
|
|
|
|
|
|
|
_sharedConnection = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -2530,7 +2524,6 @@ namespace PetaPoco
|
|
|
|
DbProviderFactory _factory;
|
|
|
|
DbProviderFactory _factory;
|
|
|
|
IDbConnection _sharedConnection;
|
|
|
|
IDbConnection _sharedConnection;
|
|
|
|
IDbTransaction _transaction;
|
|
|
|
IDbTransaction _transaction;
|
|
|
|
int _sharedConnectionDepth;
|
|
|
|
|
|
|
|
int _transactionDepth;
|
|
|
|
int _transactionDepth;
|
|
|
|
bool _transactionCancelled;
|
|
|
|
bool _transactionCancelled;
|
|
|
|
string _lastSql;
|
|
|
|
string _lastSql;
|
|
|
|