From df35b3e6771835bbd597016fc832c39d66135484 Mon Sep 17 00:00:00 2001 From: Toby Wicks Date: Mon, 5 Mar 2012 20:37:41 +1030 Subject: [PATCH] Added ability to create database views. Closes #3. Use the SQLCreateView class to generate a CREATE VIEW statement. --- DatabaseObjects.vbproj | 1 + SQL/Views/SQLCreateView.vb | 85 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 SQL/Views/SQLCreateView.vb diff --git a/DatabaseObjects.vbproj b/DatabaseObjects.vbproj index 44d55b5..ea1414d 100755 --- a/DatabaseObjects.vbproj +++ b/DatabaseObjects.vbproj @@ -325,6 +325,7 @@ + diff --git a/SQL/Views/SQLCreateView.vb b/SQL/Views/SQLCreateView.vb new file mode 100644 index 0000000..e582316 --- /dev/null +++ b/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