Methods summary
public
|
|
public
CDbConnection
|
|
public
CDbSchema
|
|
public
mixed
|
#
getLastInsertID( mixed $table )
Returns the last insertion ID for the specified table.
Returns the last insertion ID for the specified table.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
Returns
mixed last insertion id. Null is returned if no sequence name.
|
public
CDbCommand
|
#
createFindCommand( mixed $table, CDbCriteria $criteria, string $alias = 't' )
Creates a SELECT command for a single table.
Creates a SELECT command for a single table.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $criteria
CDbCriteria
$criteria the query criteria
- $alias
string $alias the alias name of the primary table. Defaults to 't'.
Returns
|
public
CDbCommand
|
#
createCountCommand( mixed $table, CDbCriteria $criteria, string $alias = 't' )
Creates a COUNT(*) command for a single table.
Creates a COUNT(*) command for a single table.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $criteria
CDbCriteria
$criteria the query criteria
- $alias
string $alias the alias name of the primary table. Defaults to 't'.
Returns
|
public
CDbCommand
|
|
public
CDbCommand
|
#
createInsertCommand( mixed $table, array $data )
Creates an INSERT command.
Creates an INSERT command.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $data
array $data data to be inserted (column name=>column value). If a key is not a
valid column name, the corresponding value will be ignored.
Returns
|
public
CDbCommand
|
#
createMultipleInsertCommand( mixed $table, array $data )
Creates a multiple INSERT command. This method could be used to achieve
better performance during insertion of the large amount of data into the
database tables.
Creates a multiple INSERT command. This method could be used to achieve
better performance during insertion of the large amount of data into the
database tables.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $data
array[] $data list data to be inserted, each value should be an array in format (column
name=>column value). If a key is not a valid column name, the corresponding
value will be ignored.
Returns
Since
1.1.14
|
protected
CDbCommand
|
#
composeMultipleInsertCommand( mixed $table, array $data, array $templates = array() )
Creates a multiple INSERT command. This method compose the SQL expression via
given part templates, providing ability to adjust command for different SQL
syntax.
Creates a multiple INSERT command. This method compose the SQL expression via
given part templates, providing ability to adjust command for different SQL
syntax.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $data
array[] $data list data to be inserted, each value should be an array in format (column
name=>column value). If a key is not a valid column name, the corresponding
value will be ignored.
- $templates
array $templates templates for the SQL parts.
Returns
Throws
|
public
CDbCommand
|
#
createUpdateCommand( mixed $table, array $data, CDbCriteria $criteria )
Creates an UPDATE command.
Creates an UPDATE command.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $data
array $data list of columns to be updated (name=>value)
- $criteria
CDbCriteria
$criteria the query criteria
Returns
Throws
CDbException
if no columns are being updated for the given table
|
public
CDbCommand
|
#
createUpdateCounterCommand( mixed $table, array $counters, CDbCriteria $criteria )
Creates an UPDATE command that increments/decrements certain columns.
Creates an UPDATE command that increments/decrements certain columns.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $counters
array $counters counters to be updated (counter increments/decrements indexed by
column names.)
- $criteria
CDbCriteria
$criteria the query criteria
Returns
Throws
CDbException
if no columns are being updated for the given table
|
public
CDbCommand
|
#
createSqlCommand( string $sql, array $params = array() )
Creates a command based on a given SQL statement.
Creates a command based on a given SQL statement.
Parameters
- $sql
string $sql the explicitly specified SQL statement
- $params
array $params parameters that will be bound to the SQL statement
Returns
|
public
string
|
#
applyJoin( string $sql, string $join )
Alters the SQL to apply JOIN clause.
Alters the SQL to apply JOIN clause.
Parameters
- $sql
string $sql the SQL statement to be altered
- $join
string $join the JOIN clause (starting with join type, such as INNER JOIN)
Returns
string the altered SQL statement
|
public
string
|
#
applyCondition( string $sql, string $condition )
Alters the SQL to apply WHERE clause.
Alters the SQL to apply WHERE clause.
Parameters
- $sql
string $sql the SQL statement without WHERE clause
- $condition
string $condition the WHERE clause (without WHERE keyword)
Returns
string the altered SQL statement
|
public
string
|
#
applyOrder( string $sql, string $orderBy )
Alters the SQL to apply ORDER BY.
Alters the SQL to apply ORDER BY.
Parameters
- $sql
string $sql SQL statement without ORDER BY.
- $orderBy
string $orderBy column ordering
Returns
string modified SQL applied with ORDER BY.
|
public
string
|
#
applyLimit( string $sql, integer $limit, integer $offset )
Alters the SQL to apply LIMIT and OFFSET. Default implementation is
applicable for PostgreSQL, MySQL, MariaDB and SQLite.
Alters the SQL to apply LIMIT and OFFSET. Default implementation is
applicable for PostgreSQL, MySQL, MariaDB and SQLite.
Parameters
- $sql
string $sql SQL query string without LIMIT and OFFSET.
- $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
|
public
string
|
#
applyGroup( string $sql, string $group )
Alters the SQL to apply GROUP BY.
Alters the SQL to apply GROUP BY.
Parameters
- $sql
string $sql SQL query string without GROUP BY.
- $group
string $group GROUP BY
Returns
string SQL with GROUP BY.
|
public
string
|
#
applyHaving( string $sql, string $having )
Alters the SQL to apply HAVING.
Alters the SQL to apply HAVING.
Parameters
- $sql
string $sql SQL query string without HAVING
- $having
string $having HAVING
Returns
string SQL with HAVING
|
public
|
#
bindValues( CDbCommand $command, array $values )
Binds parameter values for an SQL command.
Binds parameter values for an SQL command.
Parameters
- $command
CDbCommand
$command database command
- $values
array $values values for binding (integer-indexed array for question mark
placeholders, string-indexed array for named placeholders)
|
public
CDbCriteria
|
#
createCriteria( mixed $condition = '', array $params = array() )
Creates a query criteria.
Creates a query criteria.
Parameters
- $condition
mixed $condition 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 .
- $params
array $params parameters to be bound to an SQL statement. This is only used when the
first parameter is a string (query condition). In other cases, please use CDbCriteria::$params to set parameters.
Returns
Throws
CException
if the condition is not string, array and CDbCriteria
|
public
CDbCriteria
|
#
createPkCriteria( mixed $table, mixed $pk, mixed $condition = '', array $params = array(), string $prefix = null )
Creates a query criteria with the specified primary key.
Creates a query criteria with the specified primary key.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $pk
mixed $pk 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 $condition 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 $params 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.
- $prefix
string $prefix column prefix (ended with dot). If null, it will be the table name
Returns
|
public
string
|
#
createPkCondition( mixed $table, array $values, string $prefix = null )
Generates the expression for selecting rows of specified primary key
values.
Generates the expression for selecting rows of specified primary key
values.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $values
array $values list of primary key values to be selected within
- $prefix
string $prefix column prefix (ended with dot). If null, it will be the table name
Returns
string the expression for selection
|
public
CDbCriteria
|
#
createColumnCriteria( mixed $table, array $columns, mixed $condition = '', array $params = array(), string $prefix = null )
Creates a query criteria with the specified column values.
Creates a query criteria with the specified column values.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $columns
array $columns column values that should be matched in the query (name=>value)
- $condition
mixed $condition 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 $params parameters to be bound to an SQL statement. This is only used when the
third parameter is a string (query condition). In other cases, please use CDbCriteria::$params to set parameters.
- $prefix
string $prefix column prefix (ended with dot). If null, it will be the table name
Returns
Throws
|
public
string
|
#
createSearchCondition( mixed $table, array $columns, mixed $keywords, string $prefix = null, boolean $caseSensitive = true )
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.
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.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $columns
array $columns list of column names for potential search condition.
- $keywords
mixed $keywords search keywords. This can be either a string with space-separated
keywords or an array of keywords.
- $prefix
string $prefix optional column prefix (with dot at the end). If null, the table name
will be used as the prefix.
- $caseSensitive
boolean $caseSensitive whether the search is case-sensitive. Defaults to true.
Returns
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.
Throws
|
public
string
|
#
createInCondition( mixed $table, mixed $columnName, array $values, string $prefix = null )
Generates the expression for selecting rows of specified primary key
values.
Generates the expression for selecting rows of specified primary key
values.
Parameters
- $table
mixed $table the table schema (CDbTableSchema ) or the table name (string).
- $columnName
mixed $columnName 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 $values list of key values to be selected within
- $prefix
string $prefix column prefix (ended with dot). If null, it will be the table name
Returns
string the expression for selection
Throws
|
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
|
protected
|
#
ensureTable( mixed & $table )
Checks if the parameter is a valid table schema. If it is a string, the
corresponding table schema will be retrieved.
Checks if the parameter is a valid table schema. If it is a string, the
corresponding table schema will be retrieved.
Parameters
- $table
mixed $table 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.
Throws
|
protected
string
|
#
getIntegerPrimaryKeyDefaultValue( )
Returns default value of the integer/serial primary key. Default value means
that the next autoincrement/sequence value would be used.
Returns default value of the integer/serial primary key. Default value means
that the next autoincrement/sequence value would be used.
Returns
string default value of the integer/serial primary key.
Since
1.1.14
|