flash.dataSQLViewSchema A SQLViewSchema instance provides information describing a specific view in a database.flash.data:SQLTableSchema A SQLViewSchema instance provides information describing a specific view in a database. It contains the name of the view (the name property), the SQL statement used to create the view (the sql property), and information about the view's columns (the columns property).

To obtain view schema information for a database, use the SQLConnection.loadSchema() method to load the schema information, making certain to use null or SQLViewSchema for the type argument's value. In the resulting SQLSchemaResult instance, the views property contains an array of SQLViewSchema instances representing the views in the database.

Generally, developer code does not construct SQLViewSchema instances directly.

flash.data.SQLConnection.loadSchema()flash.data.SQLColumnSchemaSQLViewSchema Creates a SQLViewSchema instance.databaseStringThe name of the associated database. nameStringThe name of the view. sqlStringThe SQL statement used to create the view. columnsArrayArray of SQLColumnSchema instances describing this view's columns. Creates a SQLViewSchema instance. Generally, developer code does not call the SQLViewSchema constructor directly. To obtain schema information for a database, call the SQLConnection.loadSchema() method.
SQLColumnSchema The SQLColumnSchema class provides information describing the characteristics of a specific column within a table in a database.Object The SQLColumnSchema class provides information describing the characteristics of a specific column within a table in a database.

To obtain column schema information for one or more tables in a database, use the SQLConnection.loadSchema() method to load the schema information, making certain to use true for the includeColumnSchema argument's value. In the resulting SQLSchemaResult instance, each table and view definition includes a columns property — an array of SQLColumnSchema instances representing the columns in the table or view.

Generally, developer code does not construct SQLColumnSchema instances directly.

flash.data.SQLConnection.loadSchema()flash.data.SQLTableSchemaflash.data.SQLViewSchemaSQLColumnSchema Constructs a SQLColumnSchema instance.nameStringThe name of the column. primaryKeyBooleanIndicates whether this column is a part of the primary key for the associated table. allowNullBooleanIndicates whether this column can contain NULL values. autoIncrementBooleanIndicates whether this is an auto increment column. dataTypeStringThe declared type of the column. defaultCollationTypeStringThe collation sequence defined for this column. This value corresponds to one of the constants in the SQLCollationType class:
  • SQLCollationType.BINARY indicates that the column uses the BINARY collation sequence.
  • SQLCollationType.NO_CASE indicates that the column uses the NOCASE collation sequence, meaning text comparisons are made in a case-insensitive manner.
Constructs a SQLColumnSchema instance. Generally, developer code does not call the SQLColumnSchema constructor directly. To obtain schema information for a database, call the SQLConnection.loadSchema() method.
flash.data.SQLConnection.loadSchema()flash.data.SQLCollationType
allowNull Indicates whether NULL values are allowed in this column.Boolean Indicates whether NULL values are allowed in this column. A column that is declared with a NOT NULL constraint has a false value for the allowNull property. autoIncrement Indicates whether this is an auto-increment column.Boolean Indicates whether this is an auto-increment column. An auto-increment column is a special type of PRIMARY KEY column whose value is automatically generated as the next value in a sequence of integers when a new row is inserted into the table. dataType Gets the data type of the column as a string.String Gets the data type of the column as a string. The value is the literal data type name that was specified in the CREATE TABLE statement that was used to define the table, or null if no data type was specified. defaultCollationType Indicates the default collation sequence that is defined for this column.String Indicates the default collation sequence that is defined for this column. The value of this property corresponds to one of the constants in the SQLCollationType class:
  • SQLCollationType.BINARY indicates that the column uses the BINARY collation sequence.
  • SQLCollationType.NO_CASE indicates that the column uses the NOCASE collation sequence, meaning that text comparisons are made in a case-insensitive manner.
flash.data.SQLCollationType
name Gets the name of the column.String Gets the name of the column. primaryKey Indicates whether this column is the primary key column (or one of the primary key columns in a composite key) for its associated table.Boolean Indicates whether this column is the primary key column (or one of the primary key columns in a composite key) for its associated table.
SQLColumnNameStyle This class contains the constants that represent the possible values for the SQLConnection.columnNameStyle property.Object This class contains the constants that represent the possible values for the SQLConnection.columnNameStyle property. These values indicate different options that control how column names (property names) are formatted in the objects returned as a result of a SQL SELECT statement. flash.data.SQLConnection.columnNameStyleDEFAULT Indicates that column names returned from a SELECT statement use the default format.defaultString Indicates that column names returned from a SELECT statement use the default format. In the default format, column names have the form [table-name]_[column-name] when multiple tables are included in the SELECT statement, or [column-name] when the SELECT statement includes a single table. flash.data.SQLConnection.columnNameStyleLONG Indicates that column names returned from a SELECT statement use long-column-name format.longString Indicates that column names returned from a SELECT statement use long-column-name format. In this format, column names use the form [table-name]_[column-name] regardless of how many tables are included in the SELECT statement. flash.data.SQLConnection.columnNameStyleSHORT Indicates that column names returned from a SELECT statement use short-column-name format.shortString Indicates that column names returned from a SELECT statement use short-column-name format. In this format, column names use the form [column-name], regardless of how many tables are included in the SELECT statement.

If the result set contains multiple columns with the same name, only one property with that name is added to the result object. The value assigned to that property is taken from the last column with that name in the result row. For example, consider the following SELECT statement:

	 SELECT customers.customerId, addresses.customerId
	 FROM customers INNER JOIN addresses
	    ON customers.customerId = addresses.customerId
	 

When this statement is executed on a SQLConnection instance with short column name format, each result object has a property named customerId, containing the value from the addresses table's customerId column.

flash.data.SQLConnection.columnNameStyle
SQLSchema The SQLSchema class is the base class for schema information for database objects such as tables, views, and indices.Object The SQLSchema class is the base class for schema information for database objects such as tables, views, and indices.

To obtain schema information for a database, use the SQLConnection.loadSchema() method to load the schema information. The resulting SQLSchemaResult instance contains arrays of instances representing the objects in the database.

Generally, developer code does not construct SQLSchema instances directly.

flash.data.SQLConnection.loadSchema()SQLSchema Creates a SQLSchema instance.databaseStringThe name of the associated database. nameStringThe name of the database object. sqlStringThe SQL used to construct the database object. Creates a SQLSchema instance. Generally, developer code does not call the SQLSchema constructor directly. To obtain schema information for a database, call the SQLConnection.loadSchema() method. database The name of the database to which this schema object belongs.String The name of the database to which this schema object belongs. The name is "main" for the main database associated with a SQLConnection instance (the database file that is opened by calling a SQLConnection instance's open() or openAsync() method). For other databases that are attached to the connection using the SQLConnection.attach() method, the value is the name specified in the attach() method call. flash.data.SQLConnection.open()flash.data.SQLConnection.openAsync()flash.data.SQLConnection.attach()name The name of this schema object.String The name of this schema object. Each object within a database has a unique name. The name is defined in the SQL statement that creates the object (such as the CREATE TABLE statement for a table).

For example, if a database index is created using the following SQL statement, the value of the name property for that index's schema would be "customer_index":

CREATE INDEX customer_index ON customers (id)
sql Returns the entire text of the SQL statement that was used to create this schema object.String Returns the entire text of the SQL statement that was used to create this schema object. Each object within a database is created using a SQL statement.

For example, if a database index is created using the following SQL:

CREATE INDEX customer_index ON customers (id)

the sql property for that index's schema would be the entire text of the statement.

SQLCollationType This class contains the constants that represent the possible values for the defaultCollationType parameter of the SQLColumnSchema constructor, as well as the SQLColumnSchema.defaultCollationType property.Object This class contains the constants that represent the possible values for the defaultCollationType parameter of the SQLColumnSchema constructor, as well as the SQLColumnSchema.defaultCollationType property.

These values represent different collation sequences that can be specified for a column in a database table. A collation sequence is a way of sorting and comparing data, for example whether the database differentiates between uppercase and lowercase characters.

For more information about defining and using collation sequences, see the "COLLATE" section in the appendix "SQL support in local databases."

flash.data.SQLColumnSchema.defaultCollationTypeBINARY Indicates that the column is defined to use the BINARY collation sequence.binaryString Indicates that the column is defined to use the BINARY collation sequence. A SQLCollationType.BINARY collation compares two values using their byte values, regardless of the text encoding of the characters.

When binary collation is used with values of the TEXT storage class, the database differentiates between uppercase and lowercase characters when sorting and comparing the column's values.

flash.data.SQLColumnSchema.defaultCollationType
NO_CASE Indicates that the column is defined to use the NOCASE collation sequence.noCaseString Indicates that the column is defined to use the NOCASE collation sequence. A SQLCollationType.NO_CASE collation ignores uppercase and lowercase differences when sorting and comparing two values. flash.data.SQLColumnSchema.defaultCollationType
SQLSchemaResult A SQLSchemaResult instance contains the information resulting from a call to the SQLConnection.loadSchema() method.Object A SQLSchemaResult instance contains the information resulting from a call to the SQLConnection.loadSchema() method. It contains four Array properties that hold the requested schema data, based on the argument values used when calling SQLConnection.loadSchema().

To retrieve the SQLSchemaResult instance for a SQLConnection.loadSchema() call, call the SQLConnection instance's getSchemaResult() method. Generally, developer code does not create SQLSchemaResult instances directly.

flash.data.SQLConnection.loadSchema()flash.data.SQLConnection.getSchemaResult()SQLSchemaResult Creates a SQLSchemaResult instance.tablesArrayAn array of SQLTableSchema instances as specified in the loadSchema() request. viewsArrayAn array of SQLViewSchema instances as specified in the loadSchema() request. indicesArrayAn array of SQLIndexSchema instances as specified in the loadSchema() request. triggersArrayAn array of SQLTriggerSchema instances as specified in the loadSchema() request. Creates a SQLSchemaResult instance. Generally, developer code does not call the SQLSchemaResult constructor directly. To obtain schema information for a database, call the SQLConnection.loadSchema() method. flash.data.SQLConnection.loadSchema()indices An array of SQLIndexSchema instances requested in a call to SQLConnection.loadSchema().Array An array of SQLIndexSchema instances requested in a call to SQLConnection.loadSchema(). If the specified databases do not contain any indices, or if the loadSchema() call specifies to exclude indices from the result, the indices property is an empty array (an array whose length property is 0). flash.data.SQLConnection.loadSchema()flash.data.SQLIndexSchematables An array of SQLTableSchema instances requested in a call to SQLConnection.loadSchema().Array An array of SQLTableSchema instances requested in a call to SQLConnection.loadSchema(). If the specified databases do not contain any tables, or if the loadSchema() call specifies to exclude tables from the result, the tables property is an empty array (an array whose length property is 0). flash.data.SQLConnection.loadSchema()flash.data.SQLTableSchematriggers An array of SQLTriggerSchema instances requested in a call to SQLConnection.loadSchema().Array An array of SQLTriggerSchema instances requested in a call to SQLConnection.loadSchema(). If the specified databases do not contain any triggers, or if the loadSchema() call specifies to exclude triggers from the result, the triggers property is an empty array (an array whose length property is 0). flash.data.SQLConnection.loadSchema()flash.data.SQLTriggerSchemaviews An array of SQLViewSchema instances requested in a call to SQLConnection.loadSchema().Array An array of SQLViewSchema instances requested in a call to SQLConnection.loadSchema(). If the specified databases do not contain any views, or if the loadSchema() call indicates that views should be excluded from the result, the views property is an empty array (an array whose length property is 0). flash.data.SQLConnection.loadSchema()flash.data.SQLViewSchema
SQLTransactionLockType This class contains the constants that represent the possible values for the option parameter of the SQLConnection.begin() method.Object This class contains the constants that represent the possible values for the option parameter of the SQLConnection.begin() method. flash.data.SQLConnection.begin()DEFERRED Specifies the deferred locking transaction option.deferredString Specifies the deferred locking transaction option. A deferred-lock transaction does not acquire a lock on the database until the database is first accessed. With a deferred transaction, a lock is not acquired until the first read or write operation. flash.data.SQLConnection.begin()EXCLUSIVE Specifies the exclusive locking transaction option.exclusiveString Specifies the exclusive locking transaction option. An exclusive-locked transaction acquires a lock on the database immediately. Other SQLStatement objects executing against the same database through a different SQLConnection (in the same AIR application or a different one) can't read data from or write data to the database. flash.data.SQLConnection.begin()IMMEDIATE Specifies the immediate locking transaction option.immediateString Specifies the immediate locking transaction option. An immediate-locked transaction acquires a lock on the database immediately. SQLStatement objects executing against the same database through a different SQLConnection (in the same AIR application or a different one) can read data from the database but can't write data to it. However, for those other connections reading data from the database, the initial state of the data in the database is identical to the state of the database before the in-transaction SQLConnection instance's begin() method was called. Any uncommitted data changes made within the immediate-locked transaction are not available to the other connections. flash.data.SQLConnection.begin()SQLConnection A SQLConnection instance is used to manage the creation of and connection to local SQL database files (local databases).flash.events:EventDispatcher A SQLConnection instance is used to manage the creation of and connection to local SQL database files (local databases).

The functionality of the SQLConnection class falls into several categories:

  • A local SQL database file is created or opened by calling the open() method or the SQLConnection instance to the SQLStatement's sqlConnection property.

  • The SQLConnection class also provides state for SQL statements, including a mechanism for executing multiple statements in a transaction. Transactions are managed using the begin(), commit(), and rollback() methods. In addition, the setSavepoint(), releaseSavepoint(), and rollbackToSavepoint() methods allow code to define and manage savepoints. These are used to subdivide transactions into sets of operations.

  • The SQLConnection class provides access to database schema information for connected databases. A database's schema describes the definitions of its tables, columns, indices, and triggers. See the loadSchema() method for more information.

  • The SQLConnection class provides the ability to encrypt databases using AES with CCM. This provides both authentication and privacy for data. To encrypt a database, a 16 byte key (specified using a ByteArray) must be specified when the database is created. This key can later be changed using the SQLConnection.reencrypt() method. Encryption imposes a performance penalty on writes to and reads from the database. Encryption is applied to data stored on the disk, but not to a temporary data cache in memory. Encryption is not supported for in-memory databases.

  • A SQLConnection instance can be used to receive database-level event notifications and provide configuration control for all aspects of a database, including cache page size, process canceling, and statement execution options.

A SQLConnection instance operates in one of two distinct execution modes: asynchronous and synchronous. To use synchronous execution, you use the open() method to connect to the main database for the SQLConnection instance. To use asynchronous execution, use the openAsync() method to connect to the main database for the instance.

When you're using asynchronous execution, you use event listeners or a Responder instance to determine when an operation completes or fails. The operations run in the background rather than in the main application thread, so the application continues to run and respond to user interaction even while the database operations are being performed. Each asynchronous SQLConnection instance executes SQL statements in its own thread.

In asynchronous execution mode, you begin a specific operation by calling the appropriate method, and you can detect the completion (or failure) of the operation by registering a listener for the appropriate event. Each operation has an associated event that is dispatched when the operation completes successfully; for example, when an openAsync() method call completes successfully (when the database connection is opened) the open event is dispatched. When any operation fails, an error event is dispatched. The SQLError instance in the SQLErrorEvent object's error property contains information about the specific error, including the operation that was being attempted and the reason the operation failed.

When you're using synchronous execution, you do not need to register event listeners to determine when an operation completes or fails. To identify errors, enclose the error-throwing statements in a try..catch block. Because synchronous operations execute in the main execution thread, all application functionality (including refreshing the screen and allowing mouse and keyboard interaction) is paused while the database operation or operations are performed. For long-running operations this can cause a noticeable pause in the application.

flash.data.SQLStatementflash.events.SQLEventflash.events.SQLErrorEventflash.errors.SQLErrorQuick Start: Working asynchronously with a local SQL database (Flex)Quick Start: Working asynchronously with a local SQL database (Flash)Quick Start: Working asynchronously with a local SQL database (HTML)Quick Start: Working synchronously with a local SQL database (Flex)Quick Start: Working synchronously with a local SQL database (Flash)Quick Start: Working synchronously with a local SQL database (HTML)update Dispatched when data in any table in any of the connected databases changes as a result of a SQL UPDATE command.flash.events.SQLUpdateEvent.UPDATEflash.events.SQLUpdateEvent Dispatched when data in any table in any of the connected databases changes as a result of a SQL UPDATE command. The data change can be a direct result of a UPDATE statement executed through a SQLStatement instance, or an indirect result caused by a trigger firing in response to a statement execution. flash.data.SQLStatementsetSavepoint Dispatched when a setSavepoint() method call's operation completes successfully.flash.events.SQLEvent.SET_SAVEPOINTflash.events.SQLEvent Dispatched when a setSavepoint() method call's operation completes successfully. setSavepoint()schema Dispatched when a loadSchema() method call's operation completes successfully and the schema results are ready.flash.events.SQLEvent.SCHEMAflash.events.SQLEvent Dispatched when a loadSchema() method call's operation completes successfully and the schema results are ready. loadSchema()rollbackToSavepoint Dispatched when a rollbackToSavepoint() method call's operation completes successfully.flash.events.SQLEvent.ROLLBACK_TO_SAVEPOINTflash.events.SQLEvent Dispatched when a rollbackToSavepoint() method call's operation completes successfully. rollbackToSavepoint()rollback Dispatched when a rollback() method call's operation completes successfully.flash.events.SQLEvent.ROLLBACKflash.events.SQLEvent Dispatched when a rollback() method call's operation completes successfully. rollback()releaseSavepoint Dispatched when a releaseSavepoint() method call's operation completes successfully.flash.events.SQLEvent.RELEASE_SAVEPOINTflash.events.SQLEvent Dispatched when a releaseSavepoint() method call's operation completes successfully. releaseSavepoint()reencrypt Dispatched when a reencrypt() method call's operation completes successfully.flash.events.SQLEvent.REENCRYPTflash.events.SQLEvent Dispatched when a reencrypt() method call's operation completes successfully. reencrypt()open Dispatched when an openAsync() method call's operation completes successfully.flash.events.SQLEvent.OPENflash.events.SQLEvent Dispatched when an openAsync() method call's operation completes successfully. openAsync()insert Dispatched when data in any table in any of the connected databases changes as a result of a SQL INSERT command.flash.events.SQLUpdateEvent.INSERTflash.events.SQLUpdateEvent Dispatched when data in any table in any of the connected databases changes as a result of a SQL INSERT command. The data change can be a direct result of an INSERT statement executed through a SQLStatement instance, or an indirect result caused by a trigger firing in response to a statement execution. flash.data.SQLStatementerror Dispatched when any of the SQLConnection object's asynchronous operations results in an error.flash.events.SQLErrorEvent.ERRORflash.events.SQLErrorEvent Dispatched when any of the SQLConnection object's asynchronous operations results in an error. The SQLErrorEvent instance that's dispatched as the event object has an error property that contains information about the operation that was attempted and the cause of the failure. detach Dispatched when a detach() method call's operation completes successfully.flash.events.SQLEvent.DETACHflash.events.SQLEvent Dispatched when a detach() method call's operation completes successfully. detach()delete Dispatched when data in any table in any of the connected databases changes as a result of a SQL DELETE command.flash.events.SQLUpdateEvent.DELETEflash.events.SQLUpdateEvent Dispatched when data in any table in any of the connected databases changes as a result of a SQL DELETE command. The data change can be a direct result of a DELETE statement executed through a SQLStatement instance, or an indirect result caused by a trigger firing in response to a statement execution. flash.data.SQLStatementdeanalyze Dispatched when a deanalyze() method call's operation completes successfully.flash.events.SQLEvent.DEANALYZEflash.events.SQLEvent Dispatched when a deanalyze() method call's operation completes successfully. deanalyze()commit Dispatched when a commit() method call's operation completes successfully.flash.events.SQLEvent.COMMITflash.events.SQLEvent Dispatched when a commit() method call's operation completes successfully. commit()close Dispatched when a close() method call's operation completes successfully.flash.events.SQLEvent.CLOSEflash.events.SQLEvent Dispatched when a close() method call's operation completes successfully. close()compact Dispatched when a compact() method call's operation completes successfully.flash.events.SQLEvent.COMPACTflash.events.SQLEvent Dispatched when a compact() method call's operation completes successfully. compact()cancel Dispatched when a cancel() method call's operation completes successfully.flash.events.SQLEvent.CANCELflash.events.SQLEvent Dispatched when a cancel() method call's operation completes successfully. cancel()begin Dispatched when a begin() method call's operation completes successfully.flash.events.SQLEvent.BEGINflash.events.SQLEvent Dispatched when a begin() method call's operation completes successfully. begin()attach Dispatched when an attach() method call's operation completes successfully.flash.events.SQLEvent.ATTACHflash.events.SQLEvent Dispatched when an attach() method call's operation completes successfully. attach()analyze Dispatched when an analyze() operation completes successfully.flash.events.SQLEvent.ANALYZEflash.events.SQLEvent Dispatched when an analyze() operation completes successfully. analyze()SQLConnection Creates a SQLConnection instance.if constructor is called from any sandbox outside of the main application sandbox. SecurityErrorSecurityError Creates a SQLConnection instance. addEventListener Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.typeStringThe type of event. listenerFunctionThe listener function that processes the event. This function must accept an Event object as its only parameter and must return nothing, as this example shows: function(evt:Event):void

The function can have any name.

useCaptureBooleanfalse Determines whether the listener works in the capture phase or the target and bubbling phases. If useCapture is set to true, the listener processes the event only during the capture phase and not in the target or bubbling phase. If useCapture is false, the listener processes the event only during the target or bubbling phase. To listen for the event in all three phases, call addEventListener twice, once with useCapture set to true, then again with useCapture set to false. priorityint0.0The priority level of the event listener. The priority is designated by a signed 32-bit integer. The higher the number, the higher the priority. All listeners with priority n are processed before listeners of priority n-1. If two or more listeners share the same priority, they are processed in the order in which they were added. The default priority is 0. useWeakReferenceBooleanfalseDetermines whether the reference to the listener is strong or weak. A strong reference (the default) prevents your listener from being garbage-collected. A weak reference does not.

Class-level member functions are not subject to garbage collection, so you can set useWeakReference to true for class-level member functions without subjecting them to garbage collection. If you set useWeakReference to true for a listener that is a nested inner function, the function will be garbage-collected and no longer persistent. If you create references to the inner function (save it in another variable) then it is not garbage-collected and stays persistent.

Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. You can register event listeners on all nodes in the display list for a specific type of event, phase, and priority.

After you successfully register an event listener, you cannot change its priority through additional calls to addEventListener(). To change a listener's priority, you must first call removeListener(). Then you can register the listener again with the new priority level.

Keep in mind that after the listener is registered, subsequent calls to addEventListener() with a different type or useCapture value result in the creation of a separate listener registration. For example, if you first register a listener with useCapture set to true, it listens only during the capture phase. If you call addEventListener() again using the same listener object, but with useCapture set to false, you have two separate listeners: one that listens during the capture phase and another that listens during the target and bubbling phases.

You cannot register an event listener for only the target phase or the bubbling phase. Those phases are coupled during registration because bubbling applies only to the ancestors of the target node.

If you no longer need an event listener, remove it by calling removeEventListener(), or memory problems could result. Event listeners are not automatically removed from memory because the garbage collector does not remove the listener as long as the dispatching object exists (unless the useWeakReference parameter is set to true).

Copying an EventDispatcher instance does not copy the event listeners attached to it. (If your newly created node needs an event listener, you must attach the listener after creating the node.) However, if you move an EventDispatcher instance, the event listeners attached to it move along with it.

If the event listener is being registered on a node while an event is being processed on this node, the event listener is not triggered during the current phase but can be triggered during a later phase in the event flow, such as the bubbling phase.

If an event listener is removed from a node while an event is being processed on the node, it is still triggered by the current actions. After it is removed, the event listener is never invoked again (unless registered again for future processing).

analyze Gathers statistics about database indices and stores them in the database.When this method is called while the SQLConnection instance isn't connected to a database (the connected property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorif the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrorresourceNameStringnullThe name of the database or table whose indices are to be analyzed. If the specified resource is a table whose name is unique among all the attached databases, only the table name needs to be specified. However, a table name can be specified in the form [database-name].[table-name] to prevent ambiguity when the table name is not unique. If the resourceName parameter is null (the default), all the indices in all attached databases are analyzed. responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null an analyze or error event is dispatched when execution completes. Gathers statistics about database indices and stores them in the database. These statistics can then be used by the query optimizer (the portion of the database engine that determines the most efficient way to execute each statement). The statistics help the query optimizer make better choices about which index or indices to use when executing a particular query.

If a database has indices defined, but the analyze() method hasn't been called, the runtime still uses those indices to execute statements. However, without the additional statistical information generated by the analyze() method, the runtime may not choose the most efficient index for a particular query.

When a table's data changes (as a result of INSERT, UPDATE, or DELETE statements) the indices associated with that table change as well. The statistical information generated by analyze() is not automatically updated. Consequently, after a large number of data changes, calling the analyze() method again might be beneficial. However, the benefit obtained from calling analyze() again depends on several factors, including the number of indices defined on a table, the relationship between the number of changed rows and the total number of rows in the table, how much variation there is in the table's indexed data, and how different the changed data is from the prechange data.

The resourceName parameter indicates whether the operation is performed on the indices of all attached databases, a specific database, or a specific table.

Each time this method is called, any previously created statistical data is purged and recreated for the database or table specified in the resourceName parameter (or all tables in all connected databases if resourceName is null). This method can be called at any time while a database connection is open. The analyze() operation and its statistical data are not included in a transaction; however, it is best not to call analyze() when the database has a current transaction (the inTransaction property is true). This is because any data, table schema, or index changes that have been executed in the transaction but not yet committed are not taken into account by the analyze() call, and the analyze() data is out of date as soon as the transaction is committed.

To remove the statistical data created with the analyze() method, use the deanalyze() method.

deanalyze()analyzeflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
attach Adds another database to the SQLConnection instance, giving the new database the specified name.When the name parameter is an empty string ("") or null ArgumentErrorArgumentErrorWhen the value specified for the reference parameter is not a flash.filesystem.File instance ArgumentErrorArgumentErrorWhen the encryptionKey argument is not null and its length is not 16 bytes ArgumentErrorArgumentErrorWhen the reference parameter is null and the encryptionKey argument is not null ArgumentErrorArgumentErrorWhen the SQLConnection instance isn't connected to a database (the connected property is false); or if a transaction is currently open (the inTransaction property is true). IllegalOperationErrorflash.errors:IllegalOperationErrorif the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrornameStringThe name that is used to identify the newly attached database. This name can be used in SQL statements to explicitly indicate that a table belongs to the specified database, when using the format [database-name].[table-name]. The names "main" and "temp" are reserved and cannot be used. referenceObjectnullA reference to the database file to attach (a flash.filesystem.File instance). If the reference refers to a file that doesn't exist, either a new database file is created or an error is thrown according to the value that was specified for the openMode parameter in the open() or openAsync() call that connected the main database.

If the parameter's value is null, an in-memory database is created and attached.

responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null an attach or error event is dispatched when execution completes. encryptionKeyflash.utils:ByteArraynullThe encryption key for the database file. If the attach() call creates a database, the database is encrypted and the specified key is used as the encryption key for the database. If the call attaches an existing encrypted database, the value must match the database's encryption key or an error occurs. If the database being attached is not encrypted, or to create an unencrypted database, the value must be null (the default).

A valid encryption key is 16 bytes long. An in-memory database cannot be encrypted, so this parameter must be null when the reference parameter's value is null.

When attaching an encrypted database, if the encryption key provided doesn't match the database's encryption key, an exception occurs. In synchronous execution mode, a SQLError exception is thrown. In asynchronous execution mode, a SQLErrorEvent is dispatched, and the event object's error property contains a SQLError instance. In either case, the SQLError object's errorID property is 3138 ("File opened is not a database file").

The encryptionKey parameter is available starting with AIR 1.5.

Adds another database to the SQLConnection instance, giving the new database the specified name. Attaching a database allows that database to be used in SQL statements executed against this SQLConnection instance.

If a database is already attached using the specified name, calling attach() results in an error. However, the same database may be attached multiple times using unique names. Only ten databases can be attached to a single SQLConnection instance.

Any SQL statement can be executed on a database connected using attach() that can be executed on the main database (the database connected using open() or openAsync()). A SQL statement can access tables in any of the databases attached to the statement's associated SQLConnection instance, including accessing tables from multiple databases in a single statement. When the runtime is resolving table names in a statement, it searches through the SQLConnection instance's databases in the order in which the databases were attached, starting with the database that was connected using the open() or openAsync() method. Use the database name (as specified in the attach() method's name parameter) in the statement to explicitly qualify a table name.

To remove a database attached using the attach() method, use the detach() method. When the SQLConnection instance is closed (by calling the close() method), all attached databases are detached.

The attached database uses the same execution mode (synchronous or asynchronous) as the main database, depending on whether the main database was connected using the open() method or the openAsync() method.

open()openAsync()detach()attachflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
begin Begins a transaction within which all SQL statements executed against the connection's database or databases are grouped.When this method is called while the SQLConnection instance isn't connected to a database (the connected property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the option specified is not one of the SQLTransactionLockType constants. ArgumentErrorArgumentErrorif the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErroroptionStringnullIndicates the locking strategy that is used by the transaction. The value can be one of the constants defined in the SQLTransactionLockType class:
  • SQLTransactionLockType.DEFERRED indicates that a lock is not acquired until the first read or write operation.
  • SQLTransactionLockType.EXCLUSIVE indicates that a lock is acquired as soon as possible, and no other SQLConnection instance can read from or write to the database.
  • SQLTransactionLockType.IMMEDIATE indicates that a lock is acquired as soon as possible, in which other SQLConnection instances can read from but can't write to the database.

The default value (null) is equivalent to SQLTransactionLockType.DEFERRED.

responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a begin or error event is dispatched when execution completes.
Begins a transaction within which all SQL statements executed against the connection's database or databases are grouped.

By default, each SQL statement is executed within its own transaction, and the transaction ends when the statement's execution succeeds or fails. Creating a transaction using the begin() method causes a new, manual transaction to be created. From that point on, all SQL statements executed against the SQLConnection instance take place within the transaction, and any actions or modifications performed by the statements can be committed (made permanent) or rolled back (undone) as a group.

To end a transaction, call the commit() or rollback() method, depending on whether the changes made by the transactions' statements are to be made permanent or discarded.

Nested calls to begin() are ignored. You can create savepoints, which are like bookmarks within a transaction, by calling the setSavepoint() method. You can then partially commit or roll back SQL statements by calling the releaseSavepoint() or rollbackToSavepoint() methods. However, if a transaction is started by calling begin(), changes are not permanently committed to the database until the commit() method is called.

If the database connection closes while a transaction is currently open, AIR rolls back the transaction automatically. (Note: for AIR 1.1 and previous versions, an open transaction is automatically committed when a connection closes.)

A transaction is not limited to statement executions in a single database; it can include statements executed on different attached databases.

The following example demonstrates executing multiple SQL INSERT statements within a transaction. First a row is added to the "employees" table. Next the primary key of the newly inserted row is retrieved, and used to add a row to the related "phoneNumbers" table. package { import flash.data.SQLConnection; import flash.data.SQLResult; import flash.data.SQLStatement; import flash.display.Sprite; import flash.events.SQLErrorEvent; import flash.events.SQLEvent; import flash.filesystem.File; public class MultiInsertTransactionExample extends Sprite { private var conn:SQLConnection; private var insertEmployee:SQLStatement; private var insertPhoneNumber:SQLStatement; public function MultiInsertTransactionExample():void { // define where to find the database file var appStorage:File = File.applicationStorageDirectory; var dbFile:File = appStorage.resolvePath("ExampleDatabase.db"); // open the database connection conn = new SQLConnection(); conn.addEventListener(SQLErrorEvent.ERROR, errorHandler); conn.addEventListener(SQLEvent.OPEN, openHandler); conn.openAsync(dbFile); } // Called when the database is connected private function openHandler(event:SQLEvent):void { conn.removeEventListener(SQLEvent.OPEN, openHandler); // start a transaction conn.addEventListener(SQLEvent.BEGIN, beginHandler); conn.begin(); } // Called when the transaction begins private function beginHandler(event:SQLEvent):void { conn.removeEventListener(SQLEvent.BEGIN, beginHandler); // create and execute the first SQL statement: // insert an employee record insertEmployee = new SQLStatement(); insertEmployee.sqlConnection = conn; insertEmployee.text = "INSERT INTO employees (lastName, firstName, email) " + "VALUES (:lastName, :firstName, :email, :birthday)"; insertEmployee.parameters[":lastName"] = "Smith"; insertEmployee.parameters[":firstName"] = "Bob"; insertEmployee.parameters[":email"] = "bsmith@example.com"; insertEmployee.parameters[":birthday"] = new Date(1971, 8, 12); insertEmployee.addEventListener(SQLEvent.RESULT, insertEmployeeHandler); insertEmployee.addEventListener(SQLErrorEvent.ERROR, errorHandler); insertEmployee.execute(); } // Called after the employee record is inserted private function insertEmployeeHandler(event:SQLEvent):void { insertEmployee.removeEventListener(SQLEvent.RESULT, insertEmployeeHandler); insertEmployee.removeEventListener(SQLErrorEvent.ERROR, errorHandler); // Get the employee id of the newly created employee row var result:SQLResult = insertEmployee.getResult(); var employeeId:Number = result.lastInsertRowID; // Add a phone number to the related phoneNumbers table insertPhoneNumber = new SQLStatement(); insertPhoneNumber.sqlConnection = conn; insertPhoneNumber.text = "INSERT INTO phoneNumbers (employeeId, type, number) " + "VALUES (:employeeId, :type, :number)"; insertPhoneNumber.parameters[":employeeId"] = employeeId; insertPhoneNumber.parameters[":type"] = "Home"; insertPhoneNumber.parameters[":number"] = "(555) 555-1234"; insertPhoneNumber.addEventListener(SQLEvent.RESULT, insertPhoneNumberHandler); insertPhoneNumber.addEventListener(SQLErrorEvent.ERROR, errorHandler); insertPhoneNumber.execute(); } // Called after the phone number record is inserted private function insertPhoneNumberHandler(event:SQLEvent):void { insertPhoneNumber.removeEventListener(SQLEvent.RESULT, insertPhoneNumberHandler); insertPhoneNumber.removeEventListener(SQLErrorEvent.ERROR, errorHandler); // No errors so far, so commit the transaction conn.addEventListener(SQLEvent.COMMIT, commitHandler); conn.commit(); } // Called after the transaction is committed private function commitHandler(event:SQLEvent):void { conn.removeEventListener(SQLEvent.COMMIT, commitHandler); trace("Transaction complete"); } // Called whenever an error occurs private function errorHandler(event:SQLErrorEvent):void { // If a transaction is happening, roll it back if (conn.inTransaction) { conn.addEventListener(SQLEvent.ROLLBACK, rollbackHandler); conn.rollback(); } trace(event.error.message); trace(event.error.details); } // Called when the transaction is rolled back private function rollbackHandler(event:SQLEvent):void { conn.removeEventListener(SQLEvent.ROLLBACK, rollbackHandler); // add additional error handling, close the database, etc. } } } The following example demonstrates executing multiple SQL DELETE statements within a transaction. The transaction is used to delete an employee record. First the related rows in the "phoneNumbers" table are deleted. Next the employee record row is deleted from the "employees" table. package { import flash.data.SQLConnection; import flash.data.SQLResult; import flash.data.SQLStatement; import flash.display.Sprite; import flash.events.SQLErrorEvent; import flash.events.SQLEvent; import flash.filesystem.File; public class MultiDeleteTransactionExample extends Sprite { private var conn:SQLConnection; private var deleteEmployee:SQLStatement; private var deletePhoneNumbers:SQLStatement; private var employeeIdToDelete:Number = 25; public function MultiDeleteTransactionExample():void { // define where to find the database file var appStorage:File = File.applicationStorageDirectory; var dbFile:File = appStorage.resolvePath("ExampleDatabase.db"); // open the database connection conn = new SQLConnection(); conn.addEventListener(SQLErrorEvent.ERROR, errorHandler); conn.addEventListener(SQLEvent.OPEN, openHandler); conn.openAsync(dbFile); } // Called when the database is connected private function openHandler(event:SQLEvent):void { conn.removeEventListener(SQLEvent.OPEN, openHandler); // start a transaction conn.addEventListener(SQLEvent.BEGIN, beginHandler); conn.begin(); } // Called when the transaction begins private function beginHandler(event:SQLEvent):void { conn.removeEventListener(SQLEvent.BEGIN, beginHandler); // Create and execute the first SQL statement: // Delete an employee's phone number records deletePhoneNumbers = new SQLStatement(); deletePhoneNumbers.sqlConnection = conn; deletePhoneNumbers.text = "DELETE FROM phoneNumbers " + "WHERE employeeId = :employeeId"; deletePhoneNumbers.parameters[":employeeId"] = employeeIdToDelete; deletePhoneNumbers.addEventListener(SQLEvent.RESULT, deletePhoneNumbersHandler); deletePhoneNumbers.addEventListener(SQLErrorEvent.ERROR, errorHandler); deletePhoneNumbers.execute(); } // Called after the phone number records are deleted private function deletePhoneNumbersHandler(event:SQLEvent):void { deletePhoneNumbers.removeEventListener(SQLEvent.RESULT, deletePhoneNumbersHandler); deletePhoneNumbers.removeEventListener(SQLErrorEvent.ERROR, errorHandler); deleteEmployee = new SQLStatement(); deleteEmployee.sqlConnection = conn; deleteEmployee.text = "DELETE FROM employees " + "WHERE employeeId = :employeeId"; deleteEmployee.parameters[":employeeId"] = employeeIdToDelete; deleteEmployee.addEventListener(SQLEvent.RESULT, deleteEmployeeHandler); deleteEmployee.addEventListener(SQLErrorEvent.ERROR, errorHandler); deleteEmployee.execute(); } // Called after the employee record is deleted private function deleteEmployeeHandler(event:SQLEvent):void { deleteEmployee.removeEventListener(SQLEvent.RESULT, deleteEmployeeHandler); deleteEmployee.removeEventListener(SQLErrorEvent.ERROR, errorHandler); // No errors so far, so commit the transaction conn.addEventListener(SQLEvent.COMMIT, commitHandler); conn.commit(); } // Called after the transaction is committed private function commitHandler(event:SQLEvent):void { conn.removeEventListener(SQLEvent.COMMIT, commitHandler); trace("Transaction complete"); } // Called whenever an error occurs private function errorHandler(event:SQLErrorEvent):void { // If a transaction is happening, roll it back if (conn.inTransaction) { conn.addEventListener(SQLEvent.ROLLBACK, rollbackHandler); conn.rollback(); } trace(event.error.message); trace(event.error.details); } // Called when the transaction is rolled back private function rollbackHandler(event:SQLEvent):void { conn.removeEventListener(SQLEvent.ROLLBACK, rollbackHandler); // add additional error handling, close the database, etc. } } }
commit()rollback()setSavepoint()releaseSavepoint()rollbackToSavepoint()flash.data.SQLTransactionLockTypebeginflash.events:SQLEventDispatched when the operation completes. Dispatched when the operation completes.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
cancel Aborts all SQL statements that are currently executing on databases connected to the SQLConnection instance.When this method is called while the SQLConnection instance isn't connected to a database (the connected property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrorresponderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a cancel or error event is dispatched when execution completes. Aborts all SQL statements that are currently executing on databases connected to the SQLConnection instance. This method can be used to stop long running or runaway queries.

If there are statements executing when the cancel() method is called, this method aborts the statements' operations and any incomplete updates or transactions are rolled back. If there are no statements currently executing, calling this method rolls back an open transaction but otherwise does nothing.

flash.data.SQLStatementcancelflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
close Closes the current database connection.If the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrorresponderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a close or error event is dispatched when execution completes. Closes the current database connection. Any attached databases are detached as well.

If there is an open transaction when close() is called, the transaction is rolled back. When a SQLConnection instance is garbage-collected, the runtime calls close() automatically, including if an AIR application is closed while a SQLConnection is still connected to a database.

closeflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
commit Commits an existing transaction, causing any actions performed by the transaction's statements to be permanently applied to the database.When the method is called while the SQLConnection instance isn't connected to a database (the connected property is false); or if no transaction is currently open (the inTransaction property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorresponderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a commit or error event is dispatched when execution completes. Commits an existing transaction, causing any actions performed by the transaction's statements to be permanently applied to the database.

Intermediate savepoints, which are like bookmarks in a transaction, can be created by calling the setSavepoint() method. Using savepoints you can commit portions of a transaction by calling the releaseSavepoint() method, or roll back portions of a transaction by calling the rollbackToSavepoint() method. However, if a transaction is opened using the begin() method, changes are not permanently saved to the database until the entire transaction is committed by calling the commit() method.

For a transaction that uses savepoints, any statements that were rolled back using the rollbackToSavepoint() method are not committed when the entire transaction is committed. Statements that were committed using releaseSavepoint() or whose savepoints weren't released or rolled back are committed to the database.

begin()rollback()setSavepoint()releaseSavepoint()rollbackToSavepoint()commitflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation completes with a failure. Dispatched when the operation completes with a failure.
compact Reclaims all unused space in the database.If the method is called while the SQLConnection instance isn't connected to a database (the connected property is false); or if a transaction is currently in progress (the inTransaction property is true). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrorresponderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a compact or error event is dispatched when execution completes. Reclaims all unused space in the database. When an object (table, index, or trigger) is dropped from the database, it leaves behind empty space. This makes the database file larger than it needs to be, but can speed up INSERT operations. Over time, INSERT and DELETE operations can leave the database file structure fragmented, which slows down disk access to the database contents. This method compacts the database file, eliminating free pages, aligning table data to be contiguous, and otherwise cleaning up the database file structure.

The compact() operation can't be performed on an attached database file; it can only be performed on the main (original) database file opened by the SQLConnection instance. This operation fails if there is an active transaction, and has no effect on an in-memory database.

compactflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
deanalyze Removes all statistical information created by a call to the analyze() method.When this method is called while the SQLConnection instance isn't connected to a database (the connected property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrorresponderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a deanalyze or error event is dispatched when execution completes. Removes all statistical information created by a call to the analyze() method.

Because the statistics generated by the analyze() method take up space in a database, calling deanalyze() allows you to reclaim that space, such as after dropping several indices or tables.

This operation is not included in an active transaction.

analyze()deanalyzeflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
detach Detaches an additional database previously attached to the SQLConnection instance using the attach() method.If the name argument is null or contains an empty string (""). ArgumentErrorArgumentErrorIf this method is called while the SQLConnection instance isn't connected to a database (the connected property is false); or if the SQLConnection instance has an open transaction (the inTransaction property is true). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrornameStringThe given name of the database to detach. responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a detach or error event is dispatched when execution completes. Detaches an additional database previously attached to the SQLConnection instance using the attach() method. It is possible to have the same database attached multiple times using different names, and detaching one connection leaves the others intact. A database cannot be detached if the connection has an open transaction (if the inTransaction property is true). attach()detachflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.getSchemaResult Provides access to the result of a call to the loadSchema() method.flash.data:SQLSchemaResult Provides access to the result of a call to the loadSchema() method. The getSchemaResult() method behaves as a first-in, first-out queue of results. Each time the loadSchema() method call completes (each time the schema event is dispatched in asynchronous execution mode), a new SQLSchemaResult object is added to the queue. Each time the getSchemaResult() method is called, the earliest result (the one that was added to the queue first) is returned and removed from the queue. When there are no more objects left in the queue, getSchemaResult() returns null.

When the database connection is closed the method returns null.

loadSchema()schema event
loadSchema Loads schema information from the connected database or any attached databases.When the method is called while the SQLConnection instance isn't connected to a database (the connected property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorWhen the specified type argument value isn't one of the allowed types. ArgumentErrorArgumentErrorWhen using synchronous execution mode, if an invalid value is supplied for the name or database parameters. SQLErrorflash.errors:SQLErrortypeClassnullIndicates the type of schema to load. A null value (the default) indicates that all the schema information should be loaded. Specifying a non-null value for this parameter narrows the scope of the resulting schema, removing potentially unneeded information from the results and making the operation more efficient. The value must be the class name of one of the following classes:
  • SQLIndexSchema
  • SQLTableSchema
  • SQLTriggerSchema
  • SQLViewSchema
nameStringnullIndicates which resource's schema is loaded. How this value is used depends on the type argument specified. Typically, this is the name of a database object such as a table name, an index or view name, and so forth. If a value is specified, only schema information for the database object with the specified name is included in the result.

If the specified value is not valid an error event is dispatched (or an error is thrown in synchronous execution mode). The type parameter value must correspond to the type of the object named in order for the value to be valid, as described in the method description.

If the name argument is null then all schemata of the specified type are included. If the value specified is not valid an error event is dispatched.

databaseStringmainThe name of the database whose schema is loaded. If the value specified is not valid an error event is dispatched. includeColumnSchemaBooleantrueIndicates whether the result includes schema information for the columns of tables and views. responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a schema or error event is dispatched when execution completes.
Loads schema information from the connected database or any attached databases. The schema indicates the structure of the database's tables, columns, indices, and triggers.

To access the loaded schema use the SQLConnection.getSchemaResult() method.

In asynchronous execution mode, a schema event is dispatched if the operation is successful, or an error event is dispatched if the operation fails.

The combination of the type and name parameter values determines the type of schema data that's generated by the loadSchema() method and, consequently, the values of the properties of the SQLSchemaResult instance that's generated. The following table lists the valid type and name pairs and the schema data that's generated as a result:

type argumentname argumentRetrieves schema data for: nullnullall objects in the database (all tables, views, triggers, and indices)SQLIndexSchemanullall indices in the databaseSQLIndexSchemavalid table nameall indices defined on the specified tableSQLIndexSchemavalid index namethe specified indexSQLTableSchemanullall tables in the databaseSQLTableSchemavalid table namethe specified tableSQLTriggerSchemanullall triggers in the databaseSQLTriggerSchemavalid table nameall triggers associated with the specified tableSQLTriggerSchemavalid view nameall triggers associated with the specified view SQLTriggerSchemavalid trigger namethe specified trigger SQLViewSchemanullall views in the databaseSQLViewSchemavalid view namethe specified view

If the combination of type and name arguments does not correspond to one of the specified combinations, an error event is dispatched in asynchronous execution mode or an exception is thrown in synchronous execution mode. For instance, if the type argument is SQLViewSchema and the name argument is the name of a table (rather than the name of a view), an error is raised indicating that the database doesn't contain an object of the specified type with the specified name.

If the database is empty (it doesn't contain any tables, views, triggers, or indices), calling the loadSchema() method results in an error.

getSchemaResult()schema eventflash.data.SQLIndexSchemaflash.data.SQLTableSchemaflash.data.SQLTriggerSchemaflash.data.SQLViewSchemaschemaflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation completes with a failure. Dispatched when the operation completes with a failure.
openAsync Opens an asynchronous connection to the database file at the specified location in the file system, or creates and opens a new database file at the location, or creates and opens an in-memory database.When the SQLConnection instance already has an open connection to a database (the connected property is true). IllegalOperationErrorflash.errors:IllegalOperationErrorWhen the value specified for the reference parameter is not a flash.filesystem.File instance ArgumentErrorArgumentErrorWhen the encryptionKey argument is not null and its length is not 16 bytes ArgumentErrorArgumentErrorWhen the reference parameter is null and the encryptionKey argument is not null ArgumentErrorArgumentErrorIf an invalid pageSize parameter is specified. This includes passing a page size when the mode is SQLMode.READ. ArgumentErrorArgumentErrorreferenceObjectnullThe location of the database file that is opened. This value must be a flash.filesystem.File instance. If the parameter's value is null, an in-memory database is created and opened. openModeStringcreateIndicates how the database is opened. The value can be any of the constants defined in the SQLMode class. The default value is SQLMode.CREATE, indicating that if a database file is not found at the specified location, one is created. If openMode is SQLMode.READ and the specified file does not exist then an error event is dispatched. This parameter is ignored when the reference parameter is null. responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. If the responder argument is null an open or error event is dispatched when execution completes. autoCompactBooleanfalseIndicates whether unused space in the database is reclaimed automatically. This parameter is only valid when creating a new database file or opening a database file in which no tables have been created. By default, the space taken up by removed data is left in the database file and reused when needed. Setting this parameter to true causes the database to automatically reclaim unused space. This can negatively affect performance because it requires additional processing each time data is written to the database and can also cause the database data to become fragmented over time. To force the database to reclaim unused space in a database file at any time and to defragment the database file, use the compact() method.

This parameter is ignored when the openMode parameter is SQLMode.READ.

pageSizeint1024Indicates the page size (in bytes) for the database. This parameter is only valid when creating a new database file or opening a database file in which no tables have been created. The value must be a power of two greater than or equal to 512 and less than or equal to 32768. The default value is 1024 bytes. This value can only be set before any tables are created. Once the tables are created attempting to change this value results in an error. encryptionKeyflash.utils:ByteArraynullThe encryption key for the database file. If the openAsync() call creates a database, the database is encrypted and the specified key is used as the encryption key for the database. If the call opens an encrypted database, the value must match the database's encryption key or an error occurs. If the database being opened is not encrypted, the value must be null (the default) or an error occurs.

A valid encryption key is 16 bytes long. An in-memory database cannot be encrypted, so this parameter must be null when the reference parameter's value is null.

When opening an encrypted database, if the encryption key provided doesn't match the database's encryption key, a SQLErrorEvent is dispatched. The event object's error property contains a SQLError instance. That SQLError object's errorID property is 3138 ("File opened is not a database file").

The encryptionKey parameter is available starting with AIR 1.5.

Opens an asynchronous connection to the database file at the specified location in the file system, or creates and opens a new database file at the location, or creates and opens an in-memory database. The operations of creating and opening the database, as well as all other operations that are performed using this SQLConnection instance (including statement execution and other operations performed by a SQLStatement instance associated with this SQLConnection instance) are performed asynchronously when the database is opened using this method. To perform operations synchronously, open the database connection using the open() method instead.

Once a database is connected, use a SQLStatement instance to execute SQL commands. Database-level operations such as beginning or ending transactions, loading schema information, and other operations are performed using the SQLConnection instance.

A database that is connected using the openAsync() method is automatically assigned the database name "main"; that name can be used to explicitly qualify table names in SQL statements using the format [database-name].[table-name].

open()close()flash.data.SQLModeopenflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails. The connection is never left open after a failed operation. Dispatched when the operation fails.
open Opens a synchronous connection to the database file at the specified location in the file system, or creates and opens a new database file at the location, or creates and opens an in-memory database.When the SQLConnection instance already has an open connection to a database (the connected property is true). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails. The connection is never left open after a failed operation. SQLErrorflash.errors:SQLErrorWhen the value specified for the reference parameter is not a flash.filesystem.File instance ArgumentErrorArgumentErrorWhen the encryptionKey argument is not null and its length is not 16 bytes ArgumentErrorArgumentErrorWhen the reference parameter is null and the encryptionKey argument is not null ArgumentErrorArgumentErrorIf an invalid pageSize parameter is specified. This includes passing a page size when the mode is SQLMode.READ. ArgumentErrorArgumentErrorreferenceObjectnullThe location of the database file that is opened. This value must be a flash.filesystem.File instance. If the parameter's value is null, an in-memory database is created and opened. openModeStringcreateIndicates how the database is opened. The value can be any of the constants defined in the SQLMode class. The default value is SQLMode.CREATE, indicating that if a database file is not found at the specified location, one is created. If openMode is SQLMode.READ and the specified file does not exist then an error occurs. This parameter is ignored when the reference parameter is null. autoCompactBooleanfalseIndicates whether unused space in the database is reclaimed automatically. This parameter is only valid when creating a new database file or opening a database file in which no tables have been created. By default, the space taken up by removed data is left in the database file and reused when needed. Setting this parameter to true causes the database to automatically reclaim unused space. This can negatively affect performance because it requires additional processing each time data is written to the database and can also cause the database data to become fragmented over time. At any time you can force the database to reclaim unused space in a database file and defragment the database file using the compact() method.

This parameter is ignored when the openMode parameter is SQLMode.READ.

pageSizeint1024Indicates the page size (in bytes) for the database. This parameter is only valid when creating a new database file or opening a database file in which no tables have been created. The value must be a power of two greater than or equal to 512 and less than or equal to 32768. The default value is 1024 bytes. This value can only be set before any tables are created. Once the tables are created attempting to change this value results in an error. encryptionKeyflash.utils:ByteArraynullThe encryption key for the database file. If the open() call creates a database, the database is encrypted and the specified key is used as the encryption key for the database. If the call opens an encrypted database, the value must match the database's encryption key or an error occurs. If the database being opened is not encrypted, or to create an unencrypted database, the value must be null (the default) or an error occurs.

A valid encryption key is 16 bytes long. An in-memory database cannot be encrypted, so this parameter must be null when the reference parameter's value is null.

When opening an encrypted database, if the encryption key provided doesn't match the database's encryption key, a SQLError exception is thrown. In that case the SQLError object's errorID property is 3138 ("File opened is not a database file").

The encryptionKey parameter is available starting with AIR 1.5.

Opens a synchronous connection to the database file at the specified location in the file system, or creates and opens a new database file at the location, or creates and opens an in-memory database. The operations of creating and opening the database, as well as all other operations that are performed using this SQLConnection instance (including statement execution and other operations performed by a SQLStatement instance associated with this SQLConnection instance) are performed synchronously when the database is opened using this method. To perform operations asynchronously, open the database connection using the openAsync() method instead.

Once a database is connected, use a SQLStatement instance to execute SQL commands. Database-level operations such as beginning or ending transactions, loading schema information, and other operations are performed using the SQLConnection instance.

A database that is connected using the open() method is automatically assigned the database name "main". That name can be used to explicitly qualify table names in SQL statements using the format [database-name].[table-name].

openAsync()close()flash.data.SQLModeopenflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.
reencrypt Changes the encryption key of an encrypted database.When the newEncryptionKey value is null or its length is not 16 bytes. ArgumentErrorArgumentErrorWhen the connection is not open, or if there is an open transaction. IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrornewEncryptionKeyflash.utils:ByteArrayA ByteArray containing the new encryption key for the database. A valid encryption key is 16 bytes long. responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. If the responder argument is null a reencrypt or error event is dispatched when execution completes. Changes the encryption key of an encrypted database. This method only affects the encryption key of the main database (the database that was connected using the open() or openAsync() method). You can only call reencrypt() on a database that was encrypted when it was created. Once a database has been created as an encrypted database, it cannot be unencrypted. Likewise, a database that is created without encryption cannot be encrypted later.

The reencryption operation runs in its own transaction. If the reencryption process is interrupted, the database rolls back the transaction and the encryption key is not changed.

open()openAsync()attach()reencryptflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails. Dispatched when the operation fails.
releaseSavepoint This method commits the SQL operations made since the most recent savepoint or the named savepoint if a name is specified.when the name parameter value is an empty string (""). ArgumentErrorArgumentErrorWhen the method is called while the SQLConnection instance isn't connected to a database (the connected property is false); or if no transaction is currently open (the inTransaction property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrornameStringnullString The name of the savepoint from which all SQL operations should be committed. If no value is provided or if this parameter is null (the default) then the most recent unnamed savepoint (created by a call to setSavepoint() with no name value) is used. The name value cannot be an empty string (""). responderflash.net:RespondernullResponder An object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a releaseSavepoint or error event is dispatched when execution completes. This method commits the SQL operations made since the most recent savepoint or the named savepoint if a name is specified.

Note that until the entire transaction is committed, any changes are not permanently saved to the database. If the transaction is started using the begin() method, you must call the commit() method to commit the entire transaction. If the transaction is started by calling setSavepoint() while inTransaction is false, you can finish the entire transaction either by calling the commit() method or by calling releaseSavepoint() or rollbackToSavepoint() for the first savepoint of the transaction.

If the code calls the rollback() method, it permanently discards all changes in the transaction, regardless of whether releaseSavepoint() is called before the transaction is rolled back.

If this method is called with no parameters (or with null for the name parameter), it commits all database changes since the most recent unnamed savepoint (the most recent savepoint created by calling setSavepoint() with no name parameter). For example, if the setSavepoint() method has been called three times, three savepoints are set. Calling releaseSavepoint() at that point commits the SQL operations performed since the third (newest) savepoint.

If a value is provided for the name parameter this method commits all the SQL operations performed since the savepoint with the specified name. If other savepoints have been created more recently than the specified savepoint, operations performed after those savepoints are committed also.

Once a savepoint is released or rolled back, that savepoint and any more recent savepoints are removed. If code executes additional SQL operations after a releaseSavepoint() or rollbackToSavepoint() call removes a savepoint, those operations belong to the most recent remaining savepoint. (In other words, they belong to the savepoint created most recently before the removed savepoint.) If no savepoint remains, the operations belong to the main transaction.

setSavepoint()rollbackToSavepoint()releaseSavepointflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
removeEventListener Removes a listener from the EventDispatcher object.typeStringThe type of event. listenerFunctionThe listener object to remove. useCaptureBooleanfalse Specifies whether the listener was registered for the capture phase or the target and bubbling phases. If the listener was registered for both the capture phase and the target and bubbling phases, two calls to removeEventListener() are required to remove both, one call with useCapture() set to true, and another call with useCapture() set to false. Removes a listener from the EventDispatcher object. If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect. rollbackToSavepoint Rolls back any SQL operations since the most recent savepoint or the named savepoint if a name is specified.when the name parameter value is an empty string (""). ArgumentErrorArgumentErrorWhen the method is called while the SQLConnection instance isn't connected to a database (the connected property is false); or if no transaction is currently open (the inTransaction property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrornameStringnullString The name of the savepoint to which the database state should be rolled back. If no value is provided or if this parameter is null (the default) then most recent unnamed savepoint (created by a call to setSavepoint() with no name value) is used. The name value cannot be an empty string (""). responderflash.net:RespondernullResponder An object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a rollbackToSavepoint or error event is dispatched when execution completes. Rolls back any SQL operations since the most recent savepoint or the named savepoint if a name is specified.

Note that if the entire transaction is committed by calling the commit() method, any changes in the transaction that are not already rolled back using the rollbackToSavepoint() method are permanently saved to the database. In addition, calling the rollback() method permanently discards all changes, regardless of whether individual savepoints have been released (committed) or rolled back before the transaction is rolled back.

If this method is called with no parameters (or with null for the name parameter), it rolls back all database changes since the most recent unnamed savepoint (the most recent call to setSavepoint() with no name parameter value).

If a value is provided for the name parameter this method rolls back all the SQL operations performed since the savepoint with the specified name. If other savepoints have been created more recently than the specified savepoint, operations performed since those savepoints are rolled back also.

Once a savepoint is released or rolled back, that savepoint and any more recent savepoints are removed. If code executes additional SQL operations after a releaseSavepoint() or rollbackToSavepoint() call removes a savepoint, those operations belong to the most recent remaining savepoint. (In other words, they belong to the savepoint created most recently before the removed savepoint.) If no savepoint remains, the operations belong to the main transaction.

setSavepoint()releaseSavepoint()rollbackToSavepointflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
rollback Rolls back an existing transaction created using the begin() method, meaning all changes made by any SQL statements in the transaction are discarded.When the method is called while the SQLConnection instance isn't connected to a database (the connected property is false); or if no transaction is currently open (the inTransaction property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrorresponderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a rollback or error event is dispatched when execution completes. Rolls back an existing transaction created using the begin() method, meaning all changes made by any SQL statements in the transaction are discarded.

Intermediate savepoints can be marked within a transaction by calling the setSavepoint() method. Using savepoints you can commit portions of a transaction by calling the releaseSavepoint() method, or roll back portions of a transaction by calling rollbackToSavepoint(). However, calling the rollback() method permanently discards all changes made in a transaction, regardless of whether individual savepoints have been released (committed) before the transaction is rolled back.

begin()commit()setSavepoint()releaseSavepoint()rollbackToSavepoint()rollbackflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
setSavepoint Creates a savepoint, which is like a bookmark within a database transaction.when the name parameter value is an empty string (""). ArgumentErrorArgumentErrorWhen the method is called while the SQLConnection instance isn't connected to a database (the connected property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrornameStringnullString The name for the savepoint. If no value is provided or if this parameter is null (the default) then the next call to releaseSavepoint() or rollbackToSavepoint() with no name parameter specified commits or rolls back the SQL operations performed since the unnamed savepoint.

If the name provided is a duplicate of a previous named savepoint, the next call to either SQLConnection.releaseSavepoint() or SQLConnection.rollbackToSavepoint() commits or rolls back changes made since the most recent savepoint with that name.

The name value cannot be an empty string ("").

responderflash.net:RespondernullResponder An object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a setSavepoint or error event is dispatched when execution completes.
Creates a savepoint, which is like a bookmark within a database transaction. A savepoint represents a point within a transaction. The set of SQL operations performed between savepoints can be committed or rolled back separately from other operations using the releaseSavepoint() and rollbackToSavepoint() methods. In this way, using a savepoint allows you to treat a set of SQL operations as a nested transaction.

When the setSavepoint() method is called, if a transaction has not already been opened (by calling the begin() method), calling this method begins the transaction and creates a savepoint at the start of the transaction. If a transaction is already open, calling setSavepoint() creates a savepoint within the transaction.

Note that until the entire transaction is committed, any changes are not permanently saved to the database. If the transaction is started using the begin() method, you must call the commit() method to commit the entire transaction. If the transaction is started by calling setSavepoint() while inTransaction is false, you can finish the entire transaction either by calling the commit() method. The transaction also finishes automatically when you call releaseSavepoint() or rollbackToSavepoint() for the savepoint that started the transaction.

You can specify a name for a savepoint by providing a value for the name parameter. This allows you to to rollback or commit all changes made since that specific savepoint. If no name is specified (the default) then an unnamed savepoint is created.

Once a savepoint is released or rolled back, that savepoint and any more recent savepoints are removed. If code executes additional SQL operations after a releaseSavepoint() or rollbackToSavepoint() call removes a savepoint, those operations belong to the most recent remaining savepoint. (In other words, they belong to the savepoint created most recently before the removed savepoint.) If no savepoint remains, the operations belong to the main transaction.

begin()releaseSavepoint()rollbackToSavepoint()commit()rollback()setSavepointflash.events:SQLEventDispatched when the operation completes successfully. Dispatched when the operation completes successfully.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
autoCompact Indicates whether autocompacting was enabled when the current database was originally created (the value that was specified for the autoCompact parameter in the open() or openAsync() call that created the database).Boolean Indicates whether autocompacting was enabled when the current database was originally created (the value that was specified for the autoCompact parameter in the open() or openAsync() call that created the database). If this property is true, unused space is removed from the database file automatically after each write operation, keeping the database file smaller. If the property is false, the space previously occupied by removed data is left in the database file and reused when needed. Even when autoCompact is false, you can force the database to reclaim unused space by calling the compact() method.

If the connected property is false, this property is set to false.

open()openAsync()
cacheSize Provides access to the cache size for this connection, which represents the maximum number of database disk pages that are held in memory at one time.uintWhen an attempt is made to set this property while the SQLConnection instance isn't connected to a database (the connected property is false); or if a transaction is currently open (the inTransaction property is true). IllegalOperationErrorflash.errors:IllegalOperationError Provides access to the cache size for this connection, which represents the maximum number of database disk pages that are held in memory at one time. Each page uses about 1.5 KB of memory (depending on the value specified for the pageSize parameter of the open() or openAsync() method call that created the database). The default cache size is 2000. If an application is executing UPDATE or DELETE operations that change many rows of a database, increasing the cache size can improve speed at the cost of increased memory consumption. open()openAsync()columnNameStyle Indicates how column names are reported in the result of a SELECT statement.StringWhen an attempt is made to set this property while the SQLConnection instance isn't connected to a database (the connected property is false). IllegalOperationErrorflash.errors:IllegalOperationError Indicates how column names are reported in the result of a SELECT statement.

The constants defined in the SQLColumnNameStyle class represent the possible values for this property:

  • SQLColumnNameStyle.LONG indicates that column names are returned in the format [table-name]_[column-name].
  • SQLColumnNameStyle.SHORT specifies that column names are given the format [column-name]. If there are multiple columns with the same name, only one property with that name is added to the result object.
  • SQLColumnNameStyle.DEFAULT is the default value. When this value is used, result column names are formatted according to the number of tables in the SELECT statement that have similar column names. If the SELECT statement includes only one table, the short name format [column-name] is used, and if the SELECT statement includes multiple tables joined together, whenever there is a naming collision because two column names are identical, the long name format [table-name]_[column-name] is used for the identically named columns.
flash.data.SQLColumnNameStyle
connected Indicates whether the SQLConnection instance has an open connection to a database file.Boolean Indicates whether the SQLConnection instance has an open connection to a database file. open()openAsync()close()inTransaction Indicates whether this connection is currently involved in a transaction.Boolean Indicates whether this connection is currently involved in a transaction. begin()commit()rollback()lastInsertRowID The last generated row identifier created by a SQL INSERT statement.Number The last generated row identifier created by a SQL INSERT statement. A row identifier is used to uniquely identify a row in a table within the database. The value is frequently generated by the database.

The value is zero if no database is connected or no INSERT statement has been executed.

The row identifier for a single SQL INSERT statement execution can be obtained through the lastInsertRowID property of the SQLResult object returned by the SQLStatement object's getResult() method (when called after the SQLStatement dispatches its result event).

For more information on primary keys and generated row identifiers, see the "CREATE TABLE" and "Expressions" sections in the appendix "SQL support in local databases."

flash.data.SQLResult.lastInsertRowIDflash.events.SQLUpdateEvent.rowID
pageSize Indicates the database page size (in bytes) that was specified when the current database was originally created (the value that was specified for the pageSize parameter in the open() or openAsync() call that created the database).uint Indicates the database page size (in bytes) that was specified when the current database was originally created (the value that was specified for the pageSize parameter in the open() or openAsync() call that created the database).

If the connected property is false, this property's value is 0.

The page size for a database can be changed (using the open() or openAsync() methods) until the first table is created in the database.

open()openAsync()
totalChanges Contains the total number of data changes that have been made since the connection to the database was opened.Number Contains the total number of data changes that have been made since the connection to the database was opened. In addition to tracking changes made by INSERT, DELETE, and UPDATE statements, this value includes changes caused by triggers.

When the database connection is closed, the value is reset to 0. When the SQLConnection instance isn't connected to a database, the value is 0.

flash.data.SQLResult.rowsAffected
SQLTriggerSchema A SQLTriggerSchema instance provides information describing a specific trigger in a database.flash.data:SQLSchema A SQLTriggerSchema instance provides information describing a specific trigger in a database. It contains the name of the trigger (the name property), the name of the associated table (the table property), and the SQL statement used to create the trigger (the sql property).

To obtain trigger schema information for a database, use the SQLConnection.loadSchema() method to load the schema information, making certain to use null or SQLTriggerSchema for the type argument's value. In the resulting SQLSchemaResult instance, the triggers property contains an array of SQLTriggerSchema instances representing the triggers in the database.

Generally, developer code does not construct SQLTriggerSchema instances directly.

flash.data.SQLConnection.loadSchema()SQLTriggerSchema Creates a SQLTriggerSchema instance.databaseStringThe name of the associated database. nameStringThe name of the trigger. sqlStringThe SQL used to create the trigger. tableStringThe name of the trigger's associated table. Creates a SQLTriggerSchema instance. Generally, developer code does not call the SQLTriggerSchema constructor directly. To obtain schema information for a database, call the SQLConnection.loadSchema() method. table The name of the table on which this trigger is defined, or the name of the view if the trigger is defined on a view.String The name of the table on which this trigger is defined, or the name of the view if the trigger is defined on a view.
SQLStatement A SQLStatement instance is used to execute a SQL statement against a local SQL database that is open through a SQLConnection instance.flash.events:EventDispatcher A SQLStatement instance is used to execute a SQL statement against a local SQL database that is open through a SQLConnection instance.

A SQLStatement instance is linked to a SQLConnection instance by setting the SQLConnection instance as the value of the SQLStatement instance's sqlConnection property. The text property is populated with the actual text of the SQL statement to execute. If necessary, SQL statement parameter values are specified using the parameters property, and the statement is carried out by calling the execute() method.

For a complete description of the SQL dialect supported in local SQL databases, see the appendix SQL support in local databases.

In asynchronous execution mode, the execute() and next() methods are executed in the background, and the runtime dispatches events to registered event listeners or to a specified Responder instance when the operations complete or fail. In synchronous mode, the methods are executed on the main application thread, meaning that no other code executes until the database operations are completed. In addition, in synchronous mode if the methods fail the runtime throws an exception rather than dispatching an error event.

flash.data.SQLConnectionerror Dispatched when an error occurs during an operation.flash.events.SQLErrorEvent.ERRORflash.events.SQLErrorEvent Dispatched when an error occurs during an operation. execute()next()result Dispatched when an execute() or next() method call's operation completes successfully.flash.events.SQLEvent.RESULTflash.events.SQLEvent Dispatched when an execute() or next() method call's operation completes successfully. Once the result event is dispatched the getResult() method can be called to retrieve statement results. execute()next()getResult()SQLStatement Creates a SQLStatement instance.If the constructor is called from any sandbox outside of the main application sandbox. SecurityErrorSecurityError Creates a SQLStatement instance. cancel Cancels execution of this statement. Cancels execution of this statement. Like SQLConnection.cancel() this method is used to stop a long running query or to cancel a query that is not yet complete. However, unlike SQLConnection.cancel() this method only cancels the single statement. If the statement is not currently executing, calling this method does nothing.

No events are dispatched in direct response to the completion of the cancel() operation. However, once the cancel() operation completes and statement execution is cancelled, the SQLStatement instance dispatches an error event indicating that the statement execution (the execute() or next() call) did not complete. Alternatively, if a value was specified for the responder parameter of the execute() or next() call, the specified fault handler method is called. In either case, the SQLError instance that's passed to the listeners has an errorID property with a value of 3118 (Operation aborted).

clearParameters Clears all current parameter settings. Clears all current parameter settings. parametersexecute Executes the SQL in the text property against the database that is connected to the SQLConnection object in the sqlConnection property.If the text property is null or contains an empty string (""); if the sqlConnection property is not set; if the SQLConnection instance assigned to the sqlConnection property is not connected; or if the statement is currently executing. IllegalOperationErrorflash.errors:IllegalOperationErrorIf the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrorprefetchint-1When the statement's text property is a SELECT statement, this value indicates how many rows are returned at one time by the statement. The default value is -1, indicating that all the result rows are returned at one time. This parameter is used in conjunction with the next() method to divide large result sets into smaller sets of data. This can improve a user's perception of application performance by returning initial results more quickly and dividing result-processing operations.

When the SQL statement is a SELECT query and a prefetch argument greater than zero is specified, the statement is considered to be executing until the entire result set is returned or either the SQLStatement.cancel() or SQLConnection.cancel() method is called. Note that because the number of rows in a result set is unknown at execution time, the database cursor must move beyond the last row in the result set before the statement is considered complete. When a prefetch argument is specified in an execute() call, at least one row more than the total number of rows in the result set must be requested (either through a prefetch value that's larger than the number of rows in the result set, or through subsequent calls to the next() method) before the resulting SQLResult instance's complete property is true.

responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. In asynchronous execution mode, if the responder argument is null a result or error event is dispatched when execution completes.
Executes the SQL in the text property against the database that is connected to the SQLConnection object in the sqlConnection property.

If the responder argument is not null the specified Responder object designates methods that are called to handle the results of the operation. If the responder argument is null, in asynchronous execution mode a result event is dispatched if the operation is successful, or an error event is dispatched if the operation fails.

To access the results of a statement, such as the result rows of a SELECT statement or the database generated primary key of an INSERT statement, call the getResult() method. The results are available immediately after the statement executes in synchronous mode, and when the result event is dispatched in asynchronous mode.

Every statement must be prepared (compiled) before it can be executed. The first time a SQLStatement instance's execute() method is called, the statement is prepared by the runtime. Once a statement is prepared it does not need to be prepared again unless the text property changes. Setting one or more parameter values does not require the statement to be prepared again.

The following example demonstrates executing a SQLStatement, using event listeners to determine when the statement execution completes or fails. var conn:SQLConnection; var dbStatement:SQLStatement; function init():void { conn = new SQLConnection(); conn.addEventListener(SQLEvent.OPEN, connOpenHandler); dbStatement = new SQLStatement(); dbStatement.sqlConnection = conn; dbStatement.text = "SELECT id, name, ssn FROM employees"; var dbFile:File = new File(File.separator + "employee.db"); conn.open(dbFile); } function connOpenHandler(event:SQLEvent):void { dbStatement.addEventListener(SQLEvent.RESULT, resultHandler); dbStatement.addEventListener(SQLErrorEvent.ERROR, errorHandler); dbStatement.execute(); } function resultHandler(event:SQLEvent):void { var result:SQLResult = dbStatement.getResult(); if (result != null) { var numRows:int = result.data.length; for (var i:int = 0; i < numRows; i++) { var row:Object = result.data[i]; trace("id:", row.id, ", name:", row.name, ", ssn:", row.ssn); } } } function errorHandler(event:SQLErrorEvent):void { trace("An error occured while executing the statement."); } The following example demonstrates executing a SQLStatement, using a Responder object to indicate which functions are called when the statement execution completes or fails. var conn:SQLConnection; var dbStatement:SQLStatement; var employeeResponder:Responder; function init():void { conn = new SQLConnection(); conn.addEventListener(SQLEvent.OPEN, connOpenHandler); dbStatement = new SQLStatement(); dbStatement.sqlConnection = conn; dbStatement.text = "SELECT id, name, ssn FROM employees"; var dbFile:File = new File(File.separator + "employee.db"); conn.open(dbFile); } function connOpenHandler(event:SQLEvent):void { employeeResponder = new Responder(resultHandler, errorHandler); dbStatement.execute(-1, employeeResponder); } function resultHandler(result:SQLResult):void { if (result != null) { var numRows:int = result.data.length; for (var i:int = 0; i < numRows; i++) { var row:Object = result.data[i]; trace("id:", row.id, ", name:", row.name, ", ssn:", row.ssn); } } } function errorHandler(error:SQLError):void { trace("An error occured while executing the statement."); }
next()getResult()resultflash.events:SQLEventDispatched when the statement execution completes successfully, or when a prefetch argument value is specified and a SELECT statement returns one or more rows of data. Dispatched when the statement execution completes successfully, or when a prefetch argument value is specified and a SELECT statement returns one or more rows of data.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
getResult Provides access to a SQLResult object containing the results of the statement execution, including any result rows from a SELECT statement, and other information about the statement execution for all executed statements.A SQLResult object containing the result of a call to the execute() or next() method. flash.data:SQLResult Provides access to a SQLResult object containing the results of the statement execution, including any result rows from a SELECT statement, and other information about the statement execution for all executed statements. In asynchronous execution mode, the result information is not available until the result event is dispatched.

When a SELECT statement is executed, if the execute() method is called with the default prefetch argument of -1, the returned SQLResult object contains the entire result set of the query.

When a prefetch argument is specified for an execute() or next() method call, the getResult() method behaves as a first-in, first-out queue of results. Each time the result event is dispatched, a new SQLResult object is added to the queue. Each time the getResult() method is called, the earliest SQLResult object (the one that was added to the queue first) is returned and removed from the queue. When there are no more SQLResult objects left in the queue, getResult() returns null.

Note that unless they are removed by calling getResult(), SQLResult objects remain in the queue. For example, if the execute() method is called multiple times without calling getResult(), the SQLResult objects associated with each execute() call remains in the queue.

execute()next()result event
next Retrieves the next portion of a SELECT statement's result set.When the method is called while the statement is not currently executing (the executing property is false). IllegalOperationErrorflash.errors:IllegalOperationErrorif the operation fails in synchronous execution mode. SQLErrorflash.errors:SQLErrorprefetchint-1When the statement's text property is a SELECT statement, this value indicates how many rows are returned at one time by the statement. The default value is -1, indicating that all the result rows are returned at one time. This can improve a user's perception of application performance by returning initial results more quickly and dividing result-processing operations. responderflash.net:RespondernullAn object that designates methods to be called when the operation succeeds or fails. If the responder argument is null a result or error event is dispatched when execution completes. Retrieves the next portion of a SELECT statement's result set. If there are no more rows in the result set, a result event is dispatched but no additional SQLResult object is added to the getResult() queue.

In asynchronous execution mode, if the responder argument is not null the specified Responder object indicates the methods that are called to handle the results of the operation. If the responder argument is null, a result event is dispatched if the operation is successful, or an error event is dispatched if the operation fails.

This method can only be called when the statement is still executing. When the statement is a SELECT query and a prefetch argument greater than zero is specified, the statement is considered to be executing until the entire result set is returned or either the SQLStatement.cancel() or SQLConnection.cancel() method is called.

The following example demonstrates executing a SQLStatement, explicitly indicating that only the first 10 rows of the result set are to be returned the first time the result returns. The code checks the complete property of the SQLResult and, if not all the rows have been retrieved, calls the next() method. var conn:SQLConnection; var dbStatement:SQLStatement; function init():void { conn = new SQLConnection(); conn.addEventListener(SQLEvent.OPEN, connOpenHandler); dbStatement = new SQLStatement(); dbStatement.sqlConnection = conn; dbStatement.text = "SELECT id, name, ssn FROM employees"; var dbFile:File = new File(File.separator + "employee.db"); conn.open(dbFile); } function connOpenHandler(event:SQLEvent):void { dbStatement.addEventListener(SQLEvent.RESULT, resultHandler); dbStatement.addEventListener(SQLErrorEvent.ERROR, errorHandler); dbStatement.execute(10); } function resultHandler(event:SQLEvent):void { var result:SQLResult = dbStatement.getResult(); if (result != null) { var numRows:int = result.data.length; for (var i:int = 0; i < numRows; i++) { var row:Object = result.data[i]; trace("id:", row.id, ", name:", row.name, ", ssn:", row.ssn); } if (!result.complete) { dbStatement.next(10); } } } function errorHandler(event:SQLErrorEvent):void { trace("An error occured while executing the statement."); }
execute()resultflash.events:SQLEventDispatched when the statement execution completes successfully, or when a prefetch argument value is specified and the next() call returns one or more rows of data. Dispatched when the statement execution completes successfully, or when a prefetch argument value is specified and the next() call returns one or more rows of data.errorflash.events:SQLErrorEventDispatched when the operation fails in asynchronous execution mode. Dispatched when the operation fails in asynchronous execution mode.
executing Indicates whether the statement is currently executing.Boolean Indicates whether the statement is currently executing.

This property is true if execute() has been called and not all of the results have been returned from the database.

execute()
itemClass Indicates a class (data type) that is used for each row returned as a result of the statement's execution.Class Indicates a class (data type) that is used for each row returned as a result of the statement's execution.

By default, each row returned by a SELECT statement is created as an Object instance, with the result set's column names as the names of the properties of the object, and the value of each column as the value of its associated property.

By specifying a class for the itemClass property, each row returned by a SELECT statement executed by this SQLStatement instance is created as an instance of the designated class. Each property of the itemClass instance is assigned the value from the column with the same name as the property.

Any class assigned to this property must have a constructor that does not require any parameters. In addition, the class must have a single property for each column returned by the SELECT statement. It is considered an error if a column in the SELECT list does not have a matching property name in the itemClass class.

The following code demonstrates using the itemClass property to have the runtime create instances of a custom class from SQL SELECT statement results. // Employee class definition package { public class Employee { public var name:String; public var ssn:String; public var id:uint; public override function toString():String { return "id: "+ id.toString() + " name: " + name + " ssn: " + ssn; } } } // using the Employee class as SQLStatement.itemClass var conn:SQLConnection; var dbStatement:SQLStatement; function init():void { conn = new SQLConnection(); conn.addEventListener(SQLEvent.OPEN, connOpenHandler); dbStatement = new SQLStatement(); dbStatement.sqlConnection = conn; dbStatement.text = "SELECT id, name, ssn FROM employees"; dbStatement.itemClass = Employee; var dbFile:File = new File(File.separator + "employee.db"); conn.open(dbFile); } function connOpenHandler(event:SQLEvent):void { dbStatement.addEventListener(SQLEvent.RESULT, resultHandler); dbStatement.execute(); } function resultHandler(event:SQLEvent):void { var result:SQLResult = dbStatement.getResult(); if (result != null) { var emp:Employee; var numRows:int = result.data.length; for (var i:int = 0; i < numRows; i++) { emp = result.data[i]; trace(emp.toString()); } } }
flash.data.SQLResult.data
parameters Serves as an associative array to which you add values for the parameters specified in the SQL statement's text property.Object Serves as an associative array to which you add values for the parameters specified in the SQL statement's text property. The array keys are the names of the parameters. If an unnamed parameter is specified in the statement text, its key is the index of the parameter.

Within the text of a SQL statement, a parameter is indicated with one of the following characters: "?", ":", or "@".

The ":" and "@" tokens indicate a named parameter; the characters following the token designate the name of the parameter.

For example, in the following SQL statement, a parameter named firstName is specified using the ":" character:

SELECT FROM employees WHERE firstName = :firstName

The "?" token indicates an indexed (numbered) parameter; each parameter is automatically given an index according to the sequence of parameters in the statement text. Parameter index values are zero based. In other words, the first parameter's index is 0.

Parameters are used to allow for typed substitution of values that are unknown at the time the SQL statement is constructed. The use of parameters is the only way to guarantee the storage class for a value passed in to the database. When parameters are not used, all values are converted from their text representation to a storage class based on the associated column's type affinity. For more information on storage classes and column affinity, see the "Data type support" section in the appendix "SQL support in local databases".

Parameters are also used as a security measure to prevent a malicious technique known as a SQL injection attack. In a SQL injection attack, a user enters SQL code in a user-accessible location (for example, a data entry field). If application code constructs a SQL statement by directly concatenating user input into the SQL text, the user-entered SQL code is executed against the database. The following listing shows an example of concatenating user input into SQL text. Do not use this technique:

// assume the variables "username" and "password" // contain user-entered data var sql:String = "SELECT userId " + "FROM users " + "WHERE username = '" + username + "' " + " AND password = '" + password + "'"; var statement:SQLStatement = new SQLStatement(); statement.text = sql;

Using statement parameters instead of concatenating user-entered values into a statement's text prevents a SQL injection attack, because the parameter values are treated explicitly as substituted values, rather than becoming part of the literal statement text. The following is the recommended alternative to the previous listing:

// assume the variables "username" and "password" // contain user-entered data var sql:String = "SELECT userId " + "FROM users " + "WHERE username = :username " + " AND password = :password"; var statement:SQLStatement = new SQLStatement(); statement.text = sql; // set parameter values statement.parameters[":username"] = username; statement.parameters[":password"] = password;

All parameter values must be set before the statement is executed. Parameter values specified in the parameters array are bound (that is, combined with the statement text) when the execute() method is called. Once execute() has been called, any subsequent changes to the values are not applied to the executing statement. However, on a subsequent execute() call the changed values are used. If the statement text includes a parameter that doesn't have a value specified in the parameters property, an error occurs.

To clear all the parameter values from the parameters property, use the clearParameters() method.

The following example shows the use of a named parameter, :firstName, in a SQL statement. // employees is a SQLStatement instance employees.text = "SELECT FROM employees WHERE first = :firstName"; employees.parameters[":firstName"] = "Sam"; employees.execute(); The following example shows the use of an unnamed parameter in a SQL statement. // employees is a SQLStatement instance employees.text = "SELECT FROM employees WHERE first = ?"; employees.parameters[0] = "Sam"; employees.execute();
textclearParameters()
sqlConnection The SQLConnection object that manages the connection to the database or databases on which the statement is executed.flash.data:SQLConnectionWhen an attempt is made to change the value of this property while the statement is executing. IllegalOperationErrorflash.errors:IllegalOperationError The SQLConnection object that manages the connection to the database or databases on which the statement is executed. text The actual SQL text of the statement.StringWhen an attempt is made to change the text property while the statement is executing. IllegalOperationErrorflash.errors:IllegalOperationError The actual SQL text of the statement.

The text can be any supported SQL. For a complete description of the SQL dialect supported in local SQL databases, see the appendix "SQL support in local databases".

SQLMode This class contains the constants that represent the possible values for the openMode parameter of the SQLConnection.open() and SQLConnection.openAsync() methods.Object This class contains the constants that represent the possible values for the openMode parameter of the SQLConnection.open() and SQLConnection.openAsync() methods. flash.data.SQLConnection.open()flash.data.SQLConnection.openAsync()CREATE Indicates that the connection is opened for updates, and a database file is created if the specified file doesn't exist.createString Indicates that the connection is opened for updates, and a database file is created if the specified file doesn't exist. In this mode reading and writing are allowed to the database. If the database does not exist one is created before the operation completes. flash.data.SQLConnection.open()flash.data.SQLConnection.openAsync()READ Indicates that the connection is opened in read-only mode.readString Indicates that the connection is opened in read-only mode. In this mode writes are not allowed to the database. If the database does not exist the open operation fails. flash.data.SQLConnection.open()flash.data.SQLConnection.openAsync()UPDATE Indicates that the connection is opened for updates but a new database file is not created if the specified file doesn't exist.updateString Indicates that the connection is opened for updates but a new database file is not created if the specified file doesn't exist. In this mode reading and writing are allowed to the database. If the database does not exist the open operation fails. flash.data.SQLConnection.open()flash.data.SQLConnection.openAsync()EncryptedLocalStore The EncryptedLocalStore class provides a persistent, encrypted data storage mechanism.Object The EncryptedLocalStore class provides a persistent, encrypted data storage mechanism.

AIR profile support: This feature is supported on all desktop operating systems, but is not supported on mobile devices or AIR for TV devices. You can test for support at run time using the EncryptedLocalStore.isSupported property. See AIR Profile Support for more information regarding API support across multiple profiles.

AIR provides an encrypted local store (ELS) for each AIR application installed on a user's computer. This lets you save and retrieve data that is stored on the user’s local hard drive in an encrypted format that cannot easily be deciphered by other users. A separate encrypted local store is used for each AIR application, and each AIR application uses a separate encrypted local store for each user account on the computer.

Use the encrypted local store to cache information that must be secured, such as login credentials for web services. The ELS is appropriate for storing information that must be kept private from other users. It does not, however, protect the data from other processes run under the same user account. It is thus not appropriate for protecting secret application data, such as DRM or encryption keys.

AIR uses DPAPI on Windows, KeyChain on Mac OS, and KeyRing or KWallet on Linux to associate the encrypted local store to each application and user. The encrypted local store uses AES-CBC 128-bit encryption.

Information in the encrypted local store is only available to AIR application content in the application security sandbox.

If you update an AIR application, the updated version retains access to any existing data in the encrypted local store unless:

  • The items were added with the stronglyBound parameter set to true
  • The existing and update versions are both published prior to AIR 1.5.3 and the update is signed with a migration signature

Limitations of the encrypted local store

The data in the encrypted local store is protected by the user’s operating system account credentials. Other entities cannot access the data in the store unless they can login as that user. However, the data is not secure against access by other applications run by an authenticated user. Thus, data that your application may want to keep secret from users, such as keys used for licensing or digital rights management, is not secure. The ELS is not an appropriate location for storing such information. It is only an appropriate place for storing a user’s private data, such as passwords.

Data in the ELS can be lost for a variety of reasons. For example, the user could uninstall the application and delete the encrypted file. Or, the publisher ID could be changed as a result of an update. Thus the ELS should be treated as a private cache, not permanent data storage.

The stronglyBound parameter is deprecated and should not be set to true. Setting the parameter to true does not provide any additional protection for data. At the same time, access to the data is lost whenever the application is updated — even if the publisher ID stays the same.

The encrypted local store may perform more slowly if the stored data exceeds 10MB.

When you uninstall an AIR application, the uninstaller does not delete data stored in the encrypted local store.

The best practices for using the ELS include:

  • Use the ELS to store sensitive user data such as passwords (setting stronglyBound to false)
  • Do not use the ELS to store applications secrets such as DRM keys or licensing tokens
  • Provide a way for your application to recreate the data stored in the ELS if the ELS data is lost. For example, by prompting the user to re-enter their account credentials when necessary.
  • Do not use the stronglyBound parameter.
  • If you do set stronglyBound to true, do not migrate stored items during an update. Recreate the data after the update instead.
  • Only store relatively small amounts of data. For large amounts of data, use an AIR SQL database with encryption.

Items in the encrypted local store are identified with a string. All items are stored as byte array data.

Encrypted local store data is put in a subdirectory of the user's application data directory; the subdirectory path is Adobe/AIR/ELS/ followed by the application ID.

The following code stores a string in the encrypted local store, retrieves it, and then deletes it: var str:String = "Bob"; var bytes:ByteArray = new ByteArray(); bytes.writeUTFBytes(str); EncryptedLocalStore.setItem("firstName", bytes); var storedValue:ByteArray = EncryptedLocalStore.getItem("firstName"); trace(storedValue.readUTFBytes(storedValue.length)); // "Bob" EncryptedLocalStore.removeItem("firstName");
getItem The data corresponding to the specified name.The name value is null or an empty string. ArgumentErrorArgumentErrorThe ByteArray data. If there is no data for the provided name, the method returns null. flash.utils:ByteArraynameStringThe name of the item in the encrypted local store. The data corresponding to the specified name.

If an item does not exist by the specified name, this method returns null.

removeItem Removes the item with the given name from the encrypted local store.The name value is null or an empty string. ArgumentErrorArgumentErrornameStringThe name of the item in the encrypted local store. Removes the item with the given name from the encrypted local store. reset Clears the entire encrypted local store, deleting all data. Clears the entire encrypted local store, deleting all data. setItem Stores a ByteArray object under the specified name.The name value is null or an empty string. ArgumentErrorArgumentErrornameStringThe name of the item in the encrypted local store. dataflash.utils:ByteArrayThe data. stronglyBoundBooleanfalse(deprecated) The stronglyBound parameter should be set to false (the default value). If set to true, the stored item cannot be retrieved if any application files are altered. For example,if a user installs an update of your application, the updated application cannot read any strongly bound data that was previously written to the encrypted local store. Stores a ByteArray object under the specified name. isSupported The isSupported property is set to true if the EncryptedLocalStore class is supported on the current platform, otherwise it is set to false.BooleanReports whether the encrypted local store is available on the client system. The isSupported property is set to true if the EncryptedLocalStore class is supported on the current platform, otherwise it is set to false.
SQLIndexSchema A SQLIndexSchema instance provides information describing a specific index in a database.flash.data:SQLSchema A SQLIndexSchema instance provides information describing a specific index in a database. The available information includes the name of the associated table (the table property), the SQL statement used to create the index (the sql property), and the name of the index (the name property).

To obtain index schema information for a database, use the SQLConnection.loadSchema() method to load the schema information, making certain to use null or SQLIndexSchema for the type argument's value. In the resulting SQLSchemaResult instance, the indices property contains an array of SQLIndexSchema instances representing the indices in the database.

Generally, developer code does not construct SQLIndexSchema instances directly.

flash.data.SQLConnection.loadSchema()SQLIndexSchema Creates a SQLIndexSchema instance.databaseStringThe name of the associated database. nameStringThe name of the index. sqlStringThe SQL statement used to create this index. tableStringThe name of the table to which this index is attached. Creates a SQLIndexSchema instance. Generally, developer code does not call the SQLIndexSchema constructor directly. To obtain schema information for a database, call the SQLConnection.loadSchema() method. flash.data.SQLConnection.getSchemaResult()flash.data.SQLSchemaResult.indicestable The name of the table to which this index is attached.String The name of the table to which this index is attached.
SQLTableSchema A SQLTableSchema instance provides information describing a specific table in a database.flash.data:SQLSchema A SQLTableSchema instance provides information describing a specific table in a database. It contains the name of the table (the name property), the SQL statement used to create the table (the sql property), and information about the table's columns (the columns property).

To obtain table schema information for a database, use the SQLConnection.loadSchema() method to load the schema information, making certain to use null or SQLTableSchema for the type argument's value. In the resulting SQLSchemaResult instance, the tables property contains an array of SQLTableSchema instances representing the tables in the database.

Generally, developer code does not construct SQLTableSchema instances directly.

flash.data.SQLConnection.loadSchema()flash.data.SQLColumnSchemaSQLTableSchema Creates a SQLTableSchema instance.databaseStringThe name of the associated database. nameStringThe name of the table. sqlStringThe SQL statement used to create the table. columnsArrayArray of SQLColumnSchema instances describing this table's columns. Creates a SQLTableSchema instance. Generally, developer code does not call the SQLTableSchema constructor directly. To obtain schema information for a database, call the SQLConnection.loadSchema() method. flash.data.SQLConnection.getSchemaResult()flash.data.SQLSchemaResult.tablescolumns An array of SQLColumnSchema instances containing schema information for this table's columns.Array An array of SQLColumnSchema instances containing schema information for this table's columns. If the SQlConnection.loadSchema() call indicates that column information is excluded from the result, the columns property is an empty array (an array whose length property is 0). flash.data.SQLColumnSchemaflash.data.SQLConnection.loadSchema()
SQLResult The SQLResult class provides access to data returned in response to the execution of a SQL statement (a SQLStatement instance).Object The SQLResult class provides access to data returned in response to the execution of a SQL statement (a SQLStatement instance).

The SQLResult instance for a SQL statement is accessed by calling the SQLStatement.getResult() method or as an argument passed to the result handler of a Responder instance specified in a call to SQLStatement.execute() or SQLStatement.next(). Generally, developer code does not construct SQLResult instances directly.

You use a SQLResult object to access the rows of data returned from a SELECT statement (using the data property), to get row identifier information for an INSERT statement (using the lastInsertRowID property), to determine the number of rows affected by an INSERT, UPDATE, or DELETE statement (using the rowsAffected property), or to determine whether there are additional SELECT result rows that haven't been retrieved (using the complete property).

flash.data.SQLStatement.getResult()flash.data.SQLStatement.execute()flash.data.SQLStatement.next()SQLResult Creates a SQLResult instance.dataArraynullThe array of rows returned from the execution of a statement. If the statement doesn't return any rows this value should be null. rowsAffectedNumber0Indicates how many rows the executed statement affected. completeBooleantrueIndicates whether there are additional rows that can be fetched or whether all data has been returned. rowIDNumber0If the statement was a SQL INSERT operation this is the new unique identifier for the row. Creates a SQLResult instance. Generally, developer code does not call the SQLResult constructor directly. To retrieve a SQLResult instance associated with a particular SQLStatement instance, call the instance's getResult() method. A SQLResult instance is also passed as an argument to the result handler function when a Responder instance is specified for an execute() or next() method call. complete Indicates whether all the resulting data from a statement execution has been returned.Boolean Indicates whether all the resulting data from a statement execution has been returned.

When a statement returns one or more rows this property indicates whether all of the rows have been returned. When a SQLStatement object's execute() method is called with a prefetch argument value, only the specified number of rows of the resulting data are returned in the SQLResult object's data property. Subsequent calls to SQLStatement.next() cause additional data to become available. This property is used to determine when the final results have been returned.

Note that because the number of rows is unknown at execution time, the database cursor must move beyond the last row before a statement's execution is considered complete. When the SQLStatement.execute() method is called with a prefetch argument, at least one row more than the total number of rows in the result set must be requested before the resulting SQLResult instance's complete property is true.

flash.data.SQLStatement.execute()flash.data.SQLStatement.next()
data The data returned as a result of the statement execution, specifically when a SQL SELECT statement is executed.Array The data returned as a result of the statement execution, specifically when a SQL SELECT statement is executed.

When a statement returns one or more rows this property is an array containing objects that represent the rows of result data. Each object in the array has property names that correspond to the result data set's column names.

For example, suppose you execute the following SQL SELECT statement:

SELECT lastName, firstName FROM employees

Assuming the employees table contains 10 rows, the SQLResult.data property is an Array with 10 elements. Each element is an object with two properties, lastName and firstName.

The situation is more complex when you are using a SELECT statement with a complex result column, such as an aggregate function. For example, suppose you execute the following SQL:

SELECT departmentId, SUM(salary) FROM employees GROUP BY departmentId

In the results from this statement, each object in the data Array has two properties named departmentId and SUM(salary). However, "SUM(salary)" is not a valid identifier. If you are using a computed column such as an aggregate or other function, specify an alias for the computed column in your SQL statement. The alias is used as the property name in the result data objects. For example, consider this alternative to the previous statement:

SELECT departmentId, SUM(salary) AS salarySubtotal FROM employees GROUP BY departmentId

In this statement's data array, the result objects have two properties named departmentId and salarySubtotal.

The data property is always an Array regardless of how many rows and columns are in the result set. For example, the following SELECT statement results in one row and one column, which is essentially a single value:

SELECT COUNT(~~) AS numEmployees FROM employees

After executing the query the data property contains an Array object with one element. That element is an object with a single property, numEmployees.

If there are duplicate column names in the result data, for example if the SELECT statement includes an two different id columns from two different tables, the duplicate names are given property names according to the value of the SQLConnection.columnNameStyle property. By default, each column's name is used as the property name, but if there is are multiple columns in the result set with the same name, the long name format [table-name]_[column-name] is used for the identically named columns. This behavior can be changed by setting the SQLConnection.columnNameStyle property.

By default the objects in the data Array are Object instances. However, by setting the value of the SQLStatement.itemClass property to a class, the data Array elements are created as instances of that class instead. For every column in the result data set, the itemClass class must have a property whose name exactly matches the column name.

If a statement does not return any data this property is null. This is the case if the statement is not a SELECT statement, or if it is a SELECT statement that returns 0 rows.

The following code demonstrates using the itemClass property to have the runtime create instances of a custom class from SQL SELECT statement results. // Employee class definition package { public class Employee { public var name:String; public var ssn:String; public var id:uint; public override function toString():String { return "id: "+ id.toString() + " name: " + name + " ssn: " + ssn; } } } // using the Employee class as SQLStatement.itemClass var conn:SQLConnection; var dbStatement:SQLStatement; function init():void { conn = new SQLConnection(); conn.addEventListener(SQLEvent.OPEN, connOpenHandler); dbStatement = new SQLStatement(); dbStatement.sqlConnection = conn; dbStatement.text = "SELECT id, name, ssn FROM employees"; dbStatement.itemClass = Employee; var dbFile:File = new File(File.separator + "employee.db"); conn.open(dbFile); } function connOpenHandler(event:SQLEvent):void { dbStatement.addEventListener(SQLEvent.RESULT, resultHandler); dbStatement.execute(); } function resultHandler(event:SQLEvent):void { var result:SQLResult = dbStatement.getResult(); if (result != null) { var emp:Employee; var numRows:int = result.data.length; for (var i:int = 0; i < numRows; i++) { emp = result.data[i]; trace(emp.toString()); } } }
SQLConnection.columnNameStyleSQLStatement.itemClass
lastInsertRowID The last generated row identifier generated by a SQL INSERT statement.Number The last generated row identifier generated by a SQL INSERT statement.

The value is 0 if the executed statement was not an INSERT statement.

A row identifier is used to uniquely identify a row in a table within the database. The value is frequently generated by the database.

For more information about primary keys and generated row identifiers, see the "CREATE TABLE" and "Expressions" sections in the appendix "SQL support in local databases."

flash.data.SQLConnection.lastInsertRowIDflash.events.SQLUpdateEvent.rowID
rowsAffected Indicates how many rows were affected by the operation.Number Indicates how many rows were affected by the operation. Only changes that are directly specified by an INSERT, UPDATE, or DELETE statement are counted.

Auxiliary changes caused by triggers are not counted. Use the SQLConnection.totalChanges property to find the total number of changes including changes caused by triggers.

Note that when the related SQL operation is a DELETE statement with no WHERE clause (that is, the statement deletes all the rows in the table), the rowsAffected property is always 0, regardless of the number of rows that were deleted. If you need to know the number of rows that are deleted, you can include the WHERE clause WHERE 1 = 1, in which case all the rows are deleted, and the rowsAffected property accurately reflects the number of rows that were deleted. However, depending on the number of rows being deleted, doing so may have a negative impact on the statement's performance.

flash.data.SQLConnection.totalChanges