예제 #1
0
        private void CreateParameters(string param1Value, string param2Value)
        {
            container1 = new AggregateFilterContainer(CatalogueRepository, FilterContainerOperation.AND);
            acDataset.RootFilterContainer_ID = container1.ID;
            acDataset.SaveToDatabase();

            AggregateFilter filter1 = new AggregateFilter(CatalogueRepository, "Filter1", container1);

            filter1.WhereSQL = "@bob = 'bob'";
            filter1.SaveToDatabase();

            var paramCreator = new ParameterCreator(filter1.GetFilterFactory(), null, null);

            paramCreator.CreateAll(filter1, null);

            container2 = new AggregateFilterContainer(CatalogueRepository, FilterContainerOperation.AND);
            acCohort.RootFilterContainer_ID = container2.ID;
            acCohort.SaveToDatabase();

            AggregateFilter filter2 = new AggregateFilter(CatalogueRepository, "Filter2", container2);

            filter2.WhereSQL = "@bob = 'fish'";
            filter2.SaveToDatabase();

            paramCreator.CreateAll(filter2, null);

            parama1       = filter1.GetAllParameters()[0];
            parama1.Value = param1Value;
            parama1.SaveToDatabase();

            parama2       = filter2.GetAllParameters()[0];
            parama2.Value = param2Value;
            parama2.SaveToDatabase();
        }
예제 #2
0
        private bool SynchronizeParameters(TableValuedFunctionImporter importer, ICheckNotifier notifier)
        {
            var discoveredParameters = _toSyncTo.GetCurrentDatabase().ExpectTableValuedFunction(_tableToSync.GetRuntimeName(), _tableToSync.Schema).DiscoverParameters();
            var currentParameters    = _tableToSync.GetAllParameters();

            //For each parameter in underlying database
            foreach (DiscoveredParameter parameter in discoveredParameters)
            {
                ISqlParameter existingCatalogueReference = currentParameters.SingleOrDefault(p => p.ParameterName.Equals(parameter.ParameterName));
                if (existingCatalogueReference == null)// that is not known about by the TableInfo
                {
                    bool create = notifier.OnCheckPerformed(
                        new CheckEventArgs(
                            "TableInfo " + _tableToSync +
                            " is a Table Valued Function but it does not have a record of the parameter " +
                            parameter.ParameterName + " which appears in the underlying database", CheckResult.Fail,
                            null, "Create the Parameter"));

                    if (!create)
                    {
                        return(false); //no longer synched
                    }
                    importer.CreateParameter(_tableToSync, parameter);
                }
                else
                {
                    //it is known about by the Catalogue but has it mysteriously changed datatype since it was imported / last synced?

                    var dbDefinition = importer.GetParamaterDeclarationSQL(parameter);
                    //if there is a disagreement on type etc
                    if (existingCatalogueReference.ParameterSQL != dbDefinition)
                    {
                        bool modify =
                            notifier.OnCheckPerformed(
                                new CheckEventArgs(
                                    "Parameter " + existingCatalogueReference + " is declared as '" + dbDefinition +
                                    "' but in the Catalogue it appears as '" +
                                    existingCatalogueReference.ParameterSQL + "'", CheckResult.Fail, null,
                                    "Change the definition in the Catalogue to '" + dbDefinition + "'"));

                        if (!modify)
                        {
                            return(false);
                        }

                        existingCatalogueReference.ParameterSQL = dbDefinition;
                        existingCatalogueReference.SaveToDatabase();
                    }
                }
            }

            //Find redundant parameters - parameters that the catalogue knows about but no longer appear in the table valued function signature in the database
            foreach (ISqlParameter currentParameter in currentParameters)
            {
                if (!discoveredParameters.Any(p => p.ParameterName.Equals(currentParameter.ParameterName)))
                {
                    bool delete =
                        notifier.OnCheckPerformed(
                            new CheckEventArgs(
                                "TableInfo " + _tableToSync +
                                " is a Table Valued Function, in the Catalogue it has a parameter called " +
                                currentParameter.ParameterName +
                                " but this parameter no longer appears in the underlying database", CheckResult.Fail,
                                null, "Delete Parameter " + currentParameter.ParameterName));

                    if (!delete)
                    {
                        return(false);
                    }

                    ((IDeleteable)currentParameter).DeleteInDatabase();
                }
            }

            return(true);
        }