Пример #1
0
        /// <summary>
        /// 在指定的事务下,执行一个SQL命令并返回一个数据集
        /// </summary>
        /// <param name="pTransaction">事务</param>
        /// <param name="pCommandType">SQL命令的类别(存储过程,SQL语句等)</param>
        /// <param name="pCommandText">存储过程名称或者是SQL语句</param>
        /// <param name="pCommandParameters">SQL命令的参数</param>
        /// <returns>数据集</returns>
        public DataSet ExecuteDataset(OracleTransaction pTransaction, CommandType pCommandType, string pCommandText, params OracleParameter[] pCommandParameters)
        {
            //参数校验
            if (pTransaction == null)
            {
                throw new ArgumentNullException("pTransaction");
            }
            if (pTransaction != null && pTransaction.Connection == null)
            {
                throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "pTransaction");
            }
            //创建SQL命令
            OracleCommand cmd = new OracleCommand();

            this.PrepareCommand(cmd, pTransaction.Connection, pTransaction, pCommandType, pCommandText, pCommandParameters);

            //触发事件
            if (this.BeforeExecute != null)
            {
                OracleCommandExecutionEventArgs arg = new OracleCommandExecutionEventArgs();
                arg.Command  = cmd;
                arg.UserInfo = this.CurrentUserInfo;
                this.BeforeExecute(this, arg);
            }
            using (OracleDataAdapter da = new OracleDataAdapter(cmd))
            {
                DataSet ds = new DataSet();
                //开启SQL语句执行时间监控
                Stopwatch sw = new Stopwatch();
                sw.Start();
                //执行SQL命令
                da.Fill(ds);
                //停止监控
                sw.Stop();
                //触发事件
                if (this.OnExecuted != null)
                {
                    OracleCommandExecutionEventArgs arg = new OracleCommandExecutionEventArgs();
                    arg.Command       = cmd;
                    arg.ExecutionTime = sw.Elapsed;
                    arg.UserInfo      = this.CurrentUserInfo;
                    this.OnExecuted(this, arg);
                }
                //清理资源
                cmd.Parameters.Clear();
                //返回
                return(ds);
            }
        }
Пример #2
0
        /// <summary>
        /// 执行一个SQL命令并返回一个数据集
        /// </summary>
        /// <param name="pCommandType">SQL命令的类别(存储过程,SQL语句等)</param>
        /// <param name="pCommandText">存储过程名称或者是SQL语句</param>
        /// <param name="pCommandParameters">SQL命令的参数</param>
        /// <returns>数据集</returns>
        public DataSet ExecuteDataset(CommandType pCommandType, string pCommandText, params OracleParameter[] pCommandParameters)
        {
            //创建SQL命令
            using (var connection = this.GetConnection())
            {
                OracleCommand cmd = new OracleCommand();
                this.PrepareCommand(cmd, connection, (OracleTransaction)null, pCommandType, pCommandText, pCommandParameters);

                //触发事件
                if (this.BeforeExecute != null)
                {
                    OracleCommandExecutionEventArgs arg = new OracleCommandExecutionEventArgs();
                    arg.Command  = cmd;
                    arg.UserInfo = this.CurrentUserInfo;
                    this.BeforeExecute(this, arg);
                }
                using (OracleDataAdapter da = new OracleDataAdapter(cmd))
                {
                    DataSet ds = new DataSet();
                    //开启SQL语句执行时间监控
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    //执行SQL命令
                    da.Fill(ds);
                    //停止监控
                    sw.Stop();
                    //触发事件
                    if (this.OnExecuted != null)
                    {
                        OracleCommandExecutionEventArgs arg = new OracleCommandExecutionEventArgs();
                        arg.Command       = cmd;
                        arg.ExecutionTime = sw.Elapsed;
                        arg.UserInfo      = this.CurrentUserInfo;
                        this.OnExecuted(this, arg);
                    }
                    //清理资源
                    cmd.Parameters.Clear();
                    //返回
                    return(ds);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 执行一个SQL命令并返回一个向前的只读数据读取器
        /// </summary>
        /// <param name="pCommandType">SQL命令的类别(存储过程,SQL语句等)</param>
        /// <param name="pCommandText">存储过程名称或者是SQL语句</param>
        /// <param name="pCommandParameters">SQL命令的参数</param>
        /// <returns>向前的只读数据读取器</returns>
        public OracleDataReader ExecuteReader(CommandType pCommandType, string pCommandText, params OracleParameter[] pCommandParameters)
        {
            //创建SQL命令
            var           connection = this.GetConnection();
            OracleCommand cmd        = new OracleCommand();

            this.PrepareCommand(cmd, connection, (OracleTransaction)null, pCommandType, pCommandText, pCommandParameters);

            //触发事件
            if (this.BeforeExecute != null)
            {
                OracleCommandExecutionEventArgs arg = new OracleCommandExecutionEventArgs();
                arg.Command  = cmd;
                arg.UserInfo = this.CurrentUserInfo;
                this.BeforeExecute(this, arg);
            }
            //开启SQL语句执行时间监控
            Stopwatch sw = new Stopwatch();

            sw.Start();
            //执行SQL命令
            OracleDataReader reader = null;

            reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            //停止监控
            sw.Stop();
            //触发事件
            if (this.OnExecuted != null)
            {
                OracleCommandExecutionEventArgs arg = new OracleCommandExecutionEventArgs();
                arg.Command       = cmd;
                arg.ExecutionTime = sw.Elapsed;
                arg.UserInfo      = this.CurrentUserInfo;
                this.OnExecuted(this, arg);
            }
            //清理资源
            cmd.Parameters.Clear();
            //返回
            return(reader);
        }