Home  >  Development  >  blogs

AIR API - Retrieving Results from a Query

AddThis Social Bookmark Button
airLogo-Shadow.jpg

In the previous article, I examined the process for running a simple SELECT query on a pre-populated SQLite database in AIR. In today's example, I will actually execute a simple SELECT query and use the results to populate a data grid. I will also look at how to include a pre-populated database with an AIR application.

Retrieving Query Results

The query results can be retrieved from the instance of the SQLStatement class that was executed. They can be retrieved by calling the getResult of this instance. This will return an Array of results. The SQLEvent that is dispatched when the query is complete will contain a reference to the SQLStatement that fired it. You can get the results with this code:

var r:SQLResult = SQLStatement(event.target).getResult();

As you can see from the code, the value that is returned is of type SQLResult (link to documentation below). The data property of this class provides an Array of objects for your query results. This can be seen in the image below (which shows what the data property looks like inside of Flex Builder's variables view).

sqlresult-large.jpg
Figure 1. SQLResult Data

Including a Pre-Populated Database

If you need to include a database with your AIR application, the process is quite simple. You will need to follow these steps:

  1. Create your SQLite database with one of the tools mentioned in my first article in the series
  2. Place the file in your root source directory (the same directory as your application descriptor file).
  3. The file can now be referenced in the application directory (as shown earlier).

It would be a good idea to move the file to the application storage directory for each user (this directory is unique per user). To do this, you would simply need to check on launch to see if the file existed. If not, you could simply copy it over to the application storage directory. This is ideal especially if this data will be edited by the end user.

Sample Application

I have included a sample AIR application which includes a sample SQLite database of fake names and email addresses (generated by FakeNameGenerator.com). This table has 500 rows.

When the application launches, you will see a connect button enabled. When you click this button, it will connect to the database, and you can then click the query button. This will execute the sample query and populate the data grid below with the data from the query.

As always, View Source is enabled on this application (and you can also download the source below).



Application Source Code
Download (16.4 kb)

Reference

SQLResult [ ActionScript, JavaScript ]

Comments

1 Comments

reallypride said:

Read your article,better than read a lot of books

Leave a comment


Type the characters you see in the picture above.

Tag Cloud

Related Books

Development Series

Get an overview of the tools and technologies that work together to allow developers to build Rich Internet Applications (RIAs) quickly and easily.

Anatomy of an Enterprise Flex RIA

Archives


 
 


Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.

About Us
Meet the Experts
Meet Our Contributors
Send Us Feedback