Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Update local sqlite database with remote sqlite database

Hi All

I'm looking to update my app database with a newer version on a webserver.

Now im not sure what the best approach is. I have already made the decision to do it over a wifi connection as the new iPhone contracts in the UK are no longer unlimited data. Therefore I don't want people updating using there allocated amount of month data usage.

SO with that decision made, I'm looking to checking if a new database is available and they have a wifi connection. Then downloading the new database to replace the existing one on their iPhone.

Should i create a safety net by renaming the old database and renaming the new one to the correct name in case the connection drops. Then if the connect is broken revert back to the old database so there app still works?

Any thoughts or guidance about this would be great. Especially if anyone has done something similar.

Thanks in advance my friends

Mark

— asked July 1st 2010 by Mark Pierce
  • database
  • iphone
  • network
1 Comment
  • @mark, did you get this working? If so would you care to share what you have learnt? I am looking for the exact same solution, any pointers in the right direction would be appreciated.

    Thank you.

    — commented November 24th 2010 by Ian Tearle

2 Answers

  • The flow I would follow would be:

    • add the db to the project & a hash code to app.properties
    • query the server to see if there's a new version, passing the hash code
    • Server responds with a HTTP 304 if there's no change, otherwise HTTP 200, a header with the new hash & the database
    • hash the downloaded db and compare against the header hash
    • if both are the same - then the download was ok.
      • Close the connection to the DB if open
      • Rename the old db
      • Rename & move the new db to the right place.
      • Update the stored hash with the new value.
      • Open the DB again.
    • If both hashes aren't the same - there was an error.
      • Log the issue & inform the user
    — answered July 1st 2010 by David Ashwood
    permalink
    0 Comments
  • thank you for your quick reply! WOW! I think I will be reading and learning more about those suggestions tonight rather than developing :)

    I really value you response and thank you.

    gulp! ;)

    — answered July 1st 2010 by Mark Pierce
    permalink
    1 Comment
    • It's easier than it looks at first glance.
      Just work stepwise and then being all the pieces together :)

      — commented July 1st 2010 by David Ashwood
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.