private static object XSafeScalarQuery(AbstractSqlConnectionDescriptor connDesc,
SqlTransaction transaction, string sql, IEnumerable sqlParams)
{
object retVal;
IDbConnection conn = transaction != null
? transaction.Connection
: DbCaches.Connections.Get(connDesc);
try
{
IDbCommand cmd = DbCaches.Commands.Get(sql, conn);
if (transaction != null)
{
cmd.Transaction = transaction.Transaction;
}
try
{
SetSQLOnCommand(connDesc, cmd, sql, sqlParams);
try
{
retVal = cmd.ExecuteScalar();
}
catch (Exception e)
{
throw new UnableToRunSqlException(connDesc, sql, sqlParams, e);
}
}
finally
{
DbCaches.Commands.Return(sql, conn, cmd);
}
}
finally
{
if (transaction == null)
{
DbCaches.Connections.Return(connDesc, conn);
}
}
return retVal;
}