Thread: PATCH: Format SQL (external tool)

PATCH: Format SQL (external tool)

From
"J.F. Oster"
Date:
Hello All!

Per discussion
http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com

It's most useful for making readable queries generated by ORMs such as
Hibernate. But in general, external processing can go far beyond
formatting task.

I've implemented this feature quick-and-dirty long ago. Finally I made
myself clean it up, now it looks better, so please consider a patch.
Tested on Windows 7 and Ubuntu 14.04.

Changes:
* added new setting, ExtFormatCmd, "External formatting utility" in
  Options dialogue
* added menu item "Edit - Format - External Format" in
  Query editor
* class sysProcess supports UTF-8 and can pass STDIN for a process.

Suggested use scenario:
1. Download and install some SQL formatting utility.
2. Tell pgAdmin where it resides:
   File - Options - Query Editor: External formatting utility.
3. Open Query editor. Select a text block to format and press
   Ctrl-Shift-F. With no selection the whole text gets formatted.
   In case of non-zero exit code, STDERR will be shown in status bar.

Requirements for external formatting utility:
* Accepts a STDIN stream and writes result to STDOUT
* Finishes in less than 3 seconds
* Exits with code 0 on success
Support for UTF-8 multibyte characters is preferable.

To see whether it works well, a test can be done:
C:\> type in.sql |some_formatter >out.sql
C:\> echo %ERRORLEVEL%
or
user@linux:~$ cat in.sql |some_formatter >out.sql
user@linux:~$ echo $?

There are few available utilities depending on platform:
   * Free SQL Formatter (Linux, Windows, Mac OS X(?))
     http://fsqlf.sourceforge.net/
   * Poor Man's T-SQL Formatter (Windows)
     http://architectshack.com/PoorMansTSqlFormatter.ashx
Also it is possible to make a wrapper script for numerous online
formatting services, but it's less secure and less reliable.

Fsqlf is FOSS and seems promising. I think of extending it for
PosgreSQL-specific SQL syntax and probably even PL/pgSQL.


--
Best regards,
 J.F.

Attachment

Fwd: PATCH: Format SQL (external tool)

From
"J.F. Oster"
Date:
Hello!

Please take a look at the patch.
Thanks.

Per discussion
http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com

It's most useful for making readable queries generated by ORMs such as
Hibernate. But in general, external processing can go far beyond
formatting task.

I've implemented this feature quick-and-dirty long ago. Finally I made
myself clean it up, now it looks better, so please consider a patch.
Tested on Windows 7 and Ubuntu 14.04.

Changes:
* added new setting, ExtFormatCmd, "External formatting utility" in
  Options dialogue
* added menu item "Edit - Format - External Format" in
  Query editor
* class sysProcess supports UTF-8 and can pass STDIN for a process.

Suggested use scenario:
1. Download and install some SQL formatting utility.
2. Tell pgAdmin where it resides:
   File - Options - Query Editor: External formatting utility.
3. Open Query editor. Select a text block to format and press
   Ctrl-Shift-F. With no selection the whole text gets formatted.
   In case of non-zero exit code, STDERR will be shown in status bar.

Requirements for external formatting utility:
* Accepts a STDIN stream and writes result to STDOUT
* Finishes in less than 3 seconds
* Exits with code 0 on success
Support for UTF-8 multibyte characters is preferable.

To see whether it works well, a test can be done:
C:\> type in.sql |some_formatter >out.sql
C:\> echo %ERRORLEVEL%
or
user@linux:~$ cat in.sql |some_formatter >out.sql
user@linux:~$ echo $?

There are few available utilities depending on platform:
   * Free SQL Formatter (Linux, Windows, Mac OS X(?))
     http://fsqlf.sourceforge.net/
   * Poor Man's T-SQL Formatter (Windows)
     http://architectshack.com/PoorMansTSqlFormatter.ashx
Also it is possible to make a wrapper script for numerous online
formatting services, but it's less secure and less reliable.

Fsqlf is FOSS and seems promising. I think of extending it for
PosgreSQL-specific SQL syntax and probably even PL/pgSQL.


--
Best regards,
 J.F.

Attachment

Re: Fwd: PATCH: Format SQL (external tool)

From
Dave Page
Date:
Akshay, can you take a look please?

Thanks.

On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:
> Hello!
>
> Please take a look at the patch.
> Thanks.
>
> Per discussion
> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com
>
> It's most useful for making readable queries generated by ORMs such as
> Hibernate. But in general, external processing can go far beyond
> formatting task.
>
> I've implemented this feature quick-and-dirty long ago. Finally I made
> myself clean it up, now it looks better, so please consider a patch.
> Tested on Windows 7 and Ubuntu 14.04.
>
> Changes:
> * added new setting, ExtFormatCmd, "External formatting utility" in
>   Options dialogue
> * added menu item "Edit - Format - External Format" in
>   Query editor
> * class sysProcess supports UTF-8 and can pass STDIN for a process.
>
> Suggested use scenario:
> 1. Download and install some SQL formatting utility.
> 2. Tell pgAdmin where it resides:
>    File - Options - Query Editor: External formatting utility.
> 3. Open Query editor. Select a text block to format and press
>    Ctrl-Shift-F. With no selection the whole text gets formatted.
>    In case of non-zero exit code, STDERR will be shown in status bar.
>
> Requirements for external formatting utility:
> * Accepts a STDIN stream and writes result to STDOUT
> * Finishes in less than 3 seconds
> * Exits with code 0 on success
> Support for UTF-8 multibyte characters is preferable.
>
> To see whether it works well, a test can be done:
> C:\> type in.sql |some_formatter >out.sql
> C:\> echo %ERRORLEVEL%
> or
> user@linux:~$ cat in.sql |some_formatter >out.sql
> user@linux:~$ echo $?
>
> There are few available utilities depending on platform:
>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))
>      http://fsqlf.sourceforge.net/
>    * Poor Man's T-SQL Formatter (Windows)
>      http://architectshack.com/PoorMansTSqlFormatter.ashx
> Also it is possible to make a wrapper script for numerous online
> formatting services, but it's less secure and less reliable.
>
> Fsqlf is FOSS and seems promising. I think of extending it for
> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.
>
>
> --
> Best regards,
>  J.F.
>
>
> --
> Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>



--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: Fwd: PATCH: Format SQL (external tool)

From
Akshay Joshi
Date:
Sure.

On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:
Akshay, can you take a look please?

Thanks.

On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:
> Hello!
>
> Please take a look at the patch.
> Thanks.
>
> Per discussion
> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com
>
> It's most useful for making readable queries generated by ORMs such as
> Hibernate. But in general, external processing can go far beyond
> formatting task.
>
> I've implemented this feature quick-and-dirty long ago. Finally I made
> myself clean it up, now it looks better, so please consider a patch.
> Tested on Windows 7 and Ubuntu 14.04.
>
> Changes:
> * added new setting, ExtFormatCmd, "External formatting utility" in
>   Options dialogue
> * added menu item "Edit - Format - External Format" in
>   Query editor
> * class sysProcess supports UTF-8 and can pass STDIN for a process.
>
> Suggested use scenario:
> 1. Download and install some SQL formatting utility.
> 2. Tell pgAdmin where it resides:
>    File - Options - Query Editor: External formatting utility.
> 3. Open Query editor. Select a text block to format and press
>    Ctrl-Shift-F. With no selection the whole text gets formatted.
>    In case of non-zero exit code, STDERR will be shown in status bar.
>
> Requirements for external formatting utility:
> * Accepts a STDIN stream and writes result to STDOUT
> * Finishes in less than 3 seconds
> * Exits with code 0 on success
> Support for UTF-8 multibyte characters is preferable.
>
> To see whether it works well, a test can be done:
> C:\> type in.sql |some_formatter >out.sql
> C:\> echo %ERRORLEVEL%
> or
> user@linux:~$ cat in.sql |some_formatter >out.sql
> user@linux:~$ echo $?
>
> There are few available utilities depending on platform:
>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))
>      http://fsqlf.sourceforge.net/
>    * Poor Man's T-SQL Formatter (Windows)
>      http://architectshack.com/PoorMansTSqlFormatter.ashx
> Also it is possible to make a wrapper script for numerous online
> formatting services, but it's less secure and less reliable.
>
> Fsqlf is FOSS and seems promising. I think of extending it for
> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.
>
>
> --
> Best regards,
>  J.F.
>
>
> --
> Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>



--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



--
Akshay Joshi
Principal Software Engineer 


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246

Re: Fwd: PATCH: Format SQL (external tool)

From
Akshay Joshi
Date:
Hi J.F

I am reviewing your patch. I have applied the patch and try to test it on Windows 7. Below are the steps that I perform 
  • Download SQL Formatter from http://fsqlf.sourceforge.net/
  • Given the path of fsqlf.exe/wx_fsqlf.exe in File - Options - Query Editor: External formatting utility
  • I have opened the query tool and wrote some select query. Please refer the attached screenshot for SQL query.
When I have given fsqlf.exe in the path it throws the error ( see attached screenshot) and when I have given wx_fsqlf.exe in the path it always report an error "Formatting command did not respond in 3 seconds" in the status bar. 

I am not sure how to test it properly. Can you please provide some steps.

On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:
Sure.

On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:
Akshay, can you take a look please?

Thanks.

On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:
> Hello!
>
> Please take a look at the patch.
> Thanks.
>
> Per discussion
> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com
>
> It's most useful for making readable queries generated by ORMs such as
> Hibernate. But in general, external processing can go far beyond
> formatting task.
>
> I've implemented this feature quick-and-dirty long ago. Finally I made
> myself clean it up, now it looks better, so please consider a patch.
> Tested on Windows 7 and Ubuntu 14.04.
>
> Changes:
> * added new setting, ExtFormatCmd, "External formatting utility" in
>   Options dialogue
> * added menu item "Edit - Format - External Format" in
>   Query editor
> * class sysProcess supports UTF-8 and can pass STDIN for a process.
>
> Suggested use scenario:
> 1. Download and install some SQL formatting utility.
> 2. Tell pgAdmin where it resides:
>    File - Options - Query Editor: External formatting utility.
> 3. Open Query editor. Select a text block to format and press
>    Ctrl-Shift-F. With no selection the whole text gets formatted.
>    In case of non-zero exit code, STDERR will be shown in status bar.
>
> Requirements for external formatting utility:
> * Accepts a STDIN stream and writes result to STDOUT
> * Finishes in less than 3 seconds
> * Exits with code 0 on success
> Support for UTF-8 multibyte characters is preferable.
>
> To see whether it works well, a test can be done:
> C:\> type in.sql |some_formatter >out.sql
> C:\> echo %ERRORLEVEL%
> or
> user@linux:~$ cat in.sql |some_formatter >out.sql
> user@linux:~$ echo $?
>
> There are few available utilities depending on platform:
>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))
>      http://fsqlf.sourceforge.net/
>    * Poor Man's T-SQL Formatter (Windows)
>      http://architectshack.com/PoorMansTSqlFormatter.ashx
> Also it is possible to make a wrapper script for numerous online
> formatting services, but it's less secure and less reliable.
>
> Fsqlf is FOSS and seems promising. I think of extending it for
> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.
>
>
> --
> Best regards,
>  J.F.
>
>
> --
> Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>



--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



--
Akshay Joshi
Principal Software Engineer 


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246



--
Akshay Joshi
Principal Software Engineer 


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246
Attachment

Re: Fwd: PATCH: Format SQL (external tool)

From
"J.F. Oster"
Date:
<p>Hi Akshay,<p><br /><p>fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.<p><br /><p>I've got the
latestversion (<span class="rvts14">fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run :(</span><p>Please try
theprevious one, it works for me.<p><a class="rvts17"
href="http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download">http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download</a><p><br
/><p>Alsoplease note that fsqlf.exe could fail when run in a path containing national characters.<p><br /><p><br
/><p><br/><p>Monday, May 18, 2015, 3:42:11 PM, you wrote:<p><br /><div><table border="0" cellpadding="1"
cellspacing="2"><trvalign="top"><td style="background-color: #0000ff;" width="12"><p><span
class="rvts6">></span></td><tdstyle="background-color: #ffffff;" width="1038"><p><span class="rvts7">Hi
J.F</span><p><br/><p><span class="rvts7">I am reviewing your patch. I have applied the patch and try to test it on
Windows7. Below are the steps that I perform </span><ul style="text-indent: 0px; margin-left: 40px;
list-style-position:outside;"><li><span class="rvts7">Download SQL Formatter from </span><a class="rvts8"
href="http://fsqlf.sourceforge.net/">http://fsqlf.sourceforge.net/</a><li><spanclass="rvts7">Given the path of
fsqlf.exe/wx_fsqlf.exein </span><span class="rvts9">File - Options - Query Editor: External formatting
utility</span><li><spanclass="rvts9">I have opened the query tool and wrote some select query. Please refer the
attachedscreenshot for SQL query.</span></ul><p><span class="rvts9">When I have given fsqlf.exe in the path it throws
theerror ( see attached screenshot) and when I have given wx_fsqlf.exe in the path it always report an error
"Formattingcommand did not respond in 3 seconds" in the status bar. </span><p><br /><p><span class="rvts9">I am not
surehow to test it properly. Can you please provide some steps.</span><p><br /><p><br /><p><span class="rvts7">On Mon,
May18, 2015 at 10:10 AM, Akshay Joshi <</span><a class="rvts10"
href="mailto:akshay.joshi@enterprisedb.com">akshay.joshi@enterprisedb.com</a><spanclass="rvts7">>
wrote:</span><p><br/><p><span class="rvts7">Sure.</span><p><br /><p><br /><p><span class="rvts7">On Fri, May 15, 2015
at9:30 PM, Dave Page <</span><a class="rvts10" href="mailto:dpage@pgadmin.org">dpage@pgadmin.org</a><span
class="rvts7">>wrote:</span><p><br /><p><span class="rvts7">Akshay, can you take a look please?</span><p><br
/><p><spanclass="rvts7">Thanks.</span><p><br /><p><br /><p><span class="rvts7">On Fri, May 15, 2015 at 4:53 PM, J.F.
Oster<</span><a class="rvts10" href="mailto:jinfroster@mail.ru">jinfroster@mail.ru</a><span class="rvts7">>
wrote:</span><p><spanclass="rvts7">> Hello!</span><p><span class="rvts7">></span><p><span class="rvts7">>
Pleasetake a look at the patch.</span><p><span class="rvts7">> Thanks.</span><p><span
class="rvts7">></span><p><spanclass="rvts7">> Per discussion</span><p><span class="rvts7">> </span><a
class="rvts10"
href="http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com">http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com</a><p><span
class="rvts7">></span><p><spanclass="rvts7">> It's most useful for making readable queries generated by ORMs such
as</span><p><spanclass="rvts7">> Hibernate. But in general, external processing can go far beyond</span><p><span
class="rvts7">>formatting task.</span><p><span class="rvts7">></span><p><span class="rvts7">> I've implemented
thisfeature quick-and-dirty long ago. Finally I made</span><p><span class="rvts7">> myself clean it up, now it looks
better,so please consider a patch.</span><p><span class="rvts7">> Tested on Windows 7 and Ubuntu
14.04.</span><p><spanclass="rvts7">></span><p><span class="rvts7">> Changes:</span><p><span class="rvts7">> *
addednew setting, ExtFormatCmd, "External formatting utility" in</span><p><span class="rvts7">>   Options
dialogue</span><p><spanclass="rvts7">> * added menu item "Edit - Format - External Format" in</span><p><span
class="rvts7">>  Query editor</span><p><span class="rvts7">> * class sysProcess supports UTF-8 and can pass STDIN
fora process.</span><p><span class="rvts7">></span><p><span class="rvts7">> Suggested use
scenario:</span><p><spanclass="rvts7">> 1. Download and install some SQL formatting utility.</span><p><span
class="rvts7">>2. Tell pgAdmin where it resides:</span><p><span class="rvts7">>    File - Options - Query Editor:
Externalformatting utility.</span><p><span class="rvts7">> 3. Open Query editor. Select a text block to format and
press</span><p><spanclass="rvts7">>    Ctrl-Shift-F. With no selection the whole text gets formatted.</span><p><span
class="rvts7">>   In case of non-zero exit code, STDERR will be shown in status bar.</span><p><span
class="rvts7">></span><p><spanclass="rvts7">> Requirements for external formatting utility:</span><p><span
class="rvts7">>* Accepts a STDIN stream and writes result to STDOUT</span><p><span class="rvts7">> * Finishes in
lessthan 3 seconds</span><p><span class="rvts7">> * Exits with code 0 on success</span><p><span class="rvts7">>
Supportfor UTF-8 multibyte characters is preferable.</span><p><span class="rvts7">></span><p><span
class="rvts7">>To see whether it works well, a test can be done:</span><p><span class="rvts7">> C:\> type
in.sql|some_formatter >out.sql</span><p><span class="rvts7">> C:\> echo %ERRORLEVEL%</span><p><span
class="rvts7">>or</span><p><span class="rvts7">> user@linux:~$ cat in.sql |some_formatter
>out.sql</span><p><spanclass="rvts7">> user@linux:~$ echo $?</span><p><span class="rvts7">></span><p><span
class="rvts7">>There are few available utilities depending on platform:</span><p><span class="rvts7">>    * Free
SQLFormatter (Linux, Windows, Mac OS X(?))</span><p><span class="rvts7">>      </span><a class="rvts10"
href="http://fsqlf.sourceforge.net/">http://fsqlf.sourceforge.net/</a><p><spanclass="rvts7">>    * Poor Man's T-SQL
Formatter(Windows)</span><p><span class="rvts7">>      </span><a class="rvts10"
href="http://architectshack.com/PoorMansTSqlFormatter.ashx">http://architectshack.com/PoorMansTSqlFormatter.ashx</a><p><span
class="rvts7">>Also it is possible to make a wrapper script for numerous online</span><p><span class="rvts7">>
formattingservices, but it's less secure and less reliable.</span><p><span class="rvts7">></span><p><span
class="rvts7">>Fsqlf is FOSS and seems promising. I think of extending it for</span><p><span class="rvts7">>
PosgreSQL-specificSQL syntax and probably even PL/pgSQL.</span><p><span class="rvts7">></span><p><span
class="rvts7">></span><p><spanclass="rvts7">> --</span><p><span class="rvts7">> Best regards,</span><p><span
class="rvts7">> J.F.</span><p><span class="rvts7">></span><p><span class="rvts7">></span><p><span
class="rvts11">>--</span><p><span class="rvts11">> Sent via pgadmin-hackers mailing list (</span><a
class="rvts10"href="mailto:pgadmin-hackers@postgresql.org">pgadmin-hackers@postgresql.org</a><span
class="rvts11">)</span><p><spanclass="rvts11">> To make changes to your subscription:</span><p><span
class="rvts11">> </span><aclass="rvts10"
href="http://www.postgresql.org/mailpref/pgadmin-hackers">http://www.postgresql.org/mailpref/pgadmin-hackers</a><p><span
class="rvts11">></span><p><br/><p><br /><p><br /><p><span class="rvts11">--</span><p><span class="rvts11">Dave
Page</span><p><spanclass="rvts11">Blog: </span><a class="rvts10"
href="http://pgsnake.blogspot.com">http://pgsnake.blogspot.com</a><p><spanclass="rvts11">Twitter: @pgsnake</span><p><br
/><p><spanclass="rvts11">EnterpriseDB UK: </span><a class="rvts10"
href="http://www.enterprisedb.com">http://www.enterprisedb.com</a><p><spanclass="rvts11">The Enterprise PostgreSQL
Company</span><p><br/><p><br /><p><br /><p><br /><p><span class="rvts11">-- </span><p><br /><p><span
class="rvts12">AkshayJoshi</span><p><span class="rvts12">Principal Software Engineer </span><p><br /><p><br /><p><span
class="rvts12">Phone:+91 20-3058-9517</span><p><span class="rvts12">Mobile: +91 976-788-8246</span><p><br /><p><br
/><p><br/><p><br /><p><span class="rvts7">-- </span><p><br /><p><span class="rvts12">Akshay Joshi</span><p><span
class="rvts12">PrincipalSoftware Engineer </span><p><br /><p><br /><p><span class="rvts12">Phone: +91
20-3058-9517</span><p><spanclass="rvts12">Mobile: +91 976-788-8246</span></td></tr></table></div><p><br /><p><br
/><p><br/><p><br /><p><span class="rvts13">-- </span><p><span class="rvts13">Best regards,</span><p><span
class="rvts13"> J.F.</span>

Re: Fwd: PATCH: Format SQL (external tool)

From
Akshay Joshi
Date:
Hi J.F

The version of fsql you have suggested works for me as well. I have reviewed your patch and it looks good to me. Please remove the commented code (wxString s; //, tmp;) at line 873 in sysSettings.cpp

On Mon, May 18, 2015 at 10:31 PM, J.F. Oster <jinfroster@mail.ru> wrote:

Hi Akshay,


fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.


I've got the latest version (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run :(

Please try the previous one, it works for me.

http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download


Also please note that fsqlf.exe could fail when run in a path containing national characters.




Monday, May 18, 2015, 3:42:11 PM, you wrote:


>

Hi J.F


I am reviewing your patch. I have applied the patch and try to test it on Windows 7. Below are the steps that I perform 

  • Download SQL Formatter from http://fsqlf.sourceforge.net/
  • Given the path of fsqlf.exe/wx_fsqlf.exe in File - Options - Query Editor: External formatting utility
  • I have opened the query tool and wrote some select query. Please refer the attached screenshot for SQL query.

When I have given fsqlf.exe in the path it throws the error ( see attached screenshot) and when I have given wx_fsqlf.exe in the path it always report an error "Formatting command did not respond in 3 seconds" in the status bar. 


I am not sure how to test it properly. Can you please provide some steps.



On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:


Sure.



On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:


Akshay, can you take a look please?


Thanks.



On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:

> Hello!

>

> Please take a look at the patch.

> Thanks.

>

> Per discussion

http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com

>

> It's most useful for making readable queries generated by ORMs such as

> Hibernate. But in general, external processing can go far beyond

> formatting task.

>

> I've implemented this feature quick-and-dirty long ago. Finally I made

> myself clean it up, now it looks better, so please consider a patch.

> Tested on Windows 7 and Ubuntu 14.04.

>

> Changes:

> * added new setting, ExtFormatCmd, "External formatting utility" in

>   Options dialogue

> * added menu item "Edit - Format - External Format" in

>   Query editor

> * class sysProcess supports UTF-8 and can pass STDIN for a process.

>

> Suggested use scenario:

> 1. Download and install some SQL formatting utility.

> 2. Tell pgAdmin where it resides:

>    File - Options - Query Editor: External formatting utility.

> 3. Open Query editor. Select a text block to format and press

>    Ctrl-Shift-F. With no selection the whole text gets formatted.

>    In case of non-zero exit code, STDERR will be shown in status bar.

>

> Requirements for external formatting utility:

> * Accepts a STDIN stream and writes result to STDOUT

> * Finishes in less than 3 seconds

> * Exits with code 0 on success

> Support for UTF-8 multibyte characters is preferable.

>

> To see whether it works well, a test can be done:

> C:\> type in.sql |some_formatter >out.sql

> C:\> echo %ERRORLEVEL%

> or

> user@linux:~$ cat in.sql |some_formatter >out.sql

> user@linux:~$ echo $?

>

> There are few available utilities depending on platform:

>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))

>      http://fsqlf.sourceforge.net/

>    * Poor Man's T-SQL Formatter (Windows)

>      http://architectshack.com/PoorMansTSqlFormatter.ashx

> Also it is possible to make a wrapper script for numerous online

> formatting services, but it's less secure and less reliable.

>

> Fsqlf is FOSS and seems promising. I think of extending it for

> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.

>

>

> --

> Best regards,

>  J.F.

>

>

> --

> Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)

> To make changes to your subscription:

http://www.postgresql.org/mailpref/pgadmin-hackers

>




--

Dave Page

Blog: http://pgsnake.blogspot.com

Twitter: @pgsnake


EnterpriseDB UK: http://www.enterprisedb.com

The Enterprise PostgreSQL Company





-- 


Akshay Joshi

Principal Software Engineer 



Phone: +91 20-3058-9517

Mobile: +91 976-788-8246





-- 


Akshay Joshi

Principal Software Engineer 



Phone: +91 20-3058-9517

Mobile: +91 976-788-8246





-- 

Best regards,

 J.F.




--
Akshay Joshi
Principal Software Engineer 


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246

Re: Fwd: PATCH: Format SQL (external tool)

From
"J.F. Oster"
Date:
Hi Akshay,

Removed that.

Tuesday, May 19, 2015, 10:04:59 AM, you wrote:

AJ> Hi J.F

AJ> The version of fsql you have suggested works for me as well. I
AJ> have reviewed your patch and it looks good to me. Please remove
AJ> the commented code (wxString s; //, tmp  at line 873 in sysSettings.cpp.


AJ> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster <jinfroster@mail.ru> wrote:
AJ> Hi Akshay,

AJ> fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.

AJ> I've got the latest version (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run
AJ> Please try the previous one, it works for me.
AJ> http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download

AJ> Also please note that fsqlf.exe could fail when run in a path containing national characters.



AJ> Monday, May 18, 2015, 3:42:11 PM, you wrote:




AJ> Hi J.F

AJ> I am reviewing your patch. I have applied the patch and try to
AJ> test it on Windows 7. Below are the steps that I perform
AJ> °       Download SQL Formatter from http://fsqlf.sourceforge.net/
AJ> °       Given the path of fsqlf.exe/wx_fsqlf.exe in File -
AJ> Options - Query Editor: External formatting utility
AJ> °       I have opened the query tool and wrote some select query.
AJ> Please refer the attached screenshot for SQL query.
AJ> When I have given fsqlf.exe in the path it throws the error ( see
AJ> attached screenshot) and when I have given wx_fsqlf.exe in the
AJ> path it always report an error "Formatting command did not respond
AJ> in 3 seconds" in the status bar.

AJ> I am not sure how to test it properly. Can you please provide some steps.


AJ> On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi
AJ> <akshay.joshi@enterprisedb.com> wrote:

AJ> Sure.


AJ> On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:

AJ> Akshay, can you take a look please?

AJ> Thanks.


AJ> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:
>> Hello!

>> Please take a look at the patch.
>> Thanks.

>> Per discussion
>> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com

>> It's most useful for making readable queries generated by ORMs such as
>> Hibernate. But in general, external processing can go far beyond
>> formatting task.

>> I've implemented this feature quick-and-dirty long ago. Finally I made
>> myself clean it up, now it looks better, so please consider a patch.
>> Tested on Windows 7 and Ubuntu 14.04.

>> Changes:
>> * added new setting, ExtFormatCmd, "External formatting utility" in
>>   Options dialogue
>> * added menu item "Edit - Format - External Format" in
>>   Query editor
>> * class sysProcess supports UTF-8 and can pass STDIN for a process.

>> Suggested use scenario:
>> 1. Download and install some SQL formatting utility.
>> 2. Tell pgAdmin where it resides:
>>    File - Options - Query Editor: External formatting utility.
>> 3. Open Query editor. Select a text block to format and press
>>    Ctrl-Shift-F. With no selection the whole text gets formatted.
>>    In case of non-zero exit code, STDERR will be shown in status bar.

>> Requirements for external formatting utility:
>> * Accepts a STDIN stream and writes result to STDOUT
>> * Finishes in less than 3 seconds
>> * Exits with code 0 on success
>> Support for UTF-8 multibyte characters is preferable.

>> To see whether it works well, a test can be done:
>> C:\> type in.sql |some_formatter >out.sql
>> C:\> echo %ERRORLEVEL%
>> or
>> user@linux:~$ cat in.sql |some_formatter >out.sql
>> user@linux:~$ echo $?

>> There are few available utilities depending on platform:
>>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))
>>      http://fsqlf.sourceforge.net/
>>    * Poor Man's T-SQL Formatter (Windows)
>>      http://architectshack.com/PoorMansTSqlFormatter.ashx
>> Also it is possible to make a wrapper script for numerous online
>> formatting services, but it's less secure and less reliable.

>> Fsqlf is FOSS and seems promising. I think of extending it for
>> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.


--
Best regards,
 J.F.

Attachment

Re: Fwd: PATCH: Format SQL (external tool)

From
"J.F. Oster"
Date:
Hello Akshay,

Is there something else to fix?

JFO> Hi Akshay,

JFO> Removed that.

JFO> Tuesday, May 19, 2015, 10:04:59 AM, you wrote:

AJ>> Hi J.F

AJ>> The version of fsql you have suggested works for me as well. I
AJ>> have reviewed your patch and it looks good to me. Please remove
AJ>> the commented code (wxString s; //, tmp  at line 873 in sysSettings.cpp.


AJ>> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster <jinfroster@mail.ru> wrote:
AJ>> Hi Akshay,

AJ>> fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.

AJ>> I've got the latest version (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run
AJ>> Please try the previous one, it works for me.
AJ>> http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download

AJ>> Also please note that fsqlf.exe could fail when run in a path containing national characters.



AJ>> Monday, May 18, 2015, 3:42:11 PM, you wrote:




AJ>> Hi J.F

AJ>> I am reviewing your patch. I have applied the patch and try to
AJ>> test it on Windows 7. Below are the steps that I perform
AJ>> °       Download SQL Formatter from http://fsqlf.sourceforge.net/
AJ>> °       Given the path of fsqlf.exe/wx_fsqlf.exe in File -
AJ>> Options - Query Editor: External formatting utility
AJ>> °       I have opened the query tool and wrote some select query.
AJ>> Please refer the attached screenshot for SQL query.
AJ>> When I have given fsqlf.exe in the path it throws the error ( see
AJ>> attached screenshot) and when I have given wx_fsqlf.exe in the
AJ>> path it always report an error "Formatting command did not respond
AJ>> in 3 seconds" in the status bar.

AJ>> I am not sure how to test it properly. Can you please provide some steps.


AJ>> On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi
AJ>> <akshay.joshi@enterprisedb.com> wrote:

AJ>> Sure.


AJ>> On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:

AJ>> Akshay, can you take a look please?

AJ>> Thanks.


AJ>> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:
>>> Hello!

>>> Please take a look at the patch.
>>> Thanks.

>>> Per discussion
>>> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com

>>> It's most useful for making readable queries generated by ORMs such as
>>> Hibernate. But in general, external processing can go far beyond
>>> formatting task.

>>> I've implemented this feature quick-and-dirty long ago. Finally I made
>>> myself clean it up, now it looks better, so please consider a patch.
>>> Tested on Windows 7 and Ubuntu 14.04.

>>> Changes:
>>> * added new setting, ExtFormatCmd, "External formatting utility" in
>>>   Options dialogue
>>> * added menu item "Edit - Format - External Format" in
>>>   Query editor
>>> * class sysProcess supports UTF-8 and can pass STDIN for a process.

>>> Suggested use scenario:
>>> 1. Download and install some SQL formatting utility.
>>> 2. Tell pgAdmin where it resides:
>>>    File - Options - Query Editor: External formatting utility.
>>> 3. Open Query editor. Select a text block to format and press
>>>    Ctrl-Shift-F. With no selection the whole text gets formatted.
>>>    In case of non-zero exit code, STDERR will be shown in status bar.

>>> Requirements for external formatting utility:
>>> * Accepts a STDIN stream and writes result to STDOUT
>>> * Finishes in less than 3 seconds
>>> * Exits with code 0 on success
>>> Support for UTF-8 multibyte characters is preferable.

>>> To see whether it works well, a test can be done:
>>> C:\> type in.sql |some_formatter >out.sql
>>> C:\> echo %ERRORLEVEL%
>>> or
>>> user@linux:~$ cat in.sql |some_formatter >out.sql
>>> user@linux:~$ echo $?

>>> There are few available utilities depending on platform:
>>>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))
>>>      http://fsqlf.sourceforge.net/
>>>    * Poor Man's T-SQL Formatter (Windows)
>>>      http://architectshack.com/PoorMansTSqlFormatter.ashx
>>> Also it is possible to make a wrapper script for numerous online
>>> formatting services, but it's less secure and less reliable.

>>> Fsqlf is FOSS and seems promising. I think of extending it for
>>> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.





--
Best regards,
 J.F.



Re: Fwd: PATCH: Format SQL (external tool)

From
Akshay Joshi
Date:

On Tue, May 26, 2015 at 9:51 PM, J.F. Oster <jinfroster@mail.ru> wrote:
Hello Akshay,

Is there something else to fix?

   Nothing. Patch looks good to me. 

JFO> Hi Akshay,

JFO> Removed that.

JFO> Tuesday, May 19, 2015, 10:04:59 AM, you wrote:

AJ>> Hi J.F

AJ>> The version of fsql you have suggested works for me as well. I
AJ>> have reviewed your patch and it looks good to me. Please remove
AJ>> the commented code (wxString s; //, tmp  at line 873 in sysSettings.cpp.


AJ>> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster <jinfroster@mail.ru> wrote:
AJ>> Hi Akshay,

AJ>> fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.

AJ>> I've got the latest version (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run
AJ>> Please try the previous one, it works for me.
AJ>> http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download

AJ>> Also please note that fsqlf.exe could fail when run in a path containing national characters.



AJ>> Monday, May 18, 2015, 3:42:11 PM, you wrote:




AJ>> Hi J.F

AJ>> I am reviewing your patch. I have applied the patch and try to
AJ>> test it on Windows 7. Below are the steps that I perform
AJ>> °       Download SQL Formatter from http://fsqlf.sourceforge.net/
AJ>> °       Given the path of fsqlf.exe/wx_fsqlf.exe in File -
AJ>> Options - Query Editor: External formatting utility
AJ>> °       I have opened the query tool and wrote some select query.
AJ>> Please refer the attached screenshot for SQL query.
AJ>> When I have given fsqlf.exe in the path it throws the error ( see
AJ>> attached screenshot) and when I have given wx_fsqlf.exe in the
AJ>> path it always report an error "Formatting command did not respond
AJ>> in 3 seconds" in the status bar.

AJ>> I am not sure how to test it properly. Can you please provide some steps.


AJ>> On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi
AJ>> <akshay.joshi@enterprisedb.com> wrote:

AJ>> Sure.


AJ>> On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:

AJ>> Akshay, can you take a look please?

AJ>> Thanks.


AJ>> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:
>>> Hello!

>>> Please take a look at the patch.
>>> Thanks.

>>> Per discussion
>>> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com

>>> It's most useful for making readable queries generated by ORMs such as
>>> Hibernate. But in general, external processing can go far beyond
>>> formatting task.

>>> I've implemented this feature quick-and-dirty long ago. Finally I made
>>> myself clean it up, now it looks better, so please consider a patch.
>>> Tested on Windows 7 and Ubuntu 14.04.

>>> Changes:
>>> * added new setting, ExtFormatCmd, "External formatting utility" in
>>>   Options dialogue
>>> * added menu item "Edit - Format - External Format" in
>>>   Query editor
>>> * class sysProcess supports UTF-8 and can pass STDIN for a process.

>>> Suggested use scenario:
>>> 1. Download and install some SQL formatting utility.
>>> 2. Tell pgAdmin where it resides:
>>>    File - Options - Query Editor: External formatting utility.
>>> 3. Open Query editor. Select a text block to format and press
>>>    Ctrl-Shift-F. With no selection the whole text gets formatted.
>>>    In case of non-zero exit code, STDERR will be shown in status bar.

>>> Requirements for external formatting utility:
>>> * Accepts a STDIN stream and writes result to STDOUT
>>> * Finishes in less than 3 seconds
>>> * Exits with code 0 on success
>>> Support for UTF-8 multibyte characters is preferable.

>>> To see whether it works well, a test can be done:
>>> C:\> type in.sql |some_formatter >out.sql
>>> C:\> echo %ERRORLEVEL%
>>> or
>>> user@linux:~$ cat in.sql |some_formatter >out.sql
>>> user@linux:~$ echo $?

>>> There are few available utilities depending on platform:
>>>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))
>>>      http://fsqlf.sourceforge.net/
>>>    * Poor Man's T-SQL Formatter (Windows)
>>>      http://architectshack.com/PoorMansTSqlFormatter.ashx
>>> Also it is possible to make a wrapper script for numerous online
>>> formatting services, but it's less secure and less reliable.

>>> Fsqlf is FOSS and seems promising. I think of extending it for
>>> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.





--
Best regards,
 J.F.




--
Akshay Joshi
Principal Software Engineer 


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246

Re: Fwd: PATCH: Format SQL (external tool)

From
Ashesh Vashi
Date:
Hi J. F. Oster,

I think - we should give option to the user about wait timeout (which is hard-coded to 3 seconds).
It should be asked in the options dialog.

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company


http://www.linkedin.com/in/asheshvashi


On Wed, May 27, 2015 at 10:56 AM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:

On Tue, May 26, 2015 at 9:51 PM, J.F. Oster <jinfroster@mail.ru> wrote:
Hello Akshay,

Is there something else to fix?

   Nothing. Patch looks good to me. 

JFO> Hi Akshay,

JFO> Removed that.

JFO> Tuesday, May 19, 2015, 10:04:59 AM, you wrote:

AJ>> Hi J.F

AJ>> The version of fsql you have suggested works for me as well. I
AJ>> have reviewed your patch and it looks good to me. Please remove
AJ>> the commented code (wxString s; //, tmp  at line 873 in sysSettings.cpp.


AJ>> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster <jinfroster@mail.ru> wrote:
AJ>> Hi Akshay,

AJ>> fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.

AJ>> I've got the latest version (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run
AJ>> Please try the previous one, it works for me.
AJ>> http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download

AJ>> Also please note that fsqlf.exe could fail when run in a path containing national characters.



AJ>> Monday, May 18, 2015, 3:42:11 PM, you wrote:




AJ>> Hi J.F

AJ>> I am reviewing your patch. I have applied the patch and try to
AJ>> test it on Windows 7. Below are the steps that I perform
AJ>> °       Download SQL Formatter from http://fsqlf.sourceforge.net/
AJ>> °       Given the path of fsqlf.exe/wx_fsqlf.exe in File -
AJ>> Options - Query Editor: External formatting utility
AJ>> °       I have opened the query tool and wrote some select query.
AJ>> Please refer the attached screenshot for SQL query.
AJ>> When I have given fsqlf.exe in the path it throws the error ( see
AJ>> attached screenshot) and when I have given wx_fsqlf.exe in the
AJ>> path it always report an error "Formatting command did not respond
AJ>> in 3 seconds" in the status bar.

AJ>> I am not sure how to test it properly. Can you please provide some steps.


AJ>> On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi
AJ>> <akshay.joshi@enterprisedb.com> wrote:

AJ>> Sure.


AJ>> On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:

AJ>> Akshay, can you take a look please?

AJ>> Thanks.


AJ>> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:
>>> Hello!

>>> Please take a look at the patch.
>>> Thanks.

>>> Per discussion
>>> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com

>>> It's most useful for making readable queries generated by ORMs such as
>>> Hibernate. But in general, external processing can go far beyond
>>> formatting task.

>>> I've implemented this feature quick-and-dirty long ago. Finally I made
>>> myself clean it up, now it looks better, so please consider a patch.
>>> Tested on Windows 7 and Ubuntu 14.04.

>>> Changes:
>>> * added new setting, ExtFormatCmd, "External formatting utility" in
>>>   Options dialogue
>>> * added menu item "Edit - Format - External Format" in
>>>   Query editor
>>> * class sysProcess supports UTF-8 and can pass STDIN for a process.

>>> Suggested use scenario:
>>> 1. Download and install some SQL formatting utility.
>>> 2. Tell pgAdmin where it resides:
>>>    File - Options - Query Editor: External formatting utility.
>>> 3. Open Query editor. Select a text block to format and press
>>>    Ctrl-Shift-F. With no selection the whole text gets formatted.
>>>    In case of non-zero exit code, STDERR will be shown in status bar.

>>> Requirements for external formatting utility:
>>> * Accepts a STDIN stream and writes result to STDOUT
>>> * Finishes in less than 3 seconds
>>> * Exits with code 0 on success
>>> Support for UTF-8 multibyte characters is preferable.

>>> To see whether it works well, a test can be done:
>>> C:\> type in.sql |some_formatter >out.sql
>>> C:\> echo %ERRORLEVEL%
>>> or
>>> user@linux:~$ cat in.sql |some_formatter >out.sql
>>> user@linux:~$ echo $?

>>> There are few available utilities depending on platform:
>>>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))
>>>      http://fsqlf.sourceforge.net/
>>>    * Poor Man's T-SQL Formatter (Windows)
>>>      http://architectshack.com/PoorMansTSqlFormatter.ashx
>>> Also it is possible to make a wrapper script for numerous online
>>> formatting services, but it's less secure and less reliable.

>>> Fsqlf is FOSS and seems promising. I think of extending it for
>>> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.





--
Best regards,
 J.F.




--
Akshay Joshi
Principal Software Engineer 


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246

Re: Fwd: PATCH: Format SQL (external tool)

From
Ashesh Vashi
Date:
On Wed, May 27, 2015 at 3:19 PM, Ashesh Vashi <ashesh.vashi@enterprisedb.com> wrote:
Hi J. F. Oster,

I think - we should give option to the user about wait timeout (which is hard-coded to 3 seconds).
It should be asked in the options dialog.
Apart from that - in the AbortProcess function, we're releasing the process object.
Does EVT_END_PROCESS event get fired even in case of killing the process across all supported platform?
(FYI - I've not tested the code yet.)

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company


http://www.linkedin.com/in/asheshvashi


On Wed, May 27, 2015 at 10:56 AM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:

On Tue, May 26, 2015 at 9:51 PM, J.F. Oster <jinfroster@mail.ru> wrote:
Hello Akshay,

Is there something else to fix?

   Nothing. Patch looks good to me. 

JFO> Hi Akshay,

JFO> Removed that.

JFO> Tuesday, May 19, 2015, 10:04:59 AM, you wrote:

AJ>> Hi J.F

AJ>> The version of fsql you have suggested works for me as well. I
AJ>> have reviewed your patch and it looks good to me. Please remove
AJ>> the commented code (wxString s; //, tmp  at line 873 in sysSettings.cpp.


AJ>> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster <jinfroster@mail.ru> wrote:
AJ>> Hi Akshay,

AJ>> fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.

AJ>> I've got the latest version (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run
AJ>> Please try the previous one, it works for me.
AJ>> http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download

AJ>> Also please note that fsqlf.exe could fail when run in a path containing national characters.



AJ>> Monday, May 18, 2015, 3:42:11 PM, you wrote:




AJ>> Hi J.F

AJ>> I am reviewing your patch. I have applied the patch and try to
AJ>> test it on Windows 7. Below are the steps that I perform
AJ>> °       Download SQL Formatter from http://fsqlf.sourceforge.net/
AJ>> °       Given the path of fsqlf.exe/wx_fsqlf.exe in File -
AJ>> Options - Query Editor: External formatting utility
AJ>> °       I have opened the query tool and wrote some select query.
AJ>> Please refer the attached screenshot for SQL query.
AJ>> When I have given fsqlf.exe in the path it throws the error ( see
AJ>> attached screenshot) and when I have given wx_fsqlf.exe in the
AJ>> path it always report an error "Formatting command did not respond
AJ>> in 3 seconds" in the status bar.

AJ>> I am not sure how to test it properly. Can you please provide some steps.


AJ>> On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi
AJ>> <akshay.joshi@enterprisedb.com> wrote:

AJ>> Sure.


AJ>> On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:

AJ>> Akshay, can you take a look please?

AJ>> Thanks.


AJ>> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:
>>> Hello!

>>> Please take a look at the patch.
>>> Thanks.

>>> Per discussion
>>> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com

>>> It's most useful for making readable queries generated by ORMs such as
>>> Hibernate. But in general, external processing can go far beyond
>>> formatting task.

>>> I've implemented this feature quick-and-dirty long ago. Finally I made
>>> myself clean it up, now it looks better, so please consider a patch.
>>> Tested on Windows 7 and Ubuntu 14.04.

>>> Changes:
>>> * added new setting, ExtFormatCmd, "External formatting utility" in
>>>   Options dialogue
>>> * added menu item "Edit - Format - External Format" in
>>>   Query editor
>>> * class sysProcess supports UTF-8 and can pass STDIN for a process.

>>> Suggested use scenario:
>>> 1. Download and install some SQL formatting utility.
>>> 2. Tell pgAdmin where it resides:
>>>    File - Options - Query Editor: External formatting utility.
>>> 3. Open Query editor. Select a text block to format and press
>>>    Ctrl-Shift-F. With no selection the whole text gets formatted.
>>>    In case of non-zero exit code, STDERR will be shown in status bar.

>>> Requirements for external formatting utility:
>>> * Accepts a STDIN stream and writes result to STDOUT
>>> * Finishes in less than 3 seconds
>>> * Exits with code 0 on success
>>> Support for UTF-8 multibyte characters is preferable.

>>> To see whether it works well, a test can be done:
>>> C:\> type in.sql |some_formatter >out.sql
>>> C:\> echo %ERRORLEVEL%
>>> or
>>> user@linux:~$ cat in.sql |some_formatter >out.sql
>>> user@linux:~$ echo $?

>>> There are few available utilities depending on platform:
>>>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))
>>>      http://fsqlf.sourceforge.net/
>>>    * Poor Man's T-SQL Formatter (Windows)
>>>      http://architectshack.com/PoorMansTSqlFormatter.ashx
>>> Also it is possible to make a wrapper script for numerous online
>>> formatting services, but it's less secure and less reliable.

>>> Fsqlf is FOSS and seems promising. I think of extending it for
>>> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.





--
Best regards,
 J.F.




--
Akshay Joshi
Principal Software Engineer 


Phone: +91 20-3058-9517
Mobile: +91 976-788-8246


Re: PATCH: Format SQL (external tool)

From
"J.F. Oster"
Date:
<p>Hello Ashesh,<p><br /><p>Sorry for long absense.<p><br /><p>Are you sure we need that additional option for
specifyingtimeout?<p>How do you see it placed in the Options dialogue? For me it will look somewhat surplus and
"overloading"the form.<p>It will be needed to change extremely rarely. The only true case I can imagine is using a
wrapperscript for online formatting service.<p>I suggest to provide a value in sysSettings, but keep it hidden. If
needed,the user will be able to change it by hand. The one who manages to use such advanced functionality IS a hacker
already:) and won't feel much inconvenience anyway.<p>How do you think?<p><br /><p>Regarding the events internals -
honestly,it's too complicated for me...<p>The very first version of my code in case of a timeout could lead to SEGFAULT
somewhereinside wxWidget's event handling internals, with no pgAdmin's code in the stack. <p>After I've changed by
guessthe AbortProcess() code to it's current look, it never broke since that. But I can't tell anymore deeper, sorry...
:(<p><br/><p><br /><p>Wednesday, May 27, 2015, 12:56:25 PM, you wrote:<p><br /><div><table border="0" cellpadding="1"
cellspacing="2"><trvalign="top"><td style="background-color: #0000ff;" width="12"><p><span
class="rvts6">></span></td><tdstyle="background-color: #ffffff;" width="1038"><p><span class="rvts7">On Wed, May 27,
2015at 3:19 PM, Ashesh Vashi <</span><a class="rvts8"
href="mailto:ashesh.vashi@enterprisedb.com">ashesh.vashi@enterprisedb.com</a><spanclass="rvts7">>
wrote:</span><p><spanclass="rvts7">Hi J. F. Oster,</span><p><br /><p><span class="rvts7">I think - we should give
optionto the user about wait timeout (which is hard-coded to 3 seconds).</span><p><span class="rvts7">It should be
askedin the options dialog.</span><p><span class="rvts7">Apart from that - in the AbortProcess function, we're
releasingthe process object.</span><p><span class="rvts7">Does EVT_END_PROCESS event get fired even in case of killing
theprocess across all supported platform?</span><p><span class="rvts7">(FYI - I've not tested the code
yet.)</span><p><br/><p><br /><p><span class="rvts9">--</span><p><span class="rvts9">Thanks & Regards,</span><p><br
/><p><spanclass="rvts9">Ashesh Vashi</span><p><span class="rvts9">EnterpriseDB INDIA: </span><a class="rvts10"
href="http://www.enterprisedb.com">EnterprisePostgreSQL Company</a><p><br /><p><a class="rvts11"
href="http://www.linkedin.com/in/asheshvashi">http://www.linkedin.com/in/asheshvashi</a><p><br/><p><br /><p><span
class="rvts7">OnWed, May 27, 2015 at 10:56 AM, Akshay Joshi <</span><a class="rvts8"
href="mailto:akshay.joshi@enterprisedb.com">akshay.joshi@enterprisedb.com</a><spanclass="rvts7">>
wrote:</span><p><br/><p><br /><p><br /><p><span class="rvts7">On Tue, May 26, 2015 at 9:51 PM, J.F. Oster <</span><a
class="rvts8"href="mailto:jinfroster@mail.ru">jinfroster@mail.ru</a><span class="rvts7">> wrote:</span><p><br
/><p><spanclass="rvts7">Hello Akshay,</span><p><br /><p><span class="rvts7">Is there something else to
fix?</span><p><br/><p><span class="rvts7">   Nothing. Patch looks good to me. </span><p><br /><p><span
class="rvts7">JFO>Hi Akshay,</span><p><br /><p><span class="rvts7">JFO> Removed that.</span><p><br /><p><br
/><p><spanclass="rvts7">JFO> Tuesday, May 19, 2015, 10:04:59 AM, you wrote:</span><p><br /><p><span
class="rvts7">AJ>>Hi J.F</span><p><br /><p><span class="rvts7">AJ>> The version of fsql you have suggested
worksfor me as well. I</span><p><span class="rvts7">AJ>> have reviewed your patch and it looks good to me. Please
remove</span><p><spanclass="rvts7">AJ>> the commented code (wxString s; //, tmp  at line 873 in
sysSettings.cpp.</span><p><br/><p><br /><p><span class="rvts7">AJ>> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster
<</span><aclass="rvts8" href="mailto:jinfroster@mail.ru">jinfroster@mail.ru</a><span class="rvts7">>
wrote:</span><p><spanclass="rvts7">AJ>> Hi Akshay,</span><p><br /><p><span class="rvts7">AJ>> fsqlf.exe is
theprogram to use; wx_fsqlf.exe is just a GUI wrapper.</span><p><br /><p><span class="rvts7">AJ>> I've got the
latestversion (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run</span><p><span class="rvts7">AJ>> Please
trythe previous one, it works for me.</span><p><span class="rvts7">AJ>> </span><a class="rvts8"
href="http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download">http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download</a><p><br
/><p><spanclass="rvts7">AJ>> Also please note that fsqlf.exe could fail when run in a path containing national
characters.</span><p><br/><p><br /><p><br /><p><span class="rvts7">AJ>> Monday, May 18, 2015, 3:42:11 PM, you
wrote:</span><p><br/><p><br /><p><br /><p><br /><p><span class="rvts7">AJ>> Hi J.F</span><p><br /><p><span
class="rvts7">AJ>>I am reviewing your patch. I have applied the patch and try to</span><p><span
class="rvts7">AJ>>test it on Windows 7. Below are the steps that I perform</span><p><span
class="rvts7">AJ>>°       Download SQL Formatter from </span><a class="rvts8"
href="http://fsqlf.sourceforge.net/">http://fsqlf.sourceforge.net/</a><p><spanclass="rvts7">AJ>> °       Given
thepath of fsqlf.exe/wx_fsqlf.exe in File -</span><p><span class="rvts7">AJ>> Options - Query Editor: External
formattingutility</span><p><span class="rvts7">AJ>> °       I have opened the query tool and wrote some select
query.</span><p><spanclass="rvts7">AJ>> Please refer the attached screenshot for SQL query.</span><p><span
class="rvts7">AJ>>When I have given fsqlf.exe in the path it throws the error ( see</span><p><span
class="rvts7">AJ>>attached screenshot) and when I have given wx_fsqlf.exe in the</span><p><span
class="rvts7">AJ>>path it always report an error "Formatting command did not respond</span><p><span
class="rvts7">AJ>>in 3 seconds" in the status bar.</span><p><br /><p><span class="rvts7">AJ>> I am not sure
howto test it properly. Can you please provide some steps.</span><p><br /><p><br /><p><span class="rvts7">AJ>> On
Mon,May 18, 2015 at 10:10 AM, Akshay Joshi</span><p><span class="rvts7">AJ>> <</span><a class="rvts8"
href="mailto:akshay.joshi@enterprisedb.com">akshay.joshi@enterprisedb.com</a><spanclass="rvts7">>
wrote:</span><p><br/><p><span class="rvts7">AJ>> Sure.</span><p><br /><p><br /><p><span class="rvts7">AJ>>
OnFri, May 15, 2015 at 9:30 PM, Dave Page <</span><a class="rvts8"
href="mailto:dpage@pgadmin.org">dpage@pgadmin.org</a><spanclass="rvts7">> wrote:</span><p><br /><p><span
class="rvts7">AJ>>Akshay, can you take a look please?</span><p><br /><p><span class="rvts7">AJ>>
Thanks.</span><p><br/><p><br /><p><span class="rvts7">AJ>> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster
<</span><aclass="rvts8" href="mailto:jinfroster@mail.ru">jinfroster@mail.ru</a><span class="rvts7">>
wrote:</span><p><spanclass="rvts7">>>> Hello!</span><p><br /><p><span class="rvts7">>>> Please take a
lookat the patch.</span><p><span class="rvts7">>>> Thanks.</span><p><br /><p><span class="rvts7">>>>
Perdiscussion</span><p><span class="rvts7">>>> </span><a class="rvts8"
href="http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com">http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com</a><p><br
/><p><spanclass="rvts7">>>> It's most useful for making readable queries generated by ORMs such
as</span><p><spanclass="rvts7">>>> Hibernate. But in general, external processing can go far
beyond</span><p><spanclass="rvts7">>>> formatting task.</span><p><br /><p><span class="rvts7">>>>
I'veimplemented this feature quick-and-dirty long ago. Finally I made</span><p><span class="rvts7">>>> myself
cleanit up, now it looks better, so please consider a patch.</span><p><span class="rvts7">>>> Tested on
Windows7 and Ubuntu 14.04.</span><p><br /><p><span class="rvts7">>>> Changes:</span><p><span
class="rvts7">>>>* added new setting, ExtFormatCmd, "External formatting utility" in</span><p><span
class="rvts7">>>>  Options dialogue</span><p><span class="rvts7">>>> * added menu item "Edit - Format
-External Format" in</span><p><span class="rvts7">>>>   Query editor</span><p><span class="rvts7">>>>
*class sysProcess supports UTF-8 and can pass STDIN for a process.</span><p><br /><p><span class="rvts7">>>>
Suggesteduse scenario:</span><p><span class="rvts7">>>> 1. Download and install some SQL formatting
utility.</span><p><spanclass="rvts7">>>> 2. Tell pgAdmin where it resides:</span><p><span
class="rvts7">>>>   File - Options - Query Editor: External formatting utility.</span><p><span
class="rvts7">>>>3. Open Query editor. Select a text block to format and press</span><p><span
class="rvts7">>>>   Ctrl-Shift-F. With no selection the whole text gets formatted.</span><p><span
class="rvts7">>>>   In case of non-zero exit code, STDERR will be shown in status bar.</span><p><br /><p><span
class="rvts7">>>>Requirements for external formatting utility:</span><p><span class="rvts7">>>> *
Acceptsa STDIN stream and writes result to STDOUT</span><p><span class="rvts7">>>> * Finishes in less than 3
seconds</span><p><spanclass="rvts7">>>> * Exits with code 0 on success</span><p><span
class="rvts7">>>>Support for UTF-8 multibyte characters is preferable.</span><p><br /><p><span
class="rvts7">>>>To see whether it works well, a test can be done:</span><p><span class="rvts7">>>>
C:\>type in.sql |some_formatter >out.sql</span><p><span class="rvts7">>>> C:\> echo
%ERRORLEVEL%</span><p><spanclass="rvts7">>>> or</span><p><span class="rvts7">>>> user@linux:~$ cat
in.sql|some_formatter >out.sql</span><p><span class="rvts7">>>> user@linux:~$ echo $?</span><p><br
/><p><spanclass="rvts7">>>> There are few available utilities depending on platform:</span><p><span
class="rvts7">>>>   * Free SQL Formatter (Linux, Windows, Mac OS X(?))</span><p><span
class="rvts7">>>>     </span><a class="rvts8"
href="http://fsqlf.sourceforge.net/">http://fsqlf.sourceforge.net/</a><p><spanclass="rvts7">>>>    * Poor
Man'sT-SQL Formatter (Windows)</span><p><span class="rvts7">>>>      </span><a class="rvts8"
href="http://architectshack.com/PoorMansTSqlFormatter.ashx">http://architectshack.com/PoorMansTSqlFormatter.ashx</a><p><span
class="rvts7">>>>Also it is possible to make a wrapper script for numerous online</span><p><span
class="rvts7">>>>formatting services, but it's less secure and less reliable.</span><p><br /><p><span
class="rvts7">>>>Fsqlf is FOSS and seems promising. I think of extending it for</span><p><span
class="rvts7">>>>PosgreSQL-specific SQL syntax and probably even PL/pgSQL.</span><p><br /><p><br /><p><br
/><p><br/><p><br /><p><span class="rvts7">--</span><p><span class="rvts7">Best regards,</span><p><span
class="rvts7"> J.F.</span><p><br/><p><br /><p><br /><p><br /><p><br /><p><span class="rvts7">-- </span><p><br
/><p><spanclass="rvts12">Akshay Joshi</span><p><span class="rvts12">Principal Software Engineer </span><p><br /><p><br
/><p><spanclass="rvts12">Phone: +91 20-3058-9517</span><p><span class="rvts12">Mobile: +91
976-788-8246</span></td></tr></table></div><p><br/><p><br /><p><br /><p><br /><p><span
class="rvts13">-- </span><p><spanclass="rvts13">Best regards,</span><p><span class="rvts13"> J.F.</span> 

Re: PATCH: Format SQL (external tool)

From
"J.F. Oster"
Date:
<p>Hi All,<p><br /><p>I haven't received any feedback on last message...<p>Attaching a new version of patch. Now it
readsa value for timeout from sysSettings, but I didn't add an input to Options form for reasons explained
earlier.<p><br/><p>Please see the attached patch.<p>Thanks.<p><br /><p><br /><p><br /><p>Friday, June 26, 2015, 9:48:52
PM,J.F. Oster wrote:<p><br /><div><table border="0" cellpadding="1" cellspacing="2"><tr valign="top"><td
style="background-color:#0000ff;" width="7"><p><span class="rvts6">></span></td><td style="background-color:
#ffffff;"width="949"><p><span class="rvts7">Hello Ashesh,</span><p><br /><p><span class="rvts7">Sorry for long
absense.</span><p><br/><p><span class="rvts7">Are you sure we need that additional option for specifying
timeout?</span><p><spanclass="rvts7">How do you see it placed in the Options dialogue? For me it will look somewhat
surplusand "overloading" the form.</span><p><span class="rvts7">It will be needed to change extremely rarely. The only
truecase I can imagine is using a wrapper script for online formatting service.</span><p><span class="rvts7">I suggest
toprovide a value in sysSettings, but keep it hidden. If needed, the user will be able to change it by hand. The one
whomanages to use such advanced functionality IS a hacker already :) and won't feel much inconvenience
anyway.</span><p><spanclass="rvts7">How do you think?</span><p><br /><p><span class="rvts7">Regarding the events
internals- honestly, it's too complicated for me...</span><p><span class="rvts7">The very first version of my code in
caseof a timeout could lead to SEGFAULT somewhere inside wxWidget's event handling internals, with no pgAdmin's code in
thestack. </span><p><span class="rvts7">After I've changed by guess the AbortProcess() code to it's current look, it
neverbroke since that. But I can't tell anymore deeper, sorry... :(</span><p><br /><p><br /><p><span
class="rvts7">Wednesday,May 27, 2015, 12:56:25 PM, you wrote:</span><p><br /><div><table border="0" cellpadding="1"
cellspacing="2"><trvalign="top"><td style="background-color: #0000ff;" width="14"><p><span
class="rvts8">></span></td><tdstyle="background-color: #ffffff;" width="929"><p><span class="rvts9">On Wed, May 27,
2015at 3:19 PM, Ashesh Vashi <</span><a class="rvts10"
href="mailto:ashesh.vashi@enterprisedb.com">ashesh.vashi@enterprisedb.com</a><spanclass="rvts9">>
wrote:</span><p><spanclass="rvts9">Hi J. F. Oster,</span><p><br /><p><span class="rvts9">I think - we should give
optionto the user about wait timeout (which is hard-coded to 3 seconds).</span><p><span class="rvts9">It should be
askedin the options dialog.</span><p><span class="rvts9">Apart from that - in the AbortProcess function, we're
releasingthe process object.</span><p><span class="rvts9">Does EVT_END_PROCESS event get fired even in case of killing
theprocess across all supported platform?</span><p><span class="rvts9">(FYI - I've not tested the code
yet.)</span><p><br/><p><br /><p><span class="rvts11">--</span><p><span class="rvts11">Thanks &
Regards,</span><p><br/><p><span class="rvts11">Ashesh Vashi</span><p><span class="rvts11">EnterpriseDB INDIA: </span><a
class="rvts12"href="http://www.enterprisedb.com">Enterprise PostgreSQL Company</a><p><br /><p><a class="rvts13"
href="http://www.linkedin.com/in/asheshvashi">http://www.linkedin.com/in/asheshvashi</a><p><br/><p><br /><p><span
class="rvts9">OnWed, May 27, 2015 at 10:56 AM, Akshay Joshi <</span><a class="rvts10"
href="mailto:akshay.joshi@enterprisedb.com">akshay.joshi@enterprisedb.com</a><spanclass="rvts9">>
wrote:</span><p><br/><p><br /><p><br /><p><span class="rvts9">On Tue, May 26, 2015 at 9:51 PM, J.F. Oster <</span><a
class="rvts10"href="mailto:jinfroster@mail.ru">jinfroster@mail.ru</a><span class="rvts9">> wrote:</span><p><br
/><p><spanclass="rvts9">Hello Akshay,</span><p><br /><p><span class="rvts9">Is there something else to
fix?</span><p><br/><p><span class="rvts9">   Nothing. Patch looks good to me. </span><p><br /><p><span
class="rvts9">JFO>Hi Akshay,</span><p><br /><p><span class="rvts9">JFO> Removed that.</span><p><br /><p><br
/><p><spanclass="rvts9">JFO> Tuesday, May 19, 2015, 10:04:59 AM, you wrote:</span><p><br /><p><span
class="rvts9">AJ>>Hi J.F</span><p><br /><p><span class="rvts9">AJ>> The version of fsql you have suggested
worksfor me as well. I</span><p><span class="rvts9">AJ>> have reviewed your patch and it looks good to me. Please
remove</span><p><spanclass="rvts9">AJ>> the commented code (wxString s; //, tmp  at line 873 in
sysSettings.cpp.</span><p><br/><p><br /><p><span class="rvts9">AJ>> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster
<</span><aclass="rvts10" href="mailto:jinfroster@mail.ru">jinfroster@mail.ru</a><span class="rvts9">>
wrote:</span><p><spanclass="rvts9">AJ>> Hi Akshay,</span><p><br /><p><span class="rvts9">AJ>> fsqlf.exe is
theprogram to use; wx_fsqlf.exe is just a GUI wrapper.</span><p><br /><p><span class="rvts9">AJ>> I've got the
latestversion (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run</span><p><span class="rvts9">AJ>> Please
trythe previous one, it works for me.</span><p><span class="rvts9">AJ>> </span><a class="rvts10"
href="http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download">http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download</a><p><br
/><p><spanclass="rvts9">AJ>> Also please note that fsqlf.exe could fail when run in a path containing national
characters.</span><p><br/><p><br /><p><br /><p><span class="rvts9">AJ>> Monday, May 18, 2015, 3:42:11 PM, you
wrote:</span><p><br/><p><br /><p><br /><p><br /><p><span class="rvts9">AJ>> Hi J.F</span><p><br /><p><span
class="rvts9">AJ>>I am reviewing your patch. I have applied the patch and try to</span><p><span
class="rvts9">AJ>>test it on Windows 7. Below are the steps that I perform</span><p><span
class="rvts9">AJ>>°       Download SQL Formatter from </span><a class="rvts10"
href="http://fsqlf.sourceforge.net/">http://fsqlf.sourceforge.net/</a><p><spanclass="rvts9">AJ>> °       Given
thepath of fsqlf.exe/wx_fsqlf.exe in File -</span><p><span class="rvts9">AJ>> Options - Query Editor: External
formattingutility</span><p><span class="rvts9">AJ>> °       I have opened the query tool and wrote some select
query.</span><p><spanclass="rvts9">AJ>> Please refer the attached screenshot for SQL query.</span><p><span
class="rvts9">AJ>>When I have given fsqlf.exe in the path it throws the error ( see</span><p><span
class="rvts9">AJ>>attached screenshot) and when I have given wx_fsqlf.exe in the</span><p><span
class="rvts9">AJ>>path it always report an error "Formatting command did not respond</span><p><span
class="rvts9">AJ>>in 3 seconds" in the status bar.</span><p><br /><p><span class="rvts9">AJ>> I am not sure
howto test it properly. Can you please provide some steps.</span><p><br /><p><br /><p><span class="rvts9">AJ>> On
Mon,May 18, 2015 at 10:10 AM, Akshay Joshi</span><p><span class="rvts9">AJ>> <</span><a class="rvts10"
href="mailto:akshay.joshi@enterprisedb.com">akshay.joshi@enterprisedb.com</a><spanclass="rvts9">>
wrote:</span><p><br/><p><span class="rvts9">AJ>> Sure.</span><p><br /><p><br /><p><span class="rvts9">AJ>>
OnFri, May 15, 2015 at 9:30 PM, Dave Page <</span><a class="rvts10"
href="mailto:dpage@pgadmin.org">dpage@pgadmin.org</a><spanclass="rvts9">> wrote:</span><p><br /><p><span
class="rvts9">AJ>>Akshay, can you take a look please?</span><p><br /><p><span class="rvts9">AJ>>
Thanks.</span><p><br/><p><br /><p><span class="rvts9">AJ>> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster
<</span><aclass="rvts10" href="mailto:jinfroster@mail.ru">jinfroster@mail.ru</a><span class="rvts9">>
wrote:</span><p><spanclass="rvts9">>>> Hello!</span><p><br /><p><span class="rvts9">>>> Please take a
lookat the patch.</span><p><span class="rvts9">>>> Thanks.</span><p><br /><p><span class="rvts9">>>>
Perdiscussion</span><p><span class="rvts9">>>> </span><a class="rvts10"
href="http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com">http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com</a><p><br
/><p><spanclass="rvts9">>>> It's most useful for making readable queries generated by ORMs such
as</span><p><spanclass="rvts9">>>> Hibernate. But in general, external processing can go far
beyond</span><p><spanclass="rvts9">>>> formatting task.</span><p><br /><p><span class="rvts9">>>>
I'veimplemented this feature quick-and-dirty long ago. Finally I made</span><p><span class="rvts9">>>> myself
cleanit up, now it looks better, so please consider a patch.</span><p><span class="rvts9">>>> Tested on
Windows7 and Ubuntu 14.04.</span><p><br /><p><span class="rvts9">>>> Changes:</span><p><span
class="rvts9">>>>* added new setting, ExtFormatCmd, "External formatting utility" in</span><p><span
class="rvts9">>>>  Options dialogue</span><p><span class="rvts9">>>> * added menu item "Edit - Format
-External Format" in</span><p><span class="rvts9">>>>   Query editor</span><p><span class="rvts9">>>>
*class sysProcess supports UTF-8 and can pass STDIN for a process.</span><p><br /><p><span class="rvts9">>>>
Suggesteduse scenario:</span><p><span class="rvts9">>>> 1. Download and install some SQL formatting
utility.</span><p><spanclass="rvts9">>>> 2. Tell pgAdmin where it resides:</span><p><span
class="rvts9">>>>   File - Options - Query Editor: External formatting utility.</span><p><span
class="rvts9">>>>3. Open Query editor. Select a text block to format and press</span><p><span
class="rvts9">>>>   Ctrl-Shift-F. With no selection the whole text gets formatted.</span><p><span
class="rvts9">>>>   In case of non-zero exit code, STDERR will be shown in status bar.</span><p><br /><p><span
class="rvts9">>>>Requirements for external formatting utility:</span><p><span class="rvts9">>>> *
Acceptsa STDIN stream and writes result to STDOUT</span><p><span class="rvts9">>>> * Finishes in less than 3
seconds</span><p><spanclass="rvts9">>>> * Exits with code 0 on success</span><p><span
class="rvts9">>>>Support for UTF-8 multibyte characters is preferable.</span><p><br /><p><span
class="rvts9">>>>To see whether it works well, a test can be done:</span><p><span class="rvts9">>>>
C:\>type in.sql |some_formatter >out.sql</span><p><span class="rvts9">>>> C:\> echo
%ERRORLEVEL%</span><p><spanclass="rvts9">>>> or</span><p><span class="rvts9">>>> user@linux:~$ cat
in.sql|some_formatter >out.sql</span><p><span class="rvts9">>>> user@linux:~$ echo $?</span><p><br
/><p><spanclass="rvts9">>>> There are few available utilities depending on platform:</span><p><span
class="rvts9">>>>   * Free SQL Formatter (Linux, Windows, Mac OS X(?))</span><p><span
class="rvts9">>>>     </span><a class="rvts10"
href="http://fsqlf.sourceforge.net/">http://fsqlf.sourceforge.net/</a><p><spanclass="rvts9">>>>    * Poor
Man'sT-SQL Formatter (Windows)</span><p><span class="rvts9">>>>      </span><a class="rvts10"
href="http://architectshack.com/PoorMansTSqlFormatter.ashx">http://architectshack.com/PoorMansTSqlFormatter.ashx</a><p><span
class="rvts9">>>>Also it is possible to make a wrapper script for numerous online</span><p><span
class="rvts9">>>>formatting services, but it's less secure and less reliable.</span><p><br /><p><span
class="rvts9">>>>Fsqlf is FOSS and seems promising. I think of extending it for</span><p><span
class="rvts9">>>>PosgreSQL-specific SQL syntax and probably even PL/pgSQL.</span><p><br /><p><br /><p><br
/><p><br/><p><br /><p><span class="rvts9">--</span><p><span class="rvts9">Best regards,</span><p><span
class="rvts9"> J.F.</span><p><br/><p><br /><p><br /><p><br /><p><br /><p><span class="rvts9">-- </span><p><br
/><p><spanclass="rvts14">Akshay Joshi</span><p><span class="rvts14">Principal Software Engineer </span><p><br /><p><br
/><p><spanclass="rvts14">Phone: +91 20-3058-9517</span><p><span class="rvts14">Mobile: +91
976-788-8246</span></td></tr></table></div><p><br/><p><br /><p><br /><p><br /><p><span
class="rvts15">-- </span><p><spanclass="rvts15">Best regards,</span><p><span
class="rvts15"> J.F.</span></td></tr></table></div><p><br/><p><br /><p><br /><p><br /><p><span
class="rvts16">-- </span><p><spanclass="rvts16">Best regards,</span><p><span class="rvts16"> J.F.</span> 

Re: PATCH: Format SQL (external tool)

From
Dave Page
Date:
Have you got this Ashesh?

On Sat, Jul 18, 2015 at 1:06 PM, J.F. Oster <jinfroster@mail.ru> wrote:

Hi All,


I haven't received any feedback on last message...

Attaching a new version of patch. Now it reads a value for timeout from sysSettings, but I didn't add an input to Options form for reasons explained earlier.


Please see the attached patch.

Thanks.




Friday, June 26, 2015, 9:48:52 PM, J.F. Oster wrote:


>

Hello Ashesh,


Sorry for long absense.


Are you sure we need that additional option for specifying timeout?

How do you see it placed in the Options dialogue? For me it will look somewhat surplus and "overloading" the form.

It will be needed to change extremely rarely. The only true case I can imagine is using a wrapper script for online formatting service.

I suggest to provide a value in sysSettings, but keep it hidden. If needed, the user will be able to change it by hand. The one who manages to use such advanced functionality IS a hacker already :) and won't feel much inconvenience anyway.

How do you think?


Regarding the events internals - honestly, it's too complicated for me...

The very first version of my code in case of a timeout could lead to SEGFAULT somewhere inside wxWidget's event handling internals, with no pgAdmin's code in the stack. 

After I've changed by guess the AbortProcess() code to it's current look, it never broke since that. But I can't tell anymore deeper, sorry... :(



Wednesday, May 27, 2015, 12:56:25 PM, you wrote:


>

On Wed, May 27, 2015 at 3:19 PM, Ashesh Vashi <ashesh.vashi@enterprisedb.com> wrote:

Hi J. F. Oster,


I think - we should give option to the user about wait timeout (which is hard-coded to 3 seconds).

It should be asked in the options dialog.

Apart from that - in the AbortProcess function, we're releasing the process object.

Does EVT_END_PROCESS event get fired even in case of killing the process across all supported platform?

(FYI - I've not tested the code yet.)



--

Thanks & Regards,


Ashesh Vashi

EnterpriseDB INDIA: Enterprise PostgreSQL Company


http://www.linkedin.com/in/asheshvashi



On Wed, May 27, 2015 at 10:56 AM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:




On Tue, May 26, 2015 at 9:51 PM, J.F. Oster <jinfroster@mail.ru> wrote:


Hello Akshay,


Is there something else to fix?


   Nothing. Patch looks good to me. 


JFO> Hi Akshay,


JFO> Removed that.



JFO> Tuesday, May 19, 2015, 10:04:59 AM, you wrote:


AJ>> Hi J.F


AJ>> The version of fsql you have suggested works for me as well. I

AJ>> have reviewed your patch and it looks good to me. Please remove

AJ>> the commented code (wxString s; //, tmp  at line 873 in sysSettings.cpp.



AJ>> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster <jinfroster@mail.ru> wrote:

AJ>> Hi Akshay,


AJ>> fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.


AJ>> I've got the latest version (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run

AJ>> Please try the previous one, it works for me.

AJ>> http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download


AJ>> Also please note that fsqlf.exe could fail when run in a path containing national characters.




AJ>> Monday, May 18, 2015, 3:42:11 PM, you wrote:





AJ>> Hi J.F


AJ>> I am reviewing your patch. I have applied the patch and try to

AJ>> test it on Windows 7. Below are the steps that I perform

AJ>> °       Download SQL Formatter from http://fsqlf.sourceforge.net/

AJ>> °       Given the path of fsqlf.exe/wx_fsqlf.exe in File -

AJ>> Options - Query Editor: External formatting utility

AJ>> °       I have opened the query tool and wrote some select query.

AJ>> Please refer the attached screenshot for SQL query.

AJ>> When I have given fsqlf.exe in the path it throws the error ( see

AJ>> attached screenshot) and when I have given wx_fsqlf.exe in the

AJ>> path it always report an error "Formatting command did not respond

AJ>> in 3 seconds" in the status bar.


AJ>> I am not sure how to test it properly. Can you please provide some steps.



AJ>> On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi

AJ>> <akshay.joshi@enterprisedb.com> wrote:


AJ>> Sure.



AJ>> On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:


AJ>> Akshay, can you take a look please?


AJ>> Thanks.



AJ>> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:

>>> Hello!


>>> Please take a look at the patch.

>>> Thanks.


>>> Per discussion

>>> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com


>>> It's most useful for making readable queries generated by ORMs such as

>>> Hibernate. But in general, external processing can go far beyond

>>> formatting task.


>>> I've implemented this feature quick-and-dirty long ago. Finally I made

>>> myself clean it up, now it looks better, so please consider a patch.

>>> Tested on Windows 7 and Ubuntu 14.04.


>>> Changes:

>>> * added new setting, ExtFormatCmd, "External formatting utility" in

>>>   Options dialogue

>>> * added menu item "Edit - Format - External Format" in

>>>   Query editor

>>> * class sysProcess supports UTF-8 and can pass STDIN for a process.


>>> Suggested use scenario:

>>> 1. Download and install some SQL formatting utility.

>>> 2. Tell pgAdmin where it resides:

>>>    File - Options - Query Editor: External formatting utility.

>>> 3. Open Query editor. Select a text block to format and press

>>>    Ctrl-Shift-F. With no selection the whole text gets formatted.

>>>    In case of non-zero exit code, STDERR will be shown in status bar.


>>> Requirements for external formatting utility:

>>> * Accepts a STDIN stream and writes result to STDOUT

>>> * Finishes in less than 3 seconds

>>> * Exits with code 0 on success

>>> Support for UTF-8 multibyte characters is preferable.


>>> To see whether it works well, a test can be done:

>>> C:\> type in.sql |some_formatter >out.sql

>>> C:\> echo %ERRORLEVEL%

>>> or

>>> user@linux:~$ cat in.sql |some_formatter >out.sql

>>> user@linux:~$ echo $?


>>> There are few available utilities depending on platform:

>>>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))

>>>      http://fsqlf.sourceforge.net/

>>>    * Poor Man's T-SQL Formatter (Windows)

>>>      http://architectshack.com/PoorMansTSqlFormatter.ashx

>>> Also it is possible to make a wrapper script for numerous online

>>> formatting services, but it's less secure and less reliable.


>>> Fsqlf is FOSS and seems promising. I think of extending it for

>>> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.






--

Best regards,

 J.F.






-- 


Akshay Joshi

Principal Software Engineer 



Phone: +91 20-3058-9517

Mobile: +91 976-788-8246





-- 

Best regards,

 J.F.





-- 

Best regards,

 J.F.



--
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers




--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

Re: PATCH: Format SQL (external tool)

From
Ashesh Vashi
Date:
Hi J.F. Oster,

Looks good to me.
Committed to the repository on master branch.

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company


http://www.linkedin.com/in/asheshvashi


On Mon, Jul 20, 2015 at 1:21 PM, Dave Page <dpage@pgadmin.org> wrote:
Have you got this Ashesh?

On Sat, Jul 18, 2015 at 1:06 PM, J.F. Oster <jinfroster@mail.ru> wrote:

Hi All,


I haven't received any feedback on last message...

Attaching a new version of patch. Now it reads a value for timeout from sysSettings, but I didn't add an input to Options form for reasons explained earlier.


Please see the attached patch.

Thanks.




Friday, June 26, 2015, 9:48:52 PM, J.F. Oster wrote:


>

Hello Ashesh,


Sorry for long absense.


Are you sure we need that additional option for specifying timeout?

How do you see it placed in the Options dialogue? For me it will look somewhat surplus and "overloading" the form.

It will be needed to change extremely rarely. The only true case I can imagine is using a wrapper script for online formatting service.

I suggest to provide a value in sysSettings, but keep it hidden. If needed, the user will be able to change it by hand. The one who manages to use such advanced functionality IS a hacker already :) and won't feel much inconvenience anyway.

How do you think?


Regarding the events internals - honestly, it's too complicated for me...

The very first version of my code in case of a timeout could lead to SEGFAULT somewhere inside wxWidget's event handling internals, with no pgAdmin's code in the stack. 

After I've changed by guess the AbortProcess() code to it's current look, it never broke since that. But I can't tell anymore deeper, sorry... :(



Wednesday, May 27, 2015, 12:56:25 PM, you wrote:


>

On Wed, May 27, 2015 at 3:19 PM, Ashesh Vashi <ashesh.vashi@enterprisedb.com> wrote:

Hi J. F. Oster,


I think - we should give option to the user about wait timeout (which is hard-coded to 3 seconds).

It should be asked in the options dialog.

Apart from that - in the AbortProcess function, we're releasing the process object.

Does EVT_END_PROCESS event get fired even in case of killing the process across all supported platform?

(FYI - I've not tested the code yet.)



--

Thanks & Regards,


Ashesh Vashi

EnterpriseDB INDIA: Enterprise PostgreSQL Company


http://www.linkedin.com/in/asheshvashi



On Wed, May 27, 2015 at 10:56 AM, Akshay Joshi <akshay.joshi@enterprisedb.com> wrote:




On Tue, May 26, 2015 at 9:51 PM, J.F. Oster <jinfroster@mail.ru> wrote:


Hello Akshay,


Is there something else to fix?


   Nothing. Patch looks good to me. 


JFO> Hi Akshay,


JFO> Removed that.



JFO> Tuesday, May 19, 2015, 10:04:59 AM, you wrote:


AJ>> Hi J.F


AJ>> The version of fsql you have suggested works for me as well. I

AJ>> have reviewed your patch and it looks good to me. Please remove

AJ>> the commented code (wxString s; //, tmp  at line 873 in sysSettings.cpp.



AJ>> On Mon, May 18, 2015 at 10:31 PM, J.F. Oster <jinfroster@mail.ru> wrote:

AJ>> Hi Akshay,


AJ>> fsqlf.exe is the program to use; wx_fsqlf.exe is just a GUI wrapper.


AJ>> I've got the latest version (fsqlf.v0.03-292-gd0fd9bf.zip), and it really fails to run

AJ>> Please try the previous one, it works for me.

AJ>> http://sourceforge.net/projects/fsqlf/files/fsqlf.v0.03/fsqlf.v0.03-141-g94f5a5f.zip.gz/download


AJ>> Also please note that fsqlf.exe could fail when run in a path containing national characters.




AJ>> Monday, May 18, 2015, 3:42:11 PM, you wrote:





AJ>> Hi J.F


AJ>> I am reviewing your patch. I have applied the patch and try to

AJ>> test it on Windows 7. Below are the steps that I perform

AJ>> °       Download SQL Formatter from http://fsqlf.sourceforge.net/

AJ>> °       Given the path of fsqlf.exe/wx_fsqlf.exe in File -

AJ>> Options - Query Editor: External formatting utility

AJ>> °       I have opened the query tool and wrote some select query.

AJ>> Please refer the attached screenshot for SQL query.

AJ>> When I have given fsqlf.exe in the path it throws the error ( see

AJ>> attached screenshot) and when I have given wx_fsqlf.exe in the

AJ>> path it always report an error "Formatting command did not respond

AJ>> in 3 seconds" in the status bar.


AJ>> I am not sure how to test it properly. Can you please provide some steps.



AJ>> On Mon, May 18, 2015 at 10:10 AM, Akshay Joshi

AJ>> <akshay.joshi@enterprisedb.com> wrote:


AJ>> Sure.



AJ>> On Fri, May 15, 2015 at 9:30 PM, Dave Page <dpage@pgadmin.org> wrote:


AJ>> Akshay, can you take a look please?


AJ>> Thanks.



AJ>> On Fri, May 15, 2015 at 4:53 PM, J.F. Oster <jinfroster@mail.ru> wrote:

>>> Hello!


>>> Please take a look at the patch.

>>> Thanks.


>>> Per discussion

>>> http://www.postgresql.org/message-id/CAPyomk5NT9Tm-r3wombLzoY60Vqa+QyRDy4u84_2K9UWLbWHTg@mail.gmail.com


>>> It's most useful for making readable queries generated by ORMs such as

>>> Hibernate. But in general, external processing can go far beyond

>>> formatting task.


>>> I've implemented this feature quick-and-dirty long ago. Finally I made

>>> myself clean it up, now it looks better, so please consider a patch.

>>> Tested on Windows 7 and Ubuntu 14.04.


>>> Changes:

>>> * added new setting, ExtFormatCmd, "External formatting utility" in

>>>   Options dialogue

>>> * added menu item "Edit - Format - External Format" in

>>>   Query editor

>>> * class sysProcess supports UTF-8 and can pass STDIN for a process.


>>> Suggested use scenario:

>>> 1. Download and install some SQL formatting utility.

>>> 2. Tell pgAdmin where it resides:

>>>    File - Options - Query Editor: External formatting utility.

>>> 3. Open Query editor. Select a text block to format and press

>>>    Ctrl-Shift-F. With no selection the whole text gets formatted.

>>>    In case of non-zero exit code, STDERR will be shown in status bar.


>>> Requirements for external formatting utility:

>>> * Accepts a STDIN stream and writes result to STDOUT

>>> * Finishes in less than 3 seconds

>>> * Exits with code 0 on success

>>> Support for UTF-8 multibyte characters is preferable.


>>> To see whether it works well, a test can be done:

>>> C:\> type in.sql |some_formatter >out.sql

>>> C:\> echo %ERRORLEVEL%

>>> or

>>> user@linux:~$ cat in.sql |some_formatter >out.sql

>>> user@linux:~$ echo $?


>>> There are few available utilities depending on platform:

>>>    * Free SQL Formatter (Linux, Windows, Mac OS X(?))

>>>      http://fsqlf.sourceforge.net/

>>>    * Poor Man's T-SQL Formatter (Windows)

>>>      http://architectshack.com/PoorMansTSqlFormatter.ashx

>>> Also it is possible to make a wrapper script for numerous online

>>> formatting services, but it's less secure and less reliable.


>>> Fsqlf is FOSS and seems promising. I think of extending it for

>>> PosgreSQL-specific SQL syntax and probably even PL/pgSQL.






--

Best regards,

 J.F.






-- 


Akshay Joshi

Principal Software Engineer 



Phone: +91 20-3058-9517

Mobile: +91 976-788-8246





-- 

Best regards,

 J.F.





-- 

Best regards,

 J.F.



--
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers




--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company