Skip to content

Commit

Permalink
Add support for running TSQL or non database-agnostic SQL functions. C…
Browse files Browse the repository at this point in the history
…loses #2.
  • Loading branch information
hisystems committed Mar 4, 2012
1 parent 6f65497 commit b32b0ee
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions DatabaseObjects.vbproj
Expand Up @@ -191,6 +191,7 @@
<Compile Include="SQL\Expressions\SQLExpression.vb" />
<Compile Include="SQL\Expressions\SQLFieldAggregateExpression.vb" />
<Compile Include="SQL\Expressions\SQLFieldExpression.vb" />
<Compile Include="SQL\Expressions\SQLFunctionExpression.vb" />
<Compile Include="SQL\Expressions\SQLGetDateFunctionExpression.vb" />
<Compile Include="SQL\Expressions\SQLLeftExpression.vb" />
<Compile Include="SQL\Select\SQLSelectHavingCondition.vb" />
Expand Down
60 changes: 60 additions & 0 deletions SQL/Expressions/SQLFunctionExpression.vb
@@ -0,0 +1,60 @@

' ___________________________________________________
'
' © Hi-Integrity Systems 2010. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'

Option Strict On
Option Explicit On

Imports System.Linq

Namespace SQL

''' <summary>
''' Allows an SQL function to utilised in a WHERE clause or as a calculated column.
''' </summary>
''' <remarks>
''' Typically used to access a non database-agnostic function.
''' </remarks>
Public Class SQLFunctionExpression
Inherits SQLExpression

Private pstrFunctionName As String
Private pobjFunctionArguments As SQLExpression()

Public Sub New(strFunctionName As String)

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

pstrFunctionName = strFunctionName

End Sub

Public Sub New(strFunctionName As String, ParamArray arguments() As SQLExpression)

Me.New(strFunctionName)

pobjFunctionArguments = arguments

End Sub

Friend Overrides Function SQL(ByVal eConnectionType As Database.ConnectionType) As String

Dim strArguments As String = String.Empty

If pobjFunctionArguments IsNot Nothing Then
strArguments = String.Join(", ", pobjFunctionArguments.Select(Function(argument) argument.SQL(eConnectionType)).ToArray)
End If

Return pstrFunctionName & "(" & strArguments & ")"

End Function

End Class

End Namespace

0 comments on commit b32b0ee

Please sign in to comment.