{"id":3471,"date":"2022-04-22T23:06:34","date_gmt":"2022-04-23T07:06:34","guid":{"rendered":"https:\/\/www.gudusoft.com\/?p=3471"},"modified":"2022-04-22T23:13:36","modified_gmt":"2022-04-23T07:13:36","slug":"sql-formatter-web-service","status":"publish","type":"post","link":"https:\/\/www.gudusoft.com\/de\/sql-formatter-web-service\/","title":{"rendered":"SQL Formatter-Webdienst"},"content":{"rendered":"<div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"background-color: rgba(255,255,255,0);background-position: center center;background-repeat: no-repeat;border-width: 0px 0px 0px 0px;border-color:#e8eaf0;border-style:solid;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start\" style=\"max-width:1310.4px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_1_1 1_1 fusion-flex-column\"><div class=\"fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column\" style=\"background-position:left top;background-repeat:no-repeat;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover;background-size:cover;padding: 0px 0px 0px 0px;\"><div class=\"fusion-text fusion-text-1\" style=\"line-height:26px;\"><h3 class=\"wp-block-heading\">Updated Info (2022)<\/h3>\n<p>This is an article written back in 2006 that was published on <a href=\"https:\/\/www.codeguru.com\/csharp\/sql-formatter-web-service\/\" class=\"rank-math-link\">codeguru<\/a> , and the technology used in this article may out of date. If you are looking for a good SQL formatter that can be used in your Java or Dotnet program, please <a href=\"https:\/\/sqlparser.com\/features\/sql-formatter.php\" class=\"rank-math-link\">check this page<\/a> instead. If you are looking for a free while fantastic SQL query formatter, please check the <a href=\"https:\/\/www.dpriver.com\/pp\/sqlformat.htm\" class=\"rank-math-link\">Instant SQL formatter.<\/a><\/p>\n<h3 class=\"wp-block-heading\">Introduction<\/h3>\n<p>SQL code is much easier and faster to read and understand when it is formatted, especially when it is a long and complicated SQL statement you are dealing with, or you have to read other people\u2019s code. Writing a decent SQL formatter is not an easy task. In this article, I would like to create an online SQL formatter in C#. This consuming application sends unformatted SQL to the server, which will return the formatted SQL to the application.<\/p>\n<h3 class=\"wp-block-heading\">Using the Code<\/h3>\n<p>A Web service at&nbsp;<a href=\"https:\/\/www.gudusoft.com\/de\/\">www.gudusoft.com<\/a>&nbsp;accepts SQL code and returns formatted SQL. Take a look at the WSDL&nbsp;here. The important part is shown below; it describes the beautifySql method.<\/p>\n<pre class=\"wp-block-code\"><code>  &lt;wsdl:operation name=\"beautifySql\">\r\n   &lt;documentation >\r\n      Beautify the sql\r\n   &lt;\/documentation>\r\n   &lt;wsdl:input message=\"tns:beautifySqlSoapIn\" \/>\r\n   &lt;wsdl:output message=\"tns:beautifySqlSoapOut\" \/>\r\n&lt;\/wsdl:operation> <\/code><\/pre>\n<h4 class=\"wp-block-heading\">Step 1: Build the proxy class<\/h4>\n<p>Executing the following \u2026<\/p>\n<pre class=\"wp-block-code\"><code>C:>wsdl.exe http:\/\/www.gudusoft.com\/SQLFormatterWebService.wsdl<\/code><\/pre>\n<p>\u2026 results in a C# file, SQLFormatterWebService.cs, that contains a class called SQLFormatterWebService. Examine how the methods of this class correspond to those detailed in the WSDL file, especially the following method:<\/p>\n<pre class=\"wp-block-code\"><code>public string beautifySql(string dbvendor, string sql)\r\ndbvendor: SQL dialect of which database supports MSSQL, Oracle,\r\n          MySQL, and Access currently.\r\nsql:      SQL code needs to be formatted.<\/code><\/pre>\n<h4 class=\"wp-block-heading\">Step 2: Compile the proxy class<\/h4>\n<p>Next, you have to compile the auto-generated file. The file contains no entry point and thus has to be built as a library.<\/p>\n<pre class=\"wp-block-code\"><code>C:>csc \/t:library c:SQLFormatterWebService.cs<\/code><\/pre>\n<p>This results in a new file, SQLFormatterWebService.dll.<\/p>\n<h4 class=\"wp-block-heading\">Step 3: Create an ASP.NET application<\/h4>\n<p>This application, sqlformatter.aspx, consumes the SQL Formatter Web Service.<\/p>\n<pre class=\"wp-block-code\"><code>&lt;%@Assembly Name=&quot;SQLFormatterWebService&quot; %&gt;\r\n\r\n&lt;html&gt;\r\n   &lt;head&gt;\r\n      &lt;title&gt;Demo of SQL Formatter Web Service &lt;\/title&gt;\r\n   &lt;\/head&gt;\r\n\r\n   &lt;body&gt;\r\n    &lt;form runat=&quot;server&quot; action=&quot;&quot;&gt;\r\n          &lt;asp:textbox id=&quot;inputsql&quot; text=&quot;select f1,f2 from t1&quot;\r\n                       textmode=&quot;MultiLine&quot; rows=&quot;10&quot; columns=&quot;60&quot;\r\n                       wrap=&quot;False&quot; runat=&quot;server&quot;\/&gt;\r\n   &lt;br&gt;&lt;asp:button text=&quot; Format Code &quot; onclick=&quot;onFormat&quot;\r\n                          runat=&quot;server&quot; \/&gt;\r\n          &lt;br&gt;&lt;asp:textbox id=&quot;outputsql&quot; textmode=&quot;MultiLine&quot;\r\n                           rows=&quot;10&quot; columns=&quot;60&quot; wrap=&quot;False&quot;\r\n                           runat=&quot;server&quot;\/&gt;\r\n\r\n   &lt;input type=&quot;hidden&quot; name=&quot;trp-form-language&quot; value=&quot;de&quot;\/&gt;&lt;\/form&gt;\r\n   &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n&lt;script language=&quot;c#&quot; runat=&quot;server&quot;&gt;\r\n   void onFormat (Object sender, EventArgs e)\r\n{\r\n      SQLFormatterWebService sqlformatter =\r\n         new SQLFormatterWebService();\r\n      outputsql.Text =\r\n         sqlformatter.beautifySql(&quot;mssql&quot;,inputsql.Text);\r\n}\r\n&lt;\/script&gt;<\/code><\/pre>\n<h4 class=\"wp-block-heading\">Step 4: Set up this ASP.NET application on your IIS server<\/h4>\n<ul>\n<li>4.1 Put the sqlformatter.aspx under wwwroot, for example.<\/li>\n<li>4.2 Put the SQLFormatterWebService.dll into the bin directory under wwwroot.<\/li>\n<li>4.3 Open your browser and type in http:\/\/localhost\/sqlformatter.aspx.<\/li>\n<\/ul>\n<p>Enjoy it!<\/p>\n<h3 class=\"wp-block-heading\">Points of Interest<\/h3>\n<p>This SQL Formatter Web Service can be used widely, especially in the forums of a database-related Web site, where a lot of SQL code will be submitted by users for discussion. It would be nice if this SQL code can be formatted before it\u2019s posted to the forum.<\/p>\n<p>For further information, these sites are useful if you are interested in a SQL formatter:<\/p>\n<ul>\n<li>SQL Formatter-Webdienst<\/li>\n<li><a href=\"http:\/\/www.wangz.net\/gsqlparser\/sqlpp\/sqlformat.htm\">Free Online SQL Formatter<\/a><\/li>\n<li><a href=\"http:\/\/www.sqlparser.com\/\">SQL Parser engine used by SQL formatter<\/a><\/li>\n<\/ul>\n<\/div><\/div><\/div><style type=\"text\/css\">.fusion-body .fusion-builder-column-0{width:100% !important;margin-top : 0px;margin-bottom : 0px;}.fusion-builder-column-0 > .fusion-column-wrapper {padding-top : 0px !important;padding-right : 0px !important;margin-right : 1.92%;padding-bottom : 0px !important;padding-left : 0px !important;margin-left : 1.92%;}@media only screen and (max-width:1024px) {.fusion-body .fusion-builder-column-0{width:100% !important;}.fusion-builder-column-0 > .fusion-column-wrapper {margin-right : 1.92%;margin-left : 1.92%;}}@media only screen and (max-width:640px) {.fusion-body .fusion-builder-column-0{width:100% !important;}.fusion-builder-column-0 > .fusion-column-wrapper {margin-right : 1.92%;margin-left : 1.92%;}}<\/style><\/div><style type=\"text\/css\">.fusion-body .fusion-flex-container.fusion-builder-row-1{ padding-top : 0px;margin-top : 0px;padding-right : 0px;padding-bottom : 0px;margin-bottom : 0px;padding-left : 0px;}<\/style><\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/posts\/3471"}],"collection":[{"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/comments?post=3471"}],"version-history":[{"count":4,"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/posts\/3471\/revisions"}],"predecessor-version":[{"id":3475,"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/posts\/3471\/revisions\/3475"}],"wp:attachment":[{"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/media?parent=3471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/categories?post=3471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gudusoft.com\/de\/wp-json\/wp\/v2\/tags?post=3471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}