示例#1
0
        static void Main(string[] args)
        {
            if (args.Count() < 1)
            {
                Console.WriteLine("No input file specified");
                return;
            }

            FileInfo input = new FileInfo(args[0]);

            bool       initialQuotedIdentifiers = false;
            TSqlParser parser = new TSql110Parser(initialQuotedIdentifiers);

            StreamReader       sr = input.OpenText();
            IList <ParseError> errors;

            TSqlFragment fragment = parser.Parse(sr, out errors);

            sr.Close();

            if (errors.Count > 0)
            {
                Console.WriteLine("Parse {0} errors input stream", errors.Count);
                return;
            }

            TableVisitor tableVisitor = new TableVisitor();

            fragment.Accept(tableVisitor);

            ViewVisitor viewVisitor = new ViewVisitor();

            fragment.Accept(viewVisitor);

            ProcVisitor procVisitor = new ProcVisitor();

            fragment.Accept(procVisitor);

            foreach (var table in tableVisitor.Nodes)
            {
                Console.WriteLine("table {0}.{1}",
                                  table.SchemaObjectName.SchemaIdentifier.Value,
                                  table.SchemaObjectName.BaseIdentifier.Value);
            }

            foreach (var view in viewVisitor.Nodes)
            {
                Console.WriteLine("view {0}.{1}",
                                  view.SchemaObjectName.SchemaIdentifier.Value,
                                  view.SchemaObjectName.BaseIdentifier.Value);
            }

            foreach (var proc in procVisitor.Nodes)
            {
                Console.WriteLine("proc {0}.{1}",
                                  proc.ProcedureReference.Name.SchemaIdentifier.Value,
                                  proc.ProcedureReference.Name.BaseIdentifier.Value);
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            if (args.Count() < 1)
            {
                Console.WriteLine("No input file specified");
                return;
            }

            FileInfo input = new FileInfo(args[0]);

            bool initialQuotedIdentifiers = false;
            TSqlParser parser = new TSql110Parser(initialQuotedIdentifiers);

            StreamReader sr = input.OpenText();
            IList<ParseError> errors;

            TSqlFragment fragment = parser.Parse(sr, out errors);
            sr.Close();

            if (errors.Count > 0)
            {
                Console.WriteLine("Parse {0} errors input stream", errors.Count);
                return;
            }

            TableVisitor tableVisitor = new TableVisitor();
            fragment.Accept(tableVisitor);

            ViewVisitor viewVisitor = new ViewVisitor();
            fragment.Accept(viewVisitor);

            ProcVisitor procVisitor = new ProcVisitor();
            fragment.Accept(procVisitor);

            foreach (var table in tableVisitor.Nodes)
            {
                Console.WriteLine("table {0}.{1}",
                    table.SchemaObjectName.SchemaIdentifier.Value,
                    table.SchemaObjectName.BaseIdentifier.Value);
            }

            foreach(var view in viewVisitor.Nodes)
            {
                Console.WriteLine("view {0}.{1}",
                    view.SchemaObjectName.SchemaIdentifier.Value,
                    view.SchemaObjectName.BaseIdentifier.Value);
            }

            foreach(var proc in procVisitor.Nodes)
            {
                Console.WriteLine("proc {0}.{1}",
                    proc.ProcedureReference.Name.SchemaIdentifier.Value,
                    proc.ProcedureReference.Name.BaseIdentifier.Value);
            }
        }