Database in AIR – Async Access

As my recent explorations into AIR, I decided to take a look at using DataBases with AIR. AIR runtime comes with an embedded SQLLite DataBase. You have the flexibility of opening a DB on the file system or if required, you can even start an in-memory DB that lasts only for a single session (you could potentially use this to store periodic data that gets generated due-course the session and then query it)

A lot of others have done examples on this, but I’ll post mine nonetheless. These examples are using the Asyncronous way of updation, which mean that I’m writing listeners at each point to know if the connection has been established, SQL statement executed…etc

Anyone who has a very basic knowledge of SQL and have used it any language (I have some experience in Java) will find the AS way as intuitive as their own language APIs. Here are the basic classes used

  • A SQLConnection object to establish the connection to the DB
  • A SQLStatement object to which you need to put in your SQL Query
  • When the SQLStatement is executed, it generates one of the following
    • A SQLErrorEvent if the statement fails on execute
    • A SQLEvent.RESULT if the execute is successful
  • A SQLResult that can be got by invoking the getResult() method on the SQLStatement, once the execution is successful

It is possible to do a synchronous way of accessing DB in AIR, I’ll discuss that later. But this time its async access of DB. There are 2 examples one with a in-memory DB and other where the DB is on the file-system itself. I have abstracted the AS code into a separate file and reused it for both the examples.

ExternalDBExample | InMemoryDBExample

AsyncDBScript (AS File) – contains the AS Code


2 Responses to Database in AIR – Async Access

  1. Ravi Chandra says:

    ExternalDBExample | InMemoryDBExample

    AsyncDBScript (AS File) – contains the AS Code

    Link are broken

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s