PHP Class Prado\Data\Common\TDbCommandBuilder

Since: 3.1
Inheritance: extends Prado\TComponent
Show file Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
__construct ( $connection = null, $tableInfo = null )
applyCriterias ( $sql, $parameters = [], $ordering = [], $limit, $offset )
applyLimitOffset ( $sql, $limit, $offset ) : string Alters the sql to apply $limit and $offset. Default implementation is applicable for PostgreSQL, MySQL and SQLite.
applyOrdering ( $sql, $ordering ) : string
bindArrayValues ( $command, $values )
bindColumnValues ( $command, $values ) Bind the name-value pairs of $values where the array keys correspond to column names.
createCommand ( $sql ) : TDbCommand
createCountCommand ( $where = '1=1', $parameters = [], $ordering = [], $limit, $offset ) : TDbCommand Creates a count(*) command for the table described in {@link setTableInfo TableInfo}.
createDeleteCommand ( $where, $parameters = [] ) : TDbCommand Creates a delete command for the table described in {@link setTableInfo TableInfo}.
createFindCommand ( $where = '1=1', $parameters = [], $ordering = [], $limit, $offset, $select = '*' ) : TDbCommand Appends the $where condition to the string "SELECT * FROM tableName WHERE ".
createInsertCommand ( $data ) : TDbCommand Creates an insert command for the table described in {@link setTableInfo TableInfo} for the given data.
createUpdateCommand ( $data, $where, $parameters = [] ) : TDbCommand Creates an update command for the table described in {@link setTableInfo TableInfo} for the given data.
getDbConnection ( ) : TDbConnection
getLastInsertID ( ) : mixed Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
getPdoType ( $value ) : integer
getSearchExpression ( $fields, $keywords ) : 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).
getSelectFieldList ( $data = '*' ) : array Different behavior depends on type of passed data string usage without modification
getTableInfo ( )
setDbConnection ( $value )
setTableInfo ( $value )

Protected Methods

Method Description
getColumnBindings ( $values, $position = false ) : string Create a name-value or position-value if $position=true binding strings.
getInsertFieldBindings ( $values ) : array Returns a list of insert field name and a list of binding names.
getSearchCondition ( $column, $words ) : string
hasIntegerKey ( $array ) : boolean

Method Details

__construct() public method

public __construct ( $connection = null, $tableInfo = null )

applyCriterias() public method

public applyCriterias ( $sql, $parameters = [], $ordering = [], $limit, $offset )

applyLimitOffset() public method

Alters the sql to apply $limit and $offset. Default implementation is applicable for PostgreSQL, MySQL and SQLite.
public applyLimitOffset ( $sql, $limit, $offset ) : string
return string SQL with limit and offset.

applyOrdering() public method

public applyOrdering ( $sql, $ordering ) : string
return string modified SQL applied with ORDER BY.

bindArrayValues() public method

public bindArrayValues ( $command, $values )

bindColumnValues() public method

Bind the name-value pairs of $values where the array keys correspond to column names.
public bindColumnValues ( $command, $values )

createCommand() public method

public createCommand ( $sql ) : TDbCommand
return TDbCommand corresponding database command.

createCountCommand() public method

Creates a count(*) command for the table described in {@link setTableInfo TableInfo}.
public createCountCommand ( $where = '1=1', $parameters = [], $ordering = [], $limit, $offset ) : TDbCommand
return TDbCommand count command.

createDeleteCommand() public method

The conditions for delete is given by the $where argument and the parameters for the condition is given by $parameters.
public createDeleteCommand ( $where, $parameters = [] ) : TDbCommand
return TDbCommand delete command.

createFindCommand() public method

The tableName is obtained from the {@link setTableInfo TableInfo} property.
public createFindCommand ( $where = '1=1', $parameters = [], $ordering = [], $limit, $offset, $select = '*' ) : TDbCommand
return TDbCommand query command.

createInsertCommand() public method

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.
public createInsertCommand ( $data ) : TDbCommand
return TDbCommand insert command

createUpdateCommand() public method

Each array key in the $data array must correspond to the column name to be updated with the corresponding array value.
public createUpdateCommand ( $data, $where, $parameters = [] ) : TDbCommand
return TDbCommand update command.

getColumnBindings() protected method

Create a name-value or position-value if $position=true binding strings.
protected getColumnBindings ( $values, $position = false ) : string
return string update column names with corresponding binding substrings.

getDbConnection() public method

public getDbConnection ( ) : TDbConnection
return TDbConnection database connection.

getInsertFieldBindings() protected method

Returns a list of insert field name and a list of binding names.
protected getInsertFieldBindings ( $values ) : array
return array tuple ($fields, $bindings)

getLastInsertID() public method

Iterate through all the columns and returns the last insert id of the first column that has a sequence or serial.
public getLastInsertID ( ) : mixed
return mixed last insert id, null if none is found.

getPdoType() public static method

public static getPdoType ( $value ) : integer
return integer PDO parameter types.

getSearchCondition() protected method

protected getSearchCondition ( $column, $words ) : string
return string search condition for all words in one column.

getSearchExpression() public method

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).
public getSearchExpression ( $fields, $keywords ) : string
return string SQL search condition matching on a set of columns.

getSelectFieldList() public method

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...
Since: 3.1.7
public getSelectFieldList ( $data = '*' ) : array
return array of generated fields - use implode(', ', $selectfieldlist) to collapse field list for usage

getTableInfo() public method

public getTableInfo ( )

hasIntegerKey() protected method

protected hasIntegerKey ( $array ) : boolean
return boolean true if any array key is an integer.

setDbConnection() public method

public setDbConnection ( $value )

setTableInfo() public method

public setTableInfo ( $value )