I'm doing a backup with a method and it seems it's working.. at least it doesn't show me any error.. But I don't know how to restore that sqlite db. This method is called by a button. I'd like in another button call a for ex. "restore" but I don't know how to do that.
The method I'm using to do my sqlite backup
In the Starter module :
Thank you in advance
The method I'm using to do my sqlite backup
B4X:
Sub Backup
Dim DBDir As String = Starter.SQLDataBasePath
Dim DBName As String =Starter.SQLDateBaseName
Dim Query As String
Dim Cursor1 As Cursor
Dim TableName As String = "customers"
Query = "SELECT * FROM " & TableName 'get all columns
Cursor1 = Starter.SQL1.ExecQuery(Query)
Dim Found As Boolean = False
For l=0 To Cursor1.ColumnCount-1
Log(Cursor1.GetColumnName(l))
Next
If Found=False Then 'backup before alter ;-)
Try
File.Copy(DBDir,DBName,DBDir,DBName & DateTime.Now & "_backup") 'backup before altering table
ToastMessageShow("Base de datos Copiada con Exito", True)
Catch
Log(LastException)
End Try
Query = "PRAGMA table_info(" & TableName &")" 'Get table info -> shows column names and format
Cursor1 = Starter.SQL1.ExecQuery(Query)
For Row = 0 To Cursor1.RowCount - 1
Cursor1.Position = Row
Log(Cursor1.GetString2(1) & ":" & Cursor1.GetString2(2))
Next
End If
End Sub
In the Starter module :
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public SQL1 As SQL
Public SQLDataBasePath As String
Public SQLDateBaseName As String
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
SQLDataBasePath = File.DirInternal
SQLDateBaseName = "chinook2.db"
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Thank you in advance