当前位置: 首页>>代码示例>>C#>>正文


C# IDataSource.ReturnConnection方法代码示例

本文整理汇总了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;
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:35,代码来源:SqlExecutor.cs

示例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
			}
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:48,代码来源:SqlExecutor.cs

示例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;
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:54,代码来源:SqlExecutor.cs

示例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;
		}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:41,代码来源:SqlExecutor.cs

示例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;
        }
开发者ID:BackupTheBerlios,项目名称:puzzle-svn,代码行数:46,代码来源:SqlExecutor.cs


注:本文中的IDataSource.ReturnConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。