13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with local SQL databases in AIR<br />

Defining the data type of SELECT result data<br />

Adobe AIR 1.0 and later<br />

By default, each row returned by a SELECT statem<strong>en</strong>t is created as an Object instance with properties named for the<br />

result set's column names and with the value of each column as the value of its associated property. However, before<br />

executing a SQL SELECT statem<strong>en</strong>t, you can set the itemClass property of the SQLStatem<strong>en</strong>t instance to a class. By<br />

setting the itemClass property, each row returned by the SELECT statem<strong>en</strong>t is created as an instance of the designated<br />

class. The runtime assigns result column values to property values by matching the column names in the SELECT result<br />

set to the names of the properties in the itemClass class.<br />

Any class assigned as an itemClass property value must have a constructor that does not require any parameters. In<br />

addition, the class must have a single property for each column returned by the SELECT statem<strong>en</strong>t. It is considered an<br />

error if a column in the SELECT list does not have a matching property name in the itemClass class.<br />

Retrieving SELECT results in parts<br />

Adobe AIR 1.0 and later<br />

By default, a SELECT statem<strong>en</strong>t execution retrieves all the rows of the result set at one time. Once the statem<strong>en</strong>t<br />

completes, you usually process the retrieved data in some way, such as creating objects or displaying the data on the<br />

scre<strong>en</strong>. If the statem<strong>en</strong>t returns a large number of rows, processing all the data at once can be demanding for the<br />

computer, which in turn will cause the user interface to not redraw itself.<br />

You can improve the perceived performance of your application by instructing the runtime to return a specific number<br />

of result rows at a time. Doing so causes the initial result data to return more quickly. It also allows you to divide the<br />

result rows into sets, so that the user interface is updated after each set of rows is processed. Note that it’s only practical<br />

to use this technique in asynchronous execution mode.<br />

To retrieve SELECT results in parts, specify a value for the SQLStatem<strong>en</strong>t.execute() method’s first parameter (the<br />

prefetch parameter). The prefetch parameter indicates the number of rows to retrieve the first time the statem<strong>en</strong>t<br />

executes. Wh<strong>en</strong> you call a SQLStatem<strong>en</strong>t instance’s execute() method, specify a prefetch parameter value and only<br />

that many rows are retrieved:<br />

var stmt:SQLStatem<strong>en</strong>t = new SQLStatem<strong>en</strong>t();<br />

stmt.sqlConnection = conn;<br />

stmt.text = "SELECT ...";<br />

stmt.addEv<strong>en</strong>tList<strong>en</strong>er(SQLEv<strong>en</strong>t.RESULT, selectResult);<br />

stmt.execute(20); // only the first 20 rows (or fewer) are returned<br />

The statem<strong>en</strong>t dispatches the result ev<strong>en</strong>t, indicating that the first set of result rows is available. The resulting<br />

SQLResult instance’s data property contains the rows of data, and its complete property indicates whether there are<br />

additional result rows to retrieve. To retrieve additional result rows, call the SQLStatem<strong>en</strong>t instance’s next() method.<br />

Like the execute() method, the next() method’s first parameter is used to indicate how many rows to retrieve the<br />

next time the result ev<strong>en</strong>t is dispatched.<br />

Last updated 6/6/2012<br />

741

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!