Exemplo n.º 1
0
        /// <summary>
        /// Adds the given DbCommand and parameters to the current CommandBlock.
        /// </summary>
        /// <param name="dbCommand">Given DAAB DbCommand object.</param>
        public void AddDbCommand(DbCommand dbCommand)
        {
            if (dbCommand == null)
            {
                throw new ExceptionEvent(enumExceptionEventCodes.NullOrEmptyParameter
                                         , "dbCommand, cannot add a dbCommand that is null");
            }

            if (dbCommand.CommandType == System.Data.CommandType.StoredProcedure)
            {
                AddStoredProcedure(dbCommand.CommandText, _daMgr.CloneParameterCollection(dbCommand.Parameters));
            }

            else if (dbCommand.Parameters.Count > 0 ||
                     dbCommand.CommandText != _daMgr.BuildNoOpDbCommand().CommandText)       // dont add the empty command
            {
                AddDynamicSQL(dbCommand.CommandText, _daMgr.CloneParameterCollection(dbCommand.Parameters));
            }

            if (dbCommand.Site != null && dbCommand.Site is ParameterSite)
            {
                List <DbPredicateParameter> oldParams = new List <DbPredicateParameter>(
                    (List <DbPredicateParameter>)dbCommand.Site.GetService(null));

                List <DbPredicateParameter> copiedParams = new List <DbPredicateParameter>();

                foreach (DbPredicateParameter param in oldParams)
                {
                    DbPredicateParameter newParam = new DbPredicateParameter(param);

                    if (_paramAliases.ContainsKey(param.ParameterName))
                    {
                        string newName = _paramAliases[param.ParameterName].FirstOrDefault().ParameterName;

                        if (newName != null)
                        {
                            newParam.ParameterName = newName;
                        }
                    }

                    copiedParams.Add(newParam);
                }

                if (_dbCommand.Site == null)
                {
                    _dbCommand.Site = new ParameterSite(copiedParams);
                }
                else if (_dbCommand.Site is ParameterSite)
                {
                    ((List <DbPredicateParameter>)_dbCommand.Site.GetService(null)).AddRange(copiedParams);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Default constructor for the DbCommand Manager class.
        /// It expects a DataAccessMgr class instance in the constructor.
        /// </summary>
        /// <param name="dataAccessManager">string entry in configuration file for connection string</param>
        public DbCommandMgr(DataAccessMgr dataAccessManager)
        {
            _daMgr      = dataAccessManager;
            _database   = dataAccessManager.Database;
            _loggingMgr = dataAccessManager.loggingMgr;

            _noOpDbCommandText = _daMgr.NoOpDbCommandText;
            _paramAliases      = new Dictionary <string, List <DbParameter> >(StringComparer.CurrentCultureIgnoreCase);
            _dbCommand         = _daMgr.BuildNoOpDbCommand();
            if (_daMgr.DatabaseType == DataAccessMgr.EnumDbType.Oracle)
            {
                _commandBlockReady = false;
            }
        }