Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / Visual Basic

Object-Oriented database design with the DatabaseObjects library

Rate me:
Please Sign up or sign in to vote.
4.00/5 (6 votes)
31 Jan 20076 min read 109.6K   3.9K   64  
Demonstrates creating object-oriented database systems with the DatabaseObjects library.
' ___________________________________________________
'
'  � 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

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions