Skip to content

Commit

Permalink
Added ability to create database views. Closes #3.
Browse files Browse the repository at this point in the history
Use the SQLCreateView class to generate a CREATE VIEW statement.
  • Loading branch information
hisystems committed Mar 5, 2012
1 parent 6c6eac6 commit df35b3e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions DatabaseObjects.vbproj
Expand Up @@ -325,6 +325,7 @@
<Compile Include="Contraints\ObjectIsSetConstraint.vb" />
<Compile Include="Contraints\StringIsSetConstraint.vb" />
<Compile Include="Contraints\IConstraint.vb" />
<Compile Include="SQL\Views\SQLCreateView.vb" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
Expand Down
85 changes: 85 additions & 0 deletions SQL/Views/SQLCreateView.vb
@@ -0,0 +1,85 @@
' ___________________________________________________
'
' © Hi-Integrity Systems 2012. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'

Option Strict On
Option Explicit On

Namespace SQL

Public Class SQLCreateView
Inherits SQLStatement

Private pstrName As String
Private pobjSelect As SQLSelect

Public Sub New()

End Sub

Public Sub New(ByVal strViewName As String, ByVal objSelectStatement As SQLSelect)

Me.Name = strViewName
Me.Select = objSelectStatement

End Sub

Public Property Name() As String
Get

Return pstrName

End Get

Set(ByVal Value As String)

If String.IsNullOrEmpty(Value) Then
Throw New ArgumentNullException()
End If

pstrName = Value

End Set
End Property

Public Property [Select] As SQLSelect
Get

Return pobjSelect

End Get

Set(value As SQLSelect)

If value Is Nothing Then
Throw New ArgumentNullException
End If

pobjSelect = value

End Set
End Property

Public Overrides ReadOnly Property SQL() As String
Get

If String.IsNullOrEmpty(Me.Name) Then
Throw New Exceptions.DatabaseObjectsException("View name has not been set")
ElseIf pobjSelect Is Nothing Then
Throw New Exceptions.DatabaseObjectsException("Select statement has not been set")
End If

Return _
"CREATE VIEW " & _
SQLConvertIdentifierName(Me.Name, Me.ConnectionType) & " AS " & _
pobjSelect.SQL

End Get
End Property

End Class

End Namespace

0 comments on commit df35b3e

Please sign in to comment.