public object RunScalar(IAdfQuery query)
{
var result = new object();
if (query == null) return result;
IDbConnection connection = Provider.GetConnection(DataSource);
IDbDataAdapter da = Provider.GetAdapter();
try
{
da.TableMappings.Add("Table", query.LeadTable());
if (connection.State == ConnectionState.Closed) connection.Open();
da.SelectCommand = Provider.GetCommand(DataSource, connection, query);
IDbTransaction transaction = Provider.GetTransaction(DataSource);
if (transaction != null) da.SelectCommand.Transaction = transaction;
result = da.SelectCommand.ExecuteScalar();
}
catch (Exception exception)
{
Provider.HandleException(exception, DataSource, query);
}
finally
{
if (da.SelectCommand.Transaction == null) connection.Close();
}
return result;
}