## 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 2762 2010-02-13 15:37:13Z godzilla80@gmx.net $
- 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], [mixed $select = '*'])
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)
array getSelectFieldList ([mixed $data = '*'], mixed $value)
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 317)

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

- access: public

void bindArrayValues (TDbCommand $command, array $values)

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

bindColumnValues (line 445)

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

- return: corresponding database command.
- access: public

TDbCommand createCommand (string $sql)

- string $sql: SQL query string.

createCountCommand (line 334)

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

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

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], [mixed $select = '*'])

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

createInsertCommand (line 365)

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

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

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

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

- 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.

getSelectFieldList (line 198)

Different behavior depends on type of passed data string usage without modification

null will be expanded to full list of quoted table column names (quoting depends on database)

array

- Column names will be quoted if used as key or value of array

           array('col1', 'col2', 'col2')
           // SELECT `col1`, `col2`, `col3` FROM...

- Column aliasing

       array('mycol1' => 'col1', 'mycol2' => 'COUNT(*)')
       // SELECT `col1` AS mycol1, COUNT(*) AS mycol2 FROM...

- NULL and scalar values (strings will be quoted depending on database)

       array('col1' => 'my custom string', 'col2' => 1.0, 'col3' => 'NULL')
       // SELECT "my custom string" AS `col1`, 1.0 AS `col2`, NULL AS `col3` FROM...

- If the *-wildcard char is used as key or value, add the full list of quoted table column names

       array('col1' => 'NULL', '*')
       // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM...

- return: of generated fields - use implode(', ', $selectfieldlist) to collapse field list for usage
- access: public
- todo: add support for table aliasing
- todo: add support for quoting of column aliasing
- since: 3.1.7

array getSelectFieldList ([mixed $data = '*'], mixed $value)

- mixed $value

getTableInfo (line 64)

- access: public

void getTableInfo (TDbTableInfo 0)

- TDbTableInfo 0: table information.

hasIntegerKey (line 498)

- 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 Mon, 22 Feb 2010 12:17:34 +0000 by phpDocumentor 1.3.0RC4