コード例 #1
0
        static void RunEnumerator(SqlConnection dbConn)
        {
            Enumerator             dbEnumerator = new Enumerator(dbConn);
            ICollection <IProgram> programs     = dbEnumerator.GetDatabasePrograms();
            int programCount = 1;

            foreach (IProgram p in programs)
            {
                Console.WriteLine($"[{programCount}]: {p}");
                ++programCount;
            }

            int selectedIndex = -1;

            while (selectedIndex < 1 || selectedIndex > programs.Count)
            {
                Console.WriteLine($"Please enter an integer between 1 and {programs.Count}.");
                try
                {
                    selectedIndex = int.Parse(Console.ReadLine());
                }
                catch (ArgumentNullException)
                {
                    Console.WriteLine("No input detected.");
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid input detected.");
                }
                catch (OverflowException)
                {
                    Console.WriteLine("Input was too large to parse.");
                }
            }

            IProgram selectedProgram = programs.ElementAt(selectedIndex - 1);

            dbEnumerator.SetXMLPlanOn();
            XmlDocument queryPlan = dbEnumerator.GetQueryPlan(selectedProgram);

            dbEnumerator.SetXMLPlanOff();

            ICollection <Database> databases = dbEnumerator.DatabaseCollectionFactory(queryPlan);

            foreach (Database database in databases)
            {
                foreach (Schema schema in database.Schemas)
                {
                    foreach (Table table in schema.Tables)
                    {
                        foreach (string column in table.Columns)
                        {
                            Console.WriteLine($"{database.Name}.{schema.Name}.{table.Name}.{column}");
                        }
                    }
                }
            }

            if (databases.Count == 0)
            {
                Console.WriteLine($"Query plan for {selectedProgram} does not contain a reference to a database column");
            }
        }