Android Question How to Restore a sqlite DB from a backed one

Daniel44

Active Member
Licensed User
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

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
 

mw71

Active Member
Licensed User
Longtime User
Hi,

I Backup the SQLite File (to Goole Drive and FTP Server).

For restore:
- the File can be copy back
- i can use my Sync funkt.

i hope it's a little help
 
Upvote 0

Daniel44

Active Member
Licensed User
Hi,

I Backup the SQLite File (to Goole Drive and FTP Server).

For restore:
- the File can be copy back
- i can use my Sync funkt.

i hope it's a little help


Thank you for answering! Really? Explain please how you make a backup of the database that is in a directory hidden in the phone? Have you ever seen any topic about How to Restore from a backed and Hidden db? If you have.. just post here please Thank you
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
you will backup a SQLite DB from your App? than your App has access.
You can Upload, copy......

Google Drive: https://www.b4x.com/android/forum/t...-rest-api-v3-small-testproject.95778/#content
FTP: pse use Search, it's very easy
Copy: File.copy e.g.


Restore:
i have 2 Weeks before made a mistake, i have delete the Files on the SD Card.
I have download the Files and copy the Files via Totalcomander (you can use other) to the directory.
In the App i use RuntimePermisson.GetAllSafeDirsExternal("") to get the "best Place" for store the Files.

Or you can read the Data from your Backup and write it in your Database.
 
Upvote 0

Daniel44

Active Member
Licensed User
you will backup a SQLite DB from your App? than your App has access.
You can Upload, copy......

Google Drive: https://www.b4x.com/android/forum/t...-rest-api-v3-small-testproject.95778/#content
FTP: pse use Search, it's very easy
Copy: File.copy e.g.


Restore:
i have 2 Weeks before made a mistake, i have delete the Files on the SD Card.
I have download the Files and copy the Files via Totalcomander (you can use other) to the directory.
In the App i use RuntimePermisson.GetAllSafeDirsExternal("") to get the "best Place" for store the Files.

Or you can read the Data from your Backup and write it in your Database.
Great! Thank you very much
 
Upvote 0
Top