Not yet rated

Problem

By default, all items returned from an SQLStatement call are generic objects.

Solution

By using the itemClass property of the SQLStatement class, you can define the data type of the values returned from a SQLStatement call.

Detailed explanation

By default SQLResult returns all of your data as generic objects.  This is less than ideal, because it leaves the developer to loop over each item and convert it manually to the desired data type. AIR has the capability to return strongly-typed values to you as well. To do this, you need to use the itemClass property of the SQLStatement class. However, you should consider the following:

"Any class assigned to this property must have a constructor that does not require any parameters. In addition, the class must have a single property for each column returned by the SELECT statement. It is considered an error if a column in the SELECT list does not have a matching property name in the itemClass class."
(excerpt from the AIR Documentation)

If your data type meets those requirements, it is as easy as just pointing the itemClass property to that class:

ActionScript:
// Import the Needed Class
import vo.Conctact;...
// Set the itemClass Property
query.itemClass = Contact;

sqlite2.zip
[Sample Application Files]

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes