private DataSet RunQuery(IAdfQuery query)
{
var result = new DataSet { EnforceConstraints = false };
if (query == null) return result;
IDbConnection connection = Provider.GetConnection(DataSource);
IDbDataAdapter da = Provider.GetAdapter();
try
{
if (connection.State == ConnectionState.Closed) connection.Open();
da.TableMappings.Add("Table", query.LeadTable());
IDbCommand command = Provider.GetCommand(DataSource, connection, query);
da.SelectCommand = command;
IDbTransaction transaction = Provider.GetTransaction(DataSource);
if (transaction != null) da.SelectCommand.Transaction = transaction;
result.Load(command.ExecuteReader(CommandBehavior.KeyInfo | CommandBehavior.SchemaOnly), LoadOption.OverwriteChanges, query.LeadTable());
da.Fill(result);
}
catch(Exception exception)
{
Provider.HandleException(exception, DataSource, query);
}
finally
{
if (da.SelectCommand == null || da.SelectCommand.Transaction == null)
if (connection.State == ConnectionState.Open) connection.Close();
}
return result;
}