3 Commits

Author SHA1 Message Date
Jonathan Jenne
9d51074991 EDMIAPI: Add InitializeIDB function 2022-01-18 15:44:38 +01:00
Jonathan Jenne
cbb343bb17 EDMIService: Allow empty return values for GetScalarValue 2022-01-18 15:26:51 +01:00
Jonathan Jenne
a29f058d58 EDMIService: fix wrong return type of getscalarvaluemethod 2022-01-18 15:25:12 +01:00
2 changed files with 19 additions and 10 deletions

View File

@@ -10,7 +10,7 @@ Public Class DatabaseWithFallback
Private ReadOnly _Client As Client Private ReadOnly _Client As Client
Private ReadOnly _ClientConfig As ConfigClientConfiguration Private ReadOnly _ClientConfig As ConfigClientConfiguration
Private ReadOnly _DatabaseECM As MSSQLServer Private ReadOnly _DatabaseECM As MSSQLServer
Private ReadOnly _DatabaseIDB As MSSQLServer Private _DatabaseIDB As MSSQLServer
''' <summary> ''' <summary>
''' Options for GetDatatable ''' Options for GetDatatable
@@ -57,6 +57,14 @@ Public Class DatabaseWithFallback
_ClientConfig = Client.TryGetClientConfig() _ClientConfig = Client.TryGetClientConfig()
End Sub End Sub
''' <summary>
''' Set the IDB Database class after initializing the class.
''' It is now your responsibility to make sure to not use any IDB calls before calling this method.
''' </summary>
Public Sub InitializeIDB(pDatabaseIDB As MSSQLServer)
_DatabaseIDB = pDatabaseIDB
End Sub
Public Function GetDatatableECM(pSQL As String, Optional pConnectionId As Integer = 0) As DataTable Public Function GetDatatableECM(pSQL As String, Optional pConnectionId As Integer = 0) As DataTable
Return GetDatatable(New GetDatatableOptions(pSQL, Constants.DatabaseType.ECM) With { Return GetDatatable(New GetDatatableOptions(pSQL, Constants.DatabaseType.ECM) With {
.ConnectionId = pConnectionId .ConnectionId = pConnectionId

View File

@@ -17,18 +17,18 @@ Namespace Methods.Database.GetScalarValue
''' </summary> ''' </summary>
Public Function Run(pData As GetScalarValueRequest) As GetScalarValueResponse Public Function Run(pData As GetScalarValueRequest) As GetScalarValueResponse
Try Try
Dim oDatatable As DataTable = Nothing Dim oResult As Object = Nothing
Select Case pData.DatabaseType Select Case pData.DatabaseType
Case DatabaseType.MSSQL Case DatabaseType.MSSQL
If pData.NamedDatabase = DatabaseName.None Then If pData.NamedDatabase = DatabaseName.None Then
oDatatable = GetScalarValueByConnectionId(pData.SqlCommand, pData.ConnectionId) oResult = GetScalarValueByConnectionId(pData.SqlCommand, pData.ConnectionId)
ElseIf pData.NamedDatabase = DatabaseName.ECM Then ElseIf pData.NamedDatabase = DatabaseName.ECM Then
oDatatable = DatabaseECM.GetScalarValue(pData.SqlCommand) oResult = DatabaseECM.GetScalarValue(pData.SqlCommand)
ElseIf pData.NamedDatabase = DatabaseName.IDB Then ElseIf pData.NamedDatabase = DatabaseName.IDB Then
oDatatable = DatabaseIDB.GetScalarValue(pData.SqlCommand) oResult = DatabaseIDB.GetScalarValue(pData.SqlCommand)
Else Else
LogAndThrow($"Unsupported Named Database supplied. SQL Command [{pData.SqlCommand}] was not executed!") LogAndThrow($"Unsupported Named Database supplied. SQL Command [{pData.SqlCommand}] was not executed!")
@@ -40,11 +40,12 @@ Namespace Methods.Database.GetScalarValue
End Select End Select
If oDatatable Is Nothing Then ' Remove this in the future, empty return values for scalar should be allowed
LogAndThrow($"SQL Command did not return any results: [{pData.SqlCommand}]!") 'If oResult Is Nothing Then
End If ' LogAndThrow($"SQL Command did not return any results: [{pData.SqlCommand}]!")
'End If
Return New GetScalarValueResponse(oDatatable) Return New GetScalarValueResponse(oResult)
Catch ex As Exception Catch ex As Exception
Logger.Warn("Error occurred while getting database scalar value!") Logger.Warn("Error occurred while getting database scalar value!")
Logger.Error(ex) Logger.Error(ex)
@@ -52,7 +53,7 @@ Namespace Methods.Database.GetScalarValue
End Try End Try
End Function End Function
Private Function GetScalarValueByConnectionId(pSQLCommand As String, pConnectionId As Integer) As DataTable Private Function GetScalarValueByConnectionId(pSQLCommand As String, pConnectionId As Integer) As Object
If pConnectionId = 0 Then If pConnectionId = 0 Then
Return DatabaseECM.GetScalarValue(pSQLCommand) Return DatabaseECM.GetScalarValue(pSQLCommand)
Else Else