BN089-BS开发框架MVC4版/source20131023/Zephyr.Net/Zephyr.Data/Command/Handlers/ExecuteQueryHandler.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Data;

namespace Zephyr.Data
{
	internal class ExecuteQueryHandler
	{
		private readonly DbCommand _command;
		private bool _queryAlreadyExecuted;

		public ExecuteQueryHandler(DbCommand command)
		{
			_command = command;
		}

		internal void ExecuteQuery(bool useReader, Action action)
		{
			try
			{
				PrepareDbCommand(useReader);
				action();

				if (_command.Data.Context.Data.OnExecuted != null)
					_command.Data.Context.Data.OnExecuted(new CommandEventArgs(_command.Data.InnerCommand));
			}
			catch(Exception exception)
			{
				HandleQueryException(exception);
			}
			finally
			{
			    HandleQueryFinally();
			}
		}

		private void PrepareDbCommand(bool useReader)
		{
			if (_queryAlreadyExecuted)
			{
				if(_command.Data.UseMultipleResultsets)
					_command.Data.Reader.NextResult();
				else
					throw new FluentDataException("A query has already been executed on this command object. Please create a new command object.");
			}
			else
			{
				_command.Data.InnerCommand.CommandText = _command.Data.Sql.ToString();

				if(_command.Data.Context.Data.CommandTimeout != Int32.MinValue)
					_command.Data.InnerCommand.CommandTimeout = _command.Data.Context.Data.CommandTimeout;

				if(_command.Data.InnerCommand.Connection.State != ConnectionState.Open)
					OpenConnection();

				if(_command.Data.Context.Data.UseTransaction)
				{
					if(_command.Data.Context.Data.Transaction == null)
						_command.Data.Context.Data.Transaction = _command.Data.Context.Data.Connection.BeginTransaction((System.Data.IsolationLevel)_command.Data.Context.Data.IsolationLevel);

					_command.Data.InnerCommand.Transaction = _command.Data.Context.Data.Transaction;
后面还有 50 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。