-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormatSql.vb
31 lines (23 loc) · 1.01 KB
/
FormatSql.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Public Class FormatSql
Private Sub btnBeautify_Click(sender As Object, e As EventArgs) Handles btnBeautify.Click
txtOut.Text = ParseSql(txtIn.Text)
End Sub
Private Function ParseSql(ByVal sql As String)
Dim _tokenizer As New PoorMansTSqlFormatterLib.Tokenizers.TSqlStandardTokenizer()
Dim _parser = New PoorMansTSqlFormatterLib.Parsers.TSqlStandardParser()
Dim _treeFormatter As New PoorMansTSqlFormatterLib.Formatters.TSqlStandardFormatter()
Dim tokenized As PoorMansTSqlFormatterLib.TokenList = _tokenizer.TokenizeSQL(sql)
Dim parsed As PoorMansTSqlFormatterLib.ParseStructure.Node = _parser.ParseSQL(tokenized)
Dim sRet As String = _treeFormatter.FormatSQLTree(parsed)
If sRet.IndexOf("--WARNING! ERRORS ENCOUNTERED DURING SQL PARSING!") <> -1 Then
Return sql
End If
Return sRet
End Function
Private Sub btnSelectAll_Click(sender As Object, e As EventArgs) Handles btnSelectAll.Click
txtOut.SelectAll()
txtOut.Focus()
Clipboard.Clear()
Clipboard.SetText(txtOut.Text)
End Sub
End Class