Android Question Database Install

Derek Jee

Active Member
Licensed User
Longtime User
Hi there

I install an SQLite db like this..

B4X:
If File.Exists (File.DirDefaultExternal ,"My.db") = False Then
File.Copy(File.DirAssets,"My.db",File.DirDefaultExternal ,"My.db")
end if

I always include the database with each install but want to be able to only copy from Dir.Assets if it has changed in structure. I understand you can't delete from Dir.Assets. Is there anywhere I can run this code which only runs on install? Any different advice is very welcome..

Kind regards,


Derek.
 

ac9ts

Active Member
Licensed User
Longtime User
Add a table to the database that has a version code in it. At program start, copy the file from DirAssets to a temporary name, open, read the code, compare it to the "My.db" code and act accordingly. Unless it's a HUGE file, this should execute pretty quickly where the user doesn't notice.
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
My thoughts exactly ;-) Thank you for the tip..
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
I was just thinking, you can just as easily put a file in the assets directory (along with the table in your database) where the file has the version code. Then you won't have to copy the entire database to open it. Just read the file and compare to the installed database version code.
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
So was I :))) I have put a field in my db with the number in it, and a corresponding number in my app code.. When the new version is issued then the app number will compare to the existing db field and if different then copy the dir.assets db into the dir.internal and open that one.. That'll work too I think.. thank you for your thoughts especially being a Friday afternoon..

D:)
 
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
thank you for your thoughts especially being a Friday afternoon..

Considering it was 7:50 AM (my time) when I came up with the first post.........I've got a while to wait for my afternoon ;)
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Well you've got the whole day ahead of you!! Hope it is a great one!!
 
Upvote 0
Top