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.
Method Summary |
integer
|
|
TActiveRecordCriteria
|
|
integer
|
Executes a delete command.
|
integer
|
|
protected
array
|
Calculates the AND/OR condition from dynamic method substrings using table meta data, allows for any AND-OR combinations.
|
array
|
Find one record matching the critera.
|
TDbDataReader
|
Find one or more matching records.
|
void
|
|
TDbDataReader
|
|
TDbDataReader
|
Find zero or more matching records for arbituary SQL.
|
array
|
|
TDbDataReader
|
Find one matching records for arbituary SQL.
|
TDbCommandBuilder
|
|
protected
void
|
Construct a "pk IN ('key1', 'key2', ...)" criteria.
|
TDbConnection
|
|
protected
TDbCommand.
|
Build the find command from the criteria. Limit, Offset and Ordering are applied if applicable.
|
void
|
|
mixed
|
Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
|
protected
array
|
Create the condition and parameters for find by primary.
|
protected
TDbCommand
|
Build sql command from the criteria. Limit, Offset and Ordering are applied if applicable.
|
TDbTableInfo
|
|
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.
|
void
|
Raised when a command is prepared and parameter binding is completed.
|
void
|
Raised when a command is executed and the result from the database was returned.
|
protected
string
|
|
integer
|
Updates the table with new data.
|
integer
|
|
Method Details |
count
Input |
TSqlCriteria | $criteria | |
Output |
integer
| number of records. |
Exception |
|
createCriteriaFromString
public TActiveRecordCriteria createCriteriaFromString |
(string $method , string $condition , array $args ) |
Input |
string | $method | __call method name |
string | $condition | criteria conditions |
array | $args | method arguments |
Output |
TActiveRecordCriteria
| criteria created from the method name and its arguments. |
Exception |
|
delete
Executes a delete command.
Input |
TSqlCriteria | $criteria | delete conditions and parameters. |
Output |
integer
| number of records affected. |
Exception |
|
deleteByPk
public integer deleteByPk |
(array $keys ) |
Input |
array | $keys | multiple primary key values or composite value arrays |
Output |
integer
| number of rows affected. |
Exception |
|
extractMatchingConditions
protected array extractMatchingConditions |
(string $method , string $condition ) |
Calculates the AND/OR condition from dynamic method substrings using table meta data, allows for any AND-OR combinations.
Input |
string | $method | dynamic method name |
string | $condition | dynamic method search criteria |
Output |
array
| search condition substrings |
Exception |
|
find
Find one record matching the critera.
Input |
TSqlCriteria | $criteria | find conditions and parameters. |
Output |
array
| matching record. |
Exception |
|
findAll
Find one or more matching records.
|
findAllByIndex
public void findAllByIndex |
(mixed $criteria , mixed $fields , mixed $values ) |
Input |
mixed | $criteria | |
mixed | $fields | |
mixed | $values | |
Output |
Exception |
|
findAllByPk
Input |
array | $keys | multiple primary key values or composite value arrays |
Output |
TDbDataReader
| record reader. |
Exception |
|
findAllBySql
Find zero or more matching records for arbituary SQL.
|
findByPk
public array findByPk |
(mixed $keys ) |
Input |
mixed | $keys | primary key value, or composite key values as array. |
Output |
array
| matching record. |
Exception |
|
findBySql
Find one matching records for arbituary SQL.
|
getBuilder
|
getCompositeKeyCondition
protected void getCompositeKeyCondition |
(array $values , string 1 ) |
Construct a "pk IN ('key1', 'key2', ...)" criteria.
Input |
array | $values | values for IN predicate |
string | 1 | SQL string for primary keys IN a list. |
Output |
Exception |
|
getDbConnection
|
getFindCommand
protected TDbCommand. getFindCommand |
(TSqlCriteria $criteria ) |
Build the find command from the criteria. Limit, Offset and Ordering are applied if applicable.
|
getIndexKeyCondition
public void getIndexKeyCondition |
(mixed $table , mixed $fields , mixed $values ) |
Input |
mixed | $table | |
mixed | $fields | |
mixed | $values | |
Output |
Exception |
|
getLastInsertID
public mixed getLastInsertID |
() |
Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
Output |
mixed
| last insert id, null if none is found. |
Exception |
|
getPrimaryKeyCondition
protected array getPrimaryKeyCondition |
(array $values ) |
Create the condition and parameters for find by primary.
Input |
array | $values | primary key values |
Output |
array
| tuple($where, $parameters) |
Exception |
|
getSqlCommand
Build sql command from the criteria. Limit, Offset and Ordering are applied if applicable.
|
getTableInfo
|
insert
public mixed insert |
(array $data ) |
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.
Input |
array | $data | new record data. |
Output |
mixed
| last insert id if one column contains a serial or sequence, otherwise true if command executes successfully and affected 1 or more rows. |
Exception |
|
onCreateCommand
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.
|
onExecuteCommand
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.
|
quoteTuple
Input |
TDbConnection | $array | database connection. |
array | 1 | values |
Output |
string
| quoted recursive tuple values, e.g. "('val1', 'val2')". |
Exception |
|
update
public integer update |
(array $data , TSqlCriteria $criteria ) |
Updates the table with new data.
Input |
array | $data | date for update. |
TSqlCriteria | $criteria | update conditions and parameters. |
Output |
integer
| number of records affected. |
Exception |
|
updateByPk
public integer updateByPk |
(array $data , array $keys ) |
Input |
array | $data | update for update |
array | $keys | primary key-value name pairs. |
Output |
integer
| number of records affected. |
Exception |
|