Packagecom.ericfeminella.air.cairngorm.business
Classpublic class SQLService

Provides an API from which Adobe AIR SQL specific classes can be managed uniformly as a Service when building an application on Adobe Cairngorm

SQLService wraps both the SQLStatement and SQLConnection in order to provide a Service from which CRUD operations can be performed on a SQLite database in the same manner as one would access typical RPC Services.

SQLService supports both synchronous and asyncronous transactions. A set of convenience methods have also been provided to interface with the underlying SQLConnection object in order to perform transactions.


Example
The following example demonstrates a typical implementation of SQLService defined by AIRServiceLocator
  
  <?xml version="1.0" encoding="utf-8"?>                      
  <services:AIRServiceLocator xmlns:mx = "http://www.adobe.com/2006/mxml"
                                 xmlns:services = "com.ericfeminella.air.cairngorm.business." >
  
   <services:SQLService id = "service" 
                localDatabaseFilePath = "{ File.desktopDirectory.nativePath.toString() }"  
                localDatabaseFileName = "air.cairngorm.example.db"
                />
  
  

See also

com.adobe.cairngorm.business.ServiceLocator
flash.filesystem.File
flash.data.SQLConnection
com.ericfeminella.sql.ISQLResponder


Public Properties
 PropertyDefined by
  connection : SQLConnection
[read-only] Retrieves the SQLService SQLConnection instance
SQLService
  localDatabaseFileName : String
Retrieves the name of the local SQLite database
SQLService
  localDatabaseFilePath : String
Retrieves the path to the local SQLite database
SQLService
  result : SQLResult
[read-only] Retrieves the SQLResult object instance from the last statement execution.
SQLService
  statement : SQLStatement
[read-only] Retrieves the SQLService SQLStatement instance
SQLService
Protected Properties
 PropertyDefined by
  _connection : SQLConnection
Defines the SQLConnection from which the Service is connected
SQLService
  _databaseFile : File
Defines a reference to the physical file which contains a local SQLite database
SQLService
  databaseFileName : String
Defines the qualified name of a local SQLite database
SQLService
  databaseFilePath : String
Defines the absolute path to a local SQLite database
SQLService
  _statement : SQLStatement
Defines the SQLStatement from which queries are executed
SQLService
Public Methods
 MethodDefined by
  
Creates a new instance of SQLService and initiates members
SQLService
  
beginTransaction(lockType:String = null):void
Begins a transaction, within which all SQL statements executed against the connection's database(s) are grouped.
SQLService
  
Commits an existing transaction, causing any actions performed by the transaction's statements to be permanently applied to the database.
SQLService
  
databaseFile():File
Retrieves the local SQLite database file object
SQLService
  
execute(statement:String, dataType:Class = null, prefetch:int = -1.0):SQLResult
Executes a specific SQL operation against the SQLService synchronous mode
SQLService
  
executeAsync(statement:String, responder:ISQLResponder, dataType:Class = null, prefetch:int = -1.0):void
Executes a specific SQL operation against the SQLService in asynchronous mode
SQLService
  
open():SQLConnection
Provides a mechanism for opening the underlying SQLite database connection in synchronous mode
SQLService
  
openAsync(openHandler:Function = null, errorHandler:Function = null):void
Provides a mechanism for opening the underlying SQLite database connection in asynchronous mode
SQLService
  
Rolls back an existing transaction created using the begin() method, meaning all changes made by any SQL statements in the transaction are discarded.
SQLService
Property detail
_connectionproperty
protected var _connection:SQLConnection

Defines the SQLConnection from which the Service is connected

connectionproperty 
connection:SQLConnection  [read-only]

Retrieves the SQLService SQLConnection instance

Implementation
    public function get connection():SQLConnection
_databaseFileproperty 
protected var _databaseFile:File

Defines a reference to the physical file which contains a local SQLite database

See also

flash.filesystem.File
databaseFileNameproperty 
protected var databaseFileName:String

Defines the qualified name of a local SQLite database

databaseFilePathproperty 
protected var databaseFilePath:String

Defines the absolute path to a local SQLite database

localDatabaseFileNameproperty 
localDatabaseFileName:String  [read-write]

Retrieves the name of the local SQLite database

Implementation
    public function get localDatabaseFileName():String
    public function set localDatabaseFileName(value:String):void
localDatabaseFilePathproperty 
localDatabaseFilePath:String  [read-write]

Retrieves the path to the local SQLite database

Implementation
    public function get localDatabaseFilePath():String
    public function set localDatabaseFilePath(value:String):void
resultproperty 
result:SQLResult  [read-only]

Retrieves the SQLResult object instance from the last statement execution. For synchronous mode only.

Typically one uses a SQLResult.data object to access the rows of data returned by a SELECT statement.

Implementation
    public function get result():SQLResult
_statementproperty 
protected var _statement:SQLStatement

Defines the SQLStatement from which queries are executed

statementproperty 
statement:SQLStatement  [read-only]

Retrieves the SQLService SQLStatement instance

Implementation
    public function get statement():SQLStatement
Constructor detail
SQLService()constructor
public function SQLService()

Creates a new instance of SQLService and initiates members

Method detail
beginTransaction()method
public function beginTransaction(lockType:String = null):void

Begins a transaction, within which all SQL statements executed against the connection's database(s) are grouped.

Parameters
lockType:String (default = null)
commitTransaction()method 
public function commitTransaction():void

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

databaseFile()method 
public function databaseFile():File

Retrieves the local SQLite database file object

Returns
File — the local SQLite database file object
execute()method 
public function execute(statement:String, dataType:Class = null, prefetch:int = -1.0):SQLResult

Executes a specific SQL operation against the SQLService synchronous mode

Parameters
statement:String — SQL statement which to execute
 
dataType:Class (default = null) — which handles the operation result / fault
 
prefetch:int (default = -1.0) — the type in which a result is to be deserialized

Returns
SQLResult
executeAsync()method 
public function executeAsync(statement:String, responder:ISQLResponder, dataType:Class = null, prefetch:int = -1.0):void

Executes a specific SQL operation against the SQLService in asynchronous mode

Parameters
statement:String — SQL statement which to execute
 
responder:ISQLResponder — which handles the operation result / fault
 
dataType:Class (default = null) — the type in which a result is to be deserialized
 
prefetch:int (default = -1.0) — prefetch
open()method 
public function open():SQLConnection

Provides a mechanism for opening the underlying SQLite database connection in synchronous mode

Returns
SQLConnection — reference to the SQLConnection which has been opened
openAsync()method 
public function openAsync(openHandler:Function = null, errorHandler:Function = null):void

Provides a mechanism for opening the underlying SQLite database connection in asynchronous mode

Parameters
openHandler:Function (default = null) — handler for an SQLEvent.OPEN event
 
errorHandler:Function (default = null) — optional handler for an SQLErrorEvent.ERROR event
rollbackTransaction()method 
public function rollbackTransaction():void

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