SQL close

timo

Active Member
Licensed User
Longtime User
I'm a little old fashionned, but it souds me strange not to close a database. You close cursors and transactions but not a db. DB stay most of the time open resident with the app when the app is "closed". Is there any problem in closing a db on going out and then evaluate it's state by 'db.IsInitialised' on resume?. Which is the best way to follow with android? (I mean with SQLite)
Thanks
 

Smee

Well-Known Member
Licensed User
Longtime User
Hi Timo,

I always close my db upon exit. I have exited the program and gone straight back in without testing the status of the database. It sems to work ok for me

Joe
 
Upvote 0

timo

Active Member
Licensed User
Longtime User
but if you reopen your app while resident, without testing it in Resume (and opened in cerate (firstTime) you will have a java exception (DB not open).

Another question: what are db-wal and db-shm autocreated?
 
Last edited:
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
Hi Timo,

I always close my db upon exit. I have exited the program and gone straight back in without testing the status of the database. It sems to work ok for me

Joe

As i said above. I do not get an error. the db is always opened ok

B4X:
Sub Activity_Create(FirstTime As Boolean)
   If FirstTime=True Then
      SQL.Initialize(File.DirInternal, "WDOrders.db", True)

....
...
...
end sub

Sub Activity_Keypress (KeyCode As Int) As Boolean
Dim Answ As Int
Dim Txt As String
Log(KeyCode)

If KeyCode=KeyCodes.KEYCODE_BACK Then
   Txt = "Do you really want to Quit the Program ?"
   Answ=Msgbox2(Txt,"ATTENTION","Yes","","No",LoadBitmap(File.DirAssets,"quit.gif"))
   If Answ=DialogResponse.POSITIVE Then
      SQL.Close
           end if
end if
 
Last edited:
Upvote 0

timo

Active Member
Licensed User
Longtime User
sorry, but this way on 'second time' it remains closed. It happens when Android let your app resident in backgroud. If you never get the error, i think you're lucky:)

Try exit yor app and immediately reopen it. Do it four o five times.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I recommend you to close it only when UserClosed is True
Do I need to close the SQL object before I exit an app when I am immediately starting another application that opens the same database as the app I am exiting? If so, what do I need besides closing the cursor and: SQL1.Close
 
Upvote 0
Top