Abstract Class Yiisoft\Db\Command\AbstractCommand
| Inheritance | Yiisoft\Db\Command\AbstractCommand |
|---|---|
| Implements | Yiisoft\Db\Command\CommandInterface |
| Subclasses | Yiisoft\Db\Driver\Pdo\AbstractPdoCommand |
Represents an SQL statement to execute in a database.
It's usually created by calling {@see \Yiisoft\Db\Connection\ConnectionInterface::createCommand()}.
You can get the SQL statement it represents via the {@see \Yiisoft\Db\Command\getSql()} method.
To execute a non-query SQL (such as INSERT, DELETE, UPDATE), call {@see \Yiisoft\Db\Command\execute()}.
To execute a SQL statement that returns a result (such as SELECT), use {@see \Yiisoft\Db\Command\queryAll()}, {@see \Yiisoft\Db\Command\queryOne()},
{@see \Yiisoft\Db\Command\queryColumn()}, {@see \Yiisoft\Db\Command\queryScalar()}, or {@see \Yiisoft\Db\Command\query()}.
For example,
$users = $connectionInterface->createCommand('SELECT * FROM user')->queryAll();
Abstract command supports SQL prepared statements and parameter binding.
Call {@see \Yiisoft\Db\Command\bindValue()} to bind a value to a SQL parameter. Call {@see \Yiisoft\Db\Command\bindParam()} to bind a PHP variable to a SQL parameter.
When binding a parameter, the SQL statement is automatically prepared. You may also call {@see \Yiisoft\Db\Command\prepare()} explicitly to do it.
Abstract command supports building some SQL statements using methods such as {@see \Yiisoft\Db\Command\insert()}, {@see \Yiisoft\Db\Command\update()}, {@see \Yiisoft\Db\Command\delete()}, etc.
For example, the following code will create and execute an INSERT SQL statement:
$connectionInterface->createCommand()->insert(
'user',
['name' => 'Sam', 'age' => 30],
)->execute();
To build SELECT SQL statements, please use {@see \Yiisoft\Db\Query\QueryInterface} and its implementations instead.
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $db | Yiisoft\Db\Connection\ConnectionInterface | Yiisoft\Db\Command\AbstractCommand | |
| $dbTypecasting | boolean | Yiisoft\Db\Command\AbstractCommand | |
| $params | Yiisoft\Db\Expression\Value\Param[] | Parameters to use. | Yiisoft\Db\Command\AbstractCommand |
| $phpTypecasting | boolean | Yiisoft\Db\Command\AbstractCommand | |
| $refreshTableName | string|null | Name of the table to refresh schema for. | Yiisoft\Db\Command\AbstractCommand |
| $retryHandler | Closure|null | Yiisoft\Db\Command\AbstractCommand |
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| getQueryBuilder() | Yiisoft\Db\Command\AbstractCommand | |
| internalExecute() | Executes a prepared statement. | Yiisoft\Db\Command\AbstractCommand |
| internalGetQueryResult() | Returns the query result. | Yiisoft\Db\Command\AbstractCommand |
| is() | Check if the value has a given flag. | Yiisoft\Db\Command\AbstractCommand |
| queryInternal() | The method is called after the query is executed. | Yiisoft\Db\Command\AbstractCommand |
| requireTableSchemaRefresh() | Marks a specified table schema to be refreshed after command execution. | Yiisoft\Db\Command\AbstractCommand |
| reset() | Resets the command object, so it can be reused to build another SQL statement. | Yiisoft\Db\Command\AbstractCommand |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| QUERY_MODE_ALL | 4 | Command in this query mode returns all rows of selected data. | Yiisoft\Db\Command\AbstractCommand |
| QUERY_MODE_COLUMN | 8 | Command in this query mode returns all rows with the first column of selected data. | Yiisoft\Db\Command\AbstractCommand |
| QUERY_MODE_CURSOR | 16 | Command in this query mode returns {@see DataReaderInterface}, an abstraction for database cursor for selected data. | Yiisoft\Db\Command\AbstractCommand |
| QUERY_MODE_EXECUTE | 1 | Command in this query mode returns count of affected rows. | Yiisoft\Db\Command\AbstractCommand |
| QUERY_MODE_ROW | 2 | Command in this query mode returns the first row of selected data. | Yiisoft\Db\Command\AbstractCommand |
| QUERY_MODE_SCALAR | 32 | Command in this query mode returns the first column in the first row of the query result | Yiisoft\Db\Command\AbstractCommand |
Property Details
Parameters to use.
Name of the table to refresh schema for. Null means not to refresh the schema.
Method Details
| public mixed __construct ( Yiisoft\Db\Connection\ConnectionInterface $db ) | ||
| $db | Yiisoft\Db\Connection\ConnectionInterface |
The database connection to use. |
public function __construct(
protected readonly ConnectionInterface $db,
) {}
| public Yiisoft\Db\Command\AbstractCommand addCheck ( string $table, string $name, string $expression ) | ||
| $table | string | |
| $name | string | |
| $expression | string | |
public function addCheck(string $table, string $name, string $expression): static
{
$sql = $this->getQueryBuilder()->addCheck($table, $name, $expression);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand addColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type ) | ||
| $table | string | |
| $column | string | |
| $type | Yiisoft\Db\Schema\Column\ColumnInterface|string | |
public function addColumn(string $table, string $column, ColumnInterface|string $type): static
{
$sql = $this->getQueryBuilder()->addColumn($table, $column, $type);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand addCommentOnColumn ( string $table, string $column, string $comment ) | ||
| $table | string | |
| $column | string | |
| $comment | string | |
public function addCommentOnColumn(string $table, string $column, string $comment): static
{
$sql = $this->getQueryBuilder()->addCommentOnColumn($table, $column, $comment);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand addCommentOnTable ( string $table, string $comment ) | ||
| $table | string | |
| $comment | string | |
public function addCommentOnTable(string $table, string $comment): static
{
$sql = $this->getQueryBuilder()->addCommentOnTable($table, $comment);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand addDefaultValue ( string $table, string $name, string $column, mixed $value ) | ||
| $table | string | |
| $name | string | |
| $column | string | |
| $value | mixed | |
public function addDefaultValue(string $table, string $name, string $column, mixed $value): static
{
$sql = $this->getQueryBuilder()->addDefaultValue($table, $name, $column, $value);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand addForeignKey ( string $table, string $name, array|string $columns, string $referenceTable, array|string $referenceColumns, string|null $delete = null, string|null $update = null ) | ||
| $table | string | |
| $name | string | |
| $columns | array|string | |
| $referenceTable | string | |
| $referenceColumns | array|string | |
| $delete | string|null | |
| $update | string|null | |
public function addForeignKey(
string $table,
string $name,
array|string $columns,
string $referenceTable,
array|string $referenceColumns,
?string $delete = null,
?string $update = null,
): static {
$sql = $this->getQueryBuilder()->addForeignKey(
$table,
$name,
$columns,
$referenceTable,
$referenceColumns,
$delete,
$update,
);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand addPrimaryKey ( string $table, string $name, array|string $columns ) | ||
| $table | string | |
| $name | string | |
| $columns | array|string | |
public function addPrimaryKey(string $table, string $name, array|string $columns): static
{
$sql = $this->getQueryBuilder()->addPrimaryKey($table, $name, $columns);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand addUnique ( string $table, string $name, array|string $columns ) | ||
| $table | string | |
| $name | string | |
| $columns | array|string | |
public function addUnique(string $table, string $name, array|string $columns): static
{
$sql = $this->getQueryBuilder()->addUnique($table, $name, $columns);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand alterColumn ( string $table, string $column, Yiisoft\Db\Schema\Column\ColumnInterface|string $type ) | ||
| $table | string | |
| $column | string | |
| $type | Yiisoft\Db\Schema\Column\ColumnInterface|string | |
public function alterColumn(string $table, string $column, ColumnInterface|string $type): static
{
$sql = $this->getQueryBuilder()->alterColumn($table, $column, $type);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
Defined in: Yiisoft\Db\Command\CommandInterface::bindParam()
Binds a parameter to the SQL statement to be executed.
| public abstract Yiisoft\Db\Command\AbstractCommand bindParam ( integer|string $name, mixed &$value, integer|null $dataType = null, integer|null $length = null, mixed|null $driverOptions = null ) | ||
| $name | integer|string |
The parameter identifier. For a prepared statement using named placeholders, this will be
a parameter name of the form |
| $value | mixed |
The PHP variable to bind to the SQL statement parameter (passed by reference). |
| $dataType | integer|null |
The {@see \Yiisoft\Db\Constant\DataType SQL data type} of the parameter. If |
| $length | integer|null |
The length of the data type. |
| $driverOptions | mixed|null |
The driver-specific options. |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
public function bindParam(
int|string $name,
mixed &$value,
?int $dataType = null,
?int $length = null,
mixed $driverOptions = null,
): static;
| public abstract Yiisoft\Db\Command\AbstractCommand bindValue ( integer|string $name, mixed $value, integer|null $dataType = null ) | ||
| $name | integer|string | |
| $value | mixed | |
| $dataType | integer|null | |
abstract public function bindValue(int|string $name, mixed $value, ?int $dataType = null): static;
| public abstract Yiisoft\Db\Command\AbstractCommand bindValues ( array $values ) | ||
| $values | array | |
abstract public function bindValues(array $values): static;
Defined in: Yiisoft\Db\Command\CommandInterface::cancel()
Cancels the execution of the SQL statement.
| public abstract void cancel ( ) |
public function cancel(): void;
| public Yiisoft\Db\Command\AbstractCommand checkIntegrity ( string $schema, string $table, boolean $check = true ) | ||
| $schema | string | |
| $table | string | |
| $check | boolean | |
public function checkIntegrity(string $schema, string $table, bool $check = true): static
{
$sql = $this->getQueryBuilder()->checkIntegrity($schema, $table, $check);
return $this->setSql($sql);
}
| public Yiisoft\Db\Command\AbstractCommand createIndex ( string $table, string $name, array|string $columns, string|null $indexType = null, string|null $indexMethod = null ) | ||
| $table | string | |
| $name | string | |
| $columns | array|string | |
| $indexType | string|null | |
| $indexMethod | string|null | |
public function createIndex(
string $table,
string $name,
array|string $columns,
?string $indexType = null,
?string $indexMethod = null,
): static {
$sql = $this->getQueryBuilder()->createIndex($table, $name, $columns, $indexType, $indexMethod);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand createTable ( string $table, array $columns, string|null $options = null ) | ||
| $table | string | |
| $columns | array | |
| $options | string|null | |
public function createTable(string $table, array $columns, ?string $options = null): static
{
$sql = $this->getQueryBuilder()->createTable($table, $columns, $options);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand createView ( string $viewName, Yiisoft\Db\Query\QueryInterface|string $subQuery ) | ||
| $viewName | string | |
| $subQuery | Yiisoft\Db\Query\QueryInterface|string | |
public function createView(string $viewName, QueryInterface|string $subQuery): static
{
$sql = $this->getQueryBuilder()->createView($viewName, $subQuery);
return $this->setSql($sql)->requireTableSchemaRefresh($viewName);
}
| public Yiisoft\Db\Command\AbstractCommand delete ( string $table, array|string $condition = '', array $params = [] ) | ||
| $table | string | |
| $condition | array|string | |
| $params | array | |
public function delete(string $table, array|string $condition = '', array $params = []): static
{
$sql = $this->getQueryBuilder()->delete($table, $condition, $params);
return $this->setSql($sql)->bindValues($params);
}
| public Yiisoft\Db\Command\AbstractCommand dropCheck ( string $table, string $name ) | ||
| $table | string | |
| $name | string | |
public function dropCheck(string $table, string $name): static
{
$sql = $this->getQueryBuilder()->dropCheck($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropColumn ( string $table, string $column ) | ||
| $table | string | |
| $column | string | |
public function dropColumn(string $table, string $column): static
{
$sql = $this->getQueryBuilder()->dropColumn($table, $column);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropCommentFromColumn ( string $table, string $column ) | ||
| $table | string | |
| $column | string | |
public function dropCommentFromColumn(string $table, string $column): static
{
$sql = $this->getQueryBuilder()->dropCommentFromColumn($table, $column);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropCommentFromTable ( string $table ) | ||
| $table | string | |
public function dropCommentFromTable(string $table): static
{
$sql = $this->getQueryBuilder()->dropCommentFromTable($table);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropDefaultValue ( string $table, string $name ) | ||
| $table | string | |
| $name | string | |
public function dropDefaultValue(string $table, string $name): static
{
$sql = $this->getQueryBuilder()->dropDefaultValue($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropForeignKey ( string $table, string $name ) | ||
| $table | string | |
| $name | string | |
public function dropForeignKey(string $table, string $name): static
{
$sql = $this->getQueryBuilder()->dropForeignKey($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropIndex ( string $table, string $name ) | ||
| $table | string | |
| $name | string | |
public function dropIndex(string $table, string $name): static
{
$sql = $this->getQueryBuilder()->dropIndex($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropPrimaryKey ( string $table, string $name ) | ||
| $table | string | |
| $name | string | |
public function dropPrimaryKey(string $table, string $name): static
{
$sql = $this->getQueryBuilder()->dropPrimaryKey($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropTable ( string $table, boolean $ifExists = false, boolean $cascade = false ) | ||
| $table | string | |
| $ifExists | boolean | |
| $cascade | boolean | |
public function dropTable(string $table, bool $ifExists = false, bool $cascade = false): static
{
$sql = $this->getQueryBuilder()->dropTable($table, $ifExists, $cascade);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropUnique ( string $table, string $name ) | ||
| $table | string | |
| $name | string | |
public function dropUnique(string $table, string $name): static
{
$sql = $this->getQueryBuilder()->dropUnique($table, $name);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand dropView ( string $viewName ) | ||
| $viewName | string | |
public function dropView(string $viewName): static
{
$sql = $this->getQueryBuilder()->dropView($viewName);
return $this->setSql($sql)->requireTableSchemaRefresh($viewName);
}
| public integer execute ( ) |
public function execute(): int
{
$sql = $this->getSql();
if ($sql === '') {
return 0;
}
/** @var bool|int $execute */
$execute = $this->queryInternal(self::QUERY_MODE_EXECUTE);
return is_int($execute) ? $execute : 0;
}
| public array getParams ( boolean $asValues = true ) | ||
| $asValues | boolean | |
public function getParams(bool $asValues = true): array
{
if (!$asValues) {
return $this->params;
}
$buildParams = [];
foreach ($this->params as $name => $value) {
$buildParams[$name] = $value->value;
}
return $buildParams;
}
| protected abstract Yiisoft\Db\QueryBuilder\QueryBuilderInterface getQueryBuilder ( ) | ||
| return | Yiisoft\Db\QueryBuilder\QueryBuilderInterface |
The query builder instance. |
|---|---|---|
abstract protected function getQueryBuilder(): QueryBuilderInterface;
| public string getRawSql ( ) |
public function getRawSql(): string
{
if (empty($this->params)) {
return $this->sql;
}
$queryBuilder = $this->getQueryBuilder();
$params = array_map($queryBuilder->prepareParam(...), $this->params);
if (!isset($params[0])) {
return $queryBuilder->replacePlaceholders($this->sql, $params);
}
// Support unnamed placeholders should be dropped
$sql = '';
foreach (explode('?', $this->sql) as $i => $part) {
$sql .= $part . ($params[$i] ?? '');
}
return $sql;
}
| public Yiisoft\Db\Command\AbstractCommand insert ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns ) | ||
| $table | string | |
| $columns | array|Yiisoft\Db\Query\QueryInterface | |
public function insert(string $table, array|QueryInterface $columns): static
{
$params = [];
$sql = $this->getQueryBuilder()->insert($table, $columns, $params);
return $this->setSql($sql)->bindValues($params);
}
| public Yiisoft\Db\Command\AbstractCommand insertBatch ( string $table, iterable $rows, array $columns = [] ) | ||
| $table | string | |
| $rows | iterable | |
| $columns | array | |
public function insertBatch(string $table, iterable $rows, array $columns = []): static
{
$table = $this->getQueryBuilder()->getQuoter()->getRawTableName($table);
$params = [];
$sql = $this->getQueryBuilder()->insertBatch($table, $rows, $columns, $params);
$this->setRawSql($sql);
$this->bindValues($params);
return $this;
}
| public array insertReturningPks ( string $table, array|Yiisoft\Db\Query\QueryInterface $columns ) | ||
| $table | string | |
| $columns | array|Yiisoft\Db\Query\QueryInterface | |
public function insertReturningPks(string $table, array|QueryInterface $columns): array
{
if (empty($this->db->getSchema()->getTableSchema($table)?->getPrimaryKey())) {
$this->insert($table, $columns)->execute();
return [];
}
$params = [];
$sql = $this->getQueryBuilder()->insertReturningPks($table, $columns, $params);
$this->setSql($sql)->bindValues($params);
/** @psalm-var array<string, mixed> */
return $this->queryInternal(self::QUERY_MODE_ROW | self::QUERY_MODE_EXECUTE);
}
Executes a prepared statement.
| protected abstract void internalExecute ( ) | ||
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Throwable | |
abstract protected function internalExecute(): void;
Returns the query result.
| protected abstract mixed internalGetQueryResult ( integer $queryMode ) | ||
| $queryMode | integer |
Query mode, |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Throwable | |
abstract protected function internalGetQueryResult(int $queryMode): mixed;
Check if the value has a given flag.
| protected boolean is ( integer $value, integer $flag ) | ||
| $value | integer |
Flags value to check. |
| $flag | integer |
Flag to look for in the value. |
| return | boolean |
Whether the value has a given flag. |
|---|---|---|
protected function is(int $value, int $flag): bool
{
return ($value & $flag) === $flag;
}
Defined in: Yiisoft\Db\Command\CommandInterface::prepare()
Prepares the SQL statement to be executed.
For complex SQL statement that's to be executed many times, this may improve performance.
For SQL statement with binding parameters, this method is invoked automatically.
| public abstract void prepare ( boolean|null $forRead = null ) | ||
| $forRead | boolean|null |
Whether the method call is for a read query. If null, it means the SQL statement should be used to decide whether it's to read or write. |
| throws | Yiisoft\Db\Exception\Exception |
If there is any DB error. |
|---|---|---|
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
public function prepare(?bool $forRead = null): void;
| public Yiisoft\Db\Query\DataReaderInterface query ( ) |
public function query(): DataReaderInterface
{
/** @var DataReaderInterface */
return $this->queryInternal(self::QUERY_MODE_CURSOR);
}
| public array queryAll ( ) |
public function queryAll(): array
{
/** @psalm-var list<array>|null $results */
$results = $this->queryInternal(self::QUERY_MODE_ALL);
return $results ?? [];
}
| public array queryColumn ( ) |
public function queryColumn(): array
{
$results = $this->queryInternal(self::QUERY_MODE_COLUMN);
return is_array($results) ? $results : [];
}
The method is called after the query is executed.
| protected mixed queryInternal ( integer $queryMode ) | ||
| $queryMode | integer |
Query mode, |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | Throwable | |
protected function queryInternal(int $queryMode): mixed
{
$isReadMode = $this->isReadMode($queryMode);
$this->prepare($isReadMode);
$this->internalExecute();
$result = $this->internalGetQueryResult($queryMode);
if ($isReadMode) {
return $result;
}
if ($this->refreshTableName !== null) {
$this->db->getSchema()->refreshTableSchema($this->refreshTableName);
}
return $result;
}
| public array|null queryOne ( ) |
public function queryOne(): ?array
{
/** @psalm-var array<string,mixed>|false $results */
$results = $this->queryInternal(self::QUERY_MODE_ROW);
return is_array($results) ? $results : null;
}
| public boolean|string|integer|float|null queryScalar ( ) |
public function queryScalar(): bool|string|int|float|null
{
$result = $this->queryInternal(self::QUERY_MODE_SCALAR);
if (is_resource($result) && get_resource_type($result) === 'stream') {
return stream_get_contents($result);
}
return is_scalar($result) ? $result : null;
}
| public Yiisoft\Db\Command\AbstractCommand renameColumn ( string $table, string $oldName, string $newName ) | ||
| $table | string | |
| $oldName | string | |
| $newName | string | |
public function renameColumn(string $table, string $oldName, string $newName): static
{
$sql = $this->getQueryBuilder()->renameColumn($table, $oldName, $newName);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
| public Yiisoft\Db\Command\AbstractCommand renameTable ( string $table, string $newName ) | ||
| $table | string | |
| $newName | string | |
public function renameTable(string $table, string $newName): static
{
$sql = $this->getQueryBuilder()->renameTable($table, $newName);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}
Marks a specified table schema to be refreshed after command execution.
| protected Yiisoft\Db\Command\AbstractCommand requireTableSchemaRefresh ( string $name ) | ||
| $name | string |
Name of the table, which schema should be refreshed. |
protected function requireTableSchemaRefresh(string $name): static
{
$this->refreshTableName = $name;
return $this;
}
Resets the command object, so it can be reused to build another SQL statement.
| protected void reset ( ) |
protected function reset(): void
{
$this->sql = '';
$this->params = [];
$this->refreshTableName = null;
}
| public Yiisoft\Db\Command\AbstractCommand resetSequence ( string $table, integer|string|null $value = null ) | ||
| $table | string | |
| $value | integer|string|null | |
public function resetSequence(string $table, int|string|null $value = null): static
{
$sql = $this->getQueryBuilder()->resetSequence($table, $value);
return $this->setSql($sql);
}
| public Yiisoft\Db\Command\AbstractCommand setRawSql ( string $sql ) | ||
| $sql | string | |
public function setRawSql(string $sql): static
{
if ($sql !== $this->sql) {
$this->cancel();
$this->reset();
$this->sql = $sql;
}
return $this;
}
| public Yiisoft\Db\Command\AbstractCommand setRetryHandler ( Closure|null $handler ) | ||
| $handler | Closure|null | |
public function setRetryHandler(?Closure $handler): static
{
$this->retryHandler = $handler;
return $this;
}
| public Yiisoft\Db\Command\AbstractCommand setSql ( string $sql ) | ||
| $sql | string | |
public function setSql(string $sql): static
{
$this->cancel();
$this->reset();
$this->sql = $this->getQueryBuilder()->getQuoter()->quoteSql($sql);
return $this;
}
Defined in: Yiisoft\Db\Command\CommandInterface::showDatabases()
List all database names in the current connection.
| public abstract array showDatabases ( ) |
public function showDatabases(): array;
| public Yiisoft\Db\Command\AbstractCommand truncateTable ( string $table ) | ||
| $table | string | |
public function truncateTable(string $table): static
{
$sql = $this->getQueryBuilder()->truncateTable($table);
return $this->setSql($sql);
}
| public Yiisoft\Db\Command\AbstractCommand 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 | |
| $columns | array | |
| $condition | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $from | array|Yiisoft\Db\Expression\ExpressionInterface|string|null | |
| $params | array | |
public function update(
string $table,
array $columns,
array|ExpressionInterface|string $condition = '',
array|ExpressionInterface|string|null $from = null,
array $params = [],
): static {
$sql = $this->getQueryBuilder()->update($table, $columns, $condition, $from, $params);
return $this->setSql($sql)->bindValues($params);
}
| public Yiisoft\Db\Command\AbstractCommand upsert ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true ) | ||
| $table | string | |
| $insertColumns | array|Yiisoft\Db\Query\QueryInterface | |
| $updateColumns | array|boolean | |
public function upsert(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
): static {
$params = [];
$sql = $this->getQueryBuilder()->upsert($table, $insertColumns, $updateColumns, $params);
return $this->setSql($sql)->bindValues($params);
}
| public array upsertReturning ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true, array|null $returnColumns = null ) | ||
| $table | string | |
| $insertColumns | array|Yiisoft\Db\Query\QueryInterface | |
| $updateColumns | array|boolean | |
| $returnColumns | array|null | |
public function upsertReturning(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
?array $returnColumns = null,
): array {
if ($returnColumns === []) {
$this->upsert($table, $insertColumns, $updateColumns)->execute();
return [];
}
$params = [];
$sql = $this->getQueryBuilder()
->upsertReturning($table, $insertColumns, $updateColumns, $returnColumns, $params);
$this->setSql($sql)->bindValues($params);
/** @psalm-var array<string, mixed> */
return $this->queryInternal(self::QUERY_MODE_ROW | self::QUERY_MODE_EXECUTE);
}
| public array upsertReturningPks ( string $table, array|Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true ) | ||
| $table | string | |
| $insertColumns | array|Yiisoft\Db\Query\QueryInterface | |
| $updateColumns | array|boolean | |
public function upsertReturningPks(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
): array {
$primaryKeys = $this->db->getSchema()->getTableSchema($table)?->getPrimaryKey() ?? [];
return $this->upsertReturning($table, $insertColumns, $updateColumns, $primaryKeys);
}
| public Yiisoft\Db\Command\AbstractCommand withDbTypecasting ( boolean $dbTypecasting = true ) | ||
| $dbTypecasting | boolean | |
public function withDbTypecasting(bool $dbTypecasting = true): static
{
$new = clone $this;
$new->dbTypecasting = $dbTypecasting;
return $new;
}
| public Yiisoft\Db\Command\AbstractCommand withPhpTypecasting ( boolean $phpTypecasting = true ) | ||
| $phpTypecasting | boolean | |
public function withPhpTypecasting(bool $phpTypecasting = true): static
{
$new = clone $this;
$new->phpTypecasting = $phpTypecasting;
return $new;
}
| public Yiisoft\Db\Command\AbstractCommand withTypecasting ( boolean $typecasting = true ) | ||
| $typecasting | boolean | |
public function withTypecasting(bool $typecasting = true): static
{
$new = clone $this;
$new->dbTypecasting = $typecasting;
$new->phpTypecasting = $typecasting;
return $new;
}
Signup or Login in order to comment.