system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.i18n system.i18n.gettext system.logging system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers

CDbCommandBuilder

system.db.schema
继承 class CDbCommandBuilder » CComponent
子类 CMssqlCommandBuilder, COciCommandBuilder, CSqliteCommandBuilder
可用自 1.0
版本 $Id$
CDbCommandBuilder provides basic methods to create query commands for tables.

公共属性

隐藏继承的属性

属性类型描述被定义在
dbConnection CDbConnection database connection. CDbCommandBuilder
schema CDbSchema the schema for this command builder. CDbCommandBuilder

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() CDbCommandBuilder
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
applyCondition() Alters the SQL to apply WHERE clause. CDbCommandBuilder
applyGroup() Alters the SQL to apply GROUP BY. CDbCommandBuilder
applyHaving() Alters the SQL to apply HAVING. CDbCommandBuilder
applyJoin() Alters the SQL to apply JOIN clause. CDbCommandBuilder
applyLimit() Alters the SQL to apply LIMIT and OFFSET. CDbCommandBuilder
applyOrder() Alters the SQL to apply ORDER BY. CDbCommandBuilder
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
bindValues() Binds parameter values for an SQL command. CDbCommandBuilder
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
createColumnCriteria() Creates a query criteria with the specified column values. CDbCommandBuilder
createCountCommand() Creates a COUNT(*) command for a single table. CDbCommandBuilder
createCriteria() Creates a query criteria. CDbCommandBuilder
createDeleteCommand() Creates a DELETE command. CDbCommandBuilder
createFindCommand() Creates a SELECT command for a single table. CDbCommandBuilder
createInCondition() Generates the expression for selecting rows of specified primary key values. CDbCommandBuilder
createInsertCommand() Creates an INSERT command. CDbCommandBuilder
createPkCondition() Generates the expression for selecting rows of specified primary key values. CDbCommandBuilder
createPkCriteria() Creates a query criteria with the specified primary key. CDbCommandBuilder
createSearchCondition() Generates the expression for searching the specified keywords within a list of columns. CDbCommandBuilder
createSqlCommand() Creates a command based on a given SQL statement. CDbCommandBuilder
createUpdateCommand() Creates an UPDATE command. CDbCommandBuilder
createUpdateCounterCommand() Creates an UPDATE command that increments/decrements certain columns. CDbCommandBuilder
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
getDbConnection() CDbCommandBuilder
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getLastInsertID() Returns the last insertion ID for the specified table. CDbCommandBuilder
getSchema() CDbCommandBuilder
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent

受保护的方法

隐藏继承的方法

方法描述被定义在
createCompositeInCondition() Generates the expression for selecting rows with specified composite key values. CDbCommandBuilder
ensureTable() Checks if the parameter is a valid table schema. CDbCommandBuilder

属性详情

dbConnection 属性 只读

database connection.

schema 属性 只读

the schema for this command builder.

方法详情

__construct() 方法
public void __construct(CDbSchema $schema)
$schema CDbSchema the schema for this command builder

applyCondition() 方法
public string applyCondition(string $sql, string $condition)
$sql string the SQL statement without WHERE clause
$condition string the WHERE clause (without WHERE keyword)
{return} string the altered SQL statement

Alters the SQL to apply WHERE clause.

applyGroup() 方法
public string applyGroup(string $sql, string $group)
$sql string SQL query string without GROUP BY.
$group string GROUP BY
{return} string SQL with GROUP BY.

Alters the SQL to apply GROUP BY.

applyHaving() 方法 (自版本 v1.0.1 可用)
public string applyHaving(string $sql, string $having)
$sql string SQL query string without HAVING
$having string HAVING
{return} string SQL with HAVING

Alters the SQL to apply HAVING.

applyJoin() 方法
public string applyJoin(string $sql, string $join)
$sql string the SQL statement to be altered
$join string the JOIN clause (starting with join type, such as INNER JOIN)
{return} string the altered SQL statement

Alters the SQL to apply JOIN clause.

applyLimit() 方法
public string applyLimit(string $sql, integer $limit, integer $offset)
$sql string SQL query string without LIMIT and OFFSET.
$limit integer maximum number of rows, -1 to ignore limit.
$offset integer row offset, -1 to ignore offset.
{return} string SQL with LIMIT and OFFSET

Alters the SQL to apply LIMIT and OFFSET. Default implementation is applicable for PostgreSQL, MySQL and SQLite.

applyOrder() 方法
public string applyOrder(string $sql, string $orderBy)
$sql string SQL statement without ORDER BY.
$orderBy string column ordering
{return} string modified SQL applied with ORDER BY.

Alters the SQL to apply ORDER BY.

bindValues() 方法
public void bindValues(CDbCommand $command, array $values)
$command CDbCommand database command
$values array values for binding (integer-indexed array for question mark placeholders, string-indexed array for named placeholders)

Binds parameter values for an SQL command.

createColumnCriteria() 方法
public CDbCriteria createColumnCriteria(mixed $table, array $columns, mixed $condition='', array $params=array ( ))
$table mixed the table schema (CDbTableSchema) or the table name (string).
$columns array column values that should be matched in the query (name=>value)
$condition mixed query condition or criteria. If a string, it is treated as query condition; If an array, it is treated as the initial values for constructing a CDbCriteria; Otherwise, it should be an instance of CDbCriteria.
$params array parameters to be bound to an SQL statement. This is only used when the second parameter is a string (query condition). In other cases, please use CDbCriteria::params to set parameters.
{return} CDbCriteria the created query criteria

Creates a query criteria with the specified column values.

createCompositeInCondition() 方法 (自版本 v1.0.4 可用)
protected string createCompositeInCondition(CDbTableSchema $table, array $values, string $prefix)
$table CDbTableSchema the table schema
$values array list of primary key values to be selected within
$prefix string column prefix (ended with dot)
{return} string the expression for selection

Generates the expression for selecting rows with specified composite key values.

createCountCommand() 方法
public CDbCommand createCountCommand(mixed $table, CDbCriteria $criteria)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$criteria CDbCriteria the query criteria
{return} CDbCommand query command.

Creates a COUNT(*) command for a single table.

createCriteria() 方法
public CDbCriteria createCriteria(mixed $condition='', mixed $params=array ( ))
$condition mixed the table schema (CDbTableSchema) or the table name (string).
$params mixed query condition or criteria. If a string, it is treated as query condition (the WHERE clause); If an array, it is treated as the initial values for constructing a CDbCriteria object; Otherwise, it should be an instance of CDbCriteria.
{return} CDbCriteria the created query criteria

Creates a query criteria.

createDeleteCommand() 方法
public CDbCommand createDeleteCommand(mixed $table, CDbCriteria $criteria)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$criteria CDbCriteria the query criteria
{return} CDbCommand delete command.

Creates a DELETE command.

createFindCommand() 方法
public CDbCommand createFindCommand(mixed $table, CDbCriteria $criteria)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$criteria CDbCriteria the query criteria
{return} CDbCommand query command.

Creates a SELECT command for a single table.

createInCondition() 方法 (自版本 v1.0.4 可用)
public string createInCondition(mixed $table, mixed $columnName, array $values, string $prefix=NULL)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$columnName mixed the column name(s). It can be either a string indicating a single column or an array of column names. If the latter, it stands for a composite key.
$values array list of key values to be selected within
$prefix string column prefix (ended with dot). If null, it will be the table name
{return} string the expression for selection

Generates the expression for selecting rows of specified primary key values.

createInsertCommand() 方法
public CDbCommand createInsertCommand(mixed $table, array $data)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$data array data to be inserted (column name=>column value). If a key is not a valid column name, the corresponding value will be ignored.
{return} CDbCommand insert command

Creates an INSERT command.

createPkCondition() 方法
public string createPkCondition(mixed $table, array $values, string $prefix=NULL)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$values array list of primary key values to be selected within
$prefix string column prefix (ended with dot). If null, it will be the table name
{return} string the expression for selection

Generates the expression for selecting rows of specified primary key values.

createPkCriteria() 方法
public CDbCriteria createPkCriteria(mixed $table, mixed $pk, mixed $condition='', array $params=array ( ))
$table mixed the table schema (CDbTableSchema) or the table name (string).
$pk mixed primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value).
$condition mixed query condition or criteria. If a string, it is treated as query condition; If an array, it is treated as the initial values for constructing a CDbCriteria; Otherwise, it should be an instance of CDbCriteria.
$params array parameters to be bound to an SQL statement. This is only used when the second parameter is a string (query condition). In other cases, please use CDbCriteria::params to set parameters.
{return} CDbCriteria the created query criteria

Creates a query criteria with the specified primary key.

createSearchCondition() 方法
public string createSearchCondition(mixed $table, array $columns, mixed $keywords, string $prefix=NULL, boolean $caseSensitive=true)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$columns array list of column names for potential search condition.
$keywords mixed search keywords. This can be either a string with space-separated keywords or an array of keywords.
$prefix string optional column prefix (with dot at the end). If null, the table name will be used as the prefix.
$caseSensitive boolean whether the search is case-sensitive. Defaults to true. This parameter has been available since version 1.0.4.
{return} string SQL search condition matching on a set of columns. An empty string is returned if either the column array or the keywords are empty.

Generates the expression for searching the specified keywords within a list of columns. The search expression is generated using the 'LIKE' SQL syntax. Every word in the keywords must be present and appear in at least one of the columns.

createSqlCommand() 方法
public CDbCommand createSqlCommand(string $sql, array $params=array ( ))
$sql string the explicitly specified SQL statement
$params array parameters that will be bound to the SQL statement
{return} CDbCommand the created command

Creates a command based on a given SQL statement.

createUpdateCommand() 方法
public CDbCommand createUpdateCommand(mixed $table, array $data, CDbCriteria $criteria)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$data array list of columns to be updated (name=>value)
$criteria CDbCriteria the query criteria
{return} CDbCommand update command.

Creates an UPDATE command.

createUpdateCounterCommand() 方法
public CDbCommand createUpdateCounterCommand(mixed $table, CDbCriteria $counters, array $criteria)
$table mixed the table schema (CDbTableSchema) or the table name (string).
$counters CDbCriteria the query criteria
$criteria array counters to be updated (counter increments/decrements indexed by column names.)
{return} CDbCommand the created command

Creates an UPDATE command that increments/decrements certain columns.

ensureTable() 方法 (自版本 v1.0.4 可用)
protected void ensureTable(mixed $table)
$table mixed table schema (CDbTableSchema) or table name (string). If this refers to a valid table name, this parameter will be returned with the corresponding table schema.

Checks if the parameter is a valid table schema. If it is a string, the corresponding table schema will be retrieved.

getDbConnection() 方法
public CDbConnection getDbConnection()
{return} CDbConnection database connection.

getLastInsertID() 方法
public mixed getLastInsertID(mixed $table)
$table mixed the table schema (CDbTableSchema) or the table name (string).
{return} mixed last insertion id. Null is returned if no sequence name.

Returns the last insertion ID for the specified table.

getSchema() 方法
public CDbSchema getSchema()
{return} CDbSchema the schema for this command builder.