A.11. Add History Window

The last step in this Appendix is to utilize the data stored in the SQLite database. To use the data, we will create a simple history window showing the last 10 results of the weather service for the zip code that is currently being used. We will also need to add some methods to the DataManager class to retrieve the history data. The data will be returned as a SQLResult object and then cast as an ArrayCollection and set into the DataModel's historyData property, which is bound to a DataGrid in the History.mxml Window component. Here are the steps needed to add the history window.

Add a new SQLStatement to the DataManager class.

private var selectHistorySQL:SQLStatement;

Add import statements to the DataManager class.

import flash.data.SQLResult;
import com.everythingflex.shared.model.DataModel;
import mx.collections.ArrayCollection;

Create an instance of the DataModel within the DataManager class to hold the results of the selectHistorySQL statement:

private var model:DataModel = DataModel.getInstance();

Next, add the getHistory() function to the DataManager class.

public function getHistory(zipCode:String):void{ var sqlText:String = "SELECT MAX(TEMPERATURE) AS HIGH, " + "ZIPCODE, WEATHERDATETIMESTAMP " + "FROM CALLS " + "WHERE ZIPCODE = :zipCode " + "GROUP BY WEATHERDATETIMESTAMP " + "ORDER BY ID DESC " + "LIMIT 10 "; selectHistorySQL = new SQLStatement(); selectHistorySQL.sqlConnection = conn; selectHistorySQL.addEventListener(SQLEvent.RESULT,getHistoryResult); ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.