Exemplo n.º 1
0
        private IFilter CreateFilter(Catalogue cata, string name, string parentExtractionInformation, string whereSql, string desc)
        {
            var filter = new ExtractionFilter(_repos.CatalogueRepository, name, GetExtractionInformation(cata, parentExtractionInformation));

            filter.WhereSQL    = whereSql;
            filter.Description = desc;
            filter.SaveToDatabase();

            var parameterCreator = new ParameterCreator(filter.GetFilterFactory(), null, null);

            parameterCreator.CreateAll(filter, null);

            return(filter);
        }
Exemplo n.º 2
0
        public void GatherAndShare_ExtractionFilter_Test()
        {
            //Setup some objects under Catalogue
            var cata = new Catalogue(CatalogueRepository, "Cata");

            cata.Periodicity = Catalogue.CataloguePeriodicity.BiMonthly;
            cata.SaveToDatabase();

            var catalogueItem1 = new CatalogueItem(CatalogueRepository, cata, "Ci1");

            var tableInfo = new TableInfo(CatalogueRepository, "Myt");
            var colInfo   = new ColumnInfo(CatalogueRepository, "[Mt].[C1]", "varchar(10)", tableInfo);

            catalogueItem1.ColumnInfo_ID = colInfo.ID;
            catalogueItem1.SaveToDatabase();

            //Setup a Filter under this extractable column (the filter is what we will share)
            var ei = new ExtractionInformation(CatalogueRepository, catalogueItem1, colInfo, "UPPER(C1) as Fish");

            var filter = new ExtractionFilter(CatalogueRepository, "My Filter", ei);

            filter.Description = "amagad";
            filter.WhereSQL    = "UPPER(C1) = @a";

            //Give the filter a parameter @a just to make things interesting
            var declaration = filter.GetQuerySyntaxHelper().GetParameterDeclaration("@a", new DatabaseTypeRequest(typeof(string), 1));
            var param       = filter.GetFilterFactory().CreateNewParameter(filter, declaration);

            //Also create a 'known good value' set i.e. recommended value for the parameter to achive some goal (you can have multiple of these - this will not be shared)
            var set = new ExtractionFilterParameterSet(CatalogueRepository, filter, "Fife");
            var val = new ExtractionFilterParameterSetValue(CatalogueRepository, set, (ExtractionFilterParameter)param);

            val.Value = "'FISH'";

            //Gather the dependencies (this is what we are testing)
            var gatherer = new Gatherer(RepositoryLocator);

            Assert.IsTrue(gatherer.CanGatherDependencies(filter));
            var gathered = gatherer.GatherDependencies(filter);

            //gatherer should have gathered the filter and the parameter (but not the ExtractionFilterParameterSet sets)
            Assert.AreEqual(1, gathered.Children.Count);
            Assert.AreEqual(param, gathered.Children[0].Object);

            //Cleanup
            val.DeleteInDatabase();
            set.DeleteInDatabase();
            cata.DeleteInDatabase();
        }
Exemplo n.º 3
0
        public void Test_DatabaseTypeQueryWithParameter_IntParameter(DatabaseType dbType)
        {
            //Pick the destination server
            var tableName = TestDatabaseNames.GetConsistentName("tbl");

            //make sure there's a database ready to receive the data
            var db = GetCleanedServer(dbType);

            db.Create(true);


            //this is the table we are uploading
            var dt = new DataTable();

            dt.Columns.Add("numbercol");
            dt.Rows.Add(10);
            dt.Rows.Add(15);
            dt.Rows.Add(20);
            dt.Rows.Add(25);
            dt.TableName = tableName;
            try
            {
                ///////////////////////UPLOAD THE DataTable TO THE DESTINATION////////////////////////////////////////////
                var uploader = new DataTableUploadDestination();
                uploader.PreInitialize(db, new ThrowImmediatelyDataLoadJob());
                uploader.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadJob(), new GracefulCancellationToken());
                uploader.Dispose(new ThrowImmediatelyDataLoadJob(), null);

                var tbl = db.ExpectTable(tableName);

                var importer = new TableInfoImporter(CatalogueRepository, tbl);
                importer.DoImport(out var ti, out var ci);

                var engineer = new ForwardEngineerCatalogue(ti, ci, true);
                engineer.ExecuteForwardEngineering(out var cata, out var cis, out var ei);
                /////////////////////////////////////////////////////////////////////////////////////////////////////////

                /////////////////////////////////THE ACTUAL PROPER TEST////////////////////////////////////
                //create an extraction filter
                var extractionInformation = ei.Single();
                var filter = new ExtractionFilter(CatalogueRepository, "Filter by numbers", extractionInformation);
                filter.WhereSQL = extractionInformation.SelectSQL + " = @n";
                filter.SaveToDatabase();

                //create the parameters for filter (no globals, masters or scope adjacent parameters)
                new ParameterCreator(filter.GetFilterFactory(), null, null).CreateAll(filter, null);

                var p = filter.GetAllParameters().Single();
                Assert.AreEqual("@n", p.ParameterName);
                p.ParameterSQL = p.ParameterSQL.Replace("varchar(50)", "int"); //make it int
                p.Value        = "20";
                p.SaveToDatabase();

                var qb = new QueryBuilder(null, null);
                qb.AddColumn(extractionInformation);
                qb.RootFilterContainer = new SpontaneouslyInventedFilterContainer(new MemoryCatalogueRepository(), null, new[] { filter }, FilterContainerOperation.AND);

                using (var con = db.Server.GetConnection())
                {
                    con.Open();

                    string sql = qb.SQL;

                    var cmd = db.Server.GetCommand(sql, con);
                    var r   = cmd.ExecuteReader();
                    Assert.IsTrue(r.Read());
                    Assert.AreEqual(
                        20,
                        r[extractionInformation.GetRuntimeName()]);
                }
                ///////////////////////////////////////////////////////////////////////////////////////
            }
            finally
            {
                db.Drop();
            }
        }