jj: update Database deps, add optional transaction for select
This commit is contained in:
parent
0073fee1f9
commit
15124113f7
@ -16,7 +16,7 @@
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.1.0.0" newVersion="6.1.0.0" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.3.0.0" newVersion="6.3.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
|
||||
@ -48,14 +48,14 @@
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.Firebird, Version=6.3.0.0, Culture=neutral, PublicKeyToken=42d22d092898e5f8, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.Firebird.6.3.0\lib\net452\EntityFramework.Firebird.dll</HintPath>
|
||||
<Reference Include="EntityFramework.Firebird, Version=6.4.0.0, Culture=neutral, PublicKeyToken=42d22d092898e5f8, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.Firebird.6.4.0\lib\net452\EntityFramework.Firebird.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=6.3.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.3.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
||||
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=6.4.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.4.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
|
||||
@ -5,17 +5,17 @@ Imports DigitalData.Modules.Logging
|
||||
''' <summary>
|
||||
''' 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
|
||||
|
||||
''' <summary>
|
||||
''' Executes a non-query command.
|
||||
''' </summary>
|
||||
@ -136,29 +165,27 @@ Public Class Firebird
|
||||
''' <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
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
@ -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
|
||||
''' <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
|
||||
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
|
||||
|
||||
''' <summary>
|
||||
@ -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
|
||||
''' <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) 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
|
||||
|
||||
''' <summary>
|
||||
@ -251,10 +284,9 @@ Public Class Firebird
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
|
||||
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
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
|
||||
<package id="EntityFramework.Firebird" version="6.3.0" targetFramework="net461" />
|
||||
<package id="FirebirdSql.Data.FirebirdClient" version="6.3.0" targetFramework="net461" />
|
||||
<package id="EntityFramework.Firebird" version="6.4.0" targetFramework="net461" />
|
||||
<package id="FirebirdSql.Data.FirebirdClient" version="6.4.0" targetFramework="net461" />
|
||||
<package id="NLog" version="4.5.10" targetFramework="net461" />
|
||||
</packages>
|
||||
Loading…
x
Reference in New Issue
Block a user