106 lines
4.3 KiB
VB.net
106 lines
4.3 KiB
VB.net
Imports System.Data.SQLite
|
|
Imports DigitalData.Modules.Logging
|
|
Public Class ClassSQLITE
|
|
Private Shared db_location As String
|
|
Public Shared Passwort_admin As String
|
|
Private Shared _Logger As DigitalData.Modules.Logging.Logger
|
|
|
|
Sub New(LogConfig As LogConfig)
|
|
_Logger = LogConfig.GetLogger
|
|
|
|
End Sub
|
|
Public Function DBInit(_form As Boolean) As Boolean
|
|
Try
|
|
If My.Settings.SQLLITE_CONNECTION = String.Empty Or My.Settings.SQLLITE_CONNECTION Is Nothing = True Then
|
|
_Logger.Debug($"My.Settings.SQLLITE_CONNECTION is empty or nothing...trying to fix...")
|
|
If IO.File.Exists(Application.StartupPath & "\ToolCollection.sqlite") Then
|
|
My.Settings.SQLLITE_CONNECTION = Application.StartupPath & "\ToolCollection.sqlite"
|
|
My.Settings.Save()
|
|
End If
|
|
End If
|
|
_Logger.Debug($"SQLITE ConnString: data source={My.Settings.SQLLITE_CONNECTION};Version=3;UseUTF16Encoding=True;")
|
|
db_location = "data source=" & My.Settings.SQLLITE_CONNECTION & ";Version=3;UseUTF16Encoding=True;"
|
|
Dim SQLconnect As New SQLite.SQLiteConnection(db_location) '"Data Source=E: \ToolCollection.sqlite;Version=3;UseUTF16Encoding=True;") '""Data Source=" & db_location & ";")
|
|
'SQLconnect.ConnectionString = "Data Source=" & db_location
|
|
SQLconnect.Open()
|
|
Return True
|
|
Catch ex As Exception
|
|
If _form = False Then
|
|
_Logger.Error(ex)
|
|
Else
|
|
MsgBox("Fehler in DBInit SQLiteDatabase: " & ex.Message, MsgBoxStyle.Critical)
|
|
End If
|
|
Return False
|
|
End Try
|
|
End Function
|
|
Public Function Return_Datatable(Select_anweisung As String, _form As Boolean) As DataTable
|
|
Try
|
|
Dim SQLconnect As New SQLite.SQLiteConnection()
|
|
Dim SQLcommand As SQLiteCommand
|
|
SQLconnect.ConnectionString = db_location
|
|
SQLconnect.Open()
|
|
SQLcommand = SQLconnect.CreateCommand
|
|
SQLcommand.CommandText = Select_anweisung
|
|
|
|
|
|
Dim adapter1 As SQLiteDataAdapter = New SQLiteDataAdapter(SQLcommand)
|
|
Dim dt As DataTable = New DataTable()
|
|
adapter1.Fill(dt)
|
|
SQLconnect.Close()
|
|
Return dt
|
|
Catch ex As Exception
|
|
If _form = False Then
|
|
_Logger.Error(ex)
|
|
Else
|
|
MsgBox("FEHLER IN Return_Datatable: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
End If
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
Public Function Execute_Command(_sql As String, _form As Boolean) As Boolean
|
|
Try
|
|
Dim SQLconnect As New SQLite.SQLiteConnection()
|
|
Dim SQLcommand As SQLiteCommand
|
|
SQLconnect.ConnectionString = db_location
|
|
SQLconnect.Open()
|
|
SQLcommand = SQLconnect.CreateCommand
|
|
'Update Last Created Record in Foo
|
|
SQLcommand.CommandText = _sql
|
|
SQLcommand.ExecuteNonQuery()
|
|
SQLcommand.Dispose()
|
|
SQLconnect.Close()
|
|
Return True
|
|
Catch ex As Exception
|
|
If _form = False Then
|
|
_Logger.Error(ex)
|
|
Else
|
|
MsgBox("Fehler in: 'Execute_Command': " & vbNewLine & ex.Message & vbNewLine & vbNewLine & "SQL-Command: " & _sql, MsgBoxStyle.Critical)
|
|
End If
|
|
Return False
|
|
End Try
|
|
End Function
|
|
Public Function Execute_scalar(_sql As String, _form As Boolean)
|
|
Try
|
|
Dim SQLconnect As New SQLite.SQLiteConnection()
|
|
Dim SQLcommand As SQLiteCommand
|
|
SQLconnect.ConnectionString = db_location
|
|
SQLconnect.Open()
|
|
SQLcommand = SQLconnect.CreateCommand
|
|
'Update Last Created Record in Foo
|
|
SQLcommand.CommandText = _sql
|
|
Dim result = SQLcommand.ExecuteScalar()
|
|
SQLcommand.Dispose()
|
|
SQLconnect.Close()
|
|
Return result
|
|
Catch ex As Exception
|
|
If _form = False Then
|
|
_Logger.Error(ex)
|
|
Else
|
|
MsgBox("Fehler in: 'Execute_scalar': " & vbNewLine & ex.Message & vbNewLine & vbNewLine & "SQL-Command: " & _sql, MsgBoxStyle.Critical)
|
|
End If
|
|
Return Nothing
|
|
End Try
|
|
End Function
|
|
|
|
End Class
|