Final Class Yiisoft\Db\Mssql\DMLQueryBuilder
| Inheritance | Yiisoft\Db\Mssql\DMLQueryBuilder » Yiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder |
|---|
Implements a DML (Data Manipulation Language) SQL statements for MSSQL Server.
Public Methods
Method Details
| public insertReturningPks( string $table, array|\Yiisoft\Db\Query\QueryInterface $columns, array &$params = [] ): string | ||
| $table | string | |
| $columns | array|\Yiisoft\Db\Query\QueryInterface | |
| $params | array | |
| throws | \Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | \Yiisoft\Db\Exception\InvalidConfigException | |
| throws | \Yiisoft\Db\Exception\NotSupportedException | |
public function insertReturningPks(string $table, array|QueryInterface $columns, array &$params = []): string
{
$primaryKeys = $this->schema->getTableSchema($table)?->getPrimaryKey() ?? [];
return $this->insertReturning($table, $columns, $primaryKeys, $params);
}
| public resetSequence( string $table, integer|string|null $value = null ): string | ||
| $table | string | |
| $value | integer|string|null | |
| throws | InvalidArgumentException | |
|---|---|---|
public function resetSequence(string $table, int|string|null $value = null): string
{
$tableSchema = $this->schema->getTableSchema($table);
if ($tableSchema === null) {
throw new InvalidArgumentException("Table not found: '$table'.");
}
$sequenceName = $tableSchema->getSequenceName();
if ($sequenceName === null) {
throw new InvalidArgumentException("There is not sequence associated with table '$table'.'");
}
$tableName = $this->quoter->quoteTableName($table);
if ($value === null) {
return "DBCC CHECKIDENT ('$tableName', RESEED, 0) WITH NO_INFOMSGS;DBCC CHECKIDENT ('$tableName', RESEED)";
}
return "DBCC CHECKIDENT ('$tableName', RESEED, $value)";
}
| public update( string $table, array $columns, array|string|\Yiisoft\Db\Expression\ExpressionInterface $condition, array|string|\Yiisoft\Db\Expression\ExpressionInterface|null $from = null, array &$params = [] ): string | ||
| $table | string | |
| $columns | array | |
| $condition | array|string|\Yiisoft\Db\Expression\ExpressionInterface | |
| $from | array|string|\Yiisoft\Db\Expression\ExpressionInterface|null | |
| $params | array | |
public function update(
string $table,
array $columns,
array|string|ExpressionInterface $condition,
array|string|ExpressionInterface|null $from = null,
array &$params = [],
): string {
if ($from !== null) {
throw new NotSupportedException(__METHOD__ . '() does not support UPDATE with FROM clause with SQL Server.');
}
return parent::update($table, $columns, $condition, null, $params);
}
| public upsert( string $table, array|\Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true, array &$params = [] ): string | ||
| $table | string | |
| $insertColumns | array|\Yiisoft\Db\Query\QueryInterface | |
| $updateColumns | array|boolean | |
| $params | array | |
| throws | \Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | \Yiisoft\Db\Exception\InvalidConfigException | |
| throws | JsonException | |
| throws | \Yiisoft\Db\Exception\NotSupportedException | |
public function upsert(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
array &$params = [],
): string {
return implode('', $this->prepareUpsertParts($table, $insertColumns, $updateColumns, $params)) . ';';
}
| public upsertReturning( string $table, array|\Yiisoft\Db\Query\QueryInterface $insertColumns, array|boolean $updateColumns = true, array|null $returnColumns = null, array &$params = [] ): string | ||
| $table | string | |
| $insertColumns | array|\Yiisoft\Db\Query\QueryInterface | |
| $updateColumns | array|boolean | |
| $returnColumns | array|null | |
| $params | array | |
public function upsertReturning(
string $table,
array|QueryInterface $insertColumns,
array|bool $updateColumns = true,
?array $returnColumns = null,
array &$params = [],
): string {
[$uniqueNames] = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns);
if (empty($uniqueNames)) {
return $this->insertReturning($table, $insertColumns, $returnColumns, $params);
}
$tableSchema = $this->schema->getTableSchema($table);
$returnColumns ??= $tableSchema?->getColumnNames();
if (empty($returnColumns)) {
return $this->upsert($table, $insertColumns, $updateColumns, $params);
}
/** @var TableSchema $tableSchema */
[$declareSql, $outputSql, $selectSql] = $this->prepareReturningParts($tableSchema, $returnColumns);
[$mergeSql, $updateSql, $insertSql] = $this->prepareUpsertParts($table, $insertColumns, $updateColumns, $params);
return $declareSql
. (!empty($insertSql) && empty($updateSql) ? 'DECLARE @temp int;' : '')
. $mergeSql
. (!empty($insertSql) && empty($updateSql) ? ' WHEN MATCHED THEN UPDATE SET @temp=1' : $updateSql)
. $insertSql
. $outputSql . ';'
. $selectSql;
}
Signup or Login in order to comment.