Click here to Skip to main content
15,892,161 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 110.2K   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 SQLFieldValues
        Implements IEnumerable

        Private pobjFields As ArrayList = New ArrayList

        Public Sub New()

            MyBase.New()

        End Sub

        Public Function Add() As SQLFieldValue

            Return Add("", Nothing)

        End Function

        Public Function Add(ByVal objFieldAndValue As SQLFieldValue) As SQLFieldValue

            Return Add(objFieldAndValue.Name, objFieldAndValue.Value)

        End Function

        Public Function Add( _
            ByVal strName As String, _
            ByVal objEqualToValue As Object) As SQLFieldValue

            Dim objSQLFieldValue As New SQLFieldValue(strName, objEqualToValue)

            pobjFields.Add(objSQLFieldValue)

            Return objSQLFieldValue

        End Function

        Public Sub Add(ByVal objFieldValues As SQLFieldValues)

            For Each objFieldValue As SQLFieldValue In objFieldValues
                Me.Add(objFieldValue)
            Next

        End Sub

        Default Public ReadOnly Property Item(ByVal strFieldName As String) As SQLFieldValue
            Get

                Return DirectCast(pobjFields.Item(FieldNameIndex(strFieldName)), SQLFieldValue)

            End Get
        End Property

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

                Return DirectCast(pobjFields.Item(intIndex), SQLFieldValue)

            End Get
        End Property

        Public ReadOnly Property Count() As Integer
            Get

                Return pobjFields.Count()

            End Get
        End Property

        Public Function Exists(ByVal strFieldName As String) As Boolean

            Return FieldNameIndex(strFieldName) >= 0

        End Function

        Public Sub Delete(ByRef objFieldValue As SQLFieldValue)

            If Not pobjFields.Contains(objFieldValue) Then
                Throw New ObjectDoesNotExistException
            End If

            pobjFields.Remove(objFieldValue)
            objFieldValue = Nothing

        End Sub

        Friend Function FieldNameIndex(ByVal strFieldName As String) As Integer

            Dim objSQLFieldValue As SQLFieldValue

            strFieldName = strFieldName.Trim()

            For intIndex As Integer = 0 To Me.Count - 1
                objSQLFieldValue = DirectCast(pobjFields.Item(intIndex), SQLFieldValue)
                If String.Compare(strFieldName, objSQLFieldValue.Name, ignoreCase:=True) = 0 Then
                    Return intIndex
                End If
            Next

            Return -1

        End Function

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

            Return pobjFields.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