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

CMssqlCommandBuilder

system.db.schema.mssql
继承 class CMssqlCommandBuilder » CDbCommandBuilder » CComponent
可用自 1.0.4
版本 $Id$
CMssqlCommandBuilder provides basic methods to create query commands for tables for Mssql Servers.

公共属性

隐藏继承的属性

属性类型描述被定义在
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() This is a port from Prado Framework. CMssqlCommandBuilder
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. CMssqlCommandBuilder
createCriteria() Creates a query criteria. CDbCommandBuilder
createDeleteCommand() Creates a DELETE command. CMssqlCommandBuilder
createFindCommand() Creates a SELECT command for a single table. CMssqlCommandBuilder
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. CMssqlCommandBuilder
createUpdateCounterCommand() Creates an UPDATE command that increments/decrements certain columns. CMssqlCommandBuilder
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. CMssqlCommandBuilder
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

受保护的方法

隐藏继承的方法

方法描述被定义在
checkCriteria() Checks if the criteria has an order by clause when using offset/limit. CMssqlCommandBuilder
createCompositeInCondition() Generates the expression for selecting rows with specified composite key values. CDbCommandBuilder
ensureTable() Checks if the parameter is a valid table schema. CDbCommandBuilder
findOrdering() Base on simplified syntax http://msdn2.microsoft.com/en-us/library/aa259187(SQL.80).aspx CMssqlCommandBuilder
joinOrdering() CMssqlCommandBuilder
reverseDirection() CMssqlCommandBuilder
rewriteLimitOffsetSql() Rewrite sql to apply $limit > and $offset > 0 for MSSQL database. CMssqlCommandBuilder

方法详情

applyLimit() 方法
public string applyLimit(string $sql, integer $limit, integer $offset)
$sql string SQL query string.
$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.

This is a port from Prado Framework.

Overrides parent implementation. Alters the sql to apply $limit and $offset. The idea for limit with offset is done by modifying the sql on the fly with numerous assumptions on the structure of the sql string. The modification is done with reference to the notes from http://troels.arvin.dk/db/rdbms/#select-limit-offset

SELECT * FROM ( SELECT TOP n * FROM ( SELECT TOP z columns -- (z=n+skip) FROM tablename ORDER BY key ASC ) AS FOO ORDER BY key DESC -- ('FOO' may be anything) ) AS BAR ORDER BY key ASC -- ('BAR' may be anything)

Regular expressions are used to alter the SQL query. The resulting SQL query may be malformed for complex queries. The following restrictions apply

  • In particular, commas should NOT be used as part of the ordering expression or identifier. Commas must only be used for separating the ordering clauses.
  • In the ORDER BY clause, the column name should NOT be be qualified with a table name or view name. Alias the column names or use column index.
  • No clauses should follow the ORDER BY clause, e.g. no COMPUTE or FOR clauses.
  • checkCriteria() 方法
    protected CDbCrireria checkCriteria(CMssqlTableSchema $table, CDbCriteria $criteria)
    $table CMssqlTableSchema table schema
    $criteria CDbCriteria criteria
    {return} CDbCrireria the modified criteria

    Checks if the criteria has an order by clause when using offset/limit. Override parent implementation to check if an orderby clause if specified when querying with an offset If not, order it by pk.

    createCountCommand() 方法
    public CDbCommand createCountCommand(CDbTableSchema $table, CDbCriteria $criteria)
    $table CDbTableSchema the table metadata
    $criteria CDbCriteria the query criteria
    {return} CDbCommand query command.

    Creates a COUNT(*) command for a single table. Override parent implementation to remove the order clause of criteria if it exists

    createDeleteCommand() 方法
    public CDbCommand createDeleteCommand(CDbTableSchema $table, CDbCriteria $criteria)
    $table CDbTableSchema the table metadata
    $criteria CDbCriteria the query criteria
    {return} CDbCommand delete command.

    Creates a DELETE command. Override parent implementation to check if an orderby clause if specified when querying with an offset

    createFindCommand() 方法
    public CDbCommand createFindCommand(CDbTableSchema $table, CDbCriteria $criteria)
    $table CDbTableSchema the table metadata
    $criteria CDbCriteria the query criteria
    {return} CDbCommand query command.

    Creates a SELECT command for a single table. Override parent implementation to check if an orderby clause if specified when querying with an offset

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

    Creates an UPDATE command. Override parent implementation because mssql don't want to update an identity column

    createUpdateCounterCommand() 方法
    public CDbCommand createUpdateCounterCommand(CDbTableSchema $table, CDbCriteria $counters, array $criteria)
    $table CDbTableSchema the table metadata
    $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. Override parent implementation to check if an orderby clause if specified when querying with an offset

    findOrdering() 方法
    protected array findOrdering(string $sql)
    $sql string $sql
    {return} array ordering expression as key and ordering direction as value

    Base on simplified syntax http://msdn2.microsoft.com/en-us/library/aa259187(SQL.80).aspx

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

    Returns the last insertion ID for the specified table. Override parent implemantation since PDO mssql driver does not provide this method

    joinOrdering() 方法
    protected string joinOrdering(array $orders)
    $orders array ordering obtained from findOrdering()
    {return} string concat the orderings

    reverseDirection() 方法
    protected array reverseDirection(array $orders)
    $orders array original ordering
    {return} array ordering with reversed direction.

    rewriteLimitOffsetSql() 方法
    protected sql rewriteLimitOffsetSql(string $sql, integer $limit, integer $offset)
    $sql string sql query
    $limit integer $limit > 0
    $offset integer $offset > 0
    {return} sql modified sql query applied with limit and offset.

    Rewrite sql to apply $limit > and $offset > 0 for MSSQL database. See http://troels.arvin.dk/db/rdbms/#select-limit-offset