A.5. Integrate SQLite
Since AIR has the ability to easily integrate with SQLite, we can use a database to store some of the data that are retrieved from the weather service. These data will be utilized in a later portion of this Appendix. To handle all of the interactions with the SQLite database, we will use a DataManager class. Create a new ActionScript class named DataManager.as within the com.everythingflex.air.managers package, and enter the contents of Listing A-3.
Example A-3. The DataManager class
package com.everythingflex.air.managers { import flash.data.SQLConnection; import flash.filesystem.File; import flash.events.SQLErrorEvent; import flash.events.SQLEvent; import flash.data.SQLStatement; import flash.filesystem.FileStream; import flash.filesystem.FileMode; import flash.data.SQLResult; import mx.collections.ArrayCollection; import com.everythingflex.shared.model.DataModel; public class DataManager { private var conn:SQLConnection; private var createTableStatement:SQLStatement; private var insertStatement:SQLStatement; private var selectHistorySQL:SQLStatement; // open or create the database public function openDatabase():void { conn = new SQLConnection(); conn.addEventListener(SQLErrorEvent.ERROR, errorHandler); var dbFile:File = File.applicationStorageDirectory.resolvePath("WeatherAIR.db" ); if (dbFile.exists) { conn.addEventListener(SQLEvent.OPEN, openHandler); } else { conn.addEventListener(SQLEvent.OPEN, createHandler); } conn.openAsync(dbFile); ... |
Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.