Skip to content

Commit

Permalink
Added support for SQL length string function. Closes #25.
Browse files Browse the repository at this point in the history
Added support for SQL Server, MySQL and Access regarding the length string function.
  • Loading branch information
hisystems committed Mar 5, 2012
1 parent de3d660 commit d5dd0fc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions DatabaseObjects.vbproj
Expand Up @@ -194,6 +194,7 @@
<Compile Include="SQL\Expressions\SQLFunctionExpression.vb" />
<Compile Include="SQL\Expressions\SQLGetDateFunctionExpression.vb" />
<Compile Include="SQL\Expressions\SQLLeftExpression.vb" />
<Compile Include="SQL\Expressions\SQLLengthFunctionExpression.vb" />
<Compile Include="SQL\Select\SQLSelectHavingCondition.vb" />
<Compile Include="SQL\Select\SQLSelectHavingConditions.vb" />
<Compile Include="SQL\Select\SQLConditionExpression.vb" />
Expand Down
29 changes: 28 additions & 1 deletion SQL/Expressions/SQLFunctionExpression.vb
Expand Up @@ -38,11 +38,38 @@ Namespace SQL
Public Sub New(strFunctionName As String, ParamArray arguments() As SQLExpression)

Me.New(strFunctionName)
InitializeArguments(arguments)

End Sub

''' <summary>
''' Used when the arguments are known but the function name is dependant on the connection type.
''' Typically, in this scenario the FunctionName() will be overridden.
''' </summary>
''' <param name="arguments"></param>
''' <remarks></remarks>
Protected Sub New(ParamArray arguments() As SQLExpression)

InitializeArguments(arguments)

End Sub

Private Sub InitializeArguments(ParamArray arguments() As SQLExpression)

If arguments.Any(Function(item) item Is Nothing) Then
Throw New ArgumentNullException
End If

pobjFunctionArguments = arguments

End Sub

Protected Overridable Function FunctionName(ByVal eConnectionType As Database.ConnectionType) As String

Return pstrFunctionName

End Function

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

Dim strArguments As String = String.Empty
Expand All @@ -51,7 +78,7 @@ Namespace SQL
strArguments = String.Join(", ", pobjFunctionArguments.Select(Function(argument) argument.SQL(eConnectionType)).ToArray)
End If

Return pstrFunctionName & "(" & strArguments & ")"
Return Me.FunctionName(eConnectionType) & "(" & strArguments & ")"

End Function

Expand Down
43 changes: 43 additions & 0 deletions SQL/Expressions/SQLLengthFunctionExpression.vb
@@ -0,0 +1,43 @@

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

Option Strict On
Option Explicit On

Namespace SQL

''' <summary>
''' SQL function that returns the length of a string.
''' </summary>
Public Class SQLLengthFunctionExpression
Inherits SQLFunctionExpression

Public Sub New(objExpression As SQLExpression)

MyBase.New(objExpression)

End Sub

Protected Overrides Function FunctionName(ByVal eConnectionType As Database.ConnectionType) As String

Select Case eConnectionType
Case Database.ConnectionType.MySQL
Return "LENGTH"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.MicrosoftAccess
Return "LEN"
Case Else
Throw New NotImplementedException(eConnectionType.ToString)
End Select

Return MyBase.FunctionName(eConnectionType)

End Function

End Class

End Namespace

0 comments on commit d5dd0fc

Please sign in to comment.