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">
|
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
|
<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>
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
|
|||||||
@ -48,14 +48,14 @@
|
|||||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
<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>
|
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="EntityFramework.Firebird, Version=6.3.0.0, Culture=neutral, PublicKeyToken=42d22d092898e5f8, processorArchitecture=MSIL">
|
<Reference Include="EntityFramework.Firebird, Version=6.4.0.0, Culture=neutral, PublicKeyToken=42d22d092898e5f8, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\EntityFramework.Firebird.6.3.0\lib\net452\EntityFramework.Firebird.dll</HintPath>
|
<HintPath>..\packages\EntityFramework.Firebird.6.4.0\lib\net452\EntityFramework.Firebird.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
<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>
|
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=6.3.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=6.4.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.3.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.6.4.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
|
|||||||
@ -5,17 +5,17 @@ Imports DigitalData.Modules.Logging
|
|||||||
''' <summary>
|
''' <summary>
|
||||||
''' MODULE: Firebird
|
''' MODULE: Firebird
|
||||||
'''
|
'''
|
||||||
''' VERSION: 0.0.0.3
|
''' VERSION: 0.0.0.4
|
||||||
'''
|
'''
|
||||||
''' DATE: 08.11.2018
|
''' DATE: 05.12.2018
|
||||||
'''
|
'''
|
||||||
''' DESCRIPTION:
|
''' 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
|
''' 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
|
''' 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 _connectionPassword As String
|
||||||
Private _connectionString As String
|
Private _connectionString As String
|
||||||
|
|
||||||
|
Public Enum TransactionMode
|
||||||
|
NoTransaction
|
||||||
|
WithTransaction
|
||||||
|
End Enum
|
||||||
|
|
||||||
Public ReadOnly Property ConnectionString As String
|
Public ReadOnly Property ConnectionString As String
|
||||||
Get
|
Get
|
||||||
Return _connectionString
|
Return _connectionString
|
||||||
@ -129,6 +134,30 @@ Public Class Firebird
|
|||||||
}.ToString()
|
}.ToString()
|
||||||
End Function
|
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>
|
''' <summary>
|
||||||
''' Executes a non-query command.
|
''' Executes a non-query command.
|
||||||
''' </summary>
|
''' </summary>
|
||||||
@ -136,29 +165,27 @@ Public Class Firebird
|
|||||||
''' <param name="Connection">The Firebird connection to use</param>
|
''' <param name="Connection">The Firebird connection to use</param>
|
||||||
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
|
''' <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) As Boolean
|
||||||
Dim oConnection As FbConnection = GetConnection()
|
If Connection Is Nothing Then
|
||||||
Dim oTransaction As FbTransaction
|
Return Nothing
|
||||||
|
|
||||||
If oConnection Is Nothing Then
|
|
||||||
Return False
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
Dim oTransaction As FbTransaction = Connection.BeginTransaction()
|
||||||
|
|
||||||
Try
|
Try
|
||||||
oTransaction = oConnection.BeginTransaction()
|
|
||||||
Dim oCommand As New FbCommand With {
|
Dim oCommand As New FbCommand With {
|
||||||
.CommandText = SqlCommand,
|
.CommandText = SqlCommand,
|
||||||
.Connection = oConnection,
|
.Connection = Connection,
|
||||||
.Transaction = oTransaction
|
.Transaction = oTransaction
|
||||||
}
|
}
|
||||||
oCommand.ExecuteNonQuery()
|
oCommand.ExecuteNonQuery()
|
||||||
oTransaction.Commit()
|
|
||||||
oConnection.Close()
|
|
||||||
|
|
||||||
Return True
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex, $"Error in ExecuteNonQuery while executing command: '{SqlCommand}'")
|
_logger.Error(ex, $"Error in ExecuteNonQuery while executing command: '{SqlCommand}'")
|
||||||
Throw ex
|
Throw ex
|
||||||
|
Finally
|
||||||
|
oTransaction.Commit()
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
|
Return True
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
@ -169,7 +196,6 @@ Public Class Firebird
|
|||||||
Public Function ExecuteNonQuery(SqlCommand As String) As Boolean
|
Public Function ExecuteNonQuery(SqlCommand As String) As Boolean
|
||||||
Dim oConnection As FbConnection = GetConnection()
|
Dim oConnection As FbConnection = GetConnection()
|
||||||
Dim oScalarValue As Object = ExecuteNonQueryWithConnection(SqlCommand, oConnection)
|
Dim oScalarValue As Object = ExecuteNonQueryWithConnection(SqlCommand, oConnection)
|
||||||
|
|
||||||
oConnection.Close()
|
oConnection.Close()
|
||||||
|
|
||||||
Return oScalarValue
|
Return oScalarValue
|
||||||
@ -182,26 +208,28 @@ Public Class Firebird
|
|||||||
''' <param name="Connection">The Firebird connection to use</param>
|
''' <param name="Connection">The Firebird connection to use</param>
|
||||||
''' <returns>The scalar value if the command was executed successfully. Nothing otherwise.</returns>
|
''' <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) As Object
|
||||||
Try
|
If Connection Is Nothing Then
|
||||||
If Connection Is Nothing Then
|
Return Nothing
|
||||||
Return Nothing
|
End If
|
||||||
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 {
|
Dim oCommand As New FbCommand With {
|
||||||
.CommandText = SqlQuery,
|
.CommandText = SqlQuery,
|
||||||
.Connection = Connection,
|
.Connection = Connection,
|
||||||
.Transaction = oTransaction
|
.Transaction = oTransaction
|
||||||
}
|
}
|
||||||
Dim oResult As Object = oCommand.ExecuteScalar()
|
oResult = oCommand.ExecuteScalar()
|
||||||
|
|
||||||
oTransaction.Commit()
|
|
||||||
|
|
||||||
Return oResult
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex, $"Error in ReturnScalar while executing command: '{SqlQuery}'")
|
_logger.Error(ex, $"Error in ReturnScalar while executing command: '{SqlQuery}'")
|
||||||
Throw ex
|
Throw ex
|
||||||
|
Finally
|
||||||
|
oTransaction.Commit()
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
|
Return oResult
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
@ -212,7 +240,6 @@ Public Class Firebird
|
|||||||
Public Function GetScalarValue(SqlQuery As String) As Object
|
Public Function GetScalarValue(SqlQuery As String) As Object
|
||||||
Dim oConnection As FbConnection = GetConnection()
|
Dim oConnection As FbConnection = GetConnection()
|
||||||
Dim oScalarValue As Object = GetScalarValueWithConnection(SqlQuery, oConnection)
|
Dim oScalarValue As Object = GetScalarValueWithConnection(SqlQuery, oConnection)
|
||||||
|
|
||||||
oConnection.Close()
|
oConnection.Close()
|
||||||
|
|
||||||
Return oScalarValue
|
Return oScalarValue
|
||||||
@ -224,26 +251,32 @@ Public Class Firebird
|
|||||||
''' <param name="SqlQuery">The query to execute</param>
|
''' <param name="SqlQuery">The query to execute</param>
|
||||||
''' <param name="Connection">The Firebird connection to use</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>
|
''' <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
|
Public Function GetDatatableWithConnection(SqlQuery As String, Connection As FbConnection, Optional TransactionMode As TransactionMode = TransactionMode.NoTransaction) As DataTable
|
||||||
Try
|
If Connection Is Nothing Then
|
||||||
If Connection Is Nothing Then
|
Return Nothing
|
||||||
Return Nothing
|
End If
|
||||||
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,
|
.CommandText = SqlQuery,
|
||||||
.Connection = Connection
|
.Connection = Connection,
|
||||||
}
|
.Transaction = oTransaction
|
||||||
Dim oAdapter As New FbDataAdapter(oCommand)
|
})
|
||||||
Dim oDatatable As New DataTable() With {.TableName = "DDRESULT"}
|
|
||||||
|
|
||||||
oAdapter.Fill(oDatatable)
|
oAdapter.Fill(oDatatable)
|
||||||
|
|
||||||
Return oDatatable
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex, $"Error in GetDatatableWithConnection while executing command: '{SqlQuery}'")
|
_logger.Error(ex, $"Error in GetDatatableWithConnection while executing command: '{SqlQuery}'")
|
||||||
Throw ex
|
Throw ex
|
||||||
|
Finally
|
||||||
|
MaybeCommitTransaction(oTransaction)
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
|
Return oDatatable
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
@ -251,10 +284,9 @@ Public Class Firebird
|
|||||||
''' </summary>
|
''' </summary>
|
||||||
''' <param name="SqlQuery">The query to execute</param>
|
''' <param name="SqlQuery">The query to execute</param>
|
||||||
''' <returns>A datatable containing the results if the command was executed successfully. Nothing otherwise.</returns>
|
''' <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 oConnection As FbConnection = GetConnection()
|
||||||
Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection)
|
Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection, TransactionMode)
|
||||||
|
|
||||||
oConnection.Close()
|
oConnection.Close()
|
||||||
|
|
||||||
Return oDatatable
|
Return oDatatable
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
|
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
|
||||||
<package id="EntityFramework.Firebird" version="6.3.0" targetFramework="net461" />
|
<package id="EntityFramework.Firebird" version="6.4.0" targetFramework="net461" />
|
||||||
<package id="FirebirdSql.Data.FirebirdClient" version="6.3.0" targetFramework="net461" />
|
<package id="FirebirdSql.Data.FirebirdClient" version="6.4.0" targetFramework="net461" />
|
||||||
<package id="NLog" version="4.5.10" targetFramework="net461" />
|
<package id="NLog" version="4.5.10" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
||||||
Loading…
x
Reference in New Issue
Block a user