title: Offline/Online Database Authentication/Synchronization from jQuery Mobile
body: <p><strong>The Situation:</strong> I have a database and a web app that interact to display and update tables of scientific data. My task is to construct a mobile application that will allow users to </p>
  
  <ol>
  <li>Authenticate and Identify Themselves Offline for Tracking Purposes 
  (using predefined but dynamic user-accounts and permissions stored in the cache)</li>
  <li>Download Identification Data for Work in the Field (with internet access)</li>
  <li>Make and Store Observations in the Field (without internet access)</li>
  <li>Synchronize Observations into an Online Database at a later time </li>
  </ol>
  
  <p><strong>The Question:</strong> What is the best way to go about authenticating/downloading/storing/uploading the necessary data to administer such an application independent of consistent internet access? If two people adjust the same reading, and one update happens in between syncs, how do I track which tables and values have been altered, and prevent the changes from being lost?</p>
  
  <p><strong>The Current Train of Thought:</strong> My current tentative strategy on collision control to maintain a "Sync" table that stores JSON objects representing every online database transaction stored in sessionStorage and have the app continuously verifying its sync prior to uploading data, and checking this object for potential collisions on updates to specific primary keys. I would like to be able to lock tuples when they are in an editing stage, but that seems impossible with inconsistent internet access. </p>
  
  <p>Sorry if this is a bit of a newb question, I'm new to the whole mobile app development thing... </p>
  
  <p><strong>tl;dr</strong> How do I prevent asynchronous changes to the database from mobile apps that go on and offline from overwriting/colliding with another individual's changes to the same database? And how do I authenticate users w/o a network connection?</p>