April 2008
Beginner
350 pages
8h 21m
English
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.
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); ... |
Read now
Unlock full access