/// <summary>
        /// 获取DataReader
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public virtual MySqlDataReader GetReader(string sql, params MySqlParameter[] pars)
        {
            SetCurrentConnection(false);
            ExecLogEvent(sql, pars, true);
            MySqlCommand MySqlCommand = new MySqlCommand(sql, _MySqlConnection);

            MySqlCommand.CommandType    = CommandType;
            MySqlCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                MySqlCommand.Transaction = _tran;
            }
            if (pars != null)
            {
                MySqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(MySqlCommand.Parameters);
            }
            CheckConnect();
            MySqlDataReader sqlDataReader = MySqlCommand.ExecuteReader();

            if (IsClearParameters)
            {
                MySqlCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(sqlDataReader);
        }
        /// <summary>
        /// 获取DataSet
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public virtual DataSet GetDataSetAll(string sql, params MySqlParameter[] pars)
        {
            SetCurrentConnection(false);
            ExecLogEvent(sql, pars, true);
            MySqlDataAdapter _sqlDataAdapter = new MySqlDataAdapter(sql, _MySqlConnection);

            if (_tran != null)
            {
                _sqlDataAdapter.SelectCommand.Transaction = _tran;
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(_sqlDataAdapter.SelectCommand.Parameters);
            }
            _sqlDataAdapter.SelectCommand.CommandTimeout = this.CommandTimeOut;
            _sqlDataAdapter.SelectCommand.CommandType    = CommandType;
            if (pars != null)
            {
                _sqlDataAdapter.SelectCommand.Parameters.AddRange(pars);
            }
            CheckConnect();
            DataSet ds = new DataSet();

            _sqlDataAdapter.Fill(ds);
            if (IsClearParameters)
            {
                _sqlDataAdapter.SelectCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(ds);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 执行SQL返回受影响行数
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public int ExecuteCommand(string sql, params MySqlParameter[] pars)
        {
            ExecLogEvent(sql, pars, true);
            MySqlCommand MySqlCommand = new MySqlCommand(sql, _MySqlConnection);

            MySqlCommand.CommandType    = CommandType;
            MySqlCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                MySqlCommand.Transaction = _tran;
            }
            if (pars != null)
            {
                MySqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(MySqlCommand.Parameters);
            }
            int count = MySqlCommand.ExecuteNonQuery();

            if (IsClearParameters)
            {
                MySqlCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(count);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取DataTable
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public DataTable GetDataTable(string sql, params MySqlParameter[] pars)
        {
            ExecLogEvent(sql, pars, true);
            MySqlDataAdapter _sqlDataAdapter = new MySqlDataAdapter(sql, _MySqlConnection);

            _sqlDataAdapter.SelectCommand.CommandType = CommandType;
            if (pars != null)
            {
                _sqlDataAdapter.SelectCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(_sqlDataAdapter.SelectCommand.Parameters);
            }
            _sqlDataAdapter.SelectCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                _sqlDataAdapter.SelectCommand.Transaction = _tran;
            }
            DataTable dt = new DataTable();

            _sqlDataAdapter.Fill(dt);
            if (IsClearParameters)
            {
                _sqlDataAdapter.SelectCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(dt);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取第一行第一列
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pars"></param>
        /// <returns></returns>
        public object GetScalar(string sql, params MySqlParameter[] pars)
        {
            ExecLogEvent(sql, pars, true);
            MySqlCommand MySqlCommand = new MySqlCommand(sql, _MySqlConnection);

            MySqlCommand.CommandType = CommandType;
            if (_tran != null)
            {
                MySqlCommand.Transaction = _tran;
            }
            MySqlCommand.CommandTimeout = this.CommandTimeOut;
            if (pars != null)
            {
                MySqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(MySqlCommand.Parameters);
            }
            object scalar = MySqlCommand.ExecuteScalar();

            scalar = (scalar == null ? 0 : scalar);
            if (IsClearParameters)
            {
                MySqlCommand.Parameters.Clear();
            }
            ExecLogEvent(sql, pars, false);
            return(scalar);
        }
Exemplo n.º 6
0
        public MySqlDataReader GetReader(string sql, params MySqlParameter[] pars)
        {
            MySqlCommand sqlCommand = new MySqlCommand(sql, _sqlConnection);

            sqlCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                sqlCommand.Transaction = _tran;
            }
            if (pars != null)
            {
                sqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(sqlCommand.Parameters);
            }
            MySqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

            if (isClearParameters)
            {
                sqlCommand.Parameters.Clear();
            }
            return(sqlDataReader);
        }
Exemplo n.º 7
0
        public DataSet GetDataSetAll(string sql, params MySqlParameter[] pars)
        {
            MySqlDataAdapter _sqlDataAdapter = new MySqlDataAdapter(sql, _sqlConnection);

            if (_tran != null)
            {
                _sqlDataAdapter.SelectCommand.Transaction = _tran;
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(_sqlDataAdapter.SelectCommand.Parameters);
            }
            _sqlDataAdapter.SelectCommand.CommandTimeout = this.CommandTimeOut;
            _sqlDataAdapter.SelectCommand.Parameters.AddRange(pars);
            DataSet ds = new DataSet();

            _sqlDataAdapter.Fill(ds);
            _sqlDataAdapter.SelectCommand.Parameters.Clear();
            return(ds);
        }
Exemplo n.º 8
0
        public int ExecuteCommand(string sql, params MySqlParameter[] pars)
        {
            MySqlCommand sqlCommand = new MySqlCommand(sql, _sqlConnection);

            sqlCommand.CommandTimeout = this.CommandTimeOut;
            if (_tran != null)
            {
                sqlCommand.Transaction = _tran;
            }
            if (pars != null)
            {
                sqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(sqlCommand.Parameters);
            }
            int count = sqlCommand.ExecuteNonQuery();

            sqlCommand.Parameters.Clear();
            return(count);
        }
Exemplo n.º 9
0
        public object GetScalar(string sql, params MySqlParameter[] pars)
        {
            MySqlCommand sqlCommand = new MySqlCommand(sql, _sqlConnection);

            if (_tran != null)
            {
                sqlCommand.Transaction = _tran;
            }
            sqlCommand.CommandTimeout = this.CommandTimeOut;
            if (pars != null)
            {
                sqlCommand.Parameters.AddRange(pars);
            }
            if (IsGetPageParas)
            {
                SqlSugarToolExtensions.RequestParasToSqlParameters(sqlCommand.Parameters);
            }
            object scalar = sqlCommand.ExecuteScalar();

            scalar = (scalar == null ? 0 : scalar);
            sqlCommand.Parameters.Clear();
            return(scalar);
        }