zoukankan      html  css  js  c++  java
  • TSQL Parser

    
    // /r:"C:\Program Files\Microsoft Visual Studio 10.0\VSTSDB\Deploy\Microsoft.Data.Schema.ScriptDom.dll";"C:\Program Files\Microsoft Visual Studio 10.0\VSTSDB\Deploy\Microsoft.Data.Schema.ScriptDom.Sql.dll"
    namespace Microshaoft
    {
        using System;
        using System.Collections.Generic;
        using System.IO;
        using Microsoft.Data.Schema.ScriptDom;
        using Microsoft.Data.Schema.ScriptDom.Sql;
        public class Class1
        {
            static void Main(string[] args)
            {
                //SqlScriptGeneratorOptions options = new SqlScriptGeneratorOptions();
                //options.SqlVersion = SqlVersion.Sql100;
                //options.KeywordCasing = KeywordCasing.Uppercase;
                //Sql100ScriptGenerator scriptGenerator = new Sql100ScriptGenerator(options);
                SqlScriptGenerator scriptGenerator = new Sql100ScriptGenerator();
                TSqlParser parser = new TSql100Parser(false);
                IList<ParseError> errors;
                string sql =
    @"
                        --SELECT * FROM [from] WHERE ID='1'
                        select a.id,MAX(a.name),a.Name
                        from sysobjects aa
                        left join syscomments b
                        on a.id = b.id
                        where a.xtype = 'p'
                        and b.[text] like '% exec%'
                        group by a.id
    ";
                using (StringReader reader = new StringReader(sql))
                {
                    IScriptFragment fragment = parser.Parse(reader, out errors);
                    if (errors != null && errors.Count > 0)
                    {
                        foreach(ParseError pe in errors)
                        {
                            Console.WriteLine(pe.Message);
                        }
                    }
                    else
                    {
                        string script;
                        scriptGenerator.GenerateScript(fragment, out script);
                        Console.WriteLine(script);
                    }
                }
                Console.WriteLine(Environment.Version.ToString());
            }
        }
    }
    
    
  • 相关阅读:
    CSS中的小知识
    网络基础 中的osi七层 协议
    pickle的使用
    max()的key的运用
    read,readline,readlines的区别
    print()控制台输出带颜色的方法
    写项目时bin目录下的start中的细节(路径问题的解决)
    使用hashlib密文存储实例
    固态硬盘使用f2fs作为根分区安装linux
    工厂方法(Factory Method)
  • 原文地址:https://www.cnblogs.com/Microshaoft/p/1949409.html
Copyright © 2011-2022 走看看