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

id<strong>en</strong>tifier value as the foreign key column value just as you would with an explicitly declared INTEGER PRIMARY KEY<br />

column. In that s<strong>en</strong>se, if you are using an arbitrary primary key rather than a natural key, and as long as you don’t mind<br />

the runtime g<strong>en</strong>erating the primary key value for you, it makes little differ<strong>en</strong>ce whether you use an INTEGER PRIMARY<br />

KEY column or the system-g<strong>en</strong>erated row id<strong>en</strong>tifier as a table’s primary key for defining a foreign key relationship with<br />

betwe<strong>en</strong> two tables.<br />

For more information about primary keys and g<strong>en</strong>erated row id<strong>en</strong>tifiers, see “SQL support in local databases” on<br />

page 1093.<br />

Changing or deleting data<br />

Adobe AIR 1.0 and later<br />

The process for executing other data manipulation operations is id<strong>en</strong>tical to the process used to execute a SQL SELECT<br />

or INSERT statem<strong>en</strong>t, as described in “Working with SQL statem<strong>en</strong>ts” on page 728. Simply substitute a differ<strong>en</strong>t SQL<br />

statem<strong>en</strong>t in the SQLStatem<strong>en</strong>t instance’s text property:<br />

To change existing data in a table, use an UPDATE statem<strong>en</strong>t.<br />

To delete one or more rows of data from a table, use a DELETE statem<strong>en</strong>t.<br />

For descriptions of these statem<strong>en</strong>ts, see “SQL support in local databases” on page 1093.<br />

Working with multiple databases<br />

Adobe AIR 1.0 and later<br />

Use the SQLConnection.attach() method to op<strong>en</strong> a connection to an additional database on a SQLConnection<br />

instance that already has an op<strong>en</strong> database. You give the attached database a name using the name parameter in the<br />

attach() method call. Wh<strong>en</strong> writing statem<strong>en</strong>ts to manipulate that database, you can th<strong>en</strong> use that name in a prefix<br />

(using the form database-name.table-name) to qualify any table names in your SQL statem<strong>en</strong>ts, indicating to the<br />

runtime that the table can be found in the named database.<br />

You can execute a single SQL statem<strong>en</strong>t that includes tables from multiple databases that are connected to the same<br />

SQLConnection instance. If a transaction is created on the SQLConnection instance, that transaction applies to all SQL<br />

statem<strong>en</strong>ts that are executed using the SQLConnection instance. This is true regardless of which attached database the<br />

statem<strong>en</strong>t runs on.<br />

Alternatively, you can also create multiple SQLConnection instances in an application, each of which is connected to<br />

one or multiple databases. However, if you do use multiple connections to the same database keep in mind that a<br />

database transaction isn’t shared across SQLConnection instances. Consequ<strong>en</strong>tly, if you connect to the same database<br />

file using multiple SQLConnection instances, you can’t rely on both connections’ data changes being applied in the<br />

expected manner. For example, if two UPDATE or DELETE statem<strong>en</strong>ts are run against the same database through<br />

differ<strong>en</strong>t SQLConnection instances, and an application error occurs after one operation takes place, the database data<br />

could be left in an intermediate state that would not be reversible and might affect the integrity of the database (and<br />

consequ<strong>en</strong>tly the application).<br />

Last updated 6/6/2012<br />

748

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

Saved successfully!

Ooh no, something went wrong!