Going offline (Part 2)

In the prior article, I described a new approach for exchanging data with a server. In this article, I'll leverage this new approach to allow users to store data locally on their mobile device.

There are several ways to store local data on a mobile device. For applications with small amounts of data, both platforms provide a simple way to store and retrieve properties. In addition, if there's a need for larger amounts of non-relational data, each platform has a rich set of file IO routines. But when it comes to storing transactional data, and that data has a series of inter-relationships, the most appropriate form of persistence is a relational database.

In the past, most discussion regarding a relational database focused on large servers with huge storage drives. But over the years, a surprising number of ultra-small relational database management systems (RDBMS) have come into existence.

In the iOS / Android world, the RDBMS that comes built-in is SQLite ( http://www.sqlite.org/ ). Here are two key quotes from the web site:

  1. "SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine."
  2. "SQLite is a compact library. With all features enabled, the library size can be less than 500KiB ... If optional features are omitted, the size of the SQLite library can be reduced below 300KiB."

These two items are very important, because they illustrate that SQLite supports complex transactions and takes up less space than a 3.5" floppy disk. (Remember those?) With such powerful functions and such a small overhead cost, it makes sense to forget about trying to manipulate files manually, and simply use a relational database.

This article will focus on leveraging SQLite to implement offline storage for the FutileFishing app.