Using the SQLite Database Access API in AIR… Part 1

In my MAX session called “Liberate your Data with AIR”, I presented different approaches to access local data using the SQLite database access API in AIR.

The list of approaches included:

  1. “SQL in View”
  2. Data Access Object (DAO) pattern
  3. Using an Object Relational Mapping (ORM) framework

I demonstrated a version of inSync (a simple contact management application) built with each of these approaches. I’m dedicating one blog post to each approach. This first post is focused on the “SQL in View” approach. To spice things up just a little bit, inSync also demosntrates how to take a picture of a contact using your webcam and store it in the SQLite database as a blob.

Install inSync Local SQL Edition:
[airbadge]inSyncLocalSQL, http://coenraets.org/apps/insync/inSyncLocalSQL.air, v1, http://coenraets.org/apps/insync/insync1.png[/airbadge]

NOTE: this application uses the same skin and overall context as a sample I posted previously to illustrate offline data synchronization using LCDS, but the implementation is entirely different: No LCDS here… just local data access.

Click here to download the source code. You can also right-click the app and select View Source to view the source code and download the application.

Using the “SQL in View” approach, you embed SQL statements as needed in View components. In this example the ContactForm component has create, update, and delete methods with the appropriate embedded SQL statements to insert, update, and delete a contact in the database. This approach works for quick prototyping, but is generally a bad practice. When you mix view logic and data access logic in the same component, neither the view logic, nor the data access logic is reusable: you can’t reuse the view with a different way to access your data, and you can’t reuse your data access logic with a different view.

I provide this approach here as a quick way to get acquainted with the database access API in AIR. For real life implementations, a more partitioned approach such as the DAO pattern or an ORM framework is of course highly recommended. Stay tuned for an example of approaches 2 and 3.

css.php