Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to determine if a database view exists. Closes #5.
Add support for SQL Server, MySQL and HyperSQL via the SQLViewExists class.
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
' ___________________________________________________ | ||
' | ||
' © Hi-Integrity Systems 2012. All rights reserved. | ||
' www.hisystems.com.au - Toby Wicks | ||
' ___________________________________________________ | ||
' | ||
|
||
Option Strict On | ||
Option Explicit On | ||
|
||
Namespace SQL | ||
|
||
''' -------------------------------------------------------------------------------- | ||
''' <summary> | ||
''' This class can be used to determine whether a view exists. This class can be | ||
''' used will all databases. If after running the SQL statement the data set is not | ||
''' empty then the view exists. | ||
''' </summary> | ||
''' -------------------------------------------------------------------------------- | ||
Public Class SQLViewExists | ||
Inherits SQLStatement | ||
|
||
Private pstrViewName As String | ||
|
||
Public Sub New(ByVal strViewName As String) | ||
|
||
If String.IsNullOrEmpty(strViewName) Then | ||
Throw New ArgumentNullException | ||
End If | ||
|
||
pstrViewName = strViewName | ||
|
||
End Sub | ||
|
||
Public Overrides ReadOnly Property SQL() As String | ||
Get | ||
|
||
Dim strSQL As String = String.Empty | ||
Dim objSelect As SQLSelect | ||
|
||
Select Case Me.ConnectionType | ||
Case Database.ConnectionType.MicrosoftAccess | ||
Throw New NotSupportedException | ||
Case Database.ConnectionType.MySQL | ||
strSQL = "SHOW VIEWS LIKE " & SQLConvertValue(pstrViewName, Me.ConnectionType) | ||
Case Database.ConnectionType.SQLServer | ||
objSelect = New SQLSelect | ||
With objSelect | ||
.ConnectionType = Me.ConnectionType | ||
.Tables.Add("sysobjects") | ||
.Where.Add("Name", ComparisonOperator.EqualTo, pstrViewName) | ||
.Where.Add("XType", ComparisonOperator.EqualTo, "V") 'V = User defined view | ||
strSQL = .SQL | ||
End With | ||
Case Database.ConnectionType.Pervasive | ||
Throw New NotSupportedException | ||
Case Database.ConnectionType.HyperSQL | ||
objSelect = New SQLSelect | ||
With objSelect | ||
.ConnectionType = Me.ConnectionType | ||
.Tables.Add("VIEWS").SchemaName = "INFORMATION_SCHEMA" | ||
.Where.Add("TABLE_SCHEMA", ComparisonOperator.EqualTo, "PUBLIC") | ||
.Where.Add("TABLE_NAME", ComparisonOperator.EqualTo, pstrViewName) | ||
strSQL = .SQL | ||
End With | ||
Case Database.ConnectionType.SQLServerCompactEdition | ||
Throw New NotSupportedException | ||
Case Else | ||
Throw New NotImplementedException(Me.ConnectionType.ToString) | ||
End Select | ||
|
||
Return strSQL | ||
|
||
End Get | ||
End Property | ||
|
||
End Class | ||
|
||
End Namespace |