用于解析/识别但不针对数据库执行SQL的Java API [英] Java API for parsing/recognition but not executing SQL against a DB

查看:121
本文介绍了用于解析/识别但不针对数据库执行SQL的Java API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为工作负载自动化过程构建一个巨大的元数据字典和查找应用程序,这些过程几乎都是Sybase和Oracle直截了当的SQL脚本.我需要做的是对每个脚本中的每个SQL语句进行清点,并提取诸如语句类型(例如INSERT,UPDATE,CREATE TABLE等),表放入,来自等的表之类的东西.

I am working on building a huge meta data dictionary and lookup application for workload automation processes that are pretty much all Sybase and Oracle straight out SQL scripts. What I need to do is make an inventory for every SQL statement in every script and extract things like statement type (e.g. INSERT, UPDATE, CREATE TABLE etc), tables into, tables from etc.

我有一个原型解析应用程序,该应用程序主要使用正则表达式来完成工作.进行这样的编程非常麻烦,坦率地讲,坦率地说,我宁愿在夏天中挖3'沟渠,而不是覆盖所有可能的用例场景.另外,我觉得自己正在重新发明轮子.我认为必须有一些API,如果仅将其提供给SQL语句,它将告诉您#1是否将进行编译,然后为您提取可通过常规POJO设施访问的结构.像getStatementType,getFromTables()等.

I have a prototype parsing application that does an OK job using mostly regex. Programming something like that is tedious beyond any nightmare and, frankly, I'd rather be digging 3' ditches in the midst of summer than covering all the possible use case scenarios. Plus I feel like I am reinventing the wheel. I thought there must be some API out there that, if you feed it just a SQL statement, it will tell you #1 if it will compile and then extract the structure for you that you can access through the normal POJO facilities. Like getStatementType, getFromTables() etc.

我正在处理的脚本几乎以所有编码样式编写,没有标准格式,也存在各种表示形式和语法(表示集合,子查询,您可以为其命名).

The scripts I am dealing with are written in just about all coding styles and there is no standard format, there is also every kind of statement form and syntax represented (aggregates, subqueries, you name it).

所以我的问题是:是否有一个API可以在给定SQL的情况下解析SQL,并且可能特定于哪个供应商以返回规范化的细节?

So my question is: is there an API that parses SQL given SQL and maybe which vendor it is specific to to return normalized particulars?

我知道有一些Eclipse的插件可以做类似的事情(DDL编辑器和Quantum DB),所以我想我可以偷偷溜走一些用于SQL识别的API.有想法吗?

I know that there are plugins for Eclipse that do similar things (DDL editor and Quantum DB) so I thought I could sneak some of their API that deal with SQL recognition. Thoughts?

推荐答案

您可以使用 antl 和供应商之一特定或标准的 sql语法进行解析.

You can use antlr and one of vendor-specific or standard sql grammars for parsing.

这篇关于用于解析/识别但不针对数据库执行SQL的Java API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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