diff --git a/Modules.Database/App.config b/Modules.Database/App.config
index 10fb41e9..0e80cbda 100644
--- a/Modules.Database/App.config
+++ b/Modules.Database/App.config
@@ -16,7 +16,7 @@
-
+
diff --git a/Modules.Database/Database.vbproj b/Modules.Database/Database.vbproj
index 6b4b52f5..c57a5456 100644
--- a/Modules.Database/Database.vbproj
+++ b/Modules.Database/Database.vbproj
@@ -48,14 +48,14 @@
..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
-
- ..\packages\EntityFramework.Firebird.6.3.0\lib\net452\EntityFramework.Firebird.dll
+
+ ..\packages\EntityFramework.Firebird.6.4.0\lib\net452\EntityFramework.Firebird.dll
..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll
-
- ..\packages\FirebirdSql.Data.FirebirdClient.6.3.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll
+
+ ..\packages\FirebirdSql.Data.FirebirdClient.6.4.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll
diff --git a/Modules.Database/Firebird.vb b/Modules.Database/Firebird.vb
index 08c6daab..3dd2cbed 100644
--- a/Modules.Database/Firebird.vb
+++ b/Modules.Database/Firebird.vb
@@ -5,17 +5,17 @@ Imports DigitalData.Modules.Logging
'''
''' MODULE: Firebird
'''
-''' VERSION: 0.0.0.3
+''' VERSION: 0.0.0.4
'''
-''' DATE: 08.11.2018
+''' DATE: 05.12.2018
'''
''' DESCRIPTION:
'''
-''' DEPENDENCIES: NLog, >= 4.5.8
+''' DEPENDENCIES: NLog, >= 4.5.10
'''
-''' EntityFramework.Firebird, >= 6.1.0
+''' EntityFramework.Firebird, >= 6.4.0
'''
-''' FirebirdSql.Data.FirebirdClient, >= 6.0.0
+''' FirebirdSql.Data.FirebirdClient, >= 6.4.0
'''
''' PARAMETERS: LogConfig, DigitalData.Modules.Logging.LogConfig
''' The LogFactory containing the current log config. Used to instanciate the class logger for this and any dependent class
@@ -54,6 +54,11 @@ Public Class Firebird
Private _connectionPassword As String
Private _connectionString As String
+ Public Enum TransactionMode
+ NoTransaction
+ WithTransaction
+ End Enum
+
Public ReadOnly Property ConnectionString As String
Get
Return _connectionString
@@ -129,6 +134,30 @@ Public Class Firebird
}.ToString()
End Function
+ Private Function MaybeGetTransaction(Connection As FbConnection, Mode As TransactionMode)
+ If Mode = TransactionMode.NoTransaction Then
+ Return Nothing
+ ElseIf TransactionMode.WithTransaction Then
+ Return Connection.BeginTransaction()
+ Else
+ Return Connection.BeginTransaction()
+ End If
+ End Function
+
+ Private Function MaybeCommitTransaction(Transaction As FbTransaction)
+ If IsNothing(Transaction) Then
+ Return True
+ Else
+ Try
+ Transaction.Commit()
+ Return True
+ Catch ex As Exception
+ _logger.Error(ex)
+ Return False
+ End Try
+ End If
+ End Function
+
'''
''' Executes a non-query command.
'''
@@ -136,29 +165,27 @@ Public Class Firebird
''' The Firebird connection to use
''' True, if command was executed sucessfully. Otherwise false.
Public Function ExecuteNonQueryWithConnection(SqlCommand As String, Connection As FbConnection) As Boolean
- Dim oConnection As FbConnection = GetConnection()
- Dim oTransaction As FbTransaction
-
- If oConnection Is Nothing Then
- Return False
+ If Connection Is Nothing Then
+ Return Nothing
End If
+ Dim oTransaction As FbTransaction = Connection.BeginTransaction()
+
Try
- oTransaction = oConnection.BeginTransaction()
Dim oCommand As New FbCommand With {
.CommandText = SqlCommand,
- .Connection = oConnection,
+ .Connection = Connection,
.Transaction = oTransaction
}
oCommand.ExecuteNonQuery()
- oTransaction.Commit()
- oConnection.Close()
-
- Return True
Catch ex As Exception
_logger.Error(ex, $"Error in ExecuteNonQuery while executing command: '{SqlCommand}'")
Throw ex
+ Finally
+ oTransaction.Commit()
End Try
+
+ Return True
End Function
'''
@@ -169,7 +196,6 @@ Public Class Firebird
Public Function ExecuteNonQuery(SqlCommand As String) As Boolean
Dim oConnection As FbConnection = GetConnection()
Dim oScalarValue As Object = ExecuteNonQueryWithConnection(SqlCommand, oConnection)
-
oConnection.Close()
Return oScalarValue
@@ -182,26 +208,28 @@ Public Class Firebird
''' The Firebird connection to use
''' The scalar value if the command was executed successfully. Nothing otherwise.
Public Function GetScalarValueWithConnection(SqlQuery As String, Connection As FbConnection) As Object
- Try
- If Connection Is Nothing Then
- Return Nothing
- End If
+ If Connection Is Nothing Then
+ Return Nothing
+ End If
- Dim oTransaction As FbTransaction = Connection.BeginTransaction()
+ Dim oTransaction As FbTransaction = Connection.BeginTransaction()
+ Dim oResult As Object
+
+ Try
Dim oCommand As New FbCommand With {
.CommandText = SqlQuery,
.Connection = Connection,
.Transaction = oTransaction
}
- Dim oResult As Object = oCommand.ExecuteScalar()
-
- oTransaction.Commit()
-
- Return oResult
+ oResult = oCommand.ExecuteScalar()
Catch ex As Exception
_logger.Error(ex, $"Error in ReturnScalar while executing command: '{SqlQuery}'")
Throw ex
+ Finally
+ oTransaction.Commit()
End Try
+
+ Return oResult
End Function
'''
@@ -212,7 +240,6 @@ Public Class Firebird
Public Function GetScalarValue(SqlQuery As String) As Object
Dim oConnection As FbConnection = GetConnection()
Dim oScalarValue As Object = GetScalarValueWithConnection(SqlQuery, oConnection)
-
oConnection.Close()
Return oScalarValue
@@ -224,26 +251,32 @@ Public Class Firebird
''' The query to execute
''' The Firebird connection to use
''' A datatable containing the results if the command was executed successfully. Nothing otherwise.
- Public Function GetDatatableWithConnection(SqlQuery As String, Connection As FbConnection) As DataTable
- Try
- If Connection Is Nothing Then
- Return Nothing
- End If
+ Public Function GetDatatableWithConnection(SqlQuery As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.NoTransaction) As DataTable
+ If Connection Is Nothing Then
+ Return Nothing
+ End If
- Dim oCommand As New FbCommand With {
+ Dim oTransaction = MaybeGetTransaction(Connection, TransactionMode)
+ Dim oDatatable As New DataTable() With {
+ .TableName = "DDRESULT"
+ }
+
+ Try
+ Dim oAdapter As New FbDataAdapter(New FbCommand With {
.CommandText = SqlQuery,
- .Connection = Connection
- }
- Dim oAdapter As New FbDataAdapter(oCommand)
- Dim oDatatable As New DataTable() With {.TableName = "DDRESULT"}
+ .Connection = Connection,
+ .Transaction = oTransaction
+ })
oAdapter.Fill(oDatatable)
-
- Return oDatatable
Catch ex As Exception
_logger.Error(ex, $"Error in GetDatatableWithConnection while executing command: '{SqlQuery}'")
Throw ex
+ Finally
+ MaybeCommitTransaction(oTransaction)
End Try
+
+ Return oDatatable
End Function
'''
@@ -251,10 +284,9 @@ Public Class Firebird
'''
''' The query to execute
''' A datatable containing the results if the command was executed successfully. Nothing otherwise.
- Public Function GetDatatable(SqlQuery As String) As DataTable
+ Public Function GetDatatable(SqlQuery As String, Optional TransactionMode As TransactionMode = TransactionMode.NoTransaction) As DataTable
Dim oConnection As FbConnection = GetConnection()
- Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection)
-
+ Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection, TransactionMode)
oConnection.Close()
Return oDatatable
diff --git a/Modules.Database/packages.config b/Modules.Database/packages.config
index f27f81d3..9613071f 100644
--- a/Modules.Database/packages.config
+++ b/Modules.Database/packages.config
@@ -1,7 +1,7 @@
-
-
+
+
\ No newline at end of file