-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Individual SQL formatter #267
Comments
+1 for this |
Makes sense. And not hard to do. Will try it after 3.6.2. |
+1 Also does it make sense to "lock" (prevent new posts & maybe new comments) the feature request forum. There is a similar request there http://dbeaver.jkiss.org/forum/viewtopic.php?f=3&t=1343 I know you've posted please post all feature requests on github but users are still posting over there and it seems less than ideal to have to keep track of 2 different areas. |
Hey Serge, The above commit appears to be included in 3.6.2. Is this feature live / can you post an example of how to use it? |
The feature isn't yet ready. Maybe in 3.6.3, but not for sure. |
Thanks for the update. Also based on my reading of @Choclin 's suggestion it sounds like way the feature was requested any programming language could be used to format the string. Is this correct? (I plan on using this feature with a python script). |
Yes, my idea was that you can use any external executable, so everybody could write or use his own formatter. I don't have such a script ready to use here. A simple way would be to use a simple Python script using the sqlparse module. To me, the options of that module are not enough, but it would be enough to get started. |
More precise: Write a Perl script like this: #!/usr/bin/perl
use strict;
use warnings;
use SQL::Beautify;
my $sql_query = <STDIN>;
my $sql = SQL::Beautify->new();
$sql->query($sql_query);
print $sql->beautify; Now you can call it and send your SQL to STDIN, you will get out the formatted statement. Or with a Perl one-liner: perl -MSQL::Beautify -e 'print SQL::Beautify->new(query => join "" => <STDIN>)->beautify' For example, on a shell: echo "SELECT * FROM sklhfkajshf ✓ 08:45:41
WHERE cxc=98" | perl -MSQL::Beautify -e 'print SQL::Beautify->new(query => join "" => <STDIN>)->beautify' ...outputs: SELECT
*
FROM
sklhfkajshf
WHERE
cxc = 98 |
Yes, I got the idea. |
In SQLyog, I can start writing a SQL statement and it automatically converts keywords to uppercase within the editior. Is there already an option to do the following? |
Not yet, you could create a feature request. It is possible to make such runtime conversions using Eclipse text editor framework. |
Uhm... one thing about it: |
This feature is already there - just select a query and press ctrl+alt+f. |
Thank you for your fast reaction! I tried to build it from sources (via Docker's maven image) and got the following error when running
|
Hmm. Work ok on windows. |
Thank you. |
Something is wrong with output reading.. |
This works (similar to what I described above). It is okay for me, but it probably should be noted that there may be a problem with this type of commands. |
Try it now |
It works, thank you! |
I'm struggling to get this working what am I doing wrong? tried for reference my python script im testing is as follows
basically i just want it to return the exact sample sql unformatted with an additional line at the top with the name of the script. instead i'm just getting -- Edit nvm i got it
|
Hello, where meeting the psti.exe that Serge is using? |
Its is just some PLSQL formatter I found on the Internet. |
Thanks for the answer. |
Hi there, I believe that can be this one here: It's a SQL formatter for pl/sql for windows or Linux trough wine. Probably you have to install it to get that exe file. On Jul 21, 2016 5:36 PM, "giquieu" notifications@github.com wrote:
|
I use the below tool. It is really great. Tried to set it up by <SQLFormatter.exe> ${file}. But doesn't seems to work. No errors, but nothing changes on Apply. |
This formatter is very slow (it takes more than 1 seconds to format a tiny SQL). |
Hey, Thanks. Yes. I figured. It works fine in SSMS and Visual Studio. But command line tool just takes too long. One quick question. When using external formatter with file, passes file as input. But does it expects output at STDOUT or file? Is there a way to specify it? I learned from above that ${file} can be input file. But how to tell DBeaver where to look for output? |
For now DBeaver always gets output from STDOUT. There is not way to redefine that. Although it is possible to use a batch script which will pipe output from file to STDOUT. |
Hello, I wrote a commercial SQL Formatter called SQLinForm and it can be included as external formatter into DBeaver. There are also free versions like the free Notepad++ plugin. If you think that this message is not OK, as it links to a commercial product then please feel free to remove it. Regards |
Anyone got this working with Poor Mans SQL Formatter?? |
@jimpriest In case you didn't get this solved yet, you should be able to download the command line tool (currently 1.6.10) for Poor Mans SQL Formatter and just link to the executable in the |
@tbcrawford Tried that but doesn't work for me for some reason. I'm on Windows 10, DBeaver 5.1.2. I downloaded SQL Formatter 1.6.10, I have to add an extra slash or DBeaver complains but I get no formatting: C:\tools\SqlFormatter\SqlFormatter.exe If I don't double slash I get: Cannot run program "C:tools\SqlFormatter\SqlFormatter.exe": CreateProcess error=2, The system cannot find the file specified I hit Format and nothing happens, no error, no formatting. |
So with confirmation this works I decided to reinstall DBeaver - I selected to 'reset settings' I still have to use a double slash in the path but now the formatter actually does something :) It works! |
I have: C:\path\sqlformatter\sqlformatter.exe /sac And "use temp file" is unchecked. Not sure what the /sac flags do - I can't remember. Could probably run the command with a --help or /? and see what the flags were. |
Hello, I am trying to add an external formatter from my Mac and use that as a template for formatting SQL.
I select the "Use temp file checkbox" but once I click "Apply" I get the following message in the preview section. Can anyone, please help and let me know how should the external file (format.sql) look like? Thanks, |
Hi Paul, a SQL file is not an executable file. You have to provide a shell script or an executable binary that takes SQL as input and outputs formatted SQL. |
Thanks for your answer Dominic. I'll give it a try using your suggestion. |
I am trying to use with the Poor Man's formatter on a mac. I.e. using the npm packages from here. Verified working from the terminal ( Have anyone had success setting up poorman's formatter on mac? |
@adamal I've configured it by passing the full paths of node and sqlformat in the command line You should be able to see the absolute paths by running |
This works great! Thanks for the screenshot! |
I would like to have an option to customize the SQL formatter. Different people have different styles formatter an SQL query and I would like it very much if DBeaver could automatically format SQL statements the way I want them.
An easy way would be to add an option where one can set a program path. This program takes the SQL from STDIN and outputs it formatted on STDOUT. So everybody can use or write his own formatter script.
The text was updated successfully, but these errors were encountered: