解析SQL code在C# [英] Parsing SQL code in C#

查看:136
本文介绍了解析SQL code在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#来解析SQL code。

I want to parse SQL code using C#.

具体来说,有哪些可以解析SQL code,并生成一个树或任何其他结构出来的任何免费提供的解析器?还应生成正确的树嵌套结构。

Specifically, is there any freely available parser which can parse SQL code and generate a tree or any other structure out of it? It should also generate the proper tree for nested structures.

这也应该返回哪一种说法这棵树再presents的节点。

It should also return which kind of statement the node of this tree represents.

例如,如果该节点包含一个循环条件则它应该返回,这是一个节点的循环型

For example, if the node contains a loop condition then it should return that this is a "loop type" of a node.

或者是有任何方式,我可以解析在C#中code和生成我想要的那种类型的树?

Or is there any way by which I can parse the code in C# and generate a tree of the type I want?

推荐答案

使用微软实体框架(EF)。

它有它建立一个前pression树实体SQL解析器,

It has a "Entity SQL" parser which builds an expression tree,

using System.Data.EntityClient;
...
EntityConnection conn = new EntityConnection(myContext.Connection.ConnectionString);
conn.Open();
EntityCommand cmd = conn.CreateCommand();
cmd.CommandText = @"Select t.MyValue From MyEntities.MyTable As t";
var queryExpression = cmd.Expression;
....
conn.Close();

或类似的东西,看看MSDN上。

Or something like that, check it out on MSDN.

而这一切都在Ballmers打勾: - )

And it's all on Ballmers tick :-)

还有一个在code项目的 SQL解析器

There is also one on The Code Project, SQL Parser.

祝你好运。

这篇关于解析SQL code在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆