' ___________________________________________________
'
' � Hi-Integrity Systems 2007. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'
Option Strict On
Option Explicit On
Namespace SQL
Public Class SQLCondition
Private pobjValue As Object
Private pstrFieldName As String
Private peCompare As ComparisonOperator
Private pobjTable As SQLSelectTable
Friend Sub New()
End Sub
Public Sub New( _
ByVal strFieldName As String, _
ByVal eCompare As ComparisonOperator, _
ByVal objValue As Object)
Me.FieldName = strFieldName
Me.Compare = eCompare
pobjValue = objValue
End Sub
Public Property Table() As SQLSelectTable
Get
Return pobjTable
End Get
Set(ByVal Value As SQLSelectTable)
pobjTable = Value
End Set
End Property
Public Property FieldName() As String
Get
Return pstrFieldName
End Get
Set(ByVal Value As String)
pstrFieldName = Value
End Set
End Property
Public Property Compare() As ComparisonOperator
Get
Return peCompare
End Get
Set(ByVal Value As ComparisonOperator)
peCompare = Value
End Set
End Property
Public Property Value() As Object
Get
Value = pobjValue
End Get
Set(ByVal Value As Object)
pobjValue = SQLConditionValue(Value)
End Set
End Property
Friend ReadOnly Property SQL(ByVal eConnectionType As Database.ConnectionType) As String
Get
CompareValuePairAssertValid(Me.Compare, pobjValue)
Return Condition(Me.Table, Me.FieldName, Me.Compare, Me.Value, eConnectionType)
End Get
End Property
Private Function Condition( _
ByVal objTable As SQLSelectTable, _
ByVal strFieldName As String, _
ByVal eCompare As ComparisonOperator, _
ByVal objValue As Object, _
ByVal eConnectionType As Database.ConnectionType) As String
Dim strSQL As String = SQLFieldNameAndTablePrefix(objTable, strFieldName, eConnectionType) & " "
SQLConvertBooleanValue(objValue, eCompare)
'return 'IS NULL' rather than '= NULL'
If SQLValueIsNull(objValue) Then
If eCompare = ComparisonOperator.EqualTo Then
strSQL &= "IS " & SQLConvertValue(objValue, eConnectionType)
ElseIf eCompare = ComparisonOperator.NotEqualTo Then
strSQL &= "IS NOT " & SQLConvertValue(objValue, eConnectionType)
Else
Throw New DatabaseObjectsException("DBNull or Nothing specified as an SQLCondition value using the " & eCompare.ToString & " operator")
End If
Else
strSQL &= _
SQLConvertCompare(eCompare) & " " & _
SQLConvertValue(objValue, eConnectionType)
End If
Return strSQL
End Function
End Class
End Namespace