Android Question DbUtils.CopyDBFromAssets Android

ykucuk

Well-Known Member
Licensed User
Longtime User
Hi

My database copy each time when i run application. Records delete.

How can i copy database just once if no exist . I tried with CopyDBFromAssets but seems i don't know how to use.


B4X:
DbPath=DBUtils.CopyDBFromAssets("mydata.db")
sql.Initialize (DbPath, "mydata.db", True)
 

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi,

You can try:


in Main:
Sub Activity_Create(FirstTime As Boolean)
    '
    Starter.SysDirApk    = File.DirDefaultExternal
    Log("Data Folder: " & Starter.SysDirApk)
    '
    If FirstTime = True Then
        '
        If File.Exists(Starter.SysDirApk,"database.db3") = False Then
            File.Copy(File.DirAssets,"database.db3",Starter.SysDirApk,"database.db3")
            Log("Copiando Base de datos a : " & Starter.SysDirApk)
        End If
        '
        If Starter.DataBase.IsInitialized = False Then
            If Rutinas.Open_DataBase(Starter.SysDirApk, "database.db3") = False Then
                Log("No se pudo abrir la base de datos")
            End If
        End If
        '
    End If

End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…