How to make a backup of the SQLite database in an Android app?


#1

Estimates: I need to back up my SQLite database from my mobile app (app) to an external memory or to the cloud.
Can someone tell me how I can do that?
I have been reading documentation for many days to achieve this and I did not succeed.
Thank you very much.

Richard


#2

The best way to do this is to convert the database to a string. You can then transfer it:

Sub butStoreDatabase_onclick()  Dim DB
  DB = SqlOpenDatabase("Northwind.db")
  DBjson = SQLExport(DB, "NorthwindNew.db", exportComplete)
End Sub

Sub exportComplete()
  console.log(JSON.stringify(DBjson))
End Sub

To import the database back, do this:

Sub getDatabase
 data = ' the string that you exported earlier 
 SQLImport(data, DBnew, importComplete, NSB.overwriteAlmays)
End Sub

Sub importComplete()
  console.log("import complete")
  DBnew = SqlOpenDatabase("NorthwindNew.db")
  s = Array(["Select * from Customers;", newQueryComplete])
  Sql(DBnew, s)
End Sub

#3

Thanks for answering George, I try and comment the results in the group.


#4

Is there a way to specify what tables to export from a database or a specific selection of a table to be exported?


#5

You’ll have to create a new SQLite database with the information you want to save, then export that.


#6

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.