i need a small help to backup my Sqlite database
here is how i encrypt it
//Connect to a SQLITE database
Dim dbFile As FolderItem
Dim db As New SQLiteDatabase
dbFile = GetFolderItem("c:\XOJO PROGRAMS\PASSLOCK\entries.sqlite")
db.DatabaseFile = dbFile
Try
db.Connect
db.Encrypt("aes256:
Public Sub Backup()
'...
Dim file As FolderItem = File ' <- File As FolderItem Propertie
Dim destination As FolderItem
Var dlg As New SaveFileDialog ' SaveAsDialog
dlg.Title = "Save Database Backup as .."
dlg.ActionButtonCaption = "Save as"
dlg.CancelButtonCaption ="Cancel"
dlg.Filter = FileTypeGroup1.Backup
dlg.InitialFolder = file.Parent
dlg.SuggestedFileName = file.DisplayName + ".backup"
destination = dlg.ShowModal
If destination <> Nil Then
'file.CopyFileTo(destination)
If destination.Exists Then destination.Remove
file.CopyTo(destination)
Else
// User Cancelled
End If
End Sub
Public Shared Sub DefaultFile()
Var f As FolderItem
f = App.ExecutableFile.Parent.Child("Password.Xojo.sqlite")
If f <> Nil And f.Exists = True Then
File = f
Else
//File = SpecialFolder.Documents.Child("Database").Child("Password.Xojo.sqlite")
Var path As New FolderItem("N:\Dokumente\Database") 'my NAS
File = path.Child("Password.Xojo.sqlite")
End If
End Sub
Public Sub VACUUM()
'erzeugt eine temporäre db irgendwo und erzeugt daraus wieder eine neue ohne Restmüll
DB.ExecuteSQL("VACUUM")
End Sub
Public Sub Decrypt(encryptionKey As String)
Dim file As FolderItem = File
If file.Exists Then
DB = New SQLiteDatabase
DB.DatabaseFile = File
Try
DB.EncryptionKey = encryptionKey
DB.Connect
DB.Decrypt
DB.Close
Catch error As DatabaseException
MessageBox("Error connecting To database.")
End Try
Else
MessageBox("Error database not found.")
End If
End Sub
Public Sub Encrypt(encryptionKey As String)
Dim file As FolderItem = File
If file.Exists Then
DB = New SQLiteDatabase
DB.DatabaseFile = File
Try
DB.Connect
DB.Encrypt(encryptionKey)
DB.Close
Catch error As DatabaseException
MessageBox("Error connecting to Database.")
End Try
Else
MessageBox("Error Database not found.")
End If
End Sub
Public Function Open() As Boolean
Dim file As FolderItem = File '<- Class Propertie
Var encryptionKey As String = Password.mKey
'Var encryptionKey As String = ""
If OpenDatabase(file,encryptionKey) = True Then
Return True
Else
MessageBox("Unable to open the Database at " + file.NativePath )
Return False
End If
End Function
Private Function OpenDatabase(file As FolderItem, encryptionKey As String) As Boolean
If file.Exists Then
DB = New SQLiteDatabase '<- DB is class propertie SQLiteDatabase
DB.DatabaseFile = File
DB.EncryptionKey = encryptionKey
Try
DB.Connect
Return True
Catch error As DatabaseException
MessageBox("Error connecting to Database.")
End Try
Else
Return False
End If
End Function