/// <summary> /// Build a query based on the current <see cref="AggregateConfiguration"/> /// </summary> /// <param name="limitationSQL">See <see cref="LimitationSQL"/></param> /// <param name="countSQL"> /// Intended purpose:The line of SELECT Sql that is an 'Aggregate Function' e.g. count(*). /// <para>Other purposes: You can use this to ram arbitrary lines of code into SELECT section of the query e.g. see CohortQueryBuilder </para> /// </param> /// <param name="aggregateConfigurationIfAny"><see cref="AggregateConfiguration"/> containing columns, filters, parameters etc for the GROUP BY</param> public AggregateBuilder(string limitationSQL, string countSQL, AggregateConfiguration aggregateConfigurationIfAny) { if (limitationSQL != null && limitationSQL.Trim().StartsWith("top", StringComparison.CurrentCultureIgnoreCase)) { throw new Exception("Use AggregateTopX property instead of limitation SQL to acheive this"); } _aggregateConfigurationIfAny = aggregateConfigurationIfAny; LimitationSQL = limitationSQL; ParameterManager = new ParameterManager(); CustomLines = new List <CustomLine>(); SQLOutOfDate = true; SelectColumns = new List <QueryTimeColumn>(); if (!string.IsNullOrWhiteSpace(countSQL)) { _countColumn = new AggregateCountColumn(countSQL); _countColumn.Order = int.MaxValue;//order these last AddColumn(_countColumn); } LabelWithComment = aggregateConfigurationIfAny != null ? aggregateConfigurationIfAny.Name : ""; _queryLevelParameterProvider = aggregateConfigurationIfAny; if (aggregateConfigurationIfAny != null) { HavingSQL = aggregateConfigurationIfAny.HavingSQL; AggregateTopX = aggregateConfigurationIfAny.GetTopXIfAny(); } }
public ExecuteCommandAddParameter(IBasicActivateItems activator, ICollectSqlParameters collector, string parameterName, string datatype, string value) : base(activator) { _collector = collector; _parameterName = parameterName; _datatype = datatype; _value = value; UseTripleDotSuffix = true; }
private ISqlParameter CreateNewParameterForExtractionConfiguration(ICollectSqlParameters collector, string parameterName) { if (!parameterName.StartsWith("@")) { parameterName = "@" + parameterName; } var ec = (ExtractionConfiguration)collector; return(new GlobalExtractionFilterParameter((IDataExportRepository)ec.Repository, ec, "DECLARE " + parameterName + " as varchar(10)")); }
private ISqlParameter CreateNewParameterForExtractionConfiguration(ICollectSqlParameters collector, string parameterName) { if (!parameterName.StartsWith("@")) { parameterName = "@" + parameterName; } var ec = (ExtractionConfiguration)collector; return(new GlobalExtractionFilterParameter((IDataExportRepository)ec.Repository, ec, AnyTableSqlParameter.GetDefaultDeclaration(parameterName))); }
private void AddParametersFor(ICollectSqlParameters collector, List <ISqlParameter> toAddTo) { if (State == ParameterManagerLifecycleState.Finalized) { throw new InvalidOperationException("Cannot add new " + collector.GetType().Name + " level parameters because state is " + State); } State = ParameterManagerLifecycleState.ParameterDiscovery; toAddTo.AddRange(collector.GetAllParameters()); }
/// <summary> /// Method called when creating new parameters if no CreateNewSqlParameterHandler was provided during construction /// </summary> /// <returns></returns> private ISqlParameter CreateNewParameterDefaultImplementation(ICollectSqlParameters collector, string parameterName) { if (!parameterName.StartsWith("@")) { parameterName = "@" + parameterName; } var entity = (IMapsDirectlyToDatabaseTable)collector; var newParam = new AnyTableSqlParameter((ICatalogueRepository)entity.Repository, entity, AnyTableSqlParameter.GetDefaultDeclaration(parameterName)); newParam.Value = AnyTableSqlParameter.DefaultValue; newParam.SaveToDatabase(); return(newParam); }
/// <summary> /// Method called when creating new parameters if no CreateNewSqlParameterHandler was provided during construction /// </summary> /// <returns></returns> private ISqlParameter CreateNewParameterDefaultImplementation(ICollectSqlParameters collector, string parameterName) { if (!parameterName.StartsWith("@")) { parameterName = "@" + parameterName; } var entity = (IMapsDirectlyToDatabaseTable)collector; var newParam = new AnyTableSqlParameter((ICatalogueRepository)entity.Repository, entity, "DECLARE " + parameterName + " as varchar(10)"); newParam.Value = "'todo'"; newParam.SaveToDatabase(); return(newParam); }
public ParameterCollectionUIOptions(string useCase, ICollectSqlParameters collector, ParameterLevel currentLevel, ParameterManager parameterManager, CreateNewSqlParameterHandler createNewParameterDelegate = null) { UseCase = useCase; Collector = collector; CurrentLevel = currentLevel; ParameterManager = parameterManager; _createNewParameterDelegate = createNewParameterDelegate; if (_createNewParameterDelegate == null) { if (AnyTableSqlParameter.IsSupportedType(collector.GetType())) { _createNewParameterDelegate = CreateNewParameterDefaultImplementation; } } }
public ParameterCollectionUIOptions Create(ICollectSqlParameters host) { if (host is TableInfo) { return(Create((TableInfo)host)); } if (host is ExtractionFilterParameterSet) { return(Create((ExtractionFilterParameterSet)host)); } if (host is AggregateConfiguration) { return(Create((AggregateConfiguration)host)); } if (host is IFilter) { FilterUIOptionsFactory factory = new FilterUIOptionsFactory(); var globals = factory.Create((IFilter)host).GetGlobalParametersInFilterScope(); return(Create((IFilter)host, globals)); } if (host is CohortIdentificationConfiguration) { return(Create((CohortIdentificationConfiguration)host)); } if (host is ExtractionConfiguration) { return(Create((ExtractionConfiguration)host)); } throw new ArgumentException("Host Type was not recognised as one of the Types we know how to deal with", "host"); }
public ExecuteCommandViewSqlParameters(IActivateItems activator, ICollectSqlParameters collector) : base(activator) { _collector = collector; UseTripleDotSuffix = true; }
public ParametersNode(ICollectSqlParameters collector, ISqlParameter[] parameters) { Parameters = parameters; Collector = collector; }
/// <summary> /// Records parameters from the <see cref="ICollectSqlParameters"/> at the specified <see cref="ParameterLevel"/> /// </summary> public void AddParametersFor(ICollectSqlParameters collector, ParameterLevel parameterLevel) { AddParametersFor(collector, ParametersFoundSoFarInQueryGeneration[parameterLevel]); }