Methods summary
public
|
#
__construct( CDbConnection $connection, mixed $query = null )
Constructor.
Parameters
- $connection
CDbConnection
$connection the database connection
- $query
mixed $query the DB query to be executed. This can be either a string representing a
SQL statement, or an array whose name-value pairs will be used to set the
corresponding properties of the created command object. For example, you can
pass in either <span class="php-quote">'SELECT * FROM
tbl_user'</span> or <span
class="php-keyword1">array</span>(<span
class="php-quote">'select'</span>=><span
class="php-quote">'*'</span>, <span
class="php-quote">'from'</span>=><span
class="php-quote">'tbl_user'</span>) . They are equivalent in
terms of the final query result. When passing the query as an array, the
following properties are commonly set: CDbCommand::select() , distinct, CDbCommand::from() , CDbCommand::where() , CDbCommand::join() , CDbCommand::group() , CDbCommand::having() , CDbCommand::order() , CDbCommand::limit() , CDbCommand::offset() and CDbCommand::union() . Please refer to the
setter of each of these properties for details about valid property values. This
feature has been available since version 1.1.6. Since 1.1.7 it is possible to
use a specific mode of data fetching by setting setFetchMode FetchMode.
See http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
for more details.
|
public
array
|
#
__sleep( )
Set the statement to null when serializing.
Set the statement to null when serializing.
Returns
array
|
public
static
|
#
setFetchMode( mixed $mode )
Set the default fetch mode for this statement
Set the default fetch mode for this statement
Parameters
- $mode
mixed $mode fetch mode
Returns
static
Since
1.1.7
See
|
public
static
|
#
reset( )
Cleans up the command and prepares for building a new query. This method is
mainly used when a command object is being reused multiple times for building
different queries. Calling this method will clean up all internal states of the
command object.
Cleans up the command and prepares for building a new query. This method is
mainly used when a command object is being reused multiple times for building
different queries. Calling this method will clean up all internal states of the
command object.
Returns
static this command instance
Since
1.1.6
|
public
string
|
#
getText( )
Returns
string the SQL statement to be executed
|
public
static
|
#
setText( string $value )
Specifies the SQL statement to be executed. Any previous execution will be
terminated or cancel.
Specifies the SQL statement to be executed. Any previous execution will be
terminated or cancel.
Parameters
- $value
string $value the SQL statement to be executed
Returns
static this command instance
|
public
CDbConnection
|
|
public
PDOStatement
|
#
getPdoStatement( )
Returns
PDOStatement
the underlying PDOStatement for this command It could be null if the statement
is not prepared yet.
|
public
|
#
prepare( )
Prepares the SQL statement to be executed. For complex SQL statement that is
to be executed multiple times, this may improve performance. For SQL statement
with binding parameters, this method is invoked automatically.
Prepares the SQL statement to be executed. For complex SQL statement that is
to be executed multiple times, this may improve performance. For SQL statement
with binding parameters, this method is invoked automatically.
Throws
CDbException
if CDbCommand failed to prepare the SQL statement
|
public
|
#
cancel( )
Cancels the execution of the SQL statement.
Cancels the execution of the SQL statement.
|
public
static
|
#
bindParam( mixed $name, mixed & $value, integer $dataType = null, integer $length = null, mixed $driverOptions = null )
Binds a parameter to the SQL statement to be executed.
Binds a parameter to the SQL statement to be executed.
Parameters
- $name
mixed $name Parameter identifier. For a prepared statement using named placeholders,
this will be a parameter name of the form :name. For a prepared statement using
question mark placeholders, this will be the 1-indexed position of the
parameter.
- $value
mixed $value Name of the PHP variable to bind to the SQL statement parameter
- $dataType
integer $dataType SQL data type of the parameter. If null, the type is determined by the
PHP type of the value.
- $length
integer $length length of the data type
- $driverOptions
mixed $driverOptions the driver-specific options (this is available since version
1.1.6)
Returns
static the current command being executed
See
|
public
static
|
#
bindValue( mixed $name, mixed $value, integer $dataType = null )
Binds a value to a parameter.
Binds a value to a parameter.
Parameters
- $name
mixed $name Parameter identifier. For a prepared statement using named placeholders,
this will be a parameter name of the form :name. For a prepared statement using
question mark placeholders, this will be the 1-indexed position of the
parameter.
- $value
mixed $value The value to bind to the parameter
- $dataType
integer $dataType SQL data type of the parameter. If null, the type is determined by the
PHP type of the value.
Returns
static the current command being executed
See
|
public
static
|
#
bindValues( array $values )
Binds a list of values to the corresponding parameters. This is similar to
CDbCommand::bindValue() except that it binds multiple values. Note that the SQL data
type of each value is determined by its PHP type.
Binds a list of values to the corresponding parameters. This is similar to
CDbCommand::bindValue() except that it binds multiple values. Note that the SQL data
type of each value is determined by its PHP type.
Parameters
- $values
array $values the values to be bound. This must be given in terms of an associative
array with array keys being the parameter names, and array values the
corresponding parameter values. For example, <span
class="php-keyword1">array</span>(<span
class="php-quote">':name'</span>=><span
class="php-quote">'John'</span>, <span
class="php-quote">':age'</span>=><span
class="php-num">25</span>) .
Returns
static the current command being executed
Since
1.1.5
|
public
integer
|
#
execute( array $params = array() )
Executes the SQL statement. This method is meant only for executing non-query
SQL statement. No result set will be returned.
Executes the SQL statement. This method is meant only for executing non-query
SQL statement. No result set will be returned.
Parameters
Returns
integer number of rows affected by the execution.
Throws
|
public
CDbDataReader
|
#
query( array $params = array() )
Executes the SQL statement and returns query result. This method is for
executing an SQL query that returns result set.
Executes the SQL statement and returns query result. This method is for
executing an SQL query that returns result set.
Parameters
Returns
Throws
|
public
array
|
#
queryAll( boolean $fetchAssociative = true, array $params = array() )
Executes the SQL statement and returns all rows.
Executes the SQL statement and returns all rows.
Parameters
- $fetchAssociative
boolean $fetchAssociative whether each row should be returned as an associated array
with column names as the keys or the array keys are column indexes (0-based).
- $params
array $params input parameters (name=>value) for the SQL execution. This is an
alternative to CDbCommand::bindParam() and CDbCommand::bindValue() . If you have multiple
input parameters, passing them in this way can improve the performance. Note
that if you pass parameters in this way, you cannot bind parameters or values
using CDbCommand::bindParam() or CDbCommand::bindValue() , and vice versa. Please also note
that all values are treated as strings in this case, if you need them to be
handled as their real data types, you have to use CDbCommand::bindParam() or CDbCommand::bindValue() instead.
Returns
array all rows of the query result. Each array element is an array representing a row.
An empty array is returned if the query results in nothing.
Throws
|
public
mixed
|
#
queryRow( boolean $fetchAssociative = true, array $params = array() )
Executes the SQL statement and returns the first row of the result. This is a
convenient method of CDbCommand::query() when only the first row of data is
needed.
Executes the SQL statement and returns the first row of the result. This is a
convenient method of CDbCommand::query() when only the first row of data is
needed.
Parameters
- $fetchAssociative
boolean $fetchAssociative whether the row should be returned as an associated array with
column names as the keys or the array keys are column indexes (0-based).
- $params
array $params input parameters (name=>value) for the SQL execution. This is an
alternative to CDbCommand::bindParam() and CDbCommand::bindValue() . If you have multiple
input parameters, passing them in this way can improve the performance. Note
that if you pass parameters in this way, you cannot bind parameters or values
using CDbCommand::bindParam() or CDbCommand::bindValue() , and vice versa. Please also note
that all values are treated as strings in this case, if you need them to be
handled as their real data types, you have to use CDbCommand::bindParam() or CDbCommand::bindValue() instead.
Returns
mixed the first row (in terms of an array) of the query result, false if no result.
Throws
|
public
mixed
|
#
queryScalar( array $params = array() )
Executes the SQL statement and returns the value of the first column in the
first row of data. This is a convenient method of CDbCommand::query() when only a
single scalar value is needed (e.g. obtaining the count of the records).
Executes the SQL statement and returns the value of the first column in the
first row of data. This is a convenient method of CDbCommand::query() when only a
single scalar value is needed (e.g. obtaining the count of the records).
Parameters
Returns
mixed the value of the first column in the first row of the query result. False is
returned if there is no value.
Throws
|
public
array
|
#
queryColumn( array $params = array() )
Executes the SQL statement and returns the first column of the result. This
is a convenient method of CDbCommand::query() when only the first column of data is
needed. Note, the column returned will contain the first element in each row of
result.
Executes the SQL statement and returns the first column of the result. This
is a convenient method of CDbCommand::query() when only the first column of data is
needed. Note, the column returned will contain the first element in each row of
result.
Parameters
Returns
array the first column of the query result. Empty array if no result.
Throws
|
public
string
|
#
buildQuery( array $query )
Builds a SQL SELECT statement from the given query specification.
Builds a SQL SELECT statement from the given query specification.
Parameters
Returns
string the SQL statement
Throws
CDbException
if "from" key is not present in given query parameter
Since
1.1.6
|
public
static
|
#
select( mixed $columns = '*', string $option = '' )
Sets the SELECT part of the query.
Sets the SELECT part of the query.
Parameters
- $columns
mixed $columns the columns to be selected. Defaults to '*', meaning all columns.
Columns can be specified in either a string (e.g. "id, name") or an array (e.g.
array('id', 'name')). Columns can contain table prefixes (e.g. "tbl_user.id")
and/or column aliases (e.g. "tbl_user.id AS user_id"). The method will
automatically quote the column names unless a column contains some parenthesis
(which means the column contains a DB expression).
- $option
string $option additional option that should be appended to the 'SELECT' keyword. For
example, in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used. This parameter
is supported since version 1.1.8.
Returns
static the command object itself
Since
1.1.6
|
public
string
|
#
getSelect( )
Returns the SELECT part in the query.
Returns the SELECT part in the query.
Returns
string the SELECT part (without 'SELECT') in the query.
Since
1.1.6
|
public
|
#
setSelect( mixed $value )
Sets the SELECT part in the query.
Sets the SELECT part in the query.
Parameters
- $value
mixed $value the data to be selected. Please refer to CDbCommand::select() for details on
how to specify this parameter.
Since
1.1.6
|
public
CDbCommand
|
#
selectDistinct( mixed $columns = '*' )
Sets the SELECT part of the query with the DISTINCT flag turned on. This is
the same as CDbCommand::select() except that the DISTINCT flag is turned on.
Sets the SELECT part of the query with the DISTINCT flag turned on. This is
the same as CDbCommand::select() except that the DISTINCT flag is turned on.
Parameters
Returns
Since
1.1.6
|
public
boolean
|
#
getDistinct( )
Returns a value indicating whether SELECT DISTINCT should be used.
Returns a value indicating whether SELECT DISTINCT should be used.
Returns
boolean a value indicating whether SELECT DISTINCT should be used.
Since
1.1.6
|
public
|
#
setDistinct( boolean $value )
Sets a value indicating whether SELECT DISTINCT should be used.
Sets a value indicating whether SELECT DISTINCT should be used.
Parameters
- $value
boolean $value a value indicating whether SELECT DISTINCT should be used.
Since
1.1.6
|
public
static
|
#
from( mixed $tables )
Sets the FROM part of the query.
Sets the FROM part of the query.
Parameters
- $tables
mixed $tables the table(s) to be selected from. This can be either a string (e.g.
'tbl_user') or an array (e.g. array('tbl_user', 'tbl_profile')) specifying one
or several table names. Table names can contain schema prefixes (e.g.
'public.tbl_user') and/or table aliases (e.g. 'tbl_user u'). The method will
automatically quote the table names unless it contains some parenthesis (which
means the table is given as a sub-query or DB expression).
Returns
static the command object itself
Since
1.1.6
|
public
string
|
#
getFrom( )
Returns the FROM part in the query.
Returns the FROM part in the query.
Returns
string the FROM part (without 'FROM' ) in the query.
Since
1.1.6
|
public
|
#
setFrom( mixed $value )
Sets the FROM part in the query.
Sets the FROM part in the query.
Parameters
- $value
mixed $value the tables to be selected from. Please refer to CDbCommand::from() for
details on how to specify this parameter.
Since
1.1.6
|
public
static
|
#
where( mixed $conditions, array $params = array() )
Sets the WHERE part of the query.
Sets the WHERE part of the query.
The method requires a $conditions parameter, and optionally a $params
parameter specifying the values to be bound to the query.
The $conditions parameter should be either a string (e.g. 'id=1') or an array.
If the latter, it must be of the format <span
class="php-keyword1">array</span>(operator, operand1, operand2,
...) , where the operator can be one of the followings, and the possible
operands depend on the corresponding operator:
<span class="php-keyword1">and</span> : the operands
should be concatenated together using AND. For example, array('and', 'id=1',
'id=2') will generate 'id=1 AND id=2'. If an operand is an array, it will be
converted into a string using the same rules described here. For example,
array('and', 'type=1', array('or', 'id=1', 'id=2')) will generate 'type=1 AND
(id=1 OR id=2)'. The method will NOT do any quoting or escaping.
<span class="php-keyword1">or</span> : similar as
the <span class="php-keyword1">and</span> operator
except that the operands are concatenated using OR.
in : operand 1 should be a column or DB expression, and operand
2 be an array representing the range of the values that the column or DB
expression should be in. For example, array('in', 'id', array(1,2,3)) will
generate 'id IN (1,2,3)'. The method will properly quote the column name and
escape values in the range.
not in : similar as the in operator except that IN
is replaced with NOT IN in the generated condition.
like : operand 1 should be a column or DB expression, and
operand 2 be a string or an array representing the values that the column or DB
expression should be like. For example, array('like', 'name', '%tester%') will
generate "name LIKE '%tester%'". When the value range is given as an array,
multiple LIKE predicates will be generated and concatenated using AND. For
example, array('like', 'name', array('%test%', '%sample%')) will generate "name
LIKE '%test%' AND name LIKE '%sample%'". The method will properly quote the
column name and escape values in the range.
not like : similar as the like operator except that
LIKE is replaced with NOT LIKE in the generated condition.
<span class="php-keyword1">or</span> like : similar
as the like operator except that OR is used to concatenated the
LIKE predicates.
<span class="php-keyword1">or</span> not like :
similar as the not like operator except that OR is used to
concatenated the NOT LIKE predicates.
Parameters
- $conditions
mixed $conditions the conditions that should be put in the WHERE part.
- $params
array $params the parameters (name=>value) to be bound to the query
Returns
static the command object itself
Since
1.1.6
|
public
static
|
#
andWhere( mixed $conditions, array $params = array() )
Appends given condition to the existing WHERE part of the query with 'AND'
operator.
Appends given condition to the existing WHERE part of the query with 'AND'
operator.
This method works almost the same way as CDbCommand::where() except the fact that
it appends condition with 'AND' operator, but not replaces it with the new one.
For more information on parameters of this method refer to the CDbCommand::where()
documentation.
Parameters
- $conditions
mixed $conditions the conditions that should be appended to the WHERE part.
- $params
array $params the parameters (name=>value) to be bound to the query.
Returns
static the command object itself.
Since
1.1.13
|
public
static
|
#
orWhere( mixed $conditions, array $params = array() )
Appends given condition to the existing WHERE part of the query with 'OR'
operator.
Appends given condition to the existing WHERE part of the query with 'OR'
operator.
This method works almost the same way as CDbCommand::where() except the fact that
it appends condition with 'OR' operator, but not replaces it with the new one.
For more information on parameters of this method refer to the CDbCommand::where()
documentation.
Parameters
- $conditions
mixed $conditions the conditions that should be appended to the WHERE part.
- $params
array $params the parameters (name=>value) to be bound to the query.
Returns
static the command object itself.
Since
1.1.13
|
public
string
|
#
getWhere( )
Returns the WHERE part in the query.
Returns the WHERE part in the query.
Returns
string the WHERE part (without 'WHERE' ) in the query.
Since
1.1.6
|
public
|
#
setWhere( mixed $value )
Sets the WHERE part in the query.
Sets the WHERE part in the query.
Parameters
- $value
mixed $value the where part. Please refer to CDbCommand::where() for details on how to
specify this parameter.
Since
1.1.6
|
public
CDbCommand
|
#
join( string $table, mixed $conditions, array $params = array() )
Appends an INNER JOIN part to the query.
Appends an INNER JOIN part to the query.
Parameters
- $table
string $table the table to be joined. Table name can contain schema prefix (e.g.
'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). The method will
automatically quote the table name unless it contains some parenthesis (which
means the table is given as a sub-query or DB expression).
- $conditions
mixed $conditions the join condition that should appear in the ON part. Please refer
to CDbCommand::where() on how to specify conditions.
- $params
array $params the parameters (name=>value) to be bound to the query
Returns
Since
1.1.6
|
public
mixed
|
#
getJoin( )
Returns the join part in the query.
Returns the join part in the query.
Returns
mixed the join part in the query. This can be an array representing multiple join
fragments, or a string representing a single join fragment. Each join fragment
will contain the proper join operator (e.g. LEFT JOIN).
Since
1.1.6
|
public
|
#
setJoin( mixed $value )
Sets the join part in the query.
Sets the join part in the query.
Parameters
- $value
mixed $value the join part in the query. This can be either a string or an array
representing multiple join parts in the query. Each part must contain the proper
join operator (e.g. 'LEFT JOIN tbl_profile ON tbl_user.id=tbl_profile.id')
Since
1.1.6
|
public
CDbCommand
|
#
leftJoin( string $table, mixed $conditions, array $params = array() )
Appends a LEFT OUTER JOIN part to the query.
Appends a LEFT OUTER JOIN part to the query.
Parameters
- $table
string $table the table to be joined. Table name can contain schema prefix (e.g.
'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). The method will
automatically quote the table name unless it contains some parenthesis (which
means the table is given as a sub-query or DB expression).
- $conditions
mixed $conditions the join condition that should appear in the ON part. Please refer
to CDbCommand::where() on how to specify conditions.
- $params
array $params the parameters (name=>value) to be bound to the query
Returns
Since
1.1.6
|
public
CDbCommand
|
#
rightJoin( string $table, mixed $conditions, array $params = array() )
Appends a RIGHT OUTER JOIN part to the query.
Appends a RIGHT OUTER JOIN part to the query.
Parameters
- $table
string $table the table to be joined. Table name can contain schema prefix (e.g.
'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). The method will
automatically quote the table name unless it contains some parenthesis (which
means the table is given as a sub-query or DB expression).
- $conditions
mixed $conditions the join condition that should appear in the ON part. Please refer
to CDbCommand::where() on how to specify conditions.
- $params
array $params the parameters (name=>value) to be bound to the query
Returns
Since
1.1.6
|
public
CDbCommand
|
#
crossJoin( string $table )
Appends a CROSS JOIN part to the query. Note that not all DBMS support CROSS
JOIN.
Appends a CROSS JOIN part to the query. Note that not all DBMS support CROSS
JOIN.
Parameters
- $table
string $table the table to be joined. Table name can contain schema prefix (e.g.
'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). The method will
automatically quote the table name unless it contains some parenthesis (which
means the table is given as a sub-query or DB expression).
Returns
Since
1.1.6
|
public
CDbCommand
|
#
naturalJoin( string $table )
Appends a NATURAL JOIN part to the query. Note that not all DBMS support
NATURAL JOIN.
Appends a NATURAL JOIN part to the query. Note that not all DBMS support
NATURAL JOIN.
Parameters
- $table
string $table the table to be joined. Table name can contain schema prefix (e.g.
'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). The method will
automatically quote the table name unless it contains some parenthesis (which
means the table is given as a sub-query or DB expression).
Returns
Since
1.1.6
|
public
CDbCommand
|
#
naturalLeftJoin( string $table )
Appends a NATURAL LEFT JOIN part to the query. Note that not all DBMS support
NATURAL LEFT JOIN.
Appends a NATURAL LEFT JOIN part to the query. Note that not all DBMS support
NATURAL LEFT JOIN.
Parameters
- $table
string $table the table to be joined. Table name can contain schema prefix (e.g.
'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). The method will
automatically quote the table name unless it contains some parenthesis (which
means the table is given as a sub-query or DB expression).
Returns
Since
1.1.16
|
public
CDbCommand
|
#
naturalRightJoin( string $table )
Appends a NATURAL RIGHT JOIN part to the query. Note that not all DBMS
support NATURAL RIGHT JOIN.
Appends a NATURAL RIGHT JOIN part to the query. Note that not all DBMS
support NATURAL RIGHT JOIN.
Parameters
- $table
string $table the table to be joined. Table name can contain schema prefix (e.g.
'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). The method will
automatically quote the table name unless it contains some parenthesis (which
means the table is given as a sub-query or DB expression).
Returns
Since
1.1.16
|
public
static
|
#
group( mixed $columns )
Sets the GROUP BY part of the query.
Sets the GROUP BY part of the query.
Parameters
- $columns
mixed $columns the columns to be grouped by. Columns can be specified in either a
string (e.g. "id, name") or an array (e.g. array('id', 'name')). The method will
automatically quote the column names unless a column contains some parenthesis
(which means the column contains a DB expression).
Returns
static the command object itself
Since
1.1.6
|
public
string
|
#
getGroup( )
Returns the GROUP BY part in the query.
Returns the GROUP BY part in the query.
Returns
string the GROUP BY part (without 'GROUP BY' ) in the query.
Since
1.1.6
|
public
|
#
setGroup( mixed $value )
Sets the GROUP BY part in the query.
Sets the GROUP BY part in the query.
Parameters
- $value
mixed $value the GROUP BY part. Please refer to CDbCommand::group() for details on how to
specify this parameter.
Since
1.1.6
|
public
static
|
#
having( mixed $conditions, array $params = array() )
Sets the HAVING part of the query.
Sets the HAVING part of the query.
Parameters
- $conditions
mixed $conditions the conditions to be put after HAVING. Please refer to CDbCommand::where()
on how to specify conditions.
- $params
array $params the parameters (name=>value) to be bound to the query
Returns
static the command object itself
Since
1.1.6
|
public
string
|
#
getHaving( )
Returns the HAVING part in the query.
Returns the HAVING part in the query.
Returns
string the HAVING part (without 'HAVING' ) in the query.
Since
1.1.6
|
public
|
#
setHaving( mixed $value )
Sets the HAVING part in the query.
Sets the HAVING part in the query.
Parameters
- $value
mixed $value the HAVING part. Please refer to CDbCommand::having() for details on how to
specify this parameter.
Since
1.1.6
|
public
static
|
#
order( mixed $columns )
Sets the ORDER BY part of the query.
Sets the ORDER BY part of the query.
Parameters
- $columns
mixed $columns the columns (and the directions) to be ordered by. Columns can be
specified in either a string (e.g. "id ASC, name DESC") or an array (e.g.
array('id ASC', 'name DESC')). The method will automatically quote the column
names unless a column contains some parenthesis (which means the column contains
a DB expression). For example, to get "ORDER BY 1" you should use <pre>
$criteria->order('(1)'); </pre>
Returns
static the command object itself
Since
1.1.6
|
public
string
|
#
getOrder( )
Returns the ORDER BY part in the query.
Returns the ORDER BY part in the query.
Returns
string the ORDER BY part (without 'ORDER BY' ) in the query.
Since
1.1.6
|
public
|
#
setOrder( mixed $value )
Sets the ORDER BY part in the query.
Sets the ORDER BY part in the query.
Parameters
- $value
mixed $value the ORDER BY part. Please refer to CDbCommand::order() for details on how to
specify this parameter.
Since
1.1.6
|
public
static
|
#
limit( integer $limit, integer $offset = null )
Sets the LIMIT part of the query.
Sets the LIMIT part of the query.
Parameters
- $limit
integer $limit the limit
- $offset
integer $offset the offset
Returns
static the command object itself
Since
1.1.6
|
public
string
|
#
getLimit( )
Returns the LIMIT part in the query.
Returns the LIMIT part in the query.
Returns
string the LIMIT part (without 'LIMIT' ) in the query.
Since
1.1.6
|
public
|
#
setLimit( integer $value )
Sets the LIMIT part in the query.
Sets the LIMIT part in the query.
Parameters
- $value
integer $value the LIMIT part. Please refer to CDbCommand::limit() for details on how to
specify this parameter.
Since
1.1.6
|
public
static
|
#
offset( integer $offset )
Sets the OFFSET part of the query.
Sets the OFFSET part of the query.
Parameters
- $offset
integer $offset the offset
Returns
static the command object itself
Since
1.1.6
|
public
string
|
#
getOffset( )
Returns the OFFSET part in the query.
Returns the OFFSET part in the query.
Returns
string the OFFSET part (without 'OFFSET' ) in the query.
Since
1.1.6
|
public
|
#
setOffset( integer $value )
Sets the OFFSET part in the query.
Sets the OFFSET part in the query.
Parameters
- $value
integer $value the OFFSET part. Please refer to CDbCommand::offset() for details on how to
specify this parameter.
Since
1.1.6
|
public
static
|
#
union( string $sql )
Appends a SQL statement using UNION operator.
Appends a SQL statement using UNION operator.
Parameters
- $sql
string $sql the SQL statement to be appended using UNION
Returns
static the command object itself
Since
1.1.6
|
public
mixed
|
#
getUnion( )
Returns the UNION part in the query.
Returns the UNION part in the query.
Returns
mixed the UNION part (without 'UNION' ) in the query. This can be either a string or
an array representing multiple union parts.
Since
1.1.6
|
public
|
#
setUnion( mixed $value )
Sets the UNION part in the query.
Sets the UNION part in the query.
Parameters
- $value
mixed $value the UNION part. This can be either a string or an array representing
multiple SQL statements to be unioned together.
Since
1.1.6
|
public
integer
|
#
insert( string $table, array $columns )
Creates and executes an INSERT SQL statement. The method will properly escape
the column names, and bind the values to be inserted.
Creates and executes an INSERT SQL statement. The method will properly escape
the column names, and bind the values to be inserted.
Parameters
- $table
string $table the table that new rows will be inserted into.
- $columns
array $columns the column data (name=>value) to be inserted into the table.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
update( string $table, array $columns, mixed $conditions = '', array $params = array() )
Creates and executes an UPDATE SQL statement. The method will properly escape
the column names and bind the values to be updated.
Creates and executes an UPDATE SQL statement. The method will properly escape
the column names and bind the values to be updated.
Parameters
- $table
string $table the table to be updated.
- $columns
array $columns the column data (name=>value) to be updated.
- $conditions
mixed $conditions the conditions that will be put in the WHERE part. Please refer to
CDbCommand::where() on how to specify conditions.
- $params
array $params the parameters to be bound to the query. Do not use column names as
parameter names here. They are reserved for <span
class="php-var">$columns</span> parameter.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
delete( string $table, mixed $conditions = '', array $params = array() )
Creates and executes a DELETE SQL statement.
Creates and executes a DELETE SQL statement.
Parameters
- $table
string $table the table where the data will be deleted from.
- $conditions
mixed $conditions the conditions that will be put in the WHERE part. Please refer to
CDbCommand::where() on how to specify conditions.
- $params
array $params the parameters to be bound to the query.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
createTable( string $table, array $columns, string $options = null )
Builds and executes a SQL statement for creating a new DB table.
Builds and executes a SQL statement for creating a new DB table.
The columns in the new table should be specified as name-definition pairs
(e.g. 'name'=>'string'), where name stands for a column name which will be
properly quoted by the method, and definition stands for the column type which
can contain an abstract DB type. The getColumnType method will be
invoked to convert any abstract type into a physical one.
If a column is specified with definition only (e.g. 'PRIMARY KEY (name,
type)'), it will be directly inserted into the generated SQL.
Parameters
- $table
string $table the name of the table to be created. The name will be properly quoted by
the method.
- $columns
array $columns the columns (name=>definition) in the new table.
- $options
string $options additional SQL fragment that will be appended to the generated SQL.
Returns
Since
1.1.6
|
public
integer
|
#
renameTable( string $table, string $newName )
Builds and executes a SQL statement for renaming a DB table.
Builds and executes a SQL statement for renaming a DB table.
Parameters
- $table
string $table the table to be renamed. The name will be properly quoted by the method.
- $newName
string $newName the new table name. The name will be properly quoted by the method.
Returns
Since
1.1.6
|
public
integer
|
#
dropTable( string $table )
Builds and executes a SQL statement for dropping a DB table.
Builds and executes a SQL statement for dropping a DB table.
Parameters
- $table
string $table the table to be dropped. The name will be properly quoted by the method.
Returns
Since
1.1.6
|
public
integer
|
#
truncateTable( string $table )
Builds and executes a SQL statement for truncating a DB table.
Builds and executes a SQL statement for truncating a DB table.
Parameters
- $table
string $table the table to be truncated. The name will be properly quoted by the
method.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
addColumn( string $table, string $column, string $type )
Builds and executes a SQL statement for adding a new DB column.
Builds and executes a SQL statement for adding a new DB column.
Parameters
- $table
string $table the table that the new column will be added to. The table name will be
properly quoted by the method.
- $column
string $column the name of the new column. The name will be properly quoted by the
method.
- $type
string $type the column type. The getColumnType method will be invoked to
convert abstract column type (if any) into the physical one. Anything that is
not recognized as abstract type will be kept in the generated SQL. For example,
'string' will be turned into 'varchar(255)', while 'string not null' will become
'varchar(255) not null'.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
dropColumn( string $table, string $column )
Builds and executes a SQL statement for dropping a DB column.
Builds and executes a SQL statement for dropping a DB column.
Parameters
- $table
string $table the table whose column is to be dropped. The name will be properly quoted
by the method.
- $column
string $column the name of the column to be dropped. The name will be properly quoted
by the method.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
renameColumn( string $table, string $name, string $newName )
Builds and executes a SQL statement for renaming a column.
Builds and executes a SQL statement for renaming a column.
Parameters
- $table
string $table the table whose column is to be renamed. The name will be properly quoted
by the method.
- $name
string $name the old name of the column. The name will be properly quoted by the
method.
- $newName
string $newName the new name of the column. The name will be properly quoted by the
method.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
alterColumn( string $table, string $column, string $type )
Builds and executes a SQL statement for changing the definition of a
column.
Builds and executes a SQL statement for changing the definition of a
column.
Parameters
- $table
string $table the table whose column is to be changed. The table name will be properly
quoted by the method.
- $column
string $column the name of the column to be changed. The name will be properly quoted
by the method.
- $type
string $type the new column type. The getColumnType method will be invoked to
convert abstract column type (if any) into the physical one. Anything that is
not recognized as abstract type will be kept in the generated SQL. For example,
'string' will be turned into 'varchar(255)', while 'string not null' will become
'varchar(255) not null'.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
addForeignKey( string $name, string $table, string|array $columns, string $refTable, string|array $refColumns, string $delete = null, string $update = null )
Builds a SQL statement for adding a foreign key constraint to an existing
table. The method will properly quote the table and column names.
Builds a SQL statement for adding a foreign key constraint to an existing
table. The method will properly quote the table and column names.
Parameters
- $name
string $name the name of the foreign key constraint.
- $table
string $table the table that the foreign key constraint will be added to.
- $columns
string|array $columns the name of the column to that the constraint will be added on. If
there are multiple columns, separate them with commas or pass as an array of
column names.
- $refTable
string $refTable the table that the foreign key references to.
- $refColumns
string|array $refColumns the name of the column that the foreign key references to. If there
are multiple columns, separate them with commas or pass as an array of column
names.
- $delete
string $delete the ON DELETE option. Most DBMS support these options: RESTRICT,
CASCADE, NO ACTION, SET DEFAULT, SET NULL
- $update
string $update the ON UPDATE option. Most DBMS support these options: RESTRICT,
CASCADE, NO ACTION, SET DEFAULT, SET NULL
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
dropForeignKey( string $name, string $table )
Builds a SQL statement for dropping a foreign key constraint.
Builds a SQL statement for dropping a foreign key constraint.
Parameters
- $name
string $name the name of the foreign key constraint to be dropped. The name will be
properly quoted by the method.
- $table
string $table the table whose foreign is to be dropped. The name will be properly
quoted by the method.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
createIndex( string $name, string $table, string|array $columns, boolean $unique = false )
Builds and executes a SQL statement for creating a new index.
Builds and executes a SQL statement for creating a new index.
Parameters
- $name
string $name the name of the index. The name will be properly quoted by the method.
- $table
string $table the table that the new index will be created for. The table name will be
properly quoted by the method.
- $columns
string|array $columns the column(s) that should be included in the index. If there are
multiple columns, please separate them by commas or pass as an array of column
names. Each column name will be properly quoted by the method, unless a
parenthesis is found in the name.
- $unique
boolean $unique whether to add UNIQUE constraint on the created index.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
dropIndex( string $name, string $table )
Builds and executes a SQL statement for dropping an index.
Builds and executes a SQL statement for dropping an index.
Parameters
- $name
string $name the name of the index to be dropped. The name will be properly quoted by
the method.
- $table
string $table the table whose index is to be dropped. The name will be properly quoted
by the method.
Returns
integer number of rows affected by the execution.
Since
1.1.6
|
public
integer
|
#
addPrimaryKey( string $name, string $table, string|array $columns )
Builds a SQL statement for creating a primary key constraint.
Builds a SQL statement for creating a primary key constraint.
Parameters
- $name
string $name the name of the primary key constraint to be created. The name will be
properly quoted by the method.
- $table
string $table the table who will be inheriting the primary key. The name will be
properly quoted by the method.
- $columns
string|array $columns comma separated string or array of columns that the primary key will
consist of. Array value can be passed since 1.1.14.
Returns
integer number of rows affected by the execution.
Since
1.1.13
|
public
integer
|
#
dropPrimaryKey( string $name, string $table )
Builds a SQL statement for dropping a primary key constraint.
Builds a SQL statement for dropping a primary key constraint.
Parameters
- $name
string $name the name of the primary key constraint to be dropped. The name will be
properly quoted by the method.
- $table
string $table the table that owns the primary key. The name will be properly quoted by
the method.
Returns
integer number of rows affected by the execution.
Since
1.1.13
|