| Package | phi.interfaces |
| Interface | public interface IQuery extends flash.events.IEventDispatcher |
| Implementors | Query |
Query object.
A IQuery implementor have these responsibilities:
See also
| Property | Defined by | ||
|---|---|---|---|
| database : IDatabase
[write-only]
| IQuery | ||
| q : String [write-only]
| IQuery | ||
| queryEnd : Function [write-only]
| IQuery | ||
| Records : ArrayCollection | IQuery | ||
| Method | Defined by | ||
|---|---|---|---|
|
arrayInsert(table:String, arr:Array):String
Execute a INSERT query on a table.
| IQuery | ||
|
arrayUpdate(table:String, arr:Array, cond:String):String
Execute a UPDATE query on a table.
| IQuery | ||
|
This function allow to select the connection you want to
use for executing a SQL statements.
| IQuery | ||
|
execute(q:String, option:String = "select"):void
Execte a SQL statement.
| IQuery | ||
|
Get the current used connection.
| IQuery | ||
|
getError():String
Get the last SQL error.
| IQuery | ||
|
getLastInsertID():Number
Get the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
| IQuery | ||
|
getRecords():ArrayCollection
Get the records selected with a previous
execute() method. | IQuery | ||
|
getRow():Object
Get the next row from a previous selected records.
| IQuery | ||
|
isStackEmpty():Boolean
| IQuery | ||
|
toString():String
Return the query.
| IQuery | ||
| database | property |
| q | property |
q:String [write-only]Implementation
public function set q(value:String):void
| queryEnd | property |
queryEnd:Function [write-only]Implementation
public function set queryEnd(value:Function):void
| Records | property |
Records:ArrayCollection [read-write]This property can be used as the source for data binding.
Implementation public function get Records():ArrayCollection
public function set Records(value:ArrayCollection):void
| arrayInsert | () | method |
public function arrayInsert(table:String, arr:Array):StringExecute a INSERT query on a table.
This function can be used to save data into database. After parsing
the array this function generate a SQL statement and execute it with
execute() method.
table:String — the name of the table
|
|
arr:Array — the array that contains the data.
|
String — the SQL generated from array.
|
private functin insertNewUsers(q:IQuery):void
{
var arr :Array = new Array();
arr.push({key: fname, value: "pop"});
arr.push({key: lname, value: "lpopname"});
q.addEventListener(Query.QUERY_END, processQuery);
q.addEventListener(Query.QUERY_ERROR, processQueryError);
q.arrayInsert("users", arr);
}
private function processQuery(evt:Object):void
{
....
}
private function processQueryError(evt:Object):void
{
...
}
| arrayUpdate | () | method |
public function arrayUpdate(table:String, arr:Array, cond:String):StringExecute a UPDATE query on a table.
Parameterstable:String |
|
arr:Array |
|
cond:String |
String |
| connect | () | method |
public function connect(connection:String, db:IDatabase):void
This function allow to select the connection you want to
use for executing a SQL statements.
You must create a connection
with Database.connect() before using this.
You must select a connection before doing any operations
with a Query object.
connection:String — the connection name
|
|
db:IDatabase — a IDatabase object
|
See also
var db :IDatabase = Database.getInstance();
var q :IQuery = new Query();
db.connect("conn1", "pop", "poppass", "localhost", "yb20");
db.connect("conn2", "pop", "poppass", "localhost", "test_db");
q.connect("conn2");
| execute | () | method |
public function execute(q:String, option:String = "select"):voidExecte a SQL statement. Before executing the SQL statement this function dispatch a Query.QUERY_START event and when the SQL statement has finish execution a Query.QUERY_END will be dispatched.
Parametersq:String — the SQL string
|
|
option:String (default = "select") — leave this on default
|
— Error if there are any SQL errors.
|
var db :IDatabase = Database.getInstance();
var q :IQuery = new Query();
private function connect():void
{
db.connect("conn1", "pop", "poppass", "localhost", "test_db");
q.connect("conn1");
}
private function getUsers():void
{
connect();
q.addEventListener(Query.QUERY_END, onGetUsers);
q.execute("SELECT fname FROM users WHERE 1");
}
private function onGetUsers(evt:Object):void
{
var q :IQuery = evt.target as IQuery;
var users :ArrayCollection = q.getRecords();
}
| getConnection | () | method |
public function getConnection():ConnectionDataGet the current used connection.
ReturnsConnectionData —
the current used connection for execution of SQL statement.
|
| getError | () | method |
public function getError():StringGet the last SQL error.
ReturnsString — the SQL error.
|
| getLastInsertID | () | method |
public function getLastInsertID():NumberGet the ID generated for an AUTO_INCREMENT column by the previous INSERT query.
ReturnsNumber — the ID generated for an AUTO_INCREMENT
|
| getRecords | () | method |
public function getRecords():ArrayCollection
Get the records selected with a previous execute() method.
ArrayCollection — a ArrayCollection with all selected records.
|
| getRow | () | method |
public function getRow():ObjectGet the next row from a previous selected records.
This function can be used to process the selected records.
ReturnsObject — a Object with the row information.
|
......
......
private functin process(q:IQuery):void
{
var row :Object = new Object();
while((row = q.getRow()) != null)
{
row.fname += "_process";
}
}
| isStackEmpty | () | method |
public function isStackEmpty():BooleanReturns
Boolean — true if execute stack is empty.
|
| toString | () | method |
public function toString():StringReturn the query.
ReturnsString — the query.
|