Views and formatting SQL
| User, date | Message |
|---|---|
|
Written by Lars
3 years ago Category: General 3 posts since Fri, 17 Sep 10 |
Hello, When displaying a View, the whole view shows on one very long line (often thousans of columns wide), making it quite hard to do anything with. If I do Ctrl-F8 to format SQL, it does format parts of it, but it does not line-wrap (I tried to click the line-wrap icon, but that does nothing). Could a setting be added to auto-format the SQL in views (including wrapping lines to fit on the screen)? This way, you just click on the view and you can instantly see what it does and edit it as needed. Thanks, Lars |
|
Written by ansgar
3 years ago 3966 posts since Fri, 07 Apr 06 |
r3543 makes this "Wrap lines" button work globally, for all SQL editors. Also its state is stored across sessions, so you just need to set it once. Regarding your question to automatically apply a reformat to the VIEW code, I disagree - that's not what every user might want, as this touches the original sources. However, users just have to press Ctrl+F8 to do that manually. |
|
Written by Lars
3 years ago 3 posts since Fri, 17 Sep 10 |
Hello, Re. r3543: thanks, I'll check it out. Also, I noticed the warning about the nightly builds and bugs, which makes sense of course. But roughly how often do you release new "stable versions?" I realize that not all users wants formatting, which is why I am suggesting that it be an option - this way you can have it either way. Also, if you implement it, it could maybe be done so that it does not actually consider the view changed by the auto-reformatting (not until the user changes something would it consider the view as changed). Either way, an option for auto-reformatting of views would be very nice (an example of a tool that has this is SQLYog). Lars |
|
Written by ansgar
3 years ago 3966 posts since Fri, 07 Apr 06 |
You noticed that there *is* such a reformatting tool via Ctrl+F8? I'm not sure as you mention SQLyog suddenly. Ctrl+F8 just has to be pressed and you're done. There is just no automatism doing the same. |
|
Written by Lars
3 years ago 3 posts since Fri, 17 Sep 10 |
Yes, I know you said it is in the r3543 there is (I have not downloaded that yet - I am not sure how stable the nightly builds are). I agree that with a working Ctrl+F8 for views, it will be easy to reformat when needed. What I was asking for is an option for auto-formatting, which would make it even more user friendly. Just a suggestion for making a great product even better. |
|
Written by ansgar
3 years ago 3966 posts since Fri, 07 Apr 06 |
Auto-touching the VIEW code is not something HeidiSQL should do ever, not even with an option. We'll stick to need a keypress for that. |
|
Written by demoth
2 years ago 4 posts since Sat, 09 Apr 11 |
Hello Heidi's formatting feature was very handy, espesially for views, that are always in one line. But when i encountered pretty big views (not sure what "big" means for you but for me it's about 4 -5 tables with 10 - 15 columns), the uncomfortable thing is that all columns are still in one line(veeery long). Since vertical scrollling is more natural, could there be any plans to do something with this, maybe make an option to place all columns on a new line, like: select a as a1, b as b1, c as c1, .... from ... < - here everything is ok instead of select a as a1, b as b1, c as c1 from ... |
|
Written by ansgar
2 years ago 3966 posts since Fri, 07 Apr 06 |
Here's the code which does this reformat stuff. Probably we can enhance it here in this forum thread: function ReformatSQL(SQL: String): String; |
|
Written by demoth
2 years ago 4 posts since Sat, 09 Apr 11 |
thanks for callaborating, it'll take some time for me to think, i hope i will post soon |
|
Written by demoth
2 years ago 4 posts since Sat, 09 Apr 11 |
In somewhat strict terms my idea will look like this: var //... After_AS_KeyWord, After_Identifier: Boolean; begin After_AS_KeyWord := False; After_Identifier : False; //... // while walking arount SQL string, // if we encountered a ',' after AS keyword and after some identifier // we would like to place a new line after comma, like in here // // SELECT -- don't mind about new line here, but others may; //`epoch`.`comment` AS `year`, -- new line here; //`parameter`.`value` AS `value` -- this case is already handled by FROM keyword; // FROM `epoch` JOIN `parameter` for i:=1 to Length(SQL) do begin //... if (not InComment and not InBigComment and After_AS_KeyWord and After_Identifier and c = ',') then // something like Result[Run] := c; Result[Run+1]:= '\n'; // but i think you not you code better :) //... end; end; I described it like a special case, but i think you can integrate more seamlessly it in you flow |
|
Written by demoth
2 years ago 4 posts since Sat, 09 Apr 11 |
sorry for not wrapping that in {code} |
|
Written by ansgar
2 years ago 3966 posts since Fri, 07 Apr 06 |
That's perfect to discuss code a bit more abstract than it is actually required by some dumb compiler. Will check your proposal and see if I find the time to dive into that complicated stuff again. |
|
Written by bouvrie
2 years ago 4 posts since Wed, 10 Aug 11 |
I was wondering if the reformat SQL rules can be customizable through the UI, and indentation support be added? Basically I'm looking for a nice reformatting based on how I'm currently using Aqua Data Studio (http://www.aquafold.com/): http://imageshack.us/photo/my-images/638/beautify.jpg/# Source query: SELECT `column` FROM `table` WHERE `column`=0 AND `column`>( SELECT `column` FROM `table` WHERE `column`=( SELECT `column` FROM `table WHERE `COLUMN` BETWEEN 0 AND 10 ORDER BY `COLUMN` LIMIT 1 ) AND ` COLUMN`!=(SELECT `COLUMN` FROM `TABLE WHERE `column` BETWEEN 0 AND 10 ORDER BY `column` LIMIT 1 ) ORDER BY `column` LIMIT 1) Reformatting using HeidiSQL: SELECT `column` Reformatting using AquaData Studio, with the above (screenshot) settings: SELECT IMO the latter is far more agreeable on the eyes... |
|
Written by ansgar
2 years ago 3966 posts since Fri, 07 Apr 06 |
r3941 tries to fetch the very original source SQL the user entered before, and displays this in the VIEW editor. This is done by a quite hackish approach, loading the server's .frm file and extracting the right portion in it. |
|
Please login to leave a reply, or register at first. |