解析SQL查询,并拉出列名和表名 [英] Parsing SQL Query and pull out column name and Table name
问题描述
我有一个查询脚本是这样的:
选择View1.OrderDate,View1.Email,SUM(View1.TotalPayments)FROM DBO .View1
WHERE(View1.OrderStatus ='已完成')
GROUP BY View1.OrderDate,View1.Email
HAVING
(SUM(View1.TotalPayments)> 75);
块引用>
有没有办法,我们可以拉出来的SQL查询的一些关键信息的方法?如表名和列名,我有2个问题:
- 我做的搜索,我发现了一些解析器,如ANTLR,但我不能
找到文档解释了使用该解析器在C#语言。
- 有什么办法,我们可以使用实体框架工作来解析SQL查询?我的查询是完全动态的,它们在运行时创建
解决方案我认为最好的答案将是使用反讽解析器:
http://irony.codeplex.com/
Hanselman有如何使用它来解析SQL有很大的联系:
的 http://www.hanselman.com/blog/TheWeeklySourceCode59AnOpenSourceTreasureIronyNETLanguageImplementationKit.aspx
我希望这有助于和好运!
I have a Query Script like this:
SELECT View1.OrderDate,View1.Email,SUM(View1.TotalPayments) FROM dbo.View1 WHERE (View1.OrderStatus = 'Completed') GROUP BY View1.OrderDate,View1.Email HAVING (SUM(View1.TotalPayments) > 75);
Is there any approach that we can pull some key information out from SQL query? such as table name and column name ,I have 2 question:
- I did search I found some parser such as ANTLR , but I could not find documentation that explain the using of this parser in C# language.
- Is there any way we can use Entity Frame Work to parsing sql query? My queries are fully dynamic and they are created at run time
解决方案I think the best answer is going to be to use the Irony parser: http://irony.codeplex.com/
Hanselman has a great link to how to use it to parse SQL: http://www.hanselman.com/blog/TheWeeklySourceCode59AnOpenSourceTreasureIronyNETLanguageImplementationKit.aspx
I hope this helps, and best of luck!
这篇关于解析SQL查询,并拉出列名和表名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!