|
' ___________________________________________________
'
' � Hi-Integrity Systems 2007. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'
Option Strict On
Option Explicit On
Namespace SQL
Public Class SQLSelect
Inherits SQLStatement
Private pobjFields As SQLSelectFields = New SQLSelectFields
Private pobjTables As SQLSelectTables = New SQLSelectTables
Private pobjConditions As SQLConditions = New SQLConditions
Private pobjOrderByFields As SQLSelectOrderByFields = New SQLSelectOrderByFields
Private pobjGroupByFields As SQLSelectGroupByFields = New SQLSelectGroupByFields
Private pbDistinct As Boolean = False
Private pintTop As Integer
Public Sub New()
End Sub
Public Sub New(ByVal strTableName As String)
pobjTables.Add(strTableName)
End Sub
Public Sub New(ByVal strTableName As String, ByVal objWhereCondition As SQLCondition)
Me.Tables.Add(strTableName)
Me.Where.Add(objWhereCondition)
End Sub
Public Property Distinct() As Boolean
Get
Return pbDistinct
End Get
Set(ByVal Value As Boolean)
pbDistinct = Value
End Set
End Property
Public Property Top() As Integer
Get
Return pintTop
End Get
Set(ByVal Value As Integer)
If Value <= 0 Then
Throw New ArgumentException
End If
pintTop = Value
End Set
End Property
Public Property Tables() As SQLSelectTables
Get
Return pobjTables
End Get
Set(ByVal Value As SQLSelectTables)
If Value Is Nothing Then
Throw New ArgumentNullException
Else
pobjTables = Value
End If
End Set
End Property
Public Property Fields() As SQLSelectFields
Get
Return pobjFields
End Get
Set(ByVal Value As SQLSelectFields)
If Value Is Nothing Then
Throw New ArgumentNullException
End If
pobjFields = Value
End Set
End Property
Public Property Where() As SQLConditions
Get
Return pobjConditions
End Get
Set(ByVal Value As SQLConditions)
pobjConditions = Value
End Set
End Property
Public Property OrderBy() As SQLSelectOrderByFields
Get
Return pobjOrderByFields
End Get
Set(ByVal Value As SQLSelectOrderByFields)
pobjOrderByFields = Value
End Set
End Property
Public Property GroupBy() As SQLSelectGroupByFields
Get
Return pobjGroupByFields
End Get
Set(ByVal Value As SQLSelectGroupByFields)
pobjGroupByFields = Value
End Set
End Property
Public Overrides ReadOnly Property SQL() As String
Get
Dim strSQL As String
If pobjTables.Count = 0 Then
Throw New DatabaseObjectsException("The table has not been set.")
End If
strSQL = _
"SELECT " & DistinctClause() & TopClause() & pobjFields.SQL(Me.ConnectionType) & _
" FROM " & pobjTables.SQL(Me.ConnectionType)
If Not pobjConditions Is Nothing Then
Dim strConditions As String = pobjConditions.SQL(Me.ConnectionType)
If strConditions <> Nothing Then
strSQL &= " WHERE " & strConditions
End If
End If
If Not pobjGroupByFields Is Nothing Then
Dim strGroupBy As String = pobjGroupByFields.SQL(Me.ConnectionType)
If strGroupBy <> Nothing Then
strSQL &= " GROUP BY " & strGroupBy
End If
End If
If Not pobjOrderByFields Is Nothing Then
Dim strOrderBy As String = pobjOrderByFields.SQL(Me.ConnectionType)
If strOrderBy <> Nothing Then
strSQL &= " ORDER BY " & strOrderBy
End If
End If
Return strSQL
End Get
End Property
Private Function TopClause() As String
If pintTop > 0 Then
Return "TOP " & pintTop & " "
Else
Return String.Empty
End If
End Function
Private Function DistinctClause() As String
If pbDistinct Then
Return "DISTINCT "
Else
Return String.Empty
End If
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.
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.