1

I am looking for SQL query parser for MySQL queries. Using which I can parse the query, modify the query object and print back modified query

JSQL Parser was exactly what I needed but It has 2 main issues while escaping single quote inside column values https://github.com/JSQLParser/JSqlParser/issues/167 https://github.com/JSQLParser/JSqlParser/issues/166

So I am looking for open source alternative which can help me with the task

Presto-parser I tried was not able to parse Update queries

If anyone else is aware of any other reliable SQL Parsing library please let me know

user1228785
  • 512
  • 2
  • 6
  • 19

2 Answers2

1

Regarding JSqlParser:

Issue 166 already fixed.

The escaping of single quotes is not supported, but using double single quotes is. Therefore someone could replace all \' using '' before parsing.

EDIT: Issue 167 fixed within actual Snapshot 0.9.5 of JSqlParser.

wumpz
  • 8,257
  • 3
  • 30
  • 25
1

One year ago i search for the same thing but finally i use another approach. Those were the projects that i found to parse sql.

  • ANTLR. Is commonly used generic parser. It's a kind of parser generator. From a set of rules it writes the java code. There are rules for a lot of thins like spanish, java or sql.

  • JParsec. Seems similar to the previous one. Seems that already exists SQL rules, but does not seem easy to use.

  • ZQL. Uses JavaCC to auto-generate Java code that parses the SQL. I test this one but i can not get it working as i want. And i think that the project is discontinued.

  • sql-parser. It looks nice, but when i tested it i can not get it working. The link seems to not work, but i think that this is a fork of the original project.

  • jOOQ is a great library for those that don't need or like an ORM and also has a parser.

Francisco Puga
  • 23,869
  • 5
  • 48
  • 64
  • Thanks @LukasEder I add it. But take into account that this post was written in 2015, and I don't review the topic since then. – Francisco Puga Nov 18 '22 at 16:54