Android Example My way to work with local DB

I save the SQLite DB used by my apps in the directory corresponding to File.DirInternal, which is the app's exclusive space.

This, however, prevents you from accessing the DB from outside (directly from Windows explorer) and checking the changes made by the app.

It would be possible to get that DB if it were in rp.GetSafeDirDefaultExternal (rp = RuntimePermissions). So what I do is:

1 - create a new configuration file





2 - create a conditional symbol in this file (whatever word I want; I use SafeDirExt)
3 - initialize the DB as follows:

modDB - code module:
Sub Process_Globals
    Private DB As SQL
    Private DBDir As String
    Private Const DBName As String = "NameOfMyDB.db"
End Sub

Public Sub Init
    #If SafeDirExt
        Dim rp As RuntimePermissions
        DBDir = rp.GetSafeDirDefaultExternal("")
    #Else
        DBDir = File.DirInternal
    #End If
    If Not(File.Exists(DBDir, DBName)) Then
        File.Copy(File.DirAssets, DBName, DBDir, DBName)
    End If
    DB.Initialize(DBDir, DBName, False)
End Sub

When I run, I choose the configuration:




[You could also do the same thing using as a conditional statement: #If Debug but I prefer to work almost always in this mode]
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
When I run, I choose the configuration:
You are creating 2 databases, one in xui.defaultExternal, the other in defaultExternal. This can be a nightmare to maintain.. I don't think this is what the user wants to deal with.. If I am missing your point, please post a project.
 

LucaMs

Expert
Licensed User
Longtime User
You are creating 2 databases, one in xui.defaultExternal, the other in defaultExternal. This can be a nightmare to maintain.. I don't think this is what the user wants to deal with.. If I am missing your point, please post a project.
I always work only in debug mode (except in rare cases where higher execution speed is required). Once the app is completed, stable, compiling in Release mode the db in the DirInternal will be used; you will eliminate the other, which is only used to perform checks.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…