示例#1
0
        public DbCommand CreateCommand(DatabaseProvider database, CreateSqlState state)
        {
            if (database == null)
            {
                throw new ArgumentNullException(nameof(database));
            }
            IDataParameter[] idataParameters = null;
            string           sql             = this.commandText;

            DataParameter[] dps    = state.GetDataParameters();
            int             length = dps.Length;

            if (length > 0)
            {
                idataParameters = new IDataParameter[length];
                for (int i = 0; i < length; i++)
                {
                    DataParameter  dp             = dps[i];
                    IDataParameter idataParameter = dp.ConvertDbParameter(database, CommandType.Text);
                    idataParameters[i] = idataParameter;
                }
            }
            DbCommand command = database.CreateCommand(sql);

            command.CommandType = this.commandType;
            if (idataParameters != null)
            {
                foreach (IDataParameter param in idataParameters)
                {
                    command.Parameters.Add(param);
                }
            }
            return(command);
        }