Esempio n. 1
0
        private static int GetStatementCountFromFile(CodeUnit script)
        {
            try
            {
                var parser = new TSql110Parser(true);
                var reader = new StringReader(script.Code) as TextReader;
                IList<ParseError> errors = null;
                var fragment = parser.Parse(reader, out errors);

                if (errors != null && errors.Count> 0)
                {
                    Console.WriteLine("Error unable to parse script file: \"{0}\"", script.Name);

                    foreach (var error in errors)
                    {
                        Console.WriteLine(error.Message);
                    }

                    return 0;
                }

                var visitor = new SqlVisitor(script.Name);
                fragment.AcceptChildren(visitor);
                return visitor.StatementCount;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error parsing script: \"{0}\" error: \"{1}\"", script.Name, ex.Message);
                return 0;
            }
        }
Esempio n. 2
0
        private static int GetStatementCountFromFile(CodeUnit script)
        {
            try
            {
                var parser = new TSql110Parser(true);
                var reader = new StringReader(script.Code) as TextReader;
                IList <ParseError> errors = null;
                var fragment = parser.Parse(reader, out errors);

                if (errors != null && errors.Count > 0)
                {
                    Console.WriteLine("Error unable to parse script file: \"{0}\"", script.Name);

                    foreach (var error in errors)
                    {
                        Console.WriteLine(error.Message);
                    }

                    return(0);
                }

                var visitor = new SqlVisitor(script.Name);
                fragment.AcceptChildren(visitor);
                return(visitor.StatementCount);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error parsing script: \"{0}\" error: \"{1}\"", script.Name, ex.Message);
                return(0);
            }
        }