且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

解析SQL查询,并拉出列名和表名

更新时间:2023-02-26 10:32:10

我认为***的答案将是使用反讽解析器:
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:

  1. 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.
  2. 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!