O'Reilly logo

Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime by Rich Tretola

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required