This is old.. My app uses a SQLite database. I need to update the structure and with new data within. If the user is already has the application the new database if not used.

This is old.. My app uses a SQLite database. I need to update the structure and with new data within. If the user is already has the application the new database if not used.
Here is the point: if Android is using TPath.GetDocumentsPath do store the file, where is it exactly? Does the OS makes a copy to another folder, so after an upgrade it will try to preserve the original data?
Since old version of Delphi keep the Overwrite for file at Deployment option won't work.
I could make a script to alter data and insert the new information, but it will cost time and will require more in-code work. How can I simply delete the any persistent file there?
Thank you!

Comments

  1. Put in your code a constant number.
    In project uses clause is a unit. I think it's named StartUpCopy. You need to put a unit before this. In this unit you will verify in the initialization section if this number is in some ini file or something.
    If it's not you will delete your database and write that number in the ini file.
    StartUpCopy will see that database file is not there and it will copy it from apk.
    Next time you need to deploy a new database you only need to modify that number.

    ReplyDelete
  2. Maybe it would be nice to have o column in the deployment list named Version. And StartUpCopy to overwrite your old file with new if Version on the device is older than in apk.
    But that means StartUpCopy to keep this version numbers somewhere on the device...

    ReplyDelete
  3. Cristian Peța Thank you, I will search for that. Never listened about before. I know that Java uses a similar method to Android.
    So far I made a by-hand solution. As I already had a config table and a field with the database version now I check for it as the very first instruction. If it less that app now requires I do the following:
    read the close and delete the old database, get getPackageReourcePath info about the apk and unzip the database.
    CODE:

    procedure TDM.UnpackNewDatabase;
    var
    Zip: TZipFile;
    PackageName: JString;
    begin

    SQLConnection.Connected := False;

    PackageName := SharedActivityContext.getPackageResourcePath;

    if TFile.Exists(JStringToString(PackageName)) then
    begin

    TFile.Delete(TPath.GetHomePath + PathDelim + DATABASENAME);
    Zip := TZipFile.Create;
    Zip.Open(JStringToString(PackageName), TZipMode.zmRead);
    Zip.Extract('assets/internal/' + DATABASENAME, TPath.GetDocumentsPath, False);
    Zip.Close;
    Zip.free;
    end;
    SQLConnection.Connected := True;
    end;

    ReplyDelete

Post a Comment