本文整理汇总了C#中IDataSource.ReturnConnection方法的典型用法代码示例。如果您正苦于以下问题:C# IDataSource.ReturnConnection方法的具体用法?C# IDataSource.ReturnConnection怎么用?C# IDataSource.ReturnConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataSource
的用法示例。
在下文中一共展示了IDataSource.ReturnConnection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteScalar
public virtual object ExecuteScalar(string sql, IDataSource dataSource, IList parameters)
{
this.Context.LogManager.Info(this, "Executing scalar sql query", "Sql: " + sql); // do not localize
IDbConnection connection;
IDbCommand cmd;
object result;
ITransaction transaction;
SqlExecutorCancelEventArgs e = new SqlExecutorCancelEventArgs(sql, dataSource, parameters);
this.Context.EventManager.OnExecutingSql(this, e);
if (e.Cancel)
{
this.Context.LogManager.Warn(this, "Executing scalar sql query canceled by observer!", "Sql: " + sql); // do not localize
return 0;
}
sql = e.Sql;
dataSource = e.DataSource;
parameters = e.Parameters;
connection = dataSource.GetConnection();
cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
AddParametersToCommand(cmd, parameters);
transaction = this.Context.GetTransaction(connection);
if (transaction != null)
{
cmd.Transaction = transaction.DbTransaction;
}
result = cmd.ExecuteScalar();
dataSource.ReturnConnection();
SqlExecutorEventArgs e2 = new SqlExecutorEventArgs(sql, dataSource, parameters);
this.Context.EventManager.OnExecutedSql(this, e2);
return result;
}
示例2: ExecuteBatchedStatements
public virtual void ExecuteBatchedStatements(IDataSource dataSource)
{
if (!(m_BatchStatements.ContainsKey(dataSource)))
{
return;
}
IDbConnection connection;
IDbCommand cmd;
int result;
string sqlBatch = "";
long matchResult = 0;
IList parameters = new ArrayList() ;
foreach (BatchedSqlStatement sql in ((ArrayList) (m_BatchStatements[dataSource])))
{
sqlBatch += sql.Sql + ";";
matchResult += 1;
foreach (QueryParameter parameter in sql.Parameters)
parameters.Add(parameter);
}
SqlExecutorCancelEventArgs e = new SqlExecutorCancelEventArgs(sqlBatch, dataSource, parameters);
this.Context.EventManager.OnExecutingSql(this, e);
if (e.Cancel)
{
this.Context.LogManager.Warn(this, "Executing batched statements canceled by observer!", "Sql: " + e.Sql); // do not localize
}
sqlBatch = e.Sql;
dataSource = e.DataSource;
parameters = e.Parameters;
connection = dataSource.GetConnection();
cmd = connection.CreateCommand();
cmd.CommandText = sqlBatch;
AddParametersToCommand(cmd, parameters);
result = cmd.ExecuteNonQuery();
cmd.Dispose();
dataSource.ReturnConnection();
SqlExecutorEventArgs e2 = new SqlExecutorEventArgs(sqlBatch, dataSource, parameters);
this.Context.EventManager.OnExecutedSql(this, e2);
if (!(result == matchResult))
{
throw new OptimisticConcurrencyException("An optimistic concurrency exception occurred when executing a batch statement!", null); // do not localize
}
}
示例3: ExecuteNonQuery
public virtual int ExecuteNonQuery(string sql, IDataSource dataSource, IList parameters)
{
if (dataSource == null)
throw new ArgumentNullException("dataSource");
this.Context.LogManager.Info(this, "Executing non query", "Sql: " + sql); // do not localize
IDbConnection connection;
IDbCommand cmd;
int result = 0;
ITransaction transaction;
bool postPoned = false;
if (m_ExecutionMode == ExecutionMode.BatchExecution)
postPoned = true;
SqlExecutorCancelEventArgs e = new SqlExecutorCancelEventArgs(sql, dataSource, parameters, postPoned);
this.Context.EventManager.OnExecutingSql(this, e);
if (e.Cancel)
{
this.Context.LogManager.Warn(this, "Executing non query canceled by observer!", "Sql: " + sql); // do not localize
return 0;
}
sql = e.Sql;
dataSource = e.DataSource;
parameters = e.Parameters;
if (m_ExecutionMode == ExecutionMode.NoExecution || m_ExecutionMode == ExecutionMode.NoWriteExecution)
{
result = 1;
}
else if (m_ExecutionMode == ExecutionMode.BatchExecution)
{
result = 1;
BatchStatement(sql, dataSource, parameters);
}
else if (m_ExecutionMode == ExecutionMode.DirectExecution)
{
connection = dataSource.GetConnection();
cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
AddParametersToCommand(cmd, parameters);
cmd.CommandText = sql;
transaction = this.Context.GetTransaction(connection);
if (transaction != null)
{
cmd.Transaction = transaction.DbTransaction;
}
result = cmd.ExecuteNonQuery();
dataSource.ReturnConnection();
}
SqlExecutorEventArgs e2 = new SqlExecutorEventArgs(sql, dataSource, parameters, postPoned);
this.Context.EventManager.OnExecutedSql(this, e2);
return result;
}
示例4: ExecuteDataTable
public DataTable ExecuteDataTable(string sql, IDataSource dataSource, IList parameters)
{
this.Context.LogManager.Info(this, "Executing sql query and returning data table", "Sql: " + sql); // do not localize
IDbConnection connection;
IDbCommand cmd;
IDataReader dr;
DataTable result = null;
ITransaction transaction;
SqlExecutorCancelEventArgs e = new SqlExecutorCancelEventArgs(sql, dataSource, parameters);
this.Context.EventManager.OnExecutingSql(this, e);
if (e.Cancel)
{
this.Context.LogManager.Warn(this, "Executing sql query and returning data table canceled by observer!", "Sql: " + sql); // do not localize
return null;
}
sql = e.Sql;
parameters = e.Parameters;
if (!(m_ExecutionMode == ExecutionMode.NoExecution))
{
ExecuteBatchedStatements(dataSource);
connection = dataSource.GetConnection();
cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
AddParametersToCommand(cmd, parameters);
transaction = this.Context.GetTransaction(connection);
if (transaction != null)
{
cmd.Transaction = transaction.DbTransaction;
}
dr = cmd.ExecuteReader();
result = ReaderToDataTable(dr);
dr.Close();
dataSource.ReturnConnection();
}
SqlExecutorEventArgs e2 = new SqlExecutorEventArgs(sql, dataSource, parameters);
this.Context.EventManager.OnExecutedSql(this, e2);
return result;
}
示例5: ExecuteArray
public virtual object ExecuteArray(string sql, IDataSource dataSource, IList parameters)
{
LogMessage message = new LogMessage("Executing sql query and returning array");
LogMessage verbose = new LogMessage("Sql: {0}", sql);
this.Context.LogManager.Info(this, message, verbose); // do not localize
IDbConnection connection;
IDbCommand cmd;
IDataReader dr;
object result = null;
ITransaction transaction;
SqlExecutorCancelEventArgs e = new SqlExecutorCancelEventArgs(sql, dataSource, parameters);
this.Context.EventManager.OnExecutingSql(this, e);
if (e.Cancel)
{
message = new LogMessage("Executing sql query and returning array canceled by observer!");
verbose = new LogMessage("Sql: {0}", sql);
this.Context.LogManager.Info(this, message, verbose); // do not localize
return null;
}
sql = e.Sql;
parameters = e.Parameters;
if (!(m_ExecutionMode == ExecutionMode.NoExecution))
{
ExecuteBatchedStatements(dataSource);
connection = dataSource.GetConnection();
cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
AddParametersToCommand(cmd, parameters);
transaction = this.Context.GetTransaction(connection);
if (transaction != null)
{
cmd.Transaction = transaction.DbTransaction;
}
dr = cmd.ExecuteReader();
result = ReaderToArray(dr);
dr.Close();
dataSource.ReturnConnection();
}
SqlExecutorEventArgs e2 = new SqlExecutorEventArgs(sql, dataSource, parameters);
this.Context.EventManager.OnExecutedSql(this, e2);
return result;
}