question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pretty print for Statement

See original GitHub issue

it would be great if Statement had a

String prettyPrint(int width)

method, which formats the resulting String into a maximum width.

It would make it much nicer to display to end-users.

Or something similar, like

SELECT ...
FROM ...
WHERE ...

with predefined line breaks.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tomershaycommented, Jul 27, 2020

@stewartbryson, I didn’t try to import it directly from hibernate actually, as I needed to apply a few small changes to the hibernate formatter, so we just copied the source code of the file to our codebase, from: https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/BasicFormatterImpl.java

Once I had that class, I can just import the class BasicFormatterImpl and call: String formattedSQL = new BasicFormatterImpl().format(sql);

0reactions
manticore-projectscommented, Oct 19, 2021

Have a look at JSQLFormatter, which is using JSQLParser for understanding the AST of a SQL statement. Plenty of samples here: http://217.160.215.75:8080/jsqlformatter/samples.html and you can test it online and interactively here

Disclaimer: I am the author of this software.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prettify Your Data Structures With Pretty Print in Python
The pprint module, Python's data pretty printer, is a useful part of the standard library. You can work with it for debugging data...
Read more >
pprint — Data pretty printer — Python 3.11.1 documentation
The pprint module provides a capability to “pretty-print” arbitrary Python data structures in a form which can be used as input to the...
Read more >
Java-Code/Statement1PrettyPrint1.java at master - GitHub
Layered implementation of secondary method {@code prettyPrint} for ... Constructs into the given {@code Statement} the BLOCK statement read from.
Read more >
How to Use Pretty Print Module in Python - Linux Hint
Pretty Print Module is used to produce formatted output in Python. ... The last statement prints the output of the pretty variable.
Read more >
12.8 Pretty Printing - Brown CS
Pretty -prints the value v using the same printed form as write, but with newlines and whitespace inserted to avoid lines longer than...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found