Android Question Database Install

Discussion in 'Android Questions' started by Derek Jee, Aug 14, 2015.

  1. Derek Jee

    Derek Jee Active Member Licensed User

    Hi there

    I install an SQLite db like this..

    Code:
    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.
     
  2. ac9ts

    ac9ts Active Member Licensed 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.
     
  3. Derek Jee

    Derek Jee Active Member Licensed User

    My thoughts exactly ;-) Thank you for the tip..
     
  4. ac9ts

    ac9ts Active Member Licensed 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.
     
  5. Derek Jee

    Derek Jee Active Member Licensed 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:)
     
  6. ac9ts

    ac9ts Active Member Licensed User

    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 ;)
     
  7. Derek Jee

    Derek Jee Active Member Licensed User

    Well you've got the whole day ahead of you!! Hope it is a great one!!
     
Loading...
  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