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:

Please upgrade your Flash Player This is the content that would be shown if the user does not have Flash Player 9.0.115 or higher installed.


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.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • LinkedIn
  • StumbleUpon
  • Twitter
This entry was posted in Air, Flex, MAX, SQLite. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted November 26, 2008 at 11:51 am | Permalink

    Hey Chris, this is definitely a great idea! One could also put additional info beside the pic.

  2. pawel kaminski
    Posted January 19, 2009 at 12:46 pm | Permalink

    hej, I am using AIR and SQLite to develop some small app.

    I created db in sqliteSpy created all tables there and connected to it asynchronously. all selects statement that are not using group by or left join are executed well.

    OTHERWISE looking with debugger sqlresult.data seems to have all data I selected but when I try to trace them or assign to my valueobject all I have are null-s or NaN-s.

    I have posted the problem on 2 user group few days ago without respons

    http://groups.google.com/group/flex_india/browse_thread/thread/1da40062e78b32a6#

    maybe you can help me

  3. foxchx
    Posted May 2, 2009 at 4:35 am | Permalink

    I am all new to this, but have to create a directory in AIR, i was wondering if “insync” completely open source and can be used for commercial app. I do not know what are the copyright guide lines for this?

  4. Posted July 19, 2009 at 10:10 am | Permalink

    Hey Chris, this is definitely a great idea! One could also put additional info beside the pic.

  5. Posted October 14, 2009 at 5:41 pm | Permalink

    şk pğ hk

2 Trackbacks

  1. [...] first version of our contact management application introduced us to the database access API in AIR. However, the lack of “application [...]

  2. [...] Object (ContactDAO). This separation of concerns represented a major improvement compared to our first approach. The remaining limitation we identified was the amount of SQL we had to write [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>