Android Question Best way (proper way) to define a sqlite conecction?

cheveguerra

Member
Licensed User
Longtime User
Hi everybody,

I would like to know what us the best way to manage connections to a sqlite db, the way I see it, there are 3 options:

First one:
Declare, initialize and use the connection in every Sub of an activity:
First One:
Sub whatever
  Dim skmt As SQL
  skmt.Initialize(pathToDB,"kmt.db", True)
  c=skmt.ExecQuery("SELECT * FROM table1")
End Sub

Second One:
Declare in Activity.Globals, initialize in Activity.Create and use in any Sub we need it:
B4X:
Sub Process_Globals
    Dim skmt As SQL
End Sub
Sub Activity_Create(FirstTime As Boolean)
    skmt.Initialize(pathToDB,"kmt.db", True)
End Sub
Sub whatever
    c=skmt.ExecQuery("SELECT * FROM table1")
End Sub

Third One:
Declare as global in starter, initialize in starter and use in whatever activity we need it:
Thitd One:
STARTER
Sub Process_Globals
    Dim skmt As SQL
End sub
Sub Service_Create
    skmt.Initialize(pathToDB,"kmt.db", True)
End Sub

ANY OTHER ACTIVITY
Sub whatever
    c=Starter.skmt.ExecQuery("SELECT * FROM table1")
End sub

So, please advice on pros and cons and No No's

Best regards
 
Top