Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CMssqlColumnSchema
  • CMssqlCommandBuilder
  • CMssqlPdoAdapter
  • CMssqlSchema
  • CMssqlSqlsrvPdoAdapter
  • CMssqlTableSchema
  • Overview
  • Package
  • Class
  • Tree

Class CMssqlCommandBuilder

CMssqlCommandBuilder provides basic methods to create query commands for tables for Mssql Servers.

CComponent
Extended by CDbCommandBuilder
Extended by CMssqlCommandBuilder
Package: system\db\schema\mssql
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Author: Christophe Boulain <Christophe.Boulain@gmail.com>
Author: Wei Zhuo <weizhuo[at]gmail[dot]com>
Located at x2engine/framework/db/schema/mssql/CMssqlCommandBuilder.php
Methods summary
public CDbCommand
# createCountCommand( CDbTableSchema $table, CDbCriteria $criteria, string $alias = 't' )

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

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

Parameters

$table
CDbTableSchema
$table the table metadata
$criteria
CDbCriteria
$criteria the query criteria
$alias
string
$alias the alias name of the primary table. Defaults to 't'.

Returns

CDbCommand
query command.

Overrides

CDbCommandBuilder::createCountCommand()
public CDbCommand
# createFindCommand( CDbTableSchema $table, CDbCriteria $criteria, string $alias = 't' )

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

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

Parameters

$table
CDbTableSchema
$table the table metadata
$criteria
CDbCriteria
$criteria the query criteria
$alias
string
$alias the alias name of the primary table. Defaults to 't'.

Returns

CDbCommand
query command.

Overrides

CDbCommandBuilder::createFindCommand()
public CDbCommand
# createUpdateCommand( CDbTableSchema $table, array $data, CDbCriteria $criteria )

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

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

Parameters

$table
CDbTableSchema
$table the table metadata
$data
array
$data list of columns to be updated (name=>value)
$criteria
CDbCriteria
$criteria the query criteria

Returns

CDbCommand
update command.

Throws

CDbException
if no columns are being updated

Overrides

CDbCommandBuilder::createUpdateCommand()
public CDbCommand
# createDeleteCommand( CDbTableSchema $table, CDbCriteria $criteria )

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

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

Parameters

$table
CDbTableSchema
$table the table metadata
$criteria
CDbCriteria
$criteria the query criteria

Returns

CDbCommand
delete command.

Overrides

CDbCommandBuilder::createDeleteCommand()
public CDbCommand
# createUpdateCounterCommand( CDbTableSchema $table, CDbCriteria $counters, array $criteria )

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

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

Parameters

$table
CDbTableSchema
$table the table metadata
$counters
CDbCriteria
$counters the query criteria
$criteria
array
$criteria counters to be updated (counter increments/decrements indexed by column names.)

Returns

CDbCommand
the created command

Throws

CException
if no counter is specified

Overrides

CDbCommandBuilder::createUpdateCounterCommand()
public string
# applyLimit( string $sql, integer $limit, integer $offset )

This is a port from Prado Framework.

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.

Parameters

$sql
string
$sql SQL query string.
$limit
integer
$limit maximum number of rows, -1 to ignore limit.
$offset
integer
$offset row offset, -1 to ignore offset.

Returns

string
SQL with limit and offset.

Author

Wei Zhuo <weizhuo[at]gmail[dot]com>

Overrides

CDbCommandBuilder::applyLimit()
protected string
# rewriteLimitOffsetSql( string $sql, integer $limit, integer $offset )

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

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

Parameters

$sql
string
$sql sql query
$limit
integer
$limit $limit > 0
$offset
integer
$offset $offset > 0

Returns

string
modified sql query applied with limit and offset.

Author

Wei Zhuo <weizhuo[at]gmail[dot]com>
protected array
# findOrdering( string $sql )

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

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

Parameters

$sql
string
$sql $sql

Returns

array
ordering expression as key and ordering direction as value

Author

Wei Zhuo <weizhuo[at]gmail[dot]com>
protected string
# joinOrdering( array $orders, string $newPrefix )

Parameters

$orders
array
$orders ordering obtained from findOrdering()
$newPrefix
string
$newPrefix new table prefix to the ordering columns

Returns

string
concat the orderings

Author

Wei Zhuo <weizhuo[at]gmail[dot]com>
protected array
# reverseDirection( array $orders )

Parameters

$orders
array
$orders original ordering

Returns

array
ordering with reversed direction.

Author

Wei Zhuo <weizhuo[at]gmail[dot]com>
protected CDbCriteria
# checkCriteria( CMssqlTableSchema $table, CDbCriteria $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.

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.

Parameters

$table
CMssqlTableSchema
$table table schema
$criteria
CDbCriteria
$criteria criteria

Returns

CDbCriteria
the modified criteria
protected string
# createCompositeInCondition( CDbTableSchema $table, array $values, string $prefix )

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

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

Parameters

$table
CDbTableSchema
$table the table schema
$values
array
$values list of primary key values to be selected within
$prefix
string
$prefix column prefix (ended with dot)

Returns

string
the expression for selection

Overrides

CDbCommandBuilder::createCompositeInCondition()
Methods inherited from CDbCommandBuilder
__construct(), applyCondition(), applyGroup(), applyHaving(), applyJoin(), applyOrder(), bindValues(), composeMultipleInsertCommand(), createColumnCriteria(), createCriteria(), createInCondition(), createInsertCommand(), createMultipleInsertCommand(), createPkCondition(), createPkCriteria(), createSearchCondition(), createSqlCommand(), ensureTable(), getDbConnection(), getIntegerPrimaryKeyDefaultValue(), getLastInsertID(), getSchema()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Constants inherited from CDbCommandBuilder
PARAM_PREFIX
Magic properties inherited from CDbCommandBuilder
$dbConnection, $schema
API documentation generated by ApiGen 2.8.0