Finding Embedded SQL Designer or Formatting

I am looking for an open source Java developer or reformatter for SQL that I can use to clean up the DDL statements that I generate with openArchitectureWare .

Nothing in the answer to " Code Encoding and Formatting" suits me, and I could not get the Simple SQL Formatter to work for me.

+27
java sql open-source beautifier
Nov 23 '08 at 14:10
source share
8 answers

UPDATE 2:

org.hibernate.jdbc.util.BasicFormatterImpl been moved in release 4.0. Now it is located at: org.hibernate.engine.jdbc.internal.BasicFormatterImpl .

UPDATE 1:

Technology goes further. As Alex noted, org.hibernate.pretty.Formatter no longer exists , org.hibernate.pretty.Formatter since version 3.3.2.GA. Replacement - org.hibernate.jdbc.util.BasicFormatterImpl :

 String formattedSQL = new BasicFormatterImpl().format(sql); 



ORIGINAL RESPONSE:

If you use Hibernate, they have one built-in: org.hibernate.pretty.Formatter

 String formattedSQL = new Formatter(sql).format(); 
+44
Feb 17 '09 at 23:00
source share

Part of the eclipse data tool platform is the SQL Development Tools Project .

The page describing the use of SQL Query Parser uses very little SQLQuerySourceFormat , which provides the following options:

  • preserveSourceFormat = ability to save source source generation when generating SQL source
  • statementTerminator = character separating multiple SQL statements
  • hostVariablePrefix = character preceding the host language variable
  • parameterMarker = character that identifies the host language parameter
  • delimitedIdentifierQuote * = character that contains delimited identifiers whose record in case will be saved.
  • omitSchema = current schema (omitted in the SQL source, implicit for references to unqualified tables)
  • qualifyIdentifiers = flag describing how identifiers in the SQL source will be identified
  • preserveComments = ability to save comments in the parsed SQL source and / or the generated SQL source
  • generateCommentsForStatementOnly = the ability to generate comments for the SQL source only in the context of the full statement or if set to false, for single SQL Query objects outside the context of the statement also
+5
Feb 12 '09 at 10:27
source share

With Hibernate v3.3.2.GA, org.hibernate.pretty.Formatter no longer exists. You can use its replacement: org.hibernate.jdbc.util.BasicFormatterImpl

 Formatter f = new BasicFormatterImpl(); String formatted_sql_code = f.format(ugly_sql_code); 
+5
Feb 02 2018-11-11T00:
source share

Did you consider:

http://www.sqlinform.com

They provide both an API version and a command line version (as well as an online version).

I do not know any costs.

+2
Feb 18 '09 at 17:07
source share

You can simply use SQL grammar and build AST with antlr . Then you can print the tree in any format you like.

+1
Feb 11 '09 at 0:01
source share

Maybe jsqlparser will work for you.

It is not as easy to find as you might think, as there are several minor projects there. In fact, I could not find it, so I did my own work (based on the h2 analyzer - you can contact me if all else fails). As a result, I do not know if this decoder has one, but writing one from above should be fairly straightforward.

It is based on grammar and JavaCC, so it's probably a better option than reusing this wheel with antlr anyway. You may find, if you need to support various sql dialects in complex statements, that any grammar based approach will not give you the opportunity.

+1
Feb 18 '09 at 5:46
source share

Will it work - SQL Formatter.

+1
Feb 18 '09 at 17:32
source share

So, this is definitely what you are looking for: SQL formatting library supporting Oracle, SQL Server, DB2, MySQL, Teradata and PostgreSQL.

0
Dec 27 '11 at 2:47 a.m.
source share



All Articles