Skip to content

Commit

Permalink
Added ability to perform bitwise operations in SQL. Closes #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
hisystems committed Mar 3, 2012
1 parent ef93210 commit c9cf306
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions DatabaseObjects.vbproj
Expand Up @@ -186,6 +186,7 @@
<Compile Include="SQL\Amend\SQLInsertFromSelect.vb" />
<Compile Include="SQL\Amend\SQLUpdateField.vb" />
<Compile Include="SQL\Expressions\SQLArithmeticExpression.vb" />
<Compile Include="SQL\Expressions\SQLBitwiseExpression.vb" />
<Compile Include="SQL\Expressions\SQLCastFieldExpression.vb" />
<Compile Include="SQL\Expressions\SQLExpression.vb" />
<Compile Include="SQL\Expressions\SQLFieldAggregateExpression.vb" />
Expand Down
128 changes: 128 additions & 0 deletions SQL/Expressions/SQLBitwiseExpression.vb
@@ -0,0 +1,128 @@

' ___________________________________________________
'
' © Hi-Integrity Systems 2012. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'

Option Strict On
Option Explicit On


Namespace SQL

Public Enum BitwiseOperator
[And]
[Or]
End Enum

Public Class SQLBitwiseExpression
Inherits SQLExpression

Private pobjLeft As SQLExpression
Private peOperator As BitwiseOperator
Private pobjRight As SQLExpression

Public Sub New()

End Sub

Public Sub New(ByVal strLeftFieldName As String, ByVal eOperator As BitwiseOperator, ByVal objRightValue As Object)

Me.New(New SQLFieldExpression(strLeftFieldName), eOperator, New SQLValueExpression(objRightValue))

End Sub

Public Sub New(ByVal strLeftFieldName As String, ByVal eOperator As BitwiseOperator, ByVal objRightExpression As SQLExpression)

Me.New(New SQLFieldExpression(strLeftFieldName), eOperator, objRightExpression)

End Sub

Public Sub New(ByVal objLeftExpression As SQLExpression, ByVal eOperator As BitwiseOperator, ByVal objRightExpression As SQLExpression)

pobjLeft = objLeftExpression
peOperator = eOperator
pobjRight = objRightExpression

End Sub

Public Property LeftExpression() As SQLExpression
Get

Return pobjLeft

End Get

Set(ByVal value As SQLExpression)

If value Is Nothing Then
Throw New ArgumentNullException
End If

pobjLeft = value

End Set
End Property

Public Property RightExpression() As SQLExpression
Get

Return pobjRight

End Get

Set(ByVal value As SQLExpression)

If value Is Nothing Then
Throw New ArgumentNullException
End If

pobjRight = value

End Set
End Property

Public Property [Operator]() As BitwiseOperator
Get

Return peOperator

End Get

Set(ByVal value As BitwiseOperator)

peOperator = value

End Set
End Property

Friend Overrides Function SQL(ByVal eConnectionType As Database.ConnectionType) As String

If pobjLeft Is Nothing Then
Throw New ArgumentNullException(Me.GetType.Name & ".LeftExpression")
ElseIf pobjRight Is Nothing Then
Throw New ArgumentNullException(Me.GetType.Name & ".RightExpression")
End If

Return "(" & pobjLeft.SQL(eConnectionType) & " " & OperatorString(peOperator) & " " & pobjRight.SQL(eConnectionType) & ")"

End Function

Private Function OperatorString(ByVal eOperator As SQL.BitwiseOperator) As String

Select Case eOperator
Case BitwiseOperator.And
Return "&"
Case BitwiseOperator.Or
Return "|"
Case Else
Throw New NotSupportedException(GetType(SQL.BitwiseOperator).Name)
End Select

End Function

End Class

End Namespace

0 comments on commit c9cf306

Please sign in to comment.