Class craft\db\mysql\QueryBuilder
- Inheritance
- craft\db\mysql\QueryBuilder » yii\db\mysql\QueryBuilder » yii\db\QueryBuilder » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Available since version
- 3.0
- Source Code
- https://github.com/craftcms/cms/blob/master/src/db/mysql/QueryBuilder.php
Property | Type | Description | Defined By |
---|---|---|---|
$db |
yii\db\Connection | The database connection. | yii\db\QueryBuilder |
$separator |
string | The separator between different fragments of a SQL statement. | yii\db\QueryBuilder |
$typeMap |
array | Mapping from abstract column types (keys) to physical column types (values). | yii\db\mysql\QueryBuilder |
Property | Type | Description | Defined By |
---|---|---|---|
$conditionBuilders |
array | Map of query condition to builder methods. | yii\db\QueryBuilder |
$conditionClasses |
array | Map of condition aliases to condition classes. | yii\db\QueryBuilder |
$expressionBuilders |
string[], yii\db\ExpressionBuilderInterface | Maps expression class to expression builder class. | yii\db\QueryBuilder |
Method | Description | Defined By |
---|---|---|
__call() |
Calls the named method which is not a class method. | yii\base\BaseObject |
__construct() |
Constructor. | yii\base\BaseObject |
__get() |
Returns the value of an object property. | yii\base\BaseObject |
__isset() |
Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() |
Sets value of an object property. | yii\base\BaseObject |
__unset() |
Sets an object property to null. | yii\base\BaseObject |
addCheck() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
addColumn() |
Builds a SQL statement for adding a new DB column. | yii\db\QueryBuilder |
addCommentOnColumn() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
addCommentOnTable() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
addDefaultValue() |
Creates a SQL command for adding a default value constraint to an existing table. | yii\db\QueryBuilder |
addForeignKey() |
Builds a SQL statement for adding a foreign key constraint to an existing table. | yii\db\QueryBuilder |
addPrimaryKey() |
Builds a SQL statement for adding a primary key constraint to an existing table. | yii\db\QueryBuilder |
addUnique() |
Creates a SQL command for adding an unique constraint to an existing table. | yii\db\QueryBuilder |
alterColumn() |
Builds a SQL statement for changing the definition of a column. | yii\db\QueryBuilder |
batchInsert() |
Generates a batch INSERT SQL statement. | yii\db\QueryBuilder |
bindParam() |
Helper method to add $value to $params array using PARAM_PREFIX. | yii\db\QueryBuilder |
build() |
Generates a SELECT SQL statement from a yii\db\Query object. | yii\db\QueryBuilder |
buildAndCondition() |
Connects two or more SQL expressions with the AND or OR operator. |
yii\db\QueryBuilder |
buildBetweenCondition() |
Creates an SQL expressions with the BETWEEN operator. |
yii\db\QueryBuilder |
buildColumns() |
Processes columns and properly quotes them if necessary. | yii\db\QueryBuilder |
buildCondition() |
Parses the condition specification and generates the corresponding SQL expression. | yii\db\QueryBuilder |
buildExistsCondition() |
Creates an SQL expressions with the EXISTS operator. |
yii\db\QueryBuilder |
buildExpression() |
Builds given $expression | yii\db\QueryBuilder |
buildFrom() |
yii\db\QueryBuilder | |
buildGroupBy() |
yii\db\QueryBuilder | |
buildHashCondition() |
Creates a condition based on column-value pairs. | yii\db\QueryBuilder |
buildHaving() |
yii\db\QueryBuilder | |
buildInCondition() |
Creates an SQL expressions with the IN operator. |
yii\db\QueryBuilder |
buildJoin() |
yii\db\QueryBuilder | |
buildLikeCondition() |
Creates an SQL expressions with the LIKE operator. |
yii\db\QueryBuilder |
buildLimit() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
buildNotCondition() |
Inverts an SQL expressions with NOT operator. |
yii\db\QueryBuilder |
buildOrderBy() |
yii\db\QueryBuilder | |
buildOrderByAndLimit() |
Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL. | yii\db\QueryBuilder |
buildSelect() |
yii\db\QueryBuilder | |
buildSimpleCondition() |
Creates an SQL expressions like "column" operator value . |
yii\db\QueryBuilder |
buildUnion() |
yii\db\QueryBuilder | |
buildWhere() |
yii\db\QueryBuilder | |
canGetProperty() |
Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() |
Returns a value indicating whether a property can be set. | yii\base\BaseObject |
checkIntegrity() |
Builds a SQL statement for enabling or disabling integrity check. | yii\db\mysql\QueryBuilder |
className() |
Returns the fully qualified name of this class. | yii\base\BaseObject |
createConditionFromArray() |
Transforms $condition defined in array format (as described in yii\db\Query::where() to instance of \yii\db\yii\db\condition\ConditionInterface according to $conditionClasses map. | yii\db\QueryBuilder |
createIndex() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
createTable() |
Builds a SQL statement for creating a new DB table. | craft\db\mysql\QueryBuilder |
createView() |
Creates a SQL View. | yii\db\QueryBuilder |
delete() |
Creates a DELETE SQL statement. | yii\db\QueryBuilder |
dropCheck() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
dropColumn() |
Builds a SQL statement for dropping a DB column. | yii\db\QueryBuilder |
dropCommentFromColumn() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
dropCommentFromTable() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
dropDefaultValue() |
Creates a SQL command for dropping a default value constraint. | yii\db\QueryBuilder |
dropForeignKey() |
Builds a SQL statement for dropping a foreign key constraint. | yii\db\mysql\QueryBuilder |
dropIndex() |
Builds a SQL statement for dropping an index. | yii\db\QueryBuilder |
dropPrimaryKey() |
Builds a SQL statement for removing a primary key constraint to an existing table. | yii\db\mysql\QueryBuilder |
dropTable() |
Builds a SQL statement for dropping a DB table. | yii\db\QueryBuilder |
dropTableIfExists() |
Builds a SQL statement for dropping a DB table if it exists. | craft\db\mysql\QueryBuilder |
dropUnique() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
dropView() |
Drops a SQL View. | yii\db\QueryBuilder |
fixedOrder() |
Builds the SQL expression used to return a DB result in a fixed order. | craft\db\mysql\QueryBuilder |
getColumnType() |
Converts an abstract column type into a physical column type. | yii\db\QueryBuilder |
getExpressionBuilder() |
Gets object of yii\db\ExpressionBuilderInterface that is suitable for $expression. | yii\db\QueryBuilder |
hasMethod() |
Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() |
Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() |
{@inheritdoc} | craft\db\mysql\QueryBuilder |
insert() |
Creates an INSERT SQL statement. | yii\db\QueryBuilder |
renameColumn() |
Builds a SQL statement for renaming a column. | yii\db\mysql\QueryBuilder |
renameSequence() |
Builds a SQL statement for renaming a DB sequence. | craft\db\mysql\QueryBuilder |
renameTable() |
Builds a SQL statement for renaming a DB table. | yii\db\QueryBuilder |
replace() |
Builds a SQL statement for replacing some text with other text in a given table column. | craft\db\mysql\QueryBuilder |
resetSequence() |
Creates a SQL statement for resetting the sequence value of a table's primary key. | yii\db\mysql\QueryBuilder |
selectExists() |
Creates a SELECT EXISTS() SQL statement. | yii\db\QueryBuilder |
setConditionClasses() |
Setter for $conditionClasses property. | yii\db\QueryBuilder |
setExpressionBuilders() |
Setter for $expressionBuilders property. | yii\db\QueryBuilder |
truncateTable() |
Builds a SQL statement for truncating a DB table. | yii\db\QueryBuilder |
update() |
Creates an UPDATE SQL statement. | yii\db\QueryBuilder |
upsert() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
Method | Description | Defined By |
---|---|---|
defaultConditionClasses() |
Contains array of default condition classes. Extend this method, if you want to change default condition classes for the query builder. See $conditionClasses docs for details. | yii\db\QueryBuilder |
defaultExpressionBuilders() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
hasLimit() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
hasOffset() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
prepareInsertSelectSubQuery() |
Prepare select-subquery and field names for INSERT INTO . | yii\db\QueryBuilder |
prepareInsertValues() |
{@inheritdoc} | yii\db\mysql\QueryBuilder |
prepareUpdateSets() |
Prepares a SET parts for an UPDATE SQL statement. |
yii\db\QueryBuilder |
prepareUpsertColumns() |
yii\db\QueryBuilder |
Constant | Value | Description | Defined By |
---|---|---|---|
PARAM_PREFIX |
':qp' | The prefix for automatically generated query binding parameters. | yii\db\QueryBuilder |
Method Details
createTable()
public method
#
Builds 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.
For example,
$sql = $queryBuilder->createTable('user', [
'id' => 'pk',
'name' => 'string',
'age' => 'integer',
]);
public string createTable ( $table, $columns, $options = null )
$table |
string | The name of the table to be created. The name will be properly quoted by the method. |
$columns |
array | The columns (name => definition) in the new table. |
$options |
string, null | Additional SQL fragment that will be appended to the generated SQL. |
return | string | The SQL statement for creating a new DB table. |
---|
dropTableIfExists()
public method
#
Builds a SQL statement for dropping a DB table if it exists.
public string dropTableIfExists ( \craft\db\mysql\string $table )
$table |
string | The table to be dropped. The name will be properly quoted by the method. |
return | string | The SQL statement for dropping a DB table. |
---|
fixedOrder()
public method
#
Builds the SQL expression used to return a DB result in a fixed order.
public string fixedOrder ( \craft\db\mysql\string $column, array $values )
$column |
string | The column name that contains the values. |
$values |
array | The column values, in the order in which the rows should be returned in. |
return | string | The SQL expression. |
---|
init()
public method
#
{@inheritdoc}
public void init ( )
renameSequence()
public method
#
Builds a SQL statement for renaming a DB sequence.
public string renameSequence ( \craft\db\mysql\string $oldName, \craft\db\mysql\string $newName )
$oldName |
string | The sequence to be renamed. The name will be properly quoted by the method. |
$newName |
string | The new sequence name. The name will be properly quoted by the method. |
return | string | The SQL statement for renaming a DB table. |
---|---|---|
throws | yii\base\NotSupportedException |
replace()
public method
#
Builds a SQL statement for replacing some text with other text in a given table column.
public string replace ( \craft\db\mysql\string $table, \craft\db\mysql\string $column, \craft\db\mysql\string $find, \craft\db\mysql\string $replace, $condition, array &$params )
$table |
string | The table to be updated. |
$column |
string | The column to be searched. |
$find |
string | The text to be searched for. |
$replace |
string | The replacement text. |
$condition |
array, string | The condition that will be put in the WHERE part. Please refer to \craft\db\mysql\Query::where() on how to specify condition. |
$params |
array | The binding parameters that will be generated by this method. They should be bound to the DB command later. |
return | string | The SQL statement for replacing some text in a given table. |
---|