jj
This commit is contained in:
@@ -56,6 +56,7 @@ Public Class Firebird
|
||||
|
||||
Public Enum TransactionMode
|
||||
NoTransaction
|
||||
ExternalTransaction
|
||||
WithTransaction
|
||||
End Enum
|
||||
|
||||
@@ -138,18 +139,18 @@ Public Class Firebird
|
||||
}.ToString()
|
||||
End Function
|
||||
|
||||
Private Function MaybeGetTransaction(Connection As FbConnection, Mode As TransactionMode)
|
||||
Private Function MaybeGetTransaction(Connection As FbConnection, Mode As TransactionMode, Transaction As FbTransaction)
|
||||
If Mode = TransactionMode.NoTransaction Then
|
||||
Return Nothing
|
||||
ElseIf TransactionMode.WithTransaction Then
|
||||
Return Connection.BeginTransaction()
|
||||
ElseIf Mode = TransactionMode.ExternalTransaction Then
|
||||
Return Transaction
|
||||
Else
|
||||
Return Connection.BeginTransaction()
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function MaybeCommitTransaction(Transaction As FbTransaction)
|
||||
If IsNothing(Transaction) Then
|
||||
Private Function MaybeCommitTransaction(Transaction As FbTransaction, TransactionMode As TransactionMode)
|
||||
If TransactionMode = TransactionMode.NoTransaction Then
|
||||
Return True
|
||||
Else
|
||||
Try
|
||||
@@ -168,27 +169,31 @@ Public Class Firebird
|
||||
''' <param name="SqlCommand">The command to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
|
||||
Public Function ExecuteNonQueryWithConnection(SqlCommand As String, Connection As FbConnection) As Boolean
|
||||
Public Function ExecuteNonQueryWithConnection(SqlCommand As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction, Optional Transaction As FbTransaction = Nothing) As Boolean
|
||||
_logger.Debug("Executing Non-Query: {0}", SqlCommand)
|
||||
|
||||
If Connection Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTransaction As FbTransaction = Connection.BeginTransaction()
|
||||
Dim oTransaction = MaybeGetTransaction(Connection, TransactionMode, Transaction)
|
||||
|
||||
Try
|
||||
Dim oCommand As New FbCommand With {
|
||||
.CommandText = SqlCommand,
|
||||
.Connection = Connection,
|
||||
.Transaction = oTransaction
|
||||
.Connection = Connection
|
||||
}
|
||||
|
||||
If Not IsNothing(oTransaction) Then
|
||||
oCommand.Transaction = oTransaction
|
||||
End If
|
||||
|
||||
oCommand.ExecuteNonQuery()
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex, $"Error in ExecuteNonQuery while executing command: '{SqlCommand}'")
|
||||
Throw ex
|
||||
Finally
|
||||
oTransaction.Commit()
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
|
||||
Return True
|
||||
@@ -213,14 +218,14 @@ Public Class Firebird
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>The scalar value if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetScalarValueWithConnection(SqlQuery As String, Connection As FbConnection) As Object
|
||||
Public Function GetScalarValueWithConnection(SqlQuery As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction, Optional Transaction As FbTransaction = Nothing) As Object
|
||||
_logger.Debug("Fetching Scalar-Value: {0}", SqlQuery)
|
||||
|
||||
If Connection Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTransaction As FbTransaction = Connection.BeginTransaction()
|
||||
Dim oTransaction = MaybeGetTransaction(Connection, TransactionMode, Transaction)
|
||||
Dim oResult As Object
|
||||
|
||||
Try
|
||||
@@ -234,7 +239,7 @@ Public Class Firebird
|
||||
_logger.Error(ex, $"Error in ReturnScalar while executing command: '{SqlQuery}'")
|
||||
Throw ex
|
||||
Finally
|
||||
oTransaction.Commit()
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
|
||||
Return oResult
|
||||
@@ -259,14 +264,14 @@ Public Class Firebird
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <param name="Connection">The Firebird connection to use</param>
|
||||
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetDatatableWithConnection(SqlQuery As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.NoTransaction) As DataTable
|
||||
Public Function GetDatatableWithConnection(SqlQuery As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.NoTransaction, Optional Transaction As FbTransaction = Nothing) As DataTable
|
||||
_logger.Debug("Fetching Datatable: {0}", SqlQuery)
|
||||
|
||||
If Connection Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTransaction = MaybeGetTransaction(Connection, TransactionMode)
|
||||
Dim oTransaction = MaybeGetTransaction(Connection, TransactionMode, Transaction)
|
||||
Dim oDatatable As New DataTable() With {
|
||||
.TableName = "DDRESULT"
|
||||
}
|
||||
@@ -283,7 +288,7 @@ Public Class Firebird
|
||||
_logger.Error(ex, $"Error in GetDatatableWithConnection while executing command: '{SqlQuery}'")
|
||||
Throw ex
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction)
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
End Try
|
||||
|
||||
Return oDatatable
|
||||
|
||||
Reference in New Issue
Block a user