PHP Class Prado\Data\DataGateway\TDataGatewayCommand

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 {@link 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 {@link OnExecuteCommand} event is raised after the command is executed and resulting data is set in the TDataGatewayResultEventParameter object's Result property.
Since: 3.1
Inheritance: extends Prado\TComponent
Mostra file Open project: pradosoft/prado

Public Methods

Method Description
__construct ( $builder )
count ( TSqlCriteria $criteria ) : integer
createCriteriaFromString ( $method, $condition, $args ) : TActiveRecordCriteria
delete ( $criteria ) : integer Executes a delete command.
deleteByPk ( $keys ) : integer
find ( $criteria ) : array Find one record matching the critera.
findAll ( TSqlCriteria $criteria ) : TDbDataReader Find one or more matching records.
findAllByIndex ( $criteria, $fields, $values )
findAllByPk ( $keys ) : TDbDataReader
findAllBySql ( TSqlCriteria $criteria ) : TDbDataReader Find zero or more matching records for arbituary SQL.
findByPk ( $keys ) : array
findBySql ( TSqlCriteria $criteria ) : TDbDataReader Find one matching records for arbituary SQL.
getBuilder ( ) : TDbCommandBuilder
getDbConnection ( ) : TDbConnection
getIndexKeyCondition ( $table, $fields, $values )
getLastInsertID ( ) : mixed Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
getTableInfo ( ) : TDbTableInfo
insert ( $data ) : mixed 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.
onCreateCommand ( $command, $criteria ) Raised when a command is prepared and parameter binding is completed.
onExecuteCommand ( $command, $result ) Raised when a command is executed and the result from the database was returned.
update ( $data, $criteria ) : integer Updates the table with new data.
updateByPk ( $data, $keys ) : integer

Protected Methods

Method Description
extractMatchingConditions ( $method, $condition ) : array Calculates the AND/OR condition from dynamic method substrings using table meta data, allows for any AND-OR combinations.
getCompositeKeyCondition ( $values ) Construct a "pk IN ('key1', 'key2', .
getFindCommand ( TSqlCriteria $criteria ) : TDbCommand. Build the find command from the criteria. Limit, Offset and Ordering are applied if applicable.
getPrimaryKeyCondition ( $values ) : array Create the condition and parameters for find by primary.
getSqlCommand ( TSqlCriteria $criteria ) : TDbCommand Build sql command from the criteria. Limit, Offset and Ordering are applied if applicable.
quoteTuple ( $array ) : string

Method Details

__construct() public method

public __construct ( $builder )

count() public method

public count ( TSqlCriteria $criteria ) : integer
$criteria TSqlCriteria
return integer number of records.

createCriteriaFromString() public method

public createCriteriaFromString ( $method, $condition, $args ) : TActiveRecordCriteria
return TActiveRecordCriteria criteria created from the method name and its arguments.

delete() public method

Executes a delete command.
public delete ( $criteria ) : integer
return integer number of records affected.

deleteByPk() public method

public deleteByPk ( $keys ) : integer
return integer number of rows affected.

extractMatchingConditions() protected method

Calculates the AND/OR condition from dynamic method substrings using table meta data, allows for any AND-OR combinations.
protected extractMatchingConditions ( $method, $condition ) : array
return array search condition substrings

find() public method

Find one record matching the critera.
public find ( $criteria ) : array
return array matching record.

findAll() public method

Find one or more matching records.
public findAll ( TSqlCriteria $criteria ) : TDbDataReader
$criteria TSqlCriteria
return TDbDataReader record reader.

findAllByIndex() public method

public findAllByIndex ( $criteria, $fields, $values )

findAllByPk() public method

public findAllByPk ( $keys ) : TDbDataReader
return TDbDataReader record reader.

findAllBySql() public method

Find zero or more matching records for arbituary SQL.
public findAllBySql ( TSqlCriteria $criteria ) : TDbDataReader
$criteria TSqlCriteria
return TDbDataReader record reader.

findByPk() public method

public findByPk ( $keys ) : array
return array matching record.

findBySql() public method

Find one matching records for arbituary SQL.
public findBySql ( TSqlCriteria $criteria ) : TDbDataReader
$criteria TSqlCriteria
return TDbDataReader record reader.

getBuilder() public method

public getBuilder ( ) : TDbCommandBuilder
return TDbCommandBuilder

getCompositeKeyCondition() protected method

..)" criteria.
protected getCompositeKeyCondition ( $values )

getDbConnection() public method

public getDbConnection ( ) : TDbConnection
return TDbConnection

getFindCommand() protected method

Build the find command from the criteria. Limit, Offset and Ordering are applied if applicable.
protected getFindCommand ( TSqlCriteria $criteria ) : TDbCommand.
$criteria TSqlCriteria
return TDbCommand.

getIndexKeyCondition() public method

public getIndexKeyCondition ( $table, $fields, $values )

getLastInsertID() public method

Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
public getLastInsertID ( ) : mixed
return mixed last insert id, null if none is found.

getPrimaryKeyCondition() protected method

Create the condition and parameters for find by primary.
protected getPrimaryKeyCondition ( $values ) : array
return array tuple($where, $parameters)

getSqlCommand() protected method

Build sql command from the criteria. Limit, Offset and Ordering are applied if applicable.
protected getSqlCommand ( TSqlCriteria $criteria ) : TDbCommand
$criteria TSqlCriteria
return TDbCommand command corresponding to the criteria.

getTableInfo() public method

public getTableInfo ( ) : TDbTableInfo
return TDbTableInfo

insert() public method

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.
public insert ( $data ) : mixed
return mixed last insert id if one column contains a serial or sequence, otherwise true if command executes successfully and affected 1 or more rows.

onCreateCommand() public method

The parameter object is TDataGatewayEventParameter of which the {@link TDataGatewayEventParameter::getCommand Command} property can be inspected to obtain the sql query to be executed.
public onCreateCommand ( $command, $criteria )

onExecuteCommand() public method

The parameter object is TDataGatewayResultEventParameter of which the {@link TDataGatewayEventParameter::getResult Result} property contains the data return from the database. The data returned can be changed by setting the {@link TDataGatewayEventParameter::setResult Result} property.
public onExecuteCommand ( $command, $result )

quoteTuple() protected method

protected quoteTuple ( $array ) : string
return string quoted recursive tuple values, e.g. "('val1', 'val2')".

update() public method

Updates the table with new data.
public update ( $data, $criteria ) : integer
return integer number of records affected.

updateByPk() public method

public updateByPk ( $data, $keys ) : integer
return integer number of records affected.