Skip to content

Commit 7ab1ef1

Browse files
committed
Update according changes in db package
1 parent df3fa9a commit 7ab1ef1

File tree

2 files changed

+81
-91
lines changed

2 files changed

+81
-91
lines changed

src/DMLQueryBuilder.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use InvalidArgumentException;
1010
use Yiisoft\Db\Exception\InvalidConfigException;
1111
use Yiisoft\Db\Exception\NotSupportedException;
12-
use Yiisoft\Db\Expression\Expression;
1312
use Yiisoft\Db\Query\QueryInterface;
1413
use Yiisoft\Db\QueryBuilder\AbstractDMLQueryBuilder;
1514

@@ -213,7 +212,7 @@ private function prepareUpsertParts(
213212

214213
foreach ($columnNames as $name) {
215214
$quotedName = $this->quoter->quoteColumnName($name);
216-
$constraintCondition[] = "$quotedTableName.$quotedName=[EXCLUDED].$quotedName";
215+
$constraintCondition[] = "$quotedTableName.$quotedName=EXCLUDED.$quotedName";
217216
}
218217

219218
$onCondition[] = $constraintCondition;
@@ -227,18 +226,18 @@ private function prepareUpsertParts(
227226

228227
$mergeSql = 'MERGE ' . $quotedTableName . ' WITH (HOLDLOCK) USING ('
229228
. (!empty($placeholders) ? 'VALUES (' . implode(', ', $placeholders) . ')' : $values)
230-
. ') AS [EXCLUDED] (' . implode(', ', $quotedInsertNames) . ') ' . "ON ($on)";
229+
. ') AS EXCLUDED (' . implode(', ', $quotedInsertNames) . ') ' . "ON ($on)";
231230

232231
$insertValues = [];
233232

234233
foreach ($quotedInsertNames as $quotedName) {
235-
$insertValues[] = '[EXCLUDED].' . $quotedName;
234+
$insertValues[] = 'EXCLUDED.' . $quotedName;
236235
}
237236

238237
$insertSql = 'INSERT (' . implode(', ', $quotedInsertNames) . ')'
239238
. ' VALUES (' . implode(', ', $insertValues) . ')';
240239

241-
if ($updateColumns === false || $updateNames === []) {
240+
if (empty($updateColumns) || $updateNames === []) {
242241
/** there are no columns to update */
243242
return [
244243
$mergeSql,
@@ -247,16 +246,7 @@ private function prepareUpsertParts(
247246
];
248247
}
249248

250-
if ($updateColumns === true) {
251-
$updateColumns = [];
252-
253-
/** @psalm-var string[] $updateNames */
254-
foreach ($updateNames as $name) {
255-
$updateColumns[$name] = new Expression('[EXCLUDED].' . $this->quoter->quoteColumnName($name));
256-
}
257-
}
258-
259-
$updates = $this->prepareUpdateSets($table, $updateColumns, $params);
249+
$updates = $this->prepareUpsertSets($table, $updateColumns, $updateNames, $params);
260250

261251
return [
262252
$mergeSql,

0 commit comments

Comments
 (0)