## Class TDbCommandBuilder

Description

TDbCommandBuilder provides basic methods to create query commands for tables giving by setTableInfo the property.

- since: 3.1
- version: $Id: TDbCommandBuilder.php 2488 2008-08-06 01:34:06Z knut $
- author: Wei Zhuo <weizho[at]gmail[dot]com>

Located in /Data/Common/TDbCommandBuilder.php (line 22)

    TComponent
       |
       --TDbCommandBuilder

Direct descendents

Class | Description
--- | ---
TMssqlCommandBuilder | TMssqlCommandBuilder provides specifics methods to create limit/offset query commands for MSSQL servers.
TMysqlCommandBuilder | TMysqlCommandBuilder implements default TDbCommandBuilder
TOracleCommandBuilder | TOracleCommandBuilder provides specifics methods to create limit/offset query commands for Oracle database.
TPgsqlCommandBuilder | TPgsqlCommandBuilder provides specifics methods to create limit/offset query commands for Pgsql database.
TSqliteCommandBuilder | TSqliteCommandBuilder provides specifics methods to create limit/offset query commands for Sqlite database.

Method Summary
TDbCommandBuilder __construct ([TDbConnection $connection = null], [TDbTableInfo $tableInfo = null])
void applyCriterias (mixed $sql, [mixed $parameters = array()], [mixed $ordering = array()], [mixed $limit = -1], [mixed $offset = -1])
string applyLimitOffset (string $sql, [integer $limit = -1], [integer $offset = -1])
string applyOrdering (string $sql, array $ordering)
void bindArrayValues (TDbCommand $command, array $values)
void bindColumnValues (TDbCommand $command, array $values)
TDbCommand createCommand (string $sql)
TDbCommand createCountCommand ([string $where = '1=1'], [array $parameters = array()], [mixed $ordering = array()], [mixed $limit = -1], [mixed $offset = -1])
TDbCommand createDeleteCommand (string $where, [array $parameters = array()])
TDbCommand createFindCommand ([string $where = '1=1'], [array $parameters = array()], [mixed $ordering = array()], [mixed $limit = -1], [mixed $offset = -1])
TDbCommand createInsertCommand (array $data)
TDbCommand createUpdateCommand (array $data, string $where, [array $parameters = array()])
string getColumnBindings (array $values, [boolean $position = false])
TDbConnection getDbConnection ()
array getInsertFieldBindings (object array $values)
mixed getLastInsertID ()
integer getPdoType (mixed $value)
string getSearchCondition (string $column, array $words)
string getSearchExpression (array $fields, string $keywords)
void getTableInfo (TDbTableInfo 0)
boolean hasIntegerKey (array $array)
void setDbConnection (TDbConnection $value)
void setTableInfo (TDbTableInfo $value)
Methods
Constructor __construct (line 31)

- access: public

TDbCommandBuilder __construct ([TDbConnection $connection = null], [TDbTableInfo $tableInfo = null])

- TDbConnection $connection: database connection.
- TDbTableInfo $tableInfo: table information.

applyCriterias (line 175)

- access: public

void applyCriterias (mixed $sql, [mixed $parameters = array()], [mixed $ordering = array()], [mixed $limit = -1], [mixed $offset = -1])
applyLimitOffset (line 91)

Alters the sql to apply $limit and $offset. Default implementation is applicable for PostgreSQL, MySQL and SQLite.

- return: SQL with limit and offset.
- access: public

string applyLimitOffset (string $sql, [integer $limit = -1], [integer $offset = -1])

- string $sql: SQL query string.
- integer $limit: maximum number of rows, -1 to ignore limit.
- integer $offset: row offset, -1 to ignore offset.

Redefined in descendants as:

- TMssqlCommandBuilder::applyLimitOffset() : Overrides parent implementation. Alters the sql to apply $limit and $offset.
- TOracleCommandBuilder::applyLimitOffset() : Overrides parent implementation to use Oracle way of get paginated RecordSet instead of using LIMIT sql clause.
- TSqliteCommandBuilder::applyLimitOffset() : Alters the sql to apply $limit and $offset.

applyOrdering (line 105)

- return: modified SQL applied with ORDER BY.
- access: public

string applyOrdering (string $sql, array $ordering)

- string $sql: SQL string without existing ordering.
- array $ordering: pairs of column names as key and direction as value.

bindArrayValues (line 323)

- access: public

void bindArrayValues (TDbCommand $command, array $values)

- TDbCommand $command: database command
- array $values: values for binding.

bindColumnValues (line 307)

Bind the name-value pairs of $values where the array keys correspond to column names.

- access: public

void bindColumnValues (TDbCommand $command, array $values)

- TDbCommand $command: database command.
- array $values: name-value pairs.

createCommand (line 296)

- return: corresponding database command.
- access: public

TDbCommand createCommand (string $sql)

- string $sql: SQL query string.

createCountCommand (line 192)

Creates a count(*) command for the table described in setTableInfo.

- return: count command.
- access: public

TDbCommand createCountCommand ([string $where = '1=1'], [array $parameters = array()], [mixed $ordering = array()], [mixed $limit = -1], [mixed $offset = -1])

- string $where: count condition.
- array $parameters: binding parameters.

createDeleteCommand (line 209)

Creates a delete command for the table described in setTableInfo.

The conditions for delete is given by the $where argument and the parameters for the condition is given by $parameters.

- return: delete command.
- access: public

TDbCommand createDeleteCommand (string $where, [array $parameters = array()])

- string $where: delete condition.
- array $parameters: delete parameters.

createFindCommand (line 166)

Appends the $where condition to the string "SELECT * FROM tableName WHERE ".

The tableName is obtained from the TableInfo property.

- return: query command.
- access: public

TDbCommand createFindCommand ([string $where = '1=1'], [array $parameters = array()], [mixed $ordering = array()], [mixed $limit = -1], [mixed $offset = -1])

- string $where: query condition
- array $parameters: condition parameters.

createInsertCommand (line 227)

Creates an insert command for the table described in setTableInfo for the given data.

Each array key in the $data array must correspond to the column name of the table (if a column allows to be null, it may be omitted) to be inserted with the corresponding array value.

- return: insert command
- access: public

TDbCommand createInsertCommand (array $data)

- array $data: name-value pairs of new data to be inserted.

createUpdateCommand (line 244)

Creates an update command for the table described in setTableInfo for the given data.

Each array key in the $data array must correspond to the column name to be updated with the corresponding array value.

- return: update command.
- access: public

TDbCommand createUpdateCommand (array $data, string $where, [array $parameters = array()])

- array $data: name-value pairs of data to be updated.
- string $where: update condition.
- array $parameters: update parameters.

getColumnBindings (line 281)

Create a name-value or position-value if $position=true binding strings.

- return: update column names with corresponding binding substrings.
- access: protected

string getColumnBindings (array $values, [boolean $position = false])

- array $values: data for binding.
- boolean $position: true to bind as position values.

getDbConnection (line 40)

- return: database connection.
- access: public

TDbConnection getDbConnection ()
getInsertFieldBindings (line 264)

Returns a list of insert field name and a list of binding names.

- return: tuple ($fields, $bindings)
- access: protected

array getInsertFieldBindings (object array $values)

- object array $values: or object to be inserted.

getLastInsertID (line 74)

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

Redefined in descendants as:

- TMssqlCommandBuilder::getLastInsertID() : Overrides parent implementation. Uses "SELECT @@Identity".

getPdoType (line 345)

- return: PDO parameter types.
- static:
- access: public

integer getPdoType (mixed $value)

- mixed $value: PHP value

getSearchCondition (line 151)

- return: search condition for all words in one column.
- access: protected

string getSearchCondition (string $column, array $words)

- string $column: column name.
- array $words: keywords

Redefined in descendants as:

- TPgsqlCommandBuilder::getSearchCondition() : Overrides parent implementation to use PostgreSQL's ILIKE instead of LIKE (case-sensitive).

getSearchExpression (line 133)

Computes the SQL condition for search a set of column using regular expression (or LIKE, depending on database implementation) to match a string of keywords (default matches all keywords).

- return: SQL search condition matching on a set of columns.
- access: public

string getSearchExpression (array $fields, string $keywords)

- array $fields: list of column id for potential search condition.
- string $keywords: string of keywords

Redefined in descendants as:

- TOracleCommandBuilder::getSearchExpression() : Overrides parent implementation. Only column of type text or character (and its variants) accepts the LIKE criteria.
- TPgsqlCommandBuilder::getSearchExpression() : Overrides parent implementation. Only column of type text or character (and its variants) accepts the LIKE criteria.

getTableInfo (line 64)

- access: public

void getTableInfo (TDbTableInfo 0)

- TDbTableInfo 0: table information.

hasIntegerKey (line 360)

- return: true if any array key is an integer.
- access: protected

boolean hasIntegerKey (array $array)

- array $array

setDbConnection (line 48)

- access: public

void setDbConnection (TDbConnection $value)

- TDbConnection $value: database connection.

setTableInfo (line 56)

- access: public

void setTableInfo (TDbTableInfo $value)

- TDbTableInfo $value: table information.

#### 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 Sun, 11 Jan 2009 20:22:18 -0500 by phpDocumentor 1.3.0RC4