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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

SQL support in local databases<br />

The LIMIT clause places an upper bound on the number of rows returned in the result. A negative LIMIT indicates<br />

no upper bound. The optional OFFSET following LIMIT specifies how many rows to skip at the beginning of the result<br />

set. In a compound SELECT query, the LIMIT clause may only appear after the final SELECT statem<strong>en</strong>t, and the limit<br />

is applied to the <strong>en</strong>tire query. Note that if the OFFSET keyword is used in the LIMIT clause, th<strong>en</strong> the limit is the first<br />

integer and the offset is the second integer. If a comma is used instead of the OFFSET keyword, th<strong>en</strong> the offset is the<br />

first number and the limit is the second number. This seeming contradiction is int<strong>en</strong>tional — it maximizes<br />

compatibility with legacy SQL database systems.<br />

A compound SELECT is formed from two or more simple SELECT statem<strong>en</strong>ts connected by one of the operators<br />

UNION, UNION ALL, INTERSECT, or EXCEPT. In a compound SELECT, all the constitu<strong>en</strong>t SELECT statem<strong>en</strong>ts<br />

must specify the same number of result columns. There can only be a single ORDER BY clause after the final SELECT<br />

statem<strong>en</strong>t (and before the single LIMIT clause, if one is specified). The UNION and UNION ALL operators combine<br />

the results of the preceding and following SELECT statem<strong>en</strong>ts into a single table. The differ<strong>en</strong>ce is that in UNION, all<br />

result rows are distinct, but in UNION ALL, there may be duplicates. The INTERSECT operator takes the intersection<br />

of the results of the preceding and following SELECT statem<strong>en</strong>ts. EXCEPT takes the result of preceding SELECT after<br />

removing the results of the following SELECT. Wh<strong>en</strong> three or more SELECT statem<strong>en</strong>ts are connected into a<br />

compound, they group from first to last.<br />

For a definition of permitted expressions, see Expressions.<br />

Starting with AIR 2.5, the SQL CAST operator is supported wh<strong>en</strong> reading to convert BLOB data to ActionScript<br />

ByteArray objects. For example, the following code reads raw data that is not stored in the AMF format and stores it<br />

in a ByteArray object:<br />

stmt.text = "SELECT CAST(data AS ByteArray) AS data FROM pictures;";<br />

stmt.execute();<br />

var result:SQLResult = stmt.getResult();<br />

var bytes:ByteArray = result.data[0].data;<br />

INSERT<br />

The INSERT statem<strong>en</strong>t comes in two basic forms and is used to populate tables with data.<br />

sql-statem<strong>en</strong>t ::= INSERT [OR conflict-algorithm] INTO [database-name.] table-name [(columnlist)]<br />

VALUES (value-list) |<br />

INSERT [OR conflict-algorithm] INTO [database-name.] table-name [(columnlist)]<br />

select-statem<strong>en</strong>t<br />

REPLACE INTO [database-name.] table-name [(column-list)] VALUES (value-list) |<br />

REPLACE INTO [database-name.] table-name [(column-list)] select-statem<strong>en</strong>t<br />

The first form (with the VALUES keyword) creates a single new row in an existing table. If no column-list is specified<br />

th<strong>en</strong> the number of values must be the same as the number of columns in the table. If a column-list is specified, th<strong>en</strong><br />

the number of values must match the number of specified columns. Columns of the table that do not appear in the<br />

column list are filled with the default value defined wh<strong>en</strong> the table is created, or with NULL if no default value is<br />

defined.<br />

The second form of the INSERT statem<strong>en</strong>t takes its data from a SELECT statem<strong>en</strong>t. The number of columns in the<br />

result of the SELECT must exactly match the number of columns in the table if column-list is not specified, or it must<br />

match the number of columns named in the column-list. A new <strong>en</strong>try is made in the table for every row of the SELECT<br />

result. The SELECT may be simple or compound. For a definition of allowable SELECT statem<strong>en</strong>ts, see SELECT.<br />

The optional conflict-algorithm allows the specification of an alternative constraint conflict resolution algorithm to<br />

use during this one command. For an explanation and definition of conflict algorithms, see “Special statem<strong>en</strong>ts and<br />

clauses” on page 1103.<br />

Last updated 6/6/2012<br />

1096

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

Saved successfully!

Ooh no, something went wrong!