Common: Apply distinct to sql placeholders
This commit is contained in:
parent
48830e3dd9
commit
f0c27890a8
@ -38,11 +38,6 @@ Namespace SQLEditor
|
||||
Name = pValue
|
||||
[Module] = pModule
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return DirectCast(obj, Placeholder).Module = [Module] And
|
||||
DirectCast(obj, Placeholder).Name = Name
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@ -57,45 +57,45 @@ Namespace SQLEditor
|
||||
End Sub
|
||||
|
||||
Private Function ParseTokens() As List(Of SyntaxHighlightToken)
|
||||
Dim tokens As New List(Of SyntaxHighlightToken)()
|
||||
Dim ranges() As DocumentRange = Nothing
|
||||
Dim oTokens As New List(Of SyntaxHighlightToken)()
|
||||
Dim oRanges As IEnumerable(Of DocumentRange) = Nothing
|
||||
|
||||
' search for quoted strings
|
||||
ranges = TryCast(document.FindAll(_quotedString).GetAsFrozen(), DocumentRange())
|
||||
For i As Integer = 0 To ranges.Length - 1
|
||||
tokens.Add(CreateToken(ranges(i).Start.ToInt(), ranges(i).End.ToInt(), Color.Red))
|
||||
Next i
|
||||
oRanges = document.FindAll(_quotedString).GetAsFrozen()
|
||||
For Each oRange In oRanges
|
||||
oTokens.Add(CreateToken(oRange.Start.ToInt, oRange.End.ToInt, Color.Red))
|
||||
Next
|
||||
|
||||
'Extract all keywords
|
||||
ranges = TryCast(document.FindAll(_keywords).GetAsFrozen(), DocumentRange())
|
||||
For j As Integer = 0 To ranges.Length - 1
|
||||
If Not IsRangeInTokens(ranges(j), tokens) Then
|
||||
tokens.Add(CreateToken(ranges(j).Start.ToInt(), ranges(j).End.ToInt(), Color.Blue))
|
||||
oRanges = TryCast(document.FindAll(_keywords).GetAsFrozen(), DocumentRange())
|
||||
For Each oRange In oRanges
|
||||
If Not IsRangeInTokens(oRange, oTokens) Then
|
||||
oTokens.Add(CreateToken(oRange.Start.ToInt(), oRange.End.ToInt(), Color.Blue))
|
||||
End If
|
||||
Next j
|
||||
Next
|
||||
|
||||
'Find all placeholders
|
||||
ranges = TryCast(document.FindAll(_placeholderString).GetAsFrozen(), DocumentRange())
|
||||
For j As Integer = 0 To ranges.Length - 1
|
||||
If Not IsRangeInTokens(ranges(j), tokens) Then
|
||||
tokens.Add(CreateToken(ranges(j).Start.ToInt(), ranges(j).End.ToInt(), Color.DarkTurquoise))
|
||||
oRanges = TryCast(document.FindAll(_placeholderString).GetAsFrozen(), DocumentRange())
|
||||
For Each oRange In oRanges
|
||||
If Not IsRangeInTokens(oRange, oTokens) Then
|
||||
oTokens.Add(CreateToken(oRange.Start.ToInt(), oRange.End.ToInt(), Color.DarkTurquoise))
|
||||
End If
|
||||
Next j
|
||||
Next
|
||||
|
||||
'Find all comments
|
||||
ranges = TryCast(document.FindAll(_commentedString).GetAsFrozen(), DocumentRange())
|
||||
For j As Integer = 0 To ranges.Length - 1
|
||||
If Not IsRangeInTokens(ranges(j), tokens) Then
|
||||
tokens.Add(CreateToken(ranges(j).Start.ToInt(), ranges(j).End.ToInt(), Color.Green))
|
||||
oRanges = TryCast(document.FindAll(_commentedString).GetAsFrozen(), DocumentRange())
|
||||
For Each oRange In oRanges
|
||||
If Not IsRangeInTokens(oRange, oTokens) Then
|
||||
oTokens.Add(CreateToken(oRange.Start.ToInt(), oRange.End.ToInt(), Color.Green))
|
||||
End If
|
||||
Next j
|
||||
Next
|
||||
|
||||
' order tokens by their start position
|
||||
tokens.Sort(New SyntaxHighlightTokenComparer())
|
||||
oTokens.Sort(New SyntaxHighlightTokenComparer())
|
||||
|
||||
' fill in gaps in document coverage
|
||||
tokens = CombineWithPlainTextTokens(tokens)
|
||||
Return tokens
|
||||
oTokens = CombineWithPlainTextTokens(oTokens)
|
||||
Return oTokens
|
||||
End Function
|
||||
|
||||
'Parse the remaining text into tokens:
|
||||
@ -129,8 +129,9 @@ Namespace SQLEditor
|
||||
|
||||
'Create a token from the retrieved range and specify its forecolor
|
||||
Private Function CreateToken(ByVal start As Integer, ByVal [end] As Integer, ByVal foreColor As Color) As SyntaxHighlightToken
|
||||
Dim properties As New SyntaxHighlightProperties()
|
||||
properties.ForeColor = foreColor
|
||||
Dim properties As New SyntaxHighlightProperties With {
|
||||
.ForeColor = foreColor
|
||||
}
|
||||
Return New SyntaxHighlightToken(start, [end] - start, properties)
|
||||
End Function
|
||||
|
||||
|
||||
20
GUIs.Common/frmSQLEditor.Designer.vb
generated
20
GUIs.Common/frmSQLEditor.Designer.vb
generated
@ -39,6 +39,7 @@ Partial Class frmSQLEditor
|
||||
Me.BarButtonItem3 = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.BarButtonItem4 = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.BarButtonItem5 = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.BarButtonItem6 = New DevExpress.XtraBars.BarButtonItem()
|
||||
Me.RibbonPage1 = New DevExpress.XtraBars.Ribbon.RibbonPage()
|
||||
Me.RibbonPageGroup3 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup()
|
||||
Me.RibbonPageGroup1 = New DevExpress.XtraBars.Ribbon.RibbonPageGroup()
|
||||
@ -50,7 +51,6 @@ Partial Class frmSQLEditor
|
||||
Me.ViewPlaceholders = New DevExpress.XtraGrid.Views.Grid.GridView()
|
||||
Me.colPattern = New DevExpress.XtraGrid.Columns.GridColumn()
|
||||
Me.colValue = New DevExpress.XtraGrid.Columns.GridColumn()
|
||||
Me.BarButtonItem6 = New DevExpress.XtraBars.BarButtonItem()
|
||||
CType(Me.RibbonControl1, System.ComponentModel.ISupportInitialize).BeginInit()
|
||||
CType(Me.SvgImageCollection1, System.ComponentModel.ISupportInitialize).BeginInit()
|
||||
CType(Me.SplitContainerControl1, System.ComponentModel.ISupportInitialize).BeginInit()
|
||||
@ -65,6 +65,7 @@ Partial Class frmSQLEditor
|
||||
'
|
||||
'RibbonControl1
|
||||
'
|
||||
Me.RibbonControl1.ColorScheme = DevExpress.XtraBars.Ribbon.RibbonControlColorScheme.Green
|
||||
Me.RibbonControl1.ExpandCollapseItem.Id = 0
|
||||
Me.RibbonControl1.Items.AddRange(New DevExpress.XtraBars.BarItem() {Me.RibbonControl1.ExpandCollapseItem, Me.RibbonControl1.SearchEditItem, Me.GalleryPlaceholders, Me.btnEditConnections, Me.btnSave, Me.btnExecuteSQL, Me.GalleryConnection, Me.chkClearPlaceholders, Me.btnClearPlaceholders, Me.chkShowPlaceholders, Me.BarButtonItem1, Me.BarButtonItem2, Me.BarButtonItem3, Me.BarButtonItem4, Me.BarButtonItem5, Me.BarButtonItem6})
|
||||
Me.RibbonControl1.Location = New System.Drawing.Point(0, 0)
|
||||
@ -183,6 +184,13 @@ Partial Class frmSQLEditor
|
||||
Me.BarButtonItem5.ImageOptions.SvgImage = Global.DigitalData.GUIs.Common.My.Resources.Resources.actions_database
|
||||
Me.BarButtonItem5.Name = "BarButtonItem5"
|
||||
'
|
||||
'BarButtonItem6
|
||||
'
|
||||
Me.BarButtonItem6.Caption = "Abbrechen"
|
||||
Me.BarButtonItem6.Id = 19
|
||||
Me.BarButtonItem6.ImageOptions.SvgImage = CType(resources.GetObject("BarButtonItem6.ImageOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage)
|
||||
Me.BarButtonItem6.Name = "BarButtonItem6"
|
||||
'
|
||||
'RibbonPage1
|
||||
'
|
||||
Me.RibbonPage1.Groups.AddRange(New DevExpress.XtraBars.Ribbon.RibbonPageGroup() {Me.RibbonPageGroup3, Me.RibbonPageGroup1})
|
||||
@ -225,6 +233,7 @@ Partial Class frmSQLEditor
|
||||
Me.txtSQLCommand.Location = New System.Drawing.Point(0, 0)
|
||||
Me.txtSQLCommand.MenuManager = Me.RibbonControl1
|
||||
Me.txtSQLCommand.Name = "txtSQLCommand"
|
||||
Me.txtSQLCommand.Options.CopyPaste.InsertOptions = DevExpress.XtraRichEdit.API.Native.InsertOptions.KeepTextOnly
|
||||
Me.txtSQLCommand.Size = New System.Drawing.Size(802, 508)
|
||||
Me.txtSQLCommand.TabIndex = 2
|
||||
'
|
||||
@ -250,7 +259,7 @@ Partial Class frmSQLEditor
|
||||
'
|
||||
'GridPlaceholders
|
||||
'
|
||||
Me.GridPlaceholders.Dock = System.Windows.Forms.DockStyle.Fill
|
||||
Me.GridPlaceholders.Anchor = System.Windows.Forms.AnchorStyles.Right
|
||||
Me.GridPlaceholders.Location = New System.Drawing.Point(0, 0)
|
||||
Me.GridPlaceholders.MainView = Me.ViewPlaceholders
|
||||
Me.GridPlaceholders.MenuManager = Me.RibbonControl1
|
||||
@ -283,13 +292,6 @@ Partial Class frmSQLEditor
|
||||
Me.colValue.Visible = True
|
||||
Me.colValue.VisibleIndex = 1
|
||||
'
|
||||
'BarButtonItem6
|
||||
'
|
||||
Me.BarButtonItem6.Caption = "Abbrechen"
|
||||
Me.BarButtonItem6.Id = 19
|
||||
Me.BarButtonItem6.ImageOptions.SvgImage = CType(resources.GetObject("BarButtonItem6.ImageOptions.SvgImage"), DevExpress.Utils.Svg.SvgImage)
|
||||
Me.BarButtonItem6.Name = "BarButtonItem6"
|
||||
'
|
||||
'frmSQLEditor
|
||||
'
|
||||
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
|
||||
|
||||
@ -136,4 +136,7 @@
|
||||
LDQgIGw0LTRsMywzbC00LDRMMjMsMjB6IiBjbGFzcz0iUmVkIiAvPg0KPC9zdmc+Cw==
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="SvgImageCollection1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@ -209,6 +209,7 @@ Public Class frmSQLEditor
|
||||
' noop
|
||||
Else
|
||||
Dim oPlaceholders = oPatterns.
|
||||
Distinct().
|
||||
Select(Function(pattern) New SQLEditor.Placeholder(pattern.Value, pattern.Value, pattern.Type, pattern.Value) With {.Pattern = pattern}).
|
||||
ToList()
|
||||
GridPlaceholders.DataSource = oPlaceholders
|
||||
@ -232,7 +233,6 @@ Public Class frmSQLEditor
|
||||
Throw New ApplicationException($"Der Platzhalter '{oWrapped}' wurde nicht ausgefüllt!")
|
||||
End If
|
||||
|
||||
|
||||
oSql = oSql.Replace(oWrapped, oPlaceholder.Value)
|
||||
Next
|
||||
End If
|
||||
|
||||
@ -10,4 +10,12 @@
|
||||
Public Overrides Function ToString() As String
|
||||
Return $"{{#{Type}#{Value}}}"
|
||||
End Function
|
||||
|
||||
Public Overrides Function GetHashCode() As Integer
|
||||
Return (Value.GetHashCode & Type.GetHashCode).GetHashCode
|
||||
End Function
|
||||
|
||||
Public Overrides Function Equals(obj As Object) As Boolean
|
||||
Return Me.GetHashCode = DirectCast(obj, Pattern).GetHashCode
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user