## Class TDataGatewayCommand

Description

TDataGatewayCommand is command builder and executor class for TTableGateway and TActiveRecordGateway.

TDataGatewayCommand builds the TDbCommand for TTableGateway and TActiveRecordGateway commands such as find(), update(), insert(), etc, using the TDbCommandBuilder classes (database specific TDbCommandBuilder classes are used).

Once the command is built and the query parameters are binded, the OnCreateCommand event is raised. Event handlers for the OnCreateCommand event should not alter the Command property nor the Criteria property of the TDataGatewayEventParameter.

TDataGatewayCommand excutes the TDbCommands and returns the result obtained from the database (returned value depends on the method executed). The OnExecuteCommand event is raised after the command is executed and resulting data is set in the TDataGatewayResultEventParameter object's Result property.

- since: 3.1
- version: $Id$
- author: Wei Zhuo <weizho[at]gmail[dot]com>

Located in /Data/DataGateway/TDataGatewayCommand.php (line 37)

    TComponent
       |
       --TDataGatewayCommand

Method Summary
TDataGatewayCommand __construct (TDbCommandBuilder $builder)
integer count (TSqlCriteria $criteria)
TActiveRecordCriteria createCriteriaFromString (string $method, string $condition, array $args)
integer delete (TSqlCriteria $criteria)
integer deleteByPk (array $keys)
array extractMatchingConditions (string $method, string $condition)
array find (TSqlCriteria $criteria)
TDbDataReader findAll (TSqlCriteria $criteria)
void findAllByIndex (mixed $criteria, mixed $fields, mixed $values)
TDbDataReader findAllByPk (array $keys)
TDbDataReader findAllBySql (TSqlCriteria $criteria)
array findByPk (mixed $keys)
TDbDataReader findBySql (TSqlCriteria $criteria)
TDbCommandBuilder getBuilder ()
void getCompositeKeyCondition (array $values, string 1)
TDbConnection getDbConnection ()
TDbCommand. getFindCommand (TSqlCriteria $criteria)
void getIndexKeyCondition (mixed $table, mixed $fields, mixed $values)
mixed getLastInsertID ()
array getPrimaryKeyCondition (array $values)
TDbCommand getSqlCommand (TSqlCriteria $criteria)
TDbTableInfo getTableInfo ()
mixed insert (array $data)
void onCreateCommand (TDataGatewayCommand $command, TDataGatewayEventParameter $criteria)
void onExecuteCommand (TDataGatewayCommand $command, TDataGatewayResultEventParameter $result)
string quoteTuple (TDbConnection $array, array 1)
integer update (array $data, TSqlCriteria $criteria)
integer updateByPk (array $data, array $keys)
Methods
Constructor __construct (line 44)

- access: public

TDataGatewayCommand __construct (TDbCommandBuilder $builder)

- TDbCommandBuilder $builder: database specific database command builder.

count (line 332)

- return: number of records.
- access: public

integer count (TSqlCriteria $criteria)

- TSqlCriteria $criteria

createCriteriaFromString (line 382)

- return: criteria created from the method name and its arguments.
- access: public

TActiveRecordCriteria createCriteriaFromString (string $method, string $condition, array $args)

- string $method: __call method name
- string $condition: criteria conditions
- array $args: method arguments

delete (line 78)

Executes a delete command.

- return: number of records affected.
- access: public

integer delete (TSqlCriteria $criteria)

- TSqlCriteria $criteria: delete conditions and parameters.

deleteByPk (line 197)

- return: number of rows affected.
- access: public

integer deleteByPk (array $keys)

- array $keys: multiple primary key values or composite value arrays

extractMatchingConditions (line 401)

Calculates the AND/OR condition from dynamic method substrings using table meta data, allows for any AND-OR combinations.

- return: search condition substrings
- access: protected

array extractMatchingConditions (string $method, string $condition)

- string $method: dynamic method name
- string $condition: dynamic method search criteria

find (line 120)

Find one record matching the critera.

- return: matching record.
- access: public

array find (TSqlCriteria $criteria)

- TSqlCriteria $criteria: find conditions and parameters.

findAll (line 131)

Find one or more matching records.

- return: record reader.
- access: public

TDbDataReader findAll (TSqlCriteria $criteria)

- TSqlCriteria $criteria

findAllByIndex (line 181)

- access: public

void findAllByIndex (mixed $criteria, mixed $fields, mixed $values)
findAllByPk (line 173)

- return: record reader.
- access: public

TDbDataReader findAllByPk (array $keys)

- array $keys: multiple primary key values or composite value arrays

findAllBySql (line 301)

Find zero or more matching records for arbituary SQL.

- return: record reader.
- access: public

TDbDataReader findAllBySql (TSqlCriteria $criteria)

- TSqlCriteria $criteria

findByPk (line 161)

- return: matching record.
- access: public

array findByPk (mixed $keys)

- mixed $keys: primary key value, or composite key values as array.

findBySql (line 290)

Find one matching records for arbituary SQL.

- return: record reader.
- access: public

TDbDataReader findBySql (TSqlCriteria $criteria)

- TSqlCriteria $criteria

getBuilder (line 68)

- access: public

TDbCommandBuilder getBuilder ()
getCompositeKeyCondition (line 222)

Construct a "pk IN ('key1', 'key2', ...)" criteria.

- access: protected

void getCompositeKeyCondition (array $values, string 1)

- string 1: SQL string for primary keys IN a list.
- array $values: values for IN predicate

getDbConnection (line 60)

- access: public

TDbConnection getDbConnection ()
getFindCommand (line 142)

Build the find command from the criteria. Limit, Offset and Ordering are applied if applicable.

- access: protected

TDbCommand. getFindCommand (TSqlCriteria $criteria)

- TSqlCriteria $criteria

getIndexKeyCondition (line 206)

- access: public

void getIndexKeyCondition (mixed $table, mixed $fields, mixed $values)
getLastInsertID (line 371)

Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.

- return: last insert id, null if none is found.
- access: public

mixed getLastInsertID ()
getPrimaryKeyCondition (line 265)

Create the condition and parameters for find by primary.

- return: tuple($where, $parameters)
- access: protected

array getPrimaryKeyCondition (array $values)

- array $values: primary key values

getSqlCommand (line 312)

Build sql command from the criteria. Limit, Offset and Ordering are applied if applicable.

- return: command corresponding to the criteria.
- access: protected

TDbCommand getSqlCommand (TSqlCriteria $criteria)

- TSqlCriteria $criteria

getTableInfo (line 52)

- access: public

TDbTableInfo getTableInfo ()
insert (line 353)

Inserts a new record into the table. Each array key must correspond to a column name in the table unless a null value is permitted.

- return: last insert id if one column contains a serial or sequence, otherwise true if command executes successfully and affected 1 or more rows.
- access: public

mixed insert (array $data)

- array $data: new record data.

onCreateCommand (line 434)

Raised when a command is prepared and parameter binding is completed.

The parameter object is TDataGatewayEventParameter of which the TDataGatewayEventParameter::getCommand property can be inspected to obtain the sql query to be executed.

- access: public

void onCreateCommand (TDataGatewayCommand $command, TDataGatewayEventParameter $criteria)

- TDataGatewayCommand $command: originator $sender
- TDataGatewayEventParameter $criteria

onExecuteCommand (line 448)

Raised when a command is executed and the result from the database was returned.

The parameter object is TDataGatewayResultEventParameter of which the TDataGatewayEventParameter::getResult property contains the data return from the database. The data returned can be changed by setting the TDataGatewayEventParameter::setResult property.

- access: public

void onExecuteCommand (TDataGatewayCommand $command, TDataGatewayResultEventParameter $result)

- TDataGatewayCommand $command: originator $sender
- TDataGatewayResultEventParameter $result

quoteTuple (line 251)

- return: quoted recursive tuple values, e.g. "('val1', 'val2')".
- access: protected

string quoteTuple (TDbConnection $array, array 1)

- array 1: values
- TDbConnection $array: database connection.

update (line 94)

Updates the table with new data.

- return: number of records affected.
- access: public

integer update (array $data, TSqlCriteria $criteria)

- array $data: date for update.
- TSqlCriteria $criteria: update conditions and parameters.

updateByPk (line 109)

- return: number of records affected.
- access: public

integer updateByPk (array $data, array $keys)

- array $data: update for update
- array $keys: primary key-value name pairs.

#### Inherited Methods

Inherited From TComponent

> TComponent::addParsedObject()
> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::createdOnTemplate()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Documentation generated on Mon, 22 Feb 2010 12:17:20 +0000 by phpDocumentor 1.3.0RC4