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 />

For a network-aware application, a database can be used to store a local cache of application data, or to store data<br />

temporarily wh<strong>en</strong> a network connection isn’t available. You could create a mechanism for synchronizing the local<br />

database with the network data store.<br />

For any application, a database can be used to store individual users’ application settings, such as user options or<br />

application information like window size and position.<br />

More Help topics<br />

Christophe Co<strong>en</strong>raets: Employee Directory on AIR for Android<br />

Raymond Camd<strong>en</strong>: jQuery and AIR - Moving from web page to application<br />

About AIR databases and database files<br />

Adobe AIR 1.0 and later<br />

An individual Adobe AIR local SQL database is stored as a single file in the computer’s file system. The runtime<br />

includes the SQL database <strong>en</strong>gine that manages creation and structuring of database files and manipulation and<br />

retrieval of data from a database file. The runtime does not specify how or where database data is stored on the file<br />

system; rather, each database is stored completely within a single file. You specify the location in the file system where<br />

the database file is stored. A single AIR application can access one or many separate databases (that is, separate<br />

database files). Because the runtime stores each database as a single file on the file system, you can locate your database<br />

as needed by the design of your application and file access constraints of the operating system. Each user can have a<br />

separate database file for their specific data, or a database file can be accessed by all application users on a single<br />

computer for shared data. Because the data is local to a single computer, data is not automatically shared among users<br />

on differ<strong>en</strong>t computers. The local SQL database <strong>en</strong>gine doesn’t provide any capability to execute SQL statem<strong>en</strong>ts<br />

against a remote or server-based database.<br />

About relational databases<br />

Adobe AIR 1.0 and later<br />

A relational database is a mechanism for storing (and retrieving) data on a computer. Data is organized into tables:<br />

rows repres<strong>en</strong>t records or items, and columns (sometimes called “fields”) divide each record into individual values.<br />

For example, an address book application could contain a “fri<strong>en</strong>ds” table. Each row in the table would repres<strong>en</strong>t a<br />

single fri<strong>en</strong>d stored in the database. The table’s columns would repres<strong>en</strong>t data such as first name, last name, birth date,<br />

and so forth. For each fri<strong>en</strong>d row in the table, the database stores a separate value for each column.<br />

Relational databases are designed to store complex data, where one item is associated with or related to items of<br />

another type. In a relational database, any data that has a one-to-many relationship—where a single record can be<br />

related to multiple records of a differ<strong>en</strong>t type—should be divided among differ<strong>en</strong>t tables. For example, suppose you<br />

want your address book application to store multiple phone numbers for each fri<strong>en</strong>d; this is a one-to-many<br />

relationship. The “fri<strong>en</strong>ds” table would contain all the personal information for each fri<strong>en</strong>d. A separate “phone<br />

numbers” table would contain all the phone numbers for all the fri<strong>en</strong>ds.<br />

In addition to storing the data about fri<strong>en</strong>ds and phone numbers, each table would need a piece of data to keep track<br />

of the relationship betwe<strong>en</strong> the two tables—to match individual fri<strong>en</strong>d records with their phone numbers. This data is<br />

known as a primary key—a unique id<strong>en</strong>tifier that distinguishes each row in a table from other rows in that table. The<br />

primary key can be a “natural key,” meaning it’s one of the items of data that naturally distinguishes each record in a<br />

table. In the “fri<strong>en</strong>ds” table, if you knew that none of your fri<strong>en</strong>ds share a birth date, you could use the birth date<br />

column as the primary key (a natural key) of the “fri<strong>en</strong>ds” table. If there isn’t a natural key, you would create a separate<br />

primary key column such as a “fri<strong>en</strong>d id” —an artificial value that the application uses to distinguish betwe<strong>en</strong> rows.<br />

Last updated 6/6/2012<br />

714

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

Saved successfully!

Ooh no, something went wrong!