jj: Database Version 0.0.3
This commit is contained in:
parent
084fa29f3d
commit
c27cf5e8a0
@ -5,9 +5,9 @@ Imports DigitalData.Modules.Logging
|
||||
''' <summary>
|
||||
''' MODULE: Firebird
|
||||
'''
|
||||
''' VERSION: 0.0.0.3
|
||||
''' VERSION: 0.0.0.2
|
||||
'''
|
||||
''' DATE: 08.11.2018
|
||||
''' DATE: 03.09.2018
|
||||
'''
|
||||
''' DESCRIPTION:
|
||||
'''
|
||||
@ -17,15 +17,15 @@ Imports DigitalData.Modules.Logging
|
||||
'''
|
||||
''' FirebirdSql.Data.FirebirdClient, >= 6.0.0
|
||||
'''
|
||||
''' PARAMETERS: LogConfig, DigitalData.Modules.Logging.LogConfig
|
||||
''' PARAMETERS: LogFactory, NLog.LogFactory
|
||||
''' The LogFactory containing the current log config. Used to instanciate the class logger for this and any dependent class
|
||||
'''
|
||||
''' DataSource, String
|
||||
''' The server where the database lives, for example 127.0.0.1 or dd-vmx09-vm03
|
||||
'''
|
||||
''' Database, String
|
||||
''' The location of the Database in the format `127.0.0.1:E:\Path\To\Database.FDB`
|
||||
'''
|
||||
''' Database, String
|
||||
''' The server where the database lives, for example 127.0.0.1 or dd-vmx09-vm03
|
||||
'''
|
||||
''' User, String
|
||||
''' The user name to connect as
|
||||
'''
|
||||
@ -52,26 +52,23 @@ Public Class Firebird
|
||||
Private _connectionDatabase As String
|
||||
Private _connectionUsername As String
|
||||
Private _connectionPassword As String
|
||||
Private _connectionString As String
|
||||
|
||||
Public ReadOnly Property ConnectionEstablished As Boolean
|
||||
Public ReadOnly Property ConnectionFailed As Boolean
|
||||
Public ReadOnly Property ConnectionString As String
|
||||
Get
|
||||
Return _connectionString
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property DatabaseName As String
|
||||
Get
|
||||
Dim oRegex As New Regex("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:")
|
||||
Dim oPath As String = oRegex.Replace(_connectionDatabase, "")
|
||||
Dim oFileInfo As New IO.FileInfo(oPath)
|
||||
Return oFileInfo.Name
|
||||
Dim fi As New IO.FileInfo(oPath)
|
||||
Return fi.Name
|
||||
End Get
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
'''
|
||||
''' </summary>
|
||||
''' <param name="LogFactory"></param>
|
||||
''' <param name="Datasource"></param>
|
||||
''' <param name="Database"></param>
|
||||
''' <param name="User"></param>
|
||||
@ -87,7 +84,7 @@ Public Class Firebird
|
||||
_connectionDatabase = Database
|
||||
_connectionUsername = User
|
||||
_connectionPassword = Password
|
||||
_connectionString = oConnectionString
|
||||
_ConnectionString = oConnectionString
|
||||
|
||||
' Test the connection
|
||||
Dim oConnection = GetConnection()
|
||||
@ -101,11 +98,15 @@ Public Class Firebird
|
||||
|
||||
Public Function GetConnection() As FbConnection
|
||||
Try
|
||||
Dim oConnection = New FbConnection(_connectionString)
|
||||
Dim oConnection = New FbConnection(_ConnectionString)
|
||||
oConnection.Open()
|
||||
_ConnectionEstablished = True
|
||||
_ConnectionFailed = False
|
||||
|
||||
Return oConnection
|
||||
Catch ex As Exception
|
||||
_ConnectionFailed = True
|
||||
_ConnectionEstablished = False
|
||||
_logger.Error(ex)
|
||||
|
||||
Return Nothing
|
||||
@ -133,18 +134,16 @@ Public Class Firebird
|
||||
''' Executes a non-query command.
|
||||
''' </summary>
|
||||
''' <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
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
Dim oTransaction As FbTransaction
|
||||
|
||||
If oConnection Is Nothing Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Public Function ExecuteNonQuery(SqlCommand As String) As Boolean
|
||||
Try
|
||||
oTransaction = oConnection.BeginTransaction()
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
|
||||
If oConnection Is Nothing Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oTransaction As FbTransaction = oConnection.BeginTransaction()
|
||||
Dim oCommand As New FbCommand With {
|
||||
.CommandText = SqlCommand,
|
||||
.Connection = oConnection,
|
||||
@ -161,41 +160,29 @@ Public Class Firebird
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a non-query command.
|
||||
''' </summary>
|
||||
''' <param name="SqlCommand">The command to execute</param>
|
||||
''' <returns>True, if command was executed sucessfully. Otherwise false.</returns>
|
||||
Public Function ExecuteNonQuery(SqlCommand As String) As Boolean
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
Dim oScalarValue As Object = ExecuteNonQueryWithConnection(SqlCommand, oConnection)
|
||||
|
||||
oConnection.Close()
|
||||
|
||||
Return oScalarValue
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a scalar value.
|
||||
''' </summary>
|
||||
''' <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 GetScalarValue(SqlQuery As String) As Object
|
||||
Try
|
||||
If Connection Is Nothing Then
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
|
||||
If oConnection Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTransaction As FbTransaction = Connection.BeginTransaction()
|
||||
Dim oTransaction As FbTransaction = oConnection.BeginTransaction()
|
||||
Dim oCommand As New FbCommand With {
|
||||
.CommandText = SqlQuery,
|
||||
.Connection = Connection,
|
||||
.Connection = oConnection,
|
||||
.Transaction = oTransaction
|
||||
}
|
||||
Dim oResult As Object = oCommand.ExecuteScalar()
|
||||
|
||||
oTransaction.Commit()
|
||||
oConnection.Close()
|
||||
|
||||
Return oResult
|
||||
Catch ex As Exception
|
||||
@ -204,59 +191,33 @@ Public Class Firebird
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a scalar value.
|
||||
''' </summary>
|
||||
''' <param name="SqlQuery">The query to execute</param>
|
||||
''' <returns>The scalar value if the command was executed successfully. Nothing otherwise.</returns>
|
||||
Public Function GetScalarValue(SqlQuery As String) As Object
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
Dim oScalarValue As Object = GetScalarValueWithConnection(SqlQuery, oConnection)
|
||||
|
||||
oConnection.Close()
|
||||
|
||||
Return oScalarValue
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a table of values.
|
||||
''' </summary>
|
||||
''' <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
|
||||
|
||||
Dim oCommand As New FbCommand With {
|
||||
.CommandText = SqlQuery,
|
||||
.Connection = Connection
|
||||
}
|
||||
Dim oAdapter As New FbDataAdapter(oCommand)
|
||||
Dim oDatatable As New DataTable() With {.TableName = "DDRESULT"}
|
||||
|
||||
oAdapter.Fill(oDatatable)
|
||||
|
||||
Return oDatatable
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex, $"Error in GetDatatableWithConnection while executing command: '{SqlQuery}'")
|
||||
Throw ex
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Executes a sql query resulting in a table of values.
|
||||
''' </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
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection)
|
||||
Try
|
||||
Dim oConnection As FbConnection = GetConnection()
|
||||
|
||||
oConnection.Close()
|
||||
If oConnection Is Nothing Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Return oDatatable
|
||||
Dim oCommand As New FbCommand With {
|
||||
.CommandText = SqlQuery,
|
||||
.Connection = oConnection
|
||||
}
|
||||
Dim oAdapter As New FbDataAdapter(oCommand)
|
||||
Dim oDatatable As New DataTable()
|
||||
|
||||
oAdapter.Fill(oDatatable)
|
||||
oConnection.Close()
|
||||
|
||||
Return oDatatable
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex, $"Error in ReturnDatatable while executing command: '{SqlQuery}'")
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("0.0.0.3")>
|
||||
<Assembly: AssemblyVersion("0.0.0.2")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user