Android Question Sqlite Synchronization question ...

Discussion in 'Android Questions' started by little3399, Apr 9, 2015.

  1. little3399

    little3399 Active Member Licensed User

    Hi, everybody...

    I have a question about sqlite db synchronization ...
    Usually I will copy to sqlite db file to the File.DirDefaultExternal Dir ... but sometime the app maybe to
    upgade and the some sqlite db table structure will be change ... So in this case how to synchronization
    the new sqlite db and the old sqlite db ?
    in fact, our synchroniztion method was to uninstall the old app first ,and install the new app ...
    I want to ask .... Is the any good advice to synchronization sqlite db ? Tks!
  2. sorex

    sorex Expert Licensed User

    is it just a database to consult data?
  3. eurojam

    eurojam Well-Known Member Licensed User

    Hey Little,
    I usually have a table dbVersion in my sqlite database and proof the dbversion on the device against the needed version of the app (when the app starts). If the app needs a newer version, for example after updating the app, the new DB will be copied from File.DirAssets to File.DirDefaultExternal or File.DirInternal...

    may be there are better ways to make this, but this works for my apps

  4. little3399

    little3399 Active Member Licensed User

    Hi, eurojam
    the new DB copy from File.DirAssets , because the File.DirAssets was read-only ,so the the new DB will always be as the new DB ... so every time the APP start ... will copy from File.DirAssets ...
  5. eurojam

    eurojam Well-Known Member Licensed User

    No, the new DB carried out with the new App Version has the version code 23 (for example). Starting the app the Activity_Create will do the following things:
    • look if the is a database in the File.DirInternal: if not, no problem, copy the database from File.DirAssets and continue with the app
    • if there is already a database then check the version:
    txt = "SELECT * from dbversion where dbversion = 23;"
        Cursor1 = SQL1.ExecQuery(txt)
    If Cursor1.RowCount = 0 Then
    'database is older, now copy new version to File.DirInternal and continue the app
        End If
    This will only happen, if the the existing database is older
  6. little3399

    little3399 Active Member Licensed User

    HI, Eurojam

    I have been found the simple way to solve this promble, that is let the sqlite db name same as the VersionName, such as when the App versionname update to 2.2 , so
    the sqlite db alse change to db2_2.db , and the sqlite db can be placed on the File.DirAssert.... when the App can not found the db2_2.db file, and just to copy it from
    File.DirAsset ... that means the app using the new db ...:)
    eurojam likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice