Class TDbCommandBuilder
Direct Known Sub-classes:
TDbCommandBuilder provides basic methods to create query commands for tables giving by setTableInfo the property.
Constructor Summary |
public |
|
Method Summary |
void
|
applyCriterias
( mixed $sql, mixed $parameters, mixed $ordering, mixed $limit, mixed $offset)
|
string
|
Alters the sql to apply $limit and $offset. Default implementation is applicable for PostgreSQL, MySQL and SQLite.
|
string
|
|
void
|
|
void
|
Bind the name-value pairs of $values where the array keys correspond to column names.
|
TDbCommand
|
|
TDbCommand
|
createCountCommand
( string $where, array $parameters, mixed $ordering, mixed $limit, mixed $offset)
Creates a count(*) command for the table described in setTableInfo.
|
TDbCommand
|
Creates a delete command for the table described in setTableInfo.
|
TDbCommand
|
createFindCommand
( string $where, array $parameters, mixed $ordering, mixed $limit, mixed $offset)
Appends the $where condition to the string "SELECT * FROM tableName WHERE ".
|
TDbCommand
|
Creates an insert command for the table described in setTableInfo for the given data.
|
TDbCommand
|
Creates an update command for the table described in setTableInfo for the given data.
|
protected
string
|
Create a name-value or position-value if $position=true binding strings.
|
TDbConnection
|
|
protected
array
|
Returns a list of insert field name and a list of binding names.
|
mixed
|
Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
|
integer
|
|
protected
string
|
|
string
|
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).
|
void
|
|
protected
boolean
|
|
void
|
|
void
|
|
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
|
Method Details |
applyCriterias
public void applyCriterias |
(mixed $sql , mixed $parameters , mixed $ordering , mixed $limit , mixed $offset ) |
Input |
mixed | $sql | |
mixed | $parameters | |
mixed | $ordering | |
mixed | $limit | |
mixed | $offset | |
Output |
Exception |
|
applyLimitOffset
public string applyLimitOffset |
(string $sql , integer $limit , integer $offset ) |
Alters the sql to apply $limit and $offset. Default implementation is applicable for PostgreSQL, MySQL and SQLite.
Input |
string | $sql | SQL query string. |
integer | $limit | maximum number of rows, -1 to ignore limit. |
integer | $offset | row offset, -1 to ignore offset. |
Output |
string
| SQL with limit and offset. |
Exception |
|
applyOrdering
public string applyOrdering |
(string $sql , array $ordering ) |
Input |
string | $sql | SQL string without existing ordering. |
array | $ordering | pairs of column names as key and direction as value. |
Output |
string
| modified SQL applied with ORDER BY. |
Exception |
|
bindArrayValues
public void bindArrayValues |
(TDbCommand $command , array $values ) |
Input |
TDbCommand | $command | database command |
array | $values | values for binding. |
Output |
Exception |
|
bindColumnValues
public void bindColumnValues |
(TDbCommand $command , array $values ) |
Bind the name-value pairs of $values where the array keys correspond to column names.
Input |
TDbCommand | $command | database command. |
array | $values | name-value pairs. |
Output |
Exception |
|
createCommand
Input |
string | $sql | SQL query string. |
Output |
TDbCommand
| corresponding database command. |
Exception |
|
createCountCommand
public TDbCommand createCountCommand |
(string $where , array $parameters , mixed $ordering , mixed $limit , mixed $offset ) |
Creates a count(*) command for the table described in setTableInfo.
Input |
string | $where | count condition. |
array | $parameters | binding parameters. |
mixed | $ordering | |
mixed | $limit | |
mixed | $offset | |
Output |
TDbCommand
| count command. |
Exception |
|
createDeleteCommand
public TDbCommand createDeleteCommand |
(string $where , array $parameters ) |
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.
Input |
string | $where | delete condition. |
array | $parameters | delete parameters. |
Output |
TDbCommand
| delete command. |
Exception |
|
createFindCommand
public TDbCommand createFindCommand |
(string $where , array $parameters , mixed $ordering , mixed $limit , mixed $offset ) |
Appends the $where condition to the string "SELECT * FROM tableName WHERE ".
The tableName is obtained from the TableInfo property.
Input |
string | $where | query condition |
array | $parameters | condition parameters. |
mixed | $ordering | |
mixed | $limit | |
mixed | $offset | |
Output |
TDbCommand
| query command. |
Exception |
|
createInsertCommand
public TDbCommand createInsertCommand |
(array $data ) |
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.
Input |
array | $data | name-value pairs of new data to be inserted. |
Output |
TDbCommand
| insert command |
Exception |
|
createUpdateCommand
public TDbCommand createUpdateCommand |
(array $data , string $where , array $parameters ) |
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.
Input |
array | $data | name-value pairs of data to be updated. |
string | $where | update condition. |
array | $parameters | update parameters. |
Output |
TDbCommand
| update command. |
Exception |
|
getColumnBindings
protected string getColumnBindings |
(array $values , boolean $position ) |
Create a name-value or position-value if $position=true binding strings.
Input |
array | $values | data for binding. |
boolean | $position | true to bind as position values. |
Output |
string
| update column names with corresponding binding substrings. |
Exception |
|
getDbConnection
|
getInsertFieldBindings
protected array getInsertFieldBindings |
(object array $values ) |
Returns a list of insert field name and a list of binding names.
Input |
object array | $values | or object to be inserted. |
Output |
array
| tuple ($fields, $bindings) |
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 |
|
getPdoType
public integer getPdoType |
(mixed $value ) |
Input |
mixed | $value | PHP value |
Output |
integer
| PDO parameter types. |
Exception |
|
getSearchCondition
protected string getSearchCondition |
(string $column , array $words ) |
Input |
string | $column | column name. |
array | $words | keywords |
Output |
string
| search condition for all words in one column. |
Exception |
|
getSearchExpression
public string getSearchExpression |
(array $fields , string $keywords ) |
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).
Input |
array | $fields | list of column id for potential search condition. |
string | $keywords | string of keywords |
Output |
string
| SQL search condition matching on a set of columns. |
Exception |
|
getTableInfo
|
hasIntegerKey
protected boolean hasIntegerKey |
(array $array ) |
Input |
array | $array | |
Output |
boolean
| true if any array key is an integer. |
Exception |
|
setDbConnection
|
setTableInfo
|
|