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
Overrides
|
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
Overrides
|
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
Throws
Overrides
|
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
Returns
Overrides
|
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
Throws
Overrides
|
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
|
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
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
|
|
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
Returns
|
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
|