|
Class TDbCommandBuilder
TDbCommandBuilder provides basic methods to create query commands for tables
giving by setTableInfo TableInfo the property.
-
TComponent
-
TDbCommandBuilder
Methods summary
public
|
|
public
TDbConnection
|
|
public
|
|
public
|
|
public
|
|
public
mixed
|
#
getLastInsertID( )
Iterate through all the columns and returns the last insert id of the first
column that has a sequence or serial.
Iterate through all the columns and returns the last insert id of the first
column that has a sequence or serial.
Returns
mixed last insert id, null if none is found.
|
public
string
|
#
applyLimitOffset( string $sql, integer $limit = -1, integer $offset = -1 )
Alters the sql to apply $limit and $offset. Default implementation is
applicable for PostgreSQL, MySQL and SQLite.
Alters the sql to apply $limit and $offset. Default implementation is
applicable for PostgreSQL, MySQL and SQLite.
Parameters
- $sql
string SQL query string.
- $limit
integer maximum number of rows, -1 to ignore limit.
- $offset
integer row offset, -1 to ignore offset.
Returns
string SQL with limit and offset.
|
public
string
|
#
applyOrdering( string $sql, array $ordering )
Parameters
- $sql
string SQL string without existing ordering.
- $ordering
array pairs of column names as key and direction as value.
Returns
string modified SQL applied with ORDER BY.
|
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).
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).
Parameters
- $fields
array list of column id for potential search condition.
- $keywords
string string of keywords
Returns
string SQL search condition matching on a set of columns.
|
protected
string
|
#
getSearchCondition( string $column, array $words )
Parameters
- $column
string column name.
- $words
array keywords
Returns
string search condition for all words in one column.
|
public
array
|
#
getSelectFieldList( mixed $data = '*' )
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
array('mycol1' => 'col1', 'mycol2' => 'COUNT(*)')
- NULL and scalar values (strings will be quoted depending on database)
array('col1' => 'my custom string', 'col2' => 1.0, 'col3' => 'NULL')
- If the *-wildcard char is used as key or value, add the full list of quoted
table column names
array('col1' => 'NULL', '*')
Parameters
Returns
array of generated fields - use implode(', ', $selectfieldlist) to collapse field list
for usage
Since
3.1.7
Todo
add support for table aliasing
add support for quoting of column aliasing
|
public
TDbCommand
|
#
createFindCommand( string $where = '1=1', array $parameters = array(), mixed $ordering = array(), mixed $limit = -1, mixed $offset = -1, mixed $select = '*' )
Appends the $where condition to the string "SELECT * FROM tableName WHERE ".
The tableName is obtained from the setTableInfo TableInfo property.
Appends the $where condition to the string "SELECT * FROM tableName WHERE ".
The tableName is obtained from the setTableInfo TableInfo property.
Parameters
- $where
string query condition
- $parameters
array condition parameters.
- $ordering
- $limit
- $offset
- $select
Returns
|
public
|
#
applyCriterias( mixed $sql, mixed $parameters = array(), mixed $ordering = array(), mixed $limit = -1, mixed $offset = -1 )
|
public
TDbCommand
|
#
createCountCommand( string $where = '1=1', array $parameters = array(), mixed $ordering = array(), mixed $limit = -1, mixed $offset = -1 )
Creates a count(*) command for the table described in setTableInfo
TableInfo.
Creates a count(*) command for the table described in setTableInfo
TableInfo.
Parameters
- $where
string count condition.
- $parameters
array binding parameters.
- $ordering
- $limit
- $offset
Returns
|
public
TDbCommand
|
#
createDeleteCommand( string $where, array $parameters = array() )
Creates a delete command for the table described in setTableInfo
TableInfo. The conditions for delete is given by the $where argument and the
parameters for the condition is given by $parameters.
Creates a delete command for the table described in setTableInfo
TableInfo. The conditions for delete is given by the $where argument and the
parameters for the condition is given by $parameters.
Parameters
- $where
string delete condition.
- $parameters
array delete parameters.
Returns
|
public
TDbCommand
|
#
createInsertCommand( array $data )
Creates an insert command for the table described in setTableInfo
TableInfo 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.
Creates an insert command for the table described in setTableInfo
TableInfo 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.
Parameters
- $data
array name-value pairs of new data to be inserted.
Returns
|
public
TDbCommand
|
#
createUpdateCommand( array $data, string $where, array $parameters = array() )
Creates an update command for the table described in setTableInfo
TableInfo 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.
Creates an update command for the table described in setTableInfo
TableInfo 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.
Parameters
- $data
array name-value pairs of data to be updated.
- $where
string update condition.
- $parameters
array update parameters.
Returns
|
protected
array
|
#
getInsertFieldBindings( object $values )
Returns a list of insert field name and a list of binding names.
Returns a list of insert field name and a list of binding names.
Parameters
- $values
object array or object to be inserted.
Returns
array tuple ($fields, $bindings)
|
protected
string
|
#
getColumnBindings( array $values, boolean $position = false )
Create a name-value or position-value if $position=true binding strings.
Create a name-value or position-value if $position=true binding strings.
Parameters
- $values
array data for binding.
- $position
boolean true to bind as position values.
Returns
string update column names with corresponding binding substrings.
|
public
TDbCommand
|
#
createCommand( string $sql )
Parameters
- $sql
string SQL query string.
Returns
|
public
|
#
bindColumnValues( TDbCommand $command, array $values )
Bind the name-value pairs of $values where the array keys correspond to
column names.
Bind the name-value pairs of $values where the array keys correspond to
column names.
Parameters
- $command
TDbCommand
database command.
- $values
array name-value pairs.
|
public
|
#
bindArrayValues( TDbCommand $command, array $values )
Parameters
- $command
TDbCommand
database command
- $values
array values for binding.
|
public static
integer
|
#
getPdoType( mixed $value )
Parameters
Returns
integer PDO parameter types.
|
protected
boolean
|
#
hasIntegerKey( array $array )
Parameters
Returns
boolean true if any array key is an integer.
|
Methods inherited from TComponent
__call(),
__destruct(),
__get(),
__isset(),
__set(),
__sleep(),
__unset(),
__wakeup(),
addParsedObject(),
asa(),
attachBehavior(),
attachBehaviors(),
attachClassBehavior(),
attachEventHandler(),
canGetProperty(),
canSetProperty(),
clearBehaviors(),
createdOnTemplate(),
detachBehavior(),
detachBehaviors(),
detachClassBehavior(),
detachEventHandler(),
disableBehavior(),
disableBehaviors(),
enableBehavior(),
enableBehaviors(),
evaluateExpression(),
evaluateStatements(),
fxAttachClassBehavior(),
fxDetachClassBehavior(),
getAutoGlobalListen(),
getBehaviorsEnabled(),
getClassHierarchy(),
getEventHandlers(),
getListeningToGlobalEvents(),
getSubProperty(),
hasEvent(),
hasEventHandler(),
hasProperty(),
isa(),
listen(),
raiseEvent(),
setSubProperty(),
unlisten()
|
|