Check if you open the DB in Activity_Create under the FirstTime boolean evaluation.
If that is your case, bear in mind that FirstTime evaluates True only when the process (not the Activity) is executed for the "first time". This means that if you close an app and soon after that you launch it again, it is highly probable that the process is still in memory and FirstTime will return False.
Check if you open the DB in Activity_Create under the FirstTime boolean evaluation.
If that is your case, bear in mind that FirstTime evaluates True only when the process (not the Activity) is executed for the "first time". This means that if you close an app and soon after that you launch it again, it is highly probable that the process is still in memory and FirstTime will return False.
Thanks. I experience this, so I already change the structure. Now it runs every restart.
This is in my Activity Create now:
B4X:
If FirstTime Then
End If
If SQL1.IsInitialized = False Then
File.MakeDir(File.DirRootExternal,"XXXXXXX")
InitTable
SQL1.Initialize(FilePath, FileName, True, Wachtwoord, "")
SQLTableCreate
End If
I use SQLCypher if this could creates this problem.
If SQL1.IsInitialized = False Then
If Not(File.Exists(File.DirRootExternal,"XXXXXXX")) Then
File.MakeDir(File.DirRootExternal,"XXXXXXX")
InitTable
SQLTableCreate
End If
SQL1.Initialize(FilePath, FileName, False)
End If
B4X:
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
SQL1.Close 'if the user closes the program we close the database
End If
End Sub
Personally I wouldn't close the database. I would close the cursors, which I'm sure you do right after executing each SQL statement where a cursor is opened.
ETA : I do something like this
B4X:
If FirstTime = True Then
If File.Exists(File.DirInternal,"thedatabase.db") = False Then
'ToastMessageShow("Database hasn't been copied to read/write area",True)
'Msgbox("Database hasn't been copied to read/write area","Debug")
File.Copy(File.DirAssets,"themsc.db",File.DirInternal,"thedatabase.db")
End If
End If
If SQL1.IsInitialized = False Then
SQL1.Initialize(File.DirInternal,"thedatabase.db", True)
End If
I don't close the DB but as mentioned do close the cursors and end transaction if writing information to the DB. I also allow the PKs of User data to be written to a file and then the database reloaded if the DB is copied over anew. HTH
Personally I wouldn't close the database. I would close the cursors, which I'm sure you do right after executing each SQL statement where a cursor is opened.
1. If you do not close the database, what happens if you start a second application that uses the same database for instance graphing data from a table. If you open second application for the FirstTime, wouldn't that try to initialize the database and may produce an error since the database is already initialized by not being closed in the first application?
2. Suppose we have an open CURSOR1 and immediately create a new CURSOR1 using a different SQL statement. Would you still need to close the first one, or would the memory held by first one be released for the second instance.
In my applications, I have been closing CURSOR1 and SQL1 only whenever I finish with a given application. I have been getting away with it if it is not the proper way. I would like your opinion and others on this important topic.
Thank you
1. If you do not close the database, what happens if you start a second application that uses the same database for instance graphing data from a table. If you open second application for the FirstTime, wouldn't that try to initialize the database and may produce an error since the database is already initialized by not being closed in the first application?
2. Suppose we have an open CURSOR1 and immediately create a new CURSOR1 using a different SQL statement. Would you still need to close the first one, or would the memory held by first one be released for the second instance.
In my applications, I have been closing CURSOR1 and SQL1 only whenever I finish with a given application. I have been getting away with it if it is not the proper way. I would like your opinion and others on this important topic.
Thank you
Checking all apps utilizing db's reveals the cursor is created then closed after each query.. and the db finally closed prior to closing the app.
As I learn't SQl from B4a examples etc ,I just thought this is how it should be and have had no problems. Certainly don't have any
argument's / opinions as to the correct way.
Checking all apps utilizing db's reveals the cursor is created then closed after each query.. and the db finally closed prior to closing the app.
As I learn't SQl from B4a examples etc ,I just thought this is how it should be and have had no problems. Certainly don't have any
argument's / opinions as to the correct way.
This may be an incorrect behavior only in case of concurrency, in case of simultaneous access to a record by multiple users. If the database is local, in the device, this is fine.