- Home
- About
- Testimonials
- Demos
- Download
- Documentation
- Blogs
- Forum
- Support

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:
TActiveRecord
TActiveRecordChangeEventParameter
TActiveRecordConfig
TActiveRecordConfigurationException
TActiveRecordCriteria
TActiveRecordException
TActiveRecordGateway
TActiveRecordInvalidFinderResult
TActiveRecordManager

Keyword

# Class TActiveRecordGateway

    TComponent
       |
       --TActiveRecordGateway

TActiveRecordGateway excutes the SQL command queries and returns the data record as arrays (for most finder methods).

Since: 3.1
Author: Wei Zhuo <weizho[at]gmail[dot]com>

Constructor Summary
public | __construct Array Record gateway constructor.

Method Summary
int | countRecords ( TActiveRecord $record, TActiveRecordCriteria $criteria) Returns the number of records that match the given criteria.
int | delete ( TActiveRecord $record) Delete the record.
int | deleteRecordsByCriteria ( TActiveRecord $record, TActiveRecordCriteria $criteria) Delete multiple records by criteria.
int | deleteRecordsByPk ( TActiveRecord $record, mixed $keys) Delete multiple records using primary keys.
array | findRecordByPK ( TActiveRecord $record, array $keys) Returns record data matching the given primary key(s). If the table uses composite key, specify the name value pairs as an array.
array | findRecordBySql ( TActiveRecord $record, TActiveRecordCriteria $criteria) Return record data from sql query.
mixed | findRecordsByCriteria ( TActiveRecord $record, TActiveRecordCriteria $criteria, boolean $iterator) Returns record data matching the given critera. If $iterator is true, it will return multiple rows as TDbDataReader otherwise it returns the first row data.
void | findRecordsByIndex ( TActiveRecord $record, mixed $criteria, mixed $fields, mixed $values)
array | findRecordsByPks ( TActiveRecord $record, array $keys) Returns records matching the list of given primary keys.
TDbDataReader | findRecordsBySql ( TActiveRecord $record, TActiveRecordCriteria $criteria) Return record data from sql query.
TDataGatewayCommand | getCommand ( TActiveRecord $record)
protected array | getInsertValues ( TActiveRecord $record)
protected TActiveRecordManager | getManager ()
protected void | getPrimaryKeyValues ( TActiveRecord $record)
TDbTableInfo | getRecordTableInfo ( TActiveRecord $record) Returns table information, trys the application cache first.
protected string | getRecordTableName ( TActiveRecord $record) Gets the table name from the 'TABLE' constant of the active record class if defined, otherwise use the class name as table name.
TDbTableInfo | getTableInfo ( TDbConnection $connection, string $tableName) Returns table information for table in the database connection.
protected void | getUpdateValues ( TActiveRecord $record)
int | insert ( TActiveRecord $record) Insert a new record.
void | onCreateCommand ( TDataGatewayCommand $sender, TDataGatewayEventParameter $param) Raised when a command is prepared and parameter binding is completed.
void | onExecuteCommand ( TDataGatewayCommand $sender, TDataGatewayResultEventParameter $param) Raised when a command is executed and the result from the database was returned.
protected void | raiseCommandEvent ( string $event, TDbCommand $command, TActiveRecord $record, TActiveRecordCriteria $criteria) Raise the corresponding command event, insert, update, delete or select.
int | update ( TActiveRecord $record) Update the record.
protected void | updateAssociatedRecords ( TActiveRecord $record, mixed $updateBelongsTo)
protected void | updatePostInsert ( TActiveRecord $record) Sets the last insert ID to the corresponding property of the record if available.

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()

Constant Summary
string | TABLE_CONST | Constant name for specifying optional table name in TActiveRecord.
string | TABLE_METHOD | Method name for returning optional table name in in TActiveRecord

Constructor Details

## __construct

public __construct | Array

Record gateway constructor.

Method Details

## countRecords

public int countRecords | (TActiveRecord $record , TActiveRecordCriteria $criteria )

Returns the number of records that match the given criteria.

Input
TActiveRecord | $record | active record finder instance.
TActiveRecordCriteria | $criteria | search criteria
Output
int | number of records.
Exception

## delete

public int delete | (TActiveRecord $record )

Delete the record.

Input
TActiveRecord | $record | record to be deleted.
Output
int | number of rows affected.
Exception

## deleteRecordsByCriteria

public int deleteRecordsByCriteria | (TActiveRecord $record , TActiveRecordCriteria $criteria )

Delete multiple records by criteria.

Input
TActiveRecord | $record | active record finder instance.
TActiveRecordCriteria | $criteria | search criteria
Output
int | number of records.
Exception

## deleteRecordsByPk

public int deleteRecordsByPk | (TActiveRecord $record , mixed $keys )

Delete multiple records using primary keys.

Input
TActiveRecord | $record | finder instance.
mixed | $keys |
Output
int | number of rows deleted.
Exception

## findRecordByPK

public array findRecordByPK | (TActiveRecord $record , array $keys )

Returns record data matching the given primary key(s). If the table uses composite key, specify the name value pairs as an array.

Input
TActiveRecord | $record | active record instance.
array | $keys | primary name value pairs
Output
array | record data
Exception

## findRecordBySql

public array findRecordBySql | (TActiveRecord $record , TActiveRecordCriteria $criteria )

Return record data from sql query.

Input
TActiveRecord | $record | active record finder instance.
TActiveRecordCriteria | $criteria | sql query
Output
array | result.
Exception

## findRecordsByCriteria

public mixed findRecordsByCriteria | (TActiveRecord $record , TActiveRecordCriteria $criteria , boolean $iterator )

Returns record data matching the given critera. If $iterator is true, it will return multiple rows as TDbDataReader otherwise it returns the first row data.

Input
TActiveRecord | $record | active record finder instance.
TActiveRecordCriteria | $criteria | search criteria.
boolean | $iterator | true to return multiple rows as iterator, false returns first row.
Output
mixed | matching data.
Exception

## findRecordsByIndex

public void findRecordsByIndex | (TActiveRecord $record , mixed $criteria , mixed $fields , mixed $values )

Input
TActiveRecord | $record |
mixed | $criteria |
mixed | $fields |
mixed | $values |
Output
Exception

## findRecordsByPks

public array findRecordsByPks | (TActiveRecord $record , array $keys )

Returns records matching the list of given primary keys.

Input
TActiveRecord | $record | active record instance.
array | $keys | list of primary name value pairs
Output
array | matching data.
Exception

## findRecordsBySql

public TDbDataReader findRecordsBySql | (TActiveRecord $record , TActiveRecordCriteria $criteria )

Return record data from sql query.

Input
TActiveRecord | $record | active record finder instance.
TActiveRecordCriteria | $criteria | sql query
Output
TDbDataReader | result iterator.
Exception

## getCommand

public TDataGatewayCommand getCommand | (TActiveRecord $record )

Input
TActiveRecord | $record |
Output
Exception

## getInsertValues

protected array getInsertValues | (TActiveRecord $record )

Input
TActiveRecord | $record | record
Output
array | insert values.
Exception

## getManager

protected TActiveRecordManager getManager | ()

Output
TActiveRecordManager | record manager.
Exception

## getPrimaryKeyValues

protected void getPrimaryKeyValues | (TActiveRecord $record )

Input
TActiveRecord | $record |
Output
Exception

## getRecordTableInfo

public TDbTableInfo getRecordTableInfo | (TActiveRecord $record )

Returns table information, trys the application cache first.

Input
TActiveRecord | $record |
Output
TDbTableInfo | table information.
Exception

## getRecordTableName

protected string getRecordTableName | (TActiveRecord $record )

Gets the table name from the 'TABLE' constant of the active record class if defined, otherwise use the class name as table name.

Input
TActiveRecord | $record | active record instance
Output
string | table name for the given record class.
Exception

## getTableInfo

public TDbTableInfo getTableInfo | (TDbConnection $connection , string $tableName )

Returns table information for table in the database connection.

Input
TDbConnection | $connection | database connection
string | $tableName | table name
Output
TDbTableInfo | table details.
Exception

## getUpdateValues

protected void getUpdateValues | (TActiveRecord $record )

Input
TActiveRecord | $record |
Output
Exception

## insert

public int insert | (TActiveRecord $record )

Insert a new record.

Input
TActiveRecord | $record | new record.
Output
int | number of rows affected.
Exception

## onCreateCommand

public void onCreateCommand | (TDataGatewayCommand $sender , TDataGatewayEventParameter $param )

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. This method also raises the OnCreateCommand event on the ActiveRecord object calling this gateway.

Input
TDataGatewayCommand | $sender | originator $sender
TDataGatewayEventParameter | $param |
Output
Exception

## onExecuteCommand

public void onExecuteCommand | (TDataGatewayCommand $sender , TDataGatewayResultEventParameter $param )

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. This method also raises the OnCreateCommand event on the ActiveRecord object calling this gateway.

Input
TDataGatewayCommand | $sender | originator $sender
TDataGatewayResultEventParameter | $param |
Output
Exception

## raiseCommandEvent

protected void raiseCommandEvent | (string $event , TDbCommand $command , TActiveRecord $record , TActiveRecordCriteria $criteria )

Raise the corresponding command event, insert, update, delete or select.

Input
string | $event | command type
TDbCommand | $command | sql command to be executed.
TActiveRecord | $record | active record
TActiveRecordCriteria | $criteria | data for the command.
Output
Exception

## update

public int update | (TActiveRecord $record )

Update the record.

Input
TActiveRecord | $record | dirty record.
Output
int | number of rows affected.
Exception

## updateAssociatedRecords

protected void updateAssociatedRecords | (TActiveRecord $record , mixed $updateBelongsTo )

Input
TActiveRecord | $record |
mixed | $updateBelongsTo |
Output
Exception

## updatePostInsert

protected void updatePostInsert | (TActiveRecord $record )

Sets the last insert ID to the corresponding property of the record if available.

Input
TActiveRecord | $record | record for insertion
Output
Exception

Constant Details

### TABLE_CONST

Constant name for specifying optional table name in TActiveRecord.

#### Type:

string

#### Value:

'TABLE'

### TABLE_METHOD

Method name for returning optional table name in in TActiveRecord

#### Type:

string

#### Value:

'table'