0 follower

Interface Yiisoft\Db\QueryBuilder\QueryBuilderInterface

ExtendsYiisoft\Db\QueryBuilder\DDLQueryBuilderInterface, Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface, Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
Implemented byYiisoft\Db\QueryBuilder\AbstractQueryBuilder

Defines the common interface to be implemented by query builder classes.

A query builder is mainly responsible for creating SQL statements based on specifications given in a {@see \Yiisoft\Db\QueryBuilder\QueryInterface} object.

A query builder should also support creating SQL statements for DBMS-specific features such as creating indexes, adding foreign keys, etc. through the methods defined in {@see \Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface}, {@see \Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface} and {@see \Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface}.

Public Methods

Hide inherited methods

Method Description Defined By
addCheck() Creates an SQL command for adding a check constraint to an existing table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
addColumn() Builds an SQL statement for adding a new DB column. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
addCommentOnColumn() Builds an SQL command for adding comment to column. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
addCommentOnTable() Builds an SQL command for adding comment to the table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
addDefaultValue() Creates an SQL command for adding a default value constraint to an existing table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
addForeignKey() Builds an SQL statement for adding a foreign key constraint to an existing table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
addPrimaryKey() Builds an SQL statement for adding a primary key constraint to an existing table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
addUnique() Creates an SQL command for adding a unique constraint to an existing table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
alterColumn() Builds an SQL statement for changing the definition of a column. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
bindParam() Helper method to add $value to $params array using {@see PARAM_PREFIX}. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
build() Generates a SELECT SQL statement from a {@see Query} object. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildColumnDefinition() Builds column definition based on given column instance. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
buildColumns() Processes columns and quotes them if necessary. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildCondition() Parses the condition specification and generates the corresponding SQL expression. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildExpression() Builds given $expression. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildFor() Builds a SQL for FOR clause. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildFrom() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildGroupBy() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildHaving() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildJoin() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildLimit() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildOrderBy() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildOrderByAndLimit() Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildSelect() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildUnion() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildValue() Securely converts PHP values to their SQL representations with using bind parameters where necessary: - array values are converted to JSON or SQL array expressions; - bool values are converted to TRUE or FALSE or other DBMS-specific boolean representations; - float and int values are converted to their string representations; - null values are converted to NULL; - object values are converted to their SQL representation based on their type; - resource values are bound as LOB parameters; - closed resource throw an {@see InvalidArgumentException}; - string values are bound as string parameters; - other values are bound as parameters. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
buildWhere() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
buildWithQueries() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
checkIntegrity() Builds an SQL statement for enabling or disabling integrity check. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
createConditionFromArray() Transforms one condition defined in array format (as described in {@see Query::where()} to instance of {@see ConditionInterface}). Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
createIndex() Builds an SQL statement for creating a new index. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
createTable() Builds an SQL statement for creating a new DB table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
createView() Creates an SQL View. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
delete() Creates a DELETE SQL statement. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
dropCheck() Creates an SQL command for dropping a check constraint. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropColumn() Builds an SQL statement for dropping a DB column. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropCommentFromColumn() Builds an SQL command for dropping comment to column. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropCommentFromTable() Builds an SQL command for dropping comment to the table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropDefaultValue() Creates an SQL command for dropping a default value constraint. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropForeignKey() Builds an SQL statement for dropping a foreign key constraint. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropIndex() Builds an SQL statement for dropping an index. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropPrimaryKey() Builds an SQL statement for removing a primary key constraint to an existing table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropTable() Builds an SQL statement for dropping a DB table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropUnique() Creates an SQL command for dropping a unique constraint. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
dropView() Drops an SQL View. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
getColumnDefinitionBuilder() Returns the column definition builder for the current DBMS. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
getColumnFactory() Returns the column factory for creating column instances. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
getExpressionBuilder() Gets an object of {@see ExpressionBuilderInterface} that's suitable for $expression. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
getQuoter() Yiisoft\Db\QueryBuilder\QueryBuilderInterface
getServerInfo() Returns {@see ServerInfoInterface} instance that provides information about the database server. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
insert() Creates an INSERT SQL statement. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
insertBatch() Generates a batch INSERT SQL statement. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
insertReturningPks() Creates an INSERT SQL statement with returning inserted primary key values. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
isTypecastingEnabled() Returns whether type casting is enabled for the query builder. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
prepareParam() Converts a {@see Param} object to its SQL representation and quotes it if necessary. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
prepareValue() Converts a value to its SQL representation and quotes it if necessary. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
renameColumn() Builds an SQL statement for renaming a column. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
renameTable() Builds an SQL statement for renaming a DB table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
replacePlaceholders() Replaces placeholders in the SQL string with the corresponding values. Yiisoft\Db\QueryBuilder\QueryBuilderInterface
resetSequence() Creates an SQL statement for resetting the sequence value of a table's primary key. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
selectExists() Creates a SELECT EXISTS() SQL statement. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
setConditionClasses() Setter for {@see AbstractDQLQueryBuilder::conditionClasses} property. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
setExpressionBuilders() Setter for {@see AbstractDQLQueryBuilder::expressionBuilders} property. Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
setSeparator() Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface
truncateTable() Builds an SQL statement for truncating a DB table. Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface
update() Creates an UPDATE SQL statement. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
upsert() Creates an SQL statement to insert rows into a database table if they don't already exist (matching unique constraints), or update them if they do. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
upsertReturning() Creates an SQL statement to insert rows into a database table if they don't already exist (matching unique constraints), or update them if they do, with returning values from the specified columns. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface
withTypecasting() Clones the current instance and sets whether type casting is required for the query builder. Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface

Method Details

Hide inherited methods

addCheck() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addCheck()

Creates an SQL command for adding a check constraint to an existing table.

public abstract string addCheck ( string $table, string $name, string $expression )
$table string

The table to add the check constraint to.

$name string

The name of the check constraint.

$expression string

The SQL of the CHECK constraint.

return string

The SQL statement for adding a check constraint to an existing table.

Note: The method will quote the name and table parameters before using them in the generated SQL.

                public function addCheck(string $table, string $name, string $expression): string;

            
addColumn() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addColumn()

Builds an SQL statement for adding a new DB column.

public abstract string addColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type )
$table string

The table to add the new column will to.

$column string

The name of the new column.

$type Yiisoft\Db\Schema\Column\ColumnInterface|string

The column type which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions into SQL representation. For example, it will convert string not null to varchar(255) not null and pk to int PRIMARY KEY AUTO_INCREMENT (for MySQL).

The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

return string

The SQL statement for adding a new column.

Note: The method will quote the table and column parameters before using them in the generated SQL.

                public function addColumn(string $table, string $column, ColumnInterface|string $type): string;

            
addCommentOnColumn() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addCommentOnColumn()

Builds an SQL command for adding comment to column.

public abstract string addCommentOnColumn ( string $table, string $column, string $comment )
$table string

The table whose column to be comment.

$column string

The name of the column to comment.

$comment string

The text of the comment to add.

return string

The SQL statement for adding comment on column.

Note: The method will quote the table, column, and comment parameters before using them in the generated SQL.

throws Yiisoft\Db\Exception\Exception

                public function addCommentOnColumn(string $table, string $column, string $comment): string;

            
addCommentOnTable() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addCommentOnTable()

Builds an SQL command for adding comment to the table.

public abstract string addCommentOnTable ( string $table, string $comment )
$table string

The table whose column is to comment.

$comment string

The text of the comment to add.

return string

The SQL statement for adding comment on the table.

Note: The method will quote the table and comment parameters before using them in the generated SQL.

throws Yiisoft\Db\Exception\Exception

                public function addCommentOnTable(string $table, string $comment): string;

            
addDefaultValue() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addDefaultValue()

Creates an SQL command for adding a default value constraint to an existing table.

public abstract string addDefaultValue ( string $table, string $name, string $column, mixed $value )
$table string

The table toi add the default value constraint to.

$name string

The name of the default value constraint.

$column string

The name of the column to add constraint on.

$value mixed

The default value to set for the column.

return string

The SQL statement for adding a default value constraint to an existing table.

Note: The method will quote the name, table, and column parameters before using them in the generated SQL.

throws Yiisoft\Db\Exception\Exception
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

                public function addDefaultValue(string $table, string $name, string $column, mixed $value): string;

            
addForeignKey() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addForeignKey()

Builds an SQL statement for adding a foreign key constraint to an existing table.

The method will quote the name, table, referenceTable parameters before using them in the generated SQL.

public abstract string addForeignKey ( string $table, string $name, array|string $columns, string $referenceTable, array|string $referenceColumns, string|null $delete null, string|null $update null )
$table string

The table to add the foreign key constraint will to.

$name string

The name of the foreign key constraint.

$columns array|string

The name of the column to add the constraint will on. If there are many columns, separate them with commas or use an array to represent them.

$referenceTable string

The table that the foreign key references to.

$referenceColumns array|string

The name of the column that the foreign key references to. If there are many columns, separate them with commas or use an array to represent them.

$delete string|null

The ON DELETE option. See {@see \Yiisoft\Db\Constant\ReferentialAction} class for possible values.

$update string|null

The ON UPDATE option. See {@see \Yiisoft\Db\Constant\ReferentialAction} class for possible values.

return string

The SQL statement for adding a foreign key constraint to an existing table.

throws Yiisoft\Db\Exception\Exception
throws InvalidArgumentException

                public function addForeignKey(
    string $table,
    string $name,
    array|string $columns,
    string $referenceTable,
    array|string $referenceColumns,
    ?string $delete = null,
    ?string $update = null,
): string;

            
addPrimaryKey() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addPrimaryKey()

Builds an SQL statement for adding a primary key constraint to an existing table.

public abstract string addPrimaryKey ( string $table, string $name, string|string[] $columns )
$table string

The table to add the primary key constraint will to.

$name string

The name of the primary key constraint.

$columns string|string[]

Comma separated string or array of columns that the primary key will consist of.

return string

The SQL statement for adding a primary key constraint to an existing table.

Note: The method will quote the name, table, and column parameters before using them in the generated SQL.

                public function addPrimaryKey(string $table, string $name, array|string $columns): string;

            
addUnique() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::addUnique()

Creates an SQL command for adding a unique constraint to an existing table.

public abstract string addUnique ( string $table, string $name, string|string[] $columns )
$table string

The table to add the unique constraint to.

$name string

The name of the unique constraint.

$columns string|string[]

The name of the column to add the constraint on. If there are many columns, separate them with commas.

return string

The SQL statement for adding a unique constraint to an existing table.

Note: The method will quote the name, table, and column parameters before using them in the generated SQL.

                public function addUnique(string $table, string $name, array|string $columns): string;

            
alterColumn() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::alterColumn()

Builds an SQL statement for changing the definition of a column.

public abstract string alterColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type )
$table string

The table whose column is to change.

$column string

The name of the column to change.

$type Yiisoft\Db\Schema\Column\ColumnInterface|string

The column type which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions into SQL representation. For example, it will convert string not null to varchar(255) not null and pk to int PRIMARY KEY AUTO_INCREMENT (for MySQL).

The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

return string

The SQL statement for changing the definition of a column.

Note: The method will quote the table and column parameters before using them in the generated SQL.

                public function alterColumn(string $table, string $column, ColumnInterface|string $type): string;

            
bindParam() public abstract method

Helper method to add $value to $params array using {@see PARAM_PREFIX}.

public abstract string bindParam ( mixed $value, array &$params = [] )
$value mixed
$params array

Passed by reference.

return string

The placeholder name in $params array.

                public function bindParam(mixed $value, array &$params = []): string;

            
build() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::build()

Generates a SELECT SQL statement from a {@see Query} object.

public abstract array build ( Yiisoft\Db\Query\QueryInterface $query, array $params = [] )
$query Yiisoft\Db\Query\QueryInterface

The {@see \Yiisoft\Db\Query\Query} object from which the SQL statement will generated.

$params array

The parameters to bind to the generated SQL statement. These parameters will be included in the result, with the more parameters generated during the query building process.

return array

The generated SQL statement (the first array element) and the corresponding parameters to bind to the SQL statement (the second array element). The parameters returned include those provided in $params.

throws InvalidArgumentException
throws Yiisoft\Db\Exception\NotSupportedException

                public function build(QueryInterface $query, array $params = []): array;

            
buildColumnDefinition() public abstract method

Builds column definition based on given column instance.

public abstract string buildColumnDefinition ( Yiisoft\Db\Schema\Column\ColumnInterface|string $column )
$column Yiisoft\Db\Schema\Column\ColumnInterface|string

The column instance or string column definition which should be converted into a database string representation.

return string

The SQL column definition.

                public function buildColumnDefinition(ColumnInterface|string $column): string;

            
buildColumns() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildColumns()

Processes columns and quotes them if necessary.

It will join all columns into a string with comma as separators.

public abstract string buildColumns ( array|string $columns )
$columns array|string

The columns to process.

throws Yiisoft\Db\Exception\NotSupportedException

                public function buildColumns(array|string $columns): string;

            
buildCondition() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildCondition()

Parses the condition specification and generates the corresponding SQL expression.

public abstract string buildCondition ( array|Yiisoft\Db\Expression\ExpressionInterface|string|null $condition, array &$params = [] )
$condition array|Yiisoft\Db\Expression\ExpressionInterface|string|null

The condition specification. Please refer to {@see \Yiisoft\Db\Query\Query::where()} on how to specify a condition.

$params array

The binding parameters to populate.

throws InvalidArgumentException
throws Yiisoft\Db\Exception\NotSupportedException

                public function buildCondition(array|string|ExpressionInterface|null $condition, array &$params = []): string;

            
buildExpression() public abstract method
public abstract string buildExpression ( Yiisoft\Db\Expression\ExpressionInterface $expression, array &$params = [] )
$expression Yiisoft\Db\Expression\ExpressionInterface

The expression to build.

$params array

The parameters to bind to the generated SQL statement. These parameters will be included in the result with the more parameters generated during the expression building process.

return string

The SQL statement that won't be neither quoted nor encoded before passing to DBMS.

throws Yiisoft\Db\Exception\NotSupportedException

When $expression building isn't supported by the {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface} implementation.

                public function buildExpression(ExpressionInterface $expression, array &$params = []): string;

            
buildFor() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildFor()

Builds a SQL for FOR clause.

public abstract string buildFor ( array $values )
$values array

The value to build.

return string

The result SQL.

throws Yiisoft\Db\Exception\NotSupportedException

When the FOR clause is not supported.

                public function buildFor(array $values): string;

            
buildFrom() public abstract method
public abstract string buildFrom ( array $tables, array &$params )
$tables array

The tables to process.

$params array

The binding parameters to populate.

return string

The FROM clause built from {@see \Yiisoft\Db\Query\Query::from()}.

throws Yiisoft\Db\Exception\NotSupportedException

                public function buildFrom(array $tables, array &$params): string;

            
buildGroupBy() public abstract method
public abstract string buildGroupBy ( array $columns, array &$params = [] )
$columns array

The columns to group by. Each column can be a string representing a column name or an array representing a column specification. Please refer to {@see \Yiisoft\Db\Query\Query::groupBy()} on how to specify this parameter.

$params array

The binding parameters to populate.

return string

The GROUP BY clause

throws Yiisoft\Db\Exception\NotSupportedException

                public function buildGroupBy(array $columns, array &$params = []): string;

            
buildHaving() public abstract method
public abstract string buildHaving ( array|Yiisoft\Db\Expression\ExpressionInterface|string|null $condition, array &$params = [] )
$condition array|Yiisoft\Db\Expression\ExpressionInterface|string|null

The condition specification.

$params array

The binding parameters to populate.

return string

The HAVING clause built from {@see \Yiisoft\Db\Query\Query::having()}.

throws InvalidArgumentException
throws Yiisoft\Db\Exception\NotSupportedException

                public function buildHaving(array|ExpressionInterface|string|null $condition, array &$params = []): string;

            
buildJoin() public abstract method
public abstract string buildJoin ( array $joins, array &$params )
$joins array

The joins to process.

$params array

The binding parameters to populate.

return string

The JOIN clause built from {@see \Yiisoft\Db\Query\Query::join()}.

throws InvalidArgumentException

If the $joins parameter isn't in proper format.

throws Yiisoft\Db\Exception\NotSupportedException

                public function buildJoin(array $joins, array &$params): string;

            
buildLimit() public abstract method
public abstract string buildLimit ( Yiisoft\Db\Expression\ExpressionInterface|integer|null $limit, Yiisoft\Db\Expression\ExpressionInterface|integer|null $offset )
$limit Yiisoft\Db\Expression\ExpressionInterface|integer|null

The limit number.

$offset Yiisoft\Db\Expression\ExpressionInterface|integer|null

The offset number.

return string

The LIMIT and OFFSET clauses.

throws Yiisoft\Db\Exception\NotSupportedException

                public function buildLimit(ExpressionInterface|int|null $limit, ExpressionInterface|int|null $offset): string;

            
buildOrderBy() public abstract method
public abstract string buildOrderBy ( array $columns, array &$params = [] )
$columns array

The columns to order by. Each column can be a string representing a column name or an array representing a column specification. Please refer to {@see \Yiisoft\Db\Query\Query::orderBy()} on how to specify this parameter.

$params array

The binding parameters to populate.

return string

The ORDER BY clause built from {@see \Yiisoft\Db\Query\Query::orderBy()}.

throws Yiisoft\Db\Exception\NotSupportedException

                public function buildOrderBy(array $columns, array &$params = []): string;

            
buildOrderByAndLimit() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::buildOrderByAndLimit()

Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.

public abstract string buildOrderByAndLimit ( string $sql, array $orderBy, Yiisoft\Db\Expression\ExpressionInterface|integer|null $limit, Yiisoft\Db\Expression\ExpressionInterface|integer|null $offset, array &$params = [] )
$sql string

The existing SQL (without ORDER BY/LIMIT/OFFSET).

$orderBy array

The order by columns. {@see \Yiisoft\Db\Query\Query::orderBy()} for more details on how to specify this parameter.

$limit Yiisoft\Db\Expression\ExpressionInterface|integer|null

The limit number. {@see \Yiisoft\Db\Query\Query::limit()} For more details.

$offset Yiisoft\Db\Expression\ExpressionInterface|integer|null

The offset number. {@see \Yiisoft\Db\Query\Query::offset()} For more details.

$params array

The binding parameters to populate.

return string

The SQL completed with ORDER BY/LIMIT/OFFSET (if any).

throws Yiisoft\Db\Exception\NotSupportedException

                public function buildOrderByAndLimit(
    string $sql,
    array $orderBy,
    ExpressionInterface|int|null $limit,
    ExpressionInterface|int|null $offset,
    array &$params = [],
): string;

            
buildSelect() public abstract method
public abstract string buildSelect ( array $columns, array &$params, boolean $distinct false, string|null $selectOption null )
$columns array

The columns to select. Each column can be a string representing a column name or an array representing a column specification. Please refer to {@see \Yiisoft\Db\Query\Query::select()} on how to specify this parameter.

$params array

The binding parameters to populate.

$distinct boolean

Whether to add DISTINCT or not.

$selectOption string|null

The SELECT option to use (for example, SQL_CALC_FOUND_ROWS).

return string

The SELECT clause built from {@see \Yiisoft\Db\Query\Query::select()}.

throws InvalidArgumentException

                public function buildSelect(
    array $columns,
    array &$params,
    bool $distinct = false,
    ?string $selectOption = null,
): string;

            
buildUnion() public abstract method
public abstract string buildUnion ( array $unions, array &$params )
$unions array

The UNION queries to process.

$params array

The binding parameters to populate.

return string

The UNION clause built from {@see \Yiisoft\Db\Query\Query::union()}.

throws InvalidArgumentException
throws Yiisoft\Db\Exception\NotSupportedException

                public function buildUnion(array $unions, array &$params): string;

            
buildValue() public abstract method

Securely converts PHP values to their SQL representations with using bind parameters where necessary: - array values are converted to JSON or SQL array expressions; - bool values are converted to TRUE or FALSE or other DBMS-specific boolean representations; - float and int values are converted to their string representations; - null values are converted to NULL; - object values are converted to their SQL representation based on their type; - resource values are bound as LOB parameters; - closed resource throw an {@see InvalidArgumentException}; - string values are bound as string parameters; - other values are bound as parameters.

public abstract string buildValue ( mixed $value, array &$params )
$value mixed

The PHP value to be converted to SQL.

$params array

The parameters array to which the bound parameters will be added.

return string

The SQL representation of the value.

throws InvalidArgumentException

                public function buildValue(mixed $value, array &$params): string;

            
buildWhere() public abstract method
public abstract string buildWhere ( array|Yiisoft\Db\QueryBuilder\Condition\ConditionInterface|Yiisoft\Db\Expression\ExpressionInterface|string|null $condition, array &$params = [] )
$condition array|Yiisoft\Db\QueryBuilder\Condition\ConditionInterface|Yiisoft\Db\Expression\ExpressionInterface|string|null

The condition built from {@see \Yiisoft\Db\Query\Query::where()}.

$params array

The binding parameters to populate.

return string

The WHERE clause built from {@see \Yiisoft\Db\Query\Query::where()}.

throws InvalidArgumentException
throws Yiisoft\Db\Exception\NotSupportedException

                public function buildWhere(
    array|string|ConditionInterface|ExpressionInterface|null $condition,
    array &$params = [],
): string;

            
buildWithQueries() public abstract method
public abstract string buildWithQueries ( Yiisoft\Db\Query\WithQuery[] $withQueries, array &$params )
$withQueries Yiisoft\Db\Query\WithQuery[]

The WITH queries to process.

$params array

The binding parameters to populate.

return string

The WITH clause built from {@see \Yiisoft\Db\Query\Query::withQuery()}.

throws InvalidArgumentException
throws Yiisoft\Db\Exception\NotSupportedException

                public function buildWithQueries(array $withQueries, array &$params): string;

            
checkIntegrity() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::checkIntegrity()

Builds an SQL statement for enabling or disabling integrity check.

public abstract string checkIntegrity ( string $schema '', string $table '', boolean $check true )
$schema string

The schema of the tables. Defaults to empty string, meaning the current or default schema.

$table string

The table name. Defaults to empty string, meaning that no table will be changed.

$check boolean

Whether to turn on or off the integrity check.

return string

The SQL statement for checking integrity.

Note: The method will quote the table parameters before using them in the generated SQL.

throws Yiisoft\Db\Exception\Exception
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

                public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string;

            
createConditionFromArray() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::createConditionFromArray()

Transforms one condition defined in array format (as described in {@see Query::where()} to instance of {@see ConditionInterface}).

See also Yiisoft\Db\QueryBuilder\Condition\ConditionInterface According to conditions class map.

public abstract Yiisoft\Db\QueryBuilder\Condition\ConditionInterface createConditionFromArray ( array $condition )
$condition array

The condition in array format.

throws InvalidArgumentException

                public function createConditionFromArray(array $condition): ConditionInterface;

            
createIndex() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::createIndex()

Builds an SQL statement for creating a new index.

public abstract string createIndex ( string $table, string $name, array|string $columns, string|null $indexType null, string|null $indexMethod null )
$table string

The table to create the new index for.

$name string

The name of the index.

$columns array|string

The column(s) to include in the index. If there are many columns, separate them with commas or use an array to represent them.

$indexType string|null

The index type, UNIQUE or a DBMS specific index type or null by default. See {@see \Yiisoft\Db\Constant\IndexType} or driver specific IndexType class.

$indexMethod string|null

The index organization method, if supported by DBMS. See driver specific IndexMethod class.

return string

The SQL statement for creating a new index.

throws Yiisoft\Db\Exception\Exception
throws InvalidArgumentException

                public function createIndex(
    string $table,
    string $name,
    array|string $columns,
    ?string $indexType = null,
    ?string $indexMethod = null,
): string;

            
createTable() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::createTable()

Builds an 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 is the name of the column which will be properly quoted by the method, and definition is the type of the column which can contain a native database column type, {@see \Yiisoft\Db\QueryBuilder\ColumnType abstract} or {@see \Yiisoft\Db\QueryBuilder\PseudoType pseudo} type, or can be represented as instance of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

The {@see \Yiisoft\Db\QueryBuilder\QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions into SQL representation. For example, it will convert string not null to varchar(255) not null and pk to int PRIMARY KEY AUTO_INCREMENT (for MySQL).

The preferred way is to use {@see \Yiisoft\Db\QueryBuilder\ColumnBuilder} to generate column definitions as instances of {@see \Yiisoft\Db\Schema\Column\ColumnInterface}.

$this->createTable(
    'example_table',
    [
        'id' => ColumnBuilder::primaryKey(),
        'name' => ColumnBuilder::string(64)->notNull(),
        'type' => ColumnBuilder::integer()->notNull()->defaultValue(10),
        'description' => ColumnBuilder::text(),
        'rule_name' => ColumnBuilder::string(64),
        'data' => ColumnBuilder::text(),
        'created_at' => ColumnBuilder::datetime()->notNull(),
        'updated_at' => ColumnBuilder::datetime(),
    ],
);

If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly put into the generated SQL.

public abstract string createTable ( string $table, (Yiisoft\Db\Schema\Column\ColumnInterface|Yiisoft\Db\Expression\ExpressionInterface|string)[] $columns, string|null $options null )
$table string

The name of the table to create.

$columns (Yiisoft\Db\Schema\Column\ColumnInterface|Yiisoft\Db\Expression\ExpressionInterface|string)[]

The columns (name => definition) in the new table. The definition can be string, or {@see \Yiisoft\Db\Schema\Column\ColumnInterface} or {@see \Yiisoft\Db\Expression\ExpressionInterface} instance.

$options string|null

More SQL fragments to append to the generated SQL.

return string

The SQL statement for creating a new DB table.

Note: The method will quote the table and columns parameter before using it in the generated SQL.

                public function createTable(string $table, array $columns, ?string $options = null): string;

            
createView() public abstract method
public abstract string createView ( string $viewName, Yiisoft\Db\Query\QueryInterface|string $subQuery )
$viewName string

The name of the view to create.

$subQuery Yiisoft\Db\Query\QueryInterface|string

The select statement which defines the view. This can be either a string or a {@see \Yiisoft\Db\QueryBuilder\Query} object.

return string

The CREATE VIEW SQL statement. Note: The method will quote the viewName parameter before using it in the generated SQL.

throws Yiisoft\Db\Exception\InvalidConfigException
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

throws Yiisoft\Db\Exception\Exception

                public function createView(string $viewName, QueryInterface|string $subQuery): string;

            
delete() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::delete()

Creates a DELETE SQL statement.

For example,

$sql = $queryBuilder->delete('user', 'status = 0');
public abstract string delete ( string $table, array|string $condition, array &$params )
$table string

The table to delete the data from.

$condition array|string

The condition to put in the WHERE part. Please refer to {@see \Yiisoft\Db\QueryBuilder\Query::where()} On how to specify condition.

$params array

The binding parameters to change by this method to bind to DB command later.

return string

The DELETE SQL.

throws Yiisoft\Db\Exception\Exception
throws InvalidArgumentException
throws Yiisoft\Db\Exception\InvalidConfigException
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

                public function delete(string $table, array|string $condition, array &$params): string;

            
dropCheck() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropCheck()

Creates an SQL command for dropping a check constraint.

public abstract string dropCheck ( string $table, string $name )
$table string

The table whose check constraint is to drop.

$name string

The name of the check constraint to drop.

return string

The SQL statement for dropping a check constraint.

Note: The method will quote the name and table parameters before using them in the generated SQL.

                public function dropCheck(string $table, string $name): string;

            
dropColumn() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropColumn()

Builds an SQL statement for dropping a DB column.

public abstract string dropColumn ( string $table, string $column )
$table string

The table whose column is to drop.

$column string

The name of the column to drop.

return string

The SQL statement for dropping a DB column.

Note: The method will quote the table and column parameters before using them in the generated SQL.

                public function dropColumn(string $table, string $column): string;

            
dropCommentFromColumn() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropCommentFromColumn()

Builds an SQL command for dropping comment to column.

public abstract string dropCommentFromColumn ( string $table, string $column )
$table string

The table whose column is to comment.

$column string

The name of the column to comment.

return string

The SQL statement for dropping comment on column.

Note: The method will quote the table and column parameters before using them in the generated SQL.

                public function dropCommentFromColumn(string $table, string $column): string;

            
dropCommentFromTable() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropCommentFromTable()

Builds an SQL command for dropping comment to the table.

public abstract string dropCommentFromTable ( string $table )
$table string

The table whose column is to comment.

return string

The SQL statement for dropping comment on column.

Note: The method will quote the table parameter before using it in the generated SQL.

                public function dropCommentFromTable(string $table): string;

            
dropDefaultValue() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropDefaultValue()

Creates an SQL command for dropping a default value constraint.

public abstract string dropDefaultValue ( string $table, string $name )
$table string

The table whose default value constraint is to drop.

$name string

The name of the default value constraint to drop.

return string

The SQL statement for dropping a default value constraint.

Note: The method will quote the name and table parameters before using them in the generated SQL.

throws Yiisoft\Db\Exception\Exception
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

                public function dropDefaultValue(string $table, string $name): string;

            
dropForeignKey() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropForeignKey()

Builds an SQL statement for dropping a foreign key constraint.

public abstract string dropForeignKey ( string $table, string $name )
$table string

The table whose foreign is to drop.

$name string

The name of the foreign key constraint to drop.

return string

The SQL statement for dropping a foreign key constraint.

Note: The method will quote the name and table parameters before using them in the generated SQL.

                public function dropForeignKey(string $table, string $name): string;

            
dropIndex() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropIndex()

Builds an SQL statement for dropping an index.

public abstract string dropIndex ( string $table, string $name )
$table string

The table whose index is to drop.

$name string

The name of the index to drop.

return string

The SQL statement for dropping an index.

Note: The method will quote the name and table parameters before using them in the generated SQL.

                public function dropIndex(string $table, string $name): string;

            
dropPrimaryKey() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropPrimaryKey()

Builds an SQL statement for removing a primary key constraint to an existing table.

public abstract string dropPrimaryKey ( string $table, string $name )
$table string

The table to remove the primary key constraint from.

$name string

The name of the primary key constraint to remove.

return string

The SQL statement for removing a primary key constraint from an existing table.

Note: The method will quote the name and table parameters before using them in the generated SQL.

                public function dropPrimaryKey(string $table, string $name): string;

            
dropTable() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropTable()

Builds an SQL statement for dropping a DB table.

public abstract string dropTable ( string $table, boolean $ifExists false, boolean $cascade false )
$table string

The table to drop.

$ifExists boolean

Do not throw an error if the table does not exist.

$cascade boolean

Automatically drop objects that depend on the table.

return string

The SQL statement for dropping a DB table.

Note: The method will quote the table parameter before using it in the generated SQL.

                public function dropTable(string $table, bool $ifExists = false, bool $cascade = false): string;

            
dropUnique() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::dropUnique()

Creates an SQL command for dropping a unique constraint.

public abstract string dropUnique ( string $table, string $name )
$table string

The table whose unique constraint is to drop.

$name string

The name of the unique constraint to drop.

return string

The SQL statement for dropping an unique constraint.

Note: The method will quote the name and table parameters before using them in the generated SQL.

                public function dropUnique(string $table, string $name): string;

            
dropView() public abstract method
public abstract string dropView ( string $viewName )
$viewName string

The name of the view to drop.

return string

The DROP VIEW SQL statement.

Note: The method will quote the viewName parameter before using it in the generated SQL.

                public function dropView(string $viewName): string;

            
getColumnDefinitionBuilder() public abstract method

Returns the column definition builder for the current DBMS.

public abstract Yiisoft\Db\QueryBuilder\ColumnDefinitionBuilderInterface getColumnDefinitionBuilder ( )

                public function getColumnDefinitionBuilder(): ColumnDefinitionBuilderInterface;

            
getColumnFactory() public abstract method

Returns the column factory for creating column instances.

public abstract Yiisoft\Db\Schema\Column\ColumnFactoryInterface getColumnFactory ( )

                public function getColumnFactory(): ColumnFactoryInterface;

            
getExpressionBuilder() public abstract method

Gets an object of {@see ExpressionBuilderInterface} that's suitable for $expression.

Uses {@see \Yiisoft\Db\QueryBuilder\AbstractDQLQueryBuilder::expressionBuilders} an array to find a suitable builder class.

public abstract Yiisoft\Db\Expression\ExpressionBuilderInterface getExpressionBuilder ( Yiisoft\Db\Expression\ExpressionInterface $expression )
$expression Yiisoft\Db\Expression\ExpressionInterface

The expression to build.

throws Yiisoft\Db\Exception\NotSupportedException

When expression building isn't supported by this QueryBuilder.

                public function getExpressionBuilder(ExpressionInterface $expression): ExpressionBuilderInterface;

            
getQuoter() public abstract method

public abstract Yiisoft\Db\Schema\QuoterInterface getQuoter ( )
return Yiisoft\Db\Schema\QuoterInterface

The quoter instance.

                public function getQuoter(): QuoterInterface;

            
getServerInfo() public abstract method

Returns {@see ServerInfoInterface} instance that provides information about the database server.

public abstract Yiisoft\Db\Connection\ServerInfoInterface getServerInfo ( )

                public function getServerInfo(): ServerInfoInterface;

            
insert() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::insert()

Creates an INSERT SQL statement.

For example,

$sql = $queryBuilder->insert('user', [
    'name' => 'Sam',
    'age' => 30,
], $params);
public abstract string insert ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns, array &$params = [] )
$table string

The table to insert new rows into.

$columns array|Yiisoft\Db\Query\QueryInterface

The column data (name => value) to insert into the table or instance of {@see \Yiisoft\Db\QueryBuilder\Query} to perform INSERT INTO ... SELECT SQL statement. Passing of {@see \Yiisoft\Db\QueryBuilder\Query}.

$params array

The binding parameters that will be generated by this method. They should be bound to the DB command later.

return string

The INSERT SQL.

throws Yiisoft\Db\Exception\Exception
throws InvalidArgumentException
throws Yiisoft\Db\Exception\InvalidConfigException
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

                public function insert(string $table, array|QueryInterface $columns, array &$params = []): string;

            
insertBatch() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::insertBatch()

Generates a batch INSERT SQL statement.

For example,

$sql = $queryBuilder->insertBatch('user', [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
], ['name', 'age']);

or as associative arrays where the keys are column names

$queryBuilder->insertBatch('user', [
    ['name' => 'Tom', 'age' => 30],
    ['name' => 'Jane', 'age' => 20],
    ['name' => 'Linda', 'age' => 25],
]);
public abstract string insertBatch ( string $table, iterable $rows, string[] $columns = [], array &$params = [] )
$table string

The table to insert new rows into.

$rows iterable

The rows to batch-insert into the table.

$columns string[]

The column names of the table.

$params array

The binding parameters. This parameter exists.

return string

The batch INSERT SQL statement.

throws Yiisoft\Db\Exception\Exception
throws InvalidArgumentException

                public function insertBatch(string $table, iterable $rows, array $columns = [], array &$params = []): string;

            
insertReturningPks() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::insertReturningPks()

Creates an INSERT SQL statement with returning inserted primary key values.

public abstract string insertReturningPks ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns, array &$params = [] )
$table string

The table to insert new rows into.

$columns array|Yiisoft\Db\Query\QueryInterface

The column data (name => value) to insert into the table or instance of {@see \Yiisoft\Db\QueryBuilder\Query} to perform INSERT INTO ... SELECT SQL statement.

$params array

The binding parameters that will be generated by this method.

throws Yiisoft\Db\Exception\Exception
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

                public function insertReturningPks(string $table, array|QueryInterface $columns, array &$params = []): string;

            
isTypecastingEnabled() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::isTypecastingEnabled()

Returns whether type casting is enabled for the query builder.

See also withTypecasting().

public abstract boolean isTypecastingEnabled ( )

                public function isTypecastingEnabled(): bool;

            
prepareParam() public abstract method

Converts a {@see Param} object to its SQL representation and quotes it if necessary.

Used when the bind parameter cannot be used in the SQL query.

public abstract string prepareParam ( Yiisoft\Db\Expression\Value\Param $param )
$param Yiisoft\Db\Expression\Value\Param

                public function prepareParam(Param $param): string;

            
prepareValue() public abstract method

Converts a value to its SQL representation and quotes it if necessary.

Used when the bind parameter cannot be used in the SQL query.

public abstract string prepareValue ( mixed $value )
$value mixed

                public function prepareValue(mixed $value): string;

            
renameColumn() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::renameColumn()

Builds an SQL statement for renaming a column.

public abstract string renameColumn ( string $table, string $oldName, string $newName )
$table string

The table whose column is to rename.

$oldName string

The old name of the column.

$newName string

The new name of the column.

return string

The SQL statement for renaming a DB column.

Note: The method will quote the table, oldName and newName parameters before using them in the generated SQL.

                public function renameColumn(string $table, string $oldName, string $newName): string;

            
renameTable() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::renameTable()

Builds an SQL statement for renaming a DB table.

public abstract string renameTable ( string $oldName, string $newName )
$oldName string

The table to rename.

$newName string

The new table name.

return string

The SQL statement for renaming a DB table.

Note: The method will quote the oldName and newName parameters before using them in the generated SQL.

                public function renameTable(string $oldName, string $newName): string;

            
replacePlaceholders() public abstract method

Replaces placeholders in the SQL string with the corresponding values.

public abstract string replacePlaceholders ( string $sql, string[] $replacements )
$sql string

SQL expression where the placeholder should be replaced.

$replacements string[]

Replacements for placeholders with placeholder names as keys and values as follows:

  • quoted string values (name => value) use {@see \Yiisoft\Db\QueryBuilder\prepareValue()} to prepare the values;
  • new placeholder names prefixed with colon : (name => new name).
return string

SQL expression with replaced placeholders.

                public function replacePlaceholders(string $sql, array $replacements): string;

            
resetSequence() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::resetSequence()

Creates an SQL statement for resetting the sequence value of a table's primary key.

The sequence will be reset such that the primary key of the next new row inserted will have the specified value or 1.

public abstract string resetSequence ( string $table, integer|string|null $value null )
$table string

The name of the table whose primary key sequence will be reset.

$value integer|string|null

The value for the primary key of the next new row inserted. If this isn't set, the next new row's primary key will have value 1.

return string

The SQL statement for a resetting sequence.

Note: The method will escape the table and column names.

throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

throws Yiisoft\Db\Exception\Exception

                public function resetSequence(string $table, int|string|null $value = null): string;

            
selectExists() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::selectExists()

Creates a SELECT EXISTS() SQL statement.

public abstract string selectExists ( string $rawSql )
$rawSql string

The sub-query in a raw form to select from.

return string

The SELECT EXISTS() SQL statement.

                public function selectExists(string $rawSql): string;

            
setConditionClasses() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::setConditionClasses()

Setter for {@see AbstractDQLQueryBuilder::conditionClasses} property.

public abstract void setConditionClasses ( string[] $classes )
$classes string[]

Map of condition aliases to condition classes. For example:

['LIKE' => \Yiisoft\Db\Condition\LikeCondition::class]

                public function setConditionClasses(array $classes): void;

            
setExpressionBuilders() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DQLQueryBuilderInterface::setExpressionBuilders()

Setter for {@see AbstractDQLQueryBuilder::expressionBuilders} property.

public abstract void setExpressionBuilders ( string[] $builders )
$builders string[]

Array of builders to merge with the pre-defined ones in property.

                public function setExpressionBuilders(array $builders): void;

            
setSeparator() public abstract method
public abstract void setSeparator ( string $separator )
$separator string

The separator between different fragments of an SQL statement.

Defaults to an empty space. This is mainly used by {@see \Yiisoft\Db\QueryBuilder\build()} when generating a SQL statement.

                public function setSeparator(string $separator): void;

            
truncateTable() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface::truncateTable()

Builds an SQL statement for truncating a DB table.

public abstract string truncateTable ( string $table )
$table string

The table to truncate.

return string

The SQL statement for truncating a DB table.

Note: The method will quote the table parameter before using it in the generated SQL.

                public function truncateTable(string $table): string;

            
update() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::update()

Creates an UPDATE SQL statement.

For example,

$params = [];
$sql = $queryBuilder->update('user', ['status' => 1], 'age > 30', $params);
public abstract string update ( string $table, array $columns, array|Yiisoft\Db\Expression\ExpressionInterface|string $condition, array|Yiisoft\Db\Expression\ExpressionInterface|string|null $from null, array &$params = [] )
$table string

The table to update.

$columns array

The column data (name => value) to update the table.

$condition array|Yiisoft\Db\Expression\ExpressionInterface|string

The condition to put in the WHERE part. Please refer to {@see \Yiisoft\Db\QueryBuilder\QueryPartsInterface::where()} On how to specify condition.

$from array|Yiisoft\Db\Expression\ExpressionInterface|string|null

The FROM part. Please refer to {@see \Yiisoft\Db\QueryBuilder\QueryPartsInterface::from()} On how to specify FROM part.

$params array

The binding parameters that will be modified by this method so that they can be bound to DB command later.

return string

The UPDATE SQL.

throws Yiisoft\Db\Exception\Exception
throws InvalidArgumentException

                public function update(
    string $table,
    array $columns,
    array|ExpressionInterface|string $condition,
    array|ExpressionInterface|string|null $from = null,
    array &$params = [],
): string;

            
upsert() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::upsert()

Creates an SQL statement to insert rows into a database table if they don't already exist (matching unique constraints), or update them if they do.

For example,

$sql = $queryBuilder->upsert('pages', [
    'name' => 'Front page',
    'url' => 'http://example.com/', // url is unique
    'visits' => 0,
], [
    'visits' => new Expression('visits + 1'),
], $params);
public abstract string upsert ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns true, array &$params = [] )
$table string

The table to insert rows into or update new rows in.

$insertColumns array|Yiisoft\Db\Query\QueryInterface

The column data (name => value) to insert into the table or instance of {@see \Yiisoft\Db\QueryBuilder\Query} to perform INSERT INTO ... SELECT SQL statement.

$updateColumns array|boolean

The column data (name => value) to update if they already exist. If true is passed, the column data will be updated to match the insert column data. If false is passed, no update will be performed if the column data already exist.

$params array

The binding parameters that will be generated by this method. They should be bound to the DB command later.

throws Yiisoft\Db\Exception\Exception
throws Yiisoft\Db\Exception\InvalidConfigException
throws JsonException
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

                public function upsert(
    string $table,
    array|QueryInterface $insertColumns,
    array|bool $updateColumns = true,
    array &$params = [],
): string;

            
upsertReturning() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::upsertReturning()

Creates an SQL statement to insert rows into a database table if they don't already exist (matching unique constraints), or update them if they do, with returning values from the specified columns.

The method will quote the table, insertColumns, updateColumns and returnColumns parameters before using it in the generated SQL.

public abstract string upsertReturning ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns true, string[]|null $returnColumns null, array &$params = [] )
$table string

The table to insert rows into or update new rows in.

$insertColumns array|Yiisoft\Db\Query\QueryInterface

The column data (name => value) to insert into the table or instance of {@see \Yiisoft\Db\QueryBuilder\Query} to perform INSERT INTO ... SELECT SQL statement.

$updateColumns array|boolean

The column data (name => value) to update if they already exist. If true is passed, the column data will be updated to match the insert column data. If false is passed, no update will be performed if the column data already exist.

$returnColumns string[]|null

The column names to return values from. null means all columns.

$params array

The binding parameters that will be generated by this method. They should be bound to the DB command later.

throws Yiisoft\Db\Exception\Exception
throws Yiisoft\Db\Exception\InvalidConfigException
throws JsonException
throws Yiisoft\Db\Exception\NotSupportedException

If this isn't supported by the underlying DBMS.

                public function upsertReturning(
    string $table,
    array|QueryInterface $insertColumns,
    array|bool $updateColumns = true,
    ?array $returnColumns = null,
    array &$params = [],
): string;

            
withTypecasting() public abstract method

Defined in: Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface::withTypecasting()

Clones the current instance and sets whether type casting is required for the query builder.

See also isTypecastingEnabled().

public abstract Yiisoft\Db\QueryBuilder\QueryBuilderInterface withTypecasting ( boolean $typecasting true )
$typecasting boolean

Whether type casting is required. Defaults to true.

                public function withTypecasting(bool $typecasting = true): static;