Pacoteflash.data
Classepublic class SQLConnection
HerançaSQLConnection Inheritance EventDispatcher Inheritance Object

A SQLConnection instance is used to manage the creation of and connection to local SQL database files (local databases).

A local SQL database file is created or opened by calling the open() method. If the database file does not exist, the open() method can optionally create the database file while opening the connection. Once a connection is made to a database, a SQL statement can be created and executed against the database by creating a SQLStatement instance and assigning 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, using the begin(), commit(), and rollback() methods.

In addition, 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.

Finally, 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.

By default, the operations performed by a SQLConnection instance's methods are asynchronous; 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 events. Each operation has an associated event that is dispatched when the operation completes successfully; for exemplo, when an open() 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.

To use synchronous execution, you pass true for the isSync parameter in the SQLConnection() constructor when you instantiate the SQLConnection instance.

Veja também

flash.data.SQLStatement
flash.events.SQLEvent
flash.events.SQLErrorEvent
flash.errors.SQLError


Propriedades Públicas
 PropriedadeDefinido por
  autoCompact : Boolean
[read-only] Indicates if the current database has been set to use auto-compaction.
SQLConnection
  cacheSize : uint
Provides access to the cache size for this connection.
SQLConnection
  columnNameStyle : String
Indicates how column names are reported in the result of a SELECT statement.
SQLConnection
  connected : Boolean
[read-only] Indicates whether the SQLConnection instance has an open connection to a database file.
SQLConnection
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  inTransaction : Boolean
[read-only] Indicates whether this connection is currently involved in a transaction.
SQLConnection
  lastInsertRowID : Number
[read-only] The last generated row identifier generated by a SQL INSERT statement.
SQLConnection
  pageSize : uint
[read-only] Indicates the current page size set for the database.
SQLConnection
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  totalChanges : Number
[read-only] Contains the total number of data changes that have been made since the connection to the database was opened.
SQLConnection
Métodos Públicos
 MétodoDefinido por
  
Creates a SQLConnection instance.
SQLConnection
  
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
SQLConnection
  
analyze(resourceName:String = null, responder:Responder = null):void
The analyze() method gathers statistics about database indices and stores them in the database.
SQLConnection
  
attach(name:String, reference:Object = null, responder:Responder = null):void
Adds another database to the SQLConnection instance, giving the new database the specified name.
SQLConnection
  
begin(option:String = null, responder:Responder = null):void
Begins a transaction, within which all SQL statements executed against the connection's database(s) are grouped.
SQLConnection
  
cancel(responder:Responder = null):void
Aborts all SQL statements that are currently executing on databases connected to the SQLConnection instance.
SQLConnection
  
close(responder:Responder = null):void
Closes the current database connection.
SQLConnection
  
commit(responder:Responder = null):void
Commits an existing transaction, causing any actions performed by the transaction's statements to be permanently applied to the database.
SQLConnection
  
compact(responder:Responder = null):void
Reclaims all unused space in the database.
SQLConnection
  
deanalyze(responder:Responder = null):void
Removes all statistical information created by a call to the analyze() method.
SQLConnection
  
detach(name:String, responder:Responder = null):void
Detaches an additional database previously attached to the SQLConnection instance using the attach() method.
SQLConnection
 Inherited
Dispatches an event into the event flow.
EventDispatcher
  
Provides access to the result of a call to the loadSchema() method.
SQLConnection
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
  
loadSchema(type:Classe = null, name:String = null, database:String = "main", includeColumnSchema:Boolean = true, responder:Responder = null):void
This method loads schema information from the connected database or any attached databases.
SQLConnection
  
open(reference:Object = null, openMode:String = "create", autoCompact:Boolean = false, pageSize:int = -1):void
Opens a 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.
SQLConnection
  
openAsync(reference:Object = null, openMode:String = "create", responder:Responder = null, autoCompact:Boolean = false, pageSize:int = -1):void
Opens a 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.
SQLConnection
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
  
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
SQLConnection
  
rollback(responder:Responder = null):void
Rolls back an existing transaction created using the begin() method, meaning all changes made by any SQL statements in the transaction are discarded.
SQLConnection
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Eventos
 Evento Descrição Definido por
 Inherited Dispatched when Flash Player or the and AIR application gains operating system focus and becomes active.EventDispatcher
   Dispatched when an analyze() operation completes successfully.SQLConnection
   Dispatched when an attach() method call's operation completes successfully.SQLConnection
   Dispatched when a begin() method call's operation completes successfully.SQLConnection
   Dispatched when after cancel() method call's operation completes successfully.SQLConnection
   Dispatched when a close() method call's operation completes successfully.SQLConnection
   Dispatched when a commit() method call's operation completes successfully.SQLConnection
   Dispatched when a compact() method call's operation completes successfully.SQLConnection
 Inherited Dispatched when Flash Player loses operating system focus and is becoming inactive.EventDispatcher
   Dispatched when a deanalyze() method call's operation completes successfully.SQLConnection
   Dispatched when data in any table in any of the connected databases changes as a result of a SQL DELETE command.SQLConnection
   Dispatched when a detach() method call's operation completes successfully.SQLConnection
   Dispatched when any of the SQLConnection object's asynchronous operations results in an error.SQLConnection
   Dispatched when data in any table in any of the connected databases changes as a result of a SQL INSERT command.SQLConnection
   Dispatched when an open() method call's operation completes successfully.SQLConnection
   Dispatched when a rollback() method call's operation completes successfully.SQLConnection
   Dispatched when a loadSchema() method call's operation completes successfully and the schema results are ready.SQLConnection
   Dispatched when data in any table in any of the connected databases changes as a result of a SQL UPDATE command.SQLConnection
Detalhes da propriedade
autoCompactpropriedade
autoCompact:Boolean  [read-only]

Indicates if the current database has been set to use auto-compaction. Auto-compaction attempts to keep the size of the database file as small as possible by removing unused space within the file after each write operation.

This has performance impact and can fragment the database file over time.

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


Implementação
    public function get autoCompact():Boolean

Veja também

cacheSizepropriedade 
cacheSize:uint  [read-write]

Provides access to the cache size for this connection. The maximum number of database disk pages that will be held in memory at one time. Each page uses about 1.5K of memory. The default cache size is 2000. If you are doing UPDATEs or DELETEs that change many rows of a database increasing the cache size can improve performance.


Implementação
    public function get cacheSize():uint
    public function set cacheSize(value:uint):void

Veja também

columnNameStylepropriedade 
columnNameStyle:String  [read-write]

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:


Implementação
    public function get columnNameStyle():String
    public function set columnNameStyle(value:String):void

Throws
IllegalOperationError — When an attempt is made to set this property while the SQLConnection instance isn't connected to a database (the connected property is false).

Veja também

connectedpropriedade 
connected:Boolean  [read-only]

Indicates whether the SQLConnection instance has an open connection to a database file.


Implementação
    public function get connected():Boolean

Veja também

inTransactionpropriedade 
inTransaction:Boolean  [read-only]

Indicates whether this connection is currently involved in a transaction.


Implementação
    public function get inTransaction():Boolean

Veja também

lastInsertRowIDpropriedade 
lastInsertRowID:Number  [read-only]

The last generated row identifier generated by a SQL INSERT statement.

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

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


Implementação
    public function get lastInsertRowID():Number

Veja também

pageSizepropriedade 
pageSize:uint  [read-only]

Indicates the current page size set for the database. This value can only be set at database creation time.

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


Implementação
    public function get pageSize():uint

Veja também

totalChangespropriedade 
totalChanges:Number  [read-only]

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 file, the value is 0.


Implementação
    public function get totalChanges():Number

Veja também

Detalhes do construtor
SQLConnection()Construtor
public function SQLConnection()

Creates a SQLConnection instance.

The SQLConnection operates in two distinct modes; asynchronous and synchronous.

When you're using asynchronous execution, you must use event listeners to determine when an operation completes or fails. The operations run in the background rather than the main application thread, so the application continues to run and respond to user interaction even while the database operations are being performed.

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 noticable pause in the application.

Detalhes do método
addEventListener()método
public override function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void

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 exemplo, 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. Objects with registered event listeners are not automatically removed from memory because the garbage collector does not remove objects that still have references.

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).

Parâmetros

type:String — The type of event.
 
listener:Function — The listener function that processes the event. This function must accept an Event object as its only parameter and must return nothing, as this exemplo shows:
function(evt:Event):void

The function can have any name.

 
useCapture:Boolean (default = false)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 the useCapture set to true, then again with useCapture set to false.
 
priority:int (default = 0) — The 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.
 
useWeakReference:Boolean (default = false) — Determines 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.

Classe-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 garbge-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.

analyze()método 
public function analyze(resourceName:String = null, responder:Responder = null):void

The analyze() method gathers statistics about database indices and stores them in the database. These statistics can then be used 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(), 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 analyze() again might be beneficial. However, the benefit obtained from calling analyze() again will depend 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 pre-change data.

The resourceName parameter indicates whether the operation should be 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. 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 will not be taken into account by the analyze() call, and the analyze() data will be out of date as soon as the transaction is committed.

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

Parâmetros

resourceName:String (default = null) — The name of the database or table whose indices should 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.
 
responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
analyze:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation fails in asynchronous execution mode.

Throws
IllegalOperationError — When this method is called while the SQLConnection instance isn't connected to a database (the connected property is false).
 
SQLError — if the operation fails in synchronous execution mode.

Veja também

attach()método 
public function attach(name:String, reference:Object = null, responder:Responder = null):void

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() will result in an error event. 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()). 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() 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 is closed (by calling the close() method), all attached databases are detached.

The attached database will be opened with the same mode specifier used in the open() call.

Parâmetros

name:String — String The 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.
 
reference:Object (default = null) — Object A reference to the database file that should be attached. If the parameter's value is null, an in-memory database is attached.
 
responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
attach:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation fails in asynchronous execution mode.

Throws
ArgumentError — When the name parameter is an empty string ("") or null.
 
IllegalOperationError — If 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).
 
SQLError — if the operation fails in synchronous execution mode.

Veja também

begin()método 
public function begin(option:String = null, responder:Responder = null):void

Begins a transaction, within which all SQL statements executed against the connection's database(s) 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.

Nested transactions are not allowed (nested calls to begin() are ignored). To end a transaction, call the commit() or rollback() method, depending on whether the changes made by the transactions' statements should be made permanent or discarded.

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

Parâmetros

option:String (default = null) — Indicates the locking strategy that will be 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.
 
responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
begin:SQLEvent — Dispatched when the operation completes.
 
error:SQLErrorEvent — Dispatched when the operation fails in asynchronous execution mode.

Throws
IllegalOperationError — When this method is called while the SQLConnection instance isn't connected to a database (the connected property is false).
 
ArgumentError — If the option specified is not one of the SQLTransactionLockType constants.
 
SQLError — if the operation fails in synchronous execution mode.

Veja também

cancel()método 
public function cancel(responder:Responder = null):void

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 cancel() 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 does nothing.

Parâmetros

responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Throws
IllegalOperationError — When this method is called while the SQLConnection instance isn't connected to a database (the connected property is false).

Veja também

close()método 
public function close(responder:Responder = null):void

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 committed. 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.

Parâmetros

responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
close:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation fails in asynchronous execution mode.

Throws
SQLError — if the operation fails in synchronous execution mode.
commit()método 
public function commit(responder:Responder = null):void

Commits an existing transaction, causing any actions performed by the transaction's statements to be permanently applied to the database.

Parâmetros

responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
commit:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation completes with a failure.

Throws
IllegalOperationError — When the method is called while the SQLConnection instance isn't conntected to a database (the connected property is false); or if no transaction is currently open (the inTransaction property is false).

Veja também

compact()método 
public function compact(responder:Responder = null):void

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 will fail if there is an active transaction, and has no effect on an in-memory database.

Parâmetros

responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
compact:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation fails in asynchronous execution mode.

Throws
IllegalOperationError — 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).
 
SQLError — if the operation fails in synchronous execution mode.
deanalyze()método 
public function deanalyze(responder:Responder = null):void

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; however, it is recommended that you call this method only when inTransaction is false. This is because any data, table schema, or index changes that have been executed in the transaction but not yet committed will not be taken into account by the deanalyze() call.

Parâmetros

responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
deanalyze:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation fails in asynchronous execution mode.

Throws
IllegalOperationError — When this method is called while the SQLConnection instance isn't connected to a database (the connected property is false).
 
SQLError — if the operation fails in synchronous execution mode.

Veja também

detach()método 
public function detach(name:String, responder:Responder = null):void

Detaches an additional database previously attached to the SQLConnection instance using the attach() method. It is possible to have the same database file attached multiple times using different names, and detaching one connection to a file will leave the others intact. A database cannot be detached if the database has an open transaction (if the inTransaction property is true).

Parâmetros

name:String — The given name of the database to detach
 
responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
detach:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation fails in asynchronous execution mode.

Throws
ArgumentError — if the name argument is null or contains an empty string ("").
 
IllegalOperationError — If 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).
 
SQLError — if the operation fails in synchronous execution mode.

Veja também

getSchemaResult()método 
public function getSchemaResult():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.

Retorna
SQLSchemaResult

Veja também

loadSchema()método 
public function loadSchema(type:Classe = null, name:String = null, database:String = "main", includeColumnSchema:Boolean = true, responder:Responder = null):void

This method 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 database
valid table nameall indices defined on the specified table
valid index namethe specified index
SQLTableSchemanullall tables in the database
valid table namethe specified table
SQLTriggerSchemanullall triggers in the database
valid table nameall triggers associated with the specified table
valid view nameall triggers associated with the specified view
valid trigger namethe specified trigger
SQLViewSchemanullall views in the database
valid 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.

Parâmetros

type:Classe (default = null) — Indicates 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
 
name:String (default = null) — Indicates which resource's schema should be 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 syncronous 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.

 
database:String (default = "main") — The name of the database whose schema should be loaded. If the value specified is not valid an error event is dispatched.
 
includeColumnSchema:Boolean (default = true) — Indicates if the result should include schema information for the columns of tables and views.
 
responder:Responder (default = null) — 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 result or error event is dispatched when execution completes.


Eventos
schema:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation completes with a failure.

Throws
IllegalOperationError — When the method is called while the SQLConnection instance isn't connected to a database (the connected property is false).
 
ArgumentError — When the specified type argument value isn't one of the allowed types.
 
SQLError — When using synchronous execution mode, if an invalid value is supplied for the name or database parameters.

Veja também

open()método 
public function open(reference:Object = null, openMode:String = "create", autoCompact:Boolean = false, pageSize:int = -1):void

Opens a 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. These operations occur synchronously when using this method.

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].

Parâmetros

reference:Object (default = null) — The location of the database file that should be opened. This value must be of type File. If the parameter's value is null, an in-memory database is created and opened.
 
openMode:String (default = "create") — openMode Indicates how the database should be opened. The default value is SQLOpenMode.CREATE, indicating that if a database file is not found at the specified location, one will be created. If openMode is SQLOpenMode.READ and the specified file does not exist then an error event will be dispatched. This parameter is ignored when the reference parameter is null.
 
autoCompact:Boolean (default = false) — Indicates whether unused space in the database should be 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. To force the database to reclaim unused space in a database file at any time, use the compact() method.
 
pageSize:int (default = -1) — Indicates what the page size of the database should be. This parameter is only valid when creating a new database file. The value must be a power of two greater than or equal to 512 and less than or equal to 32768.


Eventos
open:SQLEvent — Dispatched when the operation completes successfully.

Throws
IllegalOperationError — When the SQLConnection instance already has an open connection to a database (the connected property is true).
 
SQLError — If the operation fails. The connection is never left open after a failed operation.
 
ArgumentError — If the reference specified is not of type File.

Veja também

openAsync()método 
public function openAsync(reference:Object = null, openMode:String = "create", responder:Responder = null, autoCompact:Boolean = false, pageSize:int = -1):void

Opens a 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. These operations occur asynchronously when using this method.

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].

Parâmetros

reference:Object (default = null) — The location of the database file that should be opened. This value must be of type File. If the parameter's value is null, an in-memory database is created and opened.
 
openMode:String (default = "create") — openMode Indicates how the database should be opened. The default value is SQLOpenMode.CREATE, indicating that if a database file is not found at the specified location, one will be created. If openMode is SQLOpenMode.READ and the specified file does not exist then an error event will be dispatched. This parameter is ignored when the reference parameter is null.
 
responder:Responder (default = null) — An object that designates methods to be called when the operation succeeds or fails. if the responder argument is null an event is dispatched when execution completes.
 
autoCompact:Boolean (default = false) — Indicates whether unused space in the database should be 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. To force the database to reclaim unused space in a database file at any time, use the compact() method.
 
pageSize:int (default = -1) — Indicates what the page size of the database should be. This parameter is only valid when creating a new database file. The value must be a power of two greater than or equal to 512 and less than or equal to 32768.


Eventos
open:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation fails. The connection is never left open after a failed operation.

Throws
IllegalOperationError — When the SQLConnection instance already has an open connection to a database (the connected property is true).
 
ArgumentError — If the reference specified is not of type File.

Veja também

removeEventListener()método 
public override function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void

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.

Parâmetros

type:String — The type of event.
 
listener:Function — The listener object to remove.
 
useCapture:Boolean (default = false)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.

rollback()método 
public function rollback(responder:Responder = null):void

Rolls back an existing transaction created using the begin() method, meaning all changes made by any SQL statements in the transaction are discarded.

Parâmetros

responder:Responder (default = null)


Eventos
rollback:SQLEvent — Dispatched when the operation completes successfully.
 
error:SQLErrorEvent — Dispatched when the operation fails in asynchronous execution mode.

Throws
IllegalOperationError — When the method is called while the SQLConnection instance isn't conntected to a database (the connected property is false); or if no transaction is currently open (the inTransaction property is false).
 
SQLError — if the operation fails in synchronous execution mode.

Veja também

Detalhes do evento
analyze Evento
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.ANALYZE

Dispatched when an analyze() operation completes successfully.

The SQLEvent.ANALYZE constant defines the value of the type property of an analyze event object. This type of event is dispatched when a SQLConnection.analyze() method call completes successfully. The analyze event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

attach Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.ATTACH

Dispatched when an attach() method call's operation completes successfully.

The SQLEvent.ATTACH constant defines the value of the type property of an attach event object. This type of event is dispatched when a SQLConnection.attach() method call completes successfully. The attach event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

begin Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.BEGIN

Dispatched when a begin() method call's operation completes successfully.

The SQLEvent.BEGIN constant defines the value of the type property of a begin event object. This type of event is dispatched when a SQLConnection.begin() method call completes successfully. The begin event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

cancel Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.CANCEL

Dispatched when after cancel() method call's operation completes successfully.

The SQLEvent.CANCEL constant defined the value of the type property of a cancel event object. This type of event is dispatched when a SQLConnection.cancel() or SQLStatement.cancel() method call completes successfully. The cancel event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection or SQLStatement object that performed the operation.

Veja também

close Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.CLOSE

Dispatched when a close() method call's operation completes successfully.

The SQLEvent.CLOSE constant defines the value of the type property of a close event object. This type of event is dispatched when a SQLConnection.close() method call completes successfully. The close event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

commit Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.COMMIT

Dispatched when a commit() method call's operation completes successfully.

The SQLEvent.COMMIT constant defines the value of the type property of a commit event object. This type of event is dispatched when a SQLConnection.commit() method call completes successfully. The commit event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

compact Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.COMPACT

Dispatched when a compact() method call's operation completes successfully.

The SQLEvent.COMPACT constant defines the value of the type property of a compact event object. This type of event is dispatched when a SQLConnection.compact() method call completes successfully. The compact event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

deanalyze Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.DEANALYZE

Dispatched when a deanalyze() method call's operation completes successfully.

The SQLEvent.DEANALYZE constant defines the value of the type property of a deanalyze event object. This type of event is dispatched when a SQLConnection.deanalyze() method call completes successfully. The deanalyze event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

delete Evento  
Event Object Type: flash.events.SQLUpdateEvent
SQLUpdateEvent.type property = flash.events.SQLUpdateEvent.DELETE

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.

The SQLUpdateEvent.DELETE constant defines the value of the type property of a SQLConnection delete event. The delete event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
rowIDThe unique row identifier of the row that was inserted, deleted, or updated.
targetThe SQLConnection object on which the operation was performed.
tableThe name of the table on which the change occurred.

Veja também

detach Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.DETACH

Dispatched when a detach() method call's operation completes successfully.

The SQLEvent.DETACH constant defines the value of the type property of a detach event object. This type of event is dispatched when a SQLConnection.detach() method call completes successfully.
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

error Evento  
Event Object Type: flash.events.SQLErrorEvent
SQLErrorEvent.type property = flash.events.SQLErrorEvent.ERROR

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.

The SQLErrorEvent.ERROR constant defines the value of the type property of an error event dispatched when a call to a method of a SQLConnection or SQLStatement instance completes with an error. The error event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
errorA SQLError object containing information about the type of error that occured and the operation that caused the error.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection or SQLStatement object reporting the error.
insert Evento  
Event Object Type: flash.events.SQLUpdateEvent
SQLUpdateEvent.type property = flash.events.SQLUpdateEvent.INSERT

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 a INSERT statement executed through a SQLStatement instance, or an indirect result caused by a trigger firing in response to a statement execution.

The SQLUpdateEvent.INSERT constant defines the value of the type property of a SQLConnection insert event. The insert event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
rowIDThe unique row identifier of the row that was inserted, deleted, or updated.
targetThe SQLConnection object on which the operation was performed.
tableThe name of the table on which the change occurred.

Veja também

open Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.OPEN

Dispatched when an open() method call's operation completes successfully.

The SQLEvent.OPEN constant defines the value of the type property of a open event object. This type of event is dispatched when a SQLConnection.open() method call completes successfully. The open event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

rollback Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.ROLLBACK

Dispatched when a rollback() method call's operation completes successfully.

The SQLEvent.ROLLBACK constant defines the value of the type property of a rollback event object. This type of event is dispatched when a SQLConnection.rollback() method call completes successfully. The rollback event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

schema Evento  
Event Object Type: flash.events.SQLEvent
SQLEvent.type property = flash.events.SQLEvent.SCHEMA

Dispatched when a loadSchema() method call's operation completes successfully and the schema results are ready.

The SQLEvent.SCHEMA constant defines the value of the type property of a schema event object. Dispatched when the SQLConnection.loadSchema() method completes successfully. Once the SQLEvent.SCHEMA event is dispatched the SQLConnection.getSchemaResult() method can be used to get the schema information. The schema event has the following properties:
PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
targetThe SQLConnection object that performed the operation.

Veja também

update Evento  
Event Object Type: flash.events.SQLUpdateEvent
SQLUpdateEvent.type property = flash.events.SQLUpdateEvent.UPDATE

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.

The SQLUpdateEvent.UPDATE constant defines the value of the type property of a SQLConnection update event.

The update event has the following properties:

PropriedadeValor
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the event object with an event listener.
rowIDThe unique row identifier of the row that was inserted, deleted, or updated.
targetThe SQLConnection object on which the operation was performed.
tableThe name of the table on which the change occurred.

Veja também