简体   繁体   English

如何使用antlr创建SQL Select查询解析器?

[英]How to use antlr to create SQL Select Query parser?

i am using squiggle to create dynamic select queries for postgresql, in one point of my application i need to reverse engineer the created select query and extract columns, tables, joins, orders,group by and .... from it, i googled a bit and found general sql parser which meets my demands but i need an open source solution to be able to modify it as i wish, i googled a bit more and read some where that i need antlr to write my own parser like fellas in hibernate did. 我正在使用squiggle为PostgreSQL创建动态选择查询,在我的应用程序中,我需要对所创建的选择查询进行反向工程,并从中提取列,表,联接,订单,分组依据和....,我用google搜索了一个一点点就找到了可以满足我要求的通用SQL解析器 ,但是我需要一个开放源代码的解决方案,以便能够按自己的意愿对其进行修改,我在Google上搜索了更多内容,并阅读了一些我需要像在Hibernate中的法尔斯一样编写自己的解析器的地方。 the question is i don't know how to use it and not able to find an easy to understand example. 问题是我不知道如何使用它,也找不到一个易于理解的例子。 the more important question is, considering scope of problem ( a select query) do i really need antlr to do this? 更重要的问题是,考虑到问题的范围(选择查询),我是否真的需要antlr来做到这一点? thank you 谢谢

Don't reinvent the wheel. 不要重新发明轮子。 Use for example JSqlParser (github/jsqlparser). 例如,使用JSqlParser(github / jsqlparser)。 It comes with examples of extracting tablenames. 它带有提取表名的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM