SQLite in Flex MobileWhen working with local data in mobile applications you might want to consider a SQLite database. Those are especially useful when working with large amount of data that you want to filter at runtime. Flex Mobile projects can simply take advantage of SQLite support in the Adobe AIR runtime. You could certainly write it from scratch - meaning you create a File instance and SQLConnection, set up event listeners, wait for the connection to open and set up a SQLStatement with a SQL query and more event listeners.

For most uses though there is a much easier approach using some simple SQLite wrapper classes myself and Robert Turrall wrote a while ago.


Just to illustrate how easy these wrapper classes make things for you when writing Flex Mobile projects look at the code below. These two lines do everything you need to open a connection to your database file and select all the records.

[cc lang="mxml"]


You can see that using the open event on the SQLite tag we can wire it up to automatically run the query that selects all the records from our database.

The only thing left to do is pass the result of the database query to a component to display it in our mobile application. In this case I'll be using a List component and assigning the data property of the query instance when the result event fires

[cc lang="mxml"]

import mx.collections.ArrayCollection;

private function onSelectResult():void { data_list.dataProvider = new ArrayCollection(select_query.data); }