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 2340 2007-12-04 18:59:48Z xue $
  • 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 createUpdateCommand (array $data, string $where, [array $parameters = array()])
string getColumnBindings (array $values, [boolean $position = false])
array getInsertFieldBindings (object array $values)
mixed getLastInsertID ()
integer getPdoType (mixed $value)
string getSearchCondition (string $column, array $words)
string getSearchExpression (array $fields, string $keywords)
boolean hasIntegerKey (array $array)
void setTableInfo (TDbTableInfo $value)
Methods
Constructor __construct (line 31)
  • access: public
TDbCommandBuilder __construct ([TDbConnection $connection = null], [TDbTableInfo $tableInfo = null])
applyCriterias (line 169)
  • 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:
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 317)
  • access: public
void bindArrayValues (TDbCommand $command, array $values)
  • TDbCommand $command: database command
  • array $values: values for binding.
bindColumnValues (line 301)

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 290)
  • return: corresponding database command.
  • access: public
TDbCommand createCommand (string $sql)
  • string $sql: SQL query string.
createCountCommand (line 186)

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

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

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

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

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

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

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:
getPdoType (line 339)
  • return: PDO parameter types.
  • static:
  • access: public
integer getPdoType (mixed $value)
  • mixed $value: PHP value
getSearchCondition (line 145)
  • 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:
getSearchExpression (line 127)

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:
getTableInfo (line 64)
  • access: public
void getTableInfo (TDbTableInfo 0)
hasIntegerKey (line 354)
  • 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)
setTableInfo (line 56)
  • access: public
void setTableInfo (TDbTableInfo $value)

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, 21 Apr 2008 11:34:51 -0400 by phpDocumentor 1.3.0RC4