Jump to content
Fudley

Delphi 11, Android, deploy .db file, will not overwrite previous

Recommended Posts

I am trying to deploy a prepared .db file (sqlite) with my app.

 

I have included the file ( fudley.db ) in the deployment list as follows:

 

-local path being the development folder where the app is built (i.e. blank)

-local name is fudley.db

-remote path being "assets\internal\"

-Overwrite set to always

 

the rest of the settings are default.

 

However it is never overwritten. If I add new data to the .db file, and build the APK and run it, the data on the target phone is still the same.  Uninstall the app on the target phone and reinstall = same results.  Clear the apps cache and data on the target phone = no change.

 

Any thoughts?

Share this post


Link to post
2 hours ago, Fudley said:

However it is never overwritten

Overwrite can be somewhat misleading. It refers to what happens when the file is deployed from the local file to the application package, not whether the file is overwritten when the app starts - this process occurs in the System.StartUpCopy unit (in the rtl\common folder of the Delphi source), and as evidenced by line 83 (at least in Delphi 12.1):

  if not FileExists(DestFileName) then //do not overwrite files

..when the files are put in their final destination, if the file exists it is not overwritten. A couple of possible workarounds:

 

1. Patch the System.StartUpCopy unit so that it does overwrite 


2. Use files with "versioned" filenames, e.g. fudley-1.0.0.db, and replace the entry in the deployment with the new version. In your apps startup code, look for files using pattern matching, e.g:

uses
  System.IOUtils;

procedure TForm1.FormCreate(Sender: TObject);
var
  LDBFiles: TArray<string>;
begin
  LDBFiles := TDirectory.GetFiles(TPath.GetDocumentsPath, 'fudley-*.db', TSearchOption.soTopDirectoryOnly);
  // If there's only ever one file, it should be the value in LDBFiles[0], so rename that to fudley.db 
end;

 

Share this post


Link to post

That's some great info - thanks so much! I esp like option #2.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×