Database Not Copying

Bill Norris

Active Member
Licensed User
Longtime User
Am having complete success with my database except for one issue. It seems as though if I make edits to the database in the "Files" folder externally with sqlitebrowser, the updated database is not copying over when I use DBUtils.CopyDBFromAssets. I find that I first have to go into file manager and delete the existing copy of the database, and then I get a successful copy. I've tried eliminating the "if firsttime then" part in attempt to force the overwrite, but no success. What am I missing?

Thanks,
Bill
 

margret

Well-Known Member
Licensed User
Longtime User
Android protects from copying over live data, this is just the way it works. You should be able to do this however with: File.Copy ( File.DirAssets, "mydatabase.dat", File.DirInternal, "mydatabase.dat" ). This will erase any data that might of been entered in your database through your app.
 
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Hi Bill,

If your problem is how I understand it then I had the same issue. Investigating lead me to the DBUtils module. The 'CopyDBFromAssets' sub has this statement.

B4X:
If File.Exists(TargetDir, FileName) = False Then
      File.Copy(File.DirAssets, FileName, File.DirInternal, FileName)
   End If
This basically means that the DB will only be copied IF not previously copied. Therefore, won't update with new edits to original file.

To sort it out I 'quoted' out the If / End If lines. So that the file is copied each time. Once I have finished and have setup DB version checking I will re-instate the code to make more efficient. i.e. not copying the same unchanged file every time app is loaded.
 
Upvote 0
Top