Regular Expressions are not full proof solution for extracting table names from SQL queries... As tons of things has to be considered, which would be trickier to express in RegX, and would break out in one or other cases....
Then what?? Full proof sql parsers like JSQL parser , ZQL Library, SQL Parser??
Well if you just need to extract table names from SQLs, full blown SQL parsers would be over kill, further most of the parser does not support all the dialects, You may end up modifying the grammer files for you need, just to extract table names.
This small library would help you do that very easily and concisely.
Just Use the following Syntax
new TableNameParser(sql).tables()
SQL Table Name Parser is licensed under Apache Software License, Version 2.0.
- Version 0.0.3 released on 11/03/2016.
- Version 0.0.2 released on 08/27/2016.
SQL Table Name Parser is deployed at sonatypes open source maven repository. You may use the following repository configuration (if you are interested in snapshots)
<repositories>
<repository>
<id>dexecutor-snapshots</id>
<snapshots>
<enabled>true</enabled>
</snapshots>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
This repositories releases will be synched to maven central on a regular basis. Snapshots remain at sonatype.
Alternatively you can pull it from the central maven repository, just add these to your pom.xml file:
<dependency>
<groupId>com.github.mnadeem</groupId>
<artifactId>sql-table-name-parser</artifactId>
<version>0.0.3</version>
</dependency>
As it is maven project, buidling is just a matter of executing the following in your console:
mvn package
This will produce the sql-table-name-parser-VERSION.jar file under the target directory.
If you need help using this library feel free to drop an email or create an issue in github.com (preferred)
To help Dexecutor development you are encouraged to
- Provide suggestion/feedback/Issue
- pull requests for new features
- Star 🌟 the project