Work encountered a scene, need to use VBA to re-beautiful SQL statement format, originally wanted to directly call the local Sqlworkbench tool to achieve this function, but can not find the command parameters, cannot be directly called by VBA, forget.
Find the API that can call the website directly with VBA call HTTP POST can be implemented.
Web API Description:
Https://github.com/sqlparser/sql-pretty-printer/wiki/SQL-FaaS-API-manual
The required parameters are Rqst_input_sql, and the SQL statements with conversions are passed in.
Response the parameters of attention inside, rspn_output_fmt the SQL statement after the conversion.
The VBA function code is as follows:
FunctionCallsqlformat (ByValSql as String) DimhttpSetHTTP =CreateObject("Microsoft.XMLHTTP") http. Open"POST","http://www.gudusoft.com/format.php",FalseHttp.setrequestheader"Content-type","application/x-www-form-urlencoded"Http.send"rqst_input_sql="&SQLIfhttp. Status = $ ThenResp_text=Http.responsetext Istart=InStr(Resp_text,"Rspn_formatted_sql") Iend=InStr(Resp_text,"}") Callsqlformat=Replace(Mid(Resp_text, Istart + -+2+1, Iend-istart- A),"\ n", vblf)ElseCallsqlformat=SQLEnd IfEnd Function
VBA POST calls Web API to format SQL statements