Click here to Skip to main content
15,881,413 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.3K   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 SQLSelectTableJoinConditions
        Implements IEnumerable

        Private pobjLogicalOperators As ArrayList = New ArrayList
        Private pobjConditions As ArrayList = New ArrayList
        Private pobjParent As SQLSelectTableJoin

        Friend Sub New(ByVal objParent As SQLSelectTableJoin)

            MyBase.New()
            pobjParent = objParent

        End Sub

        Friend ReadOnly Property Parent() As SQLSelectTableJoin
            Get

                Return pobjParent

            End Get
        End Property

        Public Function Add() As SQLSelectTableJoinCondition

            Return Add("", ComparisonOperator.EqualTo, "")

        End Function

        Public Function Add( _
            ByVal strLeftTableFieldName As String, _
            ByVal eCompare As ComparisonOperator, _
            ByVal strRightTableFieldName As String) As SQLSelectTableJoinCondition

            'Add the AND operator if an operator hasn't been called after the previous Add call
            If pobjLogicalOperators.Count() < pobjConditions.Count() Then
                Me.AddLogicalOperator(LogicalOperator.And)
            End If

            If eCompare = ComparisonOperator.Like Or eCompare = ComparisonOperator.NotLike Then
                Throw New DatabaseObjectsException("LIKE operator is not supported for table joins.")
            End If

            Add = New SQLSelectTableJoinCondition(Me)

            Add.LeftTableFieldName = strLeftTableFieldName
            Add.Compare = eCompare
            Add.RightTableFieldName = strRightTableFieldName

            pobjConditions.Add(Add)

        End Function

        Public Function AddLogicalOperator( _
            ByVal eLogicalOperator As LogicalOperator) As Object

            If pobjLogicalOperators.Count() + 1 > pobjConditions.Count() Then
                Throw New DatabaseObjectsException("First call the Add function - this function has been called without a prior call to Add")
            End If

            pobjLogicalOperators.Add(eLogicalOperator)

        End Function

        Default Public ReadOnly Property Item(ByVal intIndex As Integer) As SQLSelectTableJoinCondition
            Get

                Return DirectCast(pobjConditions.Item(intIndex), SQLSelectTableJoinCondition)

            End Get
        End Property

        Public ReadOnly Property Count() As Integer
            Get

                Return pobjConditions.Count()

            End Get
        End Property

        Public Sub Delete(ByRef objOrderByField As SQLSelectOrderByField)

            If Not pobjConditions.Contains(objOrderByField) Then
                Throw New ObjectDoesNotExistException
            End If

            pobjConditions.Remove(objOrderByField)
            objOrderByField = Nothing

        End Sub

        Friend ReadOnly Property SQL(ByVal eConnectionType As Database.ConnectionType) As String
            Get

                Dim objCondition As SQLSelectTableJoinCondition
                Dim strSQL As String

                With pobjConditions
                    For intIndex As Integer = 0 To .Count() - 1
                        If intIndex > 0 Then
                            strSQL &= " " & SQLConvertLogicalOperator(DirectCast(pobjLogicalOperators.Item(intIndex - 1), LogicalOperator)) & " "
                        End If

                        objCondition = DirectCast(.Item(intIndex), SQLSelectTableJoinCondition)
                        strSQL &= objCondition.SQL(eConnectionType)
                    Next
                End With

                Return strSQL

            End Get
        End Property

        Private Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator

            Return pobjConditions.GetEnumerator

        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