Packages:
default
System
System.Caching
System.Collections
System.Data
System.Data.ActiveRecord
System.Data.ActiveRecord.Relations
System.Data.ActiveRecord.Scaffold
System.Data.ActiveReecord.Scaffold.InputBuilder
System.Data.Commom.Sqlite
System.Data.Common
System.Data.Common.Mssql
System.Data.Common.Mysql
System.Data.Common.Oracle
System.Data.Common.Pgsql
System.Data.Common.Sqlite
System.Data.DataGateway
System.Data.SqlMap
System.Data.SqlMap.Configuration
System.Data.SqlMap.Statements
System.Exceptions
System.I18N
System.IO
System.Security
System.Util
System.Web
System.Web.Services
System.Web.UI
System.Web.UI.ActiveControls
System.Web.UI.WebControls
System.Web.UI.WebControls.assets
System.Xml


Classes:
Keyword

Class TDataGatewayCommand

TComponent
   |
   --TDataGatewayCommand

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
Author: Wei Zhuo <weizho[at]gmail[dot]com>

Constructor Summary
public
__construct Array

Method Summary
integer
count ( TSqlCriteria $criteria)
TActiveRecordCriteria
createCriteriaFromString ( string $method, string $condition, array $args)
integer
delete ( TSqlCriteria $criteria)
Executes a delete command.
integer
deleteByPk ( array $keys)
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.
array
find ( TSqlCriteria $criteria)
Find one record matching the critera.
TDbDataReader
findAll ( TSqlCriteria $criteria)
Find one or more matching records.
void
findAllByIndex ( mixed $criteria, mixed $fields, mixed $values)
TDbDataReader
findAllByPk ( array $keys)
TDbDataReader
findAllBySql ( TSqlCriteria $criteria)
Find zero or more matching records for arbituary SQL.
array
findByPk ( mixed $keys)
TDbDataReader
findBySql ( TSqlCriteria $criteria)
Find one matching records for arbituary SQL.
TDbCommandBuilder
protected  void
getCompositeKeyCondition ( array $values, string 1)
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
getIndexKeyCondition ( mixed $table, mixed $fields, mixed $values)
mixed
Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
protected  array
getPrimaryKeyCondition ( array $values)
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
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.
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
quoteTuple ( TDbConnection $array, array 1)
integer
update ( array $data, TSqlCriteria $criteria)
Updates the table with new data.
integer
updateByPk ( array $data, array $keys)
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()

Constructor Details

__construct

public __construct Array


Method Details

count

public integer count (TSqlCriteria $criteria )

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$conditioncriteria conditions
array$argsmethod arguments
Output
TActiveRecordCriteria criteria created from the method name and its arguments.
Exception

delete

public integer delete (TSqlCriteria $criteria )

Executes a delete command.

Input
TSqlCriteria$criteriadelete conditions and parameters.
Output
integer number of records affected.
Exception

deleteByPk

public integer deleteByPk (array $keys )

Input
array$keysmultiple 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$methoddynamic method name
string$conditiondynamic method search criteria
Output
array search condition substrings
Exception

find

public array find (TSqlCriteria $criteria )

Find one record matching the critera.

Input
TSqlCriteria$criteriafind conditions and parameters.
Output
array matching record.
Exception

findAll

public TDbDataReader findAll (TSqlCriteria $criteria )

Find one or more matching records.

Input
TSqlCriteria$criteria
Output
TDbDataReader record reader.
Exception

findAllByIndex

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

Input
mixed$criteria
mixed$fields
mixed$values
Output
Exception

findAllByPk

public TDbDataReader findAllByPk (array $keys )

Input
array$keysmultiple primary key values or composite value arrays
Output
TDbDataReader record reader.
Exception

findAllBySql

public TDbDataReader findAllBySql (TSqlCriteria $criteria )

Find zero or more matching records for arbituary SQL.

Input
TSqlCriteria$criteria
Output
TDbDataReader record reader.
Exception

findByPk

public array findByPk (mixed $keys )

Input
mixed$keysprimary key value, or composite key values as array.
Output
array matching record.
Exception

findBySql

public TDbDataReader findBySql (TSqlCriteria $criteria )

Find one matching records for arbituary SQL.

Input
TSqlCriteria$criteria
Output
TDbDataReader record reader.
Exception

getBuilder

public TDbCommandBuilder getBuilder ()

Output
Exception

getCompositeKeyCondition

protected void getCompositeKeyCondition (array $values , string 1 )

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

Input
array$valuesvalues for IN predicate
string1SQL string for primary keys IN a list.
Output
Exception

getDbConnection

public TDbConnection getDbConnection ()

Output
Exception

getFindCommand

protected TDbCommand. getFindCommand (TSqlCriteria $criteria )

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

Input
TSqlCriteria$criteria
Output
Exception

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$valuesprimary key values
Output
array tuple($where, $parameters)
Exception

getSqlCommand

protected TDbCommand getSqlCommand (TSqlCriteria $criteria )

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

Input
TSqlCriteria$criteria
Output
TDbCommand command corresponding to the criteria.
Exception

getTableInfo

public TDbTableInfo getTableInfo ()

Output
Exception

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$datanew 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

public void onCreateCommand (TDataGatewayCommand $command , TDataGatewayEventParameter $criteria )

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.

Input
TDataGatewayCommand$commandoriginator $sender
TDataGatewayEventParameter$criteria
Output
Exception

onExecuteCommand

public void onExecuteCommand (TDataGatewayCommand $command , TDataGatewayResultEventParameter $result )

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.

Input
TDataGatewayCommand$commandoriginator $sender
TDataGatewayResultEventParameter$result
Output
Exception

quoteTuple

protected string quoteTuple (TDbConnection $array , array 1 )

Input
TDbConnection$arraydatabase connection.
array1values
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$datadate for update.
TSqlCriteria$criteriaupdate conditions and parameters.
Output
integer number of records affected.
Exception

updateByPk

public integer updateByPk (array $data , array $keys )

Input
array$dataupdate for update
array$keysprimary key-value name pairs.
Output
integer number of records affected.
Exception