CDbCommandBuilder
CDbCommandBuilder provides basic methods to create query commands for tables.
Property Details
database connection.
the schema for this command builder.
Method Details
|
|
| $schema |
CDbSchema |
the schema for this command builder |
|
public string applyCondition(string $sql, string $condition)
|
| $sql |
string |
the SQL statement without WHERE clause |
| $condition |
string |
the WHERE clause (without WHERE keyword) |
| {return} |
string |
the altered SQL statement |
Alters the SQL to apply WHERE clause.
|
public string applyGroup(string $sql, string $group)
|
| $sql |
string |
SQL query string without GROUP BY. |
| $group |
string |
GROUP BY |
| {return} |
string |
SQL with GROUP BY. |
Alters the SQL to apply GROUP BY.
|
public string applyHaving(string $sql, string $having)
|
| $sql |
string |
SQL query string without HAVING |
| $having |
string |
HAVING |
| {return} |
string |
SQL with HAVING |
Alters the SQL to apply HAVING.
|
public string applyJoin(string $sql, string $join)
|
| $sql |
string |
the SQL statement to be altered |
| $join |
string |
the JOIN clause (starting with join type, such as INNER JOIN) |
| {return} |
string |
the altered SQL statement |
Alters the SQL to apply JOIN clause.
|
public string applyLimit(string $sql, integer $limit, integer $offset)
|
| $sql |
string |
SQL query string without LIMIT and OFFSET. |
| $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 |
Alters the SQL to apply LIMIT and OFFSET.
Default implementation is applicable for PostgreSQL, MySQL and SQLite.
|
public string applyOrder(string $sql, string $orderBy)
|
| $sql |
string |
SQL statement without ORDER BY. |
| $orderBy |
string |
column ordering |
| {return} |
string |
modified SQL applied with ORDER BY. |
Alters the SQL to apply ORDER BY.
public void bindValues( CDbCommand $command, array $values)
|
| $command |
CDbCommand |
database command |
| $values |
array |
values for binding (integer-indexed array for question mark placeholders, string-indexed array for named placeholders) |
Binds parameter values for an SQL command.
createColumnCriteria()
public CDbCriteria createColumnCriteria(mixed $table, array $columns, mixed $condition='', array $params=array (
), string $prefix=NULL)
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $columns |
array |
column values that should be matched in the query (name=>value) |
| $condition |
mixed |
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 |
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 |
column prefix (ended with dot). If null, it will be the table name |
| {return} |
CDbCriteria |
the created query criteria |
Creates a query criteria with the specified column values.
protected string createCompositeInCondition( CDbTableSchema $table, array $values, string $prefix)
|
| $table |
CDbTableSchema |
the table schema |
| $values |
array |
list of primary key values to be selected within |
| $prefix |
string |
column prefix (ended with dot) |
| {return} |
string |
the expression for selection |
Generates the expression for selecting rows with specified composite key values.
createCountCommand()
|
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $criteria |
CDbCriteria |
the query criteria |
| $alias |
string |
the alias name of the primary table. Defaults to 't'. |
| {return} |
CDbCommand |
query command. |
Creates a COUNT(*) command for a single table.
public CDbCriteria createCriteria(mixed $condition='', mixed $params=array (
))
|
| $condition |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $params |
mixed |
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. |
| {return} |
CDbCriteria |
the created query criteria |
Creates a query criteria.
createDeleteCommand()
Creates a DELETE command.
createFindCommand()
|
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $criteria |
CDbCriteria |
the query criteria |
| $alias |
string |
the alias name of the primary table. Defaults to 't'. |
| {return} |
CDbCommand |
query command. |
Creates a SELECT command for a single table.
|
public string createInCondition(mixed $table, mixed $columnName, array $values, string $prefix=NULL)
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $columnName |
mixed |
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 |
list of key values to be selected within |
| $prefix |
string |
column prefix (ended with dot). If null, it will be the table name |
| {return} |
string |
the expression for selection |
Generates the expression for selecting rows of specified primary key values.
createInsertCommand()
public CDbCommand createInsertCommand(mixed $table, array $data)
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $data |
array |
data to be inserted (column name=>column value). If a key is not a valid column name, the corresponding value will be ignored. |
| {return} |
CDbCommand |
insert command |
Creates an INSERT command.
|
public string createPkCondition(mixed $table, array $values, string $prefix=NULL)
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $values |
array |
list of primary key values to be selected within |
| $prefix |
string |
column prefix (ended with dot). If null, it will be the table name |
| {return} |
string |
the expression for selection |
Generates the expression for selecting rows of specified primary key values.
public CDbCriteria createPkCriteria(mixed $table, mixed $pk, mixed $condition='', array $params=array (
), string $prefix=NULL)
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $pk |
mixed |
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 |
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 |
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 |
column prefix (ended with dot). If null, it will be the table name |
| {return} |
CDbCriteria |
the created query criteria |
Creates a query criteria with the specified primary key.
|
public string createSearchCondition(mixed $table, array $columns, mixed $keywords, string $prefix=NULL, boolean $caseSensitive=true)
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $columns |
array |
list of column names for potential search condition. |
| $keywords |
mixed |
search keywords. This can be either a string with space-separated keywords or an array of keywords. |
| $prefix |
string |
optional column prefix (with dot at the end). If null, the table name will be used as the prefix. |
| $caseSensitive |
boolean |
whether the search is case-sensitive. Defaults to true. This parameter
has been available since version 1.0.4. |
| {return} |
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. |
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.
createSqlCommand()
public CDbCommand createSqlCommand(string $sql, array $params=array (
))
|
| $sql |
string |
the explicitly specified SQL statement |
| $params |
array |
parameters that will be bound to the SQL statement |
| {return} |
CDbCommand |
the created command |
Creates a command based on a given SQL statement.
createUpdateCommand()
|
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $data |
array |
list of columns to be updated (name=>value) |
| $criteria |
CDbCriteria |
the query criteria |
| {return} |
CDbCommand |
update command. |
Creates an UPDATE command.
createUpdateCounterCommand()
|
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| $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.
|
protected void ensureTable(mixed $table)
|
| $table |
mixed |
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. |
Checks if the parameter is a valid table schema.
If it is a string, the corresponding table schema will be retrieved.
|
public mixed getLastInsertID(mixed $table)
|
| $table |
mixed |
the table schema (CDbTableSchema) or the table name (string). |
| {return} |
mixed |
last insertion id. Null is returned if no sequence name. |
Returns the last insertion ID for the specified table.
|
|
| {return} |
CDbSchema |
the schema for this command builder. |
createUpdateCounterCommand() method has wrong params description:
$counters CDbCriteria the query criteria $criteria array counters to be updated (counter increments/decrements indexed by column names.)
Should be:
$counters array counters to be updated (counter increments/decrements indexed by column names.) $criteria CDbCriteria the query criteria
I think it is wrong generated from PHPDoc (params order in description doesn't match params order in function)