Home >
One of the most powerful features in Adobe AIR is the native integration of SQLite that was introduced in Beta 2. Since Beta 2 it's integration has been improved, and it is now a viable local database capable of storing application data or syncing with a database server. The implementation provided with AIR is powerful and provides two distinctly different ways to access the database. There are nineteen different classes that can be used with this API, and in the next few articles I will dissect the ones that you need to know.
What is SQLite
SQLite is an open-source lightweight relational database system developed by D. Richard Hipp. SQLite differs from traditional server based databases in several ways. First, an SQLite database is completely self-contained in a single cross-platform file. This works well for AIR, because the same database file can work on a Windows, Mac, or Linux machine. Second, SQLite handles column types in a different manner. Essentially, SQLite types the fields as well as the columns. This allows fields in a column to be of different data types.
Asynchronous vs. Synchronous
As I mentioned earlier, there are two different modes in which you can use to connect to an SQLite database in AIR: synchronous and asynchronous.
Synchronous: This method requires much less code. With this method you don't have to use event handlers when retrieving data. If you have a method call below your database query, you can be sure that it will not execute until the query has been completed. This seems like a great thing, but a synchronous call will also keep any other methods from executing during your query. In this case, the user's experience is basically 'paused' during your query. To avoid this undesirable effect, you will need to use the asynchronous mode.
Asynchronous: This method will take more code. You will have to add event listeners and event handlers. The benefit is that the user experience will be uninterrupted during your query. This is ideal for most situations except for very simple instances.
For these tutorials I will be using asynchronous calls. If you can master the programming used with asynchronous calls, using synchronous calls will be very easy.
SQLite Administration Resources
There are many different tools that you can use to administer your SQLite databases. I have listed three of these below. You will need one of these tools for the upcoming tutorials. I use both of the first two that I have listed (and I had the third one recommended by another developer).
SQLite Admin AIR Application
SQLite Manager Firefox Extension
SQLite Database Browser
Next Tutorial: In the next article, I will cover connecting to a pre-existing database and executing a simple query on that database. As always let me know if you have any specific questions.





Facebook Application Development
Hey David,
This looks like it is going to turn out to be a good series of posts. SQLite is underused in my opinion. Most people I think just store information in a file and don't harness the power of SQLLite.
Also having SQLLite especially in AIR apps is going to be tremendous as when a client looses connectivity they can have a history to browse through, instead of disabling everything.
What do you think?
cheers,
Exactly. These are just a few of the uses that I believe developers will embrace with the integrated SQLite database.
I've used this in some projects, works like a charm. Never used sync with server database though but i think wont be much work either.
One issue that i see here is when you try to move the AIR application to lets say another computer. Right now you can't "package" the AIR application along with the database files and then simply install it on the other computer just as you install an AIR application.
Is that possible somehow right now ? Or will it be figured out in the future ?
Adrian
Hi David...
You spoiled us!!!! We want another great video tutorial series like Cairngorm not just post tutorial. I am sure you can do that for us!!!!
Cheers.....
@Adrian - Check out http://www.insideria.com/2008/04/air-api-retrieving-results-fro.html and let me know if the section on including a pre-populated database answers your question.
@Vivian - Who knows - I might be able to add a few video tutorials to this. I will do my best to work that in :)
Its great to know about AIR.Suppose i am packaging a html file and creaing desktop application,then hw can i connect it to database server not local db to my main server
if i am pakaging jsp pages hw can i sync with database server
hye...i'm interested in you article.but u didn't mention on how an application can save data in the database.for example,when user click the 'save' button,all the data in that application can be saved into the database.
@dieyana - There isn't an integrated way to save the application's model state at a given point in time, but rather AIR gives the developer the flexibility to add it in whatever way works best. I will be covering some ORM options for AIR in the upcoming weeks, and you might find those helpful!
Thanks for the comment.
Nice to know the difference between Asynchronous & Synchronous method, thanks