Mojo Storage Database

This page was created to help others by giving a basic example of creating a new database for your application and storing some data in it.

SQL Overview
It needs to be mentioned that SQLite (what HTML5 uses), is not as controlling as other databases. For one it's not going to give you an error when you insert text into an integer, or anything like that so regex all input for users or limit it in some way.

Creating a Database and a Table
In order to use non-anonymous event handlers, the function supplied to db.transaction has to be bound to the current context, as in the following, modified example:

openDatabase
If you try to look for MyDB on the filesystem, you won't find it. The openDatabase method creates an entry in the Databases table in /var/usr/home/root/html5-databases/Databases.db which points to the actual location of your database. Note that the details in the Databases table are what you specified in openDatabase except version. Version is contained in the __WebKitDatabaseInfoTable__ table in the actual database.

In the examples contained in this page, the database that is created has a maximum storage capacity of 1 MB. If you need a larger database, then append ext: to the beginning of the database name. For example:

This will create the database in /media/internal/.app-storage.

Inserting Multiple Rows
With asynchronous database methods, you can really screw things up if you try to do too many transacations in rapid succession. Luckily, you can run as many executeSql methods inside a single transaction as you need.

Retrieving Data
When a query returns results to the success handler, the rows are contained in .rows.

Extra Help
http://developer.apple.com/safari/library/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/UsingtheJavascriptDatabase/UsingtheJavascriptDatabase.html